Pivot Points High Low (HH/HL/LH/LL) [Anan]

Mohamed3nan · study · 109 行 · 点赞 5,566 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=4
 
study(title="Pivot Points High Low (HH/HL/LH/LL) [Anan] ", shorttitle="Pivots HL [Anan]", overlay=true)
 
 
// - INPUTS
ShowPivots = input(true, title="Show Pivot Points")
 
left = input(5, minval=1, title="Pivot Length Left Hand Side")
right = input(5, minval=1, title="Pivot Length Right Hand Side")
ShowSRLevels = input(true, title="Show S/R Level Extensions")
ShowChannel = input(false, title="Show Levels as a Fractal Chaos Channel")
maxLvlLen = input(0, minval=0, title="Maximum S/R Level Extension Length")
 
ShowHHLL = input(true, title="Show HH,LL,LH,HL markers on Pivots Points")
clrPivot = input(false, title="Highlight Pivot with Coloured Bar")
//
ShowFB = input(true, title="Show Fractal Break Alert Arrows")
 
 
// Determine pivots
pvtLenL = left
pvtLenR = right
 
// Get High and Low Pivot Points
pvthi_ = pivothigh(high, pvtLenL, pvtLenR)
pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)
 
// Force Pivot completion before plotting.
pvthi = pvthi_
pvtlo = pvtlo_
 
//  ||-----------------------------------------------------------------------------------------------------||
//  ||---   Higher Highs, Lower Highs, Higher Lows, Lower Lows  -------------------------------------------||
valuewhen_1 = valuewhen(pvthi, high[pvtLenR], 1)
valuewhen_2 = valuewhen(pvthi, high[pvtLenR], 0)
higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
valuewhen_3 = valuewhen(pvthi, high[pvtLenR], 1)
valuewhen_4 = valuewhen(pvthi, high[pvtLenR], 0)
lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
valuewhen_5 = valuewhen(pvtlo, low[pvtLenR], 1)
valuewhen_6 = valuewhen(pvtlo, low[pvtLenR ], 0)
higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
valuewhen_7 = valuewhen(pvtlo, low[pvtLenR], 1)
valuewhen_8 = valuewhen(pvtlo, low[pvtLenR ], 0)
lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na
 
 
// If selected Display the HH/LL above/below candle.
plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.triangledown, location=location.abovebar, color=color.green, text="HH", offset=-pvtLenR)
plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.triangleup, location=location.belowbar, color=color.green, text="HL", offset=-pvtLenR)
plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.triangledown, location=location.abovebar, color=color.red, text="LH", offset=-pvtLenR)
plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.triangleup, location=location.belowbar, color=color.red, text="LL", offset=-pvtLenR)
 
// If Selected Display Pivot points
//plotshape(ShowPivots and not ShowHHLL ? pvthi :na, title='High Pivot Marker', style=shape.triangleup,location=location.abovebar, color=green, offset=-pvtLenR-Shunt,transp=0,size=size.auto)
//plotshape(ShowPivots and not ShowHHLL ? pvtlo :na,  title='Low Pivot Marker', style=shape.triangledown, location=location.belowbar, color=maroon, offset=-pvtLenR-Shunt,transp=0,size=size.auto)
plot(ShowPivots and not ShowHHLL ? pvthi : na, title='High Pivot *', style=plot.style_circles, join=false, color=color.green, offset=-pvtLenR, linewidth=3)
plot(ShowPivots and not ShowHHLL ? pvtlo : na, title='Low Pivot *', style=plot.style_circles, join=false, color=color.red, offset=-pvtLenR, linewidth=3)
plot(ShowPivots and not ShowHHLL ? pvthi : na, title='High Pivot *', style=plot.style_circles, join=false, color=color.green, offset=-pvtLenR, linewidth=3)
plot(ShowPivots and not ShowHHLL ? pvtlo : na, title='Low Pivot *', style=plot.style_circles, join=false, color=color.red, offset=-pvtLenR, linewidth=3)
 
// Highlight Pivot Bar.
ORANGE = #FFA500FF
barcolor(clrPivot and (pvthi or pvtlo) ? ORANGE : na, title="Colour Pivot Bar", offset=-pvtLenR)
 
 
 
//Count How many candles for current Pivot Level, If new reset.
counthi = 0
countlo = 0
counthi := na(pvthi) ? nz(counthi[1]) + 1 : 0
countlo := na(pvtlo) ? nz(countlo[1]) + 1 : 0
 
pvthis = 0.0
pvtlos = 0.0
pvthis := na(pvthi) ? pvthis[1] : high[pvtLenR]
pvtlos := na(pvtlo) ? pvtlos[1] : low[pvtLenR]
 
hipc = pvthis != pvthis[1] ? na : color.red
lopc = pvtlos != pvtlos[1] ? na : color.green
 
// Show Levels if Selected
plot(ShowSRLevels and not ShowChannel and (maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, linewidth=1, offset=-pvtLenR , title="Top Levels",style=plot.style_circles)
plot(ShowSRLevels and not ShowChannel and (maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, linewidth=1, offset=-pvtLenR , title="Bottom Levels",style=plot.style_circles)
plot(ShowSRLevels and not ShowChannel and (maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, linewidth=1, offset=-pvtLenR, title="Top Levels 2")
plot(ShowSRLevels and not ShowChannel and (maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, linewidth=1, offset=-pvtLenR, title="Bottom Levels 2")
 
// Show Levels as a Fractal Chaos Channel
plot(ShowSRLevels and ShowChannel ? pvthis : na, color=color.green, linewidth=1, style=plot.style_stepline, offset=0, title="Top Chaos Channel", trackprice=false)
plot(ShowSRLevels and ShowChannel ? pvtlos : na, color=color.red, linewidth=1, style=plot.style_stepline, offset=0, title="Bottom Chaos Channel", trackprice=false)
 
// // Add Optional Fractal Break Alerts
buy = false
sell = false
buy  := close>pvthis and open<=pvthis 
sell := close<pvtlos and open>=pvtlos 
 
// //
plotshape(ShowFB and buy?1:na, title="BUY Arrow", color=color.green, style=shape.triangleup,location =location.belowbar)
plotshape(ShowFB and sell?-1:na, title="SELL Arrow", color=color.red, style=shape.triangledown,location =location.abovebar)
// //
// alertcondition(buy or sell,title="Fractal Break Arrow",message="Alert")
// alertcondition(buy,title="Fractal Break Long",message="Long")
// alertcondition(sell,title="Fractal Break Short",message="Short")
 
 
// //
// //EOF

← 返回列表