Pine Script v4 · Strategy
Simple and efficient MACD crypto strategy with risk management
A Pine Script v4 strategy built on SMA or EMA (close, fast_length). It has 2 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 is one contract and pays no commission. 2 settings; defaults include Source close and Risk percentage of BALANCE 2.
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 Simple and efficient MACD crypto strategy with risk management repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 234 of 234 trades.
- How did Simple and efficient MACD crypto strategy with risk management do on BTCUSDT 1D with default settings?
- −87.73%
- From 26 Jan 2024 to 21 Oct 2026, over 643 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Simple and efficient MACD crypto strategy with risk management be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Simple and efficient MACD crypto strategy with risk management use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Simple and efficient MACD crypto strategy with risk management run in Zeal Terminal?
- Yes
- It compiles in 6 ms and runs 1,000 bars in 20 ms, in the browser.
BTCUSDT · 1D · default settings
- SMA
- SMA
- SMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −87.73%
- −$87,729.90
- Buy and hold
- +102.5%
- same period
- Closed trades
- 643
- 117 won · 526 lost
- Profitable
- 18.2%
- of closed trades
- Profit factor
- 0.75
- gross profit ÷ gross loss
- Max drawdown
- 98.16%
- −$106,614.00
One run with the author's default settings, $100,000 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
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 28, 29. 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 sma → ta.sma, ema → ta.ema.
- 2 strategy calls use the when = argument (line 28, 29). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 643 before, 62 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 14: input(type = input.source) → input.source()
- Line 19: sma → ta.sma
- Line 19: ema → ta.ema
- Line 20: sma → ta.sma
- Line 20: ema → ta.ema
5 more edits
- Line 22: sma → ta.sma
- Line 22: ema → ta.ema
- Line 28: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 29: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
- Line 33: input(type = input.float) → input.float()
⋯// © SoftKill21-//@version=4+//@version=5strategy("MACD crypto strategy", overlay=true)⋯slow_length = 26-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)signal_length = 9⋯// 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⋯//tp = input(0.1, title="tp")-strategy.entry("long",1,when=longcondition)+strategy.entry("long",strategy.long,when=longcondition)-strategy.entry("short",0,when=shortcondition)+strategy.entry("short",strategy.short,when=shortcondition)//strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")⋯//strategy.exit("x_short", "short" , loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick,alert_message = "closeshort")-risk = input(2, type=input.float,title="Risk percentage of BALANCE")+risk = input.float(2,title="Risk percentage of BALANCE")strategy.risk.max_intraday_loss(risk, strategy.percent_of_equity)Clean v5
VerifiedSame 62 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 28: when = longcondition → if block
- Line 29: when = shortcondition → if block
⋯//tp = input(0.1, title="tp")-strategy.entry("long",strategy.long,when=longcondition)+if longcondition+ strategy.entry("long",strategy.long)-strategy.entry("short",strategy.short,when=shortcondition)+if shortcondition+ strategy.entry("short",strategy.short)//strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")⋯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: 62 before, 425 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.
⋯// © SoftKill21-//@version=5+//@version=6strategy("MACD crypto strategy", 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 |
|---|---|---|---|
| Source | close | source | fast_ma slow_ma |
| Risk percentage of BALANCE | 2 | float | line 34 |
What it calculates
- SMA / EMA (
sma,ta.smain v5)Source (close), fast_lengthfast_ma · line 19 - SMA / EMA (
sma,ta.smain v5)Source (close), slow_lengthslow_ma · line 20 - SMA / EMA (
sma,ta.smain v5)macd, signal_lengthsignal · line 22
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 | longconditionhist > 0 | On | 28 |
| Open short short | shortconditionhist < 0 | On | 29 |
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 | −87.7% | +102.5% | 643 | 18% | 0.75 | 98.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.9% | +5.5% | 78 | 35% | 0.90 | 18.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −2.3% | +9.8% | 63 | 41% | 0.79 | 4.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.6% | +8.4% | 69 | 46% | 1.36 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 62 | 48% | 1.14 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 69 | 43% | 1.11 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −1.2% | +148.3% | 69 | 30% | 0.47 | 1.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.2% | +17.1% | 62 | 44% | 1.55 | 0.1% | 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 | 215 | 20% | −$60,984.50 |
| Sideways market | 254 | 17% | −$55,521.90 |
| Falling market | 174 | 17% | $28,776.50 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
98.9%
The 95th percentile of the worst drawdown when the same 643 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 90.7% to 98.9%; the tick is what actually happened, 98.0%. Order luck alone moves it this much.
The first 150 of 643 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 29 Feb 2024 62,432.10 | 3 Mar 2024 61,987.30 | 3 | $444.83 |
| long | 3 Mar 2024 61,987.30 | 4 Mar 2024 66,111.60 | 1 | $4,124.36 |
| long | 5 Mar 2024 68,245.70 | 5 Mar 2024 66,154.30 | 0 | −$2,091.38 |
| long | 6 Mar 2024 63,724.00 | 11 Mar 2024 69,861.50 | 5 | $6,137.45 |
| long | 12 Mar 2024 72,078.10 | 12 Mar 2024 69,905.80 | 0 | −$2,172.31 |
| long | 13 Mar 2024 71,452.00 | 14 Mar 2024 69,261.30 | 1 | −$2,190.66 |
| long | 15 Mar 2024 71,388.90 | 15 Mar 2024 69,303.90 | 0 | −$2,085.05 |
| long | 16 Mar 2024 69,499.80 | 16 Mar 2024 67,456.50 | 0 | −$2,043.34 |
| short | 17 Mar 2024 65,300.60 | 17 Mar 2024 67,303.10 | 0 | −$2,002.48 |
| short | 18 Mar 2024 68,393.50 | 19 Mar 2024 64,028.90 | 1 | $4,364.52 |
| short | 20 Mar 2024 61,937.40 | 20 Mar 2024 63,987.10 | 0 | −$2,049.72 |
| short | 21 Mar 2024 67,840.50 | 22 Mar 2024 65,886.20 | 1 | $1,954.27 |
| short | 23 Mar 2024 63,796.60 | 23 Mar 2024 65,844.40 | 0 | −$2,047.81 |
| short | 24 Mar 2024 63,990.00 | 24 Mar 2024 65,996.90 | 0 | −$2,006.85 |
| short | 25 Mar 2024 67,210.00 | 25 Mar 2024 69,176.70 | 0 | −$1,966.72 |
| short | 26 Mar 2024 69,880.00 | 27 Mar 2024 71,405.60 | 1 | −$1,525.57 |
| short | 28 Mar 2024 69,470.00 | 28 Mar 2024 71,366.90 | 0 | −$1,896.87 |
| short | 29 Mar 2024 70,780.60 | 2 Apr 2024 67,429.30 | 4 | $3,351.34 |
| short | 3 Apr 2024 65,464.00 | 4 Apr 2024 65,963.30 | 1 | −$499.28 |
| long | 4 Apr 2024 65,963.30 | 8 Apr 2024 69,590.90 | 4 | $3,627.62 |
| long | 9 Apr 2024 71,620.00 | 9 Apr 2024 69,631.50 | 0 | −$1,988.53 |
| long | 10 Apr 2024 69,146.00 | 12 Apr 2024 65,208.30 | 2 | −$3,937.65 |
| short | 13 Apr 2024 67,116.50 | 15 Apr 2024 65,363.90 | 2 | $1,752.60 |
| short | 16 Apr 2024 63,420.00 | 17 Apr 2024 63,225.30 | 1 | $194.71 |
| short | 18 Apr 2024 61,277.40 | 18 Apr 2024 63,186.30 | 0 | −$1,908.95 |
| short | 19 Apr 2024 63,470.10 | 19 Apr 2024 65,340.90 | 0 | −$1,870.77 |
| short | 20 Apr 2024 63,818.00 | 24 Apr 2024 66,113.50 | 4 | −$2,295.50 |
| short | 25 Apr 2024 64,289.60 | 28 Apr 2024 63,462.00 | 3 | $827.60 |
| long | 28 Apr 2024 63,462.00 | 29 Apr 2024 62,053.90 | 1 | −$1,408.06 |
| long | 30 Apr 2024 63,866.00 | 30 Apr 2024 62,090.20 | 0 | −$1,775.84 |
| long | 1 May 2024 60,672.00 | 1 May 2024 58,931.70 | 0 | −$1,740.32 |
| long | 2 May 2024 58,365.00 | 3 May 2024 61,086.20 | 1 | $2,721.19 |
| long | 4 May 2024 62,882.00 | 9 May 2024 61,310.20 | 5 | −$1,571.78 |
| long | 10 May 2024 63,074.00 | 10 May 2024 61,345.50 | 0 | −$1,728.50 |
| long | 11 May 2024 60,800.00 | 12 May 2024 60,826.00 | 1 | $26.00 |
| short | 12 May 2024 60,826.00 | 12 May 2024 61,875.60 | 0 | −$1,049.61 |
| long | 13 May 2024 61,484.00 | 15 May 2024 64,438.60 | 2 | $2,954.59 |
| long | 16 May 2024 66,206.50 | 17 May 2024 65,275.10 | 1 | −$931.41 |
| long | 18 May 2024 67,024.00 | 20 May 2024 69,644.30 | 2 | $2,620.25 |
| long | 21 May 2024 71,446.60 | 21 May 2024 69,680.30 | 0 | −$1,766.33 |
| long | 22 May 2024 70,148.30 | 24 May 2024 66,851.00 | 2 | −$3,297.38 |
| long | 25 May 2024 68,550.00 | 2 Jun 2024 67,766.80 | 8 | −$783.15 |
| short | 2 Jun 2024 67,766.80 | 7 Jun 2024 70,973.20 | 5 | −$3,206.38 |
| short | 8 Jun 2024 69,355.60 | 11 Jun 2024 68,940.30 | 3 | $415.27 |
| short | 12 Jun 2024 67,314.20 | 12 Jun 2024 68,907.80 | 0 | −$1,593.57 |
| short | 13 Jun 2024 68,264.00 | 24 Jun 2024 62,014.40 | 11 | $6,249.57 |
| short | 25 Jun 2024 60,293.30 | 25 Jun 2024 61,980.00 | 0 | −$1,686.69 |
| short | 26 Jun 2024 61,806.00 | 28 Jun 2024 62,108.40 | 2 | −$302.35 |
| short | 29 Jun 2024 60,427.80 | 3 Jul 2024 61,859.90 | 4 | −$1,432.03 |
| short | 4 Jul 2024 60,208.60 | 7 Jul 2024 58,230.10 | 3 | $1,978.44 |
| long | 7 Jul 2024 58,230.10 | 7 Jul 2024 58,897.20 | 0 | $667.04 |
| short | 8 Jul 2024 55,857.80 | 8 Jul 2024 57,529.00 | 0 | −$1,671.18 |
| long | 9 Jul 2024 56,714.60 | 15 Jul 2024 62,926.20 | 6 | $6,211.59 |
| long | 16 Jul 2024 64,724.10 | 16 Jul 2024 62,962.10 | 0 | −$1,761.98 |
| long | 17 Jul 2024 65,044.00 | 19 Jul 2024 64,900.90 | 2 | −$143.06 |
| long | 20 Jul 2024 66,660.00 | 21 Jul 2024 66,411.40 | 1 | −$248.66 |
| long | 22 Jul 2024 68,165.40 | 25 Jul 2024 64,128.30 | 3 | −$4,037.00 |
| long | 26 Jul 2024 65,799.90 | 1 Aug 2024 63,724.80 | 6 | −$2,075.18 |
| short | 2 Aug 2024 65,354.00 | 4 Aug 2024 59,901.50 | 2 | $5,452.49 |
| short | 5 Aug 2024 58,161.00 | 7 Aug 2024 56,900.40 | 2 | $1,260.59 |
| short | 8 Aug 2024 55,133.80 | 8 Aug 2024 56,864.70 | 0 | −$1,730.93 |
| short | 9 Aug 2024 61,686.00 | 11 Aug 2024 60,468.40 | 2 | $1,217.63 |
| short | 12 Aug 2024 58,712.60 | 12 Aug 2024 60,433.30 | 0 | −$1,720.66 |
| short | 13 Aug 2024 59,346.60 | 13 Aug 2024 61,032.90 | 0 | −$1,686.25 |
| short | 14 Aug 2024 60,587.20 | 15 Aug 2024 59,254.50 | 1 | $1,332.65 |
| short | 16 Aug 2024 57,541.10 | 16 Aug 2024 59,220.20 | 0 | −$1,679.18 |
| short | 17 Aug 2024 58,874.60 | 18 Aug 2024 59,492.00 | 1 | −$617.40 |
| long | 18 Aug 2024 59,492.00 | 18 Aug 2024 58,902.10 | 0 | −$589.90 |
| long | 19 Aug 2024 58,427.30 | 21 Aug 2024 59,480.00 | 2 | $1,052.66 |
| long | 22 Aug 2024 61,156.00 | 23 Aug 2024 62,337.10 | 1 | $1,181.08 |
| long | 24 Aug 2024 64,037.20 | 2 Sep 2024 57,564.10 | 9 | −$6,473.13 |
| short | 3 Sep 2024 59,132.10 | 5 Sep 2024 57,775.70 | 2 | $1,356.42 |
| short | 6 Sep 2024 56,180.00 | 17 Sep 2024 58,214.00 | 11 | −$2,033.99 |
| long | 17 Sep 2024 58,214.00 | 18 Sep 2024 60,166.00 | 1 | $1,951.97 |
| long | 19 Sep 2024 61,760.00 | 26 Sep 2024 63,543.60 | 7 | $1,783.58 |
| long | 27 Sep 2024 65,174.00 | 3 Oct 2024 60,649.30 | 6 | −$4,524.72 |
| short | 3 Oct 2024 60,649.30 | 7 Oct 2024 63,699.80 | 4 | −$3,050.56 |
| short | 8 Oct 2024 62,224.00 | 9 Oct 2024 62,114.10 | 1 | $109.92 |
| short | 10 Oct 2024 60,636.00 | 17 Oct 2024 67,620.00 | 7 | −$6,983.99 |
| long | 17 Oct 2024 67,620.00 | 23 Oct 2024 65,378.80 | 6 | −$2,241.16 |
| long | 24 Oct 2024 66,668.60 | 28 Oct 2024 68,632.30 | 4 | $1,963.68 |
| long | 29 Oct 2024 69,962.20 | 1 Nov 2024 70,292.00 | 3 | $329.80 |
| short | 1 Nov 2024 70,292.00 | 4 Nov 2024 69,208.70 | 3 | $1,083.28 |
| short | 5 Nov 2024 67,850.00 | 5 Nov 2024 69,181.60 | 0 | −$1,331.54 |
| short | 6 Nov 2024 69,372.00 | 6 Nov 2024 70,676.90 | 0 | −$1,304.91 |
| short | 7 Nov 2024 75,572.00 | 8 Nov 2024 75,857.90 | 1 | −$285.90 |
| long | 8 Nov 2024 75,857.90 | 10 Nov 2024 79,006.70 | 2 | $3,148.78 |
| long | 11 Nov 2024 80,370.00 | 12 Nov 2024 86,464.30 | 1 | $6,094.29 |
| long | 13 Nov 2024 87,952.00 | 13 Nov 2024 86,494.00 | 0 | −$1,457.96 |
| long | 14 Nov 2024 90,375.20 | 14 Nov 2024 88,946.40 | 0 | −$1,428.80 |
| long | 15 Nov 2024 87,325.60 | 19 Nov 2024 90,810.90 | 4 | $3,485.27 |
| long | 20 Nov 2024 92,310.80 | 21 Nov 2024 96,727.10 | 1 | $4,416.26 |
| long | 22 Nov 2024 98,317.10 | 24 Nov 2024 96,350.10 | 2 | −$1,966.99 |
| long | 25 Nov 2024 97,900.10 | 25 Nov 2024 96,381.10 | 0 | −$1,518.91 |
| long | 26 Nov 2024 93,010.00 | 26 Nov 2024 91,521.50 | 0 | −$1,488.54 |
| short | 27 Nov 2024 91,965.20 | 27 Nov 2024 93,423.90 | 0 | −$1,458.77 |
| short | 28 Nov 2024 95,863.10 | 2 Dec 2024 97,270.70 | 4 | −$1,407.55 |
| short | 3 Dec 2024 95,840.60 | 5 Dec 2024 98,325.00 | 2 | −$2,484.36 |
| short | 6 Dec 2024 96,945.60 | 6 Dec 2024 98,297.40 | 0 | −$1,351.75 |
| short | 7 Dec 2024 99,740.80 | 9 Dec 2024 98,650.50 | 2 | $1,090.37 |
| short | 10 Dec 2024 97,276.50 | 12 Dec 2024 101,296.00 | 2 | −$4,019.78 |
| short | 13 Dec 2024 100,004.00 | 13 Dec 2024 101,270.00 | 0 | −$1,266.13 |
| short | 14 Dec 2024 101,424.00 | 16 Dec 2024 107,207.00 | 2 | −$5,782.54 |
| short | 17 Dec 2024 106,059.00 | 17 Dec 2024 107,184.00 | 0 | −$1,125.16 |
| long | 18 Dec 2024 106,134.00 | 18 Dec 2024 105,031.00 | 0 | −$1,102.65 |
| long | 19 Dec 2024 100,204.00 | 19 Dec 2024 99,123.40 | 0 | −$1,080.60 |
| long | 20 Dec 2024 97,461.90 | 20 Dec 2024 96,402.90 | 0 | −$1,058.99 |
| short | 21 Dec 2024 97,805.40 | 21 Dec 2024 98,843.30 | 0 | −$1,037.81 |
| short | 22 Dec 2024 97,292.00 | 23 Dec 2024 95,946.70 | 1 | $1,345.27 |
| short | 24 Dec 2024 94,881.50 | 24 Dec 2024 95,925.40 | 0 | −$1,043.96 |
| short | 25 Dec 2024 98,663.60 | 26 Dec 2024 96,872.10 | 1 | $1,791.46 |
| short | 27 Dec 2024 95,791.60 | 27 Dec 2024 96,850.50 | 0 | −$1,058.91 |
| short | 28 Dec 2024 94,299.00 | 28 Dec 2024 95,336.80 | 0 | −$1,037.73 |
| short | 29 Dec 2024 95,300.00 | 30 Dec 2024 93,859.20 | 1 | $1,440.82 |
| short | 31 Dec 2024 92,792.10 | 31 Dec 2024 93,837.80 | 0 | −$1,045.79 |
| short | 1 Jan 2025 93,576.00 | 1 Jan 2025 94,600.90 | 0 | −$1,024.87 |
| short | 2 Jan 2025 94,591.80 | 2 Jan 2025 95,596.20 | 0 | −$1,004.38 |
| short | 3 Jan 2025 96,984.80 | 3 Jan 2025 97,969.10 | 0 | −$984.29 |
| short | 4 Jan 2025 98,174.20 | 7 Jan 2025 97,943.60 | 3 | $230.57 |
| long | 8 Jan 2025 96,954.60 | 8 Jan 2025 95,985.40 | 0 | −$969.21 |
| long | 9 Jan 2025 95,060.60 | 9 Jan 2025 94,110.80 | 0 | −$949.83 |
| long | 10 Jan 2025 92,552.50 | 13 Jan 2025 93,565.60 | 3 | $1,013.10 |
| long | 14 Jan 2025 94,536.10 | 15 Jan 2025 99,427.00 | 1 | $4,890.92 |
| long | 16 Jan 2025 100,497.00 | 16 Jan 2025 99,448.40 | 0 | −$1,048.91 |
| long | 17 Jan 2025 99,987.30 | 18 Jan 2025 103,437.00 | 1 | $3,449.62 |
| long | 19 Jan 2025 104,556.00 | 19 Jan 2025 103,459.00 | 0 | −$1,096.93 |
| long | 20 Jan 2025 101,332.00 | 20 Jan 2025 100,257.00 | 0 | −$1,074.99 |
| long | 21 Jan 2025 102,260.00 | 21 Jan 2025 101,207.00 | 0 | −$1,053.49 |
| long | 22 Jan 2025 106,144.00 | 22 Jan 2025 105,111.00 | 0 | −$1,032.42 |
| long | 23 Jan 2025 103,707.00 | 23 Jan 2025 102,695.00 | 0 | −$1,011.77 |
| long | 24 Jan 2025 103,910.00 | 24 Jan 2025 102,919.00 | 0 | −$991.54 |
| long | 25 Jan 2025 104,871.00 | 27 Jan 2025 101,167.00 | 2 | −$3,703.63 |
| long | 28 Jan 2025 102,083.00 | 28 Jan 2025 101,185.00 | 0 | −$897.63 |
| long | 29 Jan 2025 101,336.00 | 30 Jan 2025 103,776.00 | 1 | $2,439.99 |
| long | 31 Jan 2025 104,723.00 | 31 Jan 2025 103,794.00 | 0 | −$928.48 |
| long | 1 Feb 2025 102,430.00 | 1 Feb 2025 101,520.00 | 0 | −$909.91 |
| short | 2 Feb 2025 100,636.00 | 3 Feb 2025 102,206.00 | 1 | −$1,570.72 |
| short | 4 Feb 2025 101,329.00 | 5 Feb 2025 97,567.10 | 1 | $3,761.46 |
| short | 6 Feb 2025 96,612.40 | 6 Feb 2025 97,548.00 | 0 | −$935.53 |
| short | 7 Feb 2025 96,554.40 | 7 Feb 2025 97,471.20 | 0 | −$916.82 |
| short | 8 Feb 2025 96,506.80 | 10 Feb 2025 98,310.80 | 2 | −$1,804.02 |
| short | 11 Feb 2025 97,430.80 | 11 Feb 2025 98,293.20 | 0 | −$862.40 |
| short | 12 Feb 2025 95,778.20 | 12 Feb 2025 96,623.40 | 0 | −$845.15 |
| short | 13 Feb 2025 97,870.00 | 14 Feb 2025 98,336.10 | 1 | −$466.12 |
| short | 15 Feb 2025 97,500.50 | 16 Feb 2025 96,964.70 | 1 | $535.78 |
| short | 17 Feb 2025 96,118.10 | 17 Feb 2025 96,947.80 | 0 | −$829.64 |
| short | 18 Feb 2025 95,780.00 | 18 Feb 2025 96,593.10 | 0 | −$813.05 |
| long | 19 Feb 2025 95,671.70 | 20 Feb 2025 97,455.60 | 1 | $1,783.81 |
| long | 21 Feb 2025 98,305.00 | 21 Feb 2025 97,472.60 | 0 | −$832.46 |
| long | 22 Feb 2025 96,182.00 | 23 Feb 2025 95,440.70 | 1 | −$741.33 |
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 |
|---|---|---|---|---|---|
| Simple and efficient MACD crypto strategy with risk management this page | — | v4 strategy | −87.7% | 643 | 98.2% |
| MACD Long Strat by TheGrindToday | ema sma | v4 strategy | +24.0% | 79 | 20.1% |
| Stock trending strategy by exlux99 | ema sma | v4 strategy | +35.3% | 21 | 14.7% |
| 4-Hour Stochastic EMA Trend by slymnturkoglu | ema sma | v4 strategy | No trades on this market | ||
| 4X EMA and volume strategy by SoftKill21 | ema sma | v4 strategy | +1.8% | 3 | 25.8% |
| Simple Momentum Strategy Based on SMA, EMA and Volume by slip_stream | sma ema | v4 strategy | +7.4% | 18 | 27.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 6 ms | With a workaround 1,000 bars in 20 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 28, 29) 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/// © SoftKill21//@version=4strategy("MACD crypto strategy", overlay=true)// Getting inputs//fast_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=true)//sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)fast_length = 12slow_length = 26src = input(title="Source", type=input.source, defval=close)signal_length = 9sma_source = truesma_signal = false// 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 - signallongcondition = hist > 0 shortcondition = hist < 0 //sl = input(0.5, title="SL")//tp = input(0.1, title="tp")strategy.entry("long",1,when=longcondition)strategy.entry("short",0,when=shortcondition)//strategy.exit("x_long", "long" ,loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick , alert_message = "closelong")//strategy.entry("short",0, when= loss = close * sl / syminfo.mintick)//strategy.exit("x_short", "short" , loss = close * sl / syminfo.mintick, profit = close * tp / syminfo.mintick,alert_message = "closeshort")risk = input(2, type=input.float,title="Risk percentage of BALANCE")strategy.risk.max_intraday_loss(risk, strategy.percent_of_equity)