本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=4
study(title="Pivot Points [CB]", shorttitle="Pivots HL [CB]", overlay=true)
//---------//
// INPUTS //
//---------//
pivotLeftLength = input(8, minval=1, title="Pivot Length Left Hand Side")
pivotRightLength = input(5, minval=1, title="Pivot Length Right Hand Side")
showSRLevels = input(true, title="Show S/R Level Extensions")
// Get High and Low Pivot Points
pivotHigh = pivothigh(high, pivotLeftLength, pivotRightLength)
pivotLow = pivotlow(low, pivotLeftLength, pivotRightLength)
// HH
hhValueWhen1 = valuewhen(pivotHigh, high[pivotRightLength], 1)
hhValueWhen2 = valuewhen(pivotHigh, high[pivotRightLength], 0)
higherHigh = na(pivotHigh) ? na : hhValueWhen1 < hhValueWhen2 ? pivotHigh : na
plotshape(higherHigh, title='HH', style=shape.labeldown, location=location.abovebar, color=color.green, text="HH", textcolor=color.white, offset=-pivotRightLength)
// LH
lhValueWhen1 = valuewhen(pivotHigh, high[pivotRightLength], 1)
lhValueWhen2 = valuewhen(pivotHigh, high[pivotRightLength], 0)
lowerHigh = na(pivotHigh) ? na : lhValueWhen1 > lhValueWhen2 ? pivotHigh : na
plotshape(lowerHigh, title='LH', style=shape.labeldown, location=location.abovebar, color=color.red, text="LH", textcolor=color.white, offset=-pivotRightLength, size=size.tiny)
// HL
hlValueWhen1 = valuewhen(pivotLow, low[pivotRightLength], 1)
hlValueWhen2 = valuewhen(pivotLow, low[pivotRightLength ], 0)
higherLow = na(pivotLow) ? na : hlValueWhen1 < hlValueWhen2 ? pivotLow : na
plotshape(higherLow, title='HL', style=shape.labelup, location=location.belowbar, color=color.green, text="HL", textcolor=color.white, offset=-pivotRightLength)
// LL
llValueWhen1 = valuewhen(pivotLow, low[pivotRightLength], 1)
llValueWhen2 = valuewhen(pivotLow, low[pivotRightLength ], 0)
lowerLow = na(pivotLow) ? na : llValueWhen1 > llValueWhen2 ? pivotLow : na
plotshape(lowerLow, title='LL', style=shape.labelup, location=location.belowbar, color=color.red, text="LL", textcolor=color.white, offset=-pivotRightLength)
// Count How many candles for current Pivot Level, If new reset.
countHigh = 0
countLow = 0
countHigh := na(pivotHigh) ? nz(countHigh[1]) + 1 : 0
countLow := na(pivotLow) ? nz(countLow[1]) + 1 : 0
pivotHighs = 0.0
pivotLows = 0.0
pivotHighs := na(pivotHigh) ? pivotHighs[1] : high[pivotRightLength]
pivotLows := na(pivotLow) ? pivotLows[1] : low[pivotRightLength]
hipc = pivotHighs != pivotHighs[1] ? na : color.new(color.red,50)
lopc = pivotLows != pivotLows[1] ? na : color.new(color.green,50)
// Show Levels if Selected
plot(showSRLevels ? pivotHighs : na, color=hipc, linewidth=1, offset=-pivotRightLength , title="Top Levels",style=plot.style_circles)
plot(showSRLevels ? pivotLows : na, color=lopc, linewidth=1, offset=-pivotRightLength , title="Bottom Levels",style=plot.style_circles)