Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Simple EMA Crossing Strategy TradeMath

A Pine Script v4 strategy built on EMA (close, 21) and Crossover (emaFast, emaSlow). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 1 setting; defaults include Stop Loss 3.

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 Simple EMA Crossing Strategy TradeMath repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Simple EMA Crossing Strategy TradeMath do on BTCUSDT 1D with default settings?
−0.11%
From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Simple EMA Crossing Strategy TradeMath 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 Simple EMA Crossing Strategy TradeMath use a stop loss?
Yes
strategy.exit sets a stop on line 19.
Does Simple EMA Crossing Strategy TradeMath run in Zeal Terminal?
Yes
It compiles in 4 ms and runs 1,000 bars in 13 ms, in the browser.

BTCUSDT · 1D · default settings

  • EMA
  • EMA
  • Crossover
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (1)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$99,894$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
Net profit
−0.11%
−$105.07
Buy and hold
+102.5%
same period
Closed trades
8
2 won · 6 lost
Profitable
25.0%
of closed trades
Profit factor
0.99
gross profit ÷ gross loss
Max drawdown
9.09%
−$9,330.52

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

    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.

  • Note

    Uses an argument v6 removed

    when = on line 18. The upgraded version below moves each call inside an if block.

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.
  • 1 strategy call uses the when = argument (line 18). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 4: //@version=4 → //@version=5
  • Line 9: ema → ta.ema
  • Line 10: ema → ta.ema
  • Line 12: crossover → ta.crossover
⋯// Simple EMA strategy for BTCUSDT, timeframe - 1H. Based on crossing EMA21 and EMA55-//@version=4+//@version=5strategy("Simple EMA Crossing Strategy ", overlay=true)⋯//Ema's-emaFast=ema(close,21)+emaFast=ta.ema(close,21)-emaSlow=ema(close,55)+emaSlow=ta.ema(close,55)//Long Contition is crossover ema21 and ema55-longCond = crossover(emaFast,emaSlow) +longCond = ta.crossover(emaFast,emaSlow) //Stop level based on input percent_loss, default = 3%⋯

Clean v5

VerifiedDownload the v5 script

Same 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 7: input() → input.int()
  • Line 18: when = longCond → if block
⋯//Percent for stop loss, recommended = 3%-percent_loss = input(3, minval=1, title="Stop Loss") +percent_loss = input.int(3, minval=1, title="Stop Loss") //Ema's⋯//Entries and exits -strategy.entry("Long", strategy.long, when=longCond)+if longCond+    strategy.entry("Long", strategy.long)strategy.exit("Stop Loss/TP","Long", stop=stop_level_long, limit = take_level_long)

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: 8 before, 5 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.

⋯// Simple EMA strategy for BTCUSDT, timeframe - 1H. Based on crossing EMA21 and EMA55-//@version=5+//@version=6strategy("Simple EMA Crossing Strategy ", overlay=true)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Stop Loss3int · min 1stop_level_long take_level_long

What it calculates

  • EMA (ema, ta.ema in v5)close, 21emaFast · line 9
  • EMA (ema, ta.ema in v5)close, 55emaSlow · line 10
  • Crossover (crossover, ta.crossover in v5)emaFast, emaSlowlongCond · line 12

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.

closecloseprice datapercent_lossStop Losssetting · 3emaFastEMA→ emaFastemaSlowEMA→ emaSlowlongCondCrossover→ longCondstop_level_long, take_level_longstop_level_long · take_…2 valuesentry:LongOpen Longstrategy.entryexit:Stop Loss/TPexit Stop Loss/TPstrategy.exit

Order rules

OrderFires whenBy defaultLine
Open Long longlongCondOn18
Exit Stop Loss/TP stop and limitevery barOn19

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.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−0.1%+102.5%825%0.999.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+3.6%+5.5%250%2.842.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.1%+9.8%729%0.810.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%540%1.740.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%956%3.040.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%560%5.080.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%520%0.650.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%729%1.190.1%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 barsTradesWonP&L
Rising market10%−$1,986.20
Sideways market633%$4,193.30
Falling market10%−$2,312.17

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

14.4%

The 95th percentile of the worst drawdown when the same 8 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 6.3% to 14.4%; the tick is what actually happened, 9.1%. Order luck alone moves it this much.

0%17%
All 8 trades
SideEntryExitBarsP&L
long16 May 2024 66,206.5018 Jun 2024 64,220.3033−$1,986.20
long24 Jul 2024 65,936.0025 Jul 2024 63,957.901−$1,978.08
long24 Sep 2024 63,340.001 Oct 2024 61,439.807−$1,900.20
long26 Apr 2025 94,638.708 May 2025 103,156.0012$8,517.49
long16 Sep 2025 115,350.0022 Sep 2025 111,889.006−$3,460.50
long2 Oct 2025 118,595.0010 Oct 2025 115,037.008−$3,557.85
long18 Apr 2026 77,072.0019 Apr 2026 74,759.801−$2,312.17
long21 Aug 2026 73,027.0024 Aug 2026 79,599.503$6,572.44

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Simple EMA Crossing Strategy TradeMath this page—v4 strategy−0.1%89.1%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,274.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 4 msYes 1,000 bars in 13 msNot measured
PineTSNo 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/// © TheHulkTrading// Simple EMA strategy for BTCUSDT, timeframe - 1H. Based on crossing EMA21 and EMA55//@version=4strategy("Simple EMA Crossing Strategy ", overlay=true)//Percent for stop loss, recommended = 3%percent_loss = input(3, minval=1, title="Stop Loss") //Ema'semaFast=ema(close,21)emaSlow=ema(close,55)//Long Contition is crossover ema21 and ema55longCond = crossover(emaFast,emaSlow) //Stop level based on input percent_loss, default = 3%stop_level_long = strategy.position_avg_price*((100-percent_loss)/100)//Take profit - x3 of percent loss, default = 9%take_level_long = strategy.position_avg_price*((100+percent_loss*3)/100)//Entries and exits strategy.entry("Long", strategy.long, when=longCond)strategy.exit("Stop Loss/TP","Long", stop=stop_level_long, limit = take_level_long)