// Imported the RSI indicator code from Section 5.Indicators - Lesson #6.RSI-Chart-Signals.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @version=5
strategy("RSI Strategy", overlay=true)
// Import Zen Library
import ZenAndTheArtOfTrading/ZenLibrary/2 as zen
// Get user input
lookback = input.int(title="Lookback", defval=7)
rsiLen = input.int(title="RSI Length", defval=7)
rsiOB = input.float(title="RSI Overbought", defval=80.0)
rsiOS = input.float(title="RSI Oversold", defval=20.0)
multiplier = input.float(title="ATR Multiplier", defval=1.0)
rr = input.float(title="Risk:Reward", defval=1.0)
riskPerTrade = input.float(title="Risk Per Trade %", defval=1.0)
// Get RSI value
rsi = ta.rsi(close, rsiLen)
rsiSell = rsi > rsiOB
rsiBuy = rsi < rsiOS
// Get ATR value
atr = ta.atr(14)
// Detect candle patterns
bullEC = zen.isBullishEC()
bearEC = zen.isBearishEC()
// Detect buy and sell signals
buySignal = bullEC and (rsiBuy or rsiBuy[1]) and not na(atr) and barstate.isconfirmed and strategy.position_size == 0
sellSignal = bearEC and (rsiSell or rsiSell[1]) and not na(atr) and barstate.isconfirmed and strategy.position_size == 0
// Calculate stops & targets
longStop = ta.lowest(low, lookback) - (atr * multiplier)
shortStop = ta.highest(high, lookback) + (atr * multiplier)
longStopDistance = close - longStop
shortStopDistance = shortStop - close
longTarget = close + (longStopDistance * rr)
shortTarget = close - (shortStopDistance * rr)
// Save stops & targets
var t_stop = 0.0
var t_target = 0.0
// Enter buy orders
if buySignal
t_stop := longStop
t_target := longTarget
positionSize = math.floor((strategy.equity * (riskPerTrade/100)) / (close - t_stop))
strategy.entry(id="Long", direction=strategy.long, qty=positionSize)
// Enter sell orders
if sellSignal
t_stop := shortStop
t_target := shortTarget
positionSize = math.floor((strategy.equity * (riskPerTrade/100)) / (t_stop - close))
strategy.entry(id="Short", direction=strategy.short, qty=positionSize)
// Manage exit orders (TP & SL)
strategy.exit(id="Long Exit", from_entry="Long", limit=t_target, stop=t_stop, when=strategy.position_size > 0)
strategy.exit(id="Short Exit", from_entry="Short", limit=t_target, stop=t_stop, when=strategy.position_size < 0)
// Draw data to chart
plotshape(buySignal, style=shape.triangleup, color=color.green, location=location.belowbar)
plotshape(sellSignal, style=shape.triangledown, color=color.red, location=location.abovebar)
plot(strategy.position_size != 0 ? t_stop : na, color=color.red, style=plot.style_linebr)
plot(strategy.position_size != 0 ? t_target : na, color=color.green, style=plot.style_linebr)
Overview
RSI Strategy opens positions on confirmed bars when an overbought or oversold RSI aligns with a bullish or bearish engulfing pattern. Stop losses are calculated using swing highs or lows combined with an ATR multiplier, while take-profit targets are set according to a configurable risk-to-reward ratio. Position sizing dynamically adjusts based on equity risk percentage, and trade levels are displayed directly on the price chart.
RSI overbought and oversold condition filtering
Engulfing candlestick pattern signal triggers
Dynamic ATR and swing high/low stop loss calculation
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Lookback
int
7
lookback
RSI Length
int
7
rsiLen
RSI Overbought
float
80.0
rsiOB
RSI Oversold
float
20.0
rsiOS
ATR Multiplier
float
1.0
multiplier
Risk:Reward
float
1.0
rr
Risk Per Trade %
float
1.0
riskPerTrade
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.
This strategy calculates double-smoothed Heikin Ashi candles and plots them directly on the price chart alongside a smoothed Relative Strength Index. It evaluates market conditions against external volatility data from an inverse symbol, generating long and sh
A strategy that scores signals from ten sources: RSI, MACD, Bollinger Bands, head and shoulders, wedges, multiple tops and bottoms, candlestick reversals, pivot support and resistance, volume spikes and an EMA ribbon filter. A trade needs a minimum pattern sco
High-Frequency Swing Reversal is a Pine Script v5 strategy that computes a reversal score from Bollinger Bands distance, RSI exhaustion, and candlestick rejection patterns such as hammers and stars. It plots VWAP, Bollinger Bands, and EMA20 on the price chart.
Tweezer Lyfe is a TradingView strategy that identifies Tweezer reversal patterns on the price chart. It plots Bollinger Bands with RSI and stochastic indicators for momentum confirmation. Bullish signals require a prior bearish candle closing near the lower ba
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
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