Advertisement
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/
- // Β© saipranayvudatha
- //@version=5
- indicator(title='Dare_2_Trade magic', overlay=true, precision=4, linktoseries=false, max_bars_back=1000, max_lines_count=500)
- // Color
- upcolor = color.new(#047e37, 0)
- downcolor = color.new(#ee2906, 0)
- themecolor = color.new(#000000, 0)
- turn = input(true, title='bulb', inline='bulbπ‘')
- arrow = input(true, title='Arrow Confim', inline='scalp')
- reversal = input(false, title='Reversal Zone')
- rsiValue = ta.rsi(close, 7)
- isOverbought = rsiValue >= 65
- isOversold = rsiValue <= 35
- rsiValue1 = ta.rsi(close, 15)
- isOverbought1 = rsiValue1 >= 65
- isOversold1 = rsiValue1 <= 35
- rsiValue2 = ta.rsi(close, 15)
- isOverbought2 = rsiValue1 >= 65
- isOversold2 = rsiValue1 <= 35
- // State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
- var laststate = 0
- var laststate1 = 0
- var laststate2 = 0
- // Highest and Lowest prices since the last state change
- var hh = low
- var ll = high
- var hh1 = low
- var ll1 = high
- var hh2 = low
- var ll2 = high
- // Labels
- var label labelll = na
- var label labelhh = na
- var label labelll1 = na
- var label labelhh1 = na
- var label labelll2 = na
- var label labelhh2 = na
- // Swing lines
- var line line_up = na
- var line line_down = na
- var line line_up1 = na
- var line line_down1 = na
- var line line_up2 = na
- var line line_down2 = na
- var last_actual_label_hh_price = 0.0
- var last_actual_label_ll_price = 0.0
- var last_actual_label_hh_price1 = 0.0
- var last_actual_label_ll_price1 = 0.0
- var last_actual_label_hh_price2 = 0.0
- var last_actual_label_ll_price2 = 0.0
- // FUNCTIONS
- obLabelText1() =>
- if last_actual_label_hh_price1 < high
- 'Reversal Zone'
- else
- 'Reversal Zone'
- osLabelText1() =>
- if last_actual_label_ll_price1 < low
- 'Reversal Zone'
- else
- 'Reversal Zone'
- // Create oversold or overbought label
- createOverBoughtLabel(isIt) =>
- if isIt
- label.new(x=bar_index, y=na, yloc=yloc.price, style=label.style_circle, color=color.new(downcolor, 50), size=size.tiny)
- else
- label.new(x=bar_index, y=na, yloc=yloc.price, style=label.style_circle, color=color.new(upcolor, 50), size=size.tiny)
- createOverBoughtLabel1(isIt1) =>
- if isIt1
- label.new(x=bar_index, y=na, yloc=yloc.abovebar, style=label.style_label_down, color=downcolor, size=size.normal, text=obLabelText1(), textcolor=color.white)
- else
- label.new(x=bar_index, y=na, yloc=yloc.belowbar, style=label.style_label_up, color=upcolor, size=size.normal, text=osLabelText1(), textcolor=color.white)
- createOverBoughtLabel2(isIt2) =>
- if isIt2
- label.new(x=bar_index, y=na, yloc=yloc.abovebar, style=label.style_triangledown, color=downcolor, size=size.tiny)
- else
- label.new(x=bar_index, y=na, yloc=yloc.belowbar, style=label.style_triangleup, color=upcolor, size=size.tiny)
- // Move the oversold swing and label
- moveOversoldLabel() =>
- label.set_x(labelll, bar_index)
- label.set_y(labelll, low)
- // label.set_text(labelll, osLabelText())
- line.set_x1(line_down, bar_index)
- line.set_y1(line_down, low)
- moveOverBoughtLabel() =>
- label.set_x(labelhh, bar_index)
- label.set_y(labelhh, high)
- // label.set_text(labelhh, obLabelText())
- line.set_x1(line_up, bar_index)
- line.set_y1(line_up, high)
- moveOversoldLabel1() =>
- label.set_x(labelll1, bar_index)
- label.set_y(labelll1, low)
- label.set_text(labelll1, osLabelText1())
- line.set_x1(line_down1, bar_index)
- line.set_y1(line_down1, low)
- moveOverBoughtLabel1() =>
- label.set_x(labelhh1, bar_index)
- label.set_y(labelhh1, high)
- label.set_text(labelhh1, obLabelText1())
- line.set_x1(line_up1, bar_index)
- line.set_y1(line_up1, high)
- moveOversoldLabel2() =>
- label.set_x(labelll2, bar_index)
- label.set_y(labelll2, low)
- line.set_x1(line_down2, bar_index)
- line.set_y1(line_down2, low)
- moveOverBoughtLabel2() =>
- label.set_x(labelhh2, bar_index)
- label.set_y(labelhh2, high)
- line.set_x1(line_up2, bar_index)
- line.set_y1(line_up2, high)
- // We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
- if laststate == 2 and isOverbought and turn
- hh := high
- labelhh := createOverBoughtLabel(true)
- last_actual_label_ll_price := label.get_y(labelll)
- labelll_ts = label.get_x(labelll)
- labelll_price = label.get_y(labelll)
- // line_up := line.new(x1=bar_index, y1=high, x2=labelll_ts, y2=labelll_price, width=1)
- line_up
- if laststate1 == 2 and isOverbought1 and reversal
- hh1 := high
- labelhh1 := createOverBoughtLabel1(true)
- last_actual_label_ll_price1 := label.get_y(labelll1)
- labelll_ts1 = label.get_x(labelll1)
- labelll_price1 = label.get_y(labelll1)
- line_up1 := line.new(x1=bar_index, y1=high, x2=labelll_ts1, y2=labelll_price1, width=1)
- line_up1
- if laststate2 == 2 and isOverbought2 and arrow
- hh2 := high
- labelhh2 := createOverBoughtLabel2(true)
- last_actual_label_ll_price2 := label.get_y(labelll2)
- labelll_ts2 = label.get_x(labelll2)
- labelll_price2 = label.get_y(labelll2)
- // line_up2 := line.new(x1=bar_index, y1=high, x2=labelll_ts2, y2=labelll_price2, width=1)
- line_up2
- // We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
- if laststate == 1 and isOversold and turn
- ll := low
- labelll := createOverBoughtLabel(false)
- last_actual_label_hh_price := label.get_y(labelhh)
- labelhh_ts = label.get_x(labelhh)
- labelhh_price = label.get_y(labelhh)
- // line_down := line.new(x1=bar_index, y1=high, x2=labelhh_ts, y2=labelhh_price, width=1)
- line_down
- if laststate1 == 1 and isOversold1 and reversal
- ll1 := low
- labelll1 := createOverBoughtLabel1(false)
- last_actual_label_hh_price1 := label.get_y(labelhh1)
- labelhh_ts1 = label.get_x(labelhh1)
- labelhh_price1 = label.get_y(labelhh1)
- line_down1 := line.new(x1=bar_index, y1=high, x2=labelhh_ts1, y2=labelhh_price1, width=1)
- line_down1
- if laststate2 == 1 and isOversold2 and arrow
- ll2 := low
- labelll2 := createOverBoughtLabel2(false)
- last_actual_label_hh_price2 := label.get_y(labelhh2)
- labelhh_ts2 = label.get_x(labelhh2)
- labelhh_price2 = label.get_y(labelhh2)
- // line_down2 := line.new(x1=bar_index, y1=high, x2=labelhh_ts2, y2=labelhh_price2, width=1)
- line_down2
- // If we are overbought
- if isOverbought and turn
- if high >= hh
- hh := high
- moveOverBoughtLabel()
- laststate := 1
- laststate
- if isOverbought1 and reversal
- if high >= hh1
- hh1 := high
- moveOverBoughtLabel1()
- laststate1 := 1
- laststate1
- if isOverbought2 and arrow
- if high >= hh2
- hh2 := high
- moveOverBoughtLabel2()
- laststate2 := 1
- laststate2
- // If we are oversold
- if isOversold and turn
- if low <= ll
- ll := low
- moveOversoldLabel()
- laststate := 2
- laststate
- if isOversold1 and reversal
- if low <= ll1
- ll1 := low
- moveOversoldLabel1()
- laststate1 := 2
- laststate1
- if isOversold2 and arrow
- if low <= ll2
- ll2 := low
- moveOversoldLabel2()
- laststate2 := 2
- laststate2
- // If last state was overbought and we are overbought
- if laststate == 1 and isOverbought and turn
- if hh <= high
- hh := high
- moveOverBoughtLabel()
- if laststate1 == 1 and isOverbought1 and reversal
- if hh1 <= high
- hh1 := high
- moveOverBoughtLabel1()
- if laststate2 == 1 and isOverbought2 and arrow
- if hh2 <= high
- hh2 := high
- moveOverBoughtLabel2()
- //If we are oversold and the last state was oversold, move the drawings to the lowest price
- if laststate == 2 and isOversold and turn
- if low <= ll
- ll := low
- moveOversoldLabel()
- if laststate1 == 2 and isOversold1 and reversal
- if low <= ll1
- ll1 := low
- moveOversoldLabel1()
- if laststate2 == 2 and isOversold2 and arrow
- if low <= ll2
- ll2 := low
- moveOversoldLabel2()
- // If last state was overbought
- if laststate == 1 and turn
- if hh <= high
- hh := high
- moveOverBoughtLabel()
- if laststate1 == 1 and reversal
- if hh1 <= high
- hh1 := high
- moveOverBoughtLabel1()
- if laststate2 == 1 and arrow
- if hh2 <= high
- hh2 := high
- moveOverBoughtLabel2()
- // If last stare was oversold
- if laststate == 2 and turn
- if ll >= low
- ll := low
- moveOversoldLabel()
- if laststate1 == 2 and reversal
- if ll1 >= low
- ll1 := low
- moveOversoldLabel1()
- if laststate2 == 2 and arrow
- if ll2 >= low
- ll2 := low
- moveOversoldLabel2()
- //-------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement