Pine Script v4 · Strategy
TEMA Cross Backtest
A Pine Script v4 strategy built on EMA (xPrice, 20). 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 no commission. 8 settings; defaults include From Month 1, From Day 1 and From Year 2020.
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 TEMA Cross Backtest repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
- How did TEMA Cross Backtest do on BTCUSDT 1D with default settings?
- +71.11%
- From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can TEMA Cross Backtest 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 TEMA Cross Backtest use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does TEMA Cross Backtest run in Zeal Terminal?
- Yes
- It compiles in 10 ms and runs 1,000 bars in 38 ms, in the browser.
BTCUSDT · 1D · default settings
- TEMA1
- TEMA2
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +71.11%
- $711.09
- Buy and hold
- +102.5%
- same period
- Closed trades
- 14
- 8 won · 6 lost
- Profitable
- 57.1%
- of closed trades
- Profit factor
- 3.06
- gross profit ÷ gross loss
- Max drawdown
- 22.79%
- −$227.93
One run with the author's default settings, $1,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
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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 39, 40. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 32
transp = on line 32. v5 folds the transparency into the colour with color.new(c, transp).
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 ema → ta.ema.
- 2 strategy calls use the when = argument (line 39, 40). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 14 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 20: ema → ta.ema
- Line 21: ema → ta.ema
- Line 22: ema → ta.ema
- Line 27: ema → ta.ema
- Line 28: ema → ta.ema
- Line 29: ema → ta.ema
- Line 32: transp = 75 → color.new(xnRes > ynRes ? color.green : color.red, 75)
⋯// © Seltzer_-//@version=4+//@version=5strategy(title="TEMA Cross Backtest", shorttitle="TEMA_X_BT", overlay=true, commission_type=strategy.commission.percent, commission_value=0, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯xPrice = close-xEMA1 = ema(xPrice, xLength)+xEMA1 = ta.ema(xPrice, xLength)-xEMA2 = ema(xEMA1, xLength)+xEMA2 = ta.ema(xEMA1, xLength)-xEMA3 = ema(xEMA2, xLength)+xEMA3 = ta.ema(xEMA2, xLength)xnRes = (3 * xEMA1) - (3 * xEMA2) + xEMA3⋯yPrice = close-yEMA1 = ema(yPrice, yLength)+yEMA1 = ta.ema(yPrice, yLength)-yEMA2 = ema(yEMA1, yLength)+yEMA2 = ta.ema(yEMA1, yLength)-yEMA3 = ema(yEMA2, yLength)+yEMA3 = ta.ema(yEMA2, yLength)ynRes = (3 * yEMA1) - (3 * yEMA2) + yEMA3ynResP = plot(ynRes, color=color.red, linewidth=2, title="TEMA2")-fill(xnResP, ynResP, color=xnRes > ynRes ? color.green : color.red, transp=75, editable=true)+fill(xnResP, ynResP, color=color.new(xnRes > ynRes ? color.green : color.red, 75), editable=true)// Buy and Sell Triggers⋯Same 14 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()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
4 more edits
- Line 18: input() → input.int()
- Line 25: input() → input.int()
- Line 39: when = xnRes > ynRes and window() → if block
- Line 40: when = xnRes < ynRes → if block
⋯// Backtest inputs-FromMonth = input(defval=1, title="From Month", minval=1, maxval=12)+FromMonth = input.int(defval=1, title="From Month", minval=1, maxval=12)-FromDay = input(defval=1, title="From Day", minval=1, maxval=31)+FromDay = input.int(defval=1, title="From Day", minval=1, maxval=31)-FromYear = input(defval=2020, title="From Year", minval=2010)+FromYear = input.int(defval=2020, title="From Year", minval=2010)-ToMonth = input(defval=1, title="To Month", minval=1, maxval=12)+ToMonth = input.int(defval=1, title="To Month", minval=1, maxval=12)-ToDay = input(defval=1, title="To Day", minval=1, maxval=31)+ToDay = input.int(defval=1, title="To Day", minval=1, maxval=31)-ToYear = input(defval=9999, title="To Year", minval=2017)+ToYear = input.int(defval=9999, title="To Year", minval=2017)// Define backtest timewindow⋯//TEMA Section-xLength = input(20, minval=1, title="Fast Length")+xLength = input.int(20, minval=1, title="Fast Length")xPrice = close⋯xnResP = plot(xnRes, color=color.green, linewidth=2, title="TEMA1")-yLength = input(60, minval=1, title="Slow Length")+yLength = input.int(60, minval=1, title="Slow Length")yPrice = close⋯// Entry & Exit signals-strategy.entry("Long", strategy.long, when = xnRes > ynRes and window()) +if xnRes > ynRes and window()+ strategy.entry("Long", strategy.long) -strategy.close("Long", when = xnRes < ynRes)+if xnRes < ynRes+ strategy.close("Long")//strategy.entry("Short", strategy.short, when = xnRes < ynRes and window())⋯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: 14 before, 14 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.
⋯// © Seltzer_-//@version=5+//@version=6strategy(title="TEMA Cross Backtest", shorttitle="TEMA_X_BT", overlay=true, commission_type=strategy.commission.percent, commission_value=0, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯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 |
|---|---|---|---|
| From Month | 1 | int · min 1 · max 12 | start |
| From Day | 1 | int · min 1 · max 31 | start |
| From Year | 2020 | int · min 2010 | start |
| To Month | 1 | int · min 1 · max 12 | finish |
| To Day | 1 | int · min 1 · max 31 | finish |
| To Year | 9999 | int · min 2017 | finish |
| Fast Length | 20 | int · min 1 | xEMA1 xEMA2 xEMA3 |
| Slow Length | 60 | int · min 1 | yEMA1 yEMA2 yEMA3 |
What it calculates
- EMA (
ema,ta.emain v5)xPrice, Fast Length (20)xEMA1 · line 20 - EMA (
ema,ta.emain v5)xEMA1, Fast Length (20)xEMA2 · line 21 - EMA (
ema,ta.emain v5)xEMA2, Fast Length (20)xEMA3 · line 22 - EMA (
ema,ta.emain v5)yPrice, Slow Length (60)yEMA1 · line 27 - EMA (
ema,ta.emain v5)yEMA1, Slow Length (60)yEMA2 · line 28 - EMA (
ema,ta.emain v5)yEMA2, Slow Length (60)yEMA3 · line 29
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 | xnRes > ynRes and window() | On | 39 |
| Close Long | xnRes < ynRes | On | 40 |
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 | +71.1% | +102.5% | 14 | 57% | 3.06 | 22.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +20.4% | +5.5% | 17 | 35% | 1.91 | 6.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +52.6% | +9.8% | 13 | 46% | 1.77 | 39.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +30.9% | +8.4% | 16 | 31% | 1.88 | 14.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +12.9% | +16.7% | 18 | 39% | 1.14 | 46.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +16.5% | +21.5% | 17 | 35% | 1.34 | 17.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.3% | +148.3% | 17 | 53% | 1.00 | 36.8% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +17.2% | +17.1% | 18 | 44% | 2.10 | 9.7% | 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 | 4 | 75% | $235.70 |
| Sideways market | 8 | 50% | $331.37 |
| Falling market | 2 | 50% | $144.01 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
25.0%
The 95th percentile of the worst drawdown when the same 14 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 14.7% to 25.0%; the tick is what actually happened, 18.8%. Order luck alone moves it this much.
All 14 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 22 Jul 2024 68,165.40 | 5 Aug 2024 58,161.00 | 14 | −$146.77 |
| long | 23 Aug 2024 60,375.80 | 4 Sep 2024 57,487.70 | 12 | −$40.81 |
| long | 14 Sep 2024 60,498.00 | 10 Oct 2024 60,636.00 | 26 | $1.85 |
| long | 15 Oct 2024 66,084.00 | 6 Nov 2024 69,372.00 | 22 | $40.51 |
| long | 7 Nov 2024 75,572.00 | 3 Dec 2024 95,840.60 | 26 | $229.26 |
| long | 21 Jan 2025 102,260.00 | 2 Feb 2025 100,636.00 | 12 | −$17.22 |
| long | 20 Mar 2025 86,845.90 | 30 May 2025 105,590.00 | 71 | $230.25 |
| long | 11 Jul 2025 116,010.00 | 29 Jul 2025 118,062.00 | 18 | $22.95 |
| long | 12 Sep 2025 115,483.00 | 27 Sep 2025 109,643.00 | 15 | −$66.75 |
| long | 1 Oct 2025 114,049.00 | 15 Oct 2025 113,028.00 | 14 | −$11.22 |
| long | 3 Dec 2025 91,277.90 | 26 Jan 2026 86,670.40 | 54 | −$62.70 |
| long | 27 Feb 2026 67,485.20 | 14 May 2026 79,313.60 | 76 | $206.71 |
| long | 4 Jul 2026 62,583.30 | 12 Sep 2026 77,225.70 | 70 | $324.30 |
| long | 24 Sep 2026 84,397.60 | 27 Sep 2026 84,433.10 | 3 | $0.72 |
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 |
|---|---|---|---|---|---|
| TEMA Cross Backtest this page | — | v4 strategy | +71.1% | 14 | 22.8% |
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 10 ms | Yes 1,000 bars in 38 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/// © Seltzer_//@version=4strategy(title="TEMA Cross Backtest", shorttitle="TEMA_X_BT", overlay=true, commission_type=strategy.commission.percent, commission_value=0, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Backtest inputsFromMonth = input(defval=1, title="From Month", minval=1, maxval=12)FromDay = input(defval=1, title="From Day", minval=1, maxval=31)FromYear = input(defval=2020, title="From Year", minval=2010)ToMonth = input(defval=1, title="To Month", minval=1, maxval=12)ToDay = input(defval=1, title="To Day", minval=1, maxval=31)ToYear = input(defval=9999, title="To Year", minval=2017)// Define backtest timewindowstart = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start windowfinish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish windowwindow() => // create function "within window of time" time >= start and time <= finish ? true : false//TEMA SectionxLength = input(20, minval=1, title="Fast Length")xPrice = closexEMA1 = ema(xPrice, xLength)xEMA2 = ema(xEMA1, xLength)xEMA3 = ema(xEMA2, xLength)xnRes = (3 * xEMA1) - (3 * xEMA2) + xEMA3xnResP = plot(xnRes, color=color.green, linewidth=2, title="TEMA1")yLength = input(60, minval=1, title="Slow Length")yPrice = closeyEMA1 = ema(yPrice, yLength)yEMA2 = ema(yEMA1, yLength)yEMA3 = ema(yEMA2, yLength)ynRes = (3 * yEMA1) - (3 * yEMA2) + yEMA3ynResP = plot(ynRes, color=color.red, linewidth=2, title="TEMA2")fill(xnResP, ynResP, color=xnRes > ynRes ? color.green : color.red, transp=75, editable=true)// Buy and Sell TriggersLongEntryAlert = xnRes > ynResLongCloseAlert = xnRes < ynResShortEntryAlert = xnRes < ynResShortCloseAlert = xnRes > ynRes// Entry & Exit signalsstrategy.entry("Long", strategy.long, when = xnRes > ynRes and window()) strategy.close("Long", when = xnRes < ynRes)//strategy.entry("Short", strategy.short, when = xnRes < ynRes and window())//strategy.close("Short", when = xnRes > ynRes)