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

求TradingView Pine脚本:获取日内高低点开盘后K线编号

TradingView Pine Script:获取日内高低价对应的K线编号

功能说明

该脚本会在每个交易日开盘后,从第一根K线开始按顺序计数,实时追踪日内最高价、最低价对应的K线编号,同时在图表上用标签标注位置,数据窗口同步显示关键数值。

完整脚本

//@version=5
indicator("日内高低价K线编号追踪", overlay=true, shorttitle="Day High/Low Bar #")

// 初始化追踪变量
var int day_bar_count = 0
var float day_high = na
var int day_high_bar_num = na
var float day_low = na
var int day_low_bar_num = na

// 判断新交易日触发点
is_new_day = ta.change(time("D"))

// 新交易日重置所有追踪数据
if is_new_day
    day_bar_count := 1
    day_high := high
    day_high_bar_num := day_bar_count
    day_low := low
    day_low_bar_num := day_bar_count
else
    // 交易日内递增K线计数
    day_bar_count := day_bar_count + 1
    // 更新日内最高价及对应编号
    if high > day_high
        day_high := high
        day_high_bar_num := day_bar_count
    // 更新日内最低价及对应编号
    if low < day_low
        day_low := low
        day_low_bar_num := day_bar_count

// 在数据窗口展示核心数值
plotchar(na, "当前K线编号", "", location.bottom, display=display.data_window, value=day_bar_count)
plotchar(na, "日内最高价K线编号", "", location.bottom, display=display.data_window, value=day_high_bar_num)
plotchar(na, "日内最低价K线编号", "", location.bottom, display=display.data_window, value=day_low_bar_num)

// 在高低价K线位置添加标注标签
var label high_label = na
var label low_label = na

// 更新最高价标签
if high == day_high and barstate.islast
    high_label := label.new(bar_index, high, str.tostring(day_high_bar_num), color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
else if barstate.islast
    label.delete(high_label)

// 更新最低价标签
if low == day_low and barstate.islast
    low_label := label.new(bar_index, low, str.tostring(day_low_bar_num), color=color.red, textcolor=color.white, style=label.style_label_up, size=size.small)
else if barstate.islast
    label.delete(low_label)

使用说明

  1. 将脚本复制到TradingView的Pine编辑器,点击「添加到图表」即可运行。
  2. 每个交易日开盘后,K线会从1开始计数,后续K线依次递增。
  3. 数据窗口会实时显示当前K线编号、日内最高价/最低价对应的K线编号。
  4. 日内最高价K线会显示绿色向下标签,最低价K线会显示红色向上标签,直接标注对应编号。
  5. 适配所有时间框架(1分钟、5分钟等),切换周期后会自动重新开始当日计数。

内容的提问来源于stack exchange,提问作者Mikinkumar Patel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 03:25:35