Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- //
- study("RSI American Line with trendlines", shorttitle = "strategy of RSI with trendlines and S/R", overlay = false)
- // RSI Oscillator Chart ════════════════════════════════════════════════════════
- // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
- show_brs= input(false, title='RSI Chart Selection criteria ═════════════════')
- std_bar = input("std", title = "═> Show bar or Line RSI", options = ["bar", "std"])
- src = input(close, title = "═> RSI source")
- len = input( 9, title = "═> RSI length parameter", minval = 2, maxval = 100)
- //==Set the inner band ==//
- //inner = "disabled" //input("dynamic", title = "═> RSI inside form", options = ["dynamic", "fixed", "disabled"])
- //inner_type = input("standard deviation", title = "═> RSI dynamic inner calculation method", options = ["standard deviation", "smooth moving average"])
- //inner_mult = input(1.0, title = "═> RSI inner width", minval = 0.0, maxval = 4.0, step = 0.2)
- //==calculation ==//
- norm = if std_bar=="std"
- 1
- else
- avg(src, src[1])
- gain_loss = change(src) / norm
- RSI0 = 50 + 50 * rma(gain_loss, len) / rma(abs(gain_loss), len)
- ismoothLen=input(1)
- cti(sm, src, cd) =>
- di = (sm - 1.0) / 2.0 + 1.0
- c1 = 2 / (di + 1.0)
- c2 = 1 - c1
- c3 = 3.0 * (cd * cd + cd * cd * cd)
- c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
- c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
- i1 = 0.0
- i2 = 0.0
- i3 = 0.0
- i4 = 0.0
- i5 = 0.0
- i6 = 0.0
- i1 := c1*src + c2*nz(i1[1])
- i2 := c1*i1 + c2*nz(i2[1])
- i3 := c1*i2 + c2*nz(i3[1])
- i4 := c1*i3 + c2*nz(i4[1])
- i5 := c1*i4 + c2*nz(i5[1])
- i6 := c1*i5 + c2*nz(i6[1])
- bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
- bfr
- RSI = cti(ismoothLen, RSI0, 0)
- // 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",linewidth=2)
- //==Draw a channel==//
- // b1 = hline(40,color = color.red,linestyle = hline.style_dotted,linewidth = 1,title = "oversold")
- // b2 = hline(60,color = color.blue,linestyle = hline.style_dotted,linewidth = 1,title = "overbought")
- // fill(b1, b2, color = #AB47BC, title = "band background")
- // inner_h = plot(inner == "disabled" ? na : 50 + inner_mult * (inner == "dynamic" ? RSI_ch : 5.0),color = #A64D7933, title = "with inner edge")
- // inner_l = plot(inner == "disabled" ? na : 50 - inner_mult * (inner == "dynamic" ? RSI_ch : 5.0),color = #A64D7933, title = "inside lower edge")
- // fill(inner_h, inner_l, color = #A64D7922, title = "with inner background")
- //#########################################################||
- //--- Fibonacci Zones -------------------------------------||
- //#########################################################||
- show_fib=input(true,title='Display Fibonacci Zones ------------------------')
- fiblength=input(265,title='=> Fibonacci length')
- fib_adj = input(0.0,step=0.5,title='Fib height adjustment')
- line_inc = input("Yes", title = "═> Include Outter Lines only", options = ["Yes", "No"])
- maxr0 = highest(h, fiblength)
- minr0 = lowest(l, fiblength)
- ranr = maxr0 - minr0
- fib7640 = maxr0 - 0.236 * ranr
- fib6180 = maxr0 - 0.382 * ranr
- fib5000 = maxr0 - 0.500 * ranr
- fib3820 = minr0 + 0.382 * ranr
- fib2360 = minr0 + 0.236 * ranr
- maxr = maxr0 - (maxr0*fib_adj/100)
- fib764 = fib7640- (fib7640*fib_adj/100)
- fib618 = fib6180- (fib6180*fib_adj/100)
- fib500 = fib5000
- fib382 = fib3820+ (fib3820*fib_adj/100)
- fib236 = fib2360+ (fib2360*fib_adj/100)
- minr = minr0 + (minr0*fib_adj/100)
- ON=plot(show_fib? maxr:na , color=color.maroon, title="1",transp=0, linewidth=2)
- SS=plot(show_fib? fib764:na, title="0.764", color=color.maroon,linewidth=1,transp=0)
- SO=plot(show_fib? fib618:na, title="0.618", color=color.black,linewidth=1,transp=0)
- FI=plot(show_fib? fib500:na, title="0.5", color=color.black,linewidth=1,transp=50 )
- TE=plot(show_fib? fib382:na, title="0.382", color=color.black,linewidth=1,transp=0)
- TT=plot(show_fib? fib236:na, title="0.236", color=color.green,linewidth=1,transp=0)
- ZZ=plot(show_fib? minr:na , title="0", color=color.green,transp=0, linewidth=2)
- fill(ON,SS, color=color.red,transp=80)
- fill(SS,SO, color=#3399FF,transp=93)
- //fill(SO,FI, color=lime,transp=95)
- fill(SO,TE, color=color.silver,transp=80)
- //fill(FI,TE, color=lime,transp=95)
- fill(TE,TT, color=#3399FF,transp=93)
- fill(TT,ZZ, color=color.lime,transp=80)
- ShortFib1000 = line_inc=="Yes"?crossunder(c,maxr):na?1:0 // and c<o?1:0
- ShortFib764 = line_inc=="Yes"?crossunder(c,fib764):na?1:0 //and c<o?1:0
- ShortFib618 = line_inc=="Yes"?na:crossunder(c,fib618)?1:0 // and c<o?1:0
- // ShortFib500 = cross(high,fib500) and close<open?1:0
- // ShortFib382 = cross(high,fib382) and close<open?1:0
- // ShortFib236 = cross(high,fib236) and close<open?1:0
- ShortFib = ShortFib1000==1 or ShortFib764==1 or ShortFib618==1 //or ShortFib500==1 or ShortFib382==1 or ShortFib236==1
- // LongFib764 = cross(low,fib764) and close>open?1:0
- // LongFib618 = cross(low,fib618) and close>open?1:0
- // LongFib500 = cross(low,fib500) and close>open?1:0
- LongFib382 = line_inc=="Yes"?na:crossover(c,fib382)?1:0 // and c>o?1:0
- LongFib236 = line_inc=="Yes"?crossover(c,fib236):na?1:0 // and c>o?1:0
- LongFib000 = line_inc=="Yes"?crossover(c,minr):na?1:0 // and c>o?1:0
- LongFib = LongFib000==1 or LongFib236==1 or LongFib382==1
- plotshape(ShortFib, text="Dn", title="Condition Short-Trade", style=shape.triangledown, size=size.tiny, location=location.top, color=color.fuchsia, transp=0)
- plotshape(LongFib, text="Up", title="Condition Long-Trade", style=shape.triangleup, size=size.tiny, location=location.bottom, color=color.aqua, transp=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement