Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Trend Following based on Trend Confidence

A Pine Script v5 strategy built on Linreg (close, 30). 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 commits 100% of equity and pays 0.1 commission. 11 settings; defaults include Source close, Length 30 and Long entry threshold 0.25.

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 Following based on Trend Confidence repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
How did Trend Following based on Trend Confidence do on BTCUSDT 1D with default settings?
−1.77%
From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Trend Following based on Trend Confidence 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: 7 before, 7 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 Following based on Trend Confidence use a stop loss?
Yes
strategy.exit sets a stop on line 49, 54.
Does Trend Following based on Trend Confidence run in Zeal Terminal?
Yes
It compiles in 28 ms and runs 1,000 bars in 77 ms, in the browser.

BTCUSDT · 1D · default settings

  • Trend Confidence
  • 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,000AprJulOct2025AprJulOct2026AprJulOctTrend Confidence$982$2,025Equity from $1,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. 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.
Net profit
−1.77%
−$17.67
Buy and hold
+102.5%
same period
Closed trades
7
2 won · 5 lost
Profitable
28.6%
of closed trades
Profit factor
0.91
gross profit ÷ gross loss
Max drawdown
20.66%
−$240.21

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

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    1 setting has no label

    In the settings dialog source (line 14) shows an empty name. The labels on this page come from the variable names.

Settings

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

SettingDefaultType and rangeFeeds
Source (no label in the script)closesourcelinreg linreg_p deviationSum slope_perc deviation_perc
Start trading intervaltimestamp('2000-01-01')timein_interval
End trading intervaltimestamp('2030-01-01')timein_interval
Length30intlinreg linreg_p deviation line 37
Longstrueboolentry TC Long Entry exit TC Long Exit close TC Long Entry line 47 line 50
Shortstrueboolentry TC Short Entry exit TC Short Exit close TC Short Entry line 52 line 55
Long entry threshold0.25float · step 0.01entry TC Long Entry exit TC Long Exit line 47 plot
Long exit threshold-0.10float · step 0.01close TC Long Entry line 50 plot
Short entry threshold-0.25float · step 0.01entry TC Short Entry exit TC Short Exit line 52 plot
Short exit threshold-0.05float · step 0.01close TC Short Entry line 55 plot
Stop loss (percentage)10float · step 1sl_long sl_short

What it calculates

  • LinregSource (close), Length (30), 0linreg · line 31
  • LinregSource (close), Length (30), 0+1linreg_p · line 32

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 datalengthLengthsetting · 30stop_lossStop loss (percentage)setting · 10timetimeprice datasinceStart trading intervalsetting · timestamp('2000-01-…tillEnd trading intervalsetting · timestamp('2030-01-…long_entryLong entry thresholdsetting · 0.25long_exitLong exit thresholdsetting · -0.10short_entryShort entry thresholdsetting · -0.25short_exitShort exit thresholdsetting · -0.05linregLinreg→ linreglinreg_pLinreg→ linreg_pxxvalueslopeslopevalueinterceptinterceptvaluedeviationSumdeviationSumvaluedeviationdeviationvalueslope_percslope_percvaluedeviation_percdeviation_percvaluetrend_confidencetrend_confidencevaluesl_long, sl_shortsl_long · sl_short2 valuesin_intervalin_intervalconditionentry:TC Long EntryOpen TC Long Entrystrategy.entryexit:TC Long Exitexit TC Long Exitstrategy.exitclose:TC Long EntryClose TC Long Entrystrategy.closeentry:TC Short EntryOpen TC Short Entrystrategy.entryexit:TC Short Exitexit TC Short Exitstrategy.exitclose:TC Short EntryClose TC Short Entrystrategy.closeplot:58Trend Confidenceplotplot:59plotplot:60plotplot:61plotplot:62plot

Order rules

OrderFires whenBy defaultLine
Open TC Long Entry longin_interval and longs_on and ta.crossover(trend_confidence, long_entry)On48
Exit TC Long Exit stopin_interval and longs_on and ta.crossover(trend_confidence, long_entry)On49
Close TC Long Entryin_interval and longs_on and ta.crossunder(trend_confidence, long_exit)On51
Open TC Short Entry shortin_interval and shorts_on and ta.crossunder(trend_confidence, short_entry)On53
Exit TC Short Exit stopin_interval and shorts_on and ta.crossunder(trend_confidence, short_entry)On54
Close TC Short Entryin_interval and shorts_on and ta.crossover(trend_confidence, short_exit)On56

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.

3/3trades 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−1.8%+102.5%729%0.9120.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−2.7%+5.5%1040%0.708.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+41.0%+9.8%850%2.0921.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+8.0%+8.4%850%2.683.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−38.5%+16.7%1136%0.5246.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−7.6%+21.5%933%0.6922.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+3.2%+148.3%729%1.0728.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−15.1%+17.1%813%0.0616.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 barsTradesWonP&L
Rising market1100%$43.51
Sideways market425%$61.13
Falling market20%−$122.32

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

How bad could the drawdown be?

17.3%

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

0%20%
All 7 trades
SideEntryExitBarsP&L
short1 Jul 2024 62,772.0019 Jul 2024 63,988.0018−$21.37
long20 Nov 2024 92,310.9014 Feb 2025 96,608.1086$43.51
long4 May 2025 95,856.502 Sep 2025 109,237.00121$140.36
short21 Nov 2025 86,637.2012 Dec 2025 92,513.4021−$81.17
short10 Feb 2026 70,137.905 Mar 2026 72,666.8023−$41.15
long25 Apr 2026 77,437.2030 May 2026 73,460.7035−$55.39
short8 Jun 2026 63,332.008 Jul 2026 63,364.1030−$2.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.

ScriptSharesTypeNetTradesMax drawdown
Trend Following based on Trend Confidence this page—v5 strategy−1.8%720.7%
Linear trend by TradingAmmolinregv4 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%
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%

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.

  • 2 settings use the untyped input() (line 14, 17). 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 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 14: input() → input.source()
  • Line 17: input() → input.int()
⋯// Inputs-source      = input(close)+source      = input.source(close)since       = input.time(timestamp('2000-01-01'), title='Start trading interval')till        = input.time(timestamp('2030-01-01'), title='End trading interval')-length      = input(30, title='Length')+length      = input.int(30, title='Length')longs_on    = input.bool(true, title='Longs')⋯

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: 7 before, 7 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("Trend Following based on Trend Confidence", overlay=false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, margin_long=1./2*50, margin_short=1./2*50, commission_value=0.1, slippage=5, initial_capital=1000)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 28 msWith a workaround 1,000 bars in 77 msNot measured
PineTSNot testedNot testedNot 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/// © carefulCamel61097// ################################################################################################// "This is a trend following strategy that performed very well on the past 5 years"// "Intended to be used on BTC-USDT, 4hr timeframe"// "A factor 2 Leverage can be added by changing Order Size to 200% of equity"// "Higher leverage is not recommended due to big drawdowns"// "Also seems to work on 1D timeframe, although ideal parameters may be different"// "Also seems to work on ETH-USDT and some other altcoins, although ideal parameters are different"// ################################################################################################//@version=5strategy("Trend Following based on Trend Confidence", overlay=false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, margin_long=1./2*50, margin_short=1./2*50, commission_value=0.1, slippage=5, initial_capital=1000)// Inputssource      = input(close)since       = input.time(timestamp('2000-01-01'), title='Start trading interval')till        = input.time(timestamp('2030-01-01'), title='End trading interval')length      = input(30, title='Length')longs_on    = input.bool(true, title='Longs')shorts_on   = input.bool(true, title='Shorts')// Parameters for best performance 2018 - 2022// long_entry  = input.float(0.26, step=0.01, title='Long entry threshold')// long_exit   = input.float(-0.10, step=0.01, title='Long exit threshold')// short_entry = input.float(-0.24, step=0.01, title='Short entry threshold')// short_exit  = input.float(-0.04, step=0.01, title='Short exit threshold')long_entry  = input.float(0.25, step=0.01, title='Long entry threshold')long_exit   = input.float(-0.10, step=0.01, title='Long exit threshold')short_entry = input.float(-0.25, step=0.01, title='Short entry threshold')short_exit  = input.float(-0.05, step=0.01, title='Short exit threshold')stop_loss   = input.float(10, step=1, title='Stop loss (percentage)') / 100// Trend Confidencelinreg = ta.linreg(source, length, 0)linreg_p = ta.linreg(source, length, 0+1)x = bar_indexslope = linreg - linreg_pintercept = linreg - x*slopedeviationSum = 0.0for i = 0 to length-1    deviationSum := deviationSum + math.pow(source[i]-(slope*(x-i)+intercept), 2)deviation = math.sqrt(deviationSum/(length))slope_perc = slope / source[0]deviation_perc = deviation / source[0]trend_confidence = slope_perc / deviation_perc// Strategyin_interval = (time > since) and (time < till)sl_long = strategy.position_avg_price * (1 - stop_loss)sl_short = strategy.position_avg_price * (1 + stop_loss)if in_interval and longs_on and ta.crossover(trend_confidence, long_entry)    strategy.entry("TC Long Entry", strategy.long)    strategy.exit("TC Long Exit", stop=sl_long)if in_interval and longs_on and ta.crossunder(trend_confidence, long_exit)    strategy.close("TC Long Entry")if in_interval and shorts_on and ta.crossunder(trend_confidence, short_entry)    strategy.entry("TC Short Entry", strategy.short)    strategy.exit("TC Short Exit", stop=sl_short)if in_interval and shorts_on and ta.crossover(trend_confidence, short_exit)    strategy.close("TC Short Entry")// Plots plot(trend_confidence, "Trend Confidence", color.rgb(255, 255, 255))plot(long_entry, "", color.rgb(0, 255, 0), linewidth=1)plot(long_exit, "", color.rgb(255, 0, 0), linewidth=1)plot(short_entry, "", color=bar_index % 10 == 0 ? color.rgb(0, 255, 0) : #00000000, linewidth=1)plot(short_exit, "", color=bar_index % 10 == 0 ? color.rgb(255, 0, 0) : #00000000, linewidth=1)