Strategy · Pine Script v6 · On the chart

Stochastic RSI

by pineforge-4pass· code credited to PineForge contributors 2026

This strategy calculates a smoothed Stochastic RSI oscillator and generates trading signals based on overbought and oversold crossovers.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code39
Settings6inputs
LicenceApache-2.0
Last update7 days ago23 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

39 lines of Pine Script v6 from validation/ta-stochastic-rsi-cross-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 04 — stochastic-RSI cross
// Purpose: parity test for the ta.rsi → ta.stoch → ta.sma double-smoothing chain
// with overbought/oversold-gated crossover entries.
//
//@version=6
strategy("Stochastic RSI", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

// === Inputs ===
rsiLen    = input.int(14, "RSI Length", minval=1)
stochLen  = input.int(14, "Stoch Length", minval=1)
kSmooth   = input.int(3, "K Smoothing", minval=1)
dSmooth   = input.int(3, "D Smoothing", minval=1)
obLevel   = input.int(80, "Overbought")
osLevel   = input.int(20, "Oversold")

// === Calculations ===
rsiVal    = ta.rsi(close, rsiLen)
stochK    = ta.sma(ta.stoch(rsiVal, rsiVal, rsiVal, stochLen), kSmooth)
stochD    = ta.sma(stochK, dSmooth)

// === Signals ===
longCond  = ta.crossover(stochK, stochD) and stochK < osLevel
shortCond = ta.crossunder(stochK, stochD) and stochK > obLevel

// === Strategy ===
if longCond
    strategy.entry("Long", strategy.long)
if shortCond
    strategy.entry("Short", strategy.short)

// === Exit ===
if strategy.position_size > 0 and stochK > obLevel and ta.crossunder(stochK, stochD)
    strategy.close("Long")
if strategy.position_size < 0 and stochK < osLevel and ta.crossover(stochK, stochD)
    strategy.close("Short")

Overview

Stochastic RSI opens a long position when the %K line crosses above %D while below the oversold threshold, and enters short when %K crosses below %D while above the overbought threshold. Positions exit when an opposite crossover occurs in the opposing extreme zone. Settings allow customization of the RSI period, Stochastic length, smoothing factors, and extreme levels. It overlays on the main price chart and includes no fixed stop-loss orders.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Lengthint14rsiLen
Stoch Lengthint14stochLen
K Smoothingint3kSmooth
D Smoothingint3dSmooth
Overboughtint80obLevel
Oversoldint20osLevel
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit

Strategy v4 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Alert BB + RSI [Alorse]
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy

This strategy draws on the price chart and combines Stochastic RSI, the Money Flow Index, and an exponential moving average to open long or short trades. Longs use the lower oscillator thresholds and shorts use the upper ones, with direction limited to longs,

Strategy v5 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders
104 stars

This strategy combines Bollinger Bands with a short RSI to fade moves that leave the bands and then return. A long requires the prior bar below the lower band and oversold, then a close back inside the band while RSI is between 30 and 50. Shorts mirror that at

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 years ago · MIT GitHub repository of Bollinger Bands and RSI Strategy
53 stars

This strategy implements Larry Connors' 2-period RSI mean-reversion algorithm overlaid on the price chart. It filters trades using a long-term Simple Moving Average (SMA), entering long positions when the price trades above the SMA and the short-term RSI drops

Strategy v6 Oscillators & momentumMean reversion
Updated 2 months ago · MPL-2.0 GitHub repository of Larry Connors 2-Period RSI Strategy

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers