Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

ATR Mean Reversion Strategy V1

A Pine Script v5 strategy built on ATR (10). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 6E-5% commission. 5 settings; defaults include SL Multiplier 1.5, Source close and ATR & MA PERIOD 10.

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 ATR Mean Reversion Strategy V1 repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 19 of 19 trades.
How did ATR Mean Reversion Strategy V1 do on BTCUSDT 1D with default settings?
−19.98%
From 26 Jan 2024 to 21 Oct 2026, over 79 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does ATR Mean Reversion Strategy V1 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: 79 before, 94 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 ATR Mean Reversion Strategy V1 use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does ATR Mean Reversion Strategy V1 run in Zeal Terminal?
Yes
It compiles in 18 ms and runs 1,000 bars in 36 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Mean
  • 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 (5)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$80,025$202,527Equity from $100,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. Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 25) so the engine trades the way the script says. 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
−19.98%
−$19,980.70
Buy and hold
+102.5%
same period
Closed trades
79
36 won · 43 lost
Profitable
45.6%
of closed trades
Profit factor
0.91
gross profit ÷ gross loss
Max drawdown
59.62%
−$104,538.00

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

  • Likely bug

    ta.ema(close, period) ignores the settings line 19

    Line 19 hard-codes close where line 10 uses “Source”. Changing those settings moves one band but not this one.

    ta.ema(close, period)ta.ema(src, period)
  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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.

SettingDefaultType and rangeFeeds
SL MultiplierMultiplies ATR to widen stop on volatile assests, Higher values reduce risk:reward but increase winrate, Values below 1.2 are not reccomended1.5floatstopPrice
SourceclosesourceMean
ATR & MA PERIOD10intatr buyCondition sellCondition plot Mean
Time Filter
Start FilterStart date & time to begin searching for setupstimestamp("01 Jan 1995 13:30 +0000")timef_dateFilter
End FilterEnd date & time to stop searching for setupstimestamp("1 Jan 2099 19:30 +0000")timef_dateFilter

What it calculates

  • ATRATR & MA PERIOD (10)atr · line 15

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.

high · low · closehigh · low · closeprice dataperiodATR & MA PERIODsetting · 10openopenprice dataSLxSL Multipliersetting · 1.5lowlowprice dataclosecloseprice datahighhighprice datatimetimeprice datai_startTimeStart Filtersetting · timestamp("01 Jan 1…i_endTimeEnd Filtersetting · timestamp("1 Jan 20…atrATR→ atrbuyPricebuyPricevaluestopDistancestopDistancevaluestopPricestopPricevaluebuyConditionbuyConditionconditionsellConditionsellConditionconditionstopConditionstopConditionconditionf_dateFilterf_dateFilterconditionentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:8plotplotplot:9plotplotplot:10Meanplotplot:33plotplotplot:34plotplot

Order rules

OrderFires whenBy defaultLine
Open Long longbuyConditionOn25
Close LongsellCondition or stopConditionOn30

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, and the live replay matched history.

19/19trades 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. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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−20.0%+102.5%7946%0.9159.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+4.5%+5.5%7954%1.1119.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−71.2%+9.8%7535%0.5478.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+9.7%+8.4%7661%1.1720.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−68.5%+16.7%6834%0.6480.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+8.3%+21.5%7551%1.1321.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−50.8%+148.3%7537%0.6457.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+14.8%+17.1%8053%1.2814.4%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 market3259%$55,765.90
Sideways market3030%−$63,758.30
Falling market1747%−$11,988.30

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

How bad could the drawdown be?

56.7%

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

0%68%
All 79 trades
SideEntryExitBarsP&L
long14 Feb 2024 49,699.6015 Feb 2024 51,795.201$4,216.35
long22 Feb 2024 51,849.4024 Feb 2024 50,744.202−$2,221.61
long6 Mar 2024 63,724.007 Mar 2024 66,074.001$3,761.26
long13 Mar 2024 71,452.0016 Mar 2024 69,499.803−$2,889.51
long17 Mar 2024 65,300.6020 Mar 2024 61,937.403−$5,298.13
long3 Apr 2024 65,464.009 Apr 2024 71,620.006$9,174.87
long10 Apr 2024 69,146.0013 Apr 2024 67,116.503−$3,133.11
long14 Apr 2024 63,924.5025 Apr 2024 64,289.6011$591.57
long1 May 2024 60,672.004 May 2024 62,882.003$3,795.46
long11 May 2024 60,800.0016 May 2024 66,206.505$9,603.29
long24 May 2024 67,969.704 Jun 2024 68,809.9011$1,453.61
long8 Jun 2024 69,355.6012 Jun 2024 67,314.204−$3,504.30
long19 Jun 2024 65,175.3025 Jun 2024 60,293.306−$8,655.49
long4 Jul 2024 60,208.606 Jul 2024 56,628.802−$6,355.66
long8 Jul 2024 55,857.8016 Jul 2024 64,724.108$15,958.20
long3 Aug 2024 61,498.305 Aug 2024 58,161.002−$6,322.09
long6 Aug 2024 54,018.809 Aug 2024 61,686.003$15,637.50
long28 Aug 2024 59,415.005 Sep 2024 57,970.908−$3,058.05
long7 Sep 2024 53,963.0010 Sep 2024 57,042.003$7,004.00
long1 Oct 2024 63,327.602 Oct 2024 60,804.901−$5,169.12
long22 Oct 2024 67,377.5025 Oct 2024 68,198.303$1,517.55
long26 Oct 2024 66,698.3029 Oct 2024 69,962.203$6,170.88
long1 Nov 2024 70,292.002 Nov 2024 69,496.001−$1,498.11
long13 Nov 2024 87,952.0014 Nov 2024 90,375.201$3,603.01
long26 Nov 2024 93,010.0027 Nov 2024 91,965.201−$1,509.78
long6 Dec 2024 96,945.607 Dec 2024 99,740.801$3,830.92
long10 Dec 2024 97,276.5012 Dec 2024 101,125.002$5,408.19
long19 Dec 2024 100,204.0020 Dec 2024 97,461.901−$3,889.15
long21 Dec 2024 97,805.4025 Dec 2024 98,663.604$1,212.59
long8 Jan 2025 96,954.609 Jan 2025 95,060.601−$2,724.00
long10 Jan 2025 92,552.5016 Jan 2025 100,497.006$11,735.30
long20 Jan 2025 101,332.0021 Jan 2025 102,260.001$1,359.93
long28 Jan 2025 102,083.001 Feb 2025 102,430.004$508.65
long3 Feb 2025 97,700.6017 Feb 2025 96,118.1014−$2,434.85
long22 Feb 2025 96,182.0025 Feb 2025 91,552.903−$7,117.45
long26 Feb 2025 88,680.4028 Feb 2025 84,708.602−$6,304.65
long1 Mar 2025 84,349.903 Mar 2025 94,270.002$15,812.90
long4 Mar 2025 86,221.208 Mar 2025 86,801.704$1,011.69
long10 Mar 2025 80,734.5017 Mar 2025 82,574.507$3,447.74
long29 Mar 2025 84,424.407 Apr 2025 78,430.009−$10,986.50
long8 Apr 2025 79,163.2010 Apr 2025 82,615.202$6,267.90
long13 May 2025 102,791.0019 May 2025 106,454.006$5,345.46
long20 May 2025 105,574.0022 May 2025 109,644.002$5,989.41
long24 May 2025 107,318.0030 May 2025 105,590.006−$2,598.96
long6 Jun 2025 101,509.007 Jun 2025 104,288.001$4,347.00
long13 Jun 2025 105,672.0017 Jun 2025 106,795.004$1,732.73
long18 Jun 2025 104,551.0021 Jun 2025 103,298.003−$1,975.88
long23 Jun 2025 100,964.0024 Jun 2025 105,334.001$7,048.59
long16 Jul 2025 117,758.0021 Jul 2025 117,265.005−$711.46
long26 Jul 2025 117,614.001 Aug 2025 115,764.006−$2,661.78
long2 Aug 2025 113,298.0011 Aug 2025 119,294.009$8,813.32
long15 Aug 2025 118,295.0020 Aug 2025 112,873.005−$8,037.05
long25 Aug 2025 113,494.0030 Aug 2025 108,377.005−$7,542.07
long23 Sep 2025 112,651.0026 Sep 2025 108,994.003−$5,185.82
long8 Oct 2025 121,333.0011 Oct 2025 112,774.003−$10,903.50
long15 Oct 2025 113,028.0018 Oct 2025 106,432.003−$8,385.02
long4 Nov 2025 106,583.006 Nov 2025 103,885.002−$3,424.62
long15 Nov 2025 94,594.0021 Nov 2025 86,637.206−$11,091.70
long22 Nov 2025 85,129.402 Dec 2025 86,286.0010$1,640.67
long6 Dec 2025 89,330.0010 Dec 2025 92,678.804$4,588.75
long7 Jan 2026 93,748.009 Jan 2026 91,100.002−$3,587.34
long21 Jan 2026 88,427.7030 Jan 2026 84,650.209−$5,272.15
long31 Jan 2026 84,260.502 Feb 2026 76,968.202−$10,224.50
long4 Feb 2026 75,770.206 Feb 2026 62,909.902−$18,316.50
long24 Feb 2026 64,656.0026 Feb 2026 67,988.002$4,617.37
long19 Mar 2026 71,246.6020 Mar 2026 69,930.001−$1,741.11
long27 Mar 2026 68,820.303 Apr 2026 66,902.007−$2,577.81
long13 Apr 2026 70,741.6014 Apr 2026 74,418.001$4,671.92
long16 May 2026 79,113.2023 May 2026 75,539.507−$4,272.01
long2 Jun 2026 71,408.904 Jun 2026 64,142.802−$9,188.27
long5 Jun 2026 63,886.007 Jun 2026 60,884.602−$3,810.63
long24 Jun 2026 62,734.6026 Jun 2026 59,794.602−$3,622.55
long7 Jul 2026 64,042.909 Jul 2026 62,290.002−$2,016.71
long14 Jul 2026 62,334.5015 Jul 2026 65,044.001$3,114.71
long28 Jul 2026 63,755.901 Aug 2026 62,887.904−$1,018.08
long29 Aug 2026 77,845.904 Sep 2026 81,270.406$3,244.49
long16 Sep 2026 75,644.5019 Sep 2026 80,883.903$5,333.22
long24 Sep 2026 84,397.6029 Sep 2026 83,500.005−$875.74
long8 Oct 2026 83,321.8013 Oct 2026 81,850.005−$1,438.98

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
ATR Mean Reversion Strategy V1 this page—v5 strategy−20.0%7959.6%
SOJA PIVOT by ParaBellum68atrv4 strategy+3.3%918.2%
Volatility System by EduardoMattjeatrv5 strategy+150.2%221.5%
ATR Stop Buy Strategy by phobo3satrv4 strategyNo trades on this market
VBand Strategy by Saravanan_Ragavanatrv4 strategyNo trades on this market
Volatility Breakout Strategy [Angel Algo] by AngelAlgoatrv5 strategy+3.1%183.6%

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 settings use the untyped input() (line 5, 6). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.float()
  • Line 6: input() → input.source()
⋯strategy("ATR Mean Reversion", overlay=true, initial_capital=100000,default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=6E-5) // Brokers rate (ICmarkets = 6E-5)-SLx = input(1.5, "SL Multiplier", tooltip = "Multiplies ATR to widen stop on volatile assests, Higher values reduce risk:reward but increase winrate, Values below 1.2 are not reccomended")+SLx = input.float(1.5, "SL Multiplier", tooltip = "Multiplies ATR to widen stop on volatile assests, Higher values reduce risk:reward but increase winrate, Values below 1.2 are not reccomended")-src = input(close, title="Source")+src = input.source(close, title="Source")period = input.int(10, "ATR & MA PERIOD")⋯

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: 79 before, 94 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.

⋯// © Bcullen175-//@version=5+//@version=6strategy("ATR Mean Reversion", overlay=true, initial_capital=100000,default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=6E-5) // Brokers rate (ICmarkets = 6E-5)⋯

Where it runs

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

Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 25) so the engine trades the way the script says. 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/// © Bcullen175//@version=5strategy("ATR Mean Reversion", overlay=true, initial_capital=100000,default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=6E-5) // Brokers rate (ICmarkets = 6E-5)SLx = input(1.5, "SL Multiplier", tooltip = "Multiplies ATR to widen stop on volatile assests, Higher values reduce risk:reward but increase winrate, Values below 1.2 are not reccomended")src = input(close, title="Source")period = input.int(10, "ATR & MA PERIOD")plot(open+ta.atr(period))plot(open-ta.atr(period))plot((ta.ema(src, period)), title = "Mean", color=color.white)i_startTime     = input.time(title="Start Filter", defval=timestamp("01 Jan 1995 13:30 +0000"), group="Time Filter", tooltip="Start date & time to begin searching for setups")i_endTime       = input.time(title="End Filter", defval=timestamp("1 Jan 2099 19:30 +0000"), group="Time Filter", tooltip="End date & time to stop searching for setups")// Check filter(s)f_dateFilter = time >= i_startTime and time <= i_endTimeatr = ta.atr(period)// Check buy/sell conditionsvar float buyPrice = 0buyCondition    = low < (open-ta.atr(period)) and strategy.position_size == 0 and f_dateFiltersellCondition   = (high > (ta.ema(close, period)) and strategy.position_size > 0 and close < low[1]) or high > (open+ta.atr(period))stopDistance    = strategy.position_size > 0 ? ((buyPrice - atr)/buyPrice) : nastopPrice       = strategy.position_size > 0 ? (buyPrice - SLx*atr): nastopCondition   = strategy.position_size > 0 and low < stopPrice// Enter positionsif buyCondition    strategy.entry(id="Long", direction=strategy.long)if buyCondition[1]    buyPrice := open// Exit positionsif sellCondition or stopCondition    strategy.close(id="Long", comment="Exit" + (stopCondition ? "SL=true" : ""))    buyPrice := na// Draw pretty colorsplot(buyPrice, color=color.lime, style=plot.style_linebr)plot(stopPrice, color=color.red, style=plot.style_linebr, offset=-1)