Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

EMA Slope Trend Follower Strategy

A Pine Script v4 strategy built on Change (out), EMA (slp, 9) and Crossunder (emaslopeF, emaslopeS). It has 4 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 30% of equity and pays 0.06% commission. 10 settings; defaults include Source MA Type EMA, Source MA Length 130 and Fast Slope MA Length 9.

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 EMA Slope Trend Follower Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did EMA Slope Trend Follower Strategy do on BTCUSDT 1D with default settings?
+18.66%
From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can EMA Slope Trend Follower Strategy 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 EMA Slope Trend Follower Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does EMA Slope Trend Follower Strategy run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 36 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • 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 (10)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$11,865$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 70, 73) so the engine trades the way the script says.
Net profit
+18.66%
$1,865.62
Buy and hold
+102.5%
same period
Closed trades
25
8 won · 17 lost
Profitable
32.0%
of closed trades
Profit factor
1.85
gross profit ÷ gross loss
Max drawdown
7.44%
−$818.16

One run with the author's default settings, $10,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.

  • Note

    Uses long =, which v5 renamed line 70

    long = on line 70, 73. v5 writes it as direction = strategy.long or strategy.short.

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, change → ta.change, stdev → ta.stdev, crossunder → ta.crossunder, crossover → ta.crossover.

v4 → v5

Verified

Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.string) → input.string()
  • Line 12: input(type = input.string) → input.string()
  • Line 18: ema → ta.ema
  • Line 20: sma → ta.sma
  • Line 22: change → ta.change
13 more edits
  • Line 23: ema → ta.ema
  • Line 24: ema → ta.ema
  • Line 27: ema → ta.ema
  • Line 29: sma → ta.sma
  • Line 32: ema → ta.ema
  • Line 34: sma → ta.sma
  • Line 35: stdev → ta.stdev
  • Line 35: sma → ta.sma
  • Line 35: stdev → ta.stdev
  • Line 56: crossunder → ta.crossunder
  • Line 57: crossover → ta.crossover
  • Line 70: long = true → direction = strategy.long
  • Line 73: long = false → direction = strategy.short
⋯// © lukescream-//@version=4+//@version=5strategy("EMA Slope Trend Follower", initial_capital=10000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.06, slippage = 2, default_qty_value=30, overlay=false)//definizione input-average = input (title="Source MA Type", type=input.string, defval="EMA",options=["EMA","SMA"])+average = input.string (title="Source MA Type", defval="EMA",options=["EMA","SMA"])len = input(130, minval=1, title="Source MA Length")⋯trendfilterperiod=input(200,title="Trend Filter MA Period")-trendfiltertype=input (title="Trend Filter MA Type", type=input.string, defval="EMA",options=["EMA","SMA"])+trendfiltertype=input.string (title="Trend Filter MA Type", defval="EMA",options=["EMA","SMA"])volatilityfilter=input(false,title="Volatility Filter")⋯out = if average == "EMA" -    ema(close,len)+    ta.ema(close,len)else-    sma(close,len)+    ta.sma(close,len)    -slp = change(out)/out+slp = ta.change(out)/out-emaslopeF = ema(slp,slopeFlen)+emaslopeF = ta.ema(slp,slopeFlen)-emaslopeS = ema(slp,slopeSlen)+emaslopeS = ta.ema(slp,slopeSlen)//variabili accessorie e condizioniTrendConditionL=if trendfiltertype =="EMA"-    close>ema(close,trendfilterperiod)+    close>ta.ema(close,trendfilterperiod)else-    close>sma(close,trendfilterperiod)+    close>ta.sma(close,trendfilterperiod)    TrendConditionS=if trendfiltertype =="EMA"-    close<ema(close,trendfilterperiod)+    close<ta.ema(close,trendfilterperiod)else-    close<sma(close,trendfilterperiod)+    close<ta.sma(close,trendfilterperiod)-VolatilityCondition=stdev(close,volatilitystdevlength)>sma(stdev(close,volatilitystdevlength),volatilitystdevmalength)+VolatilityCondition=ta.stdev(close,volatilitystdevlength)>ta.sma(ta.stdev(close,volatilitystdevlength),volatilitystdevmalength)ConditionEntryL= if trendfilter == true⋯        emaslopeF<emaslopeS-ConditionExitL=crossunder(emaslopeF,emaslopeS)+ConditionExitL=ta.crossunder(emaslopeF,emaslopeS)-ConditionExitS=crossover(emaslopeF,emaslopeS)+ConditionExitS=ta.crossover(emaslopeF,emaslopeS)//plot⋯if ConditionEntryL-    strategy.entry("SLPLong",long=true)+    strategy.entry("SLPLong",direction = strategy.long)    if ConditionEntryS-    strategy.entry("SLPShort",long=false)+    strategy.entry("SLPShort",direction = strategy.short)

Clean v5

VerifiedDownload the v5 script

Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.bool()
  • Line 11: input() → input.int()
  • Line 13: input() → input.bool()
  • Line 14: input() → input.int()
  • Line 15: input() → input.int()
⋯average = input.string (title="Source MA Type", defval="EMA",options=["EMA","SMA"])-len = input(130, minval=1, title="Source MA Length")+len = input.int(130, minval=1, title="Source MA Length")-slopeFlen = input (9,title="Fast Slope MA Length")+slopeFlen = input.int (9,title="Fast Slope MA Length")-slopeSlen= input (21,title="Slow Slope MA Length")+slopeSlen= input.int (21,title="Slow Slope MA Length")-trendfilter=input(true,title="Trend Filter")+trendfilter=input.bool(true,title="Trend Filter")-trendfilterperiod=input(200,title="Trend Filter MA Period")+trendfilterperiod=input.int(200,title="Trend Filter MA Period")trendfiltertype=input.string (title="Trend Filter MA Type", defval="EMA",options=["EMA","SMA"])-volatilityfilter=input(false,title="Volatility Filter")+volatilityfilter=input.bool(false,title="Volatility Filter")-volatilitystdevlength=input(20,title="Vol Filter STDev Length")+volatilitystdevlength=input.int(20,title="Vol Filter STDev Length")-volatilitystdevmalength=input(30,title="Vol Filter STDev MA Length")+volatilitystdevmalength=input.int(30,title="Vol Filter STDev MA Length")//variabili⋯

Does it run in Pine Script v6?

Yes

Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © lukescream-//@version=5+//@version=6strategy("EMA Slope Trend Follower", initial_capital=10000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.06, slippage = 2, default_qty_value=30, overlay=false)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Source MA TypeEMAstring · options ["EMA","SMA"]out
Source MA Length130int · min 1out
Fast Slope MA Length9intemaslopeF
Slow Slope MA Length21intemaslopeS
Trend FiltertrueboolConditionEntryL ConditionEntryS
Trend Filter MA Period200intTrendConditionL TrendConditionS
Trend Filter MA TypeEMAstring · options ["EMA","SMA"]TrendConditionL TrendConditionS
Volatility FilterfalseboolConditionEntryL ConditionEntryS
Vol Filter STDev Length20intVolatilityCondition
Vol Filter STDev MA Length30intVolatilityCondition

What it calculates

  • Change (change, ta.change in v5)outslp · line 22
  • EMA (ema, ta.ema in v5)slp, Fast Slope MA Length (9)emaslopeF · line 23
  • EMA (ema, ta.ema in v5)slp, Slow Slope MA Length (21)emaslopeS · line 24
  • Crossunder (crossunder, ta.crossunder in v5)emaslopeF, emaslopeSConditionExitL · line 56
  • Crossover (crossover, ta.crossover in v5)emaslopeF, emaslopeSConditionExitS · line 57

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.

slopeFlenFast Slope MA Lengthsetting · 9slopeSlenSlow Slope MA Lengthsetting · 21closecloseprice dataaverageSource MA Typesetting · EMAlenSource MA Lengthsetting · 130trendfiltertypeTrend Filter MA Typesetting · EMAtrendfilterperiodTrend Filter MA Periodsetting · 200volatilitystdevlengthVol Filter STDev Lengthsetting · 20volatilitystdevmalengthVol Filter STDev MA Len…setting · 30slpChange→ slpemaslopeFEMA→ emaslopeFemaslopeSEMA→ emaslopeSConditionExitLCrossunder→ ConditionExitLConditionExitSCrossover→ ConditionExitSConditionEntryLConditionEntryLconditionConditionEntrySConditionEntrySconditionoutoutconditionTrendConditionL, TrendConditionSTrendConditionL · Trend…2 conditionsVolatilityConditionVolatilityConditionconditionclose:SLPShortClose SLPShortstrategy.closeclose:SLPLongClose SLPLongstrategy.closeentry:SLPLongOpen SLPLongstrategy.entryentry:SLPShortOpen SLPShortstrategy.entryplot:59plotplotplot:60plotplotplot:61plotplot

Order rules

OrderFires whenBy defaultLine
Close SLPShortstrategy.position_size < 0On65
Close SLPLongstrategy.position_size > 0On68
Open SLPLong longConditionEntryLOn70
Open SLPShort shortConditionEntrySOn73

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.

6/6trades 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+18.7%+102.5%2532%1.857.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1.6%+5.5%2921%0.876.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+52.3%+9.8%2050%4.506.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+2.4%+8.4%2020%1.246.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+23.7%+16.7%2442%1.8710.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+4.4%+21.5%2623%1.396.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+4.9%+148.3%2442%1.2113.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.2%+17.1%2532%0.975.4%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Fast Slope MA Length 15, Slow Slope MA Length 36) made +21.0% before 26 Dec 2025 and +11.4% after it, against +10.8% for the defaults. 82% of the 56 combinations made money in-sample and 89% out-of-sample.

Before 26 Dec 2025 · in-sample
Slow Slope MA Length ↓ · Fast Slope MA Length →5689111315
11+0%+3%−1%−2%0%−4%−6%
13+1%−0%−1%+3%+4%0%−8%
15+2%+1%+1%+2%+5%+10%0%
18+1%+5%+9%+9%+10%+10%+13%
21+5%+6%+9%+8%+9%+13%+19%
25+2%+6%+6%+10%+17%+20%+17%
29+8%+10%+13%+15%+19%+17%+18%
36+13%+13%+12%+20%+18%+19%+21%
From 26 Dec 2025 · out-of-sample
Slow Slope MA Length ↓ · Fast Slope MA Length →5689111315
11+8%+9%+9%+10%0%−8%−7%
13+9%+10%+11%+13%+12%0%−6%
15+11%+11%+13%+12%+12%+11%0%
18+12%+12%+12%+12%+11%+13%+12%
21+13%+12%+11%+11%+13%+11%+12%
25+11%+11%+12%+11%+14%+14%+15%
29+12%+11%+13%+13%+14%+14%+12%
36+13%+11%+12%+14%+12%+11%+11%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market743%$278.95
Sideways market1527%$1,073.48
Falling market333%$513.19

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

13.1%

The 95th percentile of the worst drawdown when the same 25 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 5.6% to 13.1%; the tick is what actually happened, 6.8%. Order luck alone moves it this much.

0%15%
All 25 trades
SideEntryExitBarsP&L
short13 Aug 2024 59,346.6024 Aug 2024 64,037.3011−$240.71
long24 Aug 2024 64,037.3031 Aug 2024 59,124.007−$227.92
short31 Aug 2024 59,124.0015 Sep 2024 59,993.0015−$45.47
long19 Sep 2024 61,760.0010 Oct 2024 60,636.0021−$55.14
short10 Oct 2024 60,636.0014 Oct 2024 62,870.004−$107.65
long14 Oct 2024 62,870.0011 Dec 2024 96,593.0058$1,495.38
long16 Dec 2024 104,464.0019 Dec 2024 100,204.003−$136.09
long19 Jan 2025 104,556.0029 Jan 2025 101,336.0010−$102.44
short27 Feb 2025 84,250.1026 Mar 2025 87,392.9027−$122.21
long26 Mar 2025 87,392.9030 Mar 2025 82,648.504−$173.91
short30 Mar 2025 82,648.5014 Apr 2025 83,760.0015−$45.20
long22 Apr 2025 87,516.201 Jun 2025 104,592.0040$594.91
long7 Jul 2025 109,204.008 Jul 2025 108,263.001−$31.87
long10 Jul 2025 111,234.0031 Jul 2025 117,840.0021$188.34
long14 Aug 2025 123,306.0015 Aug 2025 118,295.001−$137.79
long13 Sep 2025 116,029.0024 Sep 2025 111,999.0011−$116.86
long3 Oct 2025 120,529.0012 Oct 2025 110,644.009−$267.68
short18 Oct 2025 106,432.0010 Dec 2025 92,678.8053$402.02
short16 Dec 2025 86,432.1023 Dec 2025 88,620.807−$86.49
short26 Jan 2026 86,670.304 Mar 2026 68,338.0037$680.37
short31 Mar 2026 66,797.401 Apr 2026 68,284.501−$80.69
long11 May 2026 82,210.1020 May 2026 76,834.309−$227.13
short20 May 2026 76,834.306 Jul 2026 63,650.0047$570.36
long21 Aug 2026 73,027.0016 Sep 2026 75,644.5026$121.72
long20 Sep 2026 81,250.009 Oct 2026 81,754.4019$17.78

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
EMA Slope Trend Follower Strategy this page—v4 strategy+18.7%257.4%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,274.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msWith a workaround 1,000 bars in 36 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 70, 73) 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/// © lukescream//@version=4strategy("EMA Slope Trend Follower", initial_capital=10000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.06, slippage = 2, default_qty_value=30, overlay=false)//definizione inputaverage = input (title="Source MA Type", type=input.string, defval="EMA",options=["EMA","SMA"])len = input(130, minval=1, title="Source MA Length")slopeFlen = input (9,title="Fast Slope MA Length")slopeSlen= input (21,title="Slow Slope MA Length")trendfilter=input(true,title="Trend Filter")trendfilterperiod=input(200,title="Trend Filter MA Period")trendfiltertype=input (title="Trend Filter MA Type", type=input.string, defval="EMA",options=["EMA","SMA"])volatilityfilter=input(false,title="Volatility Filter")volatilitystdevlength=input(20,title="Vol Filter STDev Length")volatilitystdevmalength=input(30,title="Vol Filter STDev MA Length")//variabiliout = if average == "EMA"     ema(close,len)else    sma(close,len)    slp = change(out)/outemaslopeF = ema(slp,slopeFlen)emaslopeS = ema(slp,slopeSlen)//variabili accessorie e condizioniTrendConditionL=if trendfiltertype =="EMA"    close>ema(close,trendfilterperiod)else    close>sma(close,trendfilterperiod)    TrendConditionS=if trendfiltertype =="EMA"    close<ema(close,trendfilterperiod)else    close<sma(close,trendfilterperiod)VolatilityCondition=stdev(close,volatilitystdevlength)>sma(stdev(close,volatilitystdevlength),volatilitystdevmalength)ConditionEntryL= if trendfilter == true    if volatilityfilter == true        emaslopeF>emaslopeS and TrendConditionL and VolatilityCondition    else        emaslopeF>emaslopeS and TrendConditionLelse    if volatilityfilter == true        emaslopeF>emaslopeS and VolatilityCondition    else         emaslopeF>emaslopeSConditionEntryS= if trendfilter == true    if volatilityfilter == true        emaslopeF<emaslopeS and TrendConditionS and VolatilityCondition    else         emaslopeF<emaslopeS and TrendConditionSelse    if volatilityfilter == true        emaslopeF<emaslopeS and VolatilityCondition    else        emaslopeF<emaslopeSConditionExitL=crossunder(emaslopeF,emaslopeS)ConditionExitS=crossover(emaslopeF,emaslopeS)//plotplot (slp, color=color.white)plot (emaslopeF,color=color.yellow)plot (emaslopeS,color=color.red)//ingressi e usciteif ConditionExitS    if strategy.position_size < 0        strategy.close("SLPShort")if ConditionExitL    if strategy.position_size > 0        strategy.close("SLPLong")if ConditionEntryL    strategy.entry("SLPLong",long=true)    if ConditionEntryS    strategy.entry("SLPShort",long=false)