This strategy plots on the price chart and enters when price closes beyond the prior lookback high or low and also beyond a shorter confirmation range.
//@version=5
strategy("Momentum Breakout Strategy - Full Version", overlay=true)
// === Input: Position Sizing Options ===
position_type = input.string("Percent of Equity", title="Position Size Type", options=["Percent of Equity", "Fixed Quantity", "Fixed Cash Amount"])
qty_percent = input.float(10.0, title="Qty % of Equity", minval=0.1)
fixed_qty = input.float(1, title="Fixed Quantity", minval=0.0001)
cash_per_trade = input.float(100, title="Fixed Cash Amount ($)", minval=1)
// === Function: Determine Order Size ===
get_order_size() =>
if position_type == "Percent of Equity"
na
else if position_type == "Fixed Quantity"
fixed_qty
else
cash_per_trade / close
order_size = get_order_size()
// === Inputs for Strategy Logic ===
breakoutLen = input.int(20, title="Breakout Lookback Length")
rangeLen = input.int(10, title="Range Confirmation Length")
use_volume_filter = input.bool(false, title="Use Volume Filter?")
volume_mult = input.float(1.5, title="Volume Multiplier (vs. SMA)")
use_body_filter = input.bool(true, title="Use Candle Body Size Filter?")
body_min_mult = input.float(0.7, title="Min Body Size (x ATR)")
use_trailing_stop = input.bool(false, title="Use Trailing Stop?")
trail_atr_mult = input.float(1.5, title="Trailing ATR Multiplier")
use_time_exit = input.bool(false, title="Use Time-Based Exit?")
time_exit_bars = input.int(20, title="Exit After N Bars")
trade_direction = input.string("Both", title="Trade Direction", options=["Long Only", "Short Only", "Both"])
stop_loss_atr_mult = input.float(1.5, title="Stop Loss ATR Multiplier")
take_profit_atr_mult = input.float(3.0, title="Take Profit ATR Multiplier")
// === Indicators and Calculations ===
atr = ta.atr(14)
body_size = math.abs(close - open)
body_condition = not use_body_filter or body_size > (atr * body_min_mult)
breakoutHigh = ta.highest(high, breakoutLen)
breakoutLow = ta.lowest(low, breakoutLen)
rangeHigh = ta.highest(high, rangeLen)
rangeLow = ta.lowest(low, rangeLen)
smaVolume = ta.sma(volume, breakoutLen)
volume_condition = not use_volume_filter or volume > (smaVolume * volume_mult)
// === Long Entry ===
long_breakout = close > breakoutHigh[1]
range_confirm_long = close > rangeHigh[1]
allow_long = trade_direction == "Long Only" or trade_direction == "Both"
if long_breakout and range_confirm_long and volume_condition and body_condition and allow_long
if position_type == "Percent of Equity"
strategy.entry("Long", strategy.long, qty=qty_percent)
else
strategy.entry("Long", strategy.long, qty=order_size)
if use_trailing_stop
strategy.exit("Exit Long", from_entry="Long", trail_points=trail_atr_mult * atr, trail_offset=trail_atr_mult * atr)
else
strategy.exit("Exit Long", from_entry="Long", stop=close - stop_loss_atr_mult * atr, limit=close + take_profit_atr_mult * atr)
// === Short Entry ===
short_breakout = close < breakoutLow[1]
range_confirm_short = close < rangeLow[1]
allow_short = trade_direction == "Short Only" or trade_direction == "Both"
if short_breakout and range_confirm_short and volume_condition and body_condition and allow_short
if position_type == "Percent of Equity"
strategy.entry("Short", strategy.short, qty=qty_percent)
else
strategy.entry("Short", strategy.short, qty=order_size)
if use_trailing_stop
strategy.exit("Exit Short", from_entry="Short", trail_points=trail_atr_mult * atr, trail_offset=trail_atr_mult * atr)
else
strategy.exit("Exit Short", from_entry="Short", stop=close + stop_loss_atr_mult * atr, limit=close - take_profit_atr_mult * atr)
// === Time-based Exit ===
if use_time_exit
strategy.close("Long", when=strategy.opentrades > 0 and strategy.opentrades.entry_bar_index(0) + time_exit_bars <= bar_index)
strategy.close("Short", when=strategy.opentrades > 0 and strategy.opentrades.entry_bar_index(0) + time_exit_bars <= bar_index)
// === Plot Breakout and Range Levels ===
plot(breakoutHigh, title="Breakout High", color=color.green)
plot(breakoutLow, title="Breakout Low", color=color.red)
plot(rangeHigh, title="Range High", color=color.teal)
plot(rangeLow, title="Range Low", color=color.orange)
Overview
Long, short, or both directions can be enabled. Optional filters require volume above a volume average or a candle body larger than a fraction of ATR. Position size can be a percent of equity, a fixed quantity, or a fixed cash amount. Exits use an ATR stop and take profit, or an optional ATR trailing stop. A bar-count exit setting is present.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Position Size Type
string
Percent of Equity
position_type
Qty % of Equity
float
10.0
qty_percent
Fixed Quantity
float
1
fixed_qty
Fixed Cash Amount ($)
float
100
cash_per_trade
Breakout Lookback Length
int
20
breakoutLen
Range Confirmation Length
int
10
rangeLen
Use Volume Filter?
bool
false
use_volume_filter
Volume Multiplier (vs. SMA)
float
1.5
volume_mult
Use Candle Body Size Filter?
bool
true
use_body_filter
Min Body Size (x ATR)
float
0.7
body_min_mult
Use Trailing Stop?
bool
false
use_trailing_stop
Trailing ATR Multiplier
float
1.5
trail_atr_mult
Show all 17 settings
Setting
Type
Default
Variable
Use Time-Based Exit?
bool
false
use_time_exit
Exit After N Bars
int
20
time_exit_bars
Trade Direction
string
Both
trade_direction
Stop Loss ATR Multiplier
float
1.5
stop_loss_atr_mult
Take Profit ATR Multiplier
float
3.0
take_profit_atr_mult
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 identifies breakout momentum by combining Bollinger Bands and Keltner Channels with volume confirmation. It opens long positions when the upper Keltner Channel crosses above the upper Bollinger Band and volume exceeds its moving average. Converse
This strategy overlays Bollinger Bands on the price chart and trades a long squeeze setup. It enters long when band width is below 0.022 and volume is at least the seven-bar average, using a stop order at the lower band. It places a short order when close cros
BB Squeeze Breakout is a volatility breakout strategy that identifies consolidation squeezes using Bollinger Band width percentile ranking. When the band width drops below its 25th percentile and price crosses above or below the bands with optional volume conf
This strategy detects Bollinger Band squeezes by measuring band width against a threshold. It waits for a confirmed breakout in either direction when bands expand, using optional volume confirmation. Long and short signals trigger on breakout after squeeze. Po
This strategy enters long when the close breaks above the prior lookback high and volume exceeds its simple moving average, but only if a VIX regime score is at least three. The score counts whether the VIX to three-month VIX ratio and the VIX level sit below
This strategy identifies Minervini Volume Confirmation Patterns fused with Smart Money Concepts for Bursa Malaysia stocks. It plots entry and exit signals with trend lines, boxes and labels directly on the price chart. The strategy enters long positions when v