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

如何识别前一日高低点在15分钟周期是否为枢轴点?

解决低时间周期上前一日高低点的枢轴点判断问题

核心方案

不用直接硬找低周期K线的索引,而是通过Pine Script的request.security_lower_tf拉取低周期数据,结合时间范围筛选前一日的K线,定位高低点位置后再验证枢轴点属性。

具体实现步骤

  • 拉取低周期基础数据:获取15分钟周期的时间戳、高点、低点数组,这些数据对应当前主周期K线覆盖的所有低周期K线。
  • 筛选前一日的低周期K线:计算前一日的起始/结束时间戳,遍历低周期时间数组,锁定属于前一日的K线索引范围。
  • 定位高低点的低周期位置:在筛选出的前一日K线中,找到高点最大值、低点最小值对应的低周期索引。
  • 验证枢轴点属性:用ta.pivothigh/ta.pivotlow函数,结合低周期的高低数据,判断目标位置是否符合枢轴点定义。

代码示例

//@version=5
indicator("前一日高低点低周期枢轴点验证", overlay=true)

// 定义目标低时间周期
lower_tf = "15"

// 拉取低周期的时间戳、高点、低点数据
[lower_time, lower_high, lower_low] = request.security_lower_tf(syminfo.tickerid, lower_tf, [time, high, low])

// 计算前一日的时间范围(当日0点到前一日0点)
prev_day_start = timestamp(year, month, dayofmonth - 1, 0, 0)
prev_day_end = timestamp(year, month, dayofmonth, 0, 0)

// 定位前一日低周期K线的首尾索引
var int prev_day_first_idx = na
var int prev_day_last_idx = na
if barstate.islast
    // 找前一日第一根低周期K线
    for i = 0 to array.size(lower_time) - 1
        t = array.get(lower_time, i)
        if t >= prev_day_start and t < prev_day_end
            prev_day_first_idx := i
            break
    // 找前一日最后一根低周期K线
    for i = array.size(lower_time) - 1 down to 0
        t = array.get(lower_time, i)
        if t >= prev_day_start and t < prev_day_end
            prev_day_last_idx := i
            break

// 提取前一日的高低点数组
var float[] prev_day_highs = array.new_float()
var float[] prev_day_lows = array.new_float()
if barstate.islast and not na(prev_day_first_idx) and not na(prev_day_last_idx)
    for i = prev_day_first_idx to prev_day_last_idx
        array.push(prev_day_highs, array.get(lower_high, i))
        array.push(prev_day_lows, array.get(lower_low, i))

// 找到前一日高低点在低周期全局数组中的索引
var int prev_day_high_idx = na
var int prev_day_low_idx = na
if barstate.islast and array.size(prev_day_highs) > 0
    max_high = array.max(prev_day_highs)
    prev_day_high_idx := array.indexof(prev_day_highs, max_high) + prev_day_first_idx
    
    min_low = array.min(prev_day_lows)
    prev_day_low_idx := array.indexof(prev_day_lows, min_low) + prev_day_first_idx

// 验证是否为枢轴点(默认前后各1根K线对比)
var bool is_prev_high_pivot = false
var bool is_prev_low_pivot = false
if barstate.islast and not na(prev_day_high_idx) and not na(prev_day_low_idx)
    // 确保目标索引前后有足够K线用于判断
    if prev_day_high_idx > 1 and prev_day_high_idx < array.size(lower_high) - 1
        is_prev_high_pivot := ta.pivothigh(lower_high, 1, 1) == array.get(lower_high, prev_day_high_idx)
    if prev_day_low_idx > 1 and prev_day_low_idx < array.size(lower_low) - 1
        is_prev_low_pivot := ta.pivotlow(lower_low, 1, 1) == array.get(lower_low, prev_day_low_idx)

// 在图表上输出结果
if barstate.islast
    label.new(bar_index, high, str.format("前一日高点(15分钟): {0}", is_prev_high_pivot ? "是枢轴点" : "非枢轴点"), color=color.green)
    label.new(bar_index, low, str.format("前一日低点(15分钟): {0}", is_prev_low_pivot ? "是枢轴点" : "非枢轴点"), color=color.red)

关键说明

  • request.security_lower_tf返回的是数组,包含当前主周期K线对应的所有低周期K线数据,无需手动计算跨周期索引映射。
  • 验证枢轴点时,必须确保目标索引前后有足够的K线(比如示例中的前后1根),否则ta.pivothigh会返回na导致判断失效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 16:35:23