使用安全功能时strategy.order执行两次

时间:2020-01-01 18:39:57

标签: pine-script

仅在我使用具有安全性的strategy.order时遇到此问题。该脚本执行两次该命令:1)关闭蜡烛,2)打开下一个蜡烛。这仅在我实时运行脚本时发生,但它在历史上如预期般工作(即,仅在下一次打开时执行交易)。外观如下(左:实时,右:历史):https://www.tradingview.com/x/enZwiMfC/

注意:左右是相同的脚本,我只是更改了短标题。

这是参考脚本:

//@version=4
strategy("Executes strategy.order Twice using Security", shorttitle = "2 orders issue", overlay=true)

_3m_close = security(syminfo.tickerid, '3', close[1], barmerge.gaps_off, barmerge.lookahead_on)
_3m_open = security(syminfo.tickerid, '3', open[1], barmerge.gaps_off, barmerge.lookahead_on)

_3m_green_candle = _3m_close > _3m_open
_3m_red_candle = _3m_close < _3m_open

green_candle = close > open
red_candle = close < open

_3m_color = _3m_green_candle ? color.lime : _3m_red_candle ? color.red : color.gray

LongTrade = _3m_green_candle and green_candle
CloseAll = _3m_red_candle and red_candle

strategy.order("Long", strategy.long, when=LongTrade)
strategy.close_all(CloseAll)

//PLOTS
plot(_3m_close, linewidth=2, color=_3m_color, style=plot.style_circles)
plot(_3m_open, linewidth=1, color=_3m_color, style=plot.style_circles)
bgcolor(LongTrade ? color.lime : na)

我该怎么做才能防止此问题?预先感谢。

0 个答案:

没有答案
相关问题