Pine 脚本 - 当开盘价 > 入场价 "aka first profitable open" 时退出

Pine Script - Exit When Open Price > Entry Price "aka first profitable open"

再次感谢您的帮助。

尝试让市价订单在第一个获利开盘时执行

按照推荐,试了几个'process_orders_on_close'。设置为 true,修复了延迟退出一个小柱的原始问题(完美!)但是,它打破了入口,下面的第一张图片,因为入口是在条件上,而不是在满足条件后的柱。下图一。

[![图一][1]][1]

对于图二,目的是将 'process_orders_on_close' 从 "na" 切换为 "true"。修复了入场但最初的问题是晚退出一个柱 returns。下面图二中的结果和代码。

[![图二][2]][2]

再次感谢您。

//CODE FOR IMAGE ONE
//@version=4 
strategy(title="Pattern Tester - FPO)", process_orders_on_close = true, 
     overlay=true)
OS = (high > high[1] and low < low[1] and close < close[1])

if (OS)
    process_orders_on_close = true, strategy.entry(id="FPO", long=true)

if strategy.position_size > 0 
    strategy.close("FPO", when = open > strategy.position_avg_price)

//CODE FOR IMAGE TWO
//@version=4 
strategy(title="Pattern Tester - FPO)", process_orders_on_close = na, 
     overlay=true)
OS = (high > high[1] and low < low[1] and close < close[1])

if (OS)
    strategy.entry(id="FPO", long=true)

if strategy.position_size > 0 
    process_orders_on_close = true, strategy.close("FPO", when = open > strategy.position_avg_price)


  [1]: https://i.stack.imgur.com/4VLcQ.jpg
  [2]: https://i.stack.imgur.com/LcXsZ.jpg

您可以在等宽代码前后使用```。

您可以在 strategy() 声明语句中使用 process_orders_on_close=true