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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Fast MA Period | 12 | int · min 2 · step 1 | fastEma |
| Slow MA Period | 26 | int · min 2 · step 1 | slowEma |
| ATR length | 14 | int · min 2 · step 1 | atr |
| atr inner multiplier | 1 | float · min 0.1 · step 0.1 | ATR Upperline1 ATR Lowerline1 |
| atr middle multiplier | 2 | float · min 0.1 · step 0.1 | longStopPrice shortStopPrice overBand underBand ATR Upperline2 ATR Lowerline2 line 95 line 99 |
| atr outer multiplier | 3 | float · min 0.1 · step 0.1 | ATR Upperline3 ATR Lowerline3 |
| Start Year | 2021 | int · min 1900 · max 2100 · step 1 | startDate |
| Start Month | 12 | int · min 1 · max 12 · step 1 | startDate |
| Start Day | 1 | int · min 1 · max 31 · step 1 | startDate |
| Using Specific End Test Date | false | bool | line 27 |
| End Year | 2022 | int · min 1900 · max 2100 · step 1 | endDate |
| End Month | 1 | int · min 1 · max 12 · step 1 | endDate |
| End Day | 31 | int · min 1 · max 31 · step 1 | endDate |
| Minimum position Hold Limit | 8 | int · min 1 · max 365 · step 1 | minHoldPeriod 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | goLong or reverseToLong | On | 69 |
| Open short short | goShort or reverseToShort | On | 74 |
| Close long | goShortisBearish and isBearish[1] == 0 | On | 81 |
| Close short | goLongisBullish and isBullish[1] == 0 | On | 87 |
| Exit Long Stop atr stop | strategy.position_size > 0 | On | 97 |
| Exit Short Stop atr stop | strategy.position_size < 0 | On | 101 |
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.
- 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 | −5.6% | +102.5% | 32 | 31% | 0.81 | 14.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.5% | +5.5% | 36 | 28% | 0.89 | 5.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +22.3% | +9.8% | 29 | 41% | 1.56 | 10.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +6.0% | +8.4% | 23 | 30% | 1.60 | 3.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +9.6% | +16.7% | 28 | 36% | 1.24 | 14.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +7.6% | +21.5% | 28 | 39% | 1.64 | 3.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −9.6% | +148.3% | 32 | 31% | 0.73 | 18.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +5.6% | +17.1% | 35 | 40% | 1.65 | 4.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 | 8 | 38% | $34.00 |
| Sideways market | 16 | 25% | −$309.31 |
| Falling market | 8 | 38% | $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.
All 32 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Apr 2024 63,420.00 | 17 May 2024 67,380.00 | 31 | −$46.99 |
| long | 18 May 2024 67,024.00 | 14 Jun 2024 65,358.30 | 27 | −$18.49 |
| short | 15 Jun 2024 66,044.00 | 1 Jul 2024 63,369.80 | 16 | $29.56 |
| long | 2 Jul 2024 62,900.00 | 4 Jul 2024 58,854.80 | 2 | −$47.80 |
| long | 19 Jul 2024 63,987.90 | 2 Aug 2024 61,435.80 | 14 | −$29.22 |
| short | 3 Aug 2024 61,498.30 | 25 Aug 2024 64,157.00 | 22 | −$31.35 |
| long | 26 Aug 2024 64,220.00 | 4 Sep 2024 56,401.50 | 9 | −$87.05 |
| short | 5 Sep 2024 57,970.90 | 19 Sep 2024 61,760.00 | 14 | −$45.38 |
| long | 20 Sep 2024 62,948.00 | 3 Oct 2024 59,836.40 | 13 | −$33.79 |
| short | 4 Oct 2024 60,752.70 | 14 Oct 2024 65,867.40 | 10 | −$56.75 |
| long | 15 Oct 2024 66,084.00 | 31 Oct 2024 69,760.00 | 16 | $36.48 |
| short | 30 Dec 2024 93,738.20 | 17 Jan 2025 99,987.30 | 18 | −$44.62 |
| long | 18 Jan 2025 104,077.00 | 3 Feb 2025 94,625.60 | 16 | −$59.71 |
| short | 4 Feb 2025 101,329.00 | 2 Mar 2025 86,064.50 | 26 | $96.47 |
| long | 20 Apr 2025 85,077.00 | 12 May 2025 102,819.00 | 22 | $138.60 |
| short | 22 Jun 2025 102,120.00 | 3 Jul 2025 110,410.00 | 11 | −$56.97 |
| long | 4 Jul 2025 109,585.00 | 16 Jul 2025 117,758.00 | 12 | $51.00 |
| short | 21 Aug 2025 114,271.00 | 12 Sep 2025 116,540.00 | 22 | −$14.01 |
| long | 13 Sep 2025 116,029.00 | 25 Sep 2025 110,906.00 | 12 | −$30.83 |
| short | 26 Sep 2025 108,994.00 | 1 Oct 2025 116,898.00 | 5 | −$49.98 |
| long | 2 Oct 2025 118,595.00 | 10 Oct 2025 114,327.00 | 8 | −$24.42 |
| short | 16 Oct 2025 110,763.00 | 11 Nov 2025 107,299.00 | 26 | $20.78 |
| long | 12 Nov 2025 103,059.00 | 14 Nov 2025 97,373.70 | 2 | −$37.31 |
| long | 6 Jan 2026 93,859.70 | 20 Jan 2026 88,926.10 | 14 | −$35.06 |
| short | 21 Jan 2026 88,427.70 | 8 Feb 2026 71,751.30 | 18 | $123.56 |
| long | 16 Mar 2026 72,815.30 | 27 Mar 2026 68,820.30 | 11 | −$37.81 |
| short | 28 Mar 2026 66,407.30 | 7 Apr 2026 72,725.10 | 10 | −$64.57 |
| long | 8 Apr 2026 71,924.20 | 18 May 2026 76,092.70 | 40 | $38.18 |
| short | 19 May 2026 77,001.90 | 7 Jun 2026 63,978.00 | 19 | $113.31 |
| long | 16 Jul 2026 64,756.30 | 2 Aug 2026 62,823.70 | 17 | −$21.00 |
| short | 3 Aug 2026 63,570.00 | 19 Aug 2026 66,070.00 | 16 | −$27.42 |
| long | 20 Aug 2026 69,334.80 | 29 Aug 2026 77,845.90 | 9 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| action zone - ATR stop reverse order strategy v0.1 by 9nck this page | — | v5 strategy | −5.6% | 32 | 14.6% |
| 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% |
| [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% |
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.
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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 37 ms | With a workaround 1,000 bars in 94 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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)