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

Pine Script枢轴高低点告警触发异常问题求助

解决Pine Script枢轴高低点告警误触发问题

问题根源

你当前的告警条件直接检查tempHigh/tempLow是否非空,当脚本加载时,图表上已存在的枢轴点对应的tempHigh/tempLow是有值的,所以会立即触发告警。要实现仅在新枢轴点生成时触发,需要跟踪「新信号产生的瞬间」,而不是信号是否存在。

修改方案

我们通过新增布尔变量记录「是否刚创建了新的枢轴高低点」,仅在这个变量为true时触发告警:

修改后的完整代码

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator("Example Pivot high/low",overlay = true, max_bars_back=5000)

// 新增布尔变量,标记是否刚生成新的枢轴高低点
newPivotHigh = false
newPivotLow = false

if not na(pvtHighTemp)
    if pvtHighTemp > pvtHigh1Temp
        label.delete(tempHigh[1])
        tempHigh := label.new(bar_index[pvtLengthTemp], pvtHighTemp, '* ' + str.tostring(pvtHighTemp, format.mintick), xloc.bar_index, yloc.price, #284aa9, label.style_label_down, color.white, size.small)
        // 当创建新枢轴高点时,标记变量为true
        newPivotHigh := true
    pvtHigh1Temp := pvtHighTemp
    
if high > pvtHigh1Temp
    label.delete(tempHigh[1])

if not na(pvtLowTemp)
    if pvtLowTemp < pvtLow1Temp
        label.delete(tempLow[1])
        tempLow := label.new(bar_index[pvtLengthTemp], pvtLowTemp, '* ' + str.tostring(pvtLowTemp, format.mintick), xloc.bar_index, yloc.price, #284aa9, label.style_label_up, color.white, size.small)
        // 当创建新枢轴低点时,标记变量为true
        newPivotLow := true
    pvtLow1Temp  := pvtLowTemp

if low < pvtLow1Temp
    label.delete(tempLow[1])

// 告警条件改为仅当新信号生成时触发
alertcondition(newPivotHigh, title="Pivot TOP Alert", message="New Pivot TOP Signal")
alertcondition(newPivotLow, title="Pivot BOTTOM Alert", message="New Pivot BOTTOM Signal")

关键修改点说明

  • 新增newPivotHigh和newPivotLow两个布尔变量,初始值为false
  • 在创建新枢轴高点/低点的代码块内,将对应变量设为true,表示这根K线产生了新信号
  • 告警条件改为检测这两个变量是否为true,只有当新枢轴点被创建的瞬间才触发告警,脚本加载时已有信号不会触发

这样修改后,告警只会在新的枢轴高低点生成时触发,解决了激活时立即触发的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 10:35:05