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
- 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
VerifiedSame 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 ⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| From Year | 2009 | int · min 2000 · max 2100 | term |
| To Year | 2100 | int · min 1900 · max 2100 | term close_all line 50 |
| From Month | 04 | int · min 01 · max 12 | term |
| To Month | 12 | int · min 01 · max 12 | term close_all line 50 |
| From day | 01 | int · min 01 · max 31 | term |
| To day | 31 | int · min 01 · max 31 | term close_all line 50 |
| Fast Length (no label in the script) | 12 | int | MACD |
| Slowlength (no label in the script) | 26 | int | MACD |
| MACDLength (no label in the script) | 9 | int | aMACD |
What it calculates
- EMA (
ema,ta.emain v5)close, Fast Length (12)MACD · line 40 - EMA (
ema,ta.emain v5)MACD, MACDLength (9)aMACD · line 41 - Change (
change,ta.changein v5)strategy.wintradesmode · line 57 - Change (
change,ta.changein v5)strategy.position_sizechg · line 59 - Valuewhen (
valuewhen,ta.valuewhenin v5)_longmovement, strategy.position_avg_price, 0_b · line 60 - Valuewhen (
valuewhen,ta.valuewhenin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open MacdSE short | (crossunder(delta, 0) and term) | On | 45 |
| Close MacdSE | (crossover(delta, 0) and term) | On | 47 |
| Close MacdSE | (high >= stop_value and delta < 0 and term ) | On | 49 |
| Close | time > timestamp(toyear, tomonth, today, 23, 59) | On | 51 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +15,109.2% | +102.5% | 39 | 33% | 1.32 | 2,974.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +9,780.8% | +5.5% | 34 | 38% | 1.46 | 411.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1,720.2% | +9.8% | 37 | 24% | 0.46 | 657.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +22.6% | +8.4% | 38 | 32% | 1.02 | 110.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −19.9% | +16.7% | 32 | 34% | 0.84 | 89.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −15.5% | +21.5% | 35 | 23% | 0.63 | 26.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −387.9% | +148.3% | 35 | 20% | 0.21 | 393.8% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −103.6% | +17.1% | 39 | 28% | 0.62 | 114.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 15 | 27% | −$1,727.99 |
| Sideways market | 16 | 44% | $21,217.00 |
| Falling market | 8 | 25% | −$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.
All 39 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Mar 2024 69,499.80 | 26 Mar 2024 69,880.00 | 10 | −$380.16 |
| short | 12 May 2024 60,826.00 | 13 May 2024 61,484.00 | 1 | −$658.01 |
| short | 31 May 2024 68,352.20 | 4 Jun 2024 68,809.90 | 4 | −$457.72 |
| short | 9 Jun 2024 69,310.50 | 13 Jul 2024 57,889.10 | 34 | $11,421.40 |
| short | 1 Aug 2024 64,628.00 | 20 Aug 2024 59,438.50 | 19 | $5,189.51 |
| short | 31 Aug 2024 59,124.00 | 13 Sep 2024 58,132.30 | 13 | $991.68 |
| short | 2 Oct 2024 60,804.90 | 3 Oct 2024 60,649.30 | 1 | $155.65 |
| short | 27 Oct 2024 67,092.80 | 29 Oct 2024 69,962.20 | 2 | −$2,869.45 |
| short | 4 Nov 2024 68,776.00 | 6 Nov 2024 69,372.00 | 2 | −$596.02 |
| short | 27 Nov 2024 91,965.20 | 28 Nov 2024 95,863.10 | 1 | −$3,897.95 |
| short | 19 Dec 2024 100,204.00 | 20 Dec 2024 97,461.90 | 1 | $2,742.15 |
| short | 10 Jan 2025 92,552.50 | 11 Jan 2025 94,726.10 | 1 | −$2,173.61 |
| short | 29 Jan 2025 101,336.00 | 30 Jan 2025 103,733.00 | 1 | −$2,397.73 |
| short | 25 Feb 2025 91,552.90 | 3 Mar 2025 94,270.00 | 6 | −$2,717.11 |
| short | 9 Mar 2025 86,222.50 | 16 Mar 2025 84,338.40 | 7 | $1,884.02 |
| short | 7 Apr 2025 78,430.00 | 8 Apr 2025 79,163.20 | 1 | −$733.24 |
| short | 18 May 2025 103,127.00 | 19 May 2025 106,454.00 | 1 | −$3,327.62 |
| short | 20 May 2025 105,574.00 | 22 May 2025 109,644.00 | 2 | −$4,070.26 |
| short | 25 May 2025 107,762.00 | 27 May 2025 109,435.00 | 2 | −$1,672.88 |
| short | 13 Jun 2025 105,672.00 | 17 Jun 2025 106,795.00 | 4 | −$1,122.79 |
| short | 22 Jul 2025 117,380.00 | 23 Jul 2025 119,954.00 | 1 | −$2,574.07 |
| short | 24 Jul 2025 118,756.00 | 12 Aug 2025 118,686.00 | 19 | $70.00 |
| short | 18 Aug 2025 117,405.00 | 7 Sep 2025 110,188.00 | 20 | $7,217.03 |
| short | 24 Sep 2025 111,999.00 | 30 Sep 2025 114,312.00 | 6 | −$2,313.17 |
| short | 11 Oct 2025 112,774.00 | 13 Oct 2025 114,959.00 | 2 | −$2,184.32 |
| short | 4 Nov 2025 106,583.00 | 28 Nov 2025 91,333.90 | 24 | $15,249.10 |
| short | 18 Dec 2025 86,243.20 | 19 Dec 2025 85,516.40 | 1 | $726.82 |
| short | 21 Jan 2026 88,427.70 | 22 Jan 2026 89,454.70 | 1 | −$1,027.07 |
| short | 23 Mar 2026 67,859.00 | 24 Mar 2026 70,906.40 | 1 | −$3,047.45 |
| short | 27 Mar 2026 68,820.30 | 7 Apr 2026 68,853.70 | 11 | −$33.35 |
| short | 29 Apr 2026 76,342.80 | 30 Apr 2026 75,780.00 | 1 | $562.78 |
| short | 13 May 2026 80,504.50 | 14 Jun 2026 64,458.00 | 32 | $16,046.50 |
| short | 28 Jun 2026 60,029.00 | 30 Jun 2026 60,260.20 | 2 | −$231.19 |
| short | 1 Jul 2026 58,624.70 | 2 Jul 2026 60,024.00 | 1 | −$1,399.29 |
| short | 28 Jul 2026 63,755.90 | 31 Jul 2026 64,780.00 | 3 | −$1,024.17 |
| short | 12 Aug 2026 63,600.00 | 19 Aug 2026 64,725.40 | 7 | −$1,125.41 |
| short | 3 Sep 2026 77,340.00 | 4 Sep 2026 81,270.40 | 1 | −$3,930.36 |
| short | 5 Sep 2026 79,660.80 | 19 Sep 2026 80,883.90 | 14 | −$1,223.09 |
| short | 30 Sep 2026 83,663.70 | 1 Oct 2026 83,623.60 | 1 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| MACD 50x Leveraged Short Strategy with Real Equity this page | — | v4 strategy | +15,109.2% | 39 | 2,974.0% |
| MACD 50x Leveraged Long Strategy Results with Real Equity by Noldo | ema valuewhen | v4 strategy | +40,225.0% | 38 | 1,581.6% |
| Yesterday's High v.17.07 by tumiza999 | valuewhen ema | v5 strategy | +10.1% | 127 | 1.8% |
| PCT Trailing Stoploss-Strategy by Thumpyr | ema valuewhen | v5 strategy | No trades on this market | ||
| Sentiment Oscillator by dannylimardi | ema valuewhen | v4 strategy | +1.4% | 5 | 20.6% |
| Initial template by trading_mentalist | ema valuewhen | v4 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 32 ms | Yes 1,000 bars in 60 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/// © 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)