This strategy initiates momentum breakout positions when the Relative Strength Index reaches extreme levels and Bollinger Band standard deviation is expanding.
//@version=5
strategy("Bollinger Bands, RSI, and MA Strategy", overlay=true)
// Define input variables
b_len = input(20, title="BB Length")
bb_mult = input(2.0, title="BB Standard Deviation")
bb_deviation1 = input(1.0, title="BB Deviation 1")
rsi_len = input(14, title="RSI Length")
overbought = input(70, title="Overbought RSI Level")
oversold = input(30, title="Oversold RSI Level")
ma_len = input(50, title="MA Length")
stop_loss_percent = input(1.0, title="Stop Loss Percentage")
source = input(close, title="Source")
// Calculate Bollinger Bands
bb_upper = ta.sma(source, b_len) + bb_mult * ta.stdev(source, b_len)
bb_lower = ta.sma(source, b_len) - bb_mult * ta.stdev(source, b_len)
bb_upper1 = ta.sma(source, b_len) + bb_deviation1 * ta.stdev(source, b_len)
bb_lower1 = ta.sma(source, b_len) - bb_deviation1 * ta.stdev(source, b_len)
// Calculate RSI
rsi = ta.rsi(source, rsi_len)
// Calculate Moving Average
ma = ta.sma(source, ma_len)
// Determine if Bollinger Bands are contracting
bb_contracting = ta.stdev(source, b_len) < ta.stdev(source, b_len)[1]
// Entry conditions
enterLong = rsi > overbought and not bb_contracting
enterShort = rsi < oversold and not bb_contracting
// Exit conditions
exitLong = close < ma
exitShort = close > ma
// Exit trades and generate alerts
if strategy.position_size > 0 and exitLong
strategy.close("Long") // Exit the long trade
alert("Long Exit", alert.freq_once_per_bar_close)
if strategy.position_size < 0 and exitShort
strategy.close("Short") // Exit the short trade
alert("Short Exit", alert.freq_once_per_bar_close)
// Strategy orders
if enterLong
strategy.entry("Long", strategy.long)
if enterShort
strategy.entry("Short", strategy.short)
if exitLong
strategy.close("Long")
if exitShort
strategy.close("Short")
// Plotting Bollinger Bands
plot(bb_upper, color=color.blue, title="BB Upper 2")
plot(bb_lower, color=color.blue, title="BB Lower 2")
plot(bb_upper1, color=color.red, title="BB Upper 1")
plot(bb_lower1, color=color.red, title="BB Lower 1")
// Plotting RSI
plot(rsi, color=color.orange, title="RSI")
// Plotting Moving Average
plot(ma, color=color.green, title="Moving Average")
Expand (67 lines)
Overview
Long trades open when RSI is above the overbought threshold and bands are not contracting, while short trades trigger when RSI is below oversold and bands are expanding. Exits occur when price crosses a simple moving average. Plotted on the main price chart are two sets of Bollinger Bands, the moving average, and the raw RSI oscillator. Although a stop loss parameter exists in the inputs, it is not executed in code.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
BB Length
int
20
b_len
BB Standard Deviation
float
2.0
bb_mult
BB Deviation 1
float
1.0
bb_deviation1
RSI Length
int
14
rsi_len
Overbought RSI Level
int
70
overbought
Oversold RSI Level
int
30
oversold
MA Length
int
50
ma_len
Stop Loss Percentage
float
1.0
stop_loss_percent
Source
source
close
source
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 plots MACD line, signal line, Bollinger Bands, and RSI on the price chart. It signals long entries on MACD crossover above signal with RSI below 50 and price below BB basis, plus optional DMI filter. Short entries are available but disabled by de
This educational strategy demonstrates moving average crossovers filtered by RSI momentum, incorporating ATR-based risk management. It calculates a 10-period SMA, a 30-period SMA, a 14-period RSI, and a 14-period ATR. Long entries trigger when the fast SMA cro
This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute
This strategy plots exponential-moving-average Bollinger bands on the price chart and calculates RSI. It opens a long position when close crosses above the upper band while RSI is at or above a threshold, the date filter allows trading, and no position is open
CombinedBinHAndClucV6 is a trading strategy based on the popular BinHV45 and ClucMay72018 algorithms. It calculates dual Bollinger Bands, Exponential Moving Averages, Relative Strength Index, Average True Range, and volume metrics across primary and one-hour h
This strategy calculates Bollinger Bands, a configurable moving average slope, Stochastic RSI, ATR, and ADX directly on the price chart. It evaluates trend bias and momentum conditions to generate long and short swing entries using percent-of-equity sizing. Th