Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (2)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$12,282$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. 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.
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

Differs

Trades 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

Verified

Same 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.

SettingDefaultType and rangeFeeds
Sourceclosesourcefast_ma slow_ma
Risk percentage of BALANCE2floatline 34

What it calculates

  • SMA / EMA (sma, ta.sma in v5)Source (close), fast_lengthfast_ma · line 19
  • SMA / EMA (sma, ta.sma in v5)Source (close), slow_lengthslow_ma · line 20
  • SMA / EMA (sma, ta.sma in 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.

closecloseprice datafast_maSMA / EMA→ fast_maslow_maSMA / EMA→ slow_masignalSMA / EMA→ signalmacdmacdvaluehisthistvaluelongconditionlongconditionconditionshortconditionshortconditionconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entry

Order rules

OrderFires whenBy defaultLine
Open long longlongconditionhist > 0On28
Open short shortshortconditionhist < 0On29

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.

234/234trades 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. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−87.7%+102.5%64318%0.7598.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−5.9%+5.5%7835%0.9018.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−2.3%+9.8%6341%0.794.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.6%+8.4%6946%1.360.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%6248%1.140.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%6943%1.110.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−1.2%+148.3%6930%0.471.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.2%+17.1%6244%1.550.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 barsTradesWonP&L
Rising market21520%−$60,984.50
Sideways market25417%−$55,521.90
Falling market17417%$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.

0%114%
The first 150 of 643 trades
SideEntryExitBarsP&L
short29 Feb 2024 62,432.103 Mar 2024 61,987.303$444.83
long3 Mar 2024 61,987.304 Mar 2024 66,111.601$4,124.36
long5 Mar 2024 68,245.705 Mar 2024 66,154.300−$2,091.38
long6 Mar 2024 63,724.0011 Mar 2024 69,861.505$6,137.45
long12 Mar 2024 72,078.1012 Mar 2024 69,905.800−$2,172.31
long13 Mar 2024 71,452.0014 Mar 2024 69,261.301−$2,190.66
long15 Mar 2024 71,388.9015 Mar 2024 69,303.900−$2,085.05
long16 Mar 2024 69,499.8016 Mar 2024 67,456.500−$2,043.34
short17 Mar 2024 65,300.6017 Mar 2024 67,303.100−$2,002.48
short18 Mar 2024 68,393.5019 Mar 2024 64,028.901$4,364.52
short20 Mar 2024 61,937.4020 Mar 2024 63,987.100−$2,049.72
short21 Mar 2024 67,840.5022 Mar 2024 65,886.201$1,954.27
short23 Mar 2024 63,796.6023 Mar 2024 65,844.400−$2,047.81
short24 Mar 2024 63,990.0024 Mar 2024 65,996.900−$2,006.85
short25 Mar 2024 67,210.0025 Mar 2024 69,176.700−$1,966.72
short26 Mar 2024 69,880.0027 Mar 2024 71,405.601−$1,525.57
short28 Mar 2024 69,470.0028 Mar 2024 71,366.900−$1,896.87
short29 Mar 2024 70,780.602 Apr 2024 67,429.304$3,351.34
short3 Apr 2024 65,464.004 Apr 2024 65,963.301−$499.28
long4 Apr 2024 65,963.308 Apr 2024 69,590.904$3,627.62
long9 Apr 2024 71,620.009 Apr 2024 69,631.500−$1,988.53
long10 Apr 2024 69,146.0012 Apr 2024 65,208.302−$3,937.65
short13 Apr 2024 67,116.5015 Apr 2024 65,363.902$1,752.60
short16 Apr 2024 63,420.0017 Apr 2024 63,225.301$194.71
short18 Apr 2024 61,277.4018 Apr 2024 63,186.300−$1,908.95
short19 Apr 2024 63,470.1019 Apr 2024 65,340.900−$1,870.77
short20 Apr 2024 63,818.0024 Apr 2024 66,113.504−$2,295.50
short25 Apr 2024 64,289.6028 Apr 2024 63,462.003$827.60
long28 Apr 2024 63,462.0029 Apr 2024 62,053.901−$1,408.06
long30 Apr 2024 63,866.0030 Apr 2024 62,090.200−$1,775.84
long1 May 2024 60,672.001 May 2024 58,931.700−$1,740.32
long2 May 2024 58,365.003 May 2024 61,086.201$2,721.19
long4 May 2024 62,882.009 May 2024 61,310.205−$1,571.78
long10 May 2024 63,074.0010 May 2024 61,345.500−$1,728.50
long11 May 2024 60,800.0012 May 2024 60,826.001$26.00
short12 May 2024 60,826.0012 May 2024 61,875.600−$1,049.61
long13 May 2024 61,484.0015 May 2024 64,438.602$2,954.59
long16 May 2024 66,206.5017 May 2024 65,275.101−$931.41
long18 May 2024 67,024.0020 May 2024 69,644.302$2,620.25
long21 May 2024 71,446.6021 May 2024 69,680.300−$1,766.33
long22 May 2024 70,148.3024 May 2024 66,851.002−$3,297.38
long25 May 2024 68,550.002 Jun 2024 67,766.808−$783.15
short2 Jun 2024 67,766.807 Jun 2024 70,973.205−$3,206.38
short8 Jun 2024 69,355.6011 Jun 2024 68,940.303$415.27
short12 Jun 2024 67,314.2012 Jun 2024 68,907.800−$1,593.57
short13 Jun 2024 68,264.0024 Jun 2024 62,014.4011$6,249.57
short25 Jun 2024 60,293.3025 Jun 2024 61,980.000−$1,686.69
short26 Jun 2024 61,806.0028 Jun 2024 62,108.402−$302.35
short29 Jun 2024 60,427.803 Jul 2024 61,859.904−$1,432.03
short4 Jul 2024 60,208.607 Jul 2024 58,230.103$1,978.44
long7 Jul 2024 58,230.107 Jul 2024 58,897.200$667.04
short8 Jul 2024 55,857.808 Jul 2024 57,529.000−$1,671.18
long9 Jul 2024 56,714.6015 Jul 2024 62,926.206$6,211.59
long16 Jul 2024 64,724.1016 Jul 2024 62,962.100−$1,761.98
long17 Jul 2024 65,044.0019 Jul 2024 64,900.902−$143.06
long20 Jul 2024 66,660.0021 Jul 2024 66,411.401−$248.66
long22 Jul 2024 68,165.4025 Jul 2024 64,128.303−$4,037.00
long26 Jul 2024 65,799.901 Aug 2024 63,724.806−$2,075.18
short2 Aug 2024 65,354.004 Aug 2024 59,901.502$5,452.49
short5 Aug 2024 58,161.007 Aug 2024 56,900.402$1,260.59
short8 Aug 2024 55,133.808 Aug 2024 56,864.700−$1,730.93
short9 Aug 2024 61,686.0011 Aug 2024 60,468.402$1,217.63
short12 Aug 2024 58,712.6012 Aug 2024 60,433.300−$1,720.66
short13 Aug 2024 59,346.6013 Aug 2024 61,032.900−$1,686.25
short14 Aug 2024 60,587.2015 Aug 2024 59,254.501$1,332.65
short16 Aug 2024 57,541.1016 Aug 2024 59,220.200−$1,679.18
short17 Aug 2024 58,874.6018 Aug 2024 59,492.001−$617.40
long18 Aug 2024 59,492.0018 Aug 2024 58,902.100−$589.90
long19 Aug 2024 58,427.3021 Aug 2024 59,480.002$1,052.66
long22 Aug 2024 61,156.0023 Aug 2024 62,337.101$1,181.08
long24 Aug 2024 64,037.202 Sep 2024 57,564.109−$6,473.13
short3 Sep 2024 59,132.105 Sep 2024 57,775.702$1,356.42
short6 Sep 2024 56,180.0017 Sep 2024 58,214.0011−$2,033.99
long17 Sep 2024 58,214.0018 Sep 2024 60,166.001$1,951.97
long19 Sep 2024 61,760.0026 Sep 2024 63,543.607$1,783.58
long27 Sep 2024 65,174.003 Oct 2024 60,649.306−$4,524.72
short3 Oct 2024 60,649.307 Oct 2024 63,699.804−$3,050.56
short8 Oct 2024 62,224.009 Oct 2024 62,114.101$109.92
short10 Oct 2024 60,636.0017 Oct 2024 67,620.007−$6,983.99
long17 Oct 2024 67,620.0023 Oct 2024 65,378.806−$2,241.16
long24 Oct 2024 66,668.6028 Oct 2024 68,632.304$1,963.68
long29 Oct 2024 69,962.201 Nov 2024 70,292.003$329.80
short1 Nov 2024 70,292.004 Nov 2024 69,208.703$1,083.28
short5 Nov 2024 67,850.005 Nov 2024 69,181.600−$1,331.54
short6 Nov 2024 69,372.006 Nov 2024 70,676.900−$1,304.91
short7 Nov 2024 75,572.008 Nov 2024 75,857.901−$285.90
long8 Nov 2024 75,857.9010 Nov 2024 79,006.702$3,148.78
long11 Nov 2024 80,370.0012 Nov 2024 86,464.301$6,094.29
long13 Nov 2024 87,952.0013 Nov 2024 86,494.000−$1,457.96
long14 Nov 2024 90,375.2014 Nov 2024 88,946.400−$1,428.80
long15 Nov 2024 87,325.6019 Nov 2024 90,810.904$3,485.27
long20 Nov 2024 92,310.8021 Nov 2024 96,727.101$4,416.26
long22 Nov 2024 98,317.1024 Nov 2024 96,350.102−$1,966.99
long25 Nov 2024 97,900.1025 Nov 2024 96,381.100−$1,518.91
long26 Nov 2024 93,010.0026 Nov 2024 91,521.500−$1,488.54
short27 Nov 2024 91,965.2027 Nov 2024 93,423.900−$1,458.77
short28 Nov 2024 95,863.102 Dec 2024 97,270.704−$1,407.55
short3 Dec 2024 95,840.605 Dec 2024 98,325.002−$2,484.36
short6 Dec 2024 96,945.606 Dec 2024 98,297.400−$1,351.75
short7 Dec 2024 99,740.809 Dec 2024 98,650.502$1,090.37
short10 Dec 2024 97,276.5012 Dec 2024 101,296.002−$4,019.78
short13 Dec 2024 100,004.0013 Dec 2024 101,270.000−$1,266.13
short14 Dec 2024 101,424.0016 Dec 2024 107,207.002−$5,782.54
short17 Dec 2024 106,059.0017 Dec 2024 107,184.000−$1,125.16
long18 Dec 2024 106,134.0018 Dec 2024 105,031.000−$1,102.65
long19 Dec 2024 100,204.0019 Dec 2024 99,123.400−$1,080.60
long20 Dec 2024 97,461.9020 Dec 2024 96,402.900−$1,058.99
short21 Dec 2024 97,805.4021 Dec 2024 98,843.300−$1,037.81
short22 Dec 2024 97,292.0023 Dec 2024 95,946.701$1,345.27
short24 Dec 2024 94,881.5024 Dec 2024 95,925.400−$1,043.96
short25 Dec 2024 98,663.6026 Dec 2024 96,872.101$1,791.46
short27 Dec 2024 95,791.6027 Dec 2024 96,850.500−$1,058.91
short28 Dec 2024 94,299.0028 Dec 2024 95,336.800−$1,037.73
short29 Dec 2024 95,300.0030 Dec 2024 93,859.201$1,440.82
short31 Dec 2024 92,792.1031 Dec 2024 93,837.800−$1,045.79
short1 Jan 2025 93,576.001 Jan 2025 94,600.900−$1,024.87
short2 Jan 2025 94,591.802 Jan 2025 95,596.200−$1,004.38
short3 Jan 2025 96,984.803 Jan 2025 97,969.100−$984.29
short4 Jan 2025 98,174.207 Jan 2025 97,943.603$230.57
long8 Jan 2025 96,954.608 Jan 2025 95,985.400−$969.21
long9 Jan 2025 95,060.609 Jan 2025 94,110.800−$949.83
long10 Jan 2025 92,552.5013 Jan 2025 93,565.603$1,013.10
long14 Jan 2025 94,536.1015 Jan 2025 99,427.001$4,890.92
long16 Jan 2025 100,497.0016 Jan 2025 99,448.400−$1,048.91
long17 Jan 2025 99,987.3018 Jan 2025 103,437.001$3,449.62
long19 Jan 2025 104,556.0019 Jan 2025 103,459.000−$1,096.93
long20 Jan 2025 101,332.0020 Jan 2025 100,257.000−$1,074.99
long21 Jan 2025 102,260.0021 Jan 2025 101,207.000−$1,053.49
long22 Jan 2025 106,144.0022 Jan 2025 105,111.000−$1,032.42
long23 Jan 2025 103,707.0023 Jan 2025 102,695.000−$1,011.77
long24 Jan 2025 103,910.0024 Jan 2025 102,919.000−$991.54
long25 Jan 2025 104,871.0027 Jan 2025 101,167.002−$3,703.63
long28 Jan 2025 102,083.0028 Jan 2025 101,185.000−$897.63
long29 Jan 2025 101,336.0030 Jan 2025 103,776.001$2,439.99
long31 Jan 2025 104,723.0031 Jan 2025 103,794.000−$928.48
long1 Feb 2025 102,430.001 Feb 2025 101,520.000−$909.91
short2 Feb 2025 100,636.003 Feb 2025 102,206.001−$1,570.72
short4 Feb 2025 101,329.005 Feb 2025 97,567.101$3,761.46
short6 Feb 2025 96,612.406 Feb 2025 97,548.000−$935.53
short7 Feb 2025 96,554.407 Feb 2025 97,471.200−$916.82
short8 Feb 2025 96,506.8010 Feb 2025 98,310.802−$1,804.02
short11 Feb 2025 97,430.8011 Feb 2025 98,293.200−$862.40
short12 Feb 2025 95,778.2012 Feb 2025 96,623.400−$845.15
short13 Feb 2025 97,870.0014 Feb 2025 98,336.101−$466.12
short15 Feb 2025 97,500.5016 Feb 2025 96,964.701$535.78
short17 Feb 2025 96,118.1017 Feb 2025 96,947.800−$829.64
short18 Feb 2025 95,780.0018 Feb 2025 96,593.100−$813.05
long19 Feb 2025 95,671.7020 Feb 2025 97,455.601$1,783.81
long21 Feb 2025 98,305.0021 Feb 2025 97,472.600−$832.46
long22 Feb 2025 96,182.0023 Feb 2025 95,440.701−$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.

ScriptSharesTypeNetTradesMax drawdown
Simple and efficient MACD crypto strategy with risk management this page—v4 strategy−87.7%64398.2%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.8%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 6 msWith a workaround 1,000 bars in 20 msNot measured
PineTSNo 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)