Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Linear Regression Channel Breakout Strategy

A Pine Script v5 strategy with no technical-analysis calculation. It has 4 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 no commission. 14 settings; defaults include Source close, Length 20 and Deviation 2.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 Linear Regression Channel Breakout Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did Linear Regression Channel Breakout Strategy do on BTCUSDT 1D with default settings?
+4.83%
From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Linear Regression Channel Breakout 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: 14 before, 20 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 Linear Regression Channel Breakout Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 77, 78.
Does Linear Regression Channel Breakout Strategy run in Zeal Terminal?
Yes
It compiles in 47 ms and runs 1,000 bars in 125 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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,000AprJulOct2025AprJulOct2026AprJulOct$1,070,430$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep.
Net profit
+4.83%
$48,307.10
Buy and hold
+102.5%
same period
Closed trades
14
8 won · 6 lost
Profitable
57.1%
of closed trades
Profit factor
2.22
gross profit ÷ gross loss
Max drawdown
2.12%
−$21,892.10

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

    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
Sourceclosesourcemid slope dev y1_ y2_
Length20int · min 10mid slope intercept endy dev y1_ y2_ sidelab line 34 line 51 line 55 line 61
Deviation2.3float · min 0.1 · step 0.1outofchannel longCondition shortCondition line 51 line 55 line 62
Extend Linestrueboolline 51 line 55
Show Fibonacci Levelsfalseboolline 52
Show Broken Channeltrueboolline 44
Brokencol (no label in the script)color.bluecolorline 47
Up/Down Trend Colorscolor.limecolorline 22 line 63
Dncol (no label in the script)color.redcolorline 23 line 63
Line Width2intline 51 line 55
Stop Loss / Take Profit:
SLfalseboolexit Exit Long exit Exit Short
, %18.0float · min 0.0 · step 0.1stoploss
TPfalseboolexit Exit Long exit Exit Short
, %18.0float · min 0.0 · step 0.1takeprofit

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

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 datalenLengthsetting · 20devlenDeviationsetting · 2.3tppercent, %setting · 18.0slpercent, %setting · 18.0mid, slope, dev, y1_, y2_mid · slope +35 valuesinterceptinterceptvalueendyendyvalueoutofchanneloutofchannelvaluesidelabsidelabvaluetxt, stltxt · stl2 valuespmpmvaluetakeprofittakeprofitvaluestoplossstoplossvaluelongConditionlongConditionconditionshortConditionshortConditionconditionentrypriceentrypriceconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Exit Longexit Exit Longstrategy.exitexit:Exit Shortexit Exit Shortstrategy.exit

Order rules

OrderFires whenBy defaultLine
Open Long longlongConditionOn67
Open Short shortshortConditionOn70
Exit Exit Long stop and limitevery barOn77
Exit Exit Short stop and limitevery barOn78

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.

4/4trades 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+4.8%+102.5%1457%2.222.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.3%+5.5%1443%1.741.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.6%+9.8%1856%3.570.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%1638%1.800.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%1753%1.120.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%1443%3.220.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.1%+148.3%1926%0.350.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%2025%0.420.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 barsTradesWonP&L
Rising market580%$24,056.80
Sideways market650%$19,827.40
Falling market333%$4,422.91

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

How bad could the drawdown be?

3.1%

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

0%4%
All 14 trades
SideEntryExitBarsP&L
long29 Feb 2024 62,432.1017 Mar 2024 65,300.6017$2,868.53
short17 Mar 2024 65,300.6016 Jul 2024 64,724.10121$576.58
long16 Jul 2024 64,724.103 Aug 2024 61,498.3018−$3,225.72
short3 Aug 2024 61,498.307 Nov 2024 75,572.0096−$14,073.70
long7 Nov 2024 75,572.0020 Dec 2024 97,461.9043$21,889.90
short20 Dec 2024 97,461.9023 Apr 2025 93,443.00124$4,018.87
long23 Apr 2025 93,443.002 Aug 2025 113,298.00101$19,854.90
short2 Aug 2025 113,298.002 Oct 2025 118,595.0061−$5,297.07
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$5,820.50
short11 Oct 2025 112,774.006 Jan 2026 93,859.7087$18,914.80
long6 Jan 2026 93,859.7021 Jan 2026 88,427.7015−$5,432.05
short21 Jan 2026 88,427.705 Mar 2026 72,666.8043$15,760.90
long5 Mar 2026 72,666.803 Jun 2026 66,760.8090−$5,905.93
short3 Jun 2026 66,760.804 Jul 2026 62,583.3031$4,177.58

Similar scripts

No other indicator or strategy here shares enough of its calculations.

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.

  • 4 settings use the untyped input() (line 5, 8, 9, 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.

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.source()
  • Line 8: input() → input.bool()
  • Line 9: input() → input.bool()
  • Line 14: input() → input.int()
⋯strategy('Linear Regression Channel Breakout Strategy', overlay=true)-src = input(defval=close, title='Source')+src = input.source(defval=close, title='Source')len = input.int(defval=20, title='Length', minval=10)devlen = input.float(defval=2.3, title='Deviation', minval=0.1, step=0.1)-extendit = input(defval=true, title='Extend Lines')+extendit = input.bool(defval=true, title='Extend Lines')-showfibo = input(defval=false, title='Show Fibonacci Levels')+showfibo = input.bool(defval=false, title='Show Fibonacci Levels')showbroken = input.bool(defval=true, title='Show Broken Channel', inline='brk')⋯dncol = input.color(defval=color.red, title='', inline='trcols')-widt = input(defval=2, title='Line Width')+widt = input.int(defval=2, title='Line Width')issl = input.bool(title='SL', inline='linesl1', group='Stop Loss / Take Profit:', defval=false)⋯

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

⋯// © LonesomeTheBlue © chanu_lev10k-//@version=5+//@version=6strategy('Linear Regression Channel Breakout Strategy', overlay=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 47 msYes 1,000 bars in 125 msNot measured
PineTSNot testedNot testedNot 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/// © LonesomeTheBlue © chanu_lev10k//@version=5strategy('Linear Regression Channel Breakout Strategy', overlay=true)src = input(defval=close, title='Source')len = input.int(defval=20, title='Length', minval=10)devlen = input.float(defval=2.3, title='Deviation', minval=0.1, step=0.1)extendit = input(defval=true, title='Extend Lines')showfibo = input(defval=false, title='Show Fibonacci Levels')showbroken = input.bool(defval=true, title='Show Broken Channel', inline='brk')brokencol = input.color(defval=color.blue, title='', inline='brk')upcol = input.color(defval=color.lime, title='Up/Down Trend Colors', inline='trcols')dncol = input.color(defval=color.red, title='', inline='trcols')widt = input(defval=2, title='Line Width')issl = input.bool(title='SL', inline='linesl1', group='Stop Loss / Take Profit:', defval=false)slpercent = input.float(title=', %', inline='linesl1', group='Stop Loss / Take Profit:', defval=18.0, minval=0.0, step=0.1)istp = input.bool(title='TP', inline='linetp1', group='Stop Loss / Take Profit:', defval=false)tppercent = input.float(title=', %', inline='linetp1', group='Stop Loss / Take Profit:', defval=18.0, minval=0.0, step=0.1)var fibo_ratios = array.new_float(0)var colors = array.new_color(2)if barstate.isfirst    array.unshift(colors, upcol)    array.unshift(colors, dncol)    array.push(fibo_ratios, 0.236)    array.push(fibo_ratios, 0.382)    array.push(fibo_ratios, 0.618)    array.push(fibo_ratios, 0.786)get_channel(src, len) =>    mid = math.sum(src, len) / len    slope = ta.linreg(src, len, 0) - ta.linreg(src, len, 1)    intercept = mid - slope * math.floor(len / 2) + (1 - len % 2) / 2 * slope    endy = intercept + slope * (len - 1)    dev = 0.0    for x = 0 to len - 1 by 1        dev += math.pow(src[x] - (slope * (len - x) + intercept), 2)        dev    dev := math.sqrt(dev / len)    [intercept, endy, dev, slope][y1_, y2_, dev, slope] = get_channel(src, len)outofchannel = slope > 0 and close < y2_ - dev * devlen ? 0 : slope < 0 and close > y2_ + dev * devlen ? 2 : -1var reglines = array.new_line(3)var fibolines = array.new_line(4)for x = 0 to 2 by 1    if not showbroken or outofchannel != x or nz(outofchannel[1], -1) != -1        line.delete(array.get(reglines, x))    else        line.set_color(array.get(reglines, x), color=brokencol)        line.set_width(array.get(reglines, x), width=2)        line.set_style(array.get(reglines, x), style=line.style_dotted)        line.set_extend(array.get(reglines, x), extend=extend.none)    array.set(reglines, x, line.new(x1=bar_index - (len - 1), y1=y1_ + dev * devlen * (x - 1), x2=bar_index, y2=y2_ + dev * devlen * (x - 1), color=array.get(colors, math.round(math.max(math.sign(slope), 0))), style=x % 2 == 1 ? line.style_solid : line.style_dashed, width=widt, extend=extendit ? extend.right : extend.none))if showfibo    for x = 0 to 3 by 1        line.delete(array.get(fibolines, x))        array.set(fibolines, x, line.new(x1=bar_index - (len - 1), y1=y1_ - dev * devlen + dev * devlen * 2 * array.get(fibo_ratios, x), x2=bar_index, y2=y2_ - dev * devlen + dev * devlen * 2 * array.get(fibo_ratios, x), color=array.get(colors, math.round(math.max(math.sign(slope), 0))), style=line.style_dotted, width=widt, extend=extendit ? extend.right : extend.none))var label sidelab = label.new(x=bar_index - (len - 1), y=y1_, text='S', size=size.large)txt = slope > 0 ? slope > slope[1] ? '⇑' : '⇗' : slope < 0 ? slope < slope[1] ? '⇓' : '⇘' : '⇒'stl = slope > 0 ? slope > slope[1] ? label.style_label_up : label.style_label_upper_right : slope < 0 ? slope < slope[1] ? label.style_label_down : label.style_label_lower_right : label.style_label_rightlabel.set_style(sidelab, stl)label.set_text(sidelab, txt)label.set_x(sidelab, bar_index - (len - 1))label.set_y(sidelab, slope > 0 ? y1_ - dev * devlen : slope < 0 ? y1_ + dev * devlen : y1_)label.set_color(sidelab, slope > 0 ? upcol : slope < 0 ? dncol : color.blue)// Long Short conditionslongCondition = (slope < 0 and close > y2_ + dev * devlen) or (slope > 0 and close > y2_ + dev * devlen)if longCondition    strategy.entry('Long', strategy.long)shortCondition = (slope > 0 and close < y2_ - dev * devlen) or (slope < 0 and close < y2_ - dev * devlen)if shortCondition    strategy.entry('Short', strategy.short)// Entry price / Take Profit / Stop Loss//entryprice = strategy.position_avg_priceentryprice = ta.valuewhen(condition=longCondition or shortCondition, source=close, occurrence=0)pm = longCondition ? 1 : shortCondition ? -1 : 1 / math.sign(strategy.position_size)takeprofit = entryprice * (1 + pm * tppercent * 0.01)stoploss = entryprice * (1 - pm * slpercent * 0.01)strategy.exit(id='Exit Long', from_entry='Long', stop=issl ? stoploss : na, limit=istp ? takeprofit : na, alert_message='Exit Long')strategy.exit(id='Exit Short', from_entry='Short', stop=issl ? stoploss : na, limit=istp ? takeprofit : na, alert_message='Exit Short')