Strategy · Pine Script v6 · On the chart

Breakout Strategy

by JoelPasapera

This strategy implements a channel breakout system directly on the main price chart.

View on GitHub

GitHub stars11on the repository
Pine versionv6current
Lines of code95
Settings8inputs
LicenceApache-2.0
Last update5 months ago23 May 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

95 lines of Pine Script v6 from Breakout Strategy/Breakout Strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

Breakout Strategy.pine
//@version=6
strategy("Breakout Strategy", 
     overlay=true, 
     default_qty_type=strategy.percent_of_equity, // 
     default_qty_value=10, // Invests 10% of capital per trade
     pyramiding=0) // Does not allow adding to an existing position 

// --- 1. INPUT PARAMETERS (Configurable by the user) ---
// Breakout parameter group
var group_channels = "Breakout channels"
int entryLength = input.int(20, "Entry breakout period", minval=2, group=group_channels)  
int exitLength = input.int(10, "Period for outbound breakout", minval=1, group=group_channels) 

// Grupo de Parámetros de Gestión de Riesgo
var group_risk = "Risk management and confirmation"
bool useSL = input.bool(true, "Use stop loss", group=group_risk) 
float slMultiplier = input.float(2.0, "ATR multiplier for stop loss", minval=0.1, group=group_risk)  

bool useTP = input.bool(true, "Use Take Profit", group=group_risk) 
float tpMultiplier = input.float(4.0, "ATR multiplier for Take Profit", minval=0.1, group=group_risk) 

int atrPeriod = input.int(14, "ATR period", minval=1, group=group_risk)  

// Wait for the candle to close
bool useBarConfirm = input.bool(true, "Wait for confirmation of the candle?", 
     tooltip="Wait for the candle to close before entering/exiting. This helps prevent repainting.", group=group_risk) 


// --- 2. CALCULATIONS ---
// Calculate the ATR for risk management
float atr = ta.atr(atrPeriod)  

// Calculate the input channels (we use [1] to refer to the *previous* candle)
float upperEntry = ta.highest(high, entryLength)[1] 
float lowerEntry = ta.lowest(low, entryLength)[1] 

// Calculate the output channels
float upperExit = ta.highest(high, exitLength)[1] 
float lowerExit = ta.lowest(low, exitLength)[1] 

// Confirmation status
// We use barstate.isconfirmed to prevent the strategy from operating in the middle of the candle. 
bool confirmation = useBarConfirm ? barstate.isconfirmed : true 


// --- 3. STRATEGY LOGIC ---
// Terms and Conditions of Entry
bool enterLong = (close > upperEntry) and confirmation  
bool enterShort = (close < lowerEntry) and confirmation  

// Exit Conditions (by opposite signal)
bool exitLong = (close < lowerExit) and confirmation
bool exitShort = (close > upperExit) and confirmation


// --- 4. EXECUTION OF ORDERS ---
// Calculate SL and TP levels
float entryPrice = strategy.position_avg_price 
float sl_long = entryPrice - (atr * slMultiplier)
float tp_long = entryPrice + (atr * tpMultiplier)
float sl_short = entryPrice + (atr * slMultiplier)
float tp_short = entryPrice - (atr * tpMultiplier)

// Entry
if (enterLong and strategy.position_size == 0) // Enter only if there is no open position 
    strategy.entry("Entrada Long", strategy.long)  

if (enterShort and strategy.position_size == 0) // Enter only if there is no open position 
    strategy.entry("Entrada Short", strategy.short) 

// Signal outputs
if (exitLong)
    strategy.close("Entrada Long", comment="Salida por Señal")  

if (exitShort)
    strategy.close("Entrada Short", comment="Salida por Señal")  

// Stop Loss and Take Profit Exits
if (strategy.position_size > 0) // If we are in a long trade 
    strategy.exit("Stop/Profit Long", 
         stop = useSL ? sl_long : na, 
         limit = useTP ? tp_long : na)  

if (strategy.position_size < 0) // If we are in a short trade   
    strategy.exit("Stop/Profit Short", 
         stop = useSL ? sl_short : na, 
         limit = useTP ? tp_short : na) 


// --- 5. PLOT (Visualization) ---
plot(upperEntry, "Upper Channel (Entrance)", color=color.new(color.green, 0))  
plot(lowerEntry, "Lower Channel (Entrance)", color=color.new(color.red, 0))  

plot(upperExit, "Upper Channel (Outlet)", color=color.new(color.green, 70), style=plot.style_circles, linewidth=2)  
plot(lowerExit, "Lower Channel (Outlet)", color=color.new(color.red, 70), style=plot.style_circles, linewidth=2)

Overview

Breakout Strategy calculates highest highs and lowest lows over configurable entry and exit periods using historical candles. A long entry triggers when the close breaks above the entry channel, while a short entry triggers when it drops below. Position exits occur via channel reversals or optional ATR-based stop-loss and take-profit targets. User settings control channel lengths, ATR multipliers, and bar confirmation.

Details

Published by

JoelPasapera on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Trend, Volatility & bands

Markets

Forex, Gold, Stocks

Timeframes

M1-M5, M15-H1, H4 and above

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.

Topics

botpinescriptstrategytradingtradingview

Settings

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

SettingTypeDefaultVariable
Entry breakout periodint20entryLength
Period for outbound breakoutint10exitLength
Use stop lossbooltrueuseSL
ATR multiplier for stop lossfloat2.0slMultiplier
Use Take ProfitbooltrueuseTP
ATR multiplier for Take Profitfloat4.0tpMultiplier
ATR periodint14atrPeriod
Wait for confirmation of the candle?booltrueuseBarConfirm
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

257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
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 4 months ago · None stated GitHub repository of 均线突破交易系统
16 stars

This trend-following strategy adapts classic Donchian breakout channels according to market volatility regimes. It calculates an ATR percentile rank across a rolling lookback period, shifting dynamically between tighter breakout channels with smaller stops dur

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 1: Adaptive Volatility

This strategy executes breakout trades using two Donchian Channels alongside an optional 200-period EMA trend filter. Entries trigger when the price sets a new highest high or lowest low over the primary Donchian Channel period. Exits are managed via a shorter

Strategy v5 BreakoutTrend
Updated 1 year ago · None stated GitHub repository of Ruckard Walcrypto DoubleDonchian B002

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