Pine Script v5 · Strategy
ETF 3-Day Reversion Strategy
A Pine Script v5 strategy built on EMA (close, 5). It has 3 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 1 commission. 5 settings; defaults include EMA Trade Qualifier Length 200 and EMA Length For Exit Strategy 5.
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 ETF 3-Day Reversion Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
- How did ETF 3-Day Reversion Strategy do on BTCUSDT 1D with default settings?
- +10.19%
- From 26 Jan 2024 to 21 Oct 2026, over 31 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does ETF 3-Day Reversion 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: 31 before, 62 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 ETF 3-Day Reversion Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does ETF 3-Day Reversion Strategy run in Zeal Terminal?
- Yes
- It compiles in 11 ms and runs 1,000 bars in 27 ms, in the browser.
BTCUSDT · 1D · default settings
- Five Period EMA
- Qualifier EMA
- Exit EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +10.19%
- $1,019,330.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 31
- 25 won · 6 lost
- Profitable
- 80.6%
- of closed trades
- Profit factor
- 1.20
- gross profit ÷ gross loss
- Max drawdown
- 28.05%
- −$3,841,610.00
One run with the author's default settings, $10,000,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.
-
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.
-
Note
Uses an argument v6 removed
when = on line 23, 24. 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 |
|---|---|---|---|
| Start Time | timestamp('01 Jan 2012 05:00 +0000') | time | InDateRange |
| End Time | timestamp('01 Jan 2099 00:00 +0000') | time | InDateRange |
| Only enter trades when above qualifier EMA?When this is selected, a trade will only be entered when the price is above the EMA qualifier line. | false | bool | Rule1 |
| EMA Trade Qualifier Length | 200 | int | EMAQualifier Qualifier EMA |
| EMA Length For Exit StrategyThe strategy will sell when the price crosses over this EMA | 5 | int | Exit EMA close Long |
What it calculates
- EMAclose, 5
DayEMA5 · line 10
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 | Rule1 and Rule2 and Rule3 | On | 23 |
| Close Long | ta.crossover(close, ExitEMA) | On | 24 |
| Close | (not InDateRange) | On | 26 |
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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +10.2% | +102.5% | 31 | 81% | 1.20 | 28.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −9.2% | +5.5% | 21 | 67% | 0.48 | 17.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +5.3% | +9.8% | 30 | 73% | 1.06 | 37.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −21.0% | +8.4% | 25 | 56% | 0.38 | 25.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −28.8% | +16.7% | 36 | 58% | 0.74 | 54.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −12.7% | +21.5% | 22 | 68% | 0.56 | 24.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +42.0% | +148.3% | 34 | 65% | 1.91 | 27.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −10.4% | +17.1% | 27 | 70% | 0.53 | 18.9% | 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 | 6 | 83% | $1,117,430.00 |
| Sideways market | 16 | 81% | $566,284.00 |
| Falling market | 9 | 78% | −$664,382.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
28.2%
The 95th percentile of the worst drawdown when the same 31 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 13.4% to 28.2%; the tick is what actually happened, 19.8%. Order luck alone moves it this much.
All 31 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 Mar 2024 68,393.50 | 20 Mar 2024 67,840.50 | 3 | −$80,853.30 |
| long | 3 Apr 2024 65,963.30 | 4 Apr 2024 68,487.80 | 1 | $379,618.00 |
| long | 4 Jul 2024 57,050.00 | 9 Jul 2024 58,050.00 | 5 | $180,518.00 |
| long | 25 Jul 2024 65,799.90 | 26 Jul 2024 67,908.00 | 1 | $335,724.00 |
| long | 1 Aug 2024 65,354.00 | 8 Aug 2024 61,686.00 | 7 | −$607,000.00 |
| long | 28 Aug 2024 59,034.90 | 2 Sep 2024 59,132.10 | 5 | $16,810.50 |
| long | 2 Oct 2024 60,649.30 | 4 Oct 2024 62,086.00 | 2 | $242,214.00 |
| long | 10 Oct 2024 60,326.40 | 11 Oct 2024 62,540.00 | 1 | $384,074.00 |
| long | 20 Dec 2024 97,805.40 | 24 Dec 2024 98,663.60 | 4 | $95,205.00 |
| long | 2 Feb 2025 97,700.60 | 3 Feb 2025 101,329.00 | 1 | $406,469.00 |
| long | 18 Feb 2025 95,671.70 | 19 Feb 2025 96,644.40 | 1 | $115,414.00 |
| long | 25 Feb 2025 88,680.40 | 2 Mar 2025 94,270.00 | 5 | $722,848.00 |
| long | 11 Mar 2025 82,933.00 | 12 Mar 2025 83,680.10 | 1 | $109,825.00 |
| long | 28 Mar 2025 84,424.40 | 1 Apr 2025 85,158.30 | 4 | $106,938.00 |
| long | 5 May 2025 94,733.70 | 6 May 2025 96,834.00 | 1 | $275,091.00 |
| long | 30 May 2025 103,985.00 | 2 Jun 2025 105,858.00 | 3 | $228,384.00 |
| long | 13 Jun 2025 106,067.00 | 16 Jun 2025 106,795.00 | 3 | $88,608.70 |
| long | 20 Aug 2025 114,271.00 | 22 Aug 2025 116,936.00 | 2 | $303,149.00 |
| long | 26 Aug 2025 111,763.00 | 28 Aug 2025 112,567.00 | 2 | $95,659.00 |
| long | 23 Sep 2025 111,999.00 | 28 Sep 2025 112,164.00 | 5 | $19,755.30 |
| long | 30 Oct 2025 108,323.00 | 2 Nov 2025 110,541.00 | 3 | $274,727.00 |
| long | 14 Nov 2025 94,594.00 | 24 Nov 2025 88,300.00 | 10 | −$911,103.00 |
| long | 8 Jan 2026 91,100.00 | 12 Jan 2026 91,296.20 | 4 | $27,527.90 |
| long | 20 Jan 2026 88,427.70 | 27 Jan 2026 89,250.00 | 7 | $119,122.00 |
| long | 31 Jan 2026 78,741.10 | 13 Feb 2026 68,854.00 | 13 | −$1,623,400.00 |
| long | 18 Feb 2026 66,461.00 | 20 Feb 2026 68,020.00 | 2 | $265,193.00 |
| long | 24 Feb 2026 64,058.20 | 25 Feb 2026 67,988.00 | 1 | $709,835.00 |
| long | 8 Mar 2026 65,971.20 | 9 Mar 2026 68,432.20 | 1 | $458,099.00 |
| long | 17 May 2026 77,457.70 | 24 May 2026 77,065.00 | 7 | −$64,585.90 |
| long | 29 May 2026 73,460.80 | 11 Jun 2026 63,626.00 | 13 | −$1,696,760.00 |
| long | 25 Jun 2026 59,794.00 | 1 Jul 2026 60,024.00 | 6 | $42,221.90 |
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 |
|---|---|---|---|---|---|
| ETF 3-Day Reversion Strategy this page | — | v5 strategy | +10.2% | 31 | 28.1% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
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 23, 24). 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 31 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 23: when = Rule1 and Rule2 and Rule3 → if block
- Line 24: when = ta.crossover(close, ExitEMA) → if block
⋯if (InDateRange)- strategy.entry("Long", strategy.long, when = Rule1 and Rule2 and Rule3)+ if Rule1 and Rule2 and Rule3+ strategy.entry("Long", strategy.long)- strategy.close("Long", when = ta.crossover(close, ExitEMA))+ if ta.crossover(close, ExitEMA)+ strategy.close("Long")if (not InDateRange)⋯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: 31 before, 62 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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version = 5+// @version = 6// Author = TradeAutomation⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | Yes 1,000 bars in 27 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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/// @version = 5// Author = TradeAutomationstrategy(title="ETF 3-Day Reversion Strategy", shorttitle="ETF 3-Day Reversion Strategy", process_orders_on_close=true, overlay=true, commission_type=strategy.commission.cash_per_order, commission_value=1, initial_capital = 10000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Backtest Date Range Inputs // StartTime = input.time(defval=timestamp('01 Jan 2012 05:00 +0000'), title='Start Time')EndTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), title='End Time')InDateRange = time>=StartTime and time<=EndTime// Strategy Rules //DayEMA5 = ta.ema(close, 5)EMAQualInput = input.bool(false, "Only enter trades when above qualifier EMA?", tooltip="When this is selected, a trade will only be entered when the price is above the EMA qualifier line.")QEMA = ta.ema(close, input.int(200, "EMA Trade Qualifier Length"))EMAQualifier = close>QEMARule1 = EMAQualInput==true ? EMAQualifier : close>0Rule2 = close<DayEMA5Rule3 = high<high[1] and low<low[1] and high[1]<high[2] and low[1]<low[2] and high[2]<high[3] and low[2]<low[3]ExitEMA = ta.ema(close, input.int(5, "EMA Length For Exit Strategy", tooltip = "The strategy will sell when the price crosses over this EMA"))plot(DayEMA5, "Five Period EMA")plot(QEMA, "Qualifier EMA")plot(ExitEMA, "Exit EMA", color=color.green)// Entry & Exit Functions //if (InDateRange) strategy.entry("Long", strategy.long, when = Rule1 and Rule2 and Rule3) strategy.close("Long", when = ta.crossover(close, ExitEMA))if (not InDateRange) strategy.close_all()