我正在使用 pine 脚本来回测交易策略,但不知道如何在常规交易日结束时平仓。我的脚本继续运行并在延长交易时间时填写订单。我希望它在常规交易时段结束时关闭任何未平仓头寸,以便买入或卖出(取决于当前头寸)市场平仓订单。
这是我脚本的计时部分。感谢每天有关如何实现 MOC 订单的任何反馈。 `
start = timestamp(2022,1,1,6,30,0)
end = timestamp(2022,11,16,1,0,0)
if time >= start and time <= end
strategy.entry("buySignal",strategy.long,300.0, when = buySignal)
strategy.entry("sellSignal",strategy.short,300.0, when = sellSignal)
strategy.close("buySingnal", when = sellSignal)
strategy.close("sellSignal", when = buySignal)
`
概念来自 https://www.tradingview.com/v/mCOgJC67/
//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)
if session.isfirstbar
strategy.entry("My Long Entry Id", strategy.long)
closeAllAtEndOfRegularSession(series string comment = na, series string alertMessage = na) =>
if session.islastbar_regular and barstate.isconfirmed
strategy.close_all(comment = comment, alert_message = alertMessage, immediately = true)
closeAllAtEndOfRegularSession()
此策略将按规定进入和退出,但仅在所有其他柱上,并且它并不是所提出问题的真正解决方案。