You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅在常规交易日首根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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 18:27:08