如何仅在常规交易日首根K线开盘时执行逻辑?解决barstate函数痛点
开盘时段特定逻辑触发问题
我需要让特定逻辑仅在市场开盘时运行,尝试使用barstate.isfirst和barstate.isnew内置函数后发现:
- 这些函数要等到第一根30分钟K线收盘才会触发
- 存在重绘等不稳定问题
另外,部分低成交量股票开盘约1分钟后才会正常交易,我的算法中其他逻辑适用于除常规交易日首次开盘外的所有时段。
我尝试过的Bar States相关代码如下:
//@version=5 indicator("Testing Open Logic", shorttitle="Trend Cont - Gap Logic", overlay=true, max_labels_count=500) if session.isfirstbar label.new(bar_index[0], close, "New Bar") if barstate.isnew label.new(bar_index[0], close + 2,"BSIN", color = color.purple) if barstate.isfirst label.new(bar_index[0], close + 3, "IFB",color = color.teal)
测试截图:
内容的提问来源于stack exchange,提问作者A Singh
相关产品推荐
相关产品推荐

