Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MACD 50x Leveraged Short Strategy 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 short 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 Short Strategy with Real Equity repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did MACD 50x Leveraged Short Strategy with Real Equity do on BTCUSDT 1D with default settings?
+15,109.20%
From 26 Jan 2024 to 21 Oct 2026, over 39 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can MACD 50x Leveraged Short Strategy 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 Short Strategy 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 Short Strategy with Real Equity run in Zeal Terminal?
Yes
It compiles in 32 ms and runs 1,000 bars in 60 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$15,212$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.
Net profit
+15,109.20%
$15,109.20
Buy and hold
+102.5%
same period
Closed trades
39
13 won · 26 lost
Profitable
33.3%
of closed trades
Profit factor
1.32
gross profit ÷ gross loss
Max drawdown
2,974.00%
−$27,105.70

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

v4 → v5

Verified

Same 39 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: crossunder → ta.crossunder
6 more edits
  • Line 46: crossover → ta.crossover
  • 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 SHORT STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD SHORT 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 * 1.02 , 0)+stop_value = ta.valuewhen(strategy.position_size != 0 and strategy.position_size[1] == 0,strategy.position_avg_price * 1.02 , 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 (crossunder(delta, 0) and term)+if (ta.crossunder(delta, 0) and term)    strategy.entry("MacdSE",strategy.short,qty = possize)-if (crossover(delta, 0) and term)+if (ta.crossover(delta, 0) and term)    strategy.close("MacdSE", 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 39 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: 39 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 SHORT STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD SHORT 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 · 31highhighprice dataMACDEMA→ MACDaMACDEMA→ aMACDmodeChange→ modechgChange→ chg_bValuewhen→ _b_sValuewhen→ _ssrcsrcvaluedeltadeltavaluecapitalcapitalvaluepipspipsvaluecapitacapitavaluenetcapitalnetcapitalvaluetermtermconditionstop_valuestop_valuecondition_longmovement, _exitmovement_longmovement · _exitmo…2 conditionsentry:MacdSEOpen MacdSEstrategy.entryclose:MacdSEClose MacdSEstrategy.closeclose_all:close_all strategy.close_allplot:78plotplot

Order rules

OrderFires whenBy defaultLine
Open MacdSE short(crossunder(delta, 0) and term)On45
Close MacdSE(crossover(delta, 0) and term)On47
Close MacdSE(high >= 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.

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. 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+15,109.2%+102.5%3933%1.322,974.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+9,780.8%+5.5%3438%1.46411.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1,720.2%+9.8%3724%0.46657.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+22.6%+8.4%3832%1.02110.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−19.9%+16.7%3234%0.8489.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−15.5%+21.5%3523%0.6326.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−387.9%+148.3%3520%0.21393.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−103.6%+17.1%3928%0.62114.7%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 market1527%−$1,727.99
Sideways market1644%$21,217.00
Falling market825%−$4,379.85

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

How bad could the drawdown be?

7,732.3%

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

0%8,892%
All 39 trades
SideEntryExitBarsP&L
short16 Mar 2024 69,499.8026 Mar 2024 69,880.0010−$380.16
short12 May 2024 60,826.0013 May 2024 61,484.001−$658.01
short31 May 2024 68,352.204 Jun 2024 68,809.904−$457.72
short9 Jun 2024 69,310.5013 Jul 2024 57,889.1034$11,421.40
short1 Aug 2024 64,628.0020 Aug 2024 59,438.5019$5,189.51
short31 Aug 2024 59,124.0013 Sep 2024 58,132.3013$991.68
short2 Oct 2024 60,804.903 Oct 2024 60,649.301$155.65
short27 Oct 2024 67,092.8029 Oct 2024 69,962.202−$2,869.45
short4 Nov 2024 68,776.006 Nov 2024 69,372.002−$596.02
short27 Nov 2024 91,965.2028 Nov 2024 95,863.101−$3,897.95
short19 Dec 2024 100,204.0020 Dec 2024 97,461.901$2,742.15
short10 Jan 2025 92,552.5011 Jan 2025 94,726.101−$2,173.61
short29 Jan 2025 101,336.0030 Jan 2025 103,733.001−$2,397.73
short25 Feb 2025 91,552.903 Mar 2025 94,270.006−$2,717.11
short9 Mar 2025 86,222.5016 Mar 2025 84,338.407$1,884.02
short7 Apr 2025 78,430.008 Apr 2025 79,163.201−$733.24
short18 May 2025 103,127.0019 May 2025 106,454.001−$3,327.62
short20 May 2025 105,574.0022 May 2025 109,644.002−$4,070.26
short25 May 2025 107,762.0027 May 2025 109,435.002−$1,672.88
short13 Jun 2025 105,672.0017 Jun 2025 106,795.004−$1,122.79
short22 Jul 2025 117,380.0023 Jul 2025 119,954.001−$2,574.07
short24 Jul 2025 118,756.0012 Aug 2025 118,686.0019$70.00
short18 Aug 2025 117,405.007 Sep 2025 110,188.0020$7,217.03
short24 Sep 2025 111,999.0030 Sep 2025 114,312.006−$2,313.17
short11 Oct 2025 112,774.0013 Oct 2025 114,959.002−$2,184.32
short4 Nov 2025 106,583.0028 Nov 2025 91,333.9024$15,249.10
short18 Dec 2025 86,243.2019 Dec 2025 85,516.401$726.82
short21 Jan 2026 88,427.7022 Jan 2026 89,454.701−$1,027.07
short23 Mar 2026 67,859.0024 Mar 2026 70,906.401−$3,047.45
short27 Mar 2026 68,820.307 Apr 2026 68,853.7011−$33.35
short29 Apr 2026 76,342.8030 Apr 2026 75,780.001$562.78
short13 May 2026 80,504.5014 Jun 2026 64,458.0032$16,046.50
short28 Jun 2026 60,029.0030 Jun 2026 60,260.202−$231.19
short1 Jul 2026 58,624.702 Jul 2026 60,024.001−$1,399.29
short28 Jul 2026 63,755.9031 Jul 2026 64,780.003−$1,024.17
short12 Aug 2026 63,600.0019 Aug 2026 64,725.407−$1,125.41
short3 Sep 2026 77,340.004 Sep 2026 81,270.401−$3,930.36
short5 Sep 2026 79,660.8019 Sep 2026 80,883.9014−$1,223.09
short30 Sep 2026 83,663.701 Oct 2026 83,623.601$40.07

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 Short Strategy with Real Equity this page—v4 strategy+15,109.2%392,974.0%
MACD 50x Leveraged Long Strategy Results with Real Equity by Noldoema valuewhenv4 strategy+40,225.0%381,581.6%
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 32 msYes 1,000 bars in 60 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/// © Noldo//@version=4strategy(title="MACD SHORT STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD SHORT 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% above 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 * 1.02 , 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 (crossunder(delta, 0) and term)    strategy.entry("MacdSE",strategy.short,qty = possize)if (crossover(delta, 0) and term)    strategy.close("MacdSE", true, comment="CLOSE")if(high >= stop_value and delta < 0  and term )    strategy.close("MacdSE",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 are still not good.// 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.teal , linewidth = 2)