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

基于布林带(20,3)筛选并标记符合条件的最高高点(PineScript)

修改后的Pine Script代码实现
//@version=5
indicator(shorttitle="BBM", title="BBM - 布林带突破最高高点标记", overlay=true, max_labels_count = 500)
length = input.int(20, minval=1, title="布林带周期")
src = input(close, title="数据源")
mult = input.float(3, minval=0.001, maxval=50, title="标准差倍数")
filter_window = input.int(5, minval=1, title="过滤窗口(左右K线数量)")

// 计算布林带
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// 绘制布林带
plot(basis, style=plot.style_circles, color=color.blue, title="中轨")
p1 = plot(upper, color=color.rgb(155, 39, 176, 30), title="上轨")
p2 = plot(lower, color=color.rgb(155, 39, 176, 30), title="下轨")

// 突破上轨条件
break_upper = high > upper

// 计算当前窗口内(左右filter_window根K线)的最高高点
window_high = ta.highest(high, filter_window*2 + 1)
// 判断当前K线是否是窗口内的最高高点,同时满足突破上轨条件
is_highest_break = break_upper and high == window_high and ta.barssince(break_upper) <= filter_window

// 仅在最高突破点绘制标记
plotshape(is_highest_break ? upper : na, color=color.rgb(255, 255, 255), 
          style = shape.circle, text = "A", textcolor = color.white, 
          size=size.tiny, location=location.abovebar, title="最高突破标记")

关键逻辑说明

  • 过滤窗口配置:通过filter_window参数自定义需要过滤的左右K线数量,默认设为5根,可按需调整
  • 突破判定:保留原逻辑break_upper = high > upper识别突破布林带上轨的K线
  • 最高高点筛选:
    • window_high计算以当前K线为中心,覆盖左右各filter_window根K线范围内的最高价格
    • is_highest_break同时校验三个条件:当前K线突破上轨、当前K线价格为窗口内最高、距离最近一次突破的K线不超过设定窗口范围,避免重复标记
  • 标记绘制:仅在符合is_highest_break条件的K线位置绘制标记,自动过滤同一窗口内的其他突破点

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 03:15:09