Pine Script去除支撑位重叠区间:保留最新区间需求
问题描述
我编写了一段Pine Script代码用于标记枢轴区间(pivot Zones),目前已实现区间绘制和被突破区间的移除功能,但不知道如何去除重叠的支撑区间并保留最新的那个区间。
现有代码
//@version=6 indicator('Support Resistance', 'SR', true, max_lines_count = 500) // Supoort { // SR Basic Inputs { doji = (high - low) * 0.1 > math.abs(open - close) bullCandle = (close > open and not doji) bearCandle = (open > close and not doji) srPivotBars = input.int(4, 'Support Resistance Pivot Bars', inline = 'pivotsr', group = 'pivotsr') // Finding pivot bars Low srPivotLowValue = ta.pivotlow(srPivotBars, srPivotBars) // Validating Pivot srPivotLowTrue = na(srPivotLowValue) ? false : true // Finding Pivots 2 candle middle point when engulfing is found pivotLowMidPoint1 = srPivotLowValue + (math.max(high[srPivotBars], high[srPivotBars + 1]) - srPivotLowValue) / 2 pivotLowMidPoint2 = srPivotLowValue + (math.max(high[srPivotBars], high[srPivotBars - 1]) - srPivotLowValue) / 2 // Region Colors supportLineColor = color.new(#4caf50, 50) // #00ff0080 supportFillColor = color.new(#4caf50, 70) // #00ff0033 // storing the lines in the array var array<line> supportBottom = array.new<line>() var array<line> supportTop = array.new<line>() BROKENSUPPORTS() => if supportBottom.size() > 0 and supportTop.size() > 0 for [idx, m] in supportBottom if low < m.get_y1() m.delete() line.delete(supportTop.get(idx)) supportBottom.remove(idx) supportTop.remove(idx) //} // Pivot Point SR { showPPSR = input.bool(true, "Pivot Levels SR", group = "ppsr") pivotPointLow1 = srPivotLowTrue and bearCandle[srPivotBars + 1] and bullCandle[srPivotBars] pivotPointLow2 = srPivotLowTrue and bearCandle[srPivotBars] and bullCandle[srPivotBars - 1] if pivotPointLow1 and showPPSR and barstate.isconfirmed supportBottom.unshift(line.new(bar_index - srPivotBars - 1, srPivotLowValue, last_bar_index + 1, srPivotLowValue, xloc.bar_index, extend.right, color = supportLineColor)) supportTop.unshift(line.new(bar_index - srPivotBars - 1, pivotLowMidPoint1, last_bar_index + 1, pivotLowMidPoint1, xloc.bar_index, extend.right, color = supportLineColor)) if pivotPointLow2 and showPPSR and barstate.isconfirmed supportBottom.unshift(line.new(bar_index - srPivotBars, srPivotLowValue, last_bar_index + 1, srPivotLowValue, xloc.bar_index, extend.right, color = supportLineColor)) supportTop.unshift(line.new(bar_index - srPivotBars, pivotLowMidPoint2, last_bar_index + 1, pivotLowMidPoint2, xloc.bar_index, extend.right, color = supportLineColor)) BROKENSUPPORTS() //} // Fill color between the lines { if supportBottom.size() > 0 and supportTop.size() > 0 for i = 0 to supportBottom.size() - 1 by 1 linefill.new(supportBottom.get(i), supportTop.get(i), supportFillColor) //} //}
尝试的无效重叠判断代码
我参照BROKENSUPPORTS()逻辑编写了如下重叠判断代码,但未生效:
overlapping() => overlap = false if supportBottom.size() > 0 and supportTop.size() > 0 for [idx, m] in supportTop if low < m.get_y1() and m.get_y1() > low overlap := true overlap overlap
内容的提问来源于stack exchange,提问作者Kunthu Dhadda
相关产品推荐
相关产品推荐

