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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| SL MultiplierMultiplies ATR to widen stop on volatile assests, Higher values reduce risk:reward but increase winrate, Values below 1.2 are not reccomended | 1.5 | float | stopPrice |
| Source | close | source | Mean |
| ATR & MA PERIOD | 10 | int | atr buyCondition sellCondition plot Mean |
| Time Filter | |||
| Start FilterStart date & time to begin searching for setups | timestamp("01 Jan 1995 13:30 +0000") | time | f_dateFilter |
| End FilterEnd date & time to stop searching for setups | timestamp("1 Jan 2099 19:30 +0000") | time | f_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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | buyCondition | On | 25 |
| Close Long | sellCondition or stopCondition | On | 30 |
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.
- 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 | −20.0% | +102.5% | 79 | 46% | 0.91 | 59.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +4.5% | +5.5% | 79 | 54% | 1.11 | 19.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −71.2% | +9.8% | 75 | 35% | 0.54 | 78.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +9.7% | +8.4% | 76 | 61% | 1.17 | 20.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −68.5% | +16.7% | 68 | 34% | 0.64 | 80.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +8.3% | +21.5% | 75 | 51% | 1.13 | 21.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −50.8% | +148.3% | 75 | 37% | 0.64 | 57.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +14.8% | +17.1% | 80 | 53% | 1.28 | 14.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 32 | 59% | $55,765.90 |
| Sideways market | 30 | 30% | −$63,758.30 |
| Falling market | 17 | 47% | −$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.
All 79 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 14 Feb 2024 49,699.60 | 15 Feb 2024 51,795.20 | 1 | $4,216.35 |
| long | 22 Feb 2024 51,849.40 | 24 Feb 2024 50,744.20 | 2 | −$2,221.61 |
| long | 6 Mar 2024 63,724.00 | 7 Mar 2024 66,074.00 | 1 | $3,761.26 |
| long | 13 Mar 2024 71,452.00 | 16 Mar 2024 69,499.80 | 3 | −$2,889.51 |
| long | 17 Mar 2024 65,300.60 | 20 Mar 2024 61,937.40 | 3 | −$5,298.13 |
| long | 3 Apr 2024 65,464.00 | 9 Apr 2024 71,620.00 | 6 | $9,174.87 |
| long | 10 Apr 2024 69,146.00 | 13 Apr 2024 67,116.50 | 3 | −$3,133.11 |
| long | 14 Apr 2024 63,924.50 | 25 Apr 2024 64,289.60 | 11 | $591.57 |
| long | 1 May 2024 60,672.00 | 4 May 2024 62,882.00 | 3 | $3,795.46 |
| long | 11 May 2024 60,800.00 | 16 May 2024 66,206.50 | 5 | $9,603.29 |
| long | 24 May 2024 67,969.70 | 4 Jun 2024 68,809.90 | 11 | $1,453.61 |
| long | 8 Jun 2024 69,355.60 | 12 Jun 2024 67,314.20 | 4 | −$3,504.30 |
| long | 19 Jun 2024 65,175.30 | 25 Jun 2024 60,293.30 | 6 | −$8,655.49 |
| long | 4 Jul 2024 60,208.60 | 6 Jul 2024 56,628.80 | 2 | −$6,355.66 |
| long | 8 Jul 2024 55,857.80 | 16 Jul 2024 64,724.10 | 8 | $15,958.20 |
| long | 3 Aug 2024 61,498.30 | 5 Aug 2024 58,161.00 | 2 | −$6,322.09 |
| long | 6 Aug 2024 54,018.80 | 9 Aug 2024 61,686.00 | 3 | $15,637.50 |
| long | 28 Aug 2024 59,415.00 | 5 Sep 2024 57,970.90 | 8 | −$3,058.05 |
| long | 7 Sep 2024 53,963.00 | 10 Sep 2024 57,042.00 | 3 | $7,004.00 |
| long | 1 Oct 2024 63,327.60 | 2 Oct 2024 60,804.90 | 1 | −$5,169.12 |
| long | 22 Oct 2024 67,377.50 | 25 Oct 2024 68,198.30 | 3 | $1,517.55 |
| long | 26 Oct 2024 66,698.30 | 29 Oct 2024 69,962.20 | 3 | $6,170.88 |
| long | 1 Nov 2024 70,292.00 | 2 Nov 2024 69,496.00 | 1 | −$1,498.11 |
| long | 13 Nov 2024 87,952.00 | 14 Nov 2024 90,375.20 | 1 | $3,603.01 |
| long | 26 Nov 2024 93,010.00 | 27 Nov 2024 91,965.20 | 1 | −$1,509.78 |
| long | 6 Dec 2024 96,945.60 | 7 Dec 2024 99,740.80 | 1 | $3,830.92 |
| long | 10 Dec 2024 97,276.50 | 12 Dec 2024 101,125.00 | 2 | $5,408.19 |
| long | 19 Dec 2024 100,204.00 | 20 Dec 2024 97,461.90 | 1 | −$3,889.15 |
| long | 21 Dec 2024 97,805.40 | 25 Dec 2024 98,663.60 | 4 | $1,212.59 |
| long | 8 Jan 2025 96,954.60 | 9 Jan 2025 95,060.60 | 1 | −$2,724.00 |
| long | 10 Jan 2025 92,552.50 | 16 Jan 2025 100,497.00 | 6 | $11,735.30 |
| long | 20 Jan 2025 101,332.00 | 21 Jan 2025 102,260.00 | 1 | $1,359.93 |
| long | 28 Jan 2025 102,083.00 | 1 Feb 2025 102,430.00 | 4 | $508.65 |
| long | 3 Feb 2025 97,700.60 | 17 Feb 2025 96,118.10 | 14 | −$2,434.85 |
| long | 22 Feb 2025 96,182.00 | 25 Feb 2025 91,552.90 | 3 | −$7,117.45 |
| long | 26 Feb 2025 88,680.40 | 28 Feb 2025 84,708.60 | 2 | −$6,304.65 |
| long | 1 Mar 2025 84,349.90 | 3 Mar 2025 94,270.00 | 2 | $15,812.90 |
| long | 4 Mar 2025 86,221.20 | 8 Mar 2025 86,801.70 | 4 | $1,011.69 |
| long | 10 Mar 2025 80,734.50 | 17 Mar 2025 82,574.50 | 7 | $3,447.74 |
| long | 29 Mar 2025 84,424.40 | 7 Apr 2025 78,430.00 | 9 | −$10,986.50 |
| long | 8 Apr 2025 79,163.20 | 10 Apr 2025 82,615.20 | 2 | $6,267.90 |
| long | 13 May 2025 102,791.00 | 19 May 2025 106,454.00 | 6 | $5,345.46 |
| long | 20 May 2025 105,574.00 | 22 May 2025 109,644.00 | 2 | $5,989.41 |
| long | 24 May 2025 107,318.00 | 30 May 2025 105,590.00 | 6 | −$2,598.96 |
| long | 6 Jun 2025 101,509.00 | 7 Jun 2025 104,288.00 | 1 | $4,347.00 |
| long | 13 Jun 2025 105,672.00 | 17 Jun 2025 106,795.00 | 4 | $1,732.73 |
| long | 18 Jun 2025 104,551.00 | 21 Jun 2025 103,298.00 | 3 | −$1,975.88 |
| long | 23 Jun 2025 100,964.00 | 24 Jun 2025 105,334.00 | 1 | $7,048.59 |
| long | 16 Jul 2025 117,758.00 | 21 Jul 2025 117,265.00 | 5 | −$711.46 |
| long | 26 Jul 2025 117,614.00 | 1 Aug 2025 115,764.00 | 6 | −$2,661.78 |
| long | 2 Aug 2025 113,298.00 | 11 Aug 2025 119,294.00 | 9 | $8,813.32 |
| long | 15 Aug 2025 118,295.00 | 20 Aug 2025 112,873.00 | 5 | −$8,037.05 |
| long | 25 Aug 2025 113,494.00 | 30 Aug 2025 108,377.00 | 5 | −$7,542.07 |
| long | 23 Sep 2025 112,651.00 | 26 Sep 2025 108,994.00 | 3 | −$5,185.82 |
| long | 8 Oct 2025 121,333.00 | 11 Oct 2025 112,774.00 | 3 | −$10,903.50 |
| long | 15 Oct 2025 113,028.00 | 18 Oct 2025 106,432.00 | 3 | −$8,385.02 |
| long | 4 Nov 2025 106,583.00 | 6 Nov 2025 103,885.00 | 2 | −$3,424.62 |
| long | 15 Nov 2025 94,594.00 | 21 Nov 2025 86,637.20 | 6 | −$11,091.70 |
| long | 22 Nov 2025 85,129.40 | 2 Dec 2025 86,286.00 | 10 | $1,640.67 |
| long | 6 Dec 2025 89,330.00 | 10 Dec 2025 92,678.80 | 4 | $4,588.75 |
| long | 7 Jan 2026 93,748.00 | 9 Jan 2026 91,100.00 | 2 | −$3,587.34 |
| long | 21 Jan 2026 88,427.70 | 30 Jan 2026 84,650.20 | 9 | −$5,272.15 |
| long | 31 Jan 2026 84,260.50 | 2 Feb 2026 76,968.20 | 2 | −$10,224.50 |
| long | 4 Feb 2026 75,770.20 | 6 Feb 2026 62,909.90 | 2 | −$18,316.50 |
| long | 24 Feb 2026 64,656.00 | 26 Feb 2026 67,988.00 | 2 | $4,617.37 |
| long | 19 Mar 2026 71,246.60 | 20 Mar 2026 69,930.00 | 1 | −$1,741.11 |
| long | 27 Mar 2026 68,820.30 | 3 Apr 2026 66,902.00 | 7 | −$2,577.81 |
| long | 13 Apr 2026 70,741.60 | 14 Apr 2026 74,418.00 | 1 | $4,671.92 |
| long | 16 May 2026 79,113.20 | 23 May 2026 75,539.50 | 7 | −$4,272.01 |
| long | 2 Jun 2026 71,408.90 | 4 Jun 2026 64,142.80 | 2 | −$9,188.27 |
| long | 5 Jun 2026 63,886.00 | 7 Jun 2026 60,884.60 | 2 | −$3,810.63 |
| long | 24 Jun 2026 62,734.60 | 26 Jun 2026 59,794.60 | 2 | −$3,622.55 |
| long | 7 Jul 2026 64,042.90 | 9 Jul 2026 62,290.00 | 2 | −$2,016.71 |
| long | 14 Jul 2026 62,334.50 | 15 Jul 2026 65,044.00 | 1 | $3,114.71 |
| long | 28 Jul 2026 63,755.90 | 1 Aug 2026 62,887.90 | 4 | −$1,018.08 |
| long | 29 Aug 2026 77,845.90 | 4 Sep 2026 81,270.40 | 6 | $3,244.49 |
| long | 16 Sep 2026 75,644.50 | 19 Sep 2026 80,883.90 | 3 | $5,333.22 |
| long | 24 Sep 2026 84,397.60 | 29 Sep 2026 83,500.00 | 5 | −$875.74 |
| long | 8 Oct 2026 83,321.80 | 13 Oct 2026 81,850.00 | 5 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| ATR Mean Reversion Strategy V1 this page | — | v5 strategy | −20.0% | 79 | 59.6% |
| SOJA PIVOT by ParaBellum68 | atr | v4 strategy | +3.3% | 9 | 18.2% |
| Volatility System by EduardoMattje | atr | v5 strategy | +150.2% | 2 | 21.5% |
| ATR Stop Buy Strategy by phobo3s | atr | v4 strategy | No trades on this market | ||
| VBand Strategy by Saravanan_Ragavan | atr | v4 strategy | No trades on this market | ||
| Volatility Breakout Strategy [Angel Algo] by AngelAlgo | atr | v5 strategy | +3.1% | 18 | 3.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.
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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | With a workaround 1,000 bars in 36 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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)