Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

BV's MACD SIGNAL TESTER

A Pine Script v4 strategy built on SMA or EMA (close, 12), Crossover (macd, signal) and Crossunder or Crossover (macd, signal). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 9 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 BV's MACD SIGNAL TESTER repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did BV's MACD SIGNAL TESTER do on BTCUSDT 1D with default settings?
−19.57%
From 26 Jan 2024 to 21 Oct 2026, over 11 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can BV's MACD SIGNAL 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 BV's MACD SIGNAL TESTER use a stop loss?
Yes
strategy.exit sets a stop on line 75, 76.
Does BV's MACD SIGNAL TESTER run in Zeal Terminal?
Yes
It compiles in 11 ms and runs 1,000 bars in 37 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • SMA
  • SMA
  • Crossover
  • Crossunder
  • ATR
  • 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 (9)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$100,215$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
−19.57%
−$19,567.10
Buy and hold
+102.5%
same period
Closed trades
11
3 won · 8 lost
Profitable
27.3%
of closed trades
Profit factor
0.76
gross profit ÷ gross loss
Max drawdown
34.26%
−$40,671.10

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.

  • Likely bug

    The “Continuation” option calculates CROSSOVER line 33

    Choosing Continuation in “Choose your signal” runs ta.crossover, not ta.continuation. Anyone picking Continuation gets a different average from the one they asked for.

    signalChoice == 'Continuation' ? ta.crossover(signalChoice == 'Continuation' ? ta.continuation(
  • Likely bug

    The “Reversal” option calculates CROSSOVER line 33

    Choosing Reversal in “Choose your signal” runs ta.crossover, not ta.reversal. Anyone picking Reversal gets a different average from the one they asked for.

    signalChoice == 'Reversal' ? ta.crossover(signalChoice == 'Reversal' ? ta.reversal(
  • Likely bug

    The “Histogram” option calculates CROSSOVER line 33

    Choosing Histogram in “Choose your signal” runs ta.crossover, not ta.histogram. Anyone picking Histogram gets a different average from the one they asked for.

    signalChoice == 'Histogram' ? ta.crossover(signalChoice == 'Histogram' ? ta.histogram(
  • Likely bug

    The “Continuation” option calculates CROSSUNDER line 40

    Choosing Continuation in “Choose your signal” runs ta.crossunder, not ta.continuation. Anyone picking Continuation gets a different average from the one they asked for.

    signalChoice == 'Continuation' ? ta.crossunder(signalChoice == 'Continuation' ? ta.continuation(
  • Likely bug

    The “Reversal” option calculates CROSSOVER line 40

    Choosing Reversal in “Choose your signal” runs ta.crossover, not ta.reversal. Anyone picking Reversal gets a different average from the one they asked for.

    signalChoice == 'Reversal' ? ta.crossover(signalChoice == 'Reversal' ? ta.reversal(
  • Likely bug

    The “Histogram” option calculates CROSSUNDER line 40

    Choosing Histogram in “Choose your signal” runs ta.crossunder, not ta.histogram. Anyone picking Histogram gets a different average from the one they asked for.

    signalChoice == 'Histogram' ? ta.crossunder(signalChoice == 'Histogram' ? ta.histogram(
  • 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 sma → ta.sma, ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder, atr → ta.atr.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 9: input(type = input.integer) → input.int()
  • Line 10: input(type = input.integer) → input.int()
  • Line 11: input(type = input.source) → input.source()
  • Line 12: input(type = input.integer) → input.int()
  • Line 13: input(type = input.bool) → input.bool()
20 more edits
  • Line 14: input(type = input.bool) → input.bool()
  • Line 23: sma → ta.sma
  • Line 23: ema → ta.ema
  • Line 24: sma → ta.sma
  • Line 24: ema → ta.ema
  • Line 26: sma → ta.sma
  • Line 26: ema → ta.ema
  • Line 33: crossover → ta.crossover
  • Line 34: crossover → ta.crossover
  • Line 35: crossover → ta.crossover
  • Line 36: crossover → ta.crossover
  • Line 37: crossover → ta.crossover
  • Line 40: crossunder → ta.crossunder
  • Line 41: crossover → ta.crossover
  • Line 42: crossunder → ta.crossunder
  • Line 43: crossunder → ta.crossunder
  • Line 44: crossunder → ta.crossunder
  • Line 53: input(type = input.bool) → input.bool()
  • Line 55: atr → ta.atr
  • Line 61: input(type = input.integer) → input.int()
⋯// © vuagnouxb-//@version=4+//@version=5strategy("BV's MACD SIGNAL TESTER", overlay=true)⋯// 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⋯signalChoice = input(title = "Choose your signal", defval = "Continuation", options = ["Continuation", "Reversal", "Histogram", "MACD Line ZC", "Signal Line ZC"])-continuationSignalLong = signalChoice == "Continuation" ? crossover(macd, signal) and macd > 0 :+continuationSignalLong = signalChoice == "Continuation" ? ta.crossover(macd, signal) and macd > 0 :-   signalChoice == "Reversal" ? crossover(macd, signal) and macd < 0 : +   signalChoice == "Reversal" ? ta.crossover(macd, signal) and macd < 0 : -   signalChoice == "Histogram" ? crossover(hist, 0) : +   signalChoice == "Histogram" ? ta.crossover(hist, 0) : -   signalChoice == "MACD Line ZC" ? crossover(macd, 0) :+   signalChoice == "MACD Line ZC" ? ta.crossover(macd, 0) :-   signalChoice == "Signal Line ZC" ? crossover(signal, 0) :+   signalChoice == "Signal Line ZC" ? ta.crossover(signal, 0) :   false   -continuationSignalShort = signalChoice == "Continuation" ? crossunder(macd, signal) and macd < 0 :+continuationSignalShort = signalChoice == "Continuation" ? ta.crossunder(macd, signal) and macd < 0 :-   signalChoice == "Reversal" ? crossover(signal, macd) and macd > 0 : +   signalChoice == "Reversal" ? ta.crossover(signal, macd) and macd > 0 : -   signalChoice == "Histogram" ? crossunder(hist, 0) : +   signalChoice == "Histogram" ? ta.crossunder(hist, 0) : -   signalChoice == "MACD Line ZC" ? crossunder(macd, 0) :+   signalChoice == "MACD Line ZC" ? ta.crossunder(macd, 0) :-   signalChoice == "Signal Line ZC" ? crossunder(signal, 0) :+   signalChoice == "Signal Line ZC" ? ta.crossunder(signal, 0) :   false⋯TPmultiplier = 1-JPYPair = input(type = input.bool, title = "JPY Pair ?", defval = false)+JPYPair = input.bool(title = "JPY Pair ?", defval = false)pipAdjuster = JPYPair ? 1000 : 100000-ATR = atr(14) * pipAdjuster // 1000 for jpy pairs : 100000+ATR = ta.atr(14) * pipAdjuster // 1000 for jpy pairs : 100000SL = ATR * SLmultiplier⋯//-------------------------------------------------------------------------YearOfTesting = input(title = "How many years of testing ?" , type = input.integer, defval = 3)+YearOfTesting = input.int(title = "How many years of testing ?" , defval = 3)_time = 2020 - YearOfTesting⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 32: input() → input.string()
⋯// -- Trade entry signals-signalChoice = input(title = "Choose your signal", defval = "Continuation", options = ["Continuation", "Reversal", "Histogram", "MACD Line ZC", "Signal Line ZC"])+signalChoice = input.string(title = "Choose your signal", defval = "Continuation", options = ["Continuation", "Reversal", "Histogram", "MACD Line ZC", "Signal Line ZC"])continuationSignalLong = signalChoice == "Continuation" ? ta.crossover(macd, signal) and macd > 0 :⋯

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: 11 before, 14 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.

⋯// © vuagnouxb-//@version=5+//@version=6strategy("BV's MACD SIGNAL 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
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
Choose your signalContinuationstring · options ["Continuation", "Reversal", "Histogram", "MACD Line ZC", "Signal Line ZC"]continuationSignalLong continuationSignalShort
JPY Pair ?falseboolpipAdjuster
How many years of testing ?3int (written input.integer)_time

What it calculates

  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length (12)fast_ma · line 23
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length (26)slow_ma · line 24
  • SMA / EMA (sma, ta.sma in v5)macd, Signal Smoothing (9)signal · line 26
  • Crossover (crossover, ta.crossover in v5)macd, signal · chosen by Choose your signalcontinuationSignalLong · line 33
  • Crossunder / Crossover (crossunder, ta.crossunder in v5)macd, signal · chosen by Choose your signalcontinuationSignalShort · line 40
  • ATR (atr, ta.atr in v5)14ATR · line 55

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 · 9signalChoiceChoose your signalsetting · Continuationhigh · low · closehigh · low · closeprice dataYearOfTestingHow many years of testi…setting · 3fast_maSMA / EMA→ fast_maslow_maSMA / EMA→ slow_masignalSMA / EMA→ signalcontinuationSignalLongCrossover→ continuationSignalLong · by…continuationSignalShortCrossunder / Crossover→ continuationSignalShort · b…ATRATR→ ATRmacdmacdvaluehisthistvaluelongConditionlongConditionvalueshortConditionshortConditionvaluepipAdjusterpipAdjustervalueSL, TPSL · TP2 values_time_timevaluetimeFiltertimeFilterconditioncol_grow_above, col_grow_below, col_fall_above, col_fall_below, col_macd, col_signalColourcol_grow_above · col_grow_bel…entry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:ATRexit ATRstrategy.exit

Order rules

OrderFires whenBy defaultLine
Open Long long(longCondition and timeFilter)On68
Open Short short(shortCondition and timeFilter)On70
Exit ATR stop and limitevery barOn75
Exit ATR stop and limitevery barOn76

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.

4/4trades 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−19.6%+102.5%1127%0.7634.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+7.9%+5.5%825%1.4612.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.5%+9.8%757%1.193.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.5%+8.4%1030%0.601.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%863%2.830.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%825%0.290.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.4%+148.3%650%4.290.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.3%+17.1%911%0.290.3%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 market20%−$24,183.80
Sideways market743%$18,173.60
Falling market20%−$13,556.90

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

How bad could the drawdown be?

58.8%

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

0%68%
All 11 trades
SideEntryExitBarsP&L
short12 May 2024 60,826.006 Jun 2024 71,108.0025−$10,282.00
long6 Jun 2024 71,108.0031 Aug 2024 59,124.0086−$11,984.00
short31 Aug 2024 59,124.0015 Oct 2024 66,084.0045−$6,960.01
long15 Oct 2024 66,084.0010 Jan 2025 92,552.5087$26,468.50
short10 Jan 2025 92,552.5019 May 2025 106,454.00129−$13,901.80
long19 May 2025 106,454.004 Nov 2025 106,583.00169$128.78
short4 Nov 2025 106,583.0026 Mar 2026 71,336.50142$35,246.50
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$2,516.22
short27 Mar 2026 68,820.305 May 2026 79,861.0039−$11,040.70
long5 May 2026 79,861.0028 Jun 2026 60,029.0054−$19,832.00
short28 Jun 2026 60,029.008 Aug 2026 64,923.2041−$4,894.19

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
BV's MACD SIGNAL TESTER this page—v4 strategy−19.6%1134.3%
ATR with EOM and VORTEX by SoftKill21atr ema smav4 strategy+66.2%2229.9%
cATRpillar Strategy by Obi-wanClintobeatr sma emav4 strategy+1.02827e+24%2788,097.2%
Optimized Zhaocaijinbao strategy by fzj20020403sma ema atrv5 strategy+15.6%129.8%
EMA & Supertrend by bhavikmotaema sma atrv4 strategy+2,123.6%13980.9%
Koala System EURUSD 15min by SoftKill21sma ema atrv4 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msYes 1,000 bars in 37 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/// © vuagnouxb//@version=4strategy("BV's MACD SIGNAL TESTER", overlay=true)//------------------------------------------------------------------------//----------            Confirmation Calculation              ------------ INPUT//------------------------------------------------------------------------// 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 - signal// 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)// -- Trade entry signalssignalChoice = input(title = "Choose your signal", defval = "Continuation", options = ["Continuation", "Reversal", "Histogram", "MACD Line ZC", "Signal Line ZC"])continuationSignalLong = signalChoice == "Continuation" ? crossover(macd, signal) and macd > 0 :   signalChoice == "Reversal" ? crossover(macd, signal) and macd < 0 :    signalChoice == "Histogram" ? crossover(hist, 0) :    signalChoice == "MACD Line ZC" ? crossover(macd, 0) :   signalChoice == "Signal Line ZC" ? crossover(signal, 0) :   false   continuationSignalShort = signalChoice == "Continuation" ? crossunder(macd, signal) and macd < 0 :   signalChoice == "Reversal" ? crossover(signal, macd) and macd > 0 :    signalChoice == "Histogram" ? crossunder(hist, 0) :    signalChoice == "MACD Line ZC" ? crossunder(macd, 0) :   signalChoice == "Signal Line ZC" ? crossunder(signal, 0) :   falselongCondition = continuationSignalLongshortCondition = continuationSignalShort//------------------------------------------------------------------------//----------             ATR MONEY MANAGEMENT                 ------------//------------------------------------------------------------------------SLmultiplier = 1.5TPmultiplier = 1JPYPair = input(type = input.bool, title = "JPY Pair ?", defval = false)pipAdjuster = JPYPair ? 1000 : 100000ATR = atr(14) * pipAdjuster // 1000 for jpy pairs : 100000SL = ATR * SLmultiplierTP = ATR * TPmultiplier//------------------------------------------------------------------------//----------                  TIME FILTER                     ------------//------------------------------------------------------------------------YearOfTesting = input(title = "How many years of testing ?" , type = input.integer, defval = 3)_time = 2020 - YearOfTestingtimeFilter = (year > _time) //------------------------------------------------------------------------//---------                 ENTRY FUNCTIONS                    ----------- INPUT//------------------------------------------------------------------------if (longCondition and timeFilter)      strategy.entry("Long", strategy.long)if (shortCondition and timeFilter)     strategy.entry("Short", strategy.short)    //------------------------------------------------------------------------//---------                 EXIT  FUNCTIONS                    -----------//------------------------------------------------------------------------strategy.exit("ATR", from_entry = "Long", profit = TP, loss = SL)  strategy.exit("ATR", from_entry = "Short", profit = TP, loss = SL)