Pine Script v4 · Strategy
Triple EMA Strategy
A Pine Script v4 strategy built on EMA (close, 5). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits InitPosition in cash and pays no commission. 9 settings; defaults include Year 2021, Month (0=ALL) 0 and Stop Loss (ticks) 100.
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 Triple EMA Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Triple EMA Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- Can Triple EMA Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- Does Triple EMA Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 45, 49, 56, 61.
- Does Triple EMA Strategy run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 39 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA1
- EMA2
- EMA3
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.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.
-
Check
1 setting does nothing
“═════ Data Filtering ═════” is declared but never read.
-
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.
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, crossover → ta.crossover, crossunder → ta.crossunder, max → math.max, min → math.min.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=4 → //@version=5
- Line 18: input(type = input.integer) → input.int()
- Line 19: input(type = input.integer) → input.int()
- Line 20: input(type = input.integer) → input.int()
- Line 21: input(type = input.integer) → input.int()
- Line 22: input(type = input.integer) → input.int()
10 more edits
- Line 23: input(type = input.integer) → input.int()
- Line 24: input(type = input.integer) → input.int()
- Line 25: input(type = input.integer) → input.int()
- Line 36: ema → ta.ema
- Line 37: ema → ta.ema
- Line 38: ema → ta.ema
- Line 40: crossover → ta.crossover
- Line 41: crossunder → ta.crossunder
- Line 44: max → math.max
- Line 48: min → math.min
⋯// © Matt Dearden - IndoPilot-// @version=4+// @version=5/////////////////////////////////////////////////////// Initial Parameters /////////////////////////////////////////////////////// ⋯DateFilter = input(false, "═════ Data Filtering ═════") -InitYear = input(title="Year", type=input.integer, defval=2021, minval=2000, maxval=2021)+InitYear = input.int(title="Year", defval=2021, minval=2000, maxval=2021)-InitMonth = input(title="Month (0=ALL)", type=input.integer, defval=0, minval=0, maxval=12)+InitMonth = input.int(title="Month (0=ALL)", defval=0, minval=0, maxval=12)-InitStopLoss = input(title="Stop Loss (ticks)", type=input.integer, defval=100, minval=0, maxval=1000) +InitStopLoss = input.int(title="Stop Loss (ticks)", defval=100, minval=0, maxval=1000) -TrailingStopLoss = input(title="Trailing S/L (ticks)", type=input.integer, defval=130, minval=0, maxval=1000) +TrailingStopLoss = input.int(title="Trailing S/L (ticks)", defval=130, minval=0, maxval=1000) -InitBuffer = input(title="Buffer (ticks)", type=input.integer, defval=15, minval=0, maxval=1000) +InitBuffer = input.int(title="Buffer (ticks)", defval=15, minval=0, maxval=1000) -InitEMA1 = input(title="EMA 1", type=input.integer, defval=5, minval=0, maxval=1000) +InitEMA1 = input.int(title="EMA 1", defval=5, minval=0, maxval=1000) -InitEMA2 = input(title="EMA 2", type=input.integer, defval=20, minval=0, maxval=1000) +InitEMA2 = input.int(title="EMA 2", defval=20, minval=0, maxval=1000) -InitEMA3 = input(title="EMA 3", type=input.integer, defval=50, minval=0, maxval=1000) +InitEMA3 = input.int(title="EMA 3", defval=50, minval=0, maxval=1000) //////////////////////////////////////////////////////////// Variables ///////////////////////////////////////////////////////////⋯/////////////////////////////////////////////////////// Triple EMA Strategy //////////////////////////////////////////////////////-EMA1 = ema(close, InitEMA1)+EMA1 = ta.ema(close, InitEMA1)-EMA2= ema(close, InitEMA2)+EMA2= ta.ema(close, InitEMA2)-EMA3 = ema(close, InitEMA3)+EMA3 = ta.ema(close, InitEMA3)//entry conditions-longCondition = crossover(EMA1, EMA2) and close > EMA3 and EMA1 > EMA3 and EMA2 > EMA3 and close > (close[1] + Buffer) +longCondition = ta.crossover(EMA1, EMA2) and close > EMA3 and EMA1 > EMA3 and EMA2 > EMA3 and close > (close[1] + Buffer) -shortCondition = crossunder(EMA1, EMA2) and close < EMA3 and EMA1 < EMA3 and EMA2 < EMA3 and close < (close[1] - Buffer) +shortCondition = ta.crossunder(EMA1, EMA2) and close < EMA3 and EMA1 < EMA3 and EMA2 < EMA3 and close < (close[1] - Buffer) /////////////////////////////////////////////////////// Trailing Stoploss ////////////////////////////////////////////////////////if (strategy.position_size > 0 and (close > (StartPrice + (TrailingStopLoss / (100 * Multiplier))))) - StopLoss := max(StopLoss, close - (TrailingStopLoss / (100 * Multiplier))) + StopLoss := math.max(StopLoss, close - (TrailingStopLoss / (100 * Multiplier))) strategy.exit("Long Stoploss", "Long", stop=StopLoss) ⋯if (strategy.position_size < 0 and (close < (StartPrice - (InitStopLoss / (100 * Multiplier))))) - StopLoss := min(StopLoss, close + (TrailingStopLoss / (100 * Multiplier)))+ StopLoss := math.min(StopLoss, close + (TrailingStopLoss / (100 * Multiplier))) strategy.exit("Short Stoploss", "Short", stop=StopLoss) ⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 17: input() → input.bool()
⋯///////////////////////////////////////////////////////////// Inputs /////////////////////////////////////////////////////////////-DateFilter = input(false, "═════ Data Filtering ═════") +DateFilter = input.bool(false, "═════ Data Filtering ═════") InitYear = input.int(title="Year", defval=2021, minval=2000, maxval=2021)⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Matt Dearden - IndoPilot-// @version=5+// @version=6/////////////////////////////////////////////////////// Initial Parameters /////////////////////////////////////////////////////// ⋯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 |
|---|---|---|---|
| ═════ Data Filtering ═════ | false | bool | unused |
| Year | 2021 | int (written input.integer) · min 2000 · max 2021 | entry Long exit Long Stoploss entry Short exit Short Stoploss line 52 line 57 |
| Month (0=ALL) | 0 | int (written input.integer) · min 0 · max 12 | entry Long exit Long Stoploss entry Short exit Short Stoploss line 52 line 57 |
| Stop Loss (ticks) | 100 | int (written input.integer) · min 0 · max 1000 | StopLoss OrderQty exit Short Stoploss line 47 |
| Trailing S/L (ticks) | 130 | int (written input.integer) · min 0 · max 1000 | StopLoss exit Long Stoploss line 43 |
| Buffer (ticks) | 15 | int (written input.integer) · min 0 · max 1000 | Buffer |
| EMA 1 | 5 | int (written input.integer) · min 0 · max 1000 | EMA1 |
| EMA 2 | 20 | int (written input.integer) · min 0 · max 1000 | EMA2 |
| EMA 3 | 50 | int (written input.integer) · min 0 · max 1000 | EMA3 |
What it calculates
- EMA (
ema,ta.emain v5)close, EMA 1 (5)EMA1 · line 36 - EMA (
ema,ta.emain v5)close, EMA 2 (20)EMA2 · line 37 - EMA (
ema,ta.emain v5)close, EMA 3 (50)EMA3 · line 38
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 |
|---|---|---|---|
| Exit Long Stoploss stop | (strategy.position_size > 0 and (close > (StartPrice + (TrailingStopLoss / (100 * Multiplier))))) | On | 45 |
| Exit Short Stoploss stop | (strategy.position_size < 0 and (close < (StartPrice - (InitStopLoss / (100 * Multiplier))))) | On | 49 |
| Open Long long | (longCondition and year == InitYear and (InitMonth == 0 or month == InitMonth)) | On | 55 |
| Exit Long Stoploss stop | (longCondition and year == InitYear and (InitMonth == 0 or month == InitMonth)) | On | 56 |
| Open Short short | (shortCondition and year == InitYear and (InitMonth == 0 or month == InitMonth)) | On | 60 |
| Exit Short Stoploss stop | (shortCondition and year == InitYear and (InitMonth == 0 or month == InitMonth)) | On | 61 |
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.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 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 3, EMA 2 10) made 0.0% before 26 Dec 2025 and 0.0% after it, against 0.0% for the defaults. 0% of the 48 combinations made money in-sample and 0% out-of-sample.
| EMA 2 ↓ · EMA 1 → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 10 | 0% | 0% | 0% | 0% | 0% | 0% |
| 12 | 0% | 0% | 0% | 0% | 0% | 0% |
| 14 | 0% | 0% | 0% | 0% | 0% | 0% |
| 17 | 0% | 0% | 0% | 0% | 0% | 0% |
| 20 | 0% | 0% | 0% | 0% | 0% | 0% |
| 24 | 0% | 0% | 0% | 0% | 0% | 0% |
| 28 | 0% | 0% | 0% | 0% | 0% | 0% |
| 34 | 0% | 0% | 0% | 0% | 0% | 0% |
| EMA 2 ↓ · EMA 1 → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 10 | 0% | 0% | 0% | 0% | 0% | 0% |
| 12 | 0% | 0% | 0% | 0% | 0% | 0% |
| 14 | 0% | 0% | 0% | 0% | 0% | 0% |
| 17 | 0% | 0% | 0% | 0% | 0% | 0% |
| 20 | 0% | 0% | 0% | 0% | 0% | 0% |
| 24 | 0% | 0% | 0% | 0% | 0% | 0% |
| 28 | 0% | 0% | 0% | 0% | 0% | 0% |
| 34 | 0% | 0% | 0% | 0% | 0% | 0% |
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.
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 |
|---|---|---|---|---|---|
| Triple EMA Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| 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 19 ms | Yes 1,000 bars in 39 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/// © Matt Dearden - IndoPilot// @version=4/////////////////////////////////////////////////////// Initial Parameters /////////////////////////////////////////////////////// SystemName = "Triple EMA Strategy"ShortSystemName = "TEMA"InitPosition = 100000InitCapital = 100000InitCommission = 0.004 //approx value to compensate for Oanda spreadsInitPyramidMax = 0CalcOnorderFills = truestrategy(title=SystemName, shorttitle=ShortSystemName, overlay=true, pyramiding=InitPyramidMax, default_qty_type=strategy.cash, default_qty_value=InitPosition, commission_type=strategy.commission.percent, commission_value=InitCommission, initial_capital=InitCapital, max_lines_count=500, max_labels_count=500, process_orders_on_close=false, calc_on_every_tick=false) ///////////////////////////////////////////////////////////// Inputs /////////////////////////////////////////////////////////////DateFilter = input(false, "═════ Data Filtering ═════") InitYear = input(title="Year", type=input.integer, defval=2021, minval=2000, maxval=2021)InitMonth = input(title="Month (0=ALL)", type=input.integer, defval=0, minval=0, maxval=12)InitStopLoss = input(title="Stop Loss (ticks)", type=input.integer, defval=100, minval=0, maxval=1000) TrailingStopLoss = input(title="Trailing S/L (ticks)", type=input.integer, defval=130, minval=0, maxval=1000) InitBuffer = input(title="Buffer (ticks)", type=input.integer, defval=15, minval=0, maxval=1000) InitEMA1 = input(title="EMA 1", type=input.integer, defval=5, minval=0, maxval=1000) InitEMA2 = input(title="EMA 2", type=input.integer, defval=20, minval=0, maxval=1000) InitEMA3 = input(title="EMA 3", type=input.integer, defval=50, minval=0, maxval=1000) //////////////////////////////////////////////////////////// Variables ///////////////////////////////////////////////////////////var StopLoss = float(0.0)var StartPrice = float(0.0)//setup multipliers and catch JPY differenceMultiplier = syminfo.currency == "JPY" ? 10 : 1000//get the daily exchange rate from yesterday//X_rate = security(AccountCurrency+syminfo.currency, "D", close[1]) OrderQty = int(InitCapital / (InitStopLoss / Multiplier)) Buffer = InitBuffer / (Multiplier * 100)/////////////////////////////////////////////////////// Triple EMA Strategy //////////////////////////////////////////////////////EMA1 = ema(close, InitEMA1)EMA2= ema(close, InitEMA2)EMA3 = ema(close, InitEMA3)//entry conditionslongCondition = crossover(EMA1, EMA2) and close > EMA3 and EMA1 > EMA3 and EMA2 > EMA3 and close > (close[1] + Buffer) shortCondition = crossunder(EMA1, EMA2) and close < EMA3 and EMA1 < EMA3 and EMA2 < EMA3 and close < (close[1] - Buffer) /////////////////////////////////////////////////////// Trailing Stoploss ////////////////////////////////////////////////////////if (strategy.position_size > 0 and (close > (StartPrice + (TrailingStopLoss / (100 * Multiplier))))) StopLoss := max(StopLoss, close - (TrailingStopLoss / (100 * Multiplier))) strategy.exit("Long Stoploss", "Long", stop=StopLoss) if (strategy.position_size < 0 and (close < (StartPrice - (InitStopLoss / (100 * Multiplier))))) StopLoss := min(StopLoss, close + (TrailingStopLoss / (100 * Multiplier))) strategy.exit("Short Stoploss", "Short", stop=StopLoss) ///////////////////////////////////////////////////////// Setup entries /////////////////////////////////////////////////////////if (longCondition and year == InitYear and (InitMonth == 0 or month == InitMonth)) StartPrice := close StopLoss := StartPrice - (InitStopLoss / (100 * Multiplier)) strategy.entry("Long", strategy.long, qty=OrderQty) strategy.exit("Long Stoploss", "Long", stop=StopLoss)if (shortCondition and year == InitYear and (InitMonth == 0 or month == InitMonth)) StartPrice := close StopLoss := StartPrice + (InitStopLoss / (100 * Multiplier)) strategy.entry("Short", strategy.short, qty=OrderQty) strategy.exit("Short Stoploss", "Short", stop=StopLoss) ///////////////////////////////////////////////////////// Draw the EMAs /////////////////////////////////////////////////////////plot(EMA1, "EMA1", color=#00FF00)plot(EMA2, "EMA2", color=#FF0000)plot(EMA3, "EMA3", color=#4040FF)