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

Pine Script需求:仅在符合条件的K线绘制高低枢轴箭头

问题解决:Pine Script 遗漏单个蓝色Pivot High K线的箭头绘制问题

核心需求回顾

仅在满足RSI+ADX筛选条件的彩色K线(蓝色做多K线、黄色做空K线)上,当K线为Pivot High时绘制绿色向上箭头,为Pivot Low时绘制红色向下箭头。当前脚本存在单个蓝色Pivot High K线箭头遗漏的问题。

问题根源

遗漏通常是因为Pivot High/Low的判断逻辑与彩色K线的筛选条件未完全绑定,或是Pivot周期参数设置过严,导致单个符合做多条件的K线被排除在Pivot判定之外。

修正后的完整脚本

//@version=5
indicator("RSI+ADX Pivot Arrows", overlay=true)

// 基础指标参数配置
rsiLength = input.int(14, "RSI周期")
adxLength = input.int(14, "ADX周期")
pivotOffset = input.int(1, "Pivot偏移周期", tooltip="设置为1则单个K线即可判定为Pivot")

// 计算RSI与ADX值
rsiValue = ta.rsi(close, rsiLength)
adxValue = ta.adx(adxLength)

// 定义做多/做空K线的筛选条件
longCondition = rsiValue > 50 and adxValue > 25
shortCondition = rsiValue < 50 and adxValue > 25

// 判定当前K线是否为Pivot High/Low
isPivotHigh = ta.pivothigh(pivotOffset, pivotOffset)
isPivotLow = ta.pivotlow(pivotOffset, pivotOffset)

// 仅在符合条件的彩色K线上绘制箭头
if (longCondition and isPivotHigh)
    label.new(bar_index, high, "", color=color.green, style=label.style_uparrow, size=size.small)
if (shortCondition and isPivotLow)
    label.new(bar_index, low, "", color=color.red, style=label.style_downarrow, size=size.small)

// 绘制彩色K线用于验证
barcolor(longCondition ? color.blue : shortCondition ? color.yellow : na)

关键修正细节

  • 条件强绑定:将Pivot判定完全嵌套在做多/做空条件内,确保只有通过RSI+ADX筛选的K线才会触发箭头绘制。
  • 宽松Pivot判定:将pivotOffset设置为1,让单个K线只要比前后各1根K线的高点更高,就会被判定为Pivot High,避免遗漏孤立的符合条件K线。
  • 精准箭头定位:使用label.new替代plotarrow,箭头会精准附着在K线的高点/低点,减少视觉偏移导致的遗漏错觉。

验证步骤

  1. 运行修正脚本后,观察蓝色做多K线中单个Pivot High的位置,确认绿色箭头是否正常显示。
  2. 可调整pivotOffset参数(如设置为2,需当前K线比前后各2根K线更高才判定为Pivot),测试不同Pivot周期下的适配效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 11:15:05