Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © HeWhoMustNotBeNamed
- //@version=5
- indicator('Donchian Channel - Pivot High-Low', overlay=true)
- pvtLen = input(3)
- waitforclose = input(true)
- ShowHHLL = input(true)
- DCBase = input.string(title='Channel Base', defval='Combined', options=['Price', 'Pivots', 'Combined'])
- DCLength = input(20)
- showChannel = input(true)
- donchian(highSource, lowSource, rangeLength) =>
- top = ta.highest(highSource, rangeLength)
- bottom = ta.lowest(lowSource, rangeLength)
- middle = (top + bottom) / 2
- [middle, top, bottom]
- f_calculatePivots(pvtLen, Shunt) =>
- pvthi_ = ta.pivothigh(high, pvtLen, pvtLen)
- pvtlo_ = ta.pivotlow(low, pvtLen, pvtLen)
- pvthi = pvthi_[Shunt]
- pvtlo = pvtlo_[Shunt]
- pvthighline = pvthi
- pvthighline := na(pvthighline) ? nz(pvthighline[1]) : pvthighline
- pvtlowline = pvtlo
- pvtlowline := na(pvtlowline) ? nz(pvtlowline[1]) : pvtlowline
- higherhigh = na(pvthi) ? na : ta.valuewhen(pvthi, high[pvtLen + Shunt], 1) < ta.valuewhen(pvthi, high[pvtLen + Shunt], 0) ? pvthi : na
- lowerhigh = na(pvthi) ? na : ta.valuewhen(pvthi, high[pvtLen + Shunt], 1) > ta.valuewhen(pvthi, high[pvtLen + Shunt], 0) ? pvthi : na
- higherlow = na(pvtlo) ? na : ta.valuewhen(pvtlo, low[pvtLen + Shunt], 1) < ta.valuewhen(pvtlo, low[pvtLen + Shunt], 0) ? pvtlo : na
- lowerlow = na(pvtlo) ? na : ta.valuewhen(pvtlo, low[pvtLen + Shunt], 1) > ta.valuewhen(pvtlo, low[pvtLen + Shunt], 0) ? pvtlo : na
- [pvthighline, pvtlowline, higherhigh, lowerhigh, higherlow, lowerlow]
- Shunt = waitforclose ? 1 : 0
- [pvthighline, pvtlowline, higherhigh, lowerhigh, higherlow, lowerlow] = f_calculatePivots(pvtLen, Shunt)
- [middleP, topP, bottomP] = donchian(pvthighline, pvtlowline, DCLength)
- [middleC, topC, bottomC] = donchian(high, low, DCLength)
- top = DCBase == 'Combined' ? math.max(topP, topC) : DCBase == 'Pivots' ? topP : topC
- bottom = DCBase == 'Combined' ? math.min(bottomP, bottomC) : DCBase == 'Pivots' ? bottomP : bottomC
- middle = DCBase == 'Combined' ? (middleP + middleC) / 2 : DCBase == 'Pivots' ? middleP : middleC
- //plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.triangleup, location=location.abovebar, color=color.green, text="HH", offset=-pvtLen-Shunt, transp=50)
- //plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.triangleup, location=location.belowbar, color=color.green, text="HL", offset=-pvtLen-Shunt, transp=0)
- //plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.triangledown, location=location.abovebar, color=color.maroon, text="LH", offset=-pvtLen-Shunt, transp=0)
- //plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.triangledown, location=location.belowbar, color=color.maroon, text="LL", offset=-pvtLen-Shunt, transp=50)
- BBup = plot(showChannel ? top : na, title='Top', color=color.new(color.red, 50), linewidth=1, style=plot.style_linebr)
- BBdown = plot(showChannel ? bottom : na, title='Bottom', color=color.new(color.green, 50), linewidth=1, style=plot.style_linebr)
- BBmid = plot(showChannel ? middle : na, title='Middle', color=color.new(color.blue, 50), linewidth=1, style=plot.style_linebr)
- fill(BBup, BBmid, title='High Zone', color=color.new(color.green, 90))
- fill(BBdown, BBmid, title='Low Zone', color=color.new(color.red, 90))
- //end of this part
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © lockeyj
- // Inspired by LoneCapital
- //study("Tricolor color GMMA", overlay=true)
- // SMA
- sma12 = ta.ema(close, 12)
- sma16 = ta.ema(close, 16)
- sma20 = ta.ema(close, 20)
- sma24 = ta.ema(close, 24)
- sma28 = ta.ema(close, 28)
- sma32 = ta.ema(close, 32)
- sma36 = ta.ema(close, 36)
- sma40 = ta.ema(close, 40)
- sma44 = ta.ema(close, 44)
- sma48 = ta.ema(close, 48)
- sma52 = ta.ema(close, 52)
- sma56 = ta.ema(close, 56)
- sma60 = ta.ema(close, 60)
- sma64 = ta.ema(close, 64)
- sma68 = ta.ema(close, 68)
- sma72 = ta.ema(close, 72)
- sma76 = ta.ema(close, 76)
- sma80 = ta.ema(close, 80)
- sma84 = ta.ema(close, 84)
- sma88 = ta.ema(close, 88)
- sma92 = ta.ema(close, 92)
- sma96 = ta.ema(close, 96)
- sma100 = ta.ema(close, 100)
- sma104 = ta.ema(close, 104)
- sma108 = ta.ema(close, 108)
- sma112 = ta.ema(close, 112)
- sma116 = ta.ema(close, 116)
- sma120 = ta.ema(close, 120)
- // Bullish and bearish patterns
- bullish = sma20 > sma60 and sma60 > sma120
- bearish = sma20 < sma60 and sma60 < sma120
- color = bullish ? #008EFF : bearish ? #FF0000 : #D3D3D3
- // Slope
- slope(_src) =>
- rad2Degree = 2 / 3.1416 //pi
- angle = rad2Degree * math.atan((math.log(_src[0]) - math.log(_src[20])) / math.log(20))
- angle
- x = (sma20 + sma60 + sma120) / 3
- smaSlop = slope(x)
- // Clock position and pi
- oClock12 = 1.00 // sin(3.1416/2)
- oClock1 = 0.87 // sin(3.1416/3)
- oClock2 = 0.50 // sin(3.1416/6)
- oClock3 = 0.00 // 0
- oClock4 = -0.50 // sin(11*3.1416/6)
- oClock5 = -0.87 // sin(5*3.1416/3)
- oClock6 = -1.00 // sin(3*3.1416/2)
- // Plot clock position
- plotchar(smaSlop > oClock1 and smaSlop <= oClock12 and barstate.islast ? true : na, text='12–1 o\'clock (Avoid trading)', color=color.new(color.red, 0), offset=0, location=location.abovebar, size=size.tiny)
- plotchar(smaSlop > oClock2 and smaSlop <= oClock1 and barstate.islast ? true : na, text='1–2 o\'clock (Enter trading)', color=color.new(color.red, 0), offset=0, location=location.abovebar, size=size.tiny)
- plotchar(smaSlop > oClock3 and smaSlop <= oClock2 and barstate.islast ? true : na, text='2–3 o\'clock (Enter trading)', color=color.new(color.red, 0), offset=0, location=location.abovebar, size=size.tiny)
- plotchar(smaSlop > oClock4 and smaSlop <= oClock3 and barstate.islast ? true : na, text='3–4 o\'clock (Wait for trading)', color=color.new(color.red, 0), offset=0, location=location.abovebar, size=size.tiny)
- plotchar(smaSlop > oClock5 and smaSlop <= oClock4 and barstate.islast ? true : na, text='4–5 o\'clock (No trading)', color=color.new(color.red, 0), offset=0, location=location.abovebar, size=size.tiny)
- plotchar(smaSlop > oClock6 and smaSlop <= oClock5 and barstate.islast ? true : na, text='5–6 o\'clock (Wait for reversal)', color=color.new(color.red, 0), offset=0, location=location.abovebar, size=size.tiny)
- // Plot SMA
- plot(sma12, color=color)
- plot(sma16, color=color)
- plot(sma20, color=color)
- plot(sma24, color=color)
- plot(sma28, color=color)
- plot(sma32, color=color)
- plot(sma36, color=color)
- plot(sma40, color=color)
- plot(sma44, color=color)
- plot(sma48, color=color)
- plot(sma52, color=color)
- plot(sma56, color=color)
- plot(sma60, color=color)
- plot(sma64, color=color)
- plot(sma68, color=color)
- plot(sma72, color=color)
- plot(sma76, color=color)
- plot(sma80, color=color)
- //plot(sma84, color=color)
- plot(sma88, color=color)
- plot(sma92, color=color)
- plot(sma96, color=color)
- plot(sma100, color=color)
- plot(sma104, color=color)
- plot(sma108, color=color)
- plot(sma112, color=color)
- plot(sma116, color=color)
- plot(sma120, color=color)
Advertisement
Add Comment
Please, Sign In to add comment