Created
September 16, 2025 03:58
-
-
Save vtanathip/e330a33d4b3c14576b968f579ece90ce to your computer and use it in GitHub Desktop.
Pinescript RSI + Stochasthic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //@version=5 | |
| indicator("Crypto-Tuned Stochastic RSI Lagged For Confirmation", overlay=false) | |
| // Input parameters | |
| rsiLength = input.int(9, title="RSI Length", group="RSI Settings") // RSI lookback period | |
| rsiSourceInput = input.source(close, "Source", group="RSI Settings") // RSI Source | |
| rsiUpperBandValue = input.float(80, title="Oversold Level", group="RSI Settings") // Oversold threshold | |
| rsiLowerBandValue = input.float(20, title="Overbought Level", group="RSI Settings") // Oversold threshold | |
| stochLength = input.int(9, title="Stochastic Length", group="Stochastic Settings") // StochRSI lookback period | |
| kSmoothing = input.int(3, title="%K Smoothing", group="Stochastic Settings") // %K smoothing period | |
| dSmoothing = input.int(3, title="%D Smoothing", group="Stochastic Settings") // %D smoothing (signal line) period | |
| // Calculations | |
| change = ta.change(rsiSourceInput) | |
| up = ta.rma(math.max(change, 0), rsiLength) | |
| down = ta.rma(-math.min(change, 0), rsiLength) | |
| rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down)) | |
| stochRSI = ta.stoch(rsi, rsi, rsi, stochLength) | |
| kLine = ta.sma(stochRSI, kSmoothing) // %K line (smoothed StochRSI) | |
| dLine = ta.sma(kLine, dSmoothing) // %D line (signal line) | |
| // Plot %D Stochastic RSI lines | |
| dlinePlot = plot(dLine, color=color.orange, linewidth=1, title="%D Line") | |
| // Conditions for highlighting | |
| rsiOverbought = rsi > rsiUpperBandValue | |
| rsiOversold = rsi < rsiLowerBandValue | |
| stochOverbought = dLine > rsiUpperBandValue | |
| stochOversold = dLine < rsiLowerBandValue | |
| bothOverbought = rsiOverbought and stochOverbought | |
| bothOversold = rsiOversold and stochOversold | |
| // Plot Background | |
| rsiPlot = plot(rsi, "RSI", color=#7E57C2) | |
| midLinePlot = plot(50, color = color.new(color.gray, 50), editable = false) | |
| midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50)) | |
| rsiUpperBand = hline(rsiUpperBandValue, "RSI Upper Band", color=#787B86) | |
| rsiLowerBand = hline(rsiLowerBandValue, "RSI Lower Band", color=#787B86) | |
| fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill") | |
| // Highlight when both RSI and Stochastic RSI are overbought | |
| bgcolor(bothOverbought ? color.new(color.red, 90) : na, title="Both Overbought Highlight") | |
| // Highlight when both RSI and Stochastic RSI are oversold | |
| bgcolor(bothOversold ? color.new(color.green, 90) : na, title="Both Oversold Highlight") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment