0

我最近刚开始使用 pine scrip,我写了这段代码回测了一个策略,但是 strategy.entry() 函数似乎不起作用。我什至改变了它,使它与其余的代码完全无关,它仍然不起作用。我想知道是否有人知道什么可能会阻止我的 strategy.entry() 根本不工作。

strategy("Higher High", overlay=true, calc_on_every_tick=true, initial_capital=5000, currency='USD', commission_type=strategy.commission.cash_per_order, commission_value=10, pyramiding=50)
Period = input.int(7,"Pivot Point Period", minval = 1)
showSR = input(defval = true, title="Show Support/Resistance Level Extensions")
showPP = input(defval = true, title="Show Pivot Points Labels")
ShowFB = input(true, title="Show Fractal Break Arrows")

float pivotHigh = na //swing high
float pivotLow = na //swing low
pivotHigh := ta.pivothigh(Period, Period)
pivotLow := ta.pivotlow(Period, Period)

valuewhen_1 = ta.valuewhen(pivotHigh, high[Period], 1) // return the most recent occurence of a condition; in this case, the most 2nd recent time (so the last-last time) there was a pivot high
valuewhen_2 = ta.valuewhen(pivotHigh, high[Period], 0) //returns the most recent pivot high
higherhigh = na(pivotHigh) ? na : valuewhen_1 < valuewhen_2 ? pivotHigh : na //higher high returns the price of the most recent pivot high IF it is greater than the last pivot high
lowerhigh = na(pivotHigh) ? na : valuewhen_1 > valuewhen_2 ? pivotHigh : na
valuewhen_3 = ta.valuewhen(pivotLow, low[Period], 1)
valuewhen_4 = ta.valuewhen(pivotLow, low[Period], 0)
higherlow = na(pivotLow) ? na : valuewhen_3 < valuewhen_4 ? pivotLow : na
lowerlow = na(pivotLow) ? na : valuewhen_3 > valuewhen_4 ? pivotLow : na
////////////////


upTrend = close > high[1]
strategy.entry('Long', strategy.long, qty=10, when=upTrend, limit=close, comment = 'Long', oca_name = 'x', oca_type=strategy.oca.cancel)


////////////////
plotshape(showPP ? higherhigh  : na, title='HH', style=shape.triangledown, location=location.abovebar, color=color.new(color.green,50), text="HH",textcolor=color.new(color.green,50),offset = -Period)
plotshape(showPP ? higherlow  : na, title='HL', style=shape.triangleup, location=location.belowbar, color=color.new(color.green,50), text="HL",textcolor=color.new(color.green,50),offset = -Period)
plotshape(showPP ? lowerhigh  : na, title='LH', style=shape.triangledown, location=location.abovebar, color=color.new(color.red,50), text="LH",textcolor=color.new(color.red,50),offset = -Period)
plotshape(showPP ? lowerlow  : na, title='LL', style=shape.triangleup, location=location.belowbar, color=color.new(color.red,50), text="LL",textcolor=color.new(color.red,50),offset = -Period)

///showing the resistance and support (of pivot points)

float resistance = na
float support    = na
support    := pivotLow  ? pivotLow  : support[1]
resistance := pivotHigh ? pivotHigh : resistance[1]

plot(showSR and support    ? support    : na, color = showSR and support    ? color.new(color.teal,50) : na, style = plot.style_circles, offset = -Period)
plot(showSR and resistance ? resistance : na, color = showSR and resistance ? color.new(color.red,50)  : na, style = plot.style_circles, offset = -Period)
4

1 回答 1

0

Fireshot,您在此策略中只有入场听牌。交易正在执行,但我们无法计算没有关闭交易的交易。在达到您的限制后,我有 50 个未平仓头寸,我们一直持有这些头寸,因为我们需要使用 strategy.exit 或 strategy.close 退出交易

于 2022-01-05T06:46:53.150 回答