【问题标题】:Pinescript (Tradingview) stop and limit not working every timePinescript(Tradingview)每次都停止并限制不工作
【发布时间】:2021-07-26 14:39:01
【问题描述】:
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)

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

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

【问题讨论】:

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


    【解决方案1】:

    我刚刚想通了:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      相关资源
      最近更新 更多