Pine Script v5 · Strategy
EMA_TREND_CATCHER
A Pine Script v5 strategy built on EMA (close, 55) and Crossunder or EMA (close,100, close,200). It has 8 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 is one contract and pays 0.05% commission. 9 settings; defaults include profit_short 27, stop_short 2 and stop_long 3.
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_TREND_CATCHER repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did EMA_TREND_CATCHER do on BTCUSDT 1D with default settings?
- +3,545.00%
- From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does EMA_TREND_CATCHER run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L44:C19: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
- Does EMA_TREND_CATCHER use a stop loss?
- Yes
- strategy.exit sets a stop on line 53, 58.
- Does EMA_TREND_CATCHER run in Zeal Terminal?
- Yes
- It compiles in 25 ms and runs 1,000 bars in 57 ms, in the browser.
BTCUSDT · 1D · default settings
- ema 12
- ema 25
- ema 30
- ema 40
- ema 55
- ema 100
- ema 200
- EMA(50)
- EMA(100)
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +3,545.00%
- $35,450.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 5
- 2 won · 3 lost
- Profitable
- 40.0%
- of closed trades
- Profit factor
- 7.37
- gross profit ÷ gross loss
- Max drawdown
- 253.82%
- −$4,339.72
One run with the author's default settings, $1,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
4 settings do nothing
“media_1”, “media_2”, “resta_medias2”, “RSI_periodos” are declared but never read.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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 |
|---|---|---|---|
| profit_short | 27 | int | exit cerrar short |
| stop_short | 2 | int | exit cerrar short |
| stop_long | 3 | int | exit cerrar long |
| profit_long | 35 | int | exit cerrar long |
| media_1 | 55 | int | unused |
| media_2 | 100 | int | unused |
| resta_medias | 0 | int | col |
| resta_medias2 | 0 | int | unused |
| RSI_periodos | 42 | int | unused |
What it calculates
- EMAclose, 55
EMA50 · line 37 - EMAclose, 100
EMA100 · line 38 - Crossunder / EMAta.ema(close,100), ta.ema(close,200)
Go_Short · line 46 - Crossunder / EMAta.ema(close,25), ta.ema(close,6)
cancelar_short · line 49 - Crossunder / EMAta.ema(close,12), ta.ema(close,30)
cancelar · line 55
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 |
|---|---|---|---|
| Close enter long | every bar | On | 48 |
| Open enter short short | Go_Short | On | 51 |
| Exit cerrar short stop and limit | every bar | On | 53 |
| Close enter short | every bar | On | 54 |
| Open enter long long | Go_Long | On | 57 |
| Exit cerrar long stop and limit | every bar | On | 58 |
| Close enter short | every bar | On | 59 |
| Close enter long | every bar | On | 60 |
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 | +3,545.0% | +102.5% | 5 | 40% | 7.37 | 253.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1,286.5% | +5.5% | 4 | 50% | 13.56 | 186.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +13.6% | +9.8% | 5 | 20% | 1.49 | 19.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −6.3% | +8.4% | 2 | 0% | 0.00 | 10.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −2.5% | +16.7% | 6 | 0% | 0.00 | 2.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.9% | +21.5% | 5 | 0% | 0.00 | 0.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −10.5% | +148.3% | 6 | 0% | 0.00 | 10.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −3.3% | +17.1% | 2 | 0% | 0.00 | 3.3% | 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 | 0 | — | $0.00 |
| Sideways market | 3 | 67% | $38,588.50 |
| Falling market | 2 | 0% | −$3,138.57 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
17,673.2%
The 95th percentile of the worst drawdown when the same 5 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 120.7% to 17,673.2%; the tick is what actually happened, 122.1%. Order luck alone moves it this much.
All 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 5 Sep 2024 57,970.90 | 13 Sep 2024 59,133.60 | 8 | −$1,221.20 |
| long | 15 Oct 2024 66,084.00 | 5 Dec 2024 100,590.00 | 51 | $34,422.20 |
| long | 5 May 2025 94,277.60 | 23 Jun 2025 100,964.00 | 49 | $6,588.64 |
| short | 29 Nov 2025 90,890.70 | 3 Dec 2025 92,716.30 | 4 | −$1,917.36 |
| long | 29 Aug 2026 77,845.90 | 15 Sep 2026 75,500.20 | 17 | −$2,422.35 |
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 |
|---|---|---|---|---|---|
| EMA_TREND_CATCHER this page | — | v5 strategy | +3,545.0% | 5 | 253.8% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 9 settings use the untyped input() (line 6, 7, 8, 9, 10, 11, 12, 13, 14). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
3 more edits
- Line 12: input() → input.int()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
⋯//#####variables##############-profit_short=input(title='profit_short', defval=27)+profit_short=input.int(title='profit_short', defval=27)-stop_short=input(title='stop_short', defval=2)+stop_short=input.int(title='stop_short', defval=2)-stop_long=input(title='stop_long', defval=3)+stop_long=input.int(title='stop_long', defval=3)-profit_long=input(title='profit_long', defval=35)+profit_long=input.int(title='profit_long', defval=35)-media_1=input(title='media_1', defval=55)+media_1=input.int(title='media_1', defval=55)-media_2=input(title='media_2', defval=100)+media_2=input.int(title='media_2', defval=100)-resta_medias=input(title='resta_medias', defval=0)+resta_medias=input.int(title='resta_medias', defval=0)-resta_medias2=input(title='resta_medias2', defval=0)+resta_medias2=input.int(title='resta_medias2', defval=0)-RSI_periodos=input(title='RSI_periodos', defval=42)+RSI_periodos=input.int(title='RSI_periodos', defval=42)//###############VARIABLES###################⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L44:C19: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © pernath-//@version=5+//@version=6strategy("TREND_CATCHER", overlay=true, commission_value=0.05, commission_type=strategy.commission.percent, initial_capital=1000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 25 ms | Yes 1,000 bars in 57 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © pernath//@version=5strategy("TREND_CATCHER", overlay=true, commission_value=0.05, commission_type=strategy.commission.percent, initial_capital=1000)//#####variables##############profit_short=input(title='profit_short', defval=27)stop_short=input(title='stop_short', defval=2)stop_long=input(title='stop_long', defval=3)profit_long=input(title='profit_long', defval=35)media_1=input(title='media_1', defval=55)media_2=input(title='media_2', defval=100)resta_medias=input(title='resta_medias', defval=0)resta_medias2=input(title='resta_medias2', defval=0)RSI_periodos=input(title='RSI_periodos', defval=42)//###############VARIABLES###################//#####Alert#####id_bot = ""email_token = ""long_open =""long_close =""short_open =""short_close =""//# {{strategy.order.alert_message}}//#############################//#############################//###############EMA##############///plot(ta.ema(close, 1), title='ema 5', color=color.white)plot(ta.ema(close, 12), title='ema 12', color=color.white)plot(ta.ema(close, 25), title='ema 25', color=color.white)plot(ta.ema(close, 30), title='ema 30', color=color.white, linewidth=1)plot(ta.ema(close, 40), title='ema 40', color=color.white, linewidth=1)plot(ta.ema(close, 55), title='ema 55', color=color.orange, linewidth=1)plot(ta.ema(close, 100), title='ema 100', color=color.red, linewidth=1)plot(ta.ema(close, 200), title='ema 200', color=color.white, linewidth=3)//#############################///######VISUAL#############EMA50 = ta.ema(close, 55)EMA100 = ta.ema(close, 100)estado_medias=EMA50-EMA100a = plot(EMA50, title="EMA(50)", color=color.orange, linewidth=1 ) b = plot(EMA100, title="EMA(100)", color=color.red, linewidth=1 )var color col = nacol := estado_medias>resta_medias ? color.green : color.redfill(a,b,color=col,transp=40)//######VISUAL#############Go_Short=(ta.crossunder(ta.ema(close,100),ta.ema(close,200)))Go_Long=((ta.crossover(ta.ema(close,55),ta.ema(close,100))and(ta.ema(close,12)>ta.ema(close,200))))strategy.close("enter long", (Go_Short),alert_message=long_open)cancelar_short=((ta.crossunder(ta.ema(close,25),ta.ema(close,6))))if Go_Short strategy.entry("enter short", strategy.short,1, alert_message=short_open) strategy.exit("cerrar short", "enter short", 1, profit=close*profit_short/100/syminfo.mintick, loss=close*stop_short/100/syminfo.mintick, alert_message=short_close)strategy.close("enter short", (Go_Long),alert_message=short_close)cancelar=((ta.crossunder(ta.ema(close,12),ta.ema(close,30))))if Go_Long strategy.entry("enter long", strategy.long,1,alert_message=long_open)strategy.exit("cerrar long", "enter long", 1, profit=close*profit_long/100/syminfo.mintick, loss=close*stop_long/100/syminfo.mintick, alert_message=long_close)strategy.close("enter short", (cancelar_short),alert_message=short_close)strategy.close("enter long", (cancelar),alert_message=long_close)//posiciones abiertasbgcolor((strategy.position_size > 0 or strategy.position_size < 0) ? color.blue : na, transp=70)