Advertisement
aaahopper

RSI plus supports

Nov 8th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.47 KB | None | 0 0
  1. //@version=4
  2. //
  3. // Works: [LunaOwl] RSI American Line [RSIB]
  4. //
  5. ////////////////////////////////////
  6. // ~~!!*(๑╹◡╹๑) ** //
  7. // Production: @LunaOwl 彭彭 //
  8. // Written in: 2019/08/27 //
  9. // Posted in: 2019/10/14 //
  10. // Release 2: 2019/10/21 //
  11. // Update one: 2019/10/22 //
  12. ////////////////////////////////////
  13.  
  14. //
  15. //==Setting the study ==//
  16. study("RSI American Line", shorttitle = "RSIB", overlay = false)
  17.  
  18. //==Enter the value ==//
  19.  
  20.  
  21. std = input(false, title = "Show normal RSI")
  22. bar = input( true, title = "Show US line RSIB")
  23. src = input(close, title = "source")
  24. len = input( 14, title = "length parameter", minval = 2, maxval = 100)
  25.  
  26. //==Set the inner band ==//
  27.  
  28. inner = input("dynamic", title = "inside form", options = ["dynamic", "fixed", "disabled"])
  29. inner_type = input("standard deviation", title = "dynamic inner calculation method", options = ["standard deviation", "smooth moving average"])
  30. inner_mult = input(1.0, title = "inner width", minval = 0.0, maxval = 4.0, step = 0.2)
  31.  
  32. //==calculation ==//
  33.  
  34. norm = if std
  35. 1
  36. else
  37. avg(src, src[1])
  38.  
  39. gain_loss = change(src) / norm
  40.  
  41. RSI = 50 + 50 * rma(gain_loss, len) / rma(abs(gain_loss), len)
  42.  
  43. RSI_ch = if inner != "disabled"
  44. if inner_type == "standard deviation"
  45. stdev(abs(change(RSI)), len)
  46. else
  47. rma(abs(change(RSI)), len)
  48.  
  49. //==Draw RSIB==//
  50.  
  51. o = bar ? RSI[1] : na
  52. h = bar ? RSI : na
  53. l = bar ? RSI[1] : na
  54. c = bar ? RSI : na
  55.  
  56. plotbar(o, h, l, c, title = "RSIB", color = src[1] < src ? color.blue : color.red)
  57.  
  58. //==Draw RSI==//
  59.  
  60. plot(bar ? na : RSI, color = #A64D79FF, title = "RSI")
  61.  
  62. //==Draw a channel==//
  63.  
  64. b1 = hline(30,
  65. color = color.red,
  66. linestyle = hline.style_dotted,
  67. linewidth = 1,
  68. title = "oversold"
  69. )
  70.  
  71. b2 = hline(70,
  72. color = color.blue,
  73. linestyle = hline.style_dotted,
  74. linewidth = 1,
  75. title = "overbought"
  76. )
  77.  
  78. fill(b1, b2, color = #AB47BC, title = "band background")
  79.  
  80. inner_h = plot(
  81. inner == "disabled" ? na : 50 + inner_mult * (inner == "dynamic" ? RSI_ch : 5.0),
  82. color = #A64D7933, title = "with inner edge"
  83. )
  84.  
  85. inner_l = plot(
  86. inner == "disabled" ? na : 50 - inner_mult * (inner == "dynamic" ? RSI_ch : 5.0),
  87. color = #A64D7933, title = "inside lower edge"
  88. )
  89.  
  90. fill(inner_h, inner_l, color = #A64D7922, title = "with inner background")
  91.  
  92. // Bollinger Bands S/R ════════════════════════════════════════════════════════
  93. // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  94. show_dbbl = input(false, title='Display Bollinger Bands S/R ═════════════════')
  95. show_dbbt = input(false, title='Trade Display - Bollinger Bands +++++++++++++++')
  96. length10 = input(title="=> Bollinger Length", type=input.integer, defval=41, minval=1)
  97. multiplier = input(title="=> Bollinger Deviation", type=input.float, defval=2, minval=1)
  98. overbought = 1 //input(title="=> Overbought", type=input.integer, defval=1, minval=1)
  99. oversold = 0 //input(title="=> Oversold", type=input.integer, defval=0, minval=0)
  100.  
  101. orr = bar ? RSI[1] : RSI
  102. hrr = bar ? RSI : RSI
  103. lrr = bar ? RSI[1] : RSI
  104. crr = bar ? RSI : RSI
  105.  
  106.  
  107. smabasis = sma(RSI, length10)
  108. stdev = stdev(RSI, length10)
  109. cierre = RSI
  110. alta = RSI
  111. baja = RSI
  112. basis1 = smabasis
  113. stdevb = stdev
  114. dev5 = multiplier * stdevb
  115. upper = basis1 + dev5
  116. lower5 = basis1 - dev5
  117.  
  118. bbr = (cierre - lower5) / (upper - lower5)
  119.  
  120. // plot(bbr)
  121.  
  122. // // Top Resistance Band
  123. pintarojo = 0.0
  124. pintarojo := nz(pintarojo[1])
  125. pintarojo := bbr[1] > overbought and bbr < overbought ? alta[1] : nz(pintarojo[1])
  126. p = plot(show_dbbl ? pintarojo : na, color=#d904c4, style=plot.style_circles, linewidth=2, transp=0)
  127.  
  128. // // Bottom Support Band
  129. pintaverde = 0.0
  130. pintaverde := nz(pintaverde[1])
  131. pintaverde := bbr[1] < oversold and bbr > oversold ? baja[1] : nz(pintaverde[1])
  132. g = plot(show_dbbl ? pintaverde : na, color=#0959e3, style=plot.style_circles, linewidth=2, transp=0)
  133. //
  134. Long_bb = cross(RSI, pintaverde) //crossover(zlemabarl,pintaverde) or crossunder(zlemabarh,pintaverde) or crossover(zlemabarl,pintarojo) or crossover(pintaverde,pintaverde[1])?1:0
  135. Short_bb = cross(RSI, pintarojo) //crossunder(zlemabarh,pintarojo) or crossover(zlemabarl,pintarojo) or crossunder(zlemabarh,pintaverde) or crossover(pintarojo,pintarojo[1])?1:0
  136.  
  137. plotshape(show_dbbt ? 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)
  138. plotshape(show_dbbt ? 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)
  139.  
  140. //author: wmx_Q_systen_trading
  141. //this study simply draws a trend line base on pivot strength configuration,
  142. // and also provide configuration by using the close price and show historical trend lines
  143. //###################################################||
  144. // Diagnal High/Low support and Resistance Lines ||
  145. //###################################################||
  146. show_dhul = input(false, title='Display Diagnol S/R Lines ═══════════════════')
  147. showhtrend=input(true, title="Show History Trend Line")
  148. useclose=input(false,title='Use Open/Close')
  149.  
  150. hr=bar?(useclose?c:h):RSI
  151. lr=bar?(useclose?c:l):RSI
  152. strength=input(10,title="═> Diagnol S/R left Strength", minval=5, maxval=200)
  153.  
  154. draw_trend(High, Low, leftlen,rightlen,n)=>
  155.  
  156. //upper trend line
  157. var int startx=0
  158. var float starty=0.0
  159. var int startx2=0
  160. var float starty2=0.0
  161.  
  162. var int endx=0
  163. var float endy=0.0
  164. var float endy0=0.0
  165. var float slope=0.0
  166. var bool ispivothigh =false
  167.  
  168. ispivothigh:=High[rightlen] == pivothigh(High,leftlen,rightlen)
  169.  
  170. starty2:=valuewhen(ispivothigh,High[rightlen],n+2)
  171. startx2 := valuewhen(ispivothigh,bar_index,n+2)
  172.  
  173. starty:=valuewhen(ispivothigh,High[rightlen],n+1)
  174. startx := valuewhen(ispivothigh,bar_index,n+1)
  175.  
  176. endy:=valuewhen(ispivothigh,High[rightlen],n)
  177. endx := valuewhen(ispivothigh,bar_index,n)
  178.  
  179. slope:=(endy-starty)/(endx-startx)
  180.  
  181.  
  182. valend = endy
  183. var float Endy=0.0
  184.  
  185. Endy:=abs(endx-startx+rightlen)*slope + starty
  186.  
  187. if slope<0 and show_dhul
  188.  
  189. if n==0
  190. upper0 = line.new(endx, Endy, startx-rightlen, starty, width = 1, color=color.maroon, extend=extend.left)
  191. line.delete(upper0[1])
  192.  
  193. upper1 = line.new(endx, Endy, startx-rightlen, starty, width = 4, color=color.maroon, extend=extend.none)
  194. line.delete(upper1[1])
  195.  
  196. var float slope2= (endy-starty2)/(endx-startx2)
  197. var float Endy2=0.0
  198.  
  199. Endy:=abs(endx-startx2+rightlen)*slope + starty2
  200. if slope2<0 and show_dhul
  201. upper2 = line.new(endx, Endy2, startx2-rightlen, starty2, width = 4, color=color.maroon, extend=extend.none)
  202. line.delete(upper2[1])
  203.  
  204. //lower trend line
  205. var int lstartx=0
  206. var float lstarty=0.0
  207. var int lstartx2=0
  208. var float lstarty2=0.0
  209.  
  210. var int lendx=0
  211. var float lendy=0.0
  212. var float lendy0=0.0
  213. var float lslope=0.0
  214. var bool ispivotlow =false
  215.  
  216. ispivotlow:=Low[rightlen] == pivotlow(Low,leftlen,rightlen)
  217.  
  218. lstarty2:=valuewhen(ispivotlow,Low[rightlen],n+2)
  219. lstartx2 := valuewhen(ispivotlow,bar_index,n+2)
  220.  
  221. lstarty:=valuewhen(ispivotlow,Low[rightlen],n+1)
  222. lstartx := valuewhen(ispivotlow,bar_index,n+1)
  223.  
  224. lendy:=valuewhen(ispivotlow,Low[rightlen],n)
  225. lendx := valuewhen(ispivotlow,bar_index,n)
  226.  
  227. lslope:=(lendy-lstarty)/(lendx-lstartx)
  228. var float lEndy=0.0
  229.  
  230. lEndy:=abs(lendx-lstartx+rightlen)*lslope + lstarty
  231.  
  232.  
  233. if lslope>0 and show_dhul
  234.  
  235. if n==0
  236. Lower0 = line.new(lendx, lEndy, lstartx-rightlen, lstarty, width = 1, color=color.navy, extend=extend.left)
  237. line.delete(Lower0[1])
  238.  
  239. Lower1 = line.new(lendx, lEndy, lstartx-rightlen, lstarty, width = 4, color=color.navy, extend=extend.none)
  240. line.delete(Lower1[1])
  241.  
  242. var float lslope2= (lendy-lstarty2)/(lendx-lstartx2)
  243. var float lEndy2=0.0
  244.  
  245. lEndy:=abs(lendx-lstartx2+rightlen)*lslope + lstarty2
  246. if lslope2>0 and show_dhul
  247. lower2 = line.new(lendx, lEndy2, lstartx2-rightlen, lstarty2, width = 4, color=color.navy, extend=extend.none)
  248. line.delete(lower2[1])
  249.  
  250.  
  251.  
  252. left=strength
  253. right=strength
  254.  
  255. //draw current trendling
  256. draw_trend(hr, lr,left,right,0)
  257.  
  258. if showhtrend
  259. //show history trendling
  260. draw_trend(hr, lr,left,right,1)
  261. draw_trend(hr, lr,left,right,2)
  262. draw_trend(hr, lr,left,right,3)
  263. draw_trend(hr, lr,left,right,4)
  264. draw_trend(hr, lr,left,right,5)
  265. draw_trend(hr, lr,left,right,6)
  266. draw_trend(hr, lr,left,right,7)
  267. draw_trend(hr, lr,left,right,8)
  268. draw_trend(hr, lr,left,right,9)
  269. draw_trend(hr, lr,left,right,10)
  270. draw_trend(hr, lr,left,right,11)
  271. draw_trend(hr, lr,left,right,12)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement