Pine Script v5 · Strategy
Trend Identifier Strategy
A Pine Script v5 strategy built on ALMA (close, 140), EMA or Stoch (3) and EMA (dema-dema[1], 5). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.03% commission. 7 settings; defaults include start year 2020, start month 1 and start day 1.
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 Trend Identifier Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did Trend Identifier Strategy do on BTCUSDT 1D with default settings?
- +61.96%
- From 26 Jan 2024 to 21 Oct 2026, over 24 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Trend Identifier Strategy 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: 24 before, 33 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Trend Identifier Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Trend Identifier Strategy run in Zeal Terminal?
- Yes
- It compiles in 33 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +61.96%
- $619.62
- Buy and hold
- +102.5%
- same period
- Closed trades
- 24
- 8 won · 16 lost
- Profitable
- 33.3%
- of closed trades
- Profit factor
- 2.22
- gross profit ÷ gross loss
- Max drawdown
- 20.37%
- −$283.23
One run with the author's default settings, $1,000 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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 |
|---|---|---|---|
| start year | 2020 | int | timeStart |
| start month | 1 | int | timeStart |
| start day | 1 | int | timeStart |
| end year | 2025 | int | timeEnd |
| end month | 1 | int | timeEnd |
| end day | 1 | int | timeEnd |
| Choose Time Interval | false | bool | condTime |
What it calculates
- ALMAclose, 140, 1.1, 6
ema · line 22 - EMA / Stochta.ema(ta.stoch(dema,dema,dema,100),3), 3
stodema · line 24 - EMAdema-dema[1], 5
d2ema · line 25 - EMA / Stochta.ema(ta.stoch(d2ema,d2ema,d2ema,100),3), 3
stod2ema · line 26 - EMAclose, 120*24/tfc
ind · line 27 - EMA / Stochta.stoch(ind,ind,ind,120*24/tfc), 3
heat · line 28 - EMAheat, 7*24/tfc
index · line 29 - EMAdema, 21
demaema · line 36
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 buy long | (condTime and cond1a and ( ( ((tcolor[1] == red and demaema<0.02) or (tcolor[1] == blue and demaema < 0.02) or (tcolor[1] == yellow and demaema>-0.02) ) and tcolor == green) or (tcolor[1] == red and tcolor == blue and demaema < -0.01) ) and index<85 and ind<0.4) | On | 42 |
| order sell short | (condTime and cond1b and ( (((tcolor[1] == yellow and demaema > -0.02) or (tcolor[1] == blue and demaema < 0.02) or (tcolor[1] == green and demaema < 0.02)) and tcolor == red) or (tcolor[1] == green and tcolor == yellow and demaema > 0.015) ) and index>15 and ind>-0.1) | On | 45 |
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 | +62.0% | +102.5% | 24 | 33% | 2.22 | 20.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +102.7% | +9.8% | 10 | 40% | 2.13 | 48.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −42.4% | +16.7% | 21 | 38% | 0.64 | 62.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +45.3% | +148.3% | 21 | 33% | 1.93 | 22.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 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 | 7 | 29% | −$85.04 |
| Sideways market | 13 | 31% | $318.80 |
| Falling market | 4 | 50% | $386.34 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
28.9%
The 95th percentile of the worst drawdown when the same 24 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 13.2% to 28.9%; the tick is what actually happened, 17.9%. Order luck alone moves it this much.
All 24 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Jul 2024 64,724.10 | 3 Aug 2024 61,498.30 | 18 | −$50.42 |
| long | 24 Aug 2024 64,037.20 | 28 Aug 2024 59,415.00 | 4 | −$69.09 |
| long | 14 Sep 2024 60,498.00 | 17 Sep 2024 58,214.00 | 3 | −$33.76 |
| long | 18 Sep 2024 60,314.00 | 3 Oct 2024 60,649.30 | 15 | $4.20 |
| long | 7 Oct 2024 62,819.90 | 10 Oct 2024 60,636.00 | 3 | −$30.08 |
| long | 12 Oct 2024 62,540.00 | 23 Dec 2024 95,186.30 | 72 | $427.86 |
| long | 25 Dec 2024 98,663.60 | 27 Dec 2024 95,791.60 | 2 | −$37.09 |
| long | 4 Jan 2025 98,174.20 | 8 Jan 2025 96,954.60 | 4 | −$15.77 |
| long | 16 Jan 2025 100,497.00 | 3 Feb 2025 97,700.60 | 18 | −$33.99 |
| long | 4 Feb 2025 101,329.00 | 5 Feb 2025 97,763.10 | 1 | −$41.57 |
| long | 13 Apr 2025 85,276.90 | 6 Jun 2025 101,509.00 | 54 | $212.50 |
| long | 8 Jun 2025 105,552.00 | 18 Jun 2025 104,551.00 | 10 | −$13.44 |
| long | 24 Jun 2025 105,334.00 | 2 Jul 2025 105,681.00 | 8 | $3.56 |
| long | 3 Jul 2025 108,850.00 | 2 Aug 2025 113,298.00 | 30 | $53.25 |
| long | 7 Aug 2025 114,992.00 | 19 Aug 2025 116,227.00 | 12 | $13.95 |
| long | 23 Aug 2025 116,936.00 | 25 Aug 2025 113,494.00 | 2 | −$41.74 |
| long | 11 Sep 2025 113,960.00 | 23 Sep 2025 112,651.00 | 12 | −$16.29 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$18.71 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 110,021.00 | 3 | −$52.80 |
| long | 3 Jan 2026 89,995.10 | 21 Jan 2026 88,427.70 | 18 | −$22.71 |
| long | 5 Mar 2026 72,666.80 | 19 May 2026 77,001.90 | 75 | $73.08 |
| long | 11 Jul 2026 64,161.70 | 1 Aug 2026 62,887.90 | 21 | −$26.81 |
| long | 5 Aug 2026 64,106.60 | 11 Aug 2026 63,970.00 | 6 | −$3.50 |
| long | 18 Aug 2026 64,532.10 | 15 Oct 2026 81,682.00 | 58 | $339.47 |
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 |
|---|---|---|---|---|---|
| Trend Identifier Strategy this page | — | v5 strategy | +62.0% | 24 | 20.4% |
| Full Crypto Swing Strategy ALMA Cross with MACD by exlux99 | alma ema | v4 strategy | No trades on this market | ||
| Arnaud Legoux Moving Average Cross (ALMA) by Sarahann999 | alma ema | v5 strategy | +0.2% | 9 | 0.9% |
| Bitcoin Scalping Strategy (Sampled with- PMARP+MADRID MA RIBBON) by CheatCode1 | ema stoch | v5 strategy | −3.0% | 72 | 45.4% |
| Stochastic Moving Average by LucasVivien | stoch ema | v5 strategy | +2.8% | 7 | 4.4% |
| OTT-Stoch-TP-SL by BigCoinHunter | ema stoch | v5 strategy | No trades on this market | ||
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.
- 1 setting uses the untyped input() (line 15). 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 24 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 15: input() → input.bool()
⋯timeStart = time >= timestamp(syminfo.timezone,startyear,startmonth,startday,0,0)-choosetime = input(false,"Choose Time Interval")+choosetime = input.bool(false,"Choose Time Interval")condTime = (choosetime ? (timeStart and timeEnd) : true)⋯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: 24 before, 33 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.
⋯// -//@version=5+//@version=6strategy(title="Trend Identifier Strategy", shorttitle="Trend Identifier Strategy", format=format.price, precision=4, overlay = false, initial_capital = 1000, pyramiding = 10, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.03)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | With a workaround 1,000 bars in 46 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © spacekadet17// //@version=5strategy(title="Trend Identifier Strategy", shorttitle="Trend Identifier Strategy", format=format.price, precision=4, overlay = false, initial_capital = 1000, pyramiding = 10, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.03)//start-end timestartyear = input.int(2020,"start year")startmonth = input.int(1,"start month")startday = input.int(1,"start day")endyear = input.int(2025,"end year")endmonth = input.int(1,"end month")endday = input.int(1,"end day")timeEnd = time <= timestamp(syminfo.timezone,endyear,endmonth,endday,0,0)timeStart = time >= timestamp(syminfo.timezone,startyear,startmonth,startday,0,0)choosetime = input(false,"Choose Time Interval")condTime = (choosetime ? (timeStart and timeEnd) : true)// time frame?tfc = 1if timeframe.isdaily tfc := 24// indicators: price normalized alma, and its 1st and 2nd derivativesema = ta.alma(close,140,1.1,6)dema = (ema-ema[1])/emastodema = ta.ema(ta.ema(ta.stoch(dema,dema,dema,100),3),3)d2ema = ta.ema(dema-dema[1],5)stod2ema = ta.ema(ta.ema(ta.stoch(d2ema,d2ema,d2ema,100),3),3)ind = (close-ta.ema(close,120*24/tfc))/closeheat = ta.ema(ta.stoch(ind,ind,ind,120*24/tfc),3)index = ta.ema(heat,7*24/tfc)//plot graphgreen = color.rgb(20,255,100)yellow = color.yellowred = color.redblue = color.rgb(20,120,255)tcolor = (dema>0) and (d2ema>0)? green : (dema>0) and (d2ema<0) ? yellow : (dema < 0) and (d2ema<0) ? red : (dema < 0) and (d2ema>0) ? blue : color.blackdemaema = ta.ema(dema,21)plot(demaema, color = tcolor)//strategy buy-sell conditionscond1a = strategy.position_size <= 0cond1b = strategy.position_size > 0if (condTime and cond1a and ( ( ((tcolor[1] == red and demaema<0.02) or (tcolor[1] == blue and demaema < 0.02) or (tcolor[1] == yellow and demaema>-0.02) ) and tcolor == green) or (tcolor[1] == red and tcolor == blue and demaema < -0.01) ) and index<85 and ind<0.4) strategy.entry("buy",strategy.long, (strategy.equity-strategy.position_size*close)/1/close) if (condTime and cond1b and ( (((tcolor[1] == yellow and demaema > -0.02) or (tcolor[1] == blue and demaema < 0.02) or (tcolor[1] == green and demaema < 0.02)) and tcolor == red) or (tcolor[1] == green and tcolor == yellow and demaema > 0.015) ) and index>15 and ind>-0.1) strategy.order("sell",strategy.short, strategy.position_size)