【问题标题】:PineScript Version 5派恩脚本第 5 版
【发布时间】:2022-11-05 06:23:49
【问题描述】:

有人可以帮我纠正我在更新版本时遇到的 pinescript 问题,因为它告诉我“when”很快就会过时,我必须用“if”替换它,但问题是我不想丢失通知或警报。

谢谢


// Estrategia long 
longEntry() =>
    ta.rsi(close, 2) <= 20 and close >= ta.sma(close, 200) and ta.ema(close, 20)
longExit() =>
    ta.ema(close, 80) and ta.rsi(close, 2) >= 80


strategy.entry(id='Compra', direction=strategy.long, when=longEntry())
strategy.close(id='Compra', when=longExit())
strategy.exit('Cerrar Venta', from_entry='Venda', profit=useTakeProfit, loss=useStopLoss, trail_points=useTrailStop, trail_offset=useTrailOffset)


// Estrategia short
shortEntry() =>
    ta.rsi(close, 2) >= 80 and close <= ta.sma(close, 200) and ta.ema(close, 80)
shortExit() =>
    low <= ta.ema(close, 20) and ta.rsi(close, 2) <= 10


strategy.entry(id='Venda', direction=strategy.short, when=shortEntry())
strategy.close(id='Venda', when=shortExit())
strategy.exit('Cerrar Compra', from_entry='Compra', profit=useTakeProfit, loss=useStopLoss, trail_points=useTrailStop, trail_offset=useTrailOffset)

我已经尝试了一千件事,但这是我第一次在 pinescript 中编程,我对 strategy.close 和 .exit 感到困惑。

【问题讨论】:

    标签: pine-script pinescript-v5 pine-script-v4


    【解决方案1】:

    这只是一条警告消息,告诉您when 将在不久的将来过时。

    所以,而不是:

    strategy.entry(id='Compra', direction=strategy.long, when=longEntry())
    

    你可以做:

    if (longEntry())
        strategy.entry(id='Compra', direction=strategy.long)
    

    两者的工作方式相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 2017-09-17
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多