Pine Script v5 · Strategy
Keltner Breakout Strategy
A Pine Script v5 strategy built on EMA (close, 20), ATR (10) and Crossover (close, upper). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 10% of equity and pays 0.05% commission. 3 settings; defaults include EMA length 20, ATR length 10 and ATR multiplier 1.5.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Keltner Breakout Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
- How did Keltner Breakout Strategy do on BTCUSDT 1D with default settings?
- +3.54%
- From 26 Jan 2024 to 21 Oct 2026, over 21 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does Keltner Breakout Strategy have?
- 1
- Breakout.
- Does Keltner Breakout Strategy run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 21 before, 21 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Keltner Breakout Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 22.
BTCUSDT · 1D · default settings
- Basis
- Upper
- Lower
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +3.54%
- $353.85
- Buy and hold
- +102.5%
- same period
- Closed trades
- 21
- 6 won · 15 lost
- Profitable
- 28.6%
- of closed trades
- Profit factor
- 1.81
- gross profit ÷ gross loss
- Max drawdown
- 2.33%
- −$243.63
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
Nothing to point out.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| EMA length | 20 | int · min 1 | basis |
| ATR length | 10 | int · min 1 | atr |
| ATR multiplier | 1.5 | float · min 0.1 · step 0.1 | upper lower |
What it calculates
- EMAclose, EMA length (20)
basis · line 12 - ATRATR length (10)
atr · line 13 - Crossoverclose, upper
breakout · line 17
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | breakout | On | 20 |
| Exit Trail stop | strategy.position_size > 0 | On | 22 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Breakout | alertcondition | Close crossed above the upper Keltner channel | 29 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +3.5% | +102.5% | 21 | 29% | 1.81 | 2.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.4% | +5.5% | 13 | 23% | 2.06 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.3% | +9.8% | 18 | 39% | 1.20 | 4.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.9% | +8.4% | 12 | 33% | 3.25 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +2.3% | +16.7% | 20 | 40% | 1.36 | 4.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.9% | +21.5% | 15 | 47% | 2.23 | 0.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.5% | +148.3% | 21 | 38% | 0.92 | 3.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.4% | +17.1% | 17 | 35% | 2.30 | 0.5% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 8 | 38% | $354.28 |
| Sideways market | 11 | 18% | $30.34 |
| Falling market | 2 | 50% | −$30.78 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
3.1%
The 95th percentile of the worst drawdown when the same 21 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.3% to 3.1%; the tick is what actually happened, 2.2%. Order luck alone moves it this much.
All 21 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 25 Feb 2024 51,568.20 | 16 Mar 2024 65,282.60 | 20 | $264.68 |
| long | 21 May 2024 71,446.60 | 31 May 2024 67,211.70 | 10 | −$61.81 |
| long | 16 Jul 2024 64,724.10 | 25 Jul 2024 63,748.80 | 9 | −$16.38 |
| long | 20 Sep 2024 62,948.00 | 1 Oct 2024 62,700.10 | 11 | −$5.03 |
| long | 15 Oct 2024 66,084.00 | 23 Oct 2024 65,474.30 | 8 | −$10.40 |
| long | 29 Oct 2024 69,962.20 | 3 Nov 2024 68,184.20 | 5 | −$26.84 |
| long | 7 Nov 2024 75,572.00 | 5 Dec 2024 93,355.50 | 28 | $237.46 |
| long | 16 Dec 2024 104,464.00 | 19 Dec 2024 99,620.60 | 3 | −$49.12 |
| long | 18 Jan 2025 104,077.00 | 27 Jan 2025 101,266.00 | 9 | −$28.92 |
| long | 23 Apr 2025 93,443.00 | 29 May 2025 105,508.00 | 36 | $131.88 |
| long | 10 Jun 2025 110,263.00 | 12 Jun 2025 106,231.00 | 2 | −$39.16 |
| long | 11 Jul 2025 116,010.00 | 25 Jul 2025 115,956.00 | 14 | −$1.52 |
| long | 14 Aug 2025 123,306.00 | 15 Aug 2025 117,531.00 | 1 | −$49.68 |
| long | 2 Oct 2025 118,595.00 | 10 Oct 2025 118,503.00 | 8 | −$1.83 |
| long | 6 Jan 2026 93,859.70 | 8 Jan 2026 90,004.80 | 2 | −$43.47 |
| long | 14 Jan 2026 95,414.00 | 19 Jan 2026 92,579.90 | 5 | −$31.59 |
| long | 17 Mar 2026 74,884.70 | 18 Mar 2026 70,530.80 | 1 | −$60.67 |
| long | 14 Apr 2026 74,418.00 | 29 Apr 2026 75,419.10 | 15 | $12.70 |
| long | 5 May 2026 79,861.00 | 13 May 2026 79,043.90 | 8 | −$11.47 |
| long | 20 Aug 2026 69,334.80 | 10 Sep 2026 77,042.40 | 21 | $112.35 |
| long | 19 Sep 2026 80,883.90 | 7 Oct 2026 83,527.70 | 18 | $32.67 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Keltner Breakout Strategy this page | — | v5 strategy | +3.5% | 21 | 2.3% |
| Trend Reversal - Potential pressure by BardiaB2 | atr ema | v4 strategy | +133,960.0% | 5 | 1,504.8% |
| Simple Ema_ATR Strategy HulkTrading by TheHulkTrading | ema atr | v4 strategy | +2.2% | 14 | 15.6% |
| [EKIN] ATR Exit Strategy by ekinbasarkomur | ema atr | v5 strategy | +781.7% | 30 | 2,960.8% |
| DEMA-EMA & VOLATILITY (VAMS) by Qorbanjf | ema atr | v4 strategy | +2,833,450.0% | 19 | 15,721.0% |
| Super Z strategy - Thanks to Rafael Zioni by 03.freeman | ema atr | v4 strategy | −404,823.0% | 56 | 2,951,790.0% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 21 before, 21 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Zeal Terminal-//@version=5+//@version=6strategy("Keltner Breakout Strategy", shorttitle = "Keltner Breakout", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 10 ms | Yes 1,000 bars in 26 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Written by Zeal Terminal and published under the Mozilla Public License 2.0.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5strategy("Keltner Breakout Strategy", shorttitle = "Keltner Breakout", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1) // Not investment advice. Buys a close above the upper Keltner channel and// trails a stop at the channel basis.length = input.int(20, "EMA length", minval = 1)atrLen = input.int(10, "ATR length", minval = 1)mult = input.float(1.5, "ATR multiplier", minval = 0.1, step = 0.1) basis = ta.ema(close, length)atr = ta.atr(atrLen)upper = basis + mult * atrlower = basis - mult * atr breakout = ta.crossover(close, upper) if breakout strategy.entry("Long", strategy.long)if strategy.position_size > 0 strategy.exit("Trail", "Long", stop = basis) plot(basis, "Basis", color = #ffb74d)u = plot(upper, "Upper", color = #26a69a)l = plot(lower, "Lower", color = #ef5350)fill(u, l, color = color.new(#42a5f5, 94), title = "Channel") alertcondition(breakout, "Breakout", "Close crossed above the upper Keltner channel")