xmd79

Donchian Channel - Pivot High-Low'

Dec 15th, 2022
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © HeWhoMustNotBeNamed
  3.  
  4. //@version=5
  5. indicator('Donchian Channel - Pivot High-Low', overlay=true)
  6. pvtLen = input(3)
  7. waitforclose = input(true)
  8. ShowHHLL = input(true)
  9. DCBase = input.string(title='Channel Base', defval='Combined', options=['Price', 'Pivots', 'Combined'])
  10. DCLength = input(20)
  11. showChannel = input(true)
  12. donchian(highSource, lowSource, rangeLength) =>
  13. top = ta.highest(highSource, rangeLength)
  14. bottom = ta.lowest(lowSource, rangeLength)
  15. middle = (top + bottom) / 2
  16. [middle, top, bottom]
  17.  
  18. f_calculatePivots(pvtLen, Shunt) =>
  19. pvthi_ = ta.pivothigh(high, pvtLen, pvtLen)
  20. pvtlo_ = ta.pivotlow(low, pvtLen, pvtLen)
  21.  
  22. pvthi = pvthi_[Shunt]
  23. pvtlo = pvtlo_[Shunt]
  24.  
  25. pvthighline = pvthi
  26. pvthighline := na(pvthighline) ? nz(pvthighline[1]) : pvthighline
  27.  
  28. pvtlowline = pvtlo
  29. pvtlowline := na(pvtlowline) ? nz(pvtlowline[1]) : pvtlowline
  30.  
  31. higherhigh = na(pvthi) ? na : ta.valuewhen(pvthi, high[pvtLen + Shunt], 1) < ta.valuewhen(pvthi, high[pvtLen + Shunt], 0) ? pvthi : na
  32. lowerhigh = na(pvthi) ? na : ta.valuewhen(pvthi, high[pvtLen + Shunt], 1) > ta.valuewhen(pvthi, high[pvtLen + Shunt], 0) ? pvthi : na
  33. higherlow = na(pvtlo) ? na : ta.valuewhen(pvtlo, low[pvtLen + Shunt], 1) < ta.valuewhen(pvtlo, low[pvtLen + Shunt], 0) ? pvtlo : na
  34. lowerlow = na(pvtlo) ? na : ta.valuewhen(pvtlo, low[pvtLen + Shunt], 1) > ta.valuewhen(pvtlo, low[pvtLen + Shunt], 0) ? pvtlo : na
  35.  
  36. [pvthighline, pvtlowline, higherhigh, lowerhigh, higherlow, lowerlow]
  37.  
  38. Shunt = waitforclose ? 1 : 0
  39. [pvthighline, pvtlowline, higherhigh, lowerhigh, higherlow, lowerlow] = f_calculatePivots(pvtLen, Shunt)
  40.  
  41. [middleP, topP, bottomP] = donchian(pvthighline, pvtlowline, DCLength)
  42. [middleC, topC, bottomC] = donchian(high, low, DCLength)
  43.  
  44.  
  45. top = DCBase == 'Combined' ? math.max(topP, topC) : DCBase == 'Pivots' ? topP : topC
  46. bottom = DCBase == 'Combined' ? math.min(bottomP, bottomC) : DCBase == 'Pivots' ? bottomP : bottomC
  47. middle = DCBase == 'Combined' ? (middleP + middleC) / 2 : DCBase == 'Pivots' ? middleP : middleC
  48.  
  49. //plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.triangleup, location=location.abovebar, color=color.green, text="HH", offset=-pvtLen-Shunt, transp=50)
  50. //plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.triangleup, location=location.belowbar, color=color.green, text="HL", offset=-pvtLen-Shunt, transp=0)
  51. //plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.triangledown, location=location.abovebar, color=color.maroon, text="LH", offset=-pvtLen-Shunt, transp=0)
  52. //plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.triangledown, location=location.belowbar, color=color.maroon, text="LL", offset=-pvtLen-Shunt, transp=50)
  53.  
  54. BBup = plot(showChannel ? top : na, title='Top', color=color.new(color.red, 50), linewidth=1, style=plot.style_linebr)
  55. BBdown = plot(showChannel ? bottom : na, title='Bottom', color=color.new(color.green, 50), linewidth=1, style=plot.style_linebr)
  56. BBmid = plot(showChannel ? middle : na, title='Middle', color=color.new(color.blue, 50), linewidth=1, style=plot.style_linebr)
  57. fill(BBup, BBmid, title='High Zone', color=color.new(color.green, 90))
  58. fill(BBdown, BBmid, title='Low Zone', color=color.new(color.red, 90))
  59.  
  60. //end of this part
  61.  
  62. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  63. // © lockeyj
  64.  
  65. // Inspired by LoneCapital
  66.  
  67. //study("Tricolor color GMMA", overlay=true)
  68.  
  69. // SMA
  70. sma12 = ta.ema(close, 12)
  71. sma16 = ta.ema(close, 16)
  72. sma20 = ta.ema(close, 20)
  73. sma24 = ta.ema(close, 24)
  74. sma28 = ta.ema(close, 28)
  75. sma32 = ta.ema(close, 32)
  76. sma36 = ta.ema(close, 36)
  77. sma40 = ta.ema(close, 40)
  78. sma44 = ta.ema(close, 44)
  79. sma48 = ta.ema(close, 48)
  80. sma52 = ta.ema(close, 52)
  81. sma56 = ta.ema(close, 56)
  82. sma60 = ta.ema(close, 60)
  83. sma64 = ta.ema(close, 64)
  84. sma68 = ta.ema(close, 68)
  85. sma72 = ta.ema(close, 72)
  86. sma76 = ta.ema(close, 76)
  87. sma80 = ta.ema(close, 80)
  88. sma84 = ta.ema(close, 84)
  89. sma88 = ta.ema(close, 88)
  90. sma92 = ta.ema(close, 92)
  91. sma96 = ta.ema(close, 96)
  92. sma100 = ta.ema(close, 100)
  93. sma104 = ta.ema(close, 104)
  94. sma108 = ta.ema(close, 108)
  95. sma112 = ta.ema(close, 112)
  96. sma116 = ta.ema(close, 116)
  97. sma120 = ta.ema(close, 120)
  98.  
  99. // Bullish and bearish patterns
  100. bullish = sma20 > sma60 and sma60 > sma120
  101. bearish = sma20 < sma60 and sma60 < sma120
  102. color = bullish ? #008EFF : bearish ? #FF0000 : #D3D3D3
  103.  
  104. // Slope
  105. slope(_src) =>
  106. rad2Degree = 2 / 3.1416 //pi
  107. angle = rad2Degree * math.atan((math.log(_src[0]) - math.log(_src[20])) / math.log(20))
  108. angle
  109. x = (sma20 + sma60 + sma120) / 3
  110. smaSlop = slope(x)
  111.  
  112. // Clock position and pi
  113. oClock12 = 1.00 // sin(3.1416/2)
  114. oClock1 = 0.87 // sin(3.1416/3)
  115. oClock2 = 0.50 // sin(3.1416/6)
  116. oClock3 = 0.00 // 0
  117. oClock4 = -0.50 // sin(11*3.1416/6)
  118. oClock5 = -0.87 // sin(5*3.1416/3)
  119. oClock6 = -1.00 // sin(3*3.1416/2)
  120.  
  121. // Plot clock position
  122. 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)
  123. 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)
  124. 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)
  125. 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)
  126. 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)
  127. 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)
  128.  
  129. // Plot SMA
  130. plot(sma12, color=color)
  131. plot(sma16, color=color)
  132. plot(sma20, color=color)
  133. plot(sma24, color=color)
  134. plot(sma28, color=color)
  135. plot(sma32, color=color)
  136. plot(sma36, color=color)
  137. plot(sma40, color=color)
  138. plot(sma44, color=color)
  139. plot(sma48, color=color)
  140. plot(sma52, color=color)
  141. plot(sma56, color=color)
  142. plot(sma60, color=color)
  143. plot(sma64, color=color)
  144. plot(sma68, color=color)
  145. plot(sma72, color=color)
  146. plot(sma76, color=color)
  147. plot(sma80, color=color)
  148. //plot(sma84, color=color)
  149. plot(sma88, color=color)
  150. plot(sma92, color=color)
  151. plot(sma96, color=color)
  152. plot(sma100, color=color)
  153. plot(sma104, color=color)
  154. plot(sma108, color=color)
  155. plot(sma112, color=color)
  156. plot(sma116, color=color)
  157. plot(sma120, color=color)
  158.  
  159.  
Advertisement
Add Comment
Please, Sign In to add comment