Pine Script v5 · Strategy
[EKIN] ATR Exit Strategy
A Pine Script v5 strategy built on EMA (close, 5), ATR (14) and Crossover (fastEMA, slowEMA). It has 4 order rules and no entry of its own. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays no commission. It has no settings.
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 [EKIN] ATR Exit Strategy repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did [EKIN] ATR Exit Strategy do on BTCUSDT 1D with default settings?
- +781.67%
- From 26 Jan 2024 to 21 Oct 2026, over 30 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does [EKIN] ATR Exit 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: 30 before, 0 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 [EKIN] ATR Exit Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does [EKIN] ATR Exit Strategy run in Zeal Terminal?
- Yes
- It compiles in 32 ms and runs 1,000 bars in 35 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- profit
- close
- stop_loss
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +781.67%
- $7,816.66
- Buy and hold
- +102.5%
- same period
- Closed trades
- 30
- 16 won · 14 lost
- Profitable
- 53.3%
- of closed trades
- Profit factor
- 1.07
- gross profit ÷ gross loss
- Max drawdown
- 2,960.79%
- −$43,870.40
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
The script declares no settings.
What it calculates
- EMAclose, 5
fastEMA · line 6 - EMAclose, 20
slowEMA · line 7 - ATR14
atr · line 8 - CrossoverfastEMA, slowEMA
enterCondition · line 21
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 |
|---|---|---|---|
| order buy long | (enterCondition and timePeriod and not InTrade) | On | 36 |
| order take_half_profit short | (takeProfitCondition and timePeriod and InTrade and not tookProfit) | On | 53 |
| order exit short | tookProfit | On | 58 |
| order stop_loss short | tookProfit | On | 60 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- 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 | +781.7% | +102.5% | 30 | 53% | 1.07 | 2,960.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −403.3% | +5.5% | 27 | 41% | 0.91 | 2,029.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +135.1% | +9.8% | 22 | 50% | 1.27 | 228.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +49.2% | +8.4% | 27 | 52% | 1.51 | 30.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +29.6% | +16.7% | 29 | 72% | 1.93 | 9.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.2% | +21.5% | 29 | 45% | 1.03 | 2.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −38.3% | +148.3% | 24 | 54% | 0.66 | 70.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +22.5% | +17.1% | 31 | 58% | 1.99 | 8.0% | 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 | 9 | 56% | $1,988.89 |
| Sideways market | 14 | 50% | −$4,151.25 |
| Falling market | 7 | 57% | $9,979.02 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
2,543.3%
The 95th percentile of the worst drawdown when the same 30 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 105.4% to 2,543.3%; the tick is what actually happened, 5,545.2%. Order luck alone moves it this much.
All 30 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 25 Mar 2024 67,210.00 | 4 Apr 2024 65,963.30 | 10 | −$2,493.46 |
| long | 16 May 2024 66,206.50 | 15 Jun 2024 66,044.00 | 30 | −$325.04 |
| long | 16 Jul 2024 64,724.10 | 2 Aug 2024 65,354.00 | 17 | $1,259.92 |
| long | 24 Aug 2024 64,037.20 | 2 Sep 2024 57,301.80 | 9 | −$13,470.90 |
| long | 14 Sep 2024 60,498.00 | 3 Oct 2024 60,649.30 | 19 | $302.56 |
| long | 7 Oct 2024 62,819.90 | 20 Oct 2024 68,378.00 | 13 | $5,558.08 |
| long | 7 Oct 2024 62,819.90 | 4 Nov 2024 68,776.00 | 28 | $5,956.08 |
| long | 5 Jan 2025 98,220.50 | 14 Jan 2025 94,536.10 | 9 | −$7,368.80 |
| long | 16 Jan 2025 100,497.00 | 4 Feb 2025 101,329.00 | 19 | $1,662.32 |
| long | 25 Mar 2025 87,498.20 | 7 Apr 2025 78,430.00 | 13 | −$18,136.30 |
| long | 14 Apr 2025 83,760.00 | 3 May 2025 96,887.10 | 19 | $13,127.10 |
| long | 14 Apr 2025 83,760.00 | 31 May 2025 103,985.00 | 47 | $20,225.50 |
| long | 10 Jun 2025 110,263.00 | 22 Jun 2025 102,120.00 | 12 | −$16,286.00 |
| long | 26 Jun 2025 107,341.00 | 12 Jul 2025 117,528.00 | 16 | $10,187.10 |
| long | 26 Jun 2025 107,341.00 | 16 Jul 2025 117,758.00 | 20 | $10,417.50 |
| long | 9 Aug 2025 116,675.00 | 19 Aug 2025 116,227.00 | 10 | −$895.38 |
| long | 11 Sep 2025 113,960.00 | 24 Sep 2025 111,999.00 | 13 | −$3,922.40 |
| long | 2 Oct 2025 118,595.00 | 6 Oct 2025 123,482.00 | 4 | $4,887.33 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$5,820.50 |
| long | 28 Oct 2025 114,108.00 | 31 Oct 2025 108,323.00 | 3 | −$11,569.60 |
| long | 12 Dec 2025 92,513.40 | 21 Jan 2026 88,427.70 | 40 | −$8,171.44 |
| long | 5 Mar 2026 72,666.80 | 20 Mar 2026 69,930.00 | 15 | −$5,473.52 |
| long | 26 Mar 2026 71,336.50 | 29 Mar 2026 66,377.00 | 3 | −$9,918.98 |
| long | 8 Apr 2026 71,924.20 | 27 Apr 2026 78,657.60 | 19 | $6,733.33 |
| long | 8 Apr 2026 71,924.20 | 17 May 2026 78,148.10 | 39 | $6,223.83 |
| long | 6 Jul 2026 63,650.00 | 2 Aug 2026 62,823.70 | 27 | −$1,652.72 |
| long | 7 Aug 2026 64,323.60 | 21 Aug 2026 73,027.00 | 14 | $8,703.41 |
| long | 7 Aug 2026 64,323.60 | 17 Sep 2026 76,206.00 | 41 | $11,882.40 |
| long | 19 Sep 2026 80,883.90 | 23 Sep 2026 86,208.60 | 4 | $5,324.71 |
| long | 19 Sep 2026 80,883.90 | 9 Oct 2026 81,754.50 | 20 | $870.60 |
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 |
|---|---|---|---|---|---|
| [EKIN] ATR Exit Strategy this page | — | v5 strategy | +781.7% | 30 | 2,960.8% |
| 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% |
| Keltner Breakout Strategy by Zeal Terminal | ema atr | v5 strategy | +3.5% | 21 | 2.3% |
| 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: 30 before, 0 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.
⋯// © ekinbasarkomur-//@version=5+//@version=6strategy("[EKIN] ATR Exit Strategy", overlay=true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, calc_on_every_tick = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 32 ms | Yes 1,000 bars in 35 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
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © ekinbasarkomur//@version=5strategy("[EKIN] ATR Exit Strategy", overlay=true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, calc_on_every_tick = true)// Simple EMA trackingfastEMA = ta.ema(close, 5)slowEMA = ta.ema (close, 20)atr = ta.atr(14)// We define entry price for future referencevar float entry_price = na// We define stop and take profit for future calculationsvar float stop_price = navar float take_profit_price = na// We define atr limtim its herevar float atr_down = navar float atr_up = navar float atr_current = navar float atr_ref = naavg = (low + high) / 2// ConditionsenterCondition = ta.crossover(fastEMA, slowEMA)var bool tookProfit = falsetimePeriod = time >= timestamp(syminfo.timezone, 2021, 12, 15, 0, 0)InTrade = strategy.position_size > 0// Go long if conditions are metif (enterCondition and timePeriod and not InTrade) // Calculate and update variables entry_price := avg atr_ref := atr atr_div = int((avg - entry_price) / atr_ref) atr_down := entry_price + (atr_ref * (atr_div - 1.5)) atr_up := entry_price + (atr_ref * (atr_div + 1)) atr_current := entry_price + (atr_ref * atr_div) stop_price := (entry_price - (atr_ref * 1.5)) take_profit_price := (entry_price + (atr_ref * 3)) strategy.order("buy", strategy.long, qty = 2)// Enter here if in positionif InTrade or tookProfit stopCondition = avg < stop_price takeProfitCondition = avg > take_profit_price if avg < atr_down stopCondition := true // Move stop price and exit price if price for each atr price increase if avg > atr_up if tookProfit atr_ref := atr atr_div = int((avg - entry_price) / atr_ref) atr_down := entry_price + (atr_ref * (atr_div - 1)) atr_up := entry_price + (atr_ref * (atr_div + 1)) atr_current := entry_price + (atr_ref * atr_div) // Take half of the investment if current price is 3 atr higher than entry price if (takeProfitCondition and timePeriod and InTrade and not tookProfit) strategy.order("take_half_profit", strategy.short, qty = 1) tookProfit := true // Exit position if conditions are met and reset the variables if (stopCondition and timePeriod and InTrade) if tookProfit strategy.order("exit", strategy.short, qty = 1) else strategy.order("stop_loss", strategy.short, qty = 2) tookProfit := false// Plot EMA'splot(fastEMA, color = color.blue)plot(slowEMA, color = color.yellow)// Plot ATR Limit/Stop positionsprofit_plot = plot(series = InTrade?atr_up:na, title = "profit", color = color.green, style=plot.style_linebr)close_plot = plot(series = InTrade?atr_current:na, title = "close", color = color.white, style=plot.style_linebr)stop_plot = plot(series = InTrade?atr_down:na, title = "stop_loss", color = color.red, style=plot.style_linebr)fill(profit_plot, close_plot, color = color.new(color.green, 80))fill(close_plot, stop_plot, color =color.new(color.red,80))