Pinescript (Tradingview) 每次都停止和限制不起作用

时间:2021-07-26 14:39:01

标签: pine-script algorithmic-trading tradingview-api

longcon = crossover(ema5, ema21)
longCondition1 = longcon[4]
longCondition2 = ema50 > ema200 ? 1: 0
longCondition3 = bbr > 0.75 ? 1: 0
longCondition4 = sig > 15 ? 1: 0
longCondition5 = ao > 2 ? 1: 0
if (longCondition1 and longCondition2 and longCondition3 and longCondition4 and longCondition5)
    strategy.entry("long", strategy.long)
    strategy.exit("exit", "long", stop=strategy.position_avg_price*0.98, limit=strategy.position_avg_price*1.01)
plot(strategy.position_avg_price)
plot(strategy.position_avg_price*0.98)
plot(strategy.position_avg_price*1.01)

我一直在尝试回测此策略,但由于某种原因,止损和获利(限价)无法正常工作,我不知道为什么。我绘制了这些值,当达到这些级别时,脚本不会执行。 enter image description here

您可以看到第一次退出是错误的,因为价格上涨了 1%,但脚本没有卖出。第二次围绕脚本工作正常。这是什么原因造成的?

1 个答案:

答案 0 :(得分:0)

我刚刚想通了:

if (longCondition1 and longCondition2 and longCondition3 and longCondition4 and longCondition5)
    strategy.entry("long", strategy.long)
strategy.exit("exit", "long", stop=strategy.position_avg_price*0.98, limit=strategy.position_avg_price*1.01)