Strategy · Pine Script v5 · On the chart

Momentum Breakout Strategy

by adminalphabots

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.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code91
Settings17inputs
LicenceMIT
Last update8 months ago28 Feb 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

91 lines of Pine Script v5 from tradingview/strategies/momentumbreak_Crypto.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

momentumbreak_Crypto.pine
//@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.

Details

Published by

adminalphabots on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Breakout, Volatility & bands, Volume

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Position Size TypestringPercent of Equityposition_type
Qty % of Equityfloat10.0qty_percent
Fixed Quantityfloat1fixed_qty
Fixed Cash Amount ($)float100cash_per_trade
Breakout Lookback Lengthint20breakoutLen
Range Confirmation Lengthint10rangeLen
Use Volume Filter?boolfalseuse_volume_filter
Volume Multiplier (vs. SMA)float1.5volume_mult
Use Candle Body Size Filter?booltrueuse_body_filter
Min Body Size (x ATR)float0.7body_min_mult
Use Trailing Stop?boolfalseuse_trailing_stop
Trailing ATR Multiplierfloat1.5trail_atr_mult
Show all 17 settings
SettingTypeDefaultVariable
Use Time-Based Exit?boolfalseuse_time_exit
Exit After N Barsint20time_exit_bars
Trade DirectionstringBothtrade_direction
Stop Loss ATR Multiplierfloat1.5stop_loss_atr_mult
Take Profit ATR Multiplierfloat3.0take_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.

Similar Pine Scripts

BB and KC Strategy

by hasnocool
106 stars

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

Strategy v5 Volatility & bandsBreakout
Updated 2 years ago · GPL-3.0 GitHub repository of BB and KC Strategy

VOL/BBW/RSI/15 Strategy

by SammyEnigma
18 stars

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

Strategy v4 Volatility & bandsVolume
Updated 6 years ago · None stated GitHub repository of VOL/BBW/RSI/15 Strategy

BB Squeeze Breakout

by muammeryldrm42
7 stars

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

Strategy v5 Volatility & bandsBreakout
Updated 3 months ago · MIT GitHub repository of BB Squeeze Breakout

Bollinger Squeeze STEPFUN

by eltonaguiar
4 stars

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

Strategy v5 Volatility & bandsBreakout
Updated today · None stated GitHub repository of Bollinger Squeeze STEPFUN

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

Strategy v5 BreakoutVolatility & bands Repaints
Updated 10 months ago · MIT GitHub repository of Auto Breakout Strategy mit VIX Heatmap Gate
1 stars

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

Strategy v6 SMC / ICT / price actionVolatility & bands
Updated 4 months ago · None stated GitHub repository of Minervini VCP + SmartMCDX KLSE v8

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers