Strategy · Pine Script v6 · On the chart

Trend Breakout

by GammaExpansion

Trend Breakout is a price-chart strategy that builds a simple moving average and upper and lower bands from a multiple of standard deviation.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code41
Settings5inputs
LicenceMIT
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

41 lines of Pine Script v6 from apps/web/examples/trend-breakout.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

trend-breakout.pine
//@version=6
strategy("Trend Breakout", overlay = true,
     initial_capital = 100000,
     default_qty_type = strategy.percent_of_equity,
     default_qty_value = 50,
     commission_type = strategy.commission.percent,
     commission_value = 0.1)

length   = input.int(180, "Length", minval = 5, maxval = 200)
mult     = input.float(2.25, "Multiplier", minval = 0.25, maxval = 5.0, step = 0.25)
src      = input.source(close, "Source")
trailing = input.bool(false, "Use trailing stop")
trail    = input.float(3.0, "Trail %", minval = 0.25, maxval = 20.0, step = 0.25, group = "Risk")

basis = ta.sma(src, length)
dev   = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

longSignal  = ta.crossover(close, upper)
shortSignal = ta.crossunder(close, lower)

if longSignal
    strategy.entry("L", strategy.long)
if shortSignal
    strategy.entry("S", strategy.short)

if trailing and strategy.position_size != 0
    points = math.max(1, math.round(strategy.position_avg_price * trail / 100 / syminfo.mintick))
    strategy.exit("L trail", "L", trail_points = points, trail_offset = points)
    strategy.exit("S trail", "S", trail_points = points, trail_offset = points)

plot(basis, "Basis", color = color.teal, linewidth = 2)
plot(upper, "Upper", color = color.gray)
plot(lower, "Lower", color = color.gray)

// SPDX-License-Identifier: MIT
// Copyright (c) 2026 GammaExpansion
// Original OptiPine example. Spot candles also support simulated short positions here.
// Half-equity sizing leaves room for adverse moves without immediate margin liquidation.
// The optional trail activates after a Trail % gain and follows at that distance.

Overview

Trend Breakout enters long when close crosses above the upper band and short when close crosses below the lower band. Position size defaults to half of equity with a percentage commission. An optional trailing stop, off by default, exits after a percentage gain and follows at the same distance. There is no fixed stop loss or take profit. Length, multiplier, source, and trail percent are the main settings.

Details

Published by

GammaExpansion on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Lengthint180length
Multiplierfloat2.25mult
Sourcesourceclosesrc
Use trailing stopboolfalsetrailing
Trail %float3.0trail
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

106 stars

This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side. Entries also need ATR above a filter, a pullback check, a minimum candle-body chang

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 9:22 5 MIN 15 MIN BANKNIFTY

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 5 months ago · None stated GitHub repository of 均线突破交易系统
16 stars

This strategy plots Donchian channels, trailing stops, and profit targets directly on the price chart. It enters breakout trades using a 55-bar Donchian channel and sizes positions according to an ATR-based risk percentage per unit. The system adds units as pr

Strategy v6 TrendBreakout
Updated 12 months ago · None stated GitHub repository of Seykota Alt 10: Profit Targets
4 stars

This strategy executes trend-following trades based on Bollinger Band breakouts confirmed by a long-term moving average filter. A long position opens when the price crosses above the upper Bollinger Band, provided the band spread meets a minimum threshold and

Strategy v5 Volatility & bandsTrend
Updated 2 years ago · None stated GitHub repository of Bollinger Trend - Strategy V1
4 stars

The Keltner Channel Strategy is a breakout system plotted directly on the main price chart. It calculates upper and lower channel bands around an exponential or simple moving average using ATR, True Range, or bar range multiplied by a specified factor. A long

Strategy v5 TrendVolatility & bands
Updated 5 months ago · None stated GitHub repository of Keltner Channel Strategy

More Trend 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