Advertisement
aaahopper

RSI plus Fib supports

Jan 14th, 2020
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. //@version=4
  2. //
  3. study("RSI American Line with trendlines", shorttitle = "strategy of RSI with trendlines and S/R", overlay = false)
  4.  
  5. // RSI Oscillator Chart ════════════════════════════════════════════════════════
  6. // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  7.  
  8. show_brs= input(false, title='RSI Chart Selection criteria ═════════════════')
  9. std_bar = input("std", title = "═> Show bar or Line RSI", options = ["bar", "std"])
  10. src = input(close, title = "═> RSI source")
  11. len = input( 9, title = "═> RSI length parameter", minval = 2, maxval = 100)
  12. //==Set the inner band ==//
  13. //inner = "disabled" //input("dynamic", title = "═> RSI inside form", options = ["dynamic", "fixed", "disabled"])
  14. //inner_type = input("standard deviation", title = "═> RSI dynamic inner calculation method", options = ["standard deviation", "smooth moving average"])
  15. //inner_mult = input(1.0, title = "═> RSI inner width", minval = 0.0, maxval = 4.0, step = 0.2)
  16.  
  17. //==calculation ==//
  18.  
  19. norm = if std_bar=="std"
  20. 1
  21. else
  22. avg(src, src[1])
  23.  
  24. gain_loss = change(src) / norm
  25.  
  26. RSI0 = 50 + 50 * rma(gain_loss, len) / rma(abs(gain_loss), len)
  27.  
  28. ismoothLen=input(1)
  29. cti(sm, src, cd) =>
  30. di = (sm - 1.0) / 2.0 + 1.0
  31. c1 = 2 / (di + 1.0)
  32. c2 = 1 - c1
  33. c3 = 3.0 * (cd * cd + cd * cd * cd)
  34. c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
  35. c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
  36. i1 = 0.0
  37. i2 = 0.0
  38. i3 = 0.0
  39. i4 = 0.0
  40. i5 = 0.0
  41. i6 = 0.0
  42. i1 := c1*src + c2*nz(i1[1])
  43. i2 := c1*i1 + c2*nz(i2[1])
  44. i3 := c1*i2 + c2*nz(i3[1])
  45. i4 := c1*i3 + c2*nz(i4[1])
  46. i5 := c1*i4 + c2*nz(i5[1])
  47. i6 := c1*i5 + c2*nz(i6[1])
  48.  
  49. bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
  50. bfr
  51. RSI = cti(ismoothLen, RSI0, 0)
  52.  
  53.  
  54. // RSI_ch = if inner != "disabled"
  55. // if inner_type == "standard deviation"
  56. // stdev(abs(change(RSI)), len)
  57. // else
  58. // rma(abs(change(RSI)), len)
  59.  
  60. //==Draw RSIB==//
  61. o = std_bar=="bar" ? RSI[1] : RSI
  62. h = std_bar=="bar" ? RSI : RSI
  63. l = std_bar=="bar" ? RSI[1] : RSI
  64. c = std_bar=="bar" ? RSI : RSI
  65.  
  66. plotbar(o, h, l, c, title = "RSIB", color = src[1] < src ? color.blue : color.red)
  67.  
  68. //==Draw RSI==//
  69. plot(std_bar=="bar" ? na : RSI, color = #A64D79FF, title = "RSI",linewidth=2)
  70.  
  71. //==Draw a channel==//
  72. // b1 = hline(40,color = color.red,linestyle = hline.style_dotted,linewidth = 1,title = "oversold")
  73. // b2 = hline(60,color = color.blue,linestyle = hline.style_dotted,linewidth = 1,title = "overbought")
  74. // fill(b1, b2, color = #AB47BC, title = "band background")
  75.  
  76. // inner_h = plot(inner == "disabled" ? na : 50 + inner_mult * (inner == "dynamic" ? RSI_ch : 5.0),color = #A64D7933, title = "with inner edge")
  77. // inner_l = plot(inner == "disabled" ? na : 50 - inner_mult * (inner == "dynamic" ? RSI_ch : 5.0),color = #A64D7933, title = "inside lower edge")
  78. // fill(inner_h, inner_l, color = #A64D7922, title = "with inner background")
  79.  
  80. //#########################################################||
  81. //--- Fibonacci Zones -------------------------------------||
  82. //#########################################################||
  83. show_fib=input(true,title='Display Fibonacci Zones ------------------------')
  84. fiblength=input(265,title='=> Fibonacci length')
  85. fib_adj = input(0.0,step=0.5,title='Fib height adjustment')
  86. line_inc = input("Yes", title = "═> Include Outter Lines only", options = ["Yes", "No"])
  87. maxr0 = highest(h, fiblength)
  88. minr0 = lowest(l, fiblength)
  89. ranr = maxr0 - minr0
  90.  
  91. fib7640 = maxr0 - 0.236 * ranr
  92. fib6180 = maxr0 - 0.382 * ranr
  93. fib5000 = maxr0 - 0.500 * ranr
  94. fib3820 = minr0 + 0.382 * ranr
  95. fib2360 = minr0 + 0.236 * ranr
  96.  
  97. maxr = maxr0 - (maxr0*fib_adj/100)
  98. fib764 = fib7640- (fib7640*fib_adj/100)
  99. fib618 = fib6180- (fib6180*fib_adj/100)
  100. fib500 = fib5000
  101. fib382 = fib3820+ (fib3820*fib_adj/100)
  102. fib236 = fib2360+ (fib2360*fib_adj/100)
  103. minr = minr0 + (minr0*fib_adj/100)
  104.  
  105.  
  106. ON=plot(show_fib? maxr:na , color=color.maroon, title="1",transp=0, linewidth=2)
  107. SS=plot(show_fib? fib764:na, title="0.764", color=color.maroon,linewidth=1,transp=0)
  108. SO=plot(show_fib? fib618:na, title="0.618", color=color.black,linewidth=1,transp=0)
  109. FI=plot(show_fib? fib500:na, title="0.5", color=color.black,linewidth=1,transp=50 )
  110. TE=plot(show_fib? fib382:na, title="0.382", color=color.black,linewidth=1,transp=0)
  111. TT=plot(show_fib? fib236:na, title="0.236", color=color.green,linewidth=1,transp=0)
  112. ZZ=plot(show_fib? minr:na , title="0", color=color.green,transp=0, linewidth=2)
  113.  
  114. fill(ON,SS, color=color.red,transp=80)
  115. fill(SS,SO, color=#3399FF,transp=93)
  116. //fill(SO,FI, color=lime,transp=95)
  117. fill(SO,TE, color=color.silver,transp=80)
  118. //fill(FI,TE, color=lime,transp=95)
  119. fill(TE,TT, color=#3399FF,transp=93)
  120. fill(TT,ZZ, color=color.lime,transp=80)
  121.  
  122. ShortFib1000 = line_inc=="Yes"?crossunder(c,maxr):na?1:0 // and c<o?1:0
  123. ShortFib764 = line_inc=="Yes"?crossunder(c,fib764):na?1:0 //and c<o?1:0
  124. ShortFib618 = line_inc=="Yes"?na:crossunder(c,fib618)?1:0 // and c<o?1:0
  125. // ShortFib500 = cross(high,fib500) and close<open?1:0
  126. // ShortFib382 = cross(high,fib382) and close<open?1:0
  127. // ShortFib236 = cross(high,fib236) and close<open?1:0
  128. ShortFib = ShortFib1000==1 or ShortFib764==1 or ShortFib618==1 //or ShortFib500==1 or ShortFib382==1 or ShortFib236==1
  129.  
  130. // LongFib764 = cross(low,fib764) and close>open?1:0
  131. // LongFib618 = cross(low,fib618) and close>open?1:0
  132. // LongFib500 = cross(low,fib500) and close>open?1:0
  133. LongFib382 = line_inc=="Yes"?na:crossover(c,fib382)?1:0 // and c>o?1:0
  134. LongFib236 = line_inc=="Yes"?crossover(c,fib236):na?1:0 // and c>o?1:0
  135. LongFib000 = line_inc=="Yes"?crossover(c,minr):na?1:0 // and c>o?1:0
  136. LongFib = LongFib000==1 or LongFib236==1 or LongFib382==1
  137.  
  138. plotshape(ShortFib, text="Dn", title="Condition Short-Trade", style=shape.triangledown, size=size.tiny, location=location.top, color=color.fuchsia, transp=0)
  139. 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