xmd79

Premium / Discount Zone [Mir Nader]

Jan 2nd, 2023
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 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. // © MirNader
  3.  
  4. //@version=5
  5. indicator("Premium / Discount Zone [Mir Nader]", "Premium / Discount Zone] [Mir Nader]", overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500, max_bars_back = 500)
  6.  
  7. //Constants
  8. //-----------------------------------------------------------------------------{
  9. color TRANSP_CSS = #ffffff00
  10.  
  11. //Premium/Discount zones
  12. show_pre_dis = input(true, 'Premium/Discount Zones', group = 'Premium & Discount Zones', tooltip = 'Display premium, discount, and equilibrium zones on chart')
  13. premium_color = input.color(#f23645, 'Premium Zone', group = 'Premium & Discount Zones' , inline = '01')
  14. // eq_css = input.color(#b2b5be, 'Equilibrium Zone', group = 'Premium & Discount Zones')
  15. discount_css = input.color(#089981, 'Discount Zone', group = 'Premium & Discount Zones', inline = '01')
  16. show_hl_swings = input(true, title ='Show Strong/Weak High/Low', group = 'Real Time Swing Structure', tooltip = 'Highlight most recent strong and weak high/low points on the chart')
  17. length_swing = input.int(20, 'Minimum Swing Structure Candle', minval = 5, inline = 'swings', group = 'Real Time Swing Structure')
  18. Low_color_label = input.color(color.black , "Low Label Text Color" , group = 'Real Time Swing Structure', inline = '01')
  19. High_color_label = input.color(color.black , "High Label Text Color" , group = 'Real Time Swing Structure', inline = '01')
  20. label_color = input.color(color.rgb(184, 184, 184, 80) ,"Label Box Color", group = 'Real Time Swing Structure' )
  21. line_st = input.string(defval = "Solid (⎯⎯⎯)" , title = "Line Style" ,options = ["Solid (⎯⎯⎯)" ,"Dashed (----)" , "Doted (····)"] , group = 'Real Time Swing Structure', tooltip = " Added Soon")
  22.  
  23. //Functions
  24. atr = ta.atr(200)
  25. var line extend_top = na
  26.  
  27. swings(len)=>
  28. var os = 0
  29. upper = ta.highest(len)
  30. lower = ta.lowest(len)
  31. os := high[len] > upper ? 0 : low[len] < lower ? 1 : os[1]
  32. top = os == 0 and os[1] != 0 ? high[len] : 0
  33. btm = os == 1 and os[1] != 1 ? low[len] : 0
  34. [top, btm]
  35. //Line Style function
  36. get_line_styles(styles) =>
  37. switch styles
  38. "Solid (⎯⎯⎯) " => line.style_solid
  39. "Dashed (----) " => line.style_dashed
  40. "Doted (····) " => line.style_dotted
  41.  
  42. //Global variables
  43. var trend = 0, var itrend = 0
  44. var top_y = 0., var top_x = 0
  45. var btm_y = 0., var btm_x = 0
  46. var itop_y = 0., var itop_x = 0
  47. var ibtm_y = 0., var ibtm_x = 0
  48. var trail_up = high, var trail_dn = low
  49. var trail_up_x = 0, var trail_dn_x = 0
  50. var top_cross = true, var btm_cross = true
  51. var itop_cross = true, var ibtm_cross = true
  52. var txt_top = '', var txt_btm = ''
  53.  
  54. //Swings
  55. [top, btm] = swings(length_swing)
  56. [itop, ibtm] = swings(5)
  57. //Pivot High
  58. var label extend_top_lbl = label.new(na, na, color = label_color , textcolor = Low_color_label, style = label.style_label_left, size = size.tiny)
  59. if top
  60. top_cross := true
  61. //Extend recent top to last bar
  62. line.delete(extend_top[1])
  63. extend_top := line.new(bar_index-length_swing, top, bar_index-length_swing, top, color = Low_color_label , width = 1 )
  64. top_y := top
  65. top_x := bar_index - length_swing
  66. trail_up := top
  67. trail_up_x := bar_index - length_swing
  68. if itop
  69. itop_cross := true
  70. itop_y := itop
  71. itop_x := bar_index - 5
  72. //Trailing maximum
  73. trail_up := math.max(high, trail_up)
  74. trail_up_x := trail_up == high ? bar_index : trail_up_x
  75. //Set top extension label/line
  76. if barstate.islast and show_hl_swings
  77. line.set_xy1(extend_top, trail_up_x, trail_up)
  78. line.set_xy2(extend_top, bar_index + 20, trail_up)
  79. // line.set_style(extend_top , style = session_line_style)
  80. label.set_x(extend_top_lbl, bar_index + 21)
  81. label.set_y(extend_top_lbl, trail_up)
  82. label.set_text(extend_top_lbl, trend < 0 ? 'Strong High' : 'Weak High')
  83. //Pivot Low
  84. var line extend_btm = na
  85. var label extend_btm_lbl = label.new(na, na, color = label_color, textcolor = High_color_label, style = label.style_label_left, size = size.tiny)
  86. if btm
  87. btm_cross := true
  88. //Extend recent btm to last bar
  89. line.delete(extend_btm[1])
  90. extend_btm := line.new(bar_index - length_swing, btm, bar_index - length_swing, btm, color = High_color_label)
  91. btm_y := btm
  92. btm_x := bar_index-length_swing
  93. trail_dn := btm
  94. trail_dn_x := bar_index-length_swing
  95. if ibtm
  96. ibtm_cross := true
  97. ibtm_y := ibtm
  98. ibtm_x := bar_index - 5
  99. //Trailing minimum
  100. trail_dn := math.min(low, trail_dn)
  101. trail_dn_x := trail_dn == low ? bar_index : trail_dn_x
  102. //Set btm extension label/line
  103. if barstate.islast and show_hl_swings
  104. line.set_xy1(extend_btm, trail_dn_x, trail_dn)
  105. line.set_xy2(extend_btm, bar_index + 20, trail_dn)
  106.  
  107. label.set_x(extend_btm_lbl, bar_index + 21)
  108. label.set_y(extend_btm_lbl, trail_dn)
  109. label.set_text(extend_btm_lbl, trend > 0 ? 'Strong Low' : 'Weak Low')
  110. //Pivot High BOS/CHoCH
  111. var bull_concordant = true
  112. bull_concordant := high - math.max(close, open) > math.min(close, open - low)
  113. if ta.crossover(close, itop_y) and itop_cross and top_y != itop_y and bull_concordant
  114. itrend := 1
  115. if ta.crossover(close, top_y) and top_cross
  116. trend := 1
  117. //Pivot Low BOS/CHoCH
  118. var bear_concordant = true
  119. bear_concordant := high - math.max(close, open) < math.min(close, open - low)
  120. if ta.crossunder(close, ibtm_y) and ibtm_cross and btm_y != ibtm_y and bear_concordant
  121. itrend := -1
  122. if ta.crossunder(close, btm_y) and btm_cross
  123. trend := -1
  124. //P/D/E Function
  125. var premium = box.new(na, na, na, na, bgcolor = color.new(premium_color, 80), border_color = na)
  126. var premium_lbl = label.new(na, na, text = 'Premium Zone', color = TRANSP_CSS, textcolor = premium_color, style = label.style_label_down, size = size.small)
  127. // var eq = box.new(na, na, na, na, bgcolor = color.rgb(120, 123, 134, 100), border_color = na)
  128. // var eq_lbl = label.new(na, na, text = 'Equilibrium', color = TRANSP_CSS, textcolor = eq_css, style = label.style_label_left, size = size.small)
  129. var discount = box.new(na, na, na, na, bgcolor = color.new(discount_css, 80), border_color = na)
  130. var discount_lbl = label.new(na, na, text = 'Discount Zone', color = TRANSP_CSS, textcolor = discount_css, style = label.style_label_up, size = size.small)
  131. //Premium/Discount Zone
  132. if barstate.islast and show_pre_dis
  133. avg = math.avg(trail_up, trail_dn)
  134.  
  135. box.set_lefttop(premium, math.max(top_x, btm_x), trail_up)
  136. box.set_rightbottom(premium, bar_index + 10, .95 * trail_up + .05 * trail_dn)
  137.  
  138. label.set_xy(premium_lbl, int(math.avg(math.max(top_x, btm_x), bar_index)), trail_up)
  139.  
  140. // box.set_lefttop(eq, math.max(top_x, btm_x), .525 * trail_up + .475*trail_dn)
  141. // box.set_rightbottom(eq, bar_index, .525 * trail_dn + .475 * trail_up)
  142.  
  143. // label.set_xy(eq_lbl, bar_index, avg)
  144.  
  145. box.set_lefttop(discount, math.max(top_x, btm_x), .95 * trail_dn + .05 * trail_up)
  146. box.set_rightbottom(discount, bar_index + 10, trail_dn)
  147. label.set_xy(discount_lbl, int(math.avg(math.max(top_x, btm_x), bar_index)), trail_dn)
  148.  
  149. //End Code
  150.  
Advertisement
Add Comment
Please, Sign In to add comment