Pine Script v4 · Strategy
5-10-20 Cross
A Pine Script v4 strategy built on Supertrend (2, 14) and EMA (src, 5). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 5 settings; defaults include EMA 1 5, EMA 2 10 and EMA 3 20.
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 5-10-20 Cross repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
- How did 5-10-20 Cross do on BTCUSDT 1D with default settings?
- +35.97%
- From 26 Jan 2024 to 21 Oct 2026, over 35 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can 5-10-20 Cross be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does 5-10-20 Cross use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does 5-10-20 Cross run in Zeal Terminal?
- Yes
- It compiles in 17 ms and runs 1,000 bars in 65 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA1
- EMA2
- EMA3
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +35.97%
- $35,971.60
- Buy and hold
- +102.5%
- same period
- Closed trades
- 35
- 13 won · 22 lost
- Profitable
- 37.1%
- of closed trades
- Profit factor
- 1.31
- gross profit ÷ gross loss
- Max drawdown
- 51.16%
- −$62,524.00
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog mult (line 9), len (line 10) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames supertrend → ta.supertrend, ema → ta.ema.
v4 → v5
VerifiedSame 35 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 9: input(type = input.float) → input.float()
- Line 10: input(type = input.integer) → input.int()
- Line 11: supertrend → ta.supertrend
- Line 12: ema → ta.ema
- Line 13: ema → ta.ema
- Line 14: ema → ta.ema
⋯// © aadilpatel07-//@version=4+//@version=5strategy("5-10-20 Cross", overlay=true)⋯len3 = input(20, minval=1, title="EMA 3")-mult = input(type=input.float, defval=2)+mult = input.float(defval=2)-len = input(type=input.integer, defval=14)+len = input.int(defval=14)-[superTrend, dir] = supertrend(mult, len)+[superTrend, dir] = ta.supertrend(mult, len)-ema1 = ema(src, len1)+ema1 = ta.ema(src, len1)-ema2 = ema(src, len2)+ema2 = ta.ema(src, len2)-ema3 = ema(src, len3)+ema3 = ta.ema(src, len3)//EMA Color⋯Same 35 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
⋯src = close, -len1 = input(5, minval=1, title="EMA 1")+len1 = input.int(5, minval=1, title="EMA 1")-len2 = input(10, minval=1, title="EMA 2")+len2 = input.int(10, minval=1, title="EMA 2")-len3 = input(20, minval=1, title="EMA 3")+len3 = input.int(20, minval=1, title="EMA 3")mult = input.float(defval=2)⋯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: 35 before, 146 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.
⋯// © aadilpatel07-//@version=5+//@version=6strategy("5-10-20 Cross", overlay=true)⋯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 |
|---|---|---|---|
| EMA 1 | 5 | int · min 1 | ema1 |
| EMA 2 | 10 | int · min 1 | ema2 |
| EMA 3 | 20 | int · min 1 | ema3 |
| Mult (no label in the script) | 2 | float | superTrend dir |
| Len (no label in the script) | 14 | int (written input.integer) | superTrend dir |
What it calculates
- Supertrend (
supertrend,ta.supertrendin v5)Mult (2), Len (14)superTrend · line 11 - Supertrend (
supertrend,ta.supertrendin v5)Mult (2), Len (14)dir · line 11 - EMA (
ema,ta.emain v5)src, EMA 1 (5)ema1 · line 12 - EMA (
ema,ta.emain v5)src, EMA 2 (10)ema2 · line 13 - EMA (
ema,ta.emain v5)src, EMA 3 (20)ema3 · line 14
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 My Long Entry Id long | (longCondition) | On | 31 |
| Open My Short Entry Id short | (shortCondition) | On | 35 |
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 | +36.0% | +102.5% | 35 | 37% | 1.31 | 51.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.4% | +5.5% | 40 | 33% | 0.88 | 16.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +3.2% | +9.8% | 29 | 38% | 1.64 | 2.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.5% | +8.4% | 29 | 28% | 1.43 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 33 | 45% | 1.08 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 34 | 29% | 1.52 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.7% | +148.3% | 29 | 34% | 2.07 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 38 | 29% | 0.91 | 0.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (EMA 1 9, EMA 2 7) made +48.8% before 26 Dec 2025 and −25.0% after it, worse than the defaults' +41.8% after. Tuning on the past did not carry forward. 44% of the 48 combinations made money in-sample and 79% out-of-sample.
| EMA 2 ↓ · EMA 1 → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 5 | −27% | −27% | 0% | +3% | +14% | −16% |
| 6 | −12% | −12% | −12% | 0% | −17% | −32% |
| 7 | −13% | −13% | −13% | −13% | 0% | +49% |
| 9 | −9% | −9% | −9% | −9% | −9% | 0% |
| 10 | −6% | −6% | −6% | −6% | −6% | −6% |
| 12 | +2% | +2% | +2% | +2% | +2% | +2% |
| 14 | +3% | +3% | +3% | +3% | +3% | +3% |
| 17 | +5% | +5% | +5% | +5% | +5% | +5% |
| EMA 2 ↓ · EMA 1 → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 5 | +38% | +38% | 0% | −26% | −23% | −22% |
| 6 | +39% | +39% | +39% | 0% | −23% | −25% |
| 7 | +44% | +44% | +44% | +44% | 0% | −25% |
| 9 | +40% | +40% | +40% | +40% | +40% | 0% |
| 10 | +42% | +42% | +42% | +42% | +42% | +42% |
| 12 | +43% | +43% | +43% | +43% | +43% | +43% |
| 14 | +35% | +35% | +35% | +35% | +35% | +35% |
| 17 | +34% | +34% | +34% | +34% | +34% | +34% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 14 | 36% | −$12,188.00 |
| Sideways market | 15 | 40% | $37,813.50 |
| Falling market | 6 | 33% | $10,346.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
48.0%
The 95th percentile of the worst drawdown when the same 35 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 23.5% to 48.0%; the tick is what actually happened, 40.4%. Order luck alone moves it this much.
All 35 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 15 Feb 2024 51,795.20 | 14 Apr 2024 63,924.50 | 59 | $12,129.30 |
| short | 14 Apr 2024 63,924.50 | 17 May 2024 65,235.20 | 33 | −$1,310.69 |
| long | 17 May 2024 65,235.20 | 15 Jun 2024 66,044.00 | 29 | $808.78 |
| short | 15 Jun 2024 66,044.00 | 17 Jul 2024 65,044.00 | 32 | $999.99 |
| long | 17 Jul 2024 65,044.00 | 4 Aug 2024 60,698.00 | 18 | −$4,346.01 |
| short | 4 Aug 2024 60,698.00 | 24 Aug 2024 64,037.20 | 20 | −$3,339.25 |
| long | 24 Aug 2024 64,037.20 | 1 Sep 2024 58,974.00 | 8 | −$5,063.24 |
| short | 1 Sep 2024 58,974.00 | 18 Sep 2024 60,314.00 | 17 | −$1,339.99 |
| long | 18 Sep 2024 60,314.00 | 10 Oct 2024 60,636.00 | 22 | $322.02 |
| short | 10 Oct 2024 60,636.00 | 15 Oct 2024 66,084.00 | 5 | −$5,447.99 |
| long | 15 Oct 2024 66,084.00 | 24 Dec 2024 94,881.50 | 70 | $28,797.50 |
| short | 24 Dec 2024 94,881.50 | 7 Jan 2025 102,236.00 | 14 | −$7,354.13 |
| long | 7 Jan 2025 102,236.00 | 10 Jan 2025 92,552.50 | 3 | −$9,683.11 |
| short | 10 Jan 2025 92,552.50 | 17 Jan 2025 99,987.30 | 7 | −$7,434.81 |
| long | 17 Jan 2025 99,987.30 | 6 Feb 2025 96,612.40 | 20 | −$3,374.86 |
| short | 6 Feb 2025 96,612.40 | 22 Apr 2025 87,516.20 | 75 | $9,096.22 |
| long | 22 Apr 2025 87,516.20 | 7 Jun 2025 104,288.00 | 46 | $16,772.20 |
| short | 7 Jun 2025 104,288.00 | 10 Jun 2025 110,263.00 | 3 | −$5,974.59 |
| long | 10 Jun 2025 110,263.00 | 21 Jun 2025 103,298.00 | 11 | −$6,965.04 |
| short | 21 Jun 2025 103,298.00 | 27 Jun 2025 106,947.00 | 6 | −$3,649.08 |
| long | 27 Jun 2025 106,947.00 | 3 Aug 2025 112,546.00 | 37 | $5,599.29 |
| short | 3 Aug 2025 112,546.00 | 11 Aug 2025 119,294.00 | 8 | −$6,747.92 |
| long | 11 Aug 2025 119,294.00 | 20 Aug 2025 112,873.00 | 9 | −$6,421.32 |
| short | 20 Aug 2025 112,873.00 | 13 Sep 2025 116,029.00 | 24 | −$3,156.46 |
| long | 13 Sep 2025 116,029.00 | 26 Sep 2025 108,994.00 | 13 | −$7,034.92 |
| short | 26 Sep 2025 108,994.00 | 2 Oct 2025 118,595.00 | 6 | −$9,600.50 |
| long | 2 Oct 2025 118,595.00 | 14 Oct 2025 115,166.00 | 12 | −$3,428.99 |
| short | 14 Oct 2025 115,166.00 | 6 Jan 2026 93,859.70 | 84 | $21,306.30 |
| long | 6 Jan 2026 93,859.70 | 23 Jan 2026 89,559.70 | 17 | −$4,300.03 |
| short | 23 Jan 2026 89,559.70 | 13 Mar 2026 70,541.30 | 49 | $19,018.30 |
| long | 13 Mar 2026 70,541.30 | 28 Mar 2026 66,407.30 | 15 | −$4,134.06 |
| short | 28 Mar 2026 66,407.30 | 9 Apr 2026 71,069.90 | 12 | −$4,662.65 |
| long | 9 Apr 2026 71,069.90 | 20 May 2026 76,834.40 | 41 | $5,764.43 |
| short | 20 May 2026 76,834.40 | 11 Jul 2026 64,161.70 | 52 | $12,672.60 |
| long | 11 Jul 2026 64,161.70 | 17 Oct 2026 81,615.90 | 98 | $17,454.20 |
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 |
|---|---|---|---|---|---|
| 5-10-20 Cross this page | — | v4 strategy | +36.0% | 35 | 51.2% |
| JS-TechTrading- Supertrend-Strategy_Basic version by JS_TechTrading | supertrend ema | v5 strategy | +0.1% | 2 | 0.0% |
| [VJ] Mega Supertrend for Intraday by vikris | ema supertrend | v4 strategy | No trades on this market | ||
| Triple Supertrend with EMA and ADX strategy by kunjandetroja | supertrend ema | v5 strategy | −1.0% | 58 | 5.3% |
| 3x Supertrend and Stoch RSI by M3RZI | supertrend ema | v4 strategy | −128.7% | 24 | 207.6% |
| Strategy Myth-Busting #3 - BB_BUY+SuperTrend - [MYN] by myncrypto | ema supertrend | v5 strategy | −115.1% | 6 | 123.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 17 ms | Yes 1,000 bars in 65 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. PineTS runs Pine Script v5 and v6 only.
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/// © aadilpatel07//@version=4strategy("5-10-20 Cross", overlay=true)src = close, len1 = input(5, minval=1, title="EMA 1")len2 = input(10, minval=1, title="EMA 2")len3 = input(20, minval=1, title="EMA 3")mult = input(type=input.float, defval=2)len = input(type=input.integer, defval=14)[superTrend, dir] = supertrend(mult, len)ema1 = ema(src, len1)ema2 = ema(src, len2)ema3 = ema(src, len3)//EMA Colorcol1 = color.limecol2 = color.bluecol3 = color.red//EMA Plotsplot(series=ema1,color=col1, title="EMA1")plot(series=ema2,color=col2, title="EMA2")plot(series=ema3,color=col3, title="EMA3")//plot SuperTrendcolResistance = dir == 1 and dir == dir[1] ? color.new(color.red, 100) : color.new(color.green, 100)colSupport = dir == -1 and dir == dir[1] ? color.new(color.green, 0) : color.new(color.green, 10)plot(superTrend, color = colResistance, linewidth=1)plot(superTrend, color = colSupport, linewidth=1)//longCondition = crossover(ema1, ema2) and crossover(ema1,ema3) and crossover(ema2,ema3)longCondition = ema1 > ema2 and ema1 > ema3 and ema2 > ema3 and ema2 < ema1 and dir == -1if (longCondition) strategy.entry("My Long Entry Id", strategy.long)//shortCondition = crossover(ema2, ema1) and crossover(ema3,ema1) and crossover(ema3,ema2)shortCondition = ema1 < ema2 and ema1 < ema3 and ema2 < ema3 and ema2 > ema1 and dir == 1if (shortCondition) strategy.entry("My Short Entry Id", strategy.short)