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

如何在Pine Script中用plot绘制无中断向右延伸的支撑阻力线

解决支撑阻力线无限延伸的问题

问题分析

你当前的代码用plot函数绘制支撑阻力线,但plot依赖resistance和support变量的连续值,当新水平出现时旧水平的绘制会中断。你尝试的line.new被放在主逻辑中,每根K线都会创建新线,且仅使用当前的支撑阻力值,无法正确标记历史水平。

解决方案

核心思路是在每次检测到新的支撑/阻力水平时,单独创建一条向右无限延伸的线,而非依赖plot或重复创建线。具体步骤:

  1. 识别新的支撑/阻力信号(即highlel或lowlel非空时)
  2. 在信号出现的K线位置调用line.new,设置extend=extend.right实现无限延伸
  3. 移除原有的plot和重复创建的line.new代码

修改后的完整代码

//@version=5
indicator(title='Test029', shorttitle='Test029', overlay=true)
//Input
exhaustionSwitch = input(true, title='Show exhaustion Bar point (Arrows)')
levelSwitch = input(true, title='Show exhaustion levels (Lines)')
length = input(40, 'Exhaustions swing length')
bars = input(10, 'Exhaustion bar count')
thicknesSwitch = input(2, title='Line Thickness(Level thickness)')
//Fun Lele
test(bars, len) =>
    bindex = int(na)
    bindex := nz(bindex[1], 0)
    sindex = int(na)
    sindex := nz(sindex[1], 0)

    return_1 = 0
    bindex := close > close[4] ? bindex + 1 : bindex
    sindex := close < close[4] ? sindex + 1 : sindex
    if bindex > bars and close < open and high >= ta.highest(high, len)
        bindex := 0
        return_1 := -1
        return_1
    else
        if sindex > bars and close > open and low <= ta.lowest(low, len)
            sindex := 0
            return_1 := 1
            return_1
//Out C
testx = test(bars, length)
//Out Bar 
highlel = testx == -1 ? high : na
lowlel = testx == 1 ? low : na

// 绘制 exhaustion 箭头
if exhaustionSwitch
    plotshape(highlel, title="Resistance Arrow", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
    plotshape(lowlel, title="Support Arrow", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)

// 颜色定义
rescol = color.new(#ff0000, 1)
supcol = color.new(#138484, 1)

// 绘制支撑阻力线:仅在新水平出现时创建线
if levelSwitch
    // 新阻力水平
    if not na(highlel)
        line.new(bar_index, highlel, bar_index + 1, highlel, extend=extend.right, color=rescol, width=thicknesSwitch)
    // 新支撑水平
    if not na(lowlel)
        line.new(bar_index, lowlel, bar_index + 1, lowlel, extend=extend.right, color=supcol, width=thicknesSwitch)

alertcondition(lowlel, 'Up')
alertcondition(highlel, 'Down')

关键修改说明

  • 移除了原有的plot和重复调用的line.new,避免无效线条和中断的水平
  • 新增plotshape绘制 exhaustion 箭头(保留原有功能)
  • 仅在highlel或lowlel非空时(即检测到新水平)创建线,每条线从信号K线开始向右无限延伸
  • 保留所有输入参数的控制功能,可通过开关显示/隐藏箭头和线条

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 22:43:09