Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MacD 200 Day Moving Average Signal Crossover Strategy

A Pine Script v4 strategy built on SMA or EMA (close, 12) and SMA (close, 200). 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 commits 100% of equity and pays 0.26 commission. 7 settings; defaults include Fast Length 12, Slow Length 26 and Source close.

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 MacD 200 Day Moving Average Signal Crossover 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 MacD 200 Day Moving Average Signal Crossover Strategy do on BTCUSDT 1D with default settings?
−71.98%
From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can MacD 200 Day Moving Average Signal Crossover Strategy 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 MacD 200 Day Moving Average Signal Crossover Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does MacD 200 Day Moving Average Signal Crossover Strategy run in Zeal Terminal?
Yes
It compiles in 11 ms and runs 1,000 bars in 31 ms, in the browser.

BTCUSDT · 1D · default settings

  • Moving Average Normalized
  • Histogram
  • MACD
  • Signal
  • 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 (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctMoving Average Normalized$2,919$20,253Equity from $10,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
−71.98%
−$7,198.49
Buy and hold
+102.5%
same period
Closed trades
3
0 won · 3 lost
Profitable
0.0%
of closed trades
Profit factor
0.00
gross profit ÷ gross loss
Max drawdown
79.65%
−$7,965.17

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A short 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.

  • Likely bug

    sma(close, moving_avg_length) ignores the settings line 27

    Line 27 hard-codes close where line 21 uses “Source”. Changing those settings moves one band but not this one.

    sma(close,moving_avg_length)sma(src, moving_avg_length)
  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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 transp =, which v5 removed line 30

    transp = on line 30, 31, 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 sma → ta.sma, ema → ta.ema.

v4 → v5

VerifiedDownload the v5 script

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

  • Line 3: //@version=4 → //@version=5
  • Line 7: input(type = input.integer) → input.int()
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.source) → input.source()
  • Line 10: input(type = input.integer) → input.int()
  • Line 11: input(type = input.bool) → input.bool()
12 more edits
  • Line 12: input(type = input.bool) → input.bool()
  • Line 21: sma → ta.sma
  • Line 21: ema → ta.ema
  • Line 22: sma → ta.sma
  • Line 22: ema → ta.ema
  • Line 24: sma → ta.sma
  • Line 24: ema → ta.ema
  • Line 26: input(type = input.integer) → input.int()
  • Line 27: sma → ta.sma
  • Line 30: transp = 0 → color.new((hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), 0)
  • Line 31: transp = 0 → color.new(col_macd, 0)
  • Line 32: transp = 0 → color.new(col_signal, 0)
⋯// © x11joe-//@version=4+//@version=5//This strategy is based on a youtube strategy that suggested I do this...so I did!⋯// Getting inputs-fast_length = input(title="Fast Length", type=input.integer, defval=12)+fast_length = input.int(title="Fast Length", defval=12)-slow_length = input(title="Slow Length", type=input.integer, defval=26)+slow_length = input.int(title="Slow Length", defval=26)-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)-sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)+sma_source = input.bool(title="Simple MA(Oscillator)", defval=false)-sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)+sma_signal = input.bool(title="Simple MA(Signal Line)", defval=false)// Plot colors⋯// Calculating-fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)+fast_ma = sma_source ? ta.sma(src, fast_length) : ta.ema(src, fast_length)-slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)+slow_ma = sma_source ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_ma-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal-moving_avg_length = input(title="Moving Average Length", type=input.integer, defval=200)+moving_avg_length = input.int(title="Moving Average Length", defval=200)-moving_avg = sma(close,moving_avg_length)+moving_avg = ta.sma(close,moving_avg_length)moving_avg_normalized = close - moving_avgplot(moving_avg_normalized, title="Moving Average Normalized", style=plot.style_line, color=color.orange,linewidth=3)-plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )+plot(hist, title="Histogram", style=plot.style_columns, color=color.new((hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), 0) )-plot(macd, title="MACD", color=col_macd, transp=0)+plot(macd, title="MACD", color=color.new(col_macd, 0))-plot(signal, title="Signal", color=col_signal, transp=0)+plot(signal, title="Signal", color=color.new(col_signal, 0))if(macd>signal and macd<0 and close>moving_avg)⋯

Clean v5

Verified

Nothing 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: 3 before, 44 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.

⋯// © x11joe-//@version=5+//@version=6//This strategy is based on a youtube strategy that suggested I do this...so I did!⋯

Settings

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

SettingDefaultType and rangeFeeds
Fast Length12int (written input.integer)fast_ma
Slow Length26int (written input.integer)slow_ma
Sourceclosesourcefast_ma slow_ma
Signal Smoothing9int (written input.integer) · min 1 · max 50signal
Simple MA(Oscillator)falseboolfast_ma slow_ma
Simple MA(Signal Line)falseboolsignal
Moving Average Length200int (written input.integer)moving_avg

What it calculates

  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length (12)fast_ma · line 21
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length (26)slow_ma · line 22
  • SMA / EMA (sma, ta.sma in v5)macd, Signal Smoothing (9)signal · line 24
  • SMA (sma, ta.sma in v5)close, Moving Average Length (200)moving_avg · line 27

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 datafast_lengthFast Lengthsetting · 12slow_lengthSlow Lengthsetting · 26signal_lengthSignal Smoothingsetting · 9moving_avg_lengthMoving Average Lengthsetting · 200fast_maSMA / EMA→ fast_maslow_maSMA / EMA→ slow_masignalSMA / EMA→ signalmoving_avgSMA→ moving_avgmacdmacdvaluehisthistvaluemoving_avg_normalizedmoving_avg_normalizedvaluecol_grow_above, col_grow_below, col_fall_above, col_fall_below, col_macd, col_signalColourcol_grow_above · col_grow_bel…entry:buyOpen buystrategy.entryentry:sellOpen sellstrategy.entryplot:29Moving Average Normaliz…plotplot:30Histogramplotplot:31MACDplotplot:32Signalplot

Order rules

OrderFires whenBy defaultLine
Open buy long(macd>signal and macd<0 and close>moving_avg)On34
Open sell short(close<moving_avg and macd<signal and macd>0)On36

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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−72.0%+102.5%30%0.0079.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−29.9%+5.5%50%0.0034.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−64.0%+9.8%425%0.0682.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−13.9%+8.4%10%0.0017.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−82.1%+16.7%50%0.0090.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−15.1%+21.5%520%0.1617.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−8.8%+148.3%520%0.7348.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−12.2%+17.1%714%0.1915.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 barsTradesWonP&L
Rising market10%−$405.81
Sideways market20%−$6,785.38
Falling market0—$0.00

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

How bad could the drawdown be?

71.7%

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

0%82%
All 3 trades
SideEntryExitBarsP&L
long24 Aug 2024 64,037.202 Oct 2024 60,804.9039−$554.00
short2 Oct 2024 60,804.9016 Jan 2025 100,497.00106−$6,231.38
long16 Jan 2025 100,497.0021 Jan 2026 88,427.70370−$405.81

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
MacD 200 Day Moving Average Signal Crossover Strategy this page—v4 strategy−72.0%379.7%
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 11 msYes 1,000 bars in 31 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/// © x11joe//@version=4//This strategy is based on a youtube strategy that suggested I do this...so I did!strategy(title="MacD 200 Day Moving Average Signal Crossover Strategy", overlay=false, precision=2,commission_value=0.26, initial_capital=10000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Getting inputsfast_length = input(title="Fast Length", type=input.integer, defval=12)slow_length = input(title="Slow Length", type=input.integer, defval=26)src = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)// Plot colorscol_grow_above = #26A69Acol_grow_below = #FFCDD2col_fall_above = #B2DFDBcol_fall_below = #EF5350col_macd = #0094ffcol_signal = #ff6a00// Calculatingfast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signalmoving_avg_length = input(title="Moving Average Length", type=input.integer, defval=200)moving_avg = sma(close,moving_avg_length)moving_avg_normalized = close - moving_avgplot(moving_avg_normalized, title="Moving Average Normalized", style=plot.style_line, color=color.orange,linewidth=3)plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )plot(macd, title="MACD", color=col_macd, transp=0)plot(signal, title="Signal", color=col_signal, transp=0)if(macd>signal and macd<0 and close>moving_avg)    strategy.entry("buy",strategy.long)if(close<moving_avg and macd<signal and macd>0)    strategy.entry("sell",strategy.short)