Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Classic Long Term Trend Following System

A Pine Script v5 strategy built on EMA (close, 50), Highest (high[1], 50) and Lowest (low[1], 50). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 19 settings; defaults include Length Fast EMA 50, Length Slow EMA 150 and Source Fast MA close.

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 Classic Long Term Trend Following System 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 Classic Long Term Trend Following System do on BTCUSDT 1D with default settings?
+2.92%
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 Classic Long Term Trend Following System 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: 5 before, 5 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 Classic Long Term Trend Following System use a stop loss?
Yes
strategy.exit sets a stop on line 69, 75.
Does Classic Long Term Trend Following System run in Zeal Terminal?
Yes
It compiles in 23 ms and runs 1,000 bars in 64 ms, in the browser.

BTCUSDT · 1D · default settings

  • Fast EMA
  • Slow EMA
  • Upper
  • Lower
  • ATR Trailing Stop
  • 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)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,027,260$2,025,273Equity from $1,000,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.
Net profit
+2.92%
$29,164.40
Buy and hold
+102.5%
same period
Closed trades
5
3 won · 2 lost
Profitable
60.0%
of closed trades
Profit factor
4.38
gross profit ÷ gross loss
Max drawdown
1.15%
−$11,846.90

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

    3 settings do nothing

    “Backtest Start Date”, “Backtest End Date”, “ Color Lower Channel” are declared but never read.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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.

SettingDefaultType and rangeFeeds
backtest window
Backtest Start Datetimestamp("01 Jan 2017 00:00 +0000")timeunused
Backtest End Datetimestamp("01 Jan 2100 00:00 +0000")timeunused
Moving Average Inputs
Length Fast EMA50int · min 1fast
Length Slow EMA150int · min 1slow
Color Fast EMAcolor.new(color.red, 0)colorFast EMA
Color Slow EMAcolor.new(color.blue, 0)colorSlow EMA
Source Fast MAclosesourcefast
Source Slow MAclosesourceslow
Donchian Channels Inputs
Length Upper Channel50int · min 1h1
Length Lower Channel50int · min 1l1
Fill Colorcolor.new(color.purple, 95)colorfill
Color Upper Channelcolor.new(color.orange, 0)colorUpper Lower
Color Lower Channelcolor.new(color.orange, 0)colorunused
ATR Position Size Inputs
Leverage Used1int · min 1amount
Point Value/ATR Multipliers from Entry4int · min 1amount
ATR Period14int · min 1atr
Risk Per Trade0.01floatamount
ATR Trailing Stop Inputs
ATR Period14intxATR
ATR Multiplier4float · step .1Stop stoploss

What it calculates

  • EMASource Fast MA (close), Length Fast EMA (50)fast · line 15
  • EMASource Slow MA (close), Length Slow EMA (150)slow · line 16
  • Highesthigh[1], Length Upper Channel (50)h1 · line 22
  • Lowestlow[1], Length Lower Channel (50)l1 · line 23
  • ATRATR Period (14)atr · line 35
  • ATRATR Period (14)xATR · line 40
  • Crossoverfast, slowentrycondition1 · line 61
  • Crossunderfast, slowsellcondition1 · line 63

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 datalen1Length Fast EMAsetting · 50len2Length Slow EMAsetting · 150highhighprice dataLength1Length Upper Channelsetting · 50lowlowprice dataLength2Length Lower Channelsetting · 50high · low · closehigh · low · closeprice datalengthATR Periodsetting · 14xATRPeriodATR Periodsetting · 14riskRisk Per Tradesetting · 0.01pointvaluePoint Value/ATR Multipl…setting · 4leverageLeverage Usedsetting · 1xATRMultiplierATR Multipliersetting · 4fastEMA→ fastslowEMA→ slowh1Highest→ h1l1Lowest→ l1atrATR→ atrxATRATR→ xATRentrycondition1Crossover→ entrycondition1sellcondition1Crossunder→ sellcondition1amountamountvalueStopStopvaluestoplossstoplossvalueentrycondition2entrycondition2conditionsellcondition2sellcondition2conditionxATRTrailingStopxATRTrailingStopconditionPositionPositionconditionPlotColorColourPlotColorentry:longOpen longstrategy.entryexit:exit slexit exit slstrategy.exitclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryclose:shortClose shortstrategy.closeplot:17Fast EMAplotplot:18Slow EMAplotplot:27Upperplotplot:28Lowerplotfill:29Fillfillplot:59ATR Trailing Stopplot

Order rules

OrderFires whenBy defaultLine
Open long long(close > h1 and entrycondition2)On67
Exit exit sl stop(close > h1 and entrycondition2)On69
Close long(sellcondition1 and sellcondition2)On71
Open short short(close < l1 and sellcondition2)On73
Exit exit sl stop(close < l1 and sellcondition2)On75
Close short(entrycondition1 and entrycondition2)On77

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.

1/1trades 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+2.9%+102.5%560%4.381.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.8%+5.5%650%1.692.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.7%+9.8%540%1.371.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+1.6%+8.4%540%1.851.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−2.2%+16.7%825%0.503.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.8%+21.5%743%1.982.3%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2.0%+148.3%475%9.550.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+4.2%+17.1%540%3.251.5%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 (Length Fast EMA 25, Length Slow EMA 150) made +4.1% before 26 Dec 2025 and −0.5% after it, against −0.5% for the defaults. 98% of the 64 combinations made money in-sample and 0% out-of-sample.

Before 26 Dec 2025 · in-sample
Length Slow EMA ↓ · Length Fast EMA →2530354350607085
75+2%+3%+3%+2%+3%+3%+3%−3%
90+3%+3%+3%+3%+3%+3%+3%+3%
105+3%+3%+4%+3%+3%+3%+3%+3%
128+3%+4%+4%+3%+3%+3%+3%+3%
150+4%+3%+3%+3%+3%+3%+3%+3%
180+3%+3%+3%+3%+3%+3%+3%+3%
210+3%+3%+3%+3%+3%+3%+3%+3%
255+3%+3%+3%+3%+3%+3%+3%+3%
From 26 Dec 2025 · out-of-sample
Length Slow EMA ↓ · Length Fast EMA →2530354350607085
75−1%−1%−1%−2%−1%−1%−1%−0%
90−1%−1%−2%−1%−1%−1%−1%−1%
105−1%−1%−1%−1%−1%−1%−1%−1%
128−1%−1%−1%−1%−1%−1%−1%−1%
150−1%−1%−1%−1%−1%−1%−1%−1%
180−1%−1%−1%−1%−1%−1%−1%−1%
210−1%−1%−1%−1%−1%−1%−1%−1%
255−1%−1%−1%−1%−1%−1%−1%−1%

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 market10%−$3,573.02
Sideways market367%$23,845.10
Falling market1100%$8,892.24

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

How bad could the drawdown be?

0.8%

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, 0.5% to 0.8%; the tick is what actually happened, 0.5%. Order luck alone moves it this much.

0%1%
All 5 trades
SideEntryExitBarsP&L
long16 Oct 2024 67,074.1013 Jan 2025 90,013.2089$26,189.60
long2 May 2025 96,489.9022 Jun 2025 99,649.5051$2,710.33
long11 Jul 2025 116,010.0021 Aug 2025 112,033.0041−$3,573.02
short15 Nov 2025 94,594.0022 Apr 2026 79,418.50158$8,892.24
short3 Jun 2026 66,760.8020 Aug 2026 71,177.5078−$5,054.76

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
Classic Long Term Trend Following System this page—v5 strategy+2.9%51.1%
Richard's Strategy by Deepak8369highest lowest atr emav4 strategy+34.6%7026.3%
Strategy Myth-Busting #1 - UT Bot+STC+Hull [MYN] by myncryptoatr ema lowest highestv5 strategy−30.7%1063.5%
Strategy for UT Bot Alerts indicator by StrategiesForEveryoneema atr highest lowestv5 strategy−4.5%4215.7%
Simple and Profitable Scalping Strategy (ForexSignals TV) by kevinmck100ema atr highest lowestv5 strategyNo trades on this market
ATR + STC + MA by Romediusema lowest highest atrv5 strategy−1.2%153.3%

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.

  • 3 settings use the untyped input() (line 11, 12, 34). 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.

Clean v5

VerifiedDownload the v5 script

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

  • Line 11: input() → input.source()
  • Line 12: input() → input.source()
  • Line 34: input() → input.float()
  • Line 59: input() → input.int()
⋯len2 = input.int(150, minval = 1, title = "Length Slow EMA", group = "Moving Average Inputs")-src1 = input(close, title = "Source Fast MA")+src1 = input.source(close, title = "Source Fast MA")-src2 = input(close, title = "Source Slow MA")+src2 = input.source(close, title = "Source Slow MA")maFast = input.color(color.new(color.red, 0), title = "Color Fast EMA", group = "Moving Average Inputs", inline = "maFast")⋯length = input.int(title = "ATR Period", defval = 14, minval = 1, group ="ATR Position Size Inputs")-risk = input(title = "Risk Per Trade", defval = 0.01, group = "ATR Position Size Inputs")+risk = input.float(title = "Risk Per Trade", defval = 0.01, group = "ATR Position Size Inputs")atr = ta.atr(length)⋯PlotColor = Position == -1 ? color.orange : Position == 1 ? color.orange : color.orange-plot(xATRTrailingStop, color=PlotColor, linewidth = input(2, "Line Width", group = "ATR Trailing Stop Inputs"), style = plot.style_circles, title = "ATR Trailing Stop")+plot(xATRTrailingStop, color=PlotColor, linewidth = input.int(2, "Line Width", group = "ATR Trailing Stop Inputs"), style = plot.style_circles, title = "ATR Trailing Stop")// Buy and Sell Conditions //⋯

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: 5 before, 5 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.

⋯// © Robrecht99-//@version=5+//@version=6strategy("Classic Trend Following System", overlay=true, margin_long=0, margin_short=0, pyramiding=1)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 23 msYes 1,000 bars in 64 msNot measured
PineTSNot testedNot testedNot measured

The engine and this page's reading of the source count a different number of settings, so one of them has missed one.

“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/// © Robrecht99//@version=5strategy("Classic Trend Following System", overlay=true, margin_long=0, margin_short=0, pyramiding=1)// Backtest Range //Start = input.time(defval = timestamp("01 Jan 2017 00:00 +0000"), title = "Backtest Start Date", group = "backtest window")Finish = input.time(defval = timestamp("01 Jan 2100 00:00 +0000"), title = "Backtest End Date", group = "backtest window")// Moving Averages //len1 = input.int(50, minval = 1, title = "Length Fast EMA", group = "Moving Average Inputs")len2 = input.int(150, minval = 1, title = "Length Slow EMA", group = "Moving Average Inputs")src1 = input(close, title = "Source Fast MA")src2 = input(close, title = "Source Slow MA")maFast = input.color(color.new(color.red, 0), title = "Color Fast EMA", group = "Moving Average Inputs", inline = "maFast")maSlow = input.color(color.new(color.blue, 0), title = "Color Slow EMA", group = "Moving Average Inputs", inline = "maSlow")fast = ta.ema(src1, len1)slow = ta.ema(src2, len2)plot(fast, color = maFast, title = "Fast EMA")plot(slow, color = maSlow, title = "Slow EMA")// Donchian Channels //Length1 = input.int(title = "Length Upper Channel", defval=50, minval=1, group = "Donchian Channels Inputs")Length2 = input.int(title = "Length Lower Channel", defval=50, minval=1, group = "Donchian Channels Inputs")h1 = ta.highest(high[1], Length1)l1 = ta.lowest(low[1], Length2)fillColor = input.color(color.new(color.purple, 95), title = "Fill Color", group = "Donchian Channels Inputs")upperColor = input.color(color.new(color.orange, 0), title = " Color Upper Channel", group = "Donchian Channels Inputs", inline = "upper")lowerColor = input.color(color.new(color.orange, 0), title = " Color Lower Channel", group = "Donchian Channels Inputs", inline = "lower")u = plot(h1, "Upper", color = upperColor)l = plot(l1, "Lower", color = upperColor)fill(u, l, color=fillColor)// ATR and Position Size //leverage = input.int(title = "Leverage Used", defval = 1, minval = 1, group = "ATR Position Size Inputs")pointvalue = input.int(title = "Point Value/ATR Multipliers from Entry", defval = 4, minval = 1, group = "ATR Position Size Inputs")length = input.int(title = "ATR Period", defval = 14, minval = 1, group ="ATR Position Size Inputs")risk = input(title = "Risk Per Trade", defval = 0.01, group = "ATR Position Size Inputs")atr = ta.atr(length)amount = (risk * strategy.initial_capital / (pointvalue * atr * leverage))// ATR Trailing Stops //xATRPeriod = input.int(14, "ATR Period", group = "ATR Trailing Stop Inputs")xATRMultiplier = input.float(4, "ATR Multiplier", step = .1, group = "ATR Trailing Stop Inputs")xATR = ta.atr(xATRPeriod)Stop = xATRMultiplier * xATRvar xATRTrailingStop = 0.0xATRTrailingStop := if close>xATRTrailingStop[1] and close[1] > xATRTrailingStop[1]    math.max(xATRTrailingStop[1], close - Stop)else if close < xATRTrailingStop[1] and close[1] < xATRTrailingStop[1]    math.min(xATRTrailingStop[1], close + Stop)else if close > xATRTrailingStop[1]    close - Stop else     close+Stopvar Position = 0.0Position := if close[1] < xATRTrailingStop[1] and close > xATRTrailingStop[1]    1else if close[1] > xATRTrailingStop[1] and close < xATRTrailingStop[1]    -1else    Position[1]PlotColor = Position == -1 ? color.orange : Position == 1 ? color.orange : color.orangeplot(xATRTrailingStop, color=PlotColor, linewidth = input(2, "Line Width", group = "ATR Trailing Stop Inputs"), style = plot.style_circles, title = "ATR Trailing Stop")// Buy and Sell Conditions //entrycondition1 = ta.crossover(fast, slow)entrycondition2 = fast > slowsellcondition1 = ta.crossunder(fast, slow)sellcondition2 = slow > fast// Buy and Sell Signals //if (close > h1 and entrycondition2)    strategy.entry("long", strategy.long, qty=amount)    stoploss = close - atr * xATRMultiplier    strategy.exit("exit sl", stop=stoploss, trail_offset=stoploss)if (sellcondition1 and sellcondition2)    strategy.close(id="long")if (close < l1 and sellcondition2)    strategy.entry("short", strategy.short, qty=amount)    stoploss = close + atr * xATRMultiplier    strategy.exit("exit sl", stop=stoploss, trail_offset=stoploss)if (entrycondition1 and entrycondition2)    strategy.close(id="short")