Advertisement
xmd79

Stochastic RSI+

Jan 3rd, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. //@version=5
  2. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  3. // © Electrified (electrifiedtrading)
  4. indicator(title='Stochastic RSI+', shorttitle='Stoch RSI+', format=format.price, precision=2, timeframe='') // v2
  5.  
  6. kcolor = #0094FF
  7. dcolor = #FF6A00
  8. WMA = 'WMA'
  9. EMA = 'EMA'
  10. SMA = 'SMA'
  11. VWMA = 'VWMA'
  12. VAWMA = 'VAWMA'
  13.  
  14. ///////////////////////////////////////////////////
  15. // Input
  16.  
  17. k_mode = input.string(SMA, 'K Mode', inline='Source', options=[SMA, EMA, WMA, VWMA, VAWMA])
  18. src = input.source(close, 'Source', inline='Source')
  19. smoothK = input.int(3, 'K', inline='Values', minval=1)
  20. smoothD = input.int(3, 'D', inline='Values', minval=1)
  21.  
  22.  
  23. lengthRSI = input.int(14, 'RSI', group='Lengths', inline='Lengths', minval=1)
  24. lengthStoch = input.int(14, 'Stochastic', group='Lengths', inline='Lengths', minval=1)
  25.  
  26.  
  27. upperBand = input.int(80, 'Upper', group='Band', minval=50, maxval=100)
  28. lowerBand = input.int(20, 'Lower', group='Band', maxval=50, minval=0)
  29.  
  30.  
  31. ///////////////////////////////////////////////////
  32. // Functions
  33. vawma(src, len) =>
  34. sum = 0.0
  35. vol = 0.0
  36. for m = 1 to len by 1 // m = triangular multiple
  37. i = len - m
  38. v = volume[i] * m
  39. vol += v
  40. sum += src[i] * v
  41. sum
  42. sum / vol
  43. ////
  44.  
  45. getMA(series, mode, len) =>
  46. mode == WMA ? ta.wma(series, len) : mode == EMA ? ta.ema(series, len) : mode == VWMA ? ta.vwma(series, len) : mode == VAWMA ? vawma(series, len) : ta.sma(series, len)
  47. ////
  48.  
  49. ///////////////////////////////////////////////////
  50. // Calculation
  51. rsi1 = ta.rsi(src, lengthRSI)
  52. stoch = ta.stoch(rsi1, rsi1, rsi1, lengthStoch)
  53. k = getMA(stoch, k_mode, smoothK)
  54. d = ta.sma(k, smoothD)
  55. k_c = ta.change(k)
  56. d_c = ta.change(d)
  57. kd = k - d
  58.  
  59.  
  60. ///////////////////////////////////////////////////
  61. // Visualization
  62. h0 = hline(upperBand, 'Upper Band', color=#606060)
  63. hline(50, 'Middle Band', color=#606060)
  64. h1 = hline(lowerBand, 'Lower Band', color=#606060)
  65. fill(h0, h1, color=color.new(#9915FF, 95), title='Band Background')
  66.  
  67. signalColor = k > lowerBand and d < upperBand and k > d and k_c > 0 and d_c > 0 ? kcolor : k < upperBand and d > lowerBand and k < d and k_c < 0 and d_c < 0 ? dcolor : na
  68. kp = plot(k, 'K', color=color.new(kcolor, 0))
  69. dp = plot(d, 'D', color=color.new(dcolor, 0))
  70. fill(kp, dp, color=color.new(signalColor, 50), title='K-D')
  71.  
  72. signalUp = not na(signalColor) and kd > 0
  73. signalDown = not na(signalColor) and kd < 0
  74.  
  75. plot(signalUp ? kd : na, 'Signal Up', color=color.new(kcolor, 0), style=plot.style_columns)
  76. plot(signalDown ? kd + 100 : na, 'Signal Down', color=color.new(dcolor, 0), style=plot.style_columns, histbase=100)
  77.  
  78.  
  79. ///////////////////////////////////////////////////
  80. // Alerts
  81. alertcondition(d < lowerBand, '1: Over-sold', 'Stoch RSI+: Over-sold\nD value below lower band. ({{ticker}} {{interval}})')
  82. alertcondition(d < lowerBand and k > d, '2: Over-sold & Rising ▲', 'Stoch RSI+ Over-sold & Rising ▲\nK>D and D value below lower band. ({{ticker}} {{interval}})')
  83. alertcondition(signalUp, '3: Postitive (+) Momentum ▲', 'Stoch RSI+: Postitive (+) Momentum ▲\nK&D rising ▲ within band. ({{ticker}} {{interval}})')
  84. alertcondition(d > upperBand, '4: Over-bought', 'Stoch RSI+: Over-bought\nD value above upper band. ({{ticker}} {{interval}})')
  85. alertcondition(d > upperBand and k < d, '5: Over-bought & Falling ▼', 'Stoch RSI+: Over-bought & Falling ▼\nK<D and D value above upper band. ({{ticker}} {{interval}})')
  86. alertcondition(signalDown, '6: Negative (-) Momentum ▼', 'Stoch RSI+: Negative (-) Momentum ▼\nK&D falling ▼ within band. ({{ticker}} {{interval}})')
  87.  
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement