如何在最后一个历史柱上退出策略中的所有头寸? when=barstate.islast 不起作用,因为它会在下一根蜡烛上执行订单(对吗?)。
last_historic_bar = is the last bar but not realtime?
strategy.close_all(last_historic_bar)
答案 0 :(得分:0)
如果当前时间与当前蜡烛图将关闭的时间之间的时间差小于或等于 24 小时,则这是最后一个历史蜡烛图。
one_day_ms = 1000 * 60 * 60 * 24
last_bar = timenow - time_close <= one_day_ms
strategy.close_all(last_bar)