Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Electrified (electrifiedtrading)
- indicator(title='Stochastic RSI+', shorttitle='Stoch RSI+', format=format.price, precision=2, timeframe='') // v2
- kcolor = #0094FF
- dcolor = #FF6A00
- WMA = 'WMA'
- EMA = 'EMA'
- SMA = 'SMA'
- VWMA = 'VWMA'
- VAWMA = 'VAWMA'
- ///////////////////////////////////////////////////
- // Input
- k_mode = input.string(SMA, 'K Mode', inline='Source', options=[SMA, EMA, WMA, VWMA, VAWMA])
- src = input.source(close, 'Source', inline='Source')
- smoothK = input.int(3, 'K', inline='Values', minval=1)
- smoothD = input.int(3, 'D', inline='Values', minval=1)
- lengthRSI = input.int(14, 'RSI', group='Lengths', inline='Lengths', minval=1)
- lengthStoch = input.int(14, 'Stochastic', group='Lengths', inline='Lengths', minval=1)
- upperBand = input.int(80, 'Upper', group='Band', minval=50, maxval=100)
- lowerBand = input.int(20, 'Lower', group='Band', maxval=50, minval=0)
- ///////////////////////////////////////////////////
- // Functions
- vawma(src, len) =>
- sum = 0.0
- vol = 0.0
- for m = 1 to len by 1 // m = triangular multiple
- i = len - m
- v = volume[i] * m
- vol += v
- sum += src[i] * v
- sum
- sum / vol
- ////
- getMA(series, mode, len) =>
- 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)
- ////
- ///////////////////////////////////////////////////
- // Calculation
- rsi1 = ta.rsi(src, lengthRSI)
- stoch = ta.stoch(rsi1, rsi1, rsi1, lengthStoch)
- k = getMA(stoch, k_mode, smoothK)
- d = ta.sma(k, smoothD)
- k_c = ta.change(k)
- d_c = ta.change(d)
- kd = k - d
- ///////////////////////////////////////////////////
- // Visualization
- h0 = hline(upperBand, 'Upper Band', color=#606060)
- hline(50, 'Middle Band', color=#606060)
- h1 = hline(lowerBand, 'Lower Band', color=#606060)
- fill(h0, h1, color=color.new(#9915FF, 95), title='Band Background')
- 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
- kp = plot(k, 'K', color=color.new(kcolor, 0))
- dp = plot(d, 'D', color=color.new(dcolor, 0))
- fill(kp, dp, color=color.new(signalColor, 50), title='K-D')
- signalUp = not na(signalColor) and kd > 0
- signalDown = not na(signalColor) and kd < 0
- plot(signalUp ? kd : na, 'Signal Up', color=color.new(kcolor, 0), style=plot.style_columns)
- plot(signalDown ? kd + 100 : na, 'Signal Down', color=color.new(dcolor, 0), style=plot.style_columns, histbase=100)
- ///////////////////////////////////////////////////
- // Alerts
- alertcondition(d < lowerBand, '1: Over-sold', 'Stoch RSI+: Over-sold\nD value below lower band. ({{ticker}} {{interval}})')
- 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}})')
- alertcondition(signalUp, '3: Postitive (+) Momentum ▲', 'Stoch RSI+: Postitive (+) Momentum ▲\nK&D rising ▲ within band. ({{ticker}} {{interval}})')
- alertcondition(d > upperBand, '4: Over-bought', 'Stoch RSI+: Over-bought\nD value above upper band. ({{ticker}} {{interval}})')
- 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}})')
- alertcondition(signalDown, '6: Negative (-) Momentum ▼', 'Stoch RSI+: Negative (-) Momentum ▼\nK&D falling ▼ within band. ({{ticker}} {{interval}})')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement