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/
- // © MirNader
- //@version=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)
- //Constants
- //-----------------------------------------------------------------------------{
- color TRANSP_CSS = #ffffff00
- //Premium/Discount zones
- show_pre_dis = input(true, 'Premium/Discount Zones', group = 'Premium & Discount Zones', tooltip = 'Display premium, discount, and equilibrium zones on chart')
- premium_color = input.color(#f23645, 'Premium Zone', group = 'Premium & Discount Zones' , inline = '01')
- // eq_css = input.color(#b2b5be, 'Equilibrium Zone', group = 'Premium & Discount Zones')
- discount_css = input.color(#089981, 'Discount Zone', group = 'Premium & Discount Zones', inline = '01')
- 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')
- length_swing = input.int(20, 'Minimum Swing Structure Candle', minval = 5, inline = 'swings', group = 'Real Time Swing Structure')
- Low_color_label = input.color(color.black , "Low Label Text Color" , group = 'Real Time Swing Structure', inline = '01')
- High_color_label = input.color(color.black , "High Label Text Color" , group = 'Real Time Swing Structure', inline = '01')
- label_color = input.color(color.rgb(184, 184, 184, 80) ,"Label Box Color", group = 'Real Time Swing Structure' )
- line_st = input.string(defval = "Solid (⎯⎯⎯)" , title = "Line Style" ,options = ["Solid (⎯⎯⎯)" ,"Dashed (----)" , "Doted (····)"] , group = 'Real Time Swing Structure', tooltip = " Added Soon")
- //Functions
- atr = ta.atr(200)
- var line extend_top = na
- swings(len)=>
- var os = 0
- upper = ta.highest(len)
- lower = ta.lowest(len)
- os := high[len] > upper ? 0 : low[len] < lower ? 1 : os[1]
- top = os == 0 and os[1] != 0 ? high[len] : 0
- btm = os == 1 and os[1] != 1 ? low[len] : 0
- [top, btm]
- //Line Style function
- get_line_styles(styles) =>
- switch styles
- "Solid (⎯⎯⎯) " => line.style_solid
- "Dashed (----) " => line.style_dashed
- "Doted (····) " => line.style_dotted
- //Global variables
- var trend = 0, var itrend = 0
- var top_y = 0., var top_x = 0
- var btm_y = 0., var btm_x = 0
- var itop_y = 0., var itop_x = 0
- var ibtm_y = 0., var ibtm_x = 0
- var trail_up = high, var trail_dn = low
- var trail_up_x = 0, var trail_dn_x = 0
- var top_cross = true, var btm_cross = true
- var itop_cross = true, var ibtm_cross = true
- var txt_top = '', var txt_btm = ''
- //Swings
- [top, btm] = swings(length_swing)
- [itop, ibtm] = swings(5)
- //Pivot High
- var label extend_top_lbl = label.new(na, na, color = label_color , textcolor = Low_color_label, style = label.style_label_left, size = size.tiny)
- if top
- top_cross := true
- //Extend recent top to last bar
- line.delete(extend_top[1])
- extend_top := line.new(bar_index-length_swing, top, bar_index-length_swing, top, color = Low_color_label , width = 1 )
- top_y := top
- top_x := bar_index - length_swing
- trail_up := top
- trail_up_x := bar_index - length_swing
- if itop
- itop_cross := true
- itop_y := itop
- itop_x := bar_index - 5
- //Trailing maximum
- trail_up := math.max(high, trail_up)
- trail_up_x := trail_up == high ? bar_index : trail_up_x
- //Set top extension label/line
- if barstate.islast and show_hl_swings
- line.set_xy1(extend_top, trail_up_x, trail_up)
- line.set_xy2(extend_top, bar_index + 20, trail_up)
- // line.set_style(extend_top , style = session_line_style)
- label.set_x(extend_top_lbl, bar_index + 21)
- label.set_y(extend_top_lbl, trail_up)
- label.set_text(extend_top_lbl, trend < 0 ? 'Strong High' : 'Weak High')
- //Pivot Low
- var line extend_btm = na
- var label extend_btm_lbl = label.new(na, na, color = label_color, textcolor = High_color_label, style = label.style_label_left, size = size.tiny)
- if btm
- btm_cross := true
- //Extend recent btm to last bar
- line.delete(extend_btm[1])
- extend_btm := line.new(bar_index - length_swing, btm, bar_index - length_swing, btm, color = High_color_label)
- btm_y := btm
- btm_x := bar_index-length_swing
- trail_dn := btm
- trail_dn_x := bar_index-length_swing
- if ibtm
- ibtm_cross := true
- ibtm_y := ibtm
- ibtm_x := bar_index - 5
- //Trailing minimum
- trail_dn := math.min(low, trail_dn)
- trail_dn_x := trail_dn == low ? bar_index : trail_dn_x
- //Set btm extension label/line
- if barstate.islast and show_hl_swings
- line.set_xy1(extend_btm, trail_dn_x, trail_dn)
- line.set_xy2(extend_btm, bar_index + 20, trail_dn)
- label.set_x(extend_btm_lbl, bar_index + 21)
- label.set_y(extend_btm_lbl, trail_dn)
- label.set_text(extend_btm_lbl, trend > 0 ? 'Strong Low' : 'Weak Low')
- //Pivot High BOS/CHoCH
- var bull_concordant = true
- bull_concordant := high - math.max(close, open) > math.min(close, open - low)
- if ta.crossover(close, itop_y) and itop_cross and top_y != itop_y and bull_concordant
- itrend := 1
- if ta.crossover(close, top_y) and top_cross
- trend := 1
- //Pivot Low BOS/CHoCH
- var bear_concordant = true
- bear_concordant := high - math.max(close, open) < math.min(close, open - low)
- if ta.crossunder(close, ibtm_y) and ibtm_cross and btm_y != ibtm_y and bear_concordant
- itrend := -1
- if ta.crossunder(close, btm_y) and btm_cross
- trend := -1
- //P/D/E Function
- var premium = box.new(na, na, na, na, bgcolor = color.new(premium_color, 80), border_color = na)
- var premium_lbl = label.new(na, na, text = 'Premium Zone', color = TRANSP_CSS, textcolor = premium_color, style = label.style_label_down, size = size.small)
- // var eq = box.new(na, na, na, na, bgcolor = color.rgb(120, 123, 134, 100), border_color = na)
- // var eq_lbl = label.new(na, na, text = 'Equilibrium', color = TRANSP_CSS, textcolor = eq_css, style = label.style_label_left, size = size.small)
- var discount = box.new(na, na, na, na, bgcolor = color.new(discount_css, 80), border_color = na)
- var discount_lbl = label.new(na, na, text = 'Discount Zone', color = TRANSP_CSS, textcolor = discount_css, style = label.style_label_up, size = size.small)
- //Premium/Discount Zone
- if barstate.islast and show_pre_dis
- avg = math.avg(trail_up, trail_dn)
- box.set_lefttop(premium, math.max(top_x, btm_x), trail_up)
- box.set_rightbottom(premium, bar_index + 10, .95 * trail_up + .05 * trail_dn)
- label.set_xy(premium_lbl, int(math.avg(math.max(top_x, btm_x), bar_index)), trail_up)
- // box.set_lefttop(eq, math.max(top_x, btm_x), .525 * trail_up + .475*trail_dn)
- // box.set_rightbottom(eq, bar_index, .525 * trail_dn + .475 * trail_up)
- // label.set_xy(eq_lbl, bar_index, avg)
- box.set_lefttop(discount, math.max(top_x, btm_x), .95 * trail_dn + .05 * trail_up)
- box.set_rightbottom(discount, bar_index + 10, trail_dn)
- label.set_xy(discount_lbl, int(math.avg(math.max(top_x, btm_x), bar_index)), trail_dn)
- //End Code
Advertisement
Add Comment
Please, Sign In to add comment