Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MACD 50x Leveraged Long Strategy Results with Real Equity

A Pine Script v4 strategy built on EMA (close, 12), Change (strategy.wintrades) and Valuewhen (_longmovement). It has 4 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 1 in cash and pays no commission. 9 settings; defaults include From Year 2009, To Year 2100 and From Month 04.

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 50x Leveraged Long Strategy Results with Real Equity repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did MACD 50x Leveraged Long Strategy Results with Real Equity do on BTCUSDT 1D with default settings?
+40,225.00%
From 26 Jan 2024 to 21 Oct 2026, over 38 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can MACD 50x Leveraged Long Strategy Results with Real Equity 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 50x Leveraged Long Strategy Results with Real Equity use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does MACD 50x Leveraged Long Strategy Results with Real Equity run in Zeal Terminal?
Yes
It compiles in 18 ms and runs 1,000 bars in 59 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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 (9)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$40,329$203Equity from $100
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. Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 45) so the engine trades the way the script says.
Net profit
+40,225.00%
$40,225.00
Buy and hold
+102.5%
same period
Closed trades
38
13 won · 25 lost
Profitable
34.2%
of closed trades
Profit factor
1.81
gross profit ÷ gross loss
Max drawdown
1,581.61%
−$17,467.50

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

    3 settings have no label

    In the settings dialog fastLength (line 37), slowlength (line 38), MACDLength (line 39) show an empty name. The labels on this page come from the variable names.

  • 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 valuewhen → ta.valuewhen, ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder, change → ta.change.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 30: valuewhen → ta.valuewhen
  • Line 40: ema → ta.ema
  • Line 40: ema → ta.ema
  • Line 41: ema → ta.ema
  • Line 44: crossover → ta.crossover
7 more edits
  • Line 45: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 46: crossunder → ta.crossunder
  • Line 57: change → ta.change
  • Line 57: change → ta.change
  • Line 59: change → ta.change
  • Line 60: valuewhen → ta.valuewhen
  • Line 61: valuewhen → ta.valuewhen
⋯// © Noldo-//@version=4+//@version=5strategy(title="MACD LONG STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD LONG 50X REAL EQUITY", overlay=true, ⋯//2% below the entry price is determined as the liquidation point so that the transaction is guaranteed.-stop_value = valuewhen(strategy.position_size != 0 and strategy.position_size[1] == 0,strategy.position_avg_price * 0.98 , 0)+stop_value = ta.valuewhen(strategy.position_size != 0 and strategy.position_size[1] == 0,strategy.position_avg_price * 0.98 , 0)//⋯MACDLength = input(9)-MACD = ema(close, fastLength) - ema(close, slowlength)+MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)-aMACD = ema(MACD, MACDLength)+aMACD = ta.ema(MACD, MACDLength)delta = MACD - aMACD// STRATEGY-if (crossover(delta, 0) and term)+if (ta.crossover(delta, 0) and term)-    strategy.entry("MacdLE",true, comment="LONG" , qty = possize)+    strategy.entry("MacdLE",strategy.long, comment="LONG" , qty = possize)-if (crossunder(delta, 0))+if (ta.crossunder(delta, 0))    strategy.close("MacdLE", true, comment="CLOSE")⋯float mode = na-mode := change(strategy.wintrades) > 0 ? 1 : change(strategy.losstrades) > 0 ? -1 : nz(mode[1], 1)+mode := ta.change(strategy.wintrades) > 0 ? 1 : ta.change(strategy.losstrades) > 0 ? -1 : nz(mode[1], 1)float capital = 0.00-chg = change(strategy.position_size)+chg = ta.change(strategy.position_size)-_b = valuewhen(_longmovement,strategy.position_avg_price,0)+_b = ta.valuewhen(_longmovement,strategy.position_avg_price,0)-_s = valuewhen(_exitmovement,open,0)+_s = ta.valuewhen(_exitmovement,open,0)pips = ((_s - _b) / _b) * 100  ⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 18: input() → input.int()
  • Line 19: input() → input.int()
  • Line 20: input() → input.int()
  • Line 21: input() → input.int()
  • Line 22: input() → input.int()
  • Line 23: input() → input.int()
3 more edits
  • Line 37: input() → input.int()
  • Line 38: input() → input.int()
  • Line 39: input() → input.int()
⋯src = close -fromyear = input(2016, defval = 2009, minval = 2000, maxval = 2100, title = "From Year")+fromyear = input.int(2016, defval = 2009, minval = 2000, maxval = 2100, title = "From Year")-toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")+toyear = input.int(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")-frommonth = input(04, defval = 04, minval = 01, maxval = 12, title = "From Month")+frommonth = input.int(04, defval = 04, minval = 01, maxval = 12, title = "From Month")-tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")+tomonth = input.int(12, defval = 12, minval = 01, maxval = 12, title = "To Month")-fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")+fromday = input.int(01, defval = 01, minval = 01, maxval = 31, title = "From day")-today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")+today = input.int(31, defval = 31, minval = 01, maxval = 31, title = "To day")term = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59))⋯// MACD-fastLength = input(12)+fastLength = input.int(12)-slowlength = input(26)+slowlength = input.int(26)-MACDLength = input(9)+MACDLength = input.int(9)MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)⋯

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: 38 before, 0 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.

⋯// © Noldo-//@version=5+//@version=6strategy(title="MACD LONG STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD LONG 50X REAL EQUITY", 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
From Year2009int · min 2000 · max 2100term
To Year2100int · min 1900 · max 2100term close_all line 50
From Month04int · min 01 · max 12term
To Month12int · min 01 · max 12term close_all line 50
From day01int · min 01 · max 31term
To day31int · min 01 · max 31term close_all line 50
Fast Length (no label in the script)12intMACD
Slowlength (no label in the script)26intMACD
MACDLength (no label in the script)9intaMACD

What it calculates

  • EMA (ema, ta.ema in v5)close, Fast Length (12)MACD · line 40
  • EMA (ema, ta.ema in v5)MACD, MACDLength (9)aMACD · line 41
  • Change (change, ta.change in v5)strategy.wintradesmode · line 57
  • Change (change, ta.change in v5)strategy.position_sizechg · line 59
  • Valuewhen (valuewhen, ta.valuewhen in v5)_longmovement, strategy.position_avg_price, 0_b · line 60
  • Valuewhen (valuewhen, ta.valuewhen in v5)_exitmovement, open, 0_s · line 61

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 datafastLengthFast Lengthsetting · 12slowlengthSlowlengthsetting · 26MACDLengthMACDLengthsetting · 9openopenprice datatimetimeprice datafromyearFrom Yearsetting · 2009frommonthFrom Monthsetting · 04fromdayFrom daysetting · 01toyearTo Yearsetting · 2100tomonthTo Monthsetting · 12todayTo daysetting · 31lowlowprice dataMACDEMA→ MACDaMACDEMA→ aMACDmodeChange→ modechgChange→ chg_bValuewhen→ _b_sValuewhen→ _ssrcsrcvaluedeltadeltavaluecapitalcapitalvaluepipspipsvaluecapitacapitavaluenetcapitalnetcapitalvaluetermtermconditionstop_valuestop_valuecondition_longmovement, _exitmovement_longmovement · _exitmo…2 conditionsentry:MacdLEOpen MacdLEstrategy.entryclose:MacdLEClose MacdLEstrategy.closeclose_all:close_all strategy.close_allplot:78plotplot

Order rules

OrderFires whenBy defaultLine
Open MacdLE long(crossover(delta, 0) and term)On45
Close MacdLE(crossunder(delta, 0))On47
Close MacdLE(low <= stop_value and delta > 0 and term )On49
Close time > timestamp(toyear, tomonth, today, 23, 59)On51

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

11/11trades 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. On 0 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
  • 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+40,225.0%+102.5%3834%1.811,581.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+7,679.6%+5.5%3432%1.398,719.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−2,227.9%+9.8%3617%0.212,561.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+358.3%+8.4%3928%1.42242.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−4.9%+16.7%3244%0.9641.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−1.2%+21.5%3529%0.9713.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+248.3%+148.3%3447%2.3261.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+72.6%+17.1%3834%1.3534.8%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 market1323%$14,807.70
Sideways market1844%$29,211.10
Falling market729%−$3,793.77

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

How bad could the drawdown be?

6,765.3%

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

0%7,780%
All 38 trades
SideEntryExitBarsP&L
long6 May 2024 64,012.007 May 2024 63,165.201−$846.82
long13 May 2024 61,484.0031 May 2024 68,352.2018$6,868.17
long6 Jun 2024 71,108.008 Jun 2024 69,355.602−$1,752.40
long13 Jul 2024 57,889.101 Aug 2024 64,628.0019$6,738.92
long20 Aug 2024 59,438.5028 Aug 2024 59,415.008−$23.50
long13 Sep 2024 58,132.302 Oct 2024 60,804.9019$2,672.61
long15 Oct 2024 66,084.0027 Oct 2024 67,092.8012$1,008.76
long29 Oct 2024 69,962.204 Nov 2024 68,776.006−$1,186.22
long7 Nov 2024 75,572.0027 Nov 2024 91,965.2020$16,393.20
long17 Dec 2024 106,059.0019 Dec 2024 100,204.002−$5,854.64
long6 Jan 2025 98,363.608 Jan 2025 96,954.602−$1,409.01
long16 Jan 2025 100,497.0017 Jan 2025 99,987.301−$510.05
long21 Feb 2025 98,305.0022 Feb 2025 96,182.001−$2,123.02
long7 Mar 2025 89,931.908 Mar 2025 86,801.701−$3,130.14
long16 Mar 2025 84,338.4017 Mar 2025 82,574.501−$1,763.92
long12 Apr 2025 83,423.8018 May 2025 103,127.0036$19,702.80
long19 May 2025 106,454.0020 May 2025 105,574.001−$880.54
long22 May 2025 109,644.0024 May 2025 107,318.002−$2,325.69
long11 Jun 2025 110,274.0012 Jun 2025 108,645.001−$1,629.26
long27 Jun 2025 106,947.0022 Jul 2025 117,380.0025$10,433.30
long23 Jul 2025 119,954.0024 Jul 2025 118,756.001−$1,198.43
long12 Aug 2025 118,686.0018 Aug 2025 117,405.006−$1,280.99
long7 Sep 2025 110,188.0024 Sep 2025 111,999.0017$1,810.82
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$5,820.50
long27 Oct 2025 114,559.0029 Oct 2025 112,898.002−$1,660.97
long28 Nov 2025 91,333.902 Dec 2025 86,286.004−$5,047.93
long21 Dec 2025 88,360.9025 Dec 2025 87,669.404−$691.47
long16 Feb 2026 68,832.6017 Feb 2026 68,892.401$59.84
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$2,516.22
long7 Apr 2026 68,853.7029 Apr 2026 76,342.8022$7,489.12
long5 May 2026 79,861.0013 May 2026 80,504.508$643.46
long14 Jun 2026 64,458.0019 Jun 2026 62,958.005−$1,500.00
long30 Jun 2026 60,260.201 Jul 2026 58,624.701−$1,635.49
long2 Jul 2026 60,024.0028 Jul 2026 63,755.9026$3,731.86
long8 Aug 2026 64,923.2012 Aug 2026 63,600.004−$1,323.19
long19 Aug 2026 64,725.403 Sep 2026 77,340.0015$12,614.60
long4 Sep 2026 81,270.405 Sep 2026 79,660.801−$1,609.60
long22 Sep 2026 86,620.0024 Sep 2026 84,397.602−$2,222.41

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 50x Leveraged Long Strategy Results with Real Equity this page—v4 strategy+40,225.0%381,581.6%
MACD 50x Leveraged Short Strategy with Real Equity by Noldoema valuewhenv4 strategy+15,109.2%392,974.0%
Yesterday's High v.17.07 by tumiza999valuewhen emav5 strategy+10.1%1271.8%
PCT Trailing Stoploss-Strategy by Thumpyrema valuewhenv5 strategyNo trades on this market
Sentiment Oscillator by dannylimardiema valuewhenv4 strategy+1.4%520.6%
Initial template by trading_mentalistema valuewhenv4 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msWith a workaround 1,000 bars in 59 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 45) so the engine trades the way the script says.

“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/// © Noldo//@version=4strategy(title="MACD LONG STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD LONG 50X REAL EQUITY", overlay=true,          initial_capital=100,          linktoseries = false,         default_qty_type=strategy.cash,          default_qty_value=1,          commission_type=strategy.commission.percent,          commission_value=0.0,         calc_on_order_fills = false,         calc_on_every_tick  = true,         max_bars_back = 5000,         pyramiding = 0,         precision = 3)// Variables src = close fromyear = input(2016, defval = 2009, minval = 2000, maxval = 2100, title = "From Year")toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")frommonth = input(04, defval = 04, minval = 01, maxval = 12, title = "From Month")tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")term = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59))// STRATEGY COMPONENTS// SL values// STOP VALUE ==> //The 50x leverage explodes at just 2% below the current entry price and the current position size melts.//2% below the entry price is determined as the liquidation point so that the transaction is guaranteed.stop_value = valuewhen(strategy.position_size != 0 and strategy.position_size[1] == 0,strategy.position_avg_price * 0.98 , 0)//// LEVERAGE ==> 50Xleverage = 50 // POSITION SIZE ==> %1 (0.01)possize = 1// MACDfastLength = input(12)slowlength = input(26)MACDLength = input(9)MACD = ema(close, fastLength) - ema(close, slowlength)aMACD = ema(MACD, MACDLength)delta = MACD - aMACD// STRATEGYif (crossover(delta, 0) and term)    strategy.entry("MacdLE",true, comment="LONG" , qty = possize)if (crossunder(delta, 0))    strategy.close("MacdLE", true, comment="CLOSE")if(low <= stop_value and delta > 0  and term )    strategy.close("MacdLE",true)if time > timestamp(toyear, tomonth, today, 23, 59)    strategy.close_all()// REAL LEVERAGE SIMULATION --- _longmovement = strategy.position_size != 0 and strategy.position_size[1] == 0 _exitmovement = strategy.position_size[1] != 0 and strategy.position_size == 0// MODE : Indicating a situation for winners and losers, just like in the martingale system, to know if the strategy is losing or gaining.float mode = namode := change(strategy.wintrades) > 0 ? 1 : change(strategy.losstrades) > 0 ? -1 : nz(mode[1], 1)float capital = 0.00chg = change(strategy.position_size)_b = valuewhen(_longmovement,strategy.position_avg_price,0)_s = valuewhen(_exitmovement,open,0)pips = ((_s - _b) / _b) * 100  //If we are in profit, how much will this affect all of our capital with leverage?//If we are already at a loss, all of our position size will be gone.// Now let's put this into expression : capital := _longmovement ? nz(capital[1], 0) - chg : _exitmovement and mode == 1 ? (capital[1] - chg) + ((-chg * leverage * pips)/100) :            _exitmovement and mode != 1 ? capital[1] : capital[1]// NET CAPITALcapita = 100 + capitalfloat netcapital = nanetcapital := netcapital[1] <= 0 ? 0 : capita// Now, if we are ready, it's time to see the facts://If we had made a strategy using 1% position size and 50x leverage, that is, our entry point would be less than 2% liquidation point, the change in our capital would be in the form of a blue-colored area.//The result will not surprise://We have 0!// The first moment we switch to - is the moment we run out of cash and the game is over.// NOTE:  It is recommended to use as chart bottom indicator.plot(netcapital , color = color.blue , linewidth = 2)