Pine Script v4 · Strategy
Crypto Scalper Divergence Macd Psar Ema 200
A Pine Script v4 strategy built on EMA (close, 60) and SMA or EMA (close, 12). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.03% commission. 14 settings; defaults include Length EMA 60, Source close and Fast Length MACD 12.
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 Crypto Scalper Divergence Macd Psar Ema 200 repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 8 of 8 trades.
- How did Crypto Scalper Divergence Macd Psar Ema 200 do on BTCUSDT 1D with default settings?
- −29.35%
- From 26 Jan 2024 to 21 Oct 2026, over 21 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Crypto Scalper Divergence Macd Psar Ema 200 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 Crypto Scalper Divergence Macd Psar Ema 200 use a stop loss?
- Yes
- strategy.exit sets a stop on line 88, 91.
- Does Crypto Scalper Divergence Macd Psar Ema 200 run in Zeal Terminal?
- Yes
- It compiles in 28 ms and runs 1,000 bars in 49 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- SMA
- SMA
- SMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −29.35%
- −$29.35
- Buy and hold
- +102.5%
- same period
- Closed trades
- 21
- 6 won · 15 lost
- Profitable
- 28.6%
- of closed trades
- Profit factor
- 0.58
- gross profit ÷ gross loss
- Max drawdown
- 34.75%
- −$34.75
One run with the author's default settings, $100 starting capital, commission as the script sets it. A long 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
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
7 settings have no label
In the settings dialog start (line 20), increment (line 21), maximum (line 22), tplong (line 82), sllong (line 83), tpshort (line 84), slshort (line 85) show an empty name. The labels on this page come from the variable names.
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, sma → ta.sma, max → math.max, min → math.min.
v4 → v5
VerifiedSame 21 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 7: ema → ta.ema
- Line 9: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
- Line 11: input(type = input.integer) → input.int()
- Line 12: input(type = input.string) → input.string()
15 more edits
- Line 13: input(type = input.string) → input.string()
- Line 15: sma → ta.sma
- Line 15: ema → ta.ema
- Line 16: sma → ta.sma
- Line 16: ema → ta.ema
- Line 18: sma → ta.sma
- Line 18: ema → ta.ema
- Line 54: max → math.max
- Line 61: min → math.min
- Line 68: min → math.min
- Line 72: min → math.min
- Line 74: min → math.min
- Line 76: min → math.min
- Line 78: max → math.max
- Line 80: max → math.max
⋯// © exlux99-//@version=4+//@version=5strategy(title = "Crypto Scalper", overlay = true, pyramiding=1,initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)⋯src = input(close, title="Source")-out = ema(src, len)+out = ta.ema(src, len)//-fast_length = input(title="Fast Length MACD", type=input.integer, defval=12)+fast_length = input.int(title="Fast Length MACD", defval=12)-slow_length = input(title="Slow Length MACD", type=input.integer, defval=26)+slow_length = input.int(title="Slow Length MACD", defval=26)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)-sma_source = input(title="Oscillator MA Type MACD", type=input.string, defval="EMA", options=["SMA", "EMA"])+sma_source = input.string(title="Oscillator MA Type MACD", defval="EMA", options=["SMA", "EMA"])-sma_signal = input(title="Signal Line MA Type MACD", type=input.string, defval="EMA", options=["SMA", "EMA"])+sma_signal = input.string(title="Signal Line MA Type MACD", defval="EMA", options=["SMA", "EMA"])// Calculating-fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length)+fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)-slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length)+slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_ma-signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal⋯ uptrend := false- SAR := max(EP, high)+ SAR := math.max(EP, high) EP := low⋯ uptrend := true- SAR := min(EP, low)+ SAR := math.min(EP, low) EP := high⋯ EP := high- AF := min(AF + increment, maximum)+ AF := math.min(AF + increment, maximum) else⋯ EP := low- AF := min(AF + increment, maximum)+ AF := math.min(AF + increment, maximum) if uptrend- SAR := min(SAR, low[1])+ SAR := math.min(SAR, low[1]) if bar_index > 1- SAR := min(SAR, low[2])+ SAR := math.min(SAR, low[2]) else- SAR := max(SAR, high[1])+ SAR := math.max(SAR, high[1]) if bar_index > 1- SAR := max(SAR, high[2])+ SAR := math.max(SAR, high[2]) nextBarSAR := SAR + AF * (EP - SAR)⋯Same 21 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.source()
- Line 20: input() → input.float()
- Line 21: input() → input.float()
- Line 22: input() → input.float()
- Line 82: input() → input.float()
3 more edits
- Line 83: input() → input.float()
- Line 84: input() → input.float()
- Line 85: input() → input.float()
⋯strategy(title = "Crypto Scalper", overlay = true, pyramiding=1,initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)-len = input(60, minval=1, title="Length EMA")+len = input.int(60, minval=1, title="Length EMA")-src = input(close, title="Source")+src = input.source(close, title="Source")out = ta.ema(src, len)⋯hist = macd - signal-start = input(0.02)+start = input.float(0.02)-increment = input(0.02)+increment = input.float(0.02)-maximum = input(0.2)+maximum = input.float(0.2)var bool uptrend = na⋯ nextBarSAR := SAR + AF * (EP - SAR)-tplong=input(0.245, step=0.005)+tplong=input.float(0.245, step=0.005)-sllong=input(1.0, step=0.005)+sllong=input.float(1.0, step=0.005)-tpshort=input(0.055, step=0.005)+tpshort=input.float(0.055, step=0.005)-slshort=input(0.03, step=0.005)+slshort=input.float(0.03, step=0.005)if (uptrend and hist >0 and close < out)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L23:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © exlux99-//@version=5+//@version=6strategy(title = "Crypto Scalper", overlay = true, pyramiding=1,initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)⋯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 |
|---|---|---|---|
| Length EMA | 60 | int · min 1 | out |
| Source | close | source | out fast_ma slow_ma |
| Fast Length MACD | 12 | int (written input.integer) | fast_ma |
| Slow Length MACD | 26 | int (written input.integer) | slow_ma |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signal |
| Oscillator MA Type MACD | EMA | string · options ["SMA", "EMA"] | fast_ma slow_ma |
| Signal Line MA Type MACD | EMA | string · options ["SMA", "EMA"] | signal |
| Start (no label in the script) | 0.02 | float | SAR AF |
| Increment (no label in the script) | 0.02 | float | AF |
| Maximum (no label in the script) | 0.2 | float | AF |
| Tplong (no label in the script) | 0.245 | float · step 0.005 | exit short_tp/sl |
| Sllong (no label in the script) | 1.0 | float · step 0.005 | exit short_tp/sl |
| Tpshort (no label in the script) | 0.055 | float · step 0.005 | exit short_tp/sl |
| Slshort (no label in the script) | 0.03 | float · step 0.005 | exit short_tp/sl |
What it calculates
- EMA (
ema,ta.emain v5)Source (close), Length EMA (60)out · line 7 - SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length MACD (12) · chosen by Oscillator MA Type MACDfast_ma · line 15 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length MACD (26) · chosen by Oscillator MA Type MACDslow_ma · line 16 - SMA / EMA (
sma,ta.smain v5)macd, Signal Smoothing (9) · chosen by Signal Line MA Type MACDsignal · line 18
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 short short | (uptrend and hist >0 and close < out) | On | 87 |
| Exit short_tp/sl stop and limit | (uptrend and hist >0 and close < out) | On | 88 |
| Open long long | (not uptrend and hist <0 and close > out) | On | 90 |
| Exit short_tp/sl stop and limit | (not uptrend and hist <0 and close > out) | On | 91 |
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 | −29.4% | +102.5% | 21 | 29% | 0.58 | 34.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.8% | +5.5% | 14 | 43% | 1.04 | 9.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +10.0% | +9.8% | 24 | 46% | 1.08 | 48.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +47.3% | +8.4% | 12 | 50% | 3.55 | 8.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −21.5% | +16.7% | 24 | 38% | 0.79 | 61.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −5.2% | +21.5% | 18 | 33% | 0.88 | 26.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +127.5% | +148.3% | 19 | 53% | 2.81 | 30.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −3.5% | +17.1% | 15 | 27% | 0.90 | 18.8% | 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 | 3 | 33% | −$9.05 |
| Sideways market | 8 | 50% | −$2.01 |
| Falling market | 10 | 10% | −$18.28 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
49.8%
The 95th percentile of the worst drawdown when the same 21 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 30.5% to 49.8%; the tick is what actually happened, 29.3%. Order luck alone moves it this much.
All 21 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 8 Apr 2024 70,308.40 | 8 May 2024 62,312.10 | 30 | −$11.43 |
| long | 4 Jun 2024 70,450.20 | 4 Jul 2024 58,040.30 | 30 | −$15.65 |
| short | 4 Jul 2024 58,040.30 | 15 Jul 2024 60,797.90 | 11 | −$0.75 |
| short | 30 Aug 2024 58,431.20 | 6 Sep 2024 55,166.40 | 7 | $3.99 |
| long | 7 Oct 2024 64,109.40 | 10 Nov 2024 81,105.50 | 34 | $20.13 |
| long | 29 Nov 2024 98,450.40 | 23 Feb 2025 95,553.90 | 86 | −$2.89 |
| short | 24 Feb 2025 92,313.60 | 25 Feb 2025 87,019.40 | 1 | $5.30 |
| short | 9 Mar 2025 80,169.70 | 10 Mar 2025 82,773.70 | 1 | −$3.27 |
| short | 3 Apr 2025 81,241.30 | 3 Apr 2025 83,716.80 | 0 | −$2.97 |
| long | 8 Jun 2025 106,077.00 | 8 Sep 2025 112,190.00 | 92 | $5.27 |
| short | 25 Sep 2025 109,192.00 | 29 Sep 2025 112,539.00 | 4 | −$3.05 |
| short | 1 Dec 2025 84,300.60 | 2 Dec 2025 87,011.40 | 1 | −$3.10 |
| short | 15 Dec 2025 87,084.40 | 17 Dec 2025 89,729.60 | 2 | −$2.84 |
| short | 20 Jan 2026 88,817.10 | 29 Jan 2026 83,795.80 | 9 | $4.96 |
| short | 24 Feb 2026 63,389.40 | 25 Feb 2026 65,329.10 | 1 | −$2.92 |
| short | 22 Mar 2026 68,214.10 | 23 Mar 2026 70,281.70 | 1 | −$2.81 |
| long | 26 May 2026 77,466.10 | 2 Jun 2026 67,905.30 | 7 | −$10.91 |
| short | 2 Jun 2026 67,905.30 | 14 Jun 2026 64,360.10 | 12 | $0.56 |
| short | 19 Jun 2026 62,663.30 | 21 Jun 2026 64,552.10 | 2 | −$2.39 |
| short | 17 Jul 2026 62,671.50 | 18 Jul 2026 64,586.40 | 1 | −$2.34 |
| short | 28 Jul 2026 63,548.50 | 19 Aug 2026 65,467.60 | 22 | −$2.25 |
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 |
|---|---|---|---|---|---|
| Crypto Scalper Divergence Macd Psar Ema 200 this page | — | v4 strategy | −29.4% | 21 | 34.8% |
| 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 28 ms | Yes 1,000 bars in 49 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/// © exlux99//@version=4strategy(title = "Crypto Scalper", overlay = true, pyramiding=1,initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)len = input(60, minval=1, title="Length EMA")src = input(close, title="Source")out = ema(src, len)//fast_length = input(title="Fast Length MACD", type=input.integer, defval=12)slow_length = input(title="Slow Length MACD", type=input.integer, defval=26)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)sma_source = input(title="Oscillator MA Type MACD", type=input.string, defval="EMA", options=["SMA", "EMA"])sma_signal = input(title="Signal Line MA Type MACD", type=input.string, defval="EMA", options=["SMA", "EMA"])// Calculatingfast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length)slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signalstart = input(0.02)increment = input(0.02)maximum = input(0.2)var bool uptrend = navar float EP = navar float SAR = navar float AF = startvar float nextBarSAR = naif bar_index > 0 firstTrendBar = false SAR := nextBarSAR if bar_index == 1 float prevSAR = na float prevEP = na lowPrev = low[1] highPrev = high[1] closeCur = close closePrev = close[1] if closeCur > closePrev uptrend := true EP := high prevSAR := lowPrev prevEP := high else uptrend := false EP := low prevSAR := highPrev prevEP := low firstTrendBar := true SAR := prevSAR + start * (prevEP - prevSAR) if uptrend if SAR > low firstTrendBar := true uptrend := false SAR := max(EP, high) EP := low AF := start else if SAR < high firstTrendBar := true uptrend := true SAR := min(EP, low) EP := high AF := start if not firstTrendBar if uptrend if high > EP EP := high AF := min(AF + increment, maximum) else if low < EP EP := low AF := min(AF + increment, maximum) if uptrend SAR := min(SAR, low[1]) if bar_index > 1 SAR := min(SAR, low[2]) else SAR := max(SAR, high[1]) if bar_index > 1 SAR := max(SAR, high[2]) nextBarSAR := SAR + AF * (EP - SAR)tplong=input(0.245, step=0.005)sllong=input(1.0, step=0.005)tpshort=input(0.055, step=0.005)slshort=input(0.03, step=0.005)if (uptrend and hist >0 and close < out) strategy.entry("short", strategy.short, stop=nextBarSAR, comment="short") strategy.exit("short_tp/sl", "short", profit=close * tpshort / syminfo.mintick, loss=close * slshort / syminfo.mintick, comment='SHORT EXIT', alert_message = 'closeshort')if (not uptrend and hist <0 and close > out) strategy.entry("long", strategy.long, stop=nextBarSAR, comment="long") strategy.exit("short_tp/sl", "long", profit=close * tplong / syminfo.mintick, loss=close * sllong / syminfo.mintick, comment='LONG EXIT', alert_message = 'closelong')