Pine Script v4 · Strategy
MACD 50x Leveraged Strategy Real Equity Simulation
A Pine Script v4 strategy built on EMA (close, 12) and Change (strategy.position_size). It has 5 order rules, 2 entries among them, and trades long and short 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 Strategy Real Equity Simulation repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did MACD 50x Leveraged Strategy Real Equity Simulation do on BTCUSDT 1D with default settings?
- +16,714.70%
- From 26 Jan 2024 to 21 Oct 2026, over 117 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can MACD 50x Leveraged Strategy Real Equity Simulation 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 Strategy Real Equity Simulation use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does MACD 50x Leveraged Strategy Real Equity Simulation run in Zeal Terminal?
- Yes
- It compiles in 26 ms and runs 1,000 bars in 85 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +16,714.70%
- $16,714.70
- Buy and hold
- +102.5%
- same period
- Closed trades
- 117
- 37 won · 80 lost
- Profitable
- 31.6%
- of closed trades
- Profit factor
- 1.09
- gross profit ÷ gross loss
- Max drawdown
- 3,427.11%
- −$62,483.80
One run with the author's default settings, $100 starting capital, commission as the script sets it. A short 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.
-
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 30), slowlength (line 31), MACDLength (line 32) 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.
-
Note
Uses an argument v6 removed
when = on line 90, 91. The upgraded version below moves each call inside an if block.
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 ema → ta.ema, valuewhen → ta.valuewhen, barssince → ta.barssince, change → ta.change, abs → math.abs.
- 2 strategy calls use the when = argument (line 90, 91). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 117 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 33: ema → ta.ema
- Line 33: ema → ta.ema
- Line 34: ema → ta.ema
- Line 40: valuewhen → ta.valuewhen
- Line 41: valuewhen → ta.valuewhen
23 more edits
- Line 49: barssince → ta.barssince
- Line 49: barssince → ta.barssince
- Line 50: barssince → ta.barssince
- Line 50: barssince → ta.barssince
- Line 51: barssince → ta.barssince
- Line 51: barssince → ta.barssince
- Line 52: barssince → ta.barssince
- Line 52: barssince → ta.barssince
- Line 53: barssince → ta.barssince
- Line 53: barssince → ta.barssince
- Line 54: barssince → ta.barssince
- Line 54: barssince → ta.barssince
- Line 57: change → ta.change
- Line 59: valuewhen → ta.valuewhen
- Line 60: valuewhen → ta.valuewhen
- Line 61: valuewhen → ta.valuewhen
- Line 62: valuewhen → ta.valuewhen
- Line 63: valuewhen → ta.valuewhen
- Line 64: valuewhen → ta.valuewhen
- Line 77: change → ta.change
- Line 77: change → ta.change
- Line 78: abs → math.abs
- Line 78: abs → math.abs
⋯// © Noldo-//@version=4+//@version=5strategy(title="MACD STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD 50X REAL EQUITY", overlay=true, ⋯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⋯// SL values-stop_long = valuewhen(strategy.position_size > 0 and strategy.position_size[1] <= 0 and trend == 1 ,strategy.position_avg_price * 0.98,0)+stop_long = ta.valuewhen(strategy.position_size > 0 and strategy.position_size[1] <= 0 and trend == 1 ,strategy.position_avg_price * 0.98,0)-stop_short= valuewhen(strategy.position_size < 0 and strategy.position_size[1] >= 0 and trend == -1 ,strategy.position_avg_price * 1.02,0)+stop_short= ta.valuewhen(strategy.position_size < 0 and strategy.position_size[1] >= 0 and trend == -1 ,strategy.position_avg_price * 1.02,0)// REAL LEVERAGE SIMULATION --- ⋯_dsmov = strategy.position_size[1] > 0 and strategy.position_size < 0 -onlylong = barssince(_lmov) < barssince(_dlmov) and _lmov+onlylong = ta.barssince(_lmov) < ta.barssince(_dlmov) and _lmov-onlyshort = barssince(_smov) < barssince (_dsmov) and _smov+onlyshort = ta.barssince(_smov) < ta.barssince (_dsmov) and _smov-onlylongexit = barssince(_elmov) < barssince(_dsmov) and _elmov+onlylongexit = ta.barssince(_elmov) < ta.barssince(_dsmov) and _elmov-onlyshortexit = barssince(_esmov) < barssince(_dlmov) and _esmov+onlyshortexit = ta.barssince(_esmov) < ta.barssince(_dlmov) and _esmov-directlong = barssince(_dlmov) < barssince(_lmov) and _dlmov+directlong = ta.barssince(_dlmov) < ta.barssince(_lmov) and _dlmov-directshort = barssince(_dsmov) < barssince(_smov) and _dsmov+directshort = ta.barssince(_dsmov) < ta.barssince(_smov) and _dsmov// float capital = 0.00-chg = change(strategy.position_size)+chg = ta.change(strategy.position_size)ch = strategy.position_size-_l = valuewhen(strategy.position_size > 0 and strategy.position_size[1] == 0,strategy.position_avg_price,0) // Long after Short or Long Exit+_l = ta.valuewhen(strategy.position_size > 0 and strategy.position_size[1] == 0,strategy.position_avg_price,0) // Long after Short or Long Exit-_le = valuewhen(strategy.position_size[1] > 0 and strategy.position_size == 0 ,open,0)+_le = ta.valuewhen(strategy.position_size[1] > 0 and strategy.position_size == 0 ,open,0)-_s = valuewhen(strategy.position_size < 0 and strategy.position_size[1] == 0,strategy.position_avg_price,0) // Short after Long or Long Exit+_s = ta.valuewhen(strategy.position_size < 0 and strategy.position_size[1] == 0,strategy.position_avg_price,0) // Short after Long or Long Exit-_se = valuewhen(strategy.position_size[1] < 0 and strategy.position_size == 0 ,open,0)+_se = ta.valuewhen(strategy.position_size[1] < 0 and strategy.position_size == 0 ,open,0)-_dds = valuewhen(strategy.position_size < 0 and strategy.position_size[1] >= 0,strategy.position_avg_price,0) // Close Short and Long == DirectLong+_dds = ta.valuewhen(strategy.position_size < 0 and strategy.position_size[1] >= 0,strategy.position_avg_price,0) // Close Short and Long == DirectLong-_ddl = valuewhen(strategy.position_size > 0 and strategy.position_size[1] <= 0,strategy.position_avg_price,0) // Close Long and Short == DirectShort+_ddl = ta.valuewhen(strategy.position_size > 0 and strategy.position_size[1] <= 0,strategy.position_avg_price,0) // Close Long and Short == DirectShortpiplong = ((_le - _l) / _l) * 100 ⋯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)-pipsize = (abs(chg) - abs(ch)) +pipsize = (math.abs(chg) - math.abs(ch)) capital := onlylong ? nz(capital[1], 0) - chg : ⋯Same 117 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()
5 more edits
- Line 30: input() → input.int()
- Line 31: input() → input.int()
- Line 32: input() → input.int()
- Line 90: when = enterLong → if block
- Line 91: when = enterShort → if block
⋯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)⋯// STRATEGY-strategy.entry("Long",strategy.long, comment="LONG" ,when = enterLong , qty = possize)+if enterLong+ strategy.entry("Long",strategy.long, comment="LONG" , qty = possize)-strategy.entry("Short",strategy.short, comment="SHORT" ,when = enterShort , qty = possize)+if enterShort+ strategy.entry("Short",strategy.short, comment="SHORT" , qty = possize)if(sLong)⋯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: 117 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 STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD 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 96 |
| From Month | 04 | int · min 01 · max 12 | term |
| To Month | 12 | int · min 01 · max 12 | term close_all line 96 |
| From day | 01 | int · min 01 · max 31 | term |
| To day | 31 | int · min 01 · max 31 | term close_all line 96 |
| 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 33 - EMA (
ema,ta.emain v5)MACD, MACDLength (9)aMACD · line 34 - Change (
change,ta.changein v5)strategy.position_sizechg · line 57 - Change (
change,ta.changein v5)strategy.wintradesmode · line 77
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 | enterLong((trend == 1 and term and trend[1] != 1) or (trend == 1 and term and trend[1] != 1 and low[1] <= stop_long) or
(trend == 1 and term and trend[1] == 1 and low[1] <= stop_long)) | On | 90 |
| Open Short short | enterShort((trend == -1 and term and trend[1] != -1) or (trend == -1 and term and trend[1] != -1 and high[1] >= stop_short) or
(trend == -1 and term and trend[1] == -1 and high[1] >= stop_short)) | On | 91 |
| Close Long | (sLong) | On | 93 |
| Close Short | (sShort ) | On | 95 |
| Close | time > timestamp(toyear, tomonth, today, 23, 59) | On | 97 |
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 | +16,714.7% | +102.5% | 117 | 32% | 1.09 | 3,427.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +17,707.3% | +5.5% | 72 | 36% | 1.41 | 2,760.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −2,454.0% | +9.8% | 125 | 30% | 0.80 | 371.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −51.0% | +8.4% | 84 | 29% | 0.98 | 374.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +99.1% | +16.7% | 107 | 40% | 1.19 | 70.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −4.8% | +21.5% | 82 | 30% | 0.95 | 28.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −282.3% | +148.3% | 128 | 30% | 0.83 | 563.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +24.0% | +17.1% | 86 | 30% | 1.04 | 53.0% | 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 | 50 | 30% | −$1,714.07 |
| Sideways market | 47 | 36% | $12,818.20 |
| Falling market | 20 | 25% | $5,610.58 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
63,301.5%
The 95th percentile of the worst drawdown when the same 117 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 234.2% to 63,301.5%; the tick is what actually happened, 133.0%. Order luck alone moves it this much.
All 117 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 29 Feb 2024 62,432.10 | 16 Mar 2024 69,499.80 | 16 | $7,067.73 |
| short | 16 Mar 2024 69,499.80 | 26 Mar 2024 69,880.00 | 10 | −$380.16 |
| short | 27 Mar 2024 69,988.00 | 28 Mar 2024 69,470.00 | 1 | $518.00 |
| short | 29 Mar 2024 70,780.60 | 9 Apr 2024 71,620.00 | 11 | −$839.40 |
| short | 10 Apr 2024 69,146.00 | 11 Apr 2024 70,631.10 | 1 | −$1,485.08 |
| short | 12 Apr 2024 70,006.20 | 6 May 2024 64,012.00 | 24 | $5,994.22 |
| long | 6 May 2024 64,012.00 | 12 May 2024 60,826.00 | 6 | −$3,186.01 |
| short | 12 May 2024 60,826.00 | 13 May 2024 61,484.00 | 1 | −$658.01 |
| long | 13 May 2024 61,484.00 | 31 May 2024 68,352.20 | 18 | $6,868.17 |
| short | 31 May 2024 68,352.20 | 4 Jun 2024 68,809.90 | 4 | −$457.72 |
| short | 5 Jun 2024 70,537.80 | 6 Jun 2024 71,108.00 | 1 | −$570.17 |
| long | 6 Jun 2024 71,108.00 | 9 Jun 2024 69,310.50 | 3 | −$1,797.54 |
| short | 9 Jun 2024 69,310.50 | 13 Jul 2024 57,889.10 | 34 | $11,421.40 |
| long | 13 Jul 2024 57,889.10 | 1 Aug 2024 64,628.00 | 19 | $6,738.92 |
| short | 1 Aug 2024 64,628.00 | 20 Aug 2024 59,438.50 | 19 | $5,189.51 |
| long | 20 Aug 2024 59,438.50 | 31 Aug 2024 59,124.00 | 11 | −$314.51 |
| short | 31 Aug 2024 59,124.00 | 13 Sep 2024 58,132.30 | 13 | $991.68 |
| long | 13 Sep 2024 58,132.30 | 2 Oct 2024 60,804.90 | 19 | $2,672.61 |
| short | 2 Oct 2024 60,804.90 | 3 Oct 2024 60,649.30 | 1 | $155.65 |
| short | 4 Oct 2024 60,752.70 | 5 Oct 2024 62,086.00 | 1 | −$1,333.28 |
| short | 6 Oct 2024 62,058.00 | 8 Oct 2024 62,224.00 | 2 | −$166.00 |
| short | 9 Oct 2024 62,160.50 | 12 Oct 2024 62,540.00 | 3 | −$379.49 |
| short | 13 Oct 2024 63,206.20 | 15 Oct 2024 66,084.00 | 2 | −$2,877.77 |
| long | 15 Oct 2024 66,084.00 | 27 Oct 2024 67,092.80 | 12 | $1,008.76 |
| short | 27 Oct 2024 67,092.80 | 29 Oct 2024 69,962.20 | 2 | −$2,869.45 |
| long | 29 Oct 2024 69,962.20 | 4 Nov 2024 68,776.00 | 6 | −$1,186.22 |
| short | 4 Nov 2024 68,776.00 | 6 Nov 2024 69,372.00 | 2 | −$596.02 |
| long | 7 Nov 2024 75,572.00 | 27 Nov 2024 91,965.20 | 20 | $16,393.20 |
| short | 27 Nov 2024 91,965.20 | 28 Nov 2024 95,863.10 | 1 | −$3,897.95 |
| short | 29 Nov 2024 95,644.00 | 30 Nov 2024 97,460.00 | 1 | −$1,816.01 |
| short | 1 Dec 2024 96,408.00 | 5 Dec 2024 98,587.30 | 4 | −$2,179.33 |
| short | 6 Dec 2024 96,945.60 | 7 Dec 2024 99,740.80 | 1 | −$2,795.21 |
| short | 8 Dec 2024 99,832.00 | 12 Dec 2024 101,125.00 | 4 | −$1,293.01 |
| short | 13 Dec 2024 100,004.00 | 15 Dec 2024 101,420.00 | 2 | −$1,415.71 |
| short | 16 Dec 2024 104,464.00 | 17 Dec 2024 106,059.00 | 1 | −$1,594.66 |
| long | 17 Dec 2024 106,059.00 | 19 Dec 2024 100,204.00 | 2 | −$5,854.64 |
| short | 19 Dec 2024 100,204.00 | 20 Dec 2024 97,461.90 | 1 | $2,742.15 |
| short | 21 Dec 2024 97,805.40 | 27 Dec 2024 95,791.60 | 6 | $2,013.84 |
| short | 28 Dec 2024 94,299.00 | 1 Jan 2025 93,576.00 | 4 | $723.03 |
| short | 2 Jan 2025 94,591.80 | 3 Jan 2025 96,984.80 | 1 | −$2,393.01 |
| short | 4 Jan 2025 98,174.20 | 6 Jan 2025 98,363.60 | 2 | −$189.44 |
| long | 6 Jan 2025 98,363.60 | 10 Jan 2025 92,552.50 | 4 | −$5,811.12 |
| short | 10 Jan 2025 92,552.50 | 11 Jan 2025 94,726.10 | 1 | −$2,173.61 |
| short | 12 Jan 2025 94,600.00 | 15 Jan 2025 96,560.90 | 3 | −$1,960.86 |
| long | 16 Jan 2025 100,497.00 | 29 Jan 2025 101,336.00 | 13 | $838.17 |
| short | 29 Jan 2025 101,336.00 | 30 Jan 2025 103,733.00 | 1 | −$2,397.73 |
| short | 31 Jan 2025 104,723.00 | 21 Feb 2025 98,305.00 | 21 | $6,417.93 |
| long | 21 Feb 2025 98,305.00 | 25 Feb 2025 91,552.90 | 4 | −$6,752.13 |
| short | 25 Feb 2025 91,552.90 | 3 Mar 2025 94,270.00 | 6 | −$2,717.11 |
| short | 4 Mar 2025 86,221.20 | 5 Mar 2025 87,282.00 | 1 | −$1,060.82 |
| short | 6 Mar 2025 90,606.00 | 7 Mar 2025 89,931.90 | 1 | $674.12 |
| long | 7 Mar 2025 89,931.90 | 9 Mar 2025 86,222.50 | 2 | −$3,709.42 |
| short | 9 Mar 2025 86,222.50 | 16 Mar 2025 84,338.40 | 7 | $1,884.02 |
| long | 16 Mar 2025 84,338.40 | 7 Apr 2025 78,430.00 | 22 | −$5,908.44 |
| short | 7 Apr 2025 78,430.00 | 8 Apr 2025 79,163.20 | 1 | −$733.24 |
| short | 9 Apr 2025 76,322.40 | 10 Apr 2025 82,615.20 | 1 | −$6,292.80 |
| short | 11 Apr 2025 79,607.30 | 12 Apr 2025 83,423.80 | 1 | −$3,816.53 |
| long | 12 Apr 2025 83,423.80 | 18 May 2025 103,127.00 | 36 | $19,702.80 |
| short | 18 May 2025 103,127.00 | 19 May 2025 106,454.00 | 1 | −$3,327.62 |
| long | 19 May 2025 106,454.00 | 20 May 2025 105,574.00 | 1 | −$880.54 |
| short | 20 May 2025 105,574.00 | 22 May 2025 109,644.00 | 2 | −$4,070.26 |
| long | 22 May 2025 109,644.00 | 25 May 2025 107,762.00 | 3 | −$1,882.09 |
| short | 25 May 2025 107,762.00 | 27 May 2025 109,435.00 | 2 | −$1,672.88 |
| short | 28 May 2025 108,938.00 | 11 Jun 2025 110,274.00 | 14 | −$1,336.22 |
| long | 11 Jun 2025 110,274.00 | 13 Jun 2025 105,672.00 | 2 | −$4,602.65 |
| short | 13 Jun 2025 105,672.00 | 17 Jun 2025 106,795.00 | 4 | −$1,122.79 |
| short | 18 Jun 2025 104,551.00 | 26 Jun 2025 107,341.00 | 8 | −$2,789.42 |
| long | 27 Jun 2025 106,947.00 | 22 Jul 2025 117,380.00 | 25 | $10,433.30 |
| short | 22 Jul 2025 117,380.00 | 23 Jul 2025 119,954.00 | 1 | −$2,574.07 |
| long | 23 Jul 2025 119,954.00 | 24 Jul 2025 118,756.00 | 1 | −$1,198.43 |
| short | 24 Jul 2025 118,756.00 | 12 Aug 2025 118,686.00 | 19 | $70.00 |
| long | 12 Aug 2025 118,686.00 | 18 Aug 2025 117,405.00 | 6 | −$1,280.99 |
| short | 18 Aug 2025 117,405.00 | 7 Sep 2025 110,188.00 | 20 | $7,217.03 |
| long | 7 Sep 2025 110,188.00 | 24 Sep 2025 111,999.00 | 17 | $1,810.82 |
| short | 24 Sep 2025 111,999.00 | 30 Sep 2025 114,312.00 | 6 | −$2,313.17 |
| short | 1 Oct 2025 114,049.00 | 2 Oct 2025 118,595.00 | 1 | −$4,546.05 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$5,820.50 |
| short | 11 Oct 2025 112,774.00 | 13 Oct 2025 114,959.00 | 2 | −$2,184.32 |
| short | 14 Oct 2025 115,166.00 | 27 Oct 2025 114,559.00 | 13 | $606.59 |
| long | 27 Oct 2025 114,559.00 | 4 Nov 2025 106,583.00 | 8 | −$7,976.36 |
| short | 4 Nov 2025 106,583.00 | 28 Nov 2025 91,333.90 | 24 | $15,249.10 |
| long | 28 Nov 2025 91,333.90 | 18 Dec 2025 86,243.20 | 20 | −$5,090.71 |
| short | 18 Dec 2025 86,243.20 | 19 Dec 2025 85,516.40 | 1 | $726.82 |
| short | 20 Dec 2025 88,136.90 | 21 Dec 2025 88,360.90 | 1 | −$223.96 |
| long | 21 Dec 2025 88,360.90 | 21 Jan 2026 88,427.70 | 31 | $66.75 |
| short | 21 Jan 2026 88,427.70 | 22 Jan 2026 89,454.70 | 1 | −$1,027.07 |
| short | 23 Jan 2026 89,559.70 | 16 Feb 2026 68,832.60 | 24 | $20,727.10 |
| long | 16 Feb 2026 68,832.60 | 23 Mar 2026 67,859.00 | 35 | −$973.59 |
| short | 23 Mar 2026 67,859.00 | 24 Mar 2026 70,906.40 | 1 | −$3,047.45 |
| short | 25 Mar 2026 70,556.70 | 26 Mar 2026 71,336.50 | 1 | −$779.79 |
| long | 26 Mar 2026 71,336.50 | 27 Mar 2026 68,820.30 | 1 | −$2,516.22 |
| short | 27 Mar 2026 68,820.30 | 7 Apr 2026 68,853.70 | 11 | −$33.35 |
| long | 7 Apr 2026 68,853.70 | 29 Apr 2026 76,342.80 | 22 | $7,489.12 |
| short | 29 Apr 2026 76,342.80 | 30 Apr 2026 75,780.00 | 1 | $562.78 |
| short | 1 May 2026 76,346.60 | 2 May 2026 78,231.10 | 1 | −$1,884.55 |
| short | 3 May 2026 78,686.80 | 5 May 2026 79,861.00 | 2 | −$1,174.17 |
| long | 5 May 2026 79,861.00 | 13 May 2026 80,504.50 | 8 | $643.46 |
| short | 13 May 2026 80,504.50 | 14 Jun 2026 64,458.00 | 32 | $16,046.50 |
| long | 14 Jun 2026 64,458.00 | 28 Jun 2026 60,029.00 | 14 | −$4,429.00 |
| short | 28 Jun 2026 60,029.00 | 30 Jun 2026 60,260.20 | 2 | −$231.19 |
| long | 30 Jun 2026 60,260.20 | 1 Jul 2026 58,624.70 | 1 | −$1,635.49 |
| short | 1 Jul 2026 58,624.70 | 2 Jul 2026 60,024.00 | 1 | −$1,399.29 |
| long | 2 Jul 2026 60,024.00 | 28 Jul 2026 63,755.90 | 26 | $3,731.86 |
| short | 28 Jul 2026 63,755.90 | 31 Jul 2026 64,780.00 | 3 | −$1,024.17 |
| short | 1 Aug 2026 62,887.90 | 5 Aug 2026 64,106.60 | 4 | −$1,218.67 |
| short | 6 Aug 2026 64,665.20 | 8 Aug 2026 64,923.20 | 2 | −$257.96 |
| long | 8 Aug 2026 64,923.20 | 12 Aug 2026 63,600.00 | 4 | −$1,323.19 |
| short | 12 Aug 2026 63,600.00 | 19 Aug 2026 64,725.40 | 7 | −$1,125.41 |
| long | 19 Aug 2026 64,725.40 | 3 Sep 2026 77,340.00 | 15 | $12,614.60 |
| short | 3 Sep 2026 77,340.00 | 4 Sep 2026 81,270.40 | 1 | −$3,930.36 |
| long | 4 Sep 2026 81,270.40 | 5 Sep 2026 79,660.80 | 1 | −$1,609.60 |
| short | 5 Sep 2026 79,660.80 | 19 Sep 2026 80,883.90 | 14 | −$1,223.09 |
| short | 20 Sep 2026 81,250.00 | 22 Sep 2026 86,620.00 | 2 | −$5,370.02 |
| long | 22 Sep 2026 86,620.00 | 30 Sep 2026 83,663.70 | 8 | −$2,956.35 |
| short | 30 Sep 2026 83,663.70 | 1 Oct 2026 83,623.60 | 1 | $40.07 |
| short | 2 Oct 2026 84,880.10 | 3 Oct 2026 84,518.00 | 1 | $362.05 |
| short | 4 Oct 2026 84,753.60 | 5 Oct 2026 86,530.00 | 1 | −$1,776.43 |
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 Strategy Real Equity Simulation this page | — | v4 strategy | +16,714.7% | 117 | 3,427.1% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 26 ms | Yes 1,000 bars in 85 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 STRATEGY REAL EQUITY WITH 50X LEVERAGE",shorttitle = "MACD 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 = 0)// 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))// 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// DEFINITION : TRENDfloat trend = na trend:= delta > 0 ? 1 : -1// SL valuesstop_long = valuewhen(strategy.position_size > 0 and strategy.position_size[1] <= 0 and trend == 1 ,strategy.position_avg_price * 0.98,0)stop_short= valuewhen(strategy.position_size < 0 and strategy.position_size[1] >= 0 and trend == -1 ,strategy.position_avg_price * 1.02,0)// REAL LEVERAGE SIMULATION --- _lmov = strategy.position_size > 0 and strategy.position_size[1] == 0 _elmov = strategy.position_size[1] > 0 and strategy.position_size == 0_smov = strategy.position_size < 0 and strategy.position_size[1] == 0 _esmov= strategy.position_size[1] < 0 and strategy.position_size == 0 _dlmov = strategy.position_size[1] < 0 and strategy.position_size > 0 _dsmov = strategy.position_size[1] > 0 and strategy.position_size < 0 onlylong = barssince(_lmov) < barssince(_dlmov) and _lmovonlyshort = barssince(_smov) < barssince (_dsmov) and _smovonlylongexit = barssince(_elmov) < barssince(_dsmov) and _elmovonlyshortexit = barssince(_esmov) < barssince(_dlmov) and _esmovdirectlong = barssince(_dlmov) < barssince(_lmov) and _dlmovdirectshort = barssince(_dsmov) < barssince(_smov) and _dsmov// float capital = 0.00chg = change(strategy.position_size)ch = strategy.position_size_l = valuewhen(strategy.position_size > 0 and strategy.position_size[1] == 0,strategy.position_avg_price,0) // Long after Short or Long Exit_le = valuewhen(strategy.position_size[1] > 0 and strategy.position_size == 0 ,open,0)_s = valuewhen(strategy.position_size < 0 and strategy.position_size[1] == 0,strategy.position_avg_price,0) // Short after Long or Long Exit_se = valuewhen(strategy.position_size[1] < 0 and strategy.position_size == 0 ,open,0)_dds = valuewhen(strategy.position_size < 0 and strategy.position_size[1] >= 0,strategy.position_avg_price,0) // Close Short and Long == DirectLong_ddl = valuewhen(strategy.position_size > 0 and strategy.position_size[1] <= 0,strategy.position_avg_price,0) // Close Long and Short == DirectShortpiplong = ((_le - _l) / _l) * 100 pipshort= ((_se - _s) / _s) * 100 pipdl = ((_ddl - _dds) / _dds) * 100 // Direct Longpipds = ((_dds - _ddl) / _ddl) * 100 // Direct Short// CONSTRUCTION enterLong = ((trend == 1 and term and trend[1] != 1) or (trend == 1 and term and trend[1] != 1 and low[1] <= stop_long) or (trend == 1 and term and trend[1] == 1 and low[1] <= stop_long)) // 2sLong = low <= stop_long and trend == 1 and strategy.position_size > 0 and term // 1enterShort = ((trend == -1 and term and trend[1] != -1) or (trend == -1 and term and trend[1] != -1 and high[1] >= stop_short) or (trend == -1 and term and trend[1] == -1 and high[1] >= stop_short)) // -2sShort = high >= stop_short and trend == -1 and strategy.position_size < 0 and term // -1float mode = namode := change(strategy.wintrades) > 0 ? 1 : change(strategy.losstrades) > 0 ? -1 : nz(mode[1], 1)pipsize = (abs(chg) - abs(ch)) capital := onlylong ? nz(capital[1], 0) - chg : onlylongexit ? capital[1] : onlyshort ? nz(capital[1], 0) + chg : onlyshortexit ? capital[1] : directlong and mode == 1 ? (capital[1]) - ch + ((-pipsize * leverage * pipdl)/100) : directlong and mode != 1 ? capital[1] - ch : directshort and mode == 1 ? (capital[1]) + ch + ((pipsize * leverage * pipds)/100) : directshort and mode != 1 ? capital[1] + ch : capital[1] // NET CAPITALcapita = 100 + capitalfloat netcapital = nanetcapital := netcapital[1] <= 0 ? 0 : capita// STRATEGYstrategy.entry("Long",strategy.long, comment="LONG" ,when = enterLong , qty = possize)strategy.entry("Short",strategy.short, comment="SHORT" ,when = enterShort , qty = possize)if(sLong) strategy.close("Long",strategy.long , comment = "SL LONG")if(sShort ) strategy.close("Short" , comment = "SL SHORT")if time > timestamp(toyear, tomonth, today, 23, 59) strategy.close_all()plot(netcapital)