Advertisement
xmd79

RSI With Candlesticks

Apr 15th, 2024
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. //@version=5
  2. indicator(title="RSI With Candlesticks", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
  3.  
  4. ma(source, length, type) =>
  5. switch type
  6. "SMA" => ta.sma(source, length)
  7. "Bollinger Bands" => ta.sma(source, length)
  8. "EMA" => ta.ema(source, length)
  9. "SMMA (RMA)" => ta.rma(source, length)
  10. "WMA" => ta.wma(source, length)
  11. "VWMA" => ta.vwma(source, length)
  12.  
  13. rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
  14. rsiSourceInput = input.source(close, "Source", group="RSI Settings")
  15. maTypeInput = input.string("EMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
  16. maLengthInput = input.int(10, title="MA Length", group="MA Settings")
  17. ma2LengthInput = input.int(200, title="MA 2 Length", group="MA Settings")
  18. bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
  19. showRsiLine = input.bool(false, title="Show RSI Line", group="RSI Settings")
  20. showRsiMA = input.bool(false, title="Show RSI MA", group="RSI Settings")
  21. showRsiMA2 = input.bool(false, title="Show RSI MA 2", group="RSI Settings")
  22. showMA_Fill = input.bool(false, title="Show MA Fill", group="RSI Settings")
  23. showCandles = input.bool(true, title="Show Candles", group="RSI Settings")
  24.  
  25.  
  26. up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
  27. down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
  28. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  29. rsiMA = ma(rsi, maLengthInput, maTypeInput)
  30. rsiMA2 = ma(rsi, ma2LengthInput, maTypeInput)
  31. isBB = maTypeInput == "Bollinger Bands"
  32.  
  33. rsiPlot = plot(showRsiLine ? rsi : na, "RSI", color=color.black, linewidth = 2)
  34. ma1 = plot(showRsiMA ? rsiMA : na, "RSI-based MA", color=color.teal, linewidth = 1)
  35. ma2 = plot(showRsiMA2 ? rsiMA2 : na, "RSI-based MA", color= #fe0000, linewidth = 1)
  36. rsiUpperBand = hline(70.5, "RSI Upper Band", color=#787B86)
  37. midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50), linestyle = hline.style_solid)
  38. rsiLowerBand = hline(30.5, "RSI Lower Band", color=#787B86)
  39.  
  40. // rsi_resistance_top = hline(55, "RSI Resistance Top Line" , color=#00bcd4)
  41. // rsi_resistance_bottom = hline(52, "RSI Resistance Bottom Line", color=#00bcd4)
  42. // rsi_support_top = hline(38, "RSI Support Top Line", color=#00bcd4)
  43. // rsi_support_bottom = hline(34, "RSI Support Top Line", color=#00bcd4)
  44.  
  45. // fill(rsi_resistance_top, rsi_resistance_bottom, color=#00bcd4, title="RSI Resistance Fill")
  46. // fill(rsi_support_top , rsi_support_bottom , color=#00bcd4, title="RSI Support Fill" )
  47.  
  48. fill(ma1, ma2, color= rsiMA > rsiMA2 and showMA_Fill ? color.new(color.teal, 60) : rsiMA < rsiMA2 and showMA_Fill ? color.new(color.red, 60) : na, title="MA Fill")
  49.  
  50.  
  51. fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
  52. bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
  53. bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)
  54. fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill")
  55.  
  56. midLinePlot = plot(50, color = na, editable = false, display = display.none)
  57. fill(rsiPlot, midLinePlot, 100, 70, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100), title = "Overbought Gradient Fill")
  58. fill(rsiPlot, midLinePlot, 30, 0, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill")
  59.  
  60.  
  61.  
  62. ///===> Candlestick Oscillators
  63. // c= ma(close,osc_length, maTypeInput)
  64. // o= ma(open ,osc_length, maTypeInput)
  65. // h= ma(high ,osc_length, maTypeInput)
  66. // l= ma(low ,osc_length, maTypeInput)
  67.  
  68. c1 = ta.rsi(close, rsiLengthInput)
  69. o1 = ta.rsi(open , rsiLengthInput)
  70. h1 = ta.rsi(high , rsiLengthInput)
  71. l1 = ta.rsi(low , rsiLengthInput)
  72.  
  73. // c3= ma(close,osc2_length, maTypeInput)
  74. // o3= ma(open,osc2_length, maTypeInput)
  75. // h3= ma(high,osc2_length, maTypeInput)
  76. // l3= ma(low,osc2_length, maTypeInput)
  77.  
  78. // c2 = ta.rsi(c3, osc2_length)
  79. // o2 = ta.rsi(o3, osc2_length)
  80. // h2 = ta.rsi(h3, osc2_length)
  81. // l2 = ta.rsi(l3, osc2_length)
  82.  
  83. // plotcandle(o1,h1,l1,c1, color = o < c ? color.white : color.black, wickcolor=color.black, bordercolor = color.black)
  84. plotcandle(showCandles ? o1 : na, showCandles ? h1 : na, showCandles ? l1 : na, showCandles ? c1 : na, color = o1 < c1 ? color.blue : color.black, wickcolor= o1 < c1 ? color.blue : color.black, bordercolor = o1 < c1 ? color.blue : color.black)
  85.  
  86.  
  87.  
  88. // // Divergence
  89. // lookbackRight = 5
  90. // lookbackLeft = 5
  91. // rangeUpper = 60
  92. // rangeLower = 5
  93. // bearColor = color.red
  94. // bullColor = color.green
  95. // textColor = color.white
  96. // noneColor = color.new(color.white, 100)
  97.  
  98. // plFound = na(ta.pivotlow(rsi, lookbackLeft, lookbackRight)) ? false : true
  99. // phFound = na(ta.pivothigh(rsi, lookbackLeft, lookbackRight)) ? false : true
  100. // _inRange(cond) =>
  101. // bars = ta.barssince(cond == true)
  102. // rangeLower <= bars and bars <= rangeUpper
  103.  
  104. // //------------------------------------------------------------------------------
  105. // // Regular Bullish
  106. // // rsi: Higher Low
  107.  
  108. // rsiHL = rsi[lookbackRight] > ta.valuewhen(plFound, rsi[lookbackRight], 1) and _inRange(plFound[1])
  109.  
  110. // // Price: Lower Low
  111.  
  112. // priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
  113. // bullCondAlert = priceLL and rsiHL and plFound
  114. // bullCond = showDivergence and bullCondAlert
  115.  
  116. // plot(
  117. // plFound ? rsi[lookbackRight] : na,
  118. // offset=-lookbackRight,
  119. // title="Regular Bullish",
  120. // linewidth=2,
  121. // color=(bullCond ? bullColor : noneColor)
  122. // )
  123.  
  124. // plotshape(
  125. // bullCond ? rsi[lookbackRight] : na,
  126. // offset=-lookbackRight,
  127. // title="Regular Bullish Label",
  128. // text=" Bull ",
  129. // style=shape.labelup,
  130. // location=location.absolute,
  131. // color=bullColor,
  132. // textcolor=textColor
  133. // )
  134.  
  135. // //------------------------------------------------------------------------------
  136. // // Regular Bearish
  137. // // rsi: Lower High
  138.  
  139. // rsiLH = rsi[lookbackRight] < ta.valuewhen(phFound, rsi[lookbackRight], 1) and _inRange(phFound[1])
  140.  
  141. // // Price: Higher High
  142.  
  143. // priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)
  144.  
  145. // bearCondAlert = priceHH and rsiLH and phFound
  146. // bearCond = showDivergence and bearCondAlert
  147.  
  148. // plot(
  149. // phFound ? rsi[lookbackRight] : na,
  150. // offset=-lookbackRight,
  151. // title="Regular Bearish",
  152. // linewidth=2,
  153. // color=(bearCond ? bearColor : noneColor)
  154. // )
  155.  
  156. // plotshape(
  157. // bearCond ? rsi[lookbackRight] : na,
  158. // offset=-lookbackRight,
  159. // title="Regular Bearish Label",
  160. // text=" Bear ",
  161. // style=shape.labeldown,
  162. // location=location.absolute,
  163. // color=bearColor,
  164. // textcolor=textColor
  165. // )
  166.  
  167. // alertcondition(bullCondAlert, title='Regular Bullish Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.")
  168. // alertcondition(bearCondAlert, title='Regular Bearish Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement