Strategy · Pine Script v5 · On the chart

Donchian Channel Breakout - Eterna

by EternaHybridExchange

This strategy plots Donchian Channel bands, a middle line, and breakout signals directly on the price chart.

View on GitHub

GitHub stars9on the repository
Pine versionv5runs as is
Lines of code64
Settings6inputs
LicenceMIT
Last update7 months ago12 Mar 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

64 lines of Pine Script v5 from strategies/trend-following/donchian-channel/strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

strategy.pine
//@version=5
strategy("Donchian Channel Breakout - Eterna", 
         overlay=true, 
         initial_capital=10000,
         default_qty_type=strategy.percent_of_equity, 
         default_qty_value=10,
         commission_type=strategy.commission.percent,
         commission_value=0.075)

// ==================== Parameters ====================
channelLength = input.int(20, "Channel Length", minval=1)
breakoutConfirm = input.int(1, "Breakout Confirmation Bars", minval=0, maxval=5)
useMiddleLine = input.bool(true, "Exit at Middle Line")
leverage = input.int(5, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, step=0.001)

webhookMessage = input.string('{"action":"{{strategy.order.action}}", "symbol":"{{ticker}}", "size":' + str.tostring(positionSize) + ', "leverage":' + str.tostring(leverage) + '}', 
                               "Webhook JSON", group="Webhook")

// ==================== Donchian Channel Calculation ====================
upperBand = ta.highest(high, channelLength)
lowerBand = ta.lowest(low, channelLength)
middleLine = (upperBand + lowerBand) / 2

// ==================== Entry Conditions ====================
// Breakout above upper band
longBreakout = close > upperBand[breakoutConfirm]
longCondition = longBreakout and not longBreakout[1]

// Breakdown below lower band
shortBreakout = close < lowerBand[breakoutConfirm]
shortCondition = shortBreakout and not shortBreakout[1]

// Exit conditions
exitLong = useMiddleLine ? ta.crossunder(close, middleLine) : ta.crossunder(close, lowerBand)
exitShort = useMiddleLine ? ta.crossover(close, middleLine) : ta.crossover(close, upperBand)

// ==================== Strategy Execution ====================
if longCondition
    strategy.entry("Long", strategy.long, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "buy"))

if shortCondition
    strategy.entry("Short", strategy.short, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "sell"))

if exitLong
    strategy.close("Long", alert_message='{"action":"close", "symbol":"{{ticker}}"}')

if exitShort
    strategy.close("Short", alert_message='{"action":"close", "symbol":"{{ticker}}"}')

// ==================== Plotting ====================
upperPlot = plot(upperBand, "Upper Band", color=color.green, linewidth=2)
lowerPlot = plot(lowerBand, "Lower Band", color=color.red, linewidth=2)
plot(middleLine, "Middle Line", color=color.blue, linewidth=1, style=plot.style_circles)

// Fill channel
fill(upperPlot, lowerPlot, color=color.new(color.blue, 95))

// Entry signals
plotshape(longCondition, "Long Breakout", shape.triangleup, location.belowbar, color.green, size=size.normal)
plotshape(shortCondition, "Short Breakdown", shape.triangledown, location.abovebar, color.red, size=size.normal)

// Highlight breakout zones
bgcolor(close > upperBand ? color.new(color.green, 90) : close < lowerBand ? color.new(color.red, 90) : na)

Overview

Donchian Channel Breakout - Eterna opens long positions when price breaks above the upper band and short positions when price breaks below the lower band, evaluated after confirmation bars. Positions exit when price crosses the middle line, or the opposite band if middle line exits are disabled. Inputs configure channel period, confirmation bars, middle line exit logic, and webhook order values. Notably, the strategy lacks a defined stop loss or take profit.

Details

Published by

EternaHybridExchange on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Breakout

Markets

Crypto

Timeframes

H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingautomated-tradingbacktestingbybitcrypto-tradingeternamcppine-scripttrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Channel Lengthint20channelLength
Breakout Confirmation Barsint1breakoutConfirm
Exit at Middle LinebooltrueuseMiddleLine
Leverageint5leverage
Position Sizefloat0.01positionSize
Webhook JSONstring'{"action":"{{strategy.order.action}}", "symbol":"{{ticker}}webhookMessage
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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated today · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
257 stars

This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar

12/26-IT Strategy

by hasnocool
106 stars

This strategy executes trades based on crossovers between a 12-period and a 26-period exponential moving average (EMA). Long positions can be filtered by pivot resistance breakouts and RSI boundary ranges. For trade management, it provides two configurable par

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 12/26-IT Strategy

均线突破交易系统

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 均线突破交易系统
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy

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