Indicator · Pine Script v6 · On the chart

Logarithmic Regression Channel-Trend [BigBeluga]

by theonetrade· code credited to BigBeluga

This overlay indicator calculates a logarithmic linear regression of close prices over a customizable lookback period.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code133
Settings7inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

133 lines of Pine Script v6 from assets/indicator/bit-exact/logarithmic_regression_channel_trend_bigbeluga_o7ThImqK.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

logarithmic_regression_channel_trend_bigbeluga_o7ThImqK.pine
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International  
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga

//@version=6
indicator("Logarithmic Regression Channel-Trend [BigBeluga]", "LogReg Channel-Trend [BigBeluga]", overlay=true)

// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
int   length        = input.int(100, "Lookback Period")
float channel_width = input.float(1.5, "Channel Width", step = 0.1)
int channel_len     = input(100, "Channel Length")
bool  mid_disp      = input.bool(true, "Mid Line", inline = "s")
bool  fill_band     = input.bool(true, "Fill Band", inline = "s")
color col1          = input.color(#21dfac, "", inline = "s1")
color col2          = input.color(#df216d, "", inline = "s1")
// }


// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Function to compute logarithmic regression
f_log_regression(src, length) =>

    float sumX      = 0.0
    float sumY      = 0.0
    float sumXSqr   = 0.0
    float sumXY     = 0.0

    for i = 0 to length - 1
        val = math.log(src[i])
        per = i + 1.0
        sumX += per
        sumY += val
        sumXSqr += per * per
        sumXY += val * per

    slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX)
    average = sumY / length
    intercept = average - slope * sumX / length + slope

    [slope, intercept]

// Calculate slope and intercept
[slope, intercept] = f_log_regression(close, length)

float start     = math.exp(intercept + slope * length)
float end       = math.exp(intercept)
float diff      = end - end[3]
float deviation = ta.stdev(close, length)
bool  up_sig    = ta.crossover(diff, 0) and barstate.isconfirmed
bool  dn_sig    = ta.crossunder(diff, 0) and barstate.isconfirmed
// }



// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{

// Define Colors
color color_up      = color.from_gradient(diff, ta.lowest(diff,200), ta.highest(diff,200), na, col1)
color color_dn      = color.from_gradient(diff, ta.lowest(diff,200), ta.highest(diff,200), col2, na)
color channel_col   = end > start ? col1 : col2
color trend_col     = end > end[3] ?  color_up : color_dn
color trend_col1    = end > end[3] ?  col1 : col2

p1 = plot(end, "Log Regression", color = trend_col1, linewidth = 2)
p2 = plot(end[3], color = trend_col, display = display.none, editable = false)
plotshape(up_sig ? end : na, "Up", shape.xcross, location.absolute, chart.fg_color, size = size.tiny)
plotshape(dn_sig ? end : na, "Dn", shape.xcross, location.absolute, chart.fg_color, size = size.tiny)

fill(p1, p2, fill_band ? trend_col : na)


// Define upper and lower channel based on standard deviation
var line up1 = na
var line up = na
var line base = na
var line lw = na
var line lw1 = na
var label lbl_t = na


if na(base) and mid_disp
    base := line.new(bar_index[channel_len], start, bar_index, end, style = line.style_dashed)
else 
    base.set_xy1(bar_index[channel_len], start)
    base.set_xy2(bar_index, end)
    base.set_color(chart.fg_color)

if na(up1) 
    up1 := line.new(bar_index[channel_len], start+deviation*(channel_width+0.3), bar_index, end + deviation*(channel_width+0.3), width = 3)
else 
    up1.set_xy1(bar_index[channel_len], start+deviation*(channel_width+0.3))
    up1.set_xy2(bar_index, end + deviation*(channel_width+0.3))
    up1.set_color(channel_col)

if na(up) 
    up := line.new(bar_index[channel_len], start+deviation*channel_width, bar_index, end + deviation*channel_width, width = 1)
else 
    up.set_xy1(bar_index[channel_len], start+deviation*channel_width)
    up.set_xy2(bar_index, end + deviation*channel_width)
    up.set_color(na)

if na(lw) 
    lw := line.new(bar_index[channel_len], start-deviation*channel_width, bar_index, end - deviation*channel_width, width = 1)
else 
    lw.set_xy1(bar_index[channel_len], start-deviation*channel_width)
    lw.set_xy2(bar_index, end - deviation*channel_width)
    lw.set_color(na)

if na(lw1) 
    lw1 := line.new(bar_index[channel_len], start-deviation*(channel_width+0.3), bar_index, end - deviation*(channel_width+0.3), width = 3)
    lbl_t := label.new(bar_index[channel_len], start-deviation*(channel_width+0.3))
else 
    lw1.set_xy1(bar_index[channel_len], start-deviation*(channel_width+0.3))
    lw1.set_xy2(bar_index, end - deviation*(channel_width+0.3))
    lw1.set_color(channel_col)

    lbl_t.set_xy(bar_index[channel_len], start-deviation*(channel_width+0.3))
    lbl_t.set_text(end > start ? "UP" : "DN")
    lbl_t.set_style((end < start ? label.style_label_lower_right : label.style_label_upper_right))
    lbl_t.set_color(channel_col)
    lbl_t.set_textcolor(#070f23)

// Fill Channel Upper and Lower Zones with color
linefill.new(lw, lw1, color.new(channel_col, 70))
linefill.new(up, up1, color.new(channel_col, 70))

// Info Dash
if barstate.islast
    dash = table.new(position.top_right, 10, 10, bgcolor = color.new(chart.fg_color, 90), border_color = chart.bg_color, border_width = 5)
    dash.cell(0, 0, "Slope: " + str.tostring(slope*100, "#,###.###"), text_color = chart.fg_color)
    dash.cell(0, 1, "Log Regression Channel: " + (end > start ? "UP" : "DN"), text_color = channel_col)
    dash.cell(0, 2, "Logarithmic Regression: " + (end > end[3] ? "UP" : "DN"), text_color = color.new(trend_col, 0))
// }

Overview

Logarithmic Regression Channel-Trend [BigBeluga] projects the regression line directly on the price chart and identifies trend direction based on the rate of change in regression endpoint values. Visual shape markers highlight bullish and bearish trend slope crossovers when confirmed. Users can adjust the lookback period, channel parameters, mid-line display, and fill options.

Details

Published by

theonetrade on GitHub

Code credit

BigBeluga, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Lookback Periodint100length
Channel Widthfloat1.5channel_width
Channel Lengthint100channel_len
Mid Linebooltruemid_disp
Fill Bandbooltruefill_band
col1color#21dfaccol1
col2color#df216dcol2
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener

Swing labels

by tradoor-terminal
320 stars

Calculates swing highs and swing lows on the price chart using pivot high and pivot low detection over a specified length. It places labels above pivot highs and below pivot lows to highlight key structural swing points. The indicator measures and displays the

Indicator v6 Support & resistanceTrend
Updated 3 days ago · AGPL-3.0 GitHub repository of Swing labels

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 5 years ago · None stated GitHub repository of Function - Linear Regression

AI Trend

by dearvn
257 stars

AI Trend is an indicator that plots pivot points, trend lines, and support and resistance levels directly on the price chart. It marks high and low pivots based on user-defined length, draws trend lines that check for violations at specified points, and identi

Indicator v5 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of AI Trend

Dynamic Linear Regression

by TradersPost
228 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 4 months ago · None stated GitHub repository of Dynamic Linear Regression

Ichimoku Cloud

by harryguiacorn
220 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers