Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MM tester

A Pine Script v4 strategy built on EMA or SMA (close, 14), Crossover (MM1, MM2) and Crossunder (MM1, MM2). 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. 3 settings; defaults include MM1 14, MM2 28 and MM type EMA.

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 MM tester repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 12 of 12 trades.
How did MM tester do on BTCUSDT 1D with default settings?
−11.11%
From 26 Jan 2024 to 21 Oct 2026, over 33 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can MM tester 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 MM tester use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does MM tester run in Zeal Terminal?
Yes
It compiles in 7 ms and runs 1,000 bars in 19 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • 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 (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$104,256$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. Lines are what the script plots.
Net profit
−11.11%
−$11,111.60
Buy and hold
+102.5%
same period
Closed trades
33
8 won · 25 lost
Profitable
24.2%
of closed trades
Profit factor
0.91
gross profit ÷ gross loss
Max drawdown
37.11%
−$37,111.40

One run with the author's default settings, $100,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.

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, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 12: ema → ta.ema
  • Line 12: sma → ta.sma
  • Line 13: ema → ta.ema
  • Line 13: sma → ta.sma
  • Line 18: crossover → ta.crossover
  • Line 22: crossunder → ta.crossunder
⋯// © luisgzafra-//@version=4+//@version=5strategy("MM tester", overlay=true)⋯//-MM1             = tipo_MM == "EMA"? ema(close, ema1) : sma(close, ema1)+MM1             = tipo_MM == "EMA"? ta.ema(close, ema1) : ta.sma(close, ema1)-MM2             = tipo_MM == "EMA"? ema(close, ema2) : sma(close, ema2)+MM2             = tipo_MM == "EMA"? ta.ema(close, ema2) : ta.sma(close, ema2)//⋯//-longCondition   = crossover(MM1, MM2)+longCondition   = ta.crossover(MM1, MM2)if (longCondition)⋯//-shortCondition  = crossunder(MM1, MM2)+shortCondition  = ta.crossunder(MM1, MM2)if (shortCondition)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 10: input() → input.string()
⋯//-int ema1        = input(title="MM1", defval=14, minval=0)+int ema1        = input.int(title="MM1", defval=14, minval=0)-int ema2        = input(title="MM2", defval=28, minval=0)+int ema2        = input.int(title="MM2", defval=28, minval=0)//-tipo_MM         = input(title="MM type", options=["EMA", "SMA"], defval="EMA")+tipo_MM         = input.string(title="MM type", options=["EMA", "SMA"], defval="EMA")//⋯

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: 33 before, 24 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.

⋯// © luisgzafra-//@version=5+//@version=6strategy("MM tester", 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
MM114int · min 0MM1
MM228int · min 0MM2
MM typeEMAstring · options ["EMA", "SMA"]MM1 MM2

What it calculates

  • EMA / SMA (ema, ta.ema in v5)close, MM1 (14) · chosen by MM typeMM1 · line 12
  • EMA / SMA (ema, ta.ema in v5)close, MM2 (28) · chosen by MM typeMM2 · line 13
  • Crossover (crossover, ta.crossover in v5)MM1, MM2longCondition · line 18
  • Crossunder (crossunder, ta.crossunder in v5)MM1, MM2shortCondition · line 22

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 datatipo_MMMM typesetting · EMAema1MM1setting · 14ema2MM2setting · 28MM1EMA / SMA→ MM1 · by MM typeMM2EMA / SMA→ MM2 · by MM typelongConditionCrossover→ longConditionshortConditionCrossunder→ shortConditionentry:My Long Entry IdOpen My Long Entry Idstrategy.entryentry:My Short Entry IdOpen My Short Entry Idstrategy.entryplot:15plotplotplot:16plotplot

Order rules

OrderFires whenBy defaultLine
Open My Long Entry Id long(longCondition)On20
Open My Short Entry Id short(shortCondition)On24

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.

12/12trades 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−11.1%+102.5%3324%0.9137.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.6%+5.5%3132%1.0515.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.3%+9.8%2836%1.232.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.5%+8.4%3219%0.691.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.1%+16.7%3225%0.780.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%2540%2.190.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.7%+148.3%2433%2.300.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%3324%0.940.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 market922%−$20,025.20
Sideways market1527%$12,032.20
Falling market922%−$3,118.64

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

How bad could the drawdown be?

58.2%

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

0%67%
All 33 trades
SideEntryExitBarsP&L
short17 Apr 2024 63,793.4019 May 2024 66,915.2032−$3,121.80
long19 May 2024 66,915.2019 Jun 2024 65,175.3031−$1,739.88
short19 Jun 2024 65,175.3020 Jul 2024 66,660.0031−$1,484.69
long20 Jul 2024 66,660.005 Aug 2024 58,161.0016−$8,499.01
short5 Aug 2024 58,161.0026 Aug 2024 64,220.0021−$6,058.99
long26 Aug 2024 64,220.0029 Aug 2024 59,034.903−$5,185.09
short29 Aug 2024 59,034.9020 Sep 2024 62,948.0022−$3,913.10
long20 Sep 2024 62,948.0031 Dec 2024 92,792.10102$29,844.10
short31 Dec 2024 92,792.105 Jan 2025 98,220.505−$5,428.46
long5 Jan 2025 98,220.5010 Jan 2025 92,552.505−$5,668.02
short10 Jan 2025 92,552.5016 Jan 2025 100,497.006−$7,944.86
long16 Jan 2025 100,497.007 Feb 2025 96,554.4022−$3,943.00
short7 Feb 2025 96,554.4022 Apr 2025 87,516.2074$9,038.13
long22 Apr 2025 87,516.2023 Jun 2025 100,964.0062$13,447.60
short23 Jun 2025 100,964.0026 Jun 2025 107,341.003−$6,376.72
long26 Jun 2025 107,341.0022 Aug 2025 112,500.0057$5,159.41
short22 Aug 2025 112,500.0015 Sep 2025 115,268.0024−$2,768.01
long15 Sep 2025 115,268.0026 Sep 2025 108,994.0011−$6,273.52
short26 Sep 2025 108,994.002 Oct 2025 118,595.006−$9,600.50
long2 Oct 2025 118,595.0016 Oct 2025 110,763.0014−$7,831.71
short16 Oct 2025 110,763.006 Jan 2026 93,859.7082$16,903.60
long6 Jan 2026 93,859.7025 Jan 2026 89,225.3019−$4,634.37
short25 Jan 2026 89,225.3017 Mar 2026 74,884.7051$14,340.70
long17 Mar 2026 74,884.7023 Mar 2026 67,859.006−$7,025.67
short23 Mar 2026 67,859.0026 Mar 2026 71,336.503−$3,477.53
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$2,516.22
short27 Mar 2026 68,820.3010 Apr 2026 71,788.0014−$2,967.67
long10 Apr 2026 71,788.0026 May 2026 77,322.0046$5,534.03
short26 May 2026 77,322.0019 Jul 2026 64,834.2054$12,487.80
long19 Jul 2026 64,834.202 Aug 2026 62,823.7014−$2,010.56
short2 Aug 2026 62,823.708 Aug 2026 64,923.206−$2,099.55
long8 Aug 2026 64,923.2013 Aug 2026 63,480.005−$1,443.21
short13 Aug 2026 63,480.0020 Aug 2026 69,334.807−$5,854.79

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
MM tester this page—v4 strategy−11.1%3337.1%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.8%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 7 msYes 1,000 bars in 19 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/// © luisgzafra//@version=4strategy("MM tester", overlay=true)// Inputs//int ema1        = input(title="MM1", defval=14, minval=0)int ema2        = input(title="MM2", defval=28, minval=0)//tipo_MM         = input(title="MM type", options=["EMA", "SMA"], defval="EMA")//MM1             = tipo_MM == "EMA"? ema(close, ema1) : sma(close, ema1)MM2             = tipo_MM == "EMA"? ema(close, ema2) : sma(close, ema2)//plot            (MM1, color = color.black)plot            (MM2, color = MM1 > MM2? color.red : color.green, linewidth=2)//longCondition   = crossover(MM1, MM2)if (longCondition)    strategy.entry("My Long Entry Id", strategy.long)//shortCondition  = crossunder(MM1, MM2)if (shortCondition)    strategy.entry("My Short Entry Id", strategy.short)    // END