Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

action zone - ATR stop reverse order strategy v0.1 by 9nck

A Pine Script v5 strategy built on EMA (close, 12) and ATR (14). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 25% of equity and pays 0.01% commission. 14 settings; defaults include Fast MA Period 12, Slow MA Period 26 and ATR length 14.

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 action zone - ATR stop reverse order strategy v0.1 by 9nck repaint?
No
No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
How did action zone - ATR stop reverse order strategy v0.1 by 9nck do on BTCUSDT 1D with default settings?
−5.61%
From 26 Jan 2024 to 21 Oct 2026, over 32 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does action zone - ATR stop reverse order strategy v0.1 by 9nck 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: 32 before, 34 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 action zone - ATR stop reverse order strategy v0.1 by 9nck use a stop loss?
Yes
strategy.exit sets a stop on line 97, 101.
Does action zone - ATR stop reverse order strategy v0.1 by 9nck run in Zeal Terminal?
Yes
It compiles in 37 ms and runs 1,000 bars in 94 ms, in the browser.

BTCUSDT · 1D · default settings

  • fast ema line
  • slow ema line
  • ATR Upperline1
  • ATR Lowerline1
  • ATR Upperline2
  • ATR Lowerline2
  • ATR Upperline3
  • ATR Lowerline3
  • Plot
  • Plot
  • 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 (14)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$2,832$6,076Equity from $3,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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
−5.61%
−$168.42
Buy and hold
+102.5%
same period
Closed trades
32
10 won · 22 lost
Profitable
31.3%
of closed trades
Profit factor
0.81
gross profit ÷ gross loss
Max drawdown
14.59%
−$437.74

One run with the author's default settings, $3,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.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses an argument v6 removed

    when = on line 81, 87. The upgraded version below moves each call inside an if block.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Fast MA Period12int · min 2 · step 1fastEma
Slow MA Period26int · min 2 · step 1slowEma
ATR length14int · min 2 · step 1atr
atr inner multiplier1float · min 0.1 · step 0.1ATR Upperline1 ATR Lowerline1
atr middle multiplier2float · min 0.1 · step 0.1longStopPrice shortStopPrice overBand underBand ATR Upperline2 ATR Lowerline2 line 95 line 99
atr outer multiplier3float · min 0.1 · step 0.1ATR Upperline3 ATR Lowerline3
Start Year2021int · min 1900 · max 2100 · step 1startDate
Start Month12int · min 1 · max 12 · step 1startDate
Start Day1int · min 1 · max 31 · step 1startDate
Using Specific End Test Datefalseboolline 27
End Year2022int · min 1900 · max 2100 · step 1endDate
End Month1int · min 1 · max 12 · step 1endDate
End Day31int · min 1 · max 31 · step 1endDate
Minimum position Hold Limit8int · min 1 · max 365 · step 1minHoldPeriod fill

What it calculates

  • EMAclose, Fast MA Period (12)fastEma · line 34
  • EMAclose, Slow MA Period (26)slowEma · line 35
  • ATRATR length (14)atr · line 36

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 datafastMaInputFast MA Periodsetting · 12slowMaInputSlow MA Periodsetting · 26high · low · closehigh · low · closeprice dataatrLengthInputATR lengthsetting · 14startYearInputStart Yearsetting · 2021startMonthInputStart Monthsetting · 12startDateInputStart Daysetting · 1endYearInputEnd Yearsetting · 2022endMonthInputEnd Monthsetting · 1endDateInputEnd Daysetting · 31lowlowprice dataatrMidMultInputatr middle multipliersetting · 2highhighprice dataminHoldInputMinimum position Hold L…setting · 8timetimeprice dataatrInnerMultInputatr inner multipliersetting · 1atrOuterMultInputatr outer multipliersetting · 3fastEmaEMA→ fastEmaslowEmaEMA→ slowEmaatrATR→ atrstartDatestartDatevalueendDateendDatevaluehold_lengthhold_lengthvaluelongStopPricelongStopPricevalueshortStopPriceshortStopPricevalueminHoldPeriodminHoldPeriodvaluegoLonggoLongconditiongoShortgoShortconditioninDateRangeinDateRangeconditionisBullish, isBearishisBullish · isBearish2 conditionsgreenLong, yellowLonggreenLong · yellowLong2 conditionsblueShort, redShortblueShort · redShort2 conditionsoverBandoverBandconditionunderBandunderBandconditioninPositioninPositionconditionREDBEAR, GREENBULL, barColor, nightTimeColourREDBEAR · GREENBULL +2entry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryclose:longClose longstrategy.closeclose:shortClose shortstrategy.closeexit:Long Stop atr exit Long Stop atr strategy.exitexit:Short Stop atr exit Short Stop atr strategy.exitplot:103fast ema lineplotplot:104slow ema lineplotplot:105ATR Upperline1plotplot:106ATR Lowerline1plotplot:107ATR Upperline2plotplot:108ATR Lowerline2plotplot:109ATR Upperline3plotplot:110ATR Lowerline3plotplot:111plotplotplot:112plotplotfill:114Fillfill × 2fill:115Fillfill × 2barcolor:122barcolorbarcolorbgcolor:125bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open long longgoLong or reverseToLongOn69
Open short shortgoShort or reverseToShortOn74
Close longgoShortisBearish and isBearish[1] == 0On81
Close shortgoLongisBullish and isBullish[1] == 0On87
Exit Long Stop atr stopstrategy.position_size > 0On97
Exit Short Stop atr stopstrategy.position_size < 0On101

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source.

Not measuredAn engine gap, not the scriptThe script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script. The answer comes from the checks on the source alone.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−5.6%+102.5%3231%0.8114.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1.5%+5.5%3628%0.895.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+22.3%+9.8%2941%1.5610.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+6.0%+8.4%2330%1.603.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+9.6%+16.7%2836%1.2414.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+7.6%+21.5%2839%1.643.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−9.6%+148.3%3231%0.7318.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+5.6%+17.1%3540%1.654.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 market838%$34.00
Sideways market1625%−$309.31
Falling market838%$106.90

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

18.7%

The 95th percentile of the worst drawdown when the same 32 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 9.2% to 18.7%; the tick is what actually happened, 14.5%. Order luck alone moves it this much.

0%22%
All 32 trades
SideEntryExitBarsP&L
short16 Apr 2024 63,420.0017 May 2024 67,380.0031−$46.99
long18 May 2024 67,024.0014 Jun 2024 65,358.3027−$18.49
short15 Jun 2024 66,044.001 Jul 2024 63,369.8016$29.56
long2 Jul 2024 62,900.004 Jul 2024 58,854.802−$47.80
long19 Jul 2024 63,987.902 Aug 2024 61,435.8014−$29.22
short3 Aug 2024 61,498.3025 Aug 2024 64,157.0022−$31.35
long26 Aug 2024 64,220.004 Sep 2024 56,401.509−$87.05
short5 Sep 2024 57,970.9019 Sep 2024 61,760.0014−$45.38
long20 Sep 2024 62,948.003 Oct 2024 59,836.4013−$33.79
short4 Oct 2024 60,752.7014 Oct 2024 65,867.4010−$56.75
long15 Oct 2024 66,084.0031 Oct 2024 69,760.0016$36.48
short30 Dec 2024 93,738.2017 Jan 2025 99,987.3018−$44.62
long18 Jan 2025 104,077.003 Feb 2025 94,625.6016−$59.71
short4 Feb 2025 101,329.002 Mar 2025 86,064.5026$96.47
long20 Apr 2025 85,077.0012 May 2025 102,819.0022$138.60
short22 Jun 2025 102,120.003 Jul 2025 110,410.0011−$56.97
long4 Jul 2025 109,585.0016 Jul 2025 117,758.0012$51.00
short21 Aug 2025 114,271.0012 Sep 2025 116,540.0022−$14.01
long13 Sep 2025 116,029.0025 Sep 2025 110,906.0012−$30.83
short26 Sep 2025 108,994.001 Oct 2025 116,898.005−$49.98
long2 Oct 2025 118,595.0010 Oct 2025 114,327.008−$24.42
short16 Oct 2025 110,763.0011 Nov 2025 107,299.0026$20.78
long12 Nov 2025 103,059.0014 Nov 2025 97,373.702−$37.31
long6 Jan 2026 93,859.7020 Jan 2026 88,926.1014−$35.06
short21 Jan 2026 88,427.708 Feb 2026 71,751.3018$123.56
long16 Mar 2026 72,815.3027 Mar 2026 68,820.3011−$37.81
short28 Mar 2026 66,407.307 Apr 2026 72,725.1010−$64.57
long8 Apr 2026 71,924.2018 May 2026 76,092.7040$38.18
short19 May 2026 77,001.907 Jun 2026 63,978.0019$113.31
long16 Jul 2026 64,756.302 Aug 2026 62,823.7017−$21.00
short3 Aug 2026 63,570.0019 Aug 2026 66,070.0016−$27.42
long20 Aug 2026 69,334.8029 Aug 2026 77,845.909$84.17

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
action zone - ATR stop reverse order strategy v0.1 by 9nck this page—v5 strategy−5.6%3214.6%
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%
[EKIN] ATR Exit Strategy by ekinbasarkomurema atrv5 strategy+781.7%302,960.8%
DEMA-EMA & VOLATILITY (VAMS) by Qorbanjfema atrv4 strategy+2,833,450.0%1915,721.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.

  • 2 strategy calls use the when = argument (line 81, 87). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 32 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 81: when = goShort → if block
  • Line 87: when = goLong → if block
⋯        // if exit position by Sellcondition(which is the same as ShortCondition), Exit Long position and make Short order(by set reverse order to true)-        strategy.close('long', when=goShort, comment='exitLong(' + str.tostring(hold_length) + ')')+        if goShort+            strategy.close('long', comment='exitLong(' + str.tostring(hold_length) + ')')        reverseToShort := true⋯    else if strategy.position_size < 0-        strategy.close('short', when=goLong, comment='exitShort(' + str.tostring(hold_length) + ')')+        if goLong+            strategy.close('short', comment='exitShort(' + str.tostring(hold_length) + ')')        reverseToLong := true⋯

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: 32 before, 34 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.

⋯// © fenirlix-//@version=5+//@version=6// Strategy parameter incl. position size, commission and initial capital⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 37 msWith a workaround 1,000 bars in 94 msNot measured
PineTSNot testedNot testedNot measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © fenirlix//@version=5// Strategy parameter incl. position size, commission and initial capitalstrategy("ACTIONZONE-ATR REVERSEORDER STRATEGY", "ACTIONZONEATR-REVERSEORDER", overlay=true     ,default_qty_type=strategy.percent_of_equity, default_qty_value=25     ,commission_type='strategy.commission_percent', commission_value=0.01     ,initial_capital=3000)// User Input VariablefastMaInput     = input.int(12, "Fast MA Period", minval=2, step=1)slowMaInput     = input.int(26, "Slow MA Period", minval=2, step=1)atrLengthInput  = input.int(14, "ATR length", minval=2,step=1)atrInnerMultInput = input.float(1, "atr inner multiplier", minval=0.1, step=0.1)atrMidMultInput = input.float(2, "atr middle multiplier", minval=0.1, step=0.1) //***** MOST OF RISK MANAGEMENT LOGIC BASE ON THIS INPUT *****//atrOuterMultInput = input.float(3, "atr outer multiplier", minval=0.1, step=0.1)// Backtesting Date rangestartYearInput      = input.int(2021, "Start Year", minval=1900, maxval=2100, step=1)startMonthInput     = input.int(12, "Start Month", minval=1, maxval=12, step=1)startDateInput      = input.int(1, "Start Day", minval=1, maxval=31, step=1)setEndRangeInput    = input.bool(false, "Using Specific End Test Date") //Set specific End date or use present(end of candle) dataendYearInput        = input.int(2022, "End Year", minval=1900, maxval=2100, step=1)endMonthInput       = input.int(1, "End Month", minval=1, maxval=12, step=1)endDateInput        = input.int(31, "End Day", minval=1, maxval=31, step=1)startDate = timestamp(syminfo.timezone, startYearInput, startMonthInput, startDateInput)endDate = timestamp(syminfo.timezone, endYearInput, endMonthInput, endDateInput)inDateRange = time >= startDate //Set backtest date range to present dataif setEndRangeInput    inDateRange and time <= endDate //set backtest date range to specific date// minimum position hold period (to get rid of false signal in sideway trend)minHoldInput = input.int(8, 'Minimum position Hold Limit', minval=1, maxval=365, step=1) // Set Minimum Position Holdvar bool reverseToLong = false // Assign reverse order operatorvar bool reverseToShort = false // Assign reverse order operator// Indicator DeclarationfastEma = ta.ema(close, fastMaInput)slowEma = ta.ema(close, slowMaInput)atr = ta.atr(atrLengthInput)// Declare trend of assetisBullish = fastEma > slowEmaisBearish = fastEma <= slowEma// Record position hold length, to limit minimum hold period(candle)var int hold_length = 0if strategy.opentrades > 0 or strategy.opentrades < 0    hold_length := hold_length + 1else    hold_length := 0// create permanent variable of stop pricevar float longStopPrice = navar float shortStopPrice = na    // Chart-Indicator COLOR declarationREDBEAR     = color.new(color.red, 80)GREENBULL   = color.new(color.green, 80)greenLong = isBullish and close > fastEmayellowLong = isBullish and close < fastEmablueShort = isBearish and close > fastEmaredShort = isBearish and close < fastEma// assign oversold, overbought condition(in this case, price over middle atr plus/minus fastEma)overBand = high[1] > fastEma + (atrMidMultInput * atr)underBand = low[1] < fastEma - (atrMidMultInput * atr)// Strategy// Main Entry ConditiongoLong = isBullish and isBullish[1] == 0goShort = isBearish and isBearish[1] == 0inPosition = strategy.position_size != 0minHoldPeriod = hold_length > minHoldInput ? true : false// Entry Conditionif not inPosition and inDateRange and barstate.isconfirmed == true //compute after close of the bar to avoid repainting    if goLong or reverseToLong // Long if longcondition or reverse order receive.        strategy.entry('long', strategy.long)        longStopPrice := fastEma - (atr * atrMidMultInput) // Set stop loss price        reverseToLong := false // Reset reverse order status        else if goShort or reverseToShort        strategy.entry('short', strategy.short)        shortStopPrice := fastEma + (atr * atrMidMultInput)        reverseToShort := false// Take profit and Set Higher Stop if inPosition and minHoldPeriod and barstate.isconfirmed == true // check if we're in position and pass minimum hold period, confirm no repainting    if strategy.position_size > 0        // if exit position by Sellcondition(which is the same as ShortCondition), Exit Long position and make Short order(by set reverse order to true)        strategy.close('long', when=goShort, comment='exitLong(' + str.tostring(hold_length) + ')')        reverseToShort := true        if overBand //If overbought condition met, set Stop price to LAST LOW, and not reverse any position            longStopPrice := low[1]            reverseToShort := false    else if strategy.position_size < 0        strategy.close('short', when=goLong, comment='exitShort(' + str.tostring(hold_length) + ')')        reverseToLong := true        if underBand            shortStopPrice := high[1]            reverseToLong := false// Stop Loss and Set calculate stop loss using Atr Channelif inPosition     if strategy.position_size > 0        if fastEma - (atr * atrMidMultInput) > longStopPrice // set long stop price to the higher of latest long stop price and ATR lower channel            longStopPrice := fastEma - (atr * atrMidMultInput)        strategy.exit('Long Stop atr ', 'long', stop=longStopPrice)    else if strategy.position_size < 0        if fastEma + (atr * atrMidMultInput) < shortStopPrice            shortStopPrice := fastEma + (atr * atrMidMultInput)        strategy.exit('Short Stop atr ', 'short', stop=shortStopPrice)// PlottingfastLine = plot(fastEma, title='fast ema line', linewidth=1, color=isBullish ? color.green : color.red)slowLine = plot(slowEma, title='slow ema line', linewidth=2, color= isBullish? color.green : color.red)atrUpperLine1 = plot(fastEma + (atr * atrInnerMultInput), title='ATR Upperline1', color=color.new(color.black,85))atrLowerLine1 = plot(fastEma - (atr * atrInnerMultInput), title='ATR Lowerline1', color=color.new(color.black,85))atrUpperLine2 = plot(fastEma + (atr * atrMidMultInput), title='ATR Upperline2', color=color.new(color.black,75))atrLowerLine2 = plot(fastEma - (atr * atrMidMultInput), title='ATR Lowerline2', color=color.new(color.black,75))atrUpperLine3 = plot(fastEma + (atr * atrOuterMultInput), title='ATR Upperline3', color=color.new(color.black,50))atrLowerLine3 = plot(fastEma - (atr * atrOuterMultInput), title='ATR Lowerline3', color=color.new(color.black,50))plot(longStopPrice, color=strategy.position_size > 0 ? color.blue : na, linewidth=2)plot(shortStopPrice, color=strategy.position_size < 0 ? color.blue : na, linewidth=2)//  Fillingfill(fastLine, slowLine, color=isBullish ? GREENBULL : REDBEAR)fill(atrUpperLine3, atrLowerLine3, color=inPosition and (minHoldInput - hold_length > 0) ? color.new(color.blue,90): na)barColor = switch    greenLong => color.green    yellowLong =>  color.yellow    blueShort => color.blue    redShort => color.red    => color.blackbarcolor(color=barColor)// Fill background to distinguish inactive time(Zulu time)nightTime = time(timeframe.period, "1500-0100") ? color.new(color.black, 95): nabgcolor(nightTime)