松树止损?
Stop loss in Pine?
我想为我的每个条目设置止损。如果价格比入场价下跌 2%,就会触发止损
//@version=5
strategy(title="Test ", calc_on_every_tick=false)
haHandle=ticker.heikinashi(syminfo.tickerid)
haOpen=request.security(haHandle,timeframe.period,open)
haClose=request.security(haHandle,timeframe.period,close)
haDeltaAbs=haClose-haClose[1]
haDeltaRel=haDeltaAbs/haClose[1]*100
haEntryCondition = haDeltaRel > 0 and haDeltaRel[1] < 0
strategy.entry("trade", strategy.long, when = haEntryCondition, stop = ????)
strategy.close("trade", when = ta.falling(haClose, 1))
plot(na, "Zero line", color.gray)
但是 Pine 文档中没有说明如何使用这个“停止”参数,它至少是设置止损的正确参数吗?
此致
你应该使用 strategy.exit()
。
sl_per = input.float(2.0) * 0.01
sl_price = strategy.position_avg_price * (1 - sl_per)
if (strategy.position_size > 0)
strategy.exit("SL", "trade", stop=sl_price)
我想为我的每个条目设置止损。如果价格比入场价下跌 2%,就会触发止损
//@version=5
strategy(title="Test ", calc_on_every_tick=false)
haHandle=ticker.heikinashi(syminfo.tickerid)
haOpen=request.security(haHandle,timeframe.period,open)
haClose=request.security(haHandle,timeframe.period,close)
haDeltaAbs=haClose-haClose[1]
haDeltaRel=haDeltaAbs/haClose[1]*100
haEntryCondition = haDeltaRel > 0 and haDeltaRel[1] < 0
strategy.entry("trade", strategy.long, when = haEntryCondition, stop = ????)
strategy.close("trade", when = ta.falling(haClose, 1))
plot(na, "Zero line", color.gray)
但是 Pine 文档中没有说明如何使用这个“停止”参数,它至少是设置止损的正确参数吗?
此致
你应该使用 strategy.exit()
。
sl_per = input.float(2.0) * 0.01
sl_price = strategy.position_avg_price * (1 - sl_per)
if (strategy.position_size > 0)
strategy.exit("SL", "trade", stop=sl_price)