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
- 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
VerifiedSame 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⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Fast Length | 12 | int (written input.integer) | fast_ma |
| Slow Length | 26 | int (written input.integer) | slow_ma |
| Source | close | source | fast_ma slow_ma |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signal |
| Simple MA(Oscillator) | false | bool | fast_ma slow_ma |
| Simple MA(Signal Line) | false | bool | signal |
| Choose your signal | Continuation | string · options ["Continuation", "Reversal", "Histogram", "MACD Line ZC", "Signal Line ZC"] | continuationSignalLong continuationSignalShort |
| JPY Pair ? | false | bool | pipAdjuster |
| How many years of testing ? | 3 | int (written input.integer) | _time |
What it calculates
- SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length (12)fast_ma · line 23 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length (26)slow_ma · line 24 - SMA / EMA (
sma,ta.smain v5)macd, Signal Smoothing (9)signal · line 26 - Crossover (
crossover,ta.crossoverin v5)macd, signal · chosen by Choose your signalcontinuationSignalLong · line 33 - Crossunder / Crossover (
crossunder,ta.crossunderin v5)macd, signal · chosen by Choose your signalcontinuationSignalShort · line 40 - ATR (
atr,ta.atrin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (longCondition and timeFilter) | On | 68 |
| Open Short short | (shortCondition and timeFilter) | On | 70 |
| Exit ATR stop and limit | every bar | On | 75 |
| Exit ATR stop and limit | every bar | On | 76 |
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.
- 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 | −19.6% | +102.5% | 11 | 27% | 0.76 | 34.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +7.9% | +5.5% | 8 | 25% | 1.46 | 12.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.5% | +9.8% | 7 | 57% | 1.19 | 3.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.5% | +8.4% | 10 | 30% | 0.60 | 1.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 8 | 63% | 2.83 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 8 | 25% | 0.29 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.4% | +148.3% | 6 | 50% | 4.29 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.3% | +17.1% | 9 | 11% | 0.29 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 0% | −$24,183.80 |
| Sideways market | 7 | 43% | $18,173.60 |
| Falling market | 2 | 0% | −$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.
All 11 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 12 May 2024 60,826.00 | 6 Jun 2024 71,108.00 | 25 | −$10,282.00 |
| long | 6 Jun 2024 71,108.00 | 31 Aug 2024 59,124.00 | 86 | −$11,984.00 |
| short | 31 Aug 2024 59,124.00 | 15 Oct 2024 66,084.00 | 45 | −$6,960.01 |
| long | 15 Oct 2024 66,084.00 | 10 Jan 2025 92,552.50 | 87 | $26,468.50 |
| short | 10 Jan 2025 92,552.50 | 19 May 2025 106,454.00 | 129 | −$13,901.80 |
| long | 19 May 2025 106,454.00 | 4 Nov 2025 106,583.00 | 169 | $128.78 |
| short | 4 Nov 2025 106,583.00 | 26 Mar 2026 71,336.50 | 142 | $35,246.50 |
| long | 26 Mar 2026 71,336.50 | 27 Mar 2026 68,820.30 | 1 | −$2,516.22 |
| short | 27 Mar 2026 68,820.30 | 5 May 2026 79,861.00 | 39 | −$11,040.70 |
| long | 5 May 2026 79,861.00 | 28 Jun 2026 60,029.00 | 54 | −$19,832.00 |
| short | 28 Jun 2026 60,029.00 | 8 Aug 2026 64,923.20 | 41 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| BV's MACD SIGNAL TESTER this page | — | v4 strategy | −19.6% | 11 | 34.3% |
| ATR with EOM and VORTEX by SoftKill21 | atr ema sma | v4 strategy | +66.2% | 22 | 29.9% |
| cATRpillar Strategy by Obi-wanClintobe | atr sma ema | v4 strategy | +1.02827e+24% | 27 | 88,097.2% |
| Optimized Zhaocaijinbao strategy by fzj20020403 | sma ema atr | v5 strategy | +15.6% | 12 | 9.8% |
| EMA & Supertrend by bhavikmota | ema sma atr | v4 strategy | +2,123.6% | 13 | 980.9% |
| Koala System EURUSD 15min by SoftKill21 | sma ema atr | v4 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | Yes 1,000 bars in 37 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/// © 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)