Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Linear trend

A Pine Script v4 strategy built on Linreg (src, 13) and Crossunder (lr, 0). 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.075% commission. 11 settings; defaults include Start Year 2017, Month 12 and Day 17.

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 Linear trend repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Linear trend do on BTCUSDT 1D with default settings?
+3.28%
From 26 Jan 2024 to 21 Oct 2026, over 13 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Linear trend be converted to Pine Script v5?
No
The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
Does Linear trend use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Linear trend run in Zeal Terminal?
Yes
It compiles in 10 ms and runs 1,000 bars in 37 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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 (11)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$103,277$202,527Equity from $100,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
+3.28%
$3,278.87
Buy and hold
+102.5%
same period
Closed trades
13
4 won · 9 lost
Profitable
30.8%
of closed trades
Profit factor
1.09
gross profit ÷ gross loss
Max drawdown
16.84%
−$18,371.50

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

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

  • Note

    Uses an argument v6 removed

    when = on line 21, 23. The upgraded version below moves each call inside an if block.

  • Note

    Uses iff(), which v5 removed line 8

    iff() on line 8. v5 writes it as the ternary c ? a : b.

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 linreg → ta.linreg, crossover → ta.crossover, ema → ta.ema, crossunder → ta.crossunder.
  • 2 strategy calls use the when = argument (line 21, 23). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Differs

Trades differ: 13 before, 13 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 8: iff(c, a, b) → (c ? a : b)
  • Line 15: linreg → ta.linreg
  • Line 16: linreg → ta.linreg
  • Line 20: crossover → ta.crossover
  • Line 20: ema → ta.ema
  • Line 22: crossunder → ta.crossunder
⋯// © TradingAmmo-//@version=4+//@version=5strategy("Linear trend", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.075, currency='USD')⋯_testPeriod() =>-    iff(time >= startP and time <= end, true, false)+    (time >= startP and time <= end ? true : false)src = close⋯threshold  = input(0,step=0.5, title="Threshold")-fast_lr = linreg(src, len1, lag1)+fast_lr = ta.linreg(src, len1, lag1)-slow_lr = linreg(src, len2, lag2)+slow_lr = ta.linreg(src, len2, lag2)lr = fast_lr - slow_lr⋯plot(threshold, color=color.purple)-long_condition = crossover(lr, threshold) and close > ema(close, 200) and _testPeriod()+long_condition = ta.crossover(lr, threshold) and close > ta.ema(close, 200) and _testPeriod()strategy.entry('BUY', strategy.long, when=long_condition) -short_condition = crossunder(lr, threshold) +short_condition = ta.crossunder(lr, threshold) strategy.close('BUY', when=short_condition)

Clean v5

Verified

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

  • Line 5: input() → input.int()
  • Line 5: input() → input.int()
  • Line 5: input() → input.int()
  • Line 6: input() → input.int()
  • Line 6: input() → input.int()
  • Line 6: input() → input.int()
7 more edits
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 21: when = long_condition → if block
  • Line 23: when = short_condition → if block
⋯strategy("Linear trend", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.075, currency='USD')-startP = timestamp(input(2017, "Start Year"), input(12, "Month"), input(17, "Day"), 0, 0)+startP = timestamp(input.int(2017, "Start Year"), input.int(12, "Month"), input.int(17, "Day"), 0, 0)-end   = timestamp(input(9999, "End Year"),   input(1, "Month"),   input(1, "Day"),   0, 0)+end   = timestamp(input.int(9999, "End Year"),   input.int(1, "Month"),   input.int(1, "Day"),   0, 0)_testPeriod() =>⋯src = close-len1 = input(defval=13, minval=1, title="Fast LR")+len1 = input.int(defval=13, minval=1, title="Fast LR")-len2 = input(defval=55, minval=1, title="Slow LR")+len2 = input.int(defval=55, minval=1, title="Slow LR")-lag1 = input(0, title="Lag for fast")+lag1 = input.int(0, title="Lag for fast")-lag2 = input(0, title="Lag for slow")+lag2 = input.int(0, title="Lag for slow")-threshold  = input(0,step=0.5, title="Threshold")+threshold  = input.int(0,step=0.5, title="Threshold")fast_lr = ta.linreg(src, len1, lag1)⋯long_condition = ta.crossover(lr, threshold) and close > ta.ema(close, 200) and _testPeriod()-strategy.entry('BUY', strategy.long, when=long_condition) +if long_condition+    strategy.entry('BUY', strategy.long) short_condition = ta.crossunder(lr, threshold) -strategy.close('BUY', when=short_condition)+if short_condition+    strategy.close('BUY')

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

⋯// © TradingAmmo-//@version=5+//@version=6strategy("Linear trend", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.075, currency='USD')⋯

Settings

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

SettingDefaultType and rangeFeeds
Start Year2017intline 8
Month12intline 8
Day17intline 8
End Year9999intline 8
Month1intline 8
Day1intline 8
Fast LR13int · min 1fast_lr
Slow LR55int · min 1slow_lr
Lag for fast0intfast_lr
Lag for slow0intslow_lr
Threshold0int · step 0.5long_condition short_condition plot

What it calculates

  • Linreg (linreg, ta.linreg in v5)src, Fast LR (13), Lag for fast (0)fast_lr · line 15
  • Linreg (linreg, ta.linreg in v5)src, Slow LR (55), Lag for slow (0)slow_lr · line 16
  • Crossunder (crossunder, ta.crossunder in v5)lr, Threshold (0)short_condition · line 22

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.

len1Fast LRsetting · 13lag1Lag for fastsetting · 0len2Slow LRsetting · 55lag2Lag for slowsetting · 0thresholdThresholdsetting · 0closecloseprice datafast_lrLinreg→ fast_lrslow_lrLinreg→ slow_lrshort_conditionCrossunder→ short_conditionsrcsrcvaluelrlrvaluelong_conditionlong_conditionconditionentry:BUYOpen BUYstrategy.entryclose:BUYClose BUYstrategy.closeplot:18plotplotplot:19plotplot

Order rules

OrderFires whenBy defaultLine
Open BUY longlong_conditioncrossover(lr, threshold) and close > ema(close, 200) and _testPeriod()On21
Close BUYshort_conditionOn23

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.

2/2trades 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+3.3%+102.5%1331%1.0916.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−4.6%+5.5%1331%0.7112.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+5.6%+9.8%743%1.0840.8%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+15.7%+8.4%1625%1.6512.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−30.4%+16.7%1136%0.5742.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+5.3%+21.5%1429%1.1913.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.5%+148.3%1338%1.0121.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+21.9%+17.1%1145%2.545.7%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 market540%$23,769.30
Sideways market825%−$20,490.50
Falling market0—$0.00

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

How bad could the drawdown be?

28.6%

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

0%33%
All 13 trades
SideEntryExitBarsP&L
long24 Aug 2024 64,037.202 Sep 2024 57,301.809−$10,652.20
long15 Oct 2024 66,084.0027 Oct 2024 67,092.8012$1,227.91
long30 Oct 2024 72,736.406 Nov 2024 69,372.007−$4,319.03
long7 Nov 2024 75,572.001 Dec 2024 96,408.0024$23,617.00
long18 Jan 2025 104,077.003 Feb 2025 97,700.6016−$6,886.61
long22 May 2025 109,644.0026 May 2025 109,004.004−$754.41
long30 Jun 2025 108,357.0027 Jul 2025 117,920.0027$8,855.80
long9 Sep 2025 112,065.0026 Sep 2025 108,994.0017−$3,205.92
long2 Oct 2025 118,595.0013 Oct 2025 114,959.0011−$3,464.48
long29 Oct 2025 112,898.001 Nov 2025 109,608.003−$3,195.22
long3 Nov 2025 110,541.004 Nov 2025 106,583.001−$3,770.33
long21 Aug 2026 73,027.0010 Sep 2026 78,306.4020$6,888.77
long24 Sep 2026 84,397.6030 Sep 2026 83,663.706−$1,062.41

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
Linear trend this page—v4 strategy+3.3%1316.8%
Linear Channel - Scalp Strategy 15M by TradingAmmolinregv4 strategy+2.5%730.1%
Crypto Squeeze Strategy by Bungholelinregv4 strategy−43.8%1564.0%
Trend Following based on Trend Confidence by carefulCamel61097linregv5 strategy−1.8%720.7%
Strategy Myth-Busting #9 - HullSuite+LSMA - [MYN] by myncryptolinregv5 strategy−38.3%1372.6%
Strategy Myth-Busting #4 - LSMA+HULL Crossover - [MYN] by myncryptolinregv5 strategy+22.2%1374.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 10 msYes 1,000 bars in 37 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/// © TradingAmmo//@version=4strategy("Linear trend", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.075, currency='USD')startP = timestamp(input(2017, "Start Year"), input(12, "Month"), input(17, "Day"), 0, 0)end   = timestamp(input(9999, "End Year"),   input(1, "Month"),   input(1, "Day"),   0, 0)_testPeriod() =>    iff(time >= startP and time <= end, true, false)src = closelen1 = input(defval=13, minval=1, title="Fast LR")len2 = input(defval=55, minval=1, title="Slow LR")lag1 = input(0, title="Lag for fast")lag2 = input(0, title="Lag for slow")threshold  = input(0,step=0.5, title="Threshold")fast_lr = linreg(src, len1, lag1)slow_lr = linreg(src, len2, lag2)lr = fast_lr - slow_lrplot_fast = plot(lr, color = lr > 0 ? color.green : color.red)plot(threshold, color=color.purple)long_condition = crossover(lr, threshold) and close > ema(close, 200) and _testPeriod()strategy.entry('BUY', strategy.long, when=long_condition) short_condition = crossunder(lr, threshold) strategy.close('BUY', when=short_condition)