Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- //
- study("V01. RSI American Line with trendlines with HiLoPositions", shorttitle = "V01. strategy of RSI with trendlines and S/R with HiLoPositions", overlay = false)
- // Chart Display Criteria ════════════════════════════════════════════════════════
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- display1=input(true, title="RSI display format section ══════════════════")
- Trd_All = input("Both", title ="+++ Show trade locations", options = ["Both", "S/R", "Ob/Os"])
- ShowTrendCandles = input("Yes",title = "+++ Highlight Trend Candles", options = ["No", "Yes"])
- std_bar = input("bar", title = "+++ Show RSI in Line or Bar format", options = ["bar", "std"])
- log_chart = input("No",title = "+++ Use Log Chart", options = ["No", "Yes"])
- inner = input("dynamic", title = "+++ Inside form", options = ["dynamic", "fixed", "disabled"])
- inner_type = input("standard deviation", title = "+++ dynamic inner calculation method", options = ["standard deviation", "smooth moving average"])
- a_Color_Type = input(defval="Colored", title = "+++ Trendlines color Scheme", options=["Colored", "Monochrome"])
- // RSI Input Criteria ════════════════════════════════════════════════════════
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- display02=input(true, title="RSI Data Entry section ════════════════════")
- len = input( 9, title = "+++ RSI length parameter", minval = 2, maxval = 100)
- src = input(close, title = "+++ RSI source")
- Hline= input(60,title='+++ Overbought RSI Line')
- Lline= input(40,title='+++ Oversold RSI Line')
- inner_mult = input(1.0, title = "+++ RSI inner Channel width", minval = 0.0, maxval = 4.0, step = 0.1)
- //==calculation ==//
- norm = if std_bar=="std"
- 1
- else
- avg(src, src[1])
- gain_loss = change(src) / norm
- RSI = 50 + 50 * rma(gain_loss, len) / rma(abs(gain_loss), len)
- RSI_ch = if inner != "disabled"
- if inner_type == "standard deviation"
- stdev(abs(change(RSI)), len)
- else
- rma(abs(change(RSI)), len)
- //==Draw RSIB==//
- o = std_bar=="bar" ? RSI[1] : RSI
- h = std_bar=="bar" ? RSI : RSI
- l = std_bar=="bar" ? RSI[1] : RSI
- c = std_bar=="bar" ? RSI : RSI
- plotbar(o, h, l, c, title = "RSIB", color = src[1] < src ? color.blue : color.red)
- //==Draw RSI==//
- plot(std_bar=="bar" ? na : RSI, color = #A64D79FF, title = "RSI")
- //==Draw a channel==//
- b1 = hline(Lline,color = color.red,linestyle = hline.style_dotted,linewidth = 1,title = "oversold")
- b2 = hline(Hline,color = color.blue,linestyle = hline.style_dotted,linewidth = 1,title = "overbought")
- fill(b1, b2, color = #AB47BC, title = "band background")
- //Inner Lines
- Inner_hi = inner == "disabled" ? na : 50 + inner_mult * (inner == "dynamic" ? RSI_ch : 5.0)
- Inner_lo = inner == "disabled" ? na : 50 - inner_mult * (inner == "dynamic" ? RSI_ch : 5.0)
- inner_h = plot(Inner_hi,color = #A64D7933, title = "with inner edge")
- inner_l = plot(Inner_lo,color = #A64D7933, title = "inside lower edge")
- fill(inner_h, inner_l, color = #A64D7922, title = "with inner background")
- Long_rsi01 = crossover(RSI, Lline) and src[1] < src
- Short_rsi01= crossunder(RSI, Hline) and src[1] > src
- plotshape(Trd_All=="Both" or Trd_All=="Ob/Os" ? Short_rsi01: na, text="Dn", title="Condition Short-Trade", style=shape.triangledown, size=size.tiny, location=location.top, color=color.fuchsia, transp=0)
- plotshape(Trd_All=="Both" or Trd_All=="Ob/Os" ? Long_rsi01: na, text="Up", title="Condition Long-Trade", style=shape.triangleup, size=size.tiny, location=location.bottom, color=color.aqua, transp=0)
- // Bollinger Bands S/R ════════════════════════════════════════════════════════
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- show_dbbl = input(true, title='Display Bollinger Bands S/R ═════════════════')
- length10 = input(title="+++ Bollinger Length", type=input.integer, defval=38, minval=1)
- multiplier = input(title="+++ Bollinger Deviation", type=input.float, defval=2, step=0.1, minval=1)
- overbought = 1 //input(title="=> Overbought", type=input.integer, defval=1, minval=1)
- oversold = 0 //input(title="=> Oversold", type=input.integer, defval=0, minval=0)
- smabasis = sma(c, length10)
- stdev = stdev(c, length10)
- cierre = c
- alta = h
- baja = l
- basis1 = smabasis
- stdevb = stdev
- dev5 = multiplier * stdevb
- upper = basis1 + dev5
- lower5 = basis1 - dev5
- bbr = (cierre - lower5) / (upper - lower5)
- plot(bbr)
- // // Top Resistance Band
- pintarojo = 0.0
- pintarojo := nz(pintarojo[1])
- pintarojo := bbr[1] > overbought and bbr < overbought ? alta[1] : nz(pintarojo[1])
- p = plot(show_dbbl ? pintarojo : na, color=#d904c4, style=plot.style_circles, linewidth=2, transp=0)
- // // Bottom Support Band
- pintaverde = 0.0
- pintaverde := nz(pintaverde[1])
- pintaverde := bbr[1] < oversold and bbr > oversold ? baja[1] : nz(pintaverde[1])
- g = plot(show_dbbl ? pintaverde : na, color=#0959e3, style=plot.style_circles, linewidth=2, transp=0)
- //
- Long_bb = cross(RSI, pintaverde)
- Short_bb = cross(RSI, pintarojo)
- plotshape(Trd_All=="Both" or Trd_All=="S/R" ? Short_bb and src[1] > src: na, text="Dn", title="Condition Short-Trade", style=shape.triangledown, size=size.tiny, location=location.top, color=color.fuchsia, transp=0)
- plotshape(Trd_All=="Both" or Trd_All=="S/R" ? Long_bb and src[1] < src: na, text="Up", title="Condition Long-Trade", style=shape.triangleup, size=size.tiny, location=location.bottom, color=color.aqua, transp=0)
- //Trendlines 2 lots ════════════════════════════════════════════════════════
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- // Input variables
- show_text= input(true, title='══════════════════════════════════')
- a_Show_Primary = input(true, title = "1 ═> Display Primary Trendlines ═════════════")
- a_len = input(20, title = "+++ Primary Lookback Length")
- a_Extensions = input( title = "+++ Primary Trendline Extensions", defval=" 50", options=["Infinate", " 25", " 50", " 75", " 100", " 150", " 200", " 300", " 400", " 500", " 750", "1000"])
- a_width = input(2, title = "+++ Primary Line Width", minval = 0, maxval = 10)
- a_Show_Breaks = "n/a"
- a_trendline_nr = 0
- a_Rising_Upper_Falling_Lower = false
- b_Show_Secondary = input(true, title = "2 ═> Display Secondary Trendlines ════════════")
- b_len = input(10, title = "+++ Secondary Lookback Length")
- b_Extensions = input( title = "+++ Secondary Trendline Extensions", defval=" 25", options=["Infinate", " 25", " 50", " 75", " 100", " 150", " 200", " 300", " 400", " 500", " 750", "1000"])
- b_width = input(1, title = "+++ Secondary Line Width", minval = 0, maxval = 10)
- b_Show_Breaks = "n/a"
- b_trendline_nr = 0
- b_Rising_Upper_Falling_Lower = false
- a_bar_time = time - time[1]
- b_bar_time = time - time[1]
- ///// Primary Trendlines /////
- // Trendline Extensions
- a_Extension_Multiplier=
- a_Extensions==" 25"? 1 :
- a_Extensions==" 50"? 2 :
- a_Extensions==" 75"? 3 :
- a_Extensions==" 100"? 4 :
- a_Extensions==" 150"? 6 :
- a_Extensions==" 200"? 8 :
- a_Extensions==" 300"? 12 :
- a_Extensions==" 400"? 16 :
- a_Extensions==" 500"? 20 :
- a_Extensions==" 750"? 30 :
- a_Extensions=="1000"? 40 :
- a_Extensions=="Infinate"? 0 : na
- // Declaration of trendline function
- a_f_trendline(a__input_function, a__delay, a__only_up, a__extend) =>
- // Calculate line coordinates (Ax,Ay) - (Bx,By)
- var int a_Ax = 1
- var int a_Bx = 1
- var float a_By = 0
- var float a_slope = 0
- a_Ay = fixnan(a__input_function)
- if change(a_Ay)!=0
- a_Ax := time[a__delay]
- a_By := a_Ay[1]
- a_Bx := a_Ax[1]
- a_slope:= log_chart=="Yes"? ((log(a_Ay) - log(a_By)) / (a_Ax - a_Bx)) : ((a_Ay - a_By) / (a_Ax - a_Bx))
- else
- a_Ax := a_Ax[1]
- a_Bx := a_Bx[1]
- a_By := a_By[1]
- // Draw trendlines
- var line a_trendline = na
- var int a_Axbis = 0
- var float a_Aybis = 0
- var bool a__xtend = true
- a_extension_time = a_Extension_Multiplier * a_bar_time * 25
- a_Axbis := a_Ax + a_extension_time
- a_Aybis := log_chart=="Yes"? (a_Ay * exp(a_extension_time * a_slope)) : (a_Ay + a_extension_time * a_slope)
- if a_Extension_Multiplier != 0
- a__xtend := false
- if change(a_Ay) != 0
- a_line_color_Rising_Falling = a_slope * time < 0? (a__only_up ? a_Rising_Upper_Falling_Lower ? (a_Color_Type=="Colored" ? color.gray : color.teal) : na : (a_Color_Type=="Colored" ? #cf0a83 : color.teal)) : (a__only_up? (a_Color_Type=="Colored"? #027521 : color.teal) : a_Rising_Upper_Falling_Lower ? (a_Color_Type=="Colored"? color.gray : color.teal) : na)
- a_line_color_Not_Rising_Falling = a_slope * time < 0? (a__only_up ? na :(a_Color_Type=="Colored" ? #cf0a83 : color.teal)) : (a__only_up? (a_Color_Type=="Colored"? #027521 : color.teal) : na)
- a_line_color = a_Show_Primary and not a_Rising_Upper_Falling_Lower ? a_line_color_Not_Rising_Falling : a_Show_Primary and a_Rising_Upper_Falling_Lower ? a_line_color_Rising_Falling : na
- if not na(a_line_color)
- a_trendline = line.new(a_Bx, a_By, a_Axbis, a_Aybis, xloc.bar_time, extend = a__xtend? extend.right : extend.none, color = a_line_color, style = line.style_solid, width = a_width)
- [a_Bx, a_By, a_Axbis, a_Aybis, a_slope]
- // Calculate pivot points
- a_high_point = pivothigh((c > o? c : o), a_len, a_len / 2)
- a_low_point = pivotlow((c > o? o : c), a_len, a_len / 2)
- // Call trendline function for high and low pivot points
- [a_phx1, a_phy1, a_phx2, a_phy2, a_slope_high] = a_f_trendline(a_high_point, a_len / 2, false, true)
- [a_plx1, a_ply1, a_plx2, a_ply2, a_slope_low] = a_f_trendline(a_low_point, a_len / 2, true, true)
- // ///// Secondary Trendlines /////
- // // Trendline Extensions
- b_Extension_Multiplier=
- b_Extensions==" 25"? 1 :
- b_Extensions==" 50"? 2 :
- b_Extensions==" 75"? 3 :
- b_Extensions==" 100"? 4 :
- b_Extensions==" 150"? 6 :
- b_Extensions==" 200"? 8 :
- b_Extensions==" 300"? 12 :
- b_Extensions==" 400"? 16 :
- b_Extensions==" 500"? 20 :
- b_Extensions==" 750"? 30 :
- b_Extensions=="1000"? 40 :
- b_Extensions=="Infinate"? 0 : na
- // Declaration of trendline function
- b_f_trendline(b__input_function, b__delay, b__only_up, b__extend) =>
- // Calculate line coordinates (Ax,Ay) - (Bx,By)
- var int b_Ax = 1
- var int b_Bx = 1
- var float b_By = 0
- var float b_slope = 0
- b_Ay = fixnan(b__input_function)
- if change(b_Ay)!=0
- b_Ax := time[b__delay]
- b_By := b_Ay[1]
- b_Bx := b_Ax[1]
- b_slope:= log_chart=="Yes"? ((log(b_Ay) - log(b_By)) / (b_Ax - b_Bx)) : ((b_Ay - b_By) / (b_Ax - b_Bx))
- else
- b_Ax := b_Ax[1]
- b_Bx := b_Bx[1]
- b_By := b_By[1]
- // Draw trendlines
- var line b_trendline = na
- var int b_Axbis = 0
- var float b_Aybis = 0
- var bool b__xtend = true
- b_extension_time = b_Extension_Multiplier * b_bar_time * 25
- b_Axbis := b_Ax + b_extension_time
- b_Aybis := log_chart=="Yes"? (b_Ay * exp(b_extension_time * b_slope)) : (b_Ay + b_extension_time * b_slope)
- if b_Extension_Multiplier != 0
- b__xtend := false
- if change(b_Ay) != 0
- b_line_color_Rising_Falling = b_slope * time < 0? (b__only_up ? b_Rising_Upper_Falling_Lower ? (a_Color_Type=="Colored" ? color.gray : color.teal) : na : (a_Color_Type=="Colored" ? color.red : color.teal)) : (b__only_up? (a_Color_Type=="Colored"? color.green : color.teal) : b_Rising_Upper_Falling_Lower ? (a_Color_Type=="Colored"? color.gray : color.teal) : na)
- b_line_color_Not_Rising_Falling = b_slope * time < 0? (b__only_up ? na :(a_Color_Type=="Colored" ? color.red : color.teal)) : (b__only_up? (a_Color_Type=="Colored"? color.green : color.teal) : na)
- b_line_color = b_Show_Secondary and not b_Rising_Upper_Falling_Lower ? b_line_color_Not_Rising_Falling : b_Show_Secondary and b_Rising_Upper_Falling_Lower ? b_line_color_Rising_Falling : na
- if not na(b_line_color)
- b_trendline = line.new(b_Bx, b_By, b_Axbis, b_Aybis, xloc.bar_time, extend = b__xtend? extend.right : extend.none, color = b_line_color, style = line.style_dashed, width = b_width)
- [b_Bx, b_By, b_Axbis, b_Aybis, b_slope]
- // Calculate pivot points
- b_high_point = pivothigh((c > o? c : o), b_len, b_len / 2)
- b_low_point = pivotlow((c > o? o : c), b_len, b_len / 2)
- // Call trendline function for high and low pivot points
- [b_phx1, b_phy1, b_phx2, b_phy2, b_slope_high] = b_f_trendline(b_high_point, b_len / 2, false, true)
- [b_plx1, b_ply1, b_plx2, b_ply2, b_slope_low] = b_f_trendline(b_low_point, b_len / 2, true, true)
- // Plot and connect pivot points
- b_color_high = b_slope_high * time < 0 ? color.green : na
- b_color_low = b_slope_low * time > 0 ? color.red : na
- // Trend Candles //
- //UCS_Trend by ucsgears copy Trend Candles
- //Interpretation of TTM Trend bars. It is really close to the actual.
- haclose = c
- haopen = 0.0
- haopen := na(haopen[1]) ? (o + c) / 2 : (haopen[1] + haclose[1]) / 2
- ccolor = haclose - haopen > 0 ? 1 : 0
- inside6 = haopen <= max(haopen[6],haclose[6]) and haopen>=min(haopen[6],haclose[6]) and haclose <= max(haopen[6],haclose[6]) and haclose >= min(haopen[6],haclose[6]) ? 1 : 0
- inside5 = haopen <= max(haopen[5],haclose[5]) and haopen>=min(haopen[5],haclose[5]) and haclose <= max(haopen[5],haclose[5]) and haclose >= min(haopen[5],haclose[5]) ? 1 : 0
- inside4 = haopen <= max(haopen[4],haclose[4]) and haopen>=min(haopen[4],haclose[4]) and haclose <= max(haopen[4],haclose[4]) and haclose >= min(haopen[4],haclose[4]) ? 1 : 0
- inside3 = haopen <= max(haopen[3],haclose[3]) and haopen>=min(haopen[3],haclose[3]) and haclose <= max(haopen[3],haclose[3]) and haclose >= min(haopen[3],haclose[3]) ? 1 : 0
- inside2 = haopen <= max(haopen[2],haclose[2]) and haopen>=min(haopen[2],haclose[2]) and haclose <= max(haopen[2],haclose[2]) and haclose >= min(haopen[2],haclose[2]) ? 1 : 0
- inside1 = haopen <= max(haopen[1],haclose[1]) and haopen>=min(haopen[1],haclose[1]) and haclose <= max(haopen[1],haclose[1]) and haclose >= min(haopen[1],haclose[1]) ? 1 : 0
- colorvalue = inside6 ? ccolor[6] : inside5 ? ccolor[5] : inside4 ? ccolor[4] : inside3 ? ccolor[3] : inside2 ? ccolor[2] : inside1 ? ccolor[1] : ccolor
- Trend_Candle_Color = colorvalue ? color.lime : color.fuchsia
- // Bar Color according to Trend Candles
- barcolor(ShowTrendCandles=="Yes"? Trend_Candle_Color : na, title = "Trend Candles")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement