Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (0)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,679$2,025Equity from $1,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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, 5fastEMA · line 6
  • EMAclose, 20slowEMA · line 7
  • ATR14atr · line 8
  • CrossoverfastEMA, slowEMAenterCondition · 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.

closecloseprice datahigh · low · closehigh · low · closeprice datahighhighprice datalowlowprice datatimetimeprice datafastEMAEMA→ fastEMAslowEMAEMA→ slowEMAatrATR→ atrenterConditionCrossover→ enterConditionentry_priceentry_pricevaluestop_price, take_profit_pricestop_price · take_profi…2 valuesatr_down, atr_up, atr_currentatr_down · atr_up +13 valuesatr_refatr_refvalueavgavgvalueatr_divatr_divvaluetimePeriodtimePeriodconditionInTradeInTradeconditiontakeProfitConditiontakeProfitConditionconditionstopConditionstopConditionconditionorder:buyorder buystrategy.orderorder:take_half_profitorder take_half_profitstrategy.orderorder:exitorder exitstrategy.orderorder:stop_lossorder stop_lossstrategy.orderplot:63plotplotplot:64plotplotplot:66profitplotplot:67closeplotplot:68stop_lossplotfill:69Fillfill × 2fill:70Fillfill × 2

Order rules

OrderFires whenBy defaultLine
order buy long(enterCondition and timePeriod and not InTrade)On36
order take_half_profit short(takeProfitCondition and timePeriod and InTrade and not tookProfit)On53
order exit shorttookProfitOn58
order stop_loss shorttookProfitOn60

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.

9/9trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. On 0 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+781.7%+102.5%3053%1.072,960.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−403.3%+5.5%2741%0.912,029.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+135.1%+9.8%2250%1.27228.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+49.2%+8.4%2752%1.5130.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+29.6%+16.7%2972%1.939.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.2%+21.5%2945%1.032.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−38.3%+148.3%2454%0.6670.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+22.5%+17.1%3158%1.998.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 barsTradesWonP&L
Rising market956%$1,988.89
Sideways market1450%−$4,151.25
Falling market757%$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.

0%6,377%
All 30 trades
SideEntryExitBarsP&L
long25 Mar 2024 67,210.004 Apr 2024 65,963.3010−$2,493.46
long16 May 2024 66,206.5015 Jun 2024 66,044.0030−$325.04
long16 Jul 2024 64,724.102 Aug 2024 65,354.0017$1,259.92
long24 Aug 2024 64,037.202 Sep 2024 57,301.809−$13,470.90
long14 Sep 2024 60,498.003 Oct 2024 60,649.3019$302.56
long7 Oct 2024 62,819.9020 Oct 2024 68,378.0013$5,558.08
long7 Oct 2024 62,819.904 Nov 2024 68,776.0028$5,956.08
long5 Jan 2025 98,220.5014 Jan 2025 94,536.109−$7,368.80
long16 Jan 2025 100,497.004 Feb 2025 101,329.0019$1,662.32
long25 Mar 2025 87,498.207 Apr 2025 78,430.0013−$18,136.30
long14 Apr 2025 83,760.003 May 2025 96,887.1019$13,127.10
long14 Apr 2025 83,760.0031 May 2025 103,985.0047$20,225.50
long10 Jun 2025 110,263.0022 Jun 2025 102,120.0012−$16,286.00
long26 Jun 2025 107,341.0012 Jul 2025 117,528.0016$10,187.10
long26 Jun 2025 107,341.0016 Jul 2025 117,758.0020$10,417.50
long9 Aug 2025 116,675.0019 Aug 2025 116,227.0010−$895.38
long11 Sep 2025 113,960.0024 Sep 2025 111,999.0013−$3,922.40
long2 Oct 2025 118,595.006 Oct 2025 123,482.004$4,887.33
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$5,820.50
long28 Oct 2025 114,108.0031 Oct 2025 108,323.003−$11,569.60
long12 Dec 2025 92,513.4021 Jan 2026 88,427.7040−$8,171.44
long5 Mar 2026 72,666.8020 Mar 2026 69,930.0015−$5,473.52
long26 Mar 2026 71,336.5029 Mar 2026 66,377.003−$9,918.98
long8 Apr 2026 71,924.2027 Apr 2026 78,657.6019$6,733.33
long8 Apr 2026 71,924.2017 May 2026 78,148.1039$6,223.83
long6 Jul 2026 63,650.002 Aug 2026 62,823.7027−$1,652.72
long7 Aug 2026 64,323.6021 Aug 2026 73,027.0014$8,703.41
long7 Aug 2026 64,323.6017 Sep 2026 76,206.0041$11,882.40
long19 Sep 2026 80,883.9023 Sep 2026 86,208.604$5,324.71
long19 Sep 2026 80,883.909 Oct 2026 81,754.5020$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.

ScriptSharesTypeNetTradesMax drawdown
[EKIN] ATR Exit Strategy this page—v5 strategy+781.7%302,960.8%
Trend Reversal - Potential pressure by BardiaB2atr emav4 strategy+133,960.0%51,504.8%
Simple Ema_ATR Strategy HulkTrading by TheHulkTradingema atrv4 strategy+2.2%1415.6%
Keltner Breakout Strategy by Zeal Terminalema atrv5 strategy+3.5%212.3%
DEMA-EMA & VOLATILITY (VAMS) by Qorbanjfema atrv4 strategy+2,833,450.0%1915,721.0%
Super Z strategy - Thanks to Rafael Zioni by 03.freemanema atrv4 strategy−404,823.0%562,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

Verified

Nothing 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 32 msYes 1,000 bars in 35 msNot measured
PineTSNot testedNot testedNot 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))