Pine Script v5 · Strategy
EMA12-26 buy spot only
A Pine Script v5 strategy built on Crossover or EMA (close, 12, close, 26). 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 is one contract and pays no commission. It has no settings.
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 EMA12-26 buy spot only repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did EMA12-26 buy spot only do on BTCUSDT 1D with default settings?
- +1.00%
- From 26 Jan 2024 to 21 Oct 2026, over 16 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does EMA12-26 buy spot only 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: 16 before, 12 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 EMA12-26 buy spot only use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does EMA12-26 buy spot only run in Zeal Terminal?
- Yes
- It compiles in 7 ms and runs 1,000 bars in 15 ms, in the browser.
BTCUSDT · 1D · default settings
- Crossover
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +1.00%
- $10,012.70
- Buy and hold
- +102.5%
- same period
- Closed trades
- 16
- 4 won · 12 lost
- Profitable
- 25.0%
- of closed trades
- Profit factor
- 1.20
- gross profit ÷ gross loss
- Max drawdown
- 2.68%
- −$27,714.40
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A long 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
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.
The script declares no settings.
What it calculates
- Crossover / EMAta.ema(close, 12), ta.ema(close, 26)
longCondition · line 5
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 buy long | (longCondition) | On | 7 |
| Close buy | ta.crossunder(ta.ema(close, 12), ta.ema(close, 26)) | On | 9 |
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 | +1.0% | +102.5% | 16 | 25% | 1.20 | 2.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.0% | +5.5% | 21 | 29% | 1.01 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 14 | 29% | 1.17 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 16 | 31% | 1.59 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 15 | 33% | 0.84 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 15 | 33% | 2.60 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 16 | 38% | 2.06 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 18 | 28% | 1.34 | 0.0% | 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 | 25% | −$2,602.48 |
| Sideways market | 6 | 17% | $1,317.41 |
| Falling market | 6 | 33% | $11,297.80 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
4.0%
The 95th percentile of the worst drawdown when the same 16 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.8% to 4.0%; the tick is what actually happened, 2.6%. Order luck alone moves it this much.
All 16 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 18 May 2024 67,024.00 | 17 Jun 2024 66,676.90 | 30 | −$347.14 |
| long | 19 Jul 2024 63,987.90 | 5 Aug 2024 58,161.00 | 17 | −$5,826.92 |
| long | 25 Aug 2024 64,157.00 | 29 Aug 2024 59,034.90 | 4 | −$5,122.12 |
| long | 19 Sep 2024 61,760.00 | 30 Dec 2024 93,738.20 | 102 | $31,978.20 |
| long | 6 Jan 2025 98,363.60 | 10 Jan 2025 92,552.50 | 4 | −$5,811.12 |
| long | 17 Jan 2025 99,987.30 | 6 Feb 2025 96,612.40 | 20 | −$3,374.86 |
| long | 20 Apr 2025 85,077.00 | 22 Jun 2025 102,120.00 | 63 | $17,043.00 |
| long | 26 Jun 2025 107,341.00 | 21 Aug 2025 114,271.00 | 56 | $6,930.64 |
| long | 14 Sep 2025 115,918.00 | 26 Sep 2025 108,994.00 | 12 | −$6,923.80 |
| long | 2 Oct 2025 118,595.00 | 16 Oct 2025 110,763.00 | 14 | −$7,831.71 |
| long | 6 Jan 2026 93,859.70 | 25 Jan 2026 89,225.30 | 19 | −$4,634.37 |
| long | 16 Mar 2026 72,815.30 | 23 Mar 2026 67,859.00 | 7 | −$4,956.25 |
| long | 24 Mar 2026 70,906.40 | 27 Mar 2026 68,820.30 | 3 | −$2,086.14 |
| long | 10 Apr 2026 71,788.00 | 23 May 2026 75,539.50 | 43 | $3,751.52 |
| long | 16 Jul 2026 64,756.30 | 2 Aug 2026 62,823.70 | 17 | −$1,932.63 |
| long | 7 Aug 2026 64,323.60 | 13 Aug 2026 63,480.00 | 6 | −$843.62 |
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 |
|---|---|---|---|---|---|
| EMA12-26 buy spot only this page | — | v5 strategy | +1.0% | 16 | 2.7% |
| 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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
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: 16 before, 12 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.
⋯// © sasinp-//@version=5+//@version=6strategy("EMA12/26 buy spot only", overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 7 ms | Yes 1,000 bars in 15 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/// © sasinp//@version=5strategy("EMA12/26 buy spot only", overlay=true)longCondition = ta.crossover(ta.ema(close, 12), ta.ema(close, 26))if (longCondition) strategy.entry("buy", strategy.long)if ta.crossunder(ta.ema(close, 12), ta.ema(close, 26)) strategy.close("buy")