xmd79

ICT Donchian Smart Money Structure

May 22nd, 2023
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  2. // © Zeiierman
  3.  
  4. //@version=5
  5. indicator("ICT Donchian Smart Money Structure",overlay=true,max_bars_back=5000,max_labels_count=500,max_lines_count=500)
  6.  
  7. // ~~ Tooltips {
  8. string t1 = "Set the pivot period"
  9. string t2 = "Set the response period. A low value returns a short-term structure and a high value returns a long-term structure. If you disable this option the pivot length above will be used."
  10. string t3 = "Enable the Donchian Channel."
  11. string t4 = "A high value returns the long-term structure and a low value returns the short-term structure."
  12. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  13.  
  14. // ~~ Inputs {
  15. prd = input.int(20,minval=1,title="Structure Period",tooltip=t1)
  16. s1 = input.bool(true,title="Structure Response  ", inline="resp")
  17. resp = input.int(7,minval=1,title="",inline="resp",tooltip=t2)
  18. bull = input.bool(true,"Bullish Structure     ",inline="Bullish"), bull2 = input.color(color.rgb(8, 236, 126),"",inline="Bullish"), bull3 = input.color(color.rgb(8, 236, 126),"",inline="Bullish")
  19. bear = input.bool(true,"Bearish Structure    ",inline="Bearish"), bear2 = input.color(color.rgb(255, 34, 34),"",inline="Bearish"), bear3 = input.color(color.rgb(255, 34, 34),"",inline="Bearish")
  20. showPD = input.bool(true,"Premium & Discount",inline="pd"), prem = input.color(color.new(color.rgb(255, 34, 34),80),"",inline="pd"), disc = input.color(color.new(color.rgb(8, 236, 126),80),"",inline="pd")
  21. don = input.bool(false,"Donchian Channel", tooltip=t3)
  22. Candle = input.bool(true, "Structure Candles", inline="", group="Structure Candles")
  23. length = input.int(40, minval=1,title="Structure Response", inline="", group="Structure Candles", tooltip=t4)
  24. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  25.  
  26. // ~~ Variables {
  27. b = bar_index
  28. var Up = float(na)
  29. var Dn = float(na)
  30. var iUp = int(na)
  31. var iDn = int(na)
  32. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  33.  
  34. // ~~ Functions {
  35. //Labels
  36. CreateLabel(x,y,txt,col,z)=>
  37. label.new(x,y,txt,textcolor=col,style=z?label.style_label_down:label.style_label_up,color=color(na))
  38. //Lines
  39. CreateLine(x1,x2,y,col)=>
  40. line.new(x1,x2,b,y,color=col)
  41. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  42.  
  43. // ~~ Pivots {
  44. Up := math.max(Up[1],high)
  45. Dn := math.min(Dn[1],low)
  46. pvtHi = ta.pivothigh(high,prd,prd)
  47. pvtLo = ta.pivotlow(low,prd,prd)
  48. if pvtHi
  49. Up := pvtHi
  50. if pvtLo
  51. Dn := pvtLo
  52. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  53.  
  54. // ~~ Structure {
  55. var pos = 0
  56. if Up>Up[1]
  57. iUp := b
  58. centerBull = math.round(math.avg(iUp[1],b))
  59. if pos<=0
  60. if bull
  61. CreateLabel(centerBull,Up[1],"CHoCH",bull3,true)
  62. CreateLine(iUp[1],Up[1],Up[1],bull2)
  63. pos := 1
  64. else if pos==1 and Up>Up[1] and Up[1]==Up[s1?resp:prd]
  65. if bull
  66. CreateLabel(centerBull,Up[1],"SMS",bull3,true)
  67. CreateLine(iUp[1],Up[1],Up[1],bull2)
  68. pos := 2
  69. else if pos>1 and Up>Up[1] and Up[1]==Up[s1?resp:prd]
  70. if bull
  71. CreateLabel(centerBull,Up[1],"BMS",bull3,true)
  72. CreateLine(iUp[1],Up[1],Up[1],bull2)
  73. pos := pos + 1
  74. else if Up<Up[1]
  75. iUp := b-prd
  76. if Dn<Dn[1]
  77. iDn := b
  78. centerBear = math.round(math.avg(iDn[1],b))
  79. if pos>=0
  80. if bear
  81. CreateLabel(centerBear,Dn[1],"CHoCH",bear3,false)
  82. CreateLine(iDn[1],Dn[1],Dn[1],bear2)
  83. pos := -1
  84. else if pos==-1 and Dn<Dn[1] and Dn[1]==Dn[s1?resp:prd]
  85. if bear
  86. CreateLabel(centerBear,Dn[1],"SMS",bear3,false)
  87. CreateLine(iDn[1],Dn[1],Dn[1],bear2)
  88. pos := -2
  89. else if pos<-1 and Dn<Dn[1] and Dn[1]==Dn[s1?resp:prd]
  90. if bear
  91. CreateLabel(centerBear,Dn[1],"BMS",bear3,false)
  92. CreateLine(iDn[1],Dn[1],Dn[1],bear2)
  93. pos := pos - 1
  94. else if Dn>Dn[1]
  95. iDn := b-prd
  96. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  97.  
  98. // ~~ Premium & Discount {
  99. PremiumTop = Up-(Up-Dn)*.1
  100. PremiumBot = Up-(Up-Dn)*.25
  101. DiscountTop = Dn+(Up-Dn)*.25
  102. DiscountBot = Dn+(Up-Dn)*.1
  103. MidTop = Up-(Up-Dn)*.45
  104. MidBot = Dn+(Up-Dn)*.45
  105. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  106.  
  107. // ~~ Plots {
  108. r1 = plot(don?Up:na,"Range High",bear2)
  109. r2 = plot(don?Dn:na,"Range Low",bull2)
  110. p1 = plot(showPD?PremiumTop:na,"Premium",na)
  111. p2 = plot(showPD?PremiumBot:na,"Premium",na)
  112. d1 = plot(showPD?DiscountTop:na,"Discount",na)
  113. d2 = plot(showPD?DiscountBot:na,"Discount",na)
  114. m1 = plot(showPD?MidTop:na,"Equilibrium",na)
  115. m2 = plot(showPD?MidBot:na,"Equilibrium",na)
  116.  
  117. fill(p1,p2,color=prem)
  118. fill(d1,d2,color=disc)
  119. fill(m1,m2,color=color.new(color.gray,75))
  120. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  121.  
  122. DonCandles(high_, low_, close_,src_,factor_,candle_,length_)=>
  123. initial = 0.0
  124. Don_High = ta.highest(high_,length_)
  125. Don_Low = ta.lowest(low_,length_)
  126. Norm = ((close_ - Don_Low) / (Don_High - Don_Low))
  127. initial := candle_?(Norm * close + ((1 - Norm)) * nz(initial[1], close)): (Norm * close + ((1 - Norm*2)) * nz(initial[1], close))
  128. Factor = candle_?(1-Norm)* nz(initial[1], src_) :(factor_? (1-Norm*2):(1-Norm/2)) * nz(initial[1], src_)
  129. output = (Norm * src_) + Factor
  130.  
  131. // Return Trend Candles
  132. O = Candle?DonCandles(Up,Dn,close,open,true,false,length):na
  133. H = Candle?DonCandles(Up,Dn,close,high,false,false,length):na
  134. L = Candle?DonCandles(Up,Dn,close,low,false,false,length):na
  135. C = Candle?DonCandles(Up,Dn,close,close,true,false,length):na
  136.  
  137. // Return Color Sign
  138. pricewick(h_,a)=>
  139. cond = h_>a
  140. cond
  141. cond_open = pricewick(H,open)
  142. cond_high = pricewick(H,high)
  143. cond_low = pricewick(H,low)
  144. cond_close = pricewick(H,close)
  145. sign = (cond_open or cond_high or cond_low or cond_close)?color.lime:color.red
  146.  
  147. // Plot Structure Candles
  148. plotcandle(open, high,low,close, color=Candle?sign:na,bordercolor=Candle?sign:na, wickcolor=Candle?sign:na, title="Structure Candles")
  149.  
Advertisement
Add Comment
Please, Sign In to add comment