Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (14)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$74$203Equity from $100
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.
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

Verified

Same 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)⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Length EMA60int · min 1out
Sourceclosesourceout fast_ma slow_ma
Fast Length MACD12int (written input.integer)fast_ma
Slow Length MACD26int (written input.integer)slow_ma
Signal Smoothing9int (written input.integer) · min 1 · max 50signal
Oscillator MA Type MACDEMAstring · options ["SMA", "EMA"]fast_ma slow_ma
Signal Line MA Type MACDEMAstring · options ["SMA", "EMA"]signal
Start (no label in the script)0.02floatSAR AF
Increment (no label in the script)0.02floatAF
Maximum (no label in the script)0.2floatAF
Tplong (no label in the script)0.245float · step 0.005exit short_tp/sl
Sllong (no label in the script)1.0float · step 0.005exit short_tp/sl
Tpshort (no label in the script)0.055float · step 0.005exit short_tp/sl
Slshort (no label in the script)0.03float · step 0.005exit short_tp/sl

What it calculates

  • EMA (ema, ta.ema in v5)Source (close), Length EMA (60)out · line 7
  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length MACD (12) · chosen by Oscillator MA Type MACDfast_ma · line 15
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length MACD (26) · chosen by Oscillator MA Type MACDslow_ma · line 16
  • SMA / EMA (sma, ta.sma in 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.

closecloseprice datalenLength EMAsetting · 60sma_sourceOscillator MA Type MACDsetting · EMAfast_lengthFast Length MACDsetting · 12slow_lengthSlow Length MACDsetting · 26sma_signalSignal Line MA Type MACDsetting · EMAsignal_lengthSignal Smoothingsetting · 9lowlowprice datahighhighprice datastartStartsetting · 0.02incrementIncrementsetting · 0.02maximumMaximumsetting · 0.2outEMA→ outfast_maSMA / EMA→ fast_ma · by Oscillator MA …slow_maSMA / EMA→ slow_ma · by Oscillator MA …signalSMA / EMA→ signal · by Signal Line MA …macdmacdvaluehisthistvalueEP, prevEPEP · prevEP2 valuesSARSARvalueAFAFvaluenextBarSARnextBarSARvalueprevSARprevSARvaluelowPrevlowPrevvaluehighPrevhighPrevvaluecloseCur, closePrevcloseCur · closePrev2 valuesentry:shortOpen shortstrategy.entryexit:short_tp/slexit short_tp/slstrategy.exitentry:longOpen longstrategy.entry

Order rules

OrderFires whenBy defaultLine
Open short short(uptrend and hist >0 and close < out)On87
Exit short_tp/sl stop and limit(uptrend and hist >0 and close < out)On88
Open long long(not uptrend and hist <0 and close > out)On90
Exit short_tp/sl stop and limit(not uptrend and hist <0 and close > out)On91

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.

8/8trades 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−29.4%+102.5%2129%0.5834.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.8%+5.5%1443%1.049.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+10.0%+9.8%2446%1.0848.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+47.3%+8.4%1250%3.558.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−21.5%+16.7%2438%0.7961.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−5.2%+21.5%1833%0.8826.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+127.5%+148.3%1953%2.8130.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−3.5%+17.1%1527%0.9018.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 barsTradesWonP&L
Rising market333%−$9.05
Sideways market850%−$2.01
Falling market1010%−$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.

0%57%
All 21 trades
SideEntryExitBarsP&L
long8 Apr 2024 70,308.408 May 2024 62,312.1030−$11.43
long4 Jun 2024 70,450.204 Jul 2024 58,040.3030−$15.65
short4 Jul 2024 58,040.3015 Jul 2024 60,797.9011−$0.75
short30 Aug 2024 58,431.206 Sep 2024 55,166.407$3.99
long7 Oct 2024 64,109.4010 Nov 2024 81,105.5034$20.13
long29 Nov 2024 98,450.4023 Feb 2025 95,553.9086−$2.89
short24 Feb 2025 92,313.6025 Feb 2025 87,019.401$5.30
short9 Mar 2025 80,169.7010 Mar 2025 82,773.701−$3.27
short3 Apr 2025 81,241.303 Apr 2025 83,716.800−$2.97
long8 Jun 2025 106,077.008 Sep 2025 112,190.0092$5.27
short25 Sep 2025 109,192.0029 Sep 2025 112,539.004−$3.05
short1 Dec 2025 84,300.602 Dec 2025 87,011.401−$3.10
short15 Dec 2025 87,084.4017 Dec 2025 89,729.602−$2.84
short20 Jan 2026 88,817.1029 Jan 2026 83,795.809$4.96
short24 Feb 2026 63,389.4025 Feb 2026 65,329.101−$2.92
short22 Mar 2026 68,214.1023 Mar 2026 70,281.701−$2.81
long26 May 2026 77,466.102 Jun 2026 67,905.307−$10.91
short2 Jun 2026 67,905.3014 Jun 2026 64,360.1012$0.56
short19 Jun 2026 62,663.3021 Jun 2026 64,552.102−$2.39
short17 Jul 2026 62,671.5018 Jul 2026 64,586.401−$2.34
short28 Jul 2026 63,548.5019 Aug 2026 65,467.6022−$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.

ScriptSharesTypeNetTradesMax drawdown
Crypto Scalper Divergence Macd Psar Ema 200 this page—v4 strategy−29.4%2134.8%
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 28 msYes 1,000 bars in 49 msNot measured
PineTSNo 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')