Isolated Scroll Container

1. Logarithmic Regression Channel-Trend Strategy Description

A straight regression line fitted through the logarithm of price over a lookback window, drawn from today back to a chosen number of bars, with two colour-coded outer boundary lines offset by a multiple of price's own standard deviation, X-mark crossover signals on its short-term direction, and a small dashboard summarising all three readings at once.

1.1 Indicator Concept

A normal linear regression line fits a straight line through raw price. This indicator fits the straight line through the logarithm of price instead, then turns the fitted values back into prices with exp(). The result is a line that represents a constant percentage growth rate rather than a constant point-per-bar rate — useful on instruments or long windows where price has grown by multiples, where a straight line on raw price would badly under- or over-shoot the early and late parts of the window.

  • One straight line, two readings of it. The regression produces exactly one line, but the indicator looks at it two different ways: has the line's own current value moved up or down over the last few bars (a short-term read), and is today's value above or below the line's value at the far left edge (a whole-window read). These two reads can disagree, and each colours a different set of drawings — see Flow 3.
  • A channel built from price's own volatility. Two boundary lines run parallel to the regression line, offset above and below it by a multiple of the standard deviation of raw closing price (not log price) over the same window — a volatility envelope wrapped around a log-growth trend line.
  • Only a thin frame of that channel is actually shaded. Despite looking like a "channel" indicator, the coloured fill is a narrow stripe hugging the outer boundary only — the open space between the centre line and that boundary is left blank. See Flow 4 and the technical notes.
  • X-mark signals on the line's own momentum. A cross appears when the regression line's current value, which had been falling for the last 3 bars, turns to rising (or the reverse) — a signal about the trend line itself, not a price-action signal.

In short: a log-space regression trend line with a volatility channel wrapped around it, two independent up/down readings (short-term and whole-window) driving different colours, momentum-turn markers on the line itself, and a compact info table.

1.2 Indicator Features

  • Display:
    • The main regression line (2px wide), from today's fitted value back to the left edge, coloured teal or pink depending on its own 3-bar direction (plain colour, not gradient).
    • A thin halo fill along that same line (optional, "Fill Band"), between the live line and an invisible copy of itself from 3 bars ago, in a colour that fades in or out with how strong the recent 3-bar move has been relative to the last 200 bars.
    • A dashed centre line (optional, "Mid Line") connecting today's fitted value to the fitted value at the left edge of the drawn window, in the chart's default text colour.
    • Two thick outer boundary lines (always shown, no toggle), offset from the centre by Channel Width + 0.3 standard deviations, coloured teal or pink by the line's whole-window direction.
    • A narrow shaded stripe right along each outer boundary (70% transparent, same colour) — from Channel Width out to Channel Width + 0.3 standard deviations. The space between the centre line and the Channel Width level itself is not shaded.
    • A text label ("UP" or "DN") at the left end of the lower boundary, dark navy text on a teal/pink background.
    • X-mark shapes at the regression line's current value, in the chart's neutral text colour, whenever the line's own 3-bar momentum turns.
    • A 3-row info table (top-right): the log-growth slope, the whole-window channel direction, and the short-term line direction.
  • Alerts: The indicator has NO alertcondition() calls.

1.3 How to Use the Indicator

  • Treat the regression line as a log-growth trend estimate, not a moving average — it is a single straight line (in log space) fitted once per bar over the whole lookback window, so it reacts to the window's overall shape, not just recent candles.
  • Read the main line's own colour (teal/pink) as a short-term "is the trend line itself rising or falling right now" gauge, and the outer channel's colour as a separate "has price grown net up or net down across the whole drawn window" gauge. Expect them to disagree sometimes — e.g. a line that is teal (recently turned up) sitting inside a pink (net-down) channel describes an early bounce inside a larger downward-sloping window.
  • Use the X-mark crosses as "the trend line's own momentum just flipped" markers, not entry signals in themselves — they fire once per 3-bar turn in the line's own value, gated to a closed bar so they will not repaint on the live candle (though the line and channel themselves still shift intrabar as the live close changes — see the technical notes).
  • Use the outer boundary + its narrow coloured stripe as a volatility extreme, not as "the edge of a trading channel". Because only a thin frame is shaded, the useful visual reference is the boundary line itself (and the label's UP/DN text), not a filled area to buy or sell from.
  • Keep "Lookback Period" and "Channel Length" equal unless you deliberately want a stretched or compressed-looking line. The regression math is computed over "Lookback Period" bars, but the line is drawn across "Channel Length" bars on the chart — if the two differ, the drawn line's apparent steepness will not match the regression's true calculated slope (see the technical notes).
  • Read the dashboard's "Slope" value as an approximate %-per-bar growth rate — it is the log-regression slope multiplied by 100, not a price-per-bar figure.
  • Be cautious turning "Mid Line" off — see the technical notes for a likely runtime error this can trigger; test it on your own chart before relying on that setting.

1.4 How the Indicator Works

Inputs & their role

  • length ("Lookback Period", integer, default 100): the number of bars (today plus 99 bars back) the log-regression line is mathematically fitted over, and also the window used for the standard-deviation channel width. Before/after: 50 → the line reacts to a shorter, more recent stretch of price; 200 → a longer, slower-moving fit.
  • channel_width ("Channel Width", decimal, default 1.5, step 0.1): how many standard deviations of raw close price the channel's inner (invisible) edge sits from the centre line. The visible, coloured outer edge always sits 0.3 further out than this (hard-coded, see below). Example: at 1.5, inner edge at 1.5σ, outer edge at 1.8σ; at 2.5, inner edge 2.5σ, outer 2.8σ — a wider channel on more volatile data.
  • channel_len ("Channel Length", integer, default 100): how many bars back, on the chart, the left end of the regression line and channel are drawn. This is a separate input from "Lookback Period" — they share the same default (100) but are not linked. See the technical notes for what happens if you change one without the other.
  • mid_disp ("Mid Line", tick box, default on, same row as "Fill Band"): shows or hides the dashed centre line connecting the regression's left-edge and right-edge fitted values.
  • fill_band ("Fill Band", tick box, default on, same row as "Mid Line"): despite the name, this does not toggle the channel's shaded stripe (that is always on) — it only toggles a thin highlight fill right along the main regression line itself, between the live line and its own value 3 bars ago.
  • col1 / col2 (two colour swatches, no titles, one row, defaults teal #21dfac and pink #df216d): col1 is used for every "up" reading (both the short-term line colour and the whole-window channel colour), col2 for every "down" reading. Colours only.

Hard-coded constants (NOT inputs)

  • The momentum window: fixed at 3 bars. diff = end − end[3] drives both the gradient-fill colours and the X-mark cross signals — not adjustable, and independent of "Lookback Period"/"Channel Length".
  • The outer-edge offset: fixed at +0.3 standard deviations beyond "Channel Width" — this is what makes the visible/shaded boundary sit further out than the invisible inner edge.
  • The gradient range: the fill colours (teal/pink intensity along the main line) are scaled against the lowest and highest 3-bar move of the last 200 bars — a fixed 200-bar lookback, separate from both main inputs.
  • Label text colour: always dark navy (#070f23), regardless of chart theme; the label's background follows col1/col2.
  • Table size: 10 columns × 10 rows allocated, only 3 cells of column 0 actually used.
  • The indicator has no plot/line/box/table count overrides in its declaration — it relies on TradingView's defaults.

Main logic blocks

⏱️ Flow 0 — Order of work on every candle

  • ① fit the log-regression line over the last length bars → ② turn the fitted values at today and at the far edge back into real prices (end, start) → ③ measure the line's own 3-bar move and price's own volatility → ④ decide the two separate up/down readings and their colours → ⑤ draw the centre line, the channel boundaries and the shaded stripe → ⑥ plot the X-mark signals → ⑦ update the info table.

📐 Flow 1 — Fitting the log-regression line

  • For each of the last length bars, the script takes log(close[i]) and pairs it with a position number per = i + 1 — so per = 1 is today (the most recent close) and per = length is the oldest bar in the window. This numbering runs backwards compared to normal calendar order.
  • A standard least-squares line is then fitted through these (per, log-close) pairs — the same formula a normal linear regression uses, just applied to the logarithm of price instead of price itself. This produces one slope and one reference value per bar.
  • Concrete example: if price has been growing at a roughly steady percentage rate, the fitted log-line is nearly straight and slope is a small positive log-value (e.g. 0.0015, meaning roughly +0.15% average growth per bar, log-compounded).

📏 Flow 2 — Converting the fit back into prices, and the two raw signals

  • end = exp(fitted value at per = 1) — the regression line's price-space value for today, drawn at bar_index (the right edge).
  • start = exp(fitted value at per = length) — the regression line's price-space value at the oldest bar actually in the window, drawn at bar_index[channel_len] (the left edge). When channel_len equals length (the shared default, 100), this lines up exactly with where the math says it should; if you set them differently, the drawn line's left end no longer sits where the fitted value was actually computed for (see the technical notes).
  • diff = end − end[3]: how much the line's own fitted "today" value has moved compared to 3 bars ago. Example: end now 2,655.20, end[3] was 2,648.10 → diff = +7.10 (the line has risen over the last 3 bars).
  • deviation = stdev(close, length): the standard deviation of raw closing price (not log price) over the same length-bar window — this is what the channel's width is measured in.

🎨 Flow 3 — Two independent up/down readings

  • Whole-window reading — channel_col: end > start ? col1 : col2 — is today's fitted value above or below the fitted value at the far left edge of the drawn line? This colours the outer channel boundaries, their shaded stripe, and the "UP"/"DN" label, plus the dashboard's "Log Regression Channel" row.
  • Short-term reading — trend_col1 (plain) and trend_col (gradient): end > end[3] ? col1 : col2 — has the line's own value risen or fallen over the last 3 bars? trend_col1 colours the main regression line itself and the dashboard's "Logarithmic Regression" row; trend_col (a gradient between na and col1/col2, scaled by diff's position within its own 200-bar range) colours the thin fill along the line ("Fill Band").
  • These two readings can disagree. A line that has just turned up over the last 3 bars (teal main line) can still sit inside a channel whose overall left-to-right direction is still net down (pink outer boundary) — and vice versa.

📦 Flow 4 — Drawing the centre line, the channel, and what actually gets shaded

  • Five drawing objects (base, up1, up, lw, lw1) and one label are created once and then repositioned on every later bar, a standard "create once, update after" pattern.
  • base (the dashed centre line, if mid_disp is on): from (bar_index[channel_len], start) to (bar_index, end), coloured in the chart's default text colour.
  • up1 / lw1 (the thick, visible outer boundaries): offset ±deviation × (channel_width + 0.3) from the centre line, coloured by channel_col.
  • up / lw (the thin inner edges): offset ±deviation × channel_width, always invisible (color = na after the first bar) — they exist only to anchor the shaded fill.
  • linefill between up/up1 and between lw/lw1, 70% transparent, in channel_col — this shades only the narrow 0.3-standard-deviation stripe between the inner and outer edges. The space between the centre line and the channel_width level is left completely unshaded — there is no fill covering "the whole channel".
  • The "UP"/"DN" label sits at the left end of the lower boundary, text #070f23 (fixed dark navy) on a channel_col background, with its anchor side flipped depending on end < start so the text does not overlap the line.

❌ Flow 5 — X-mark signals

  • up_sig = crossover(diff, 0) and barstate.isconfirmed: the line's own 3-bar move, which had been negative, turns positive — and the bar has fully closed. dn_sig is the mirror (crossunder).
  • Marks are drawn at the current end price, in the chart's neutral text colour (not teal/pink).
  • Because of the barstate.isconfirmed gate, these specific marks do not repaint on the forming candle — they only appear once a bar is finished. The regression line and channel positions themselves, however, still shift on every tick of the live candle, since they are recalculated from the live (not yet closed) close.

🗂️ Flow 6 — The info table (top-right, last bar only)

  • Row 0 — "Slope": slope × 100, in the chart's default text colour. An approximate %-per-bar log-growth rate.
  • Row 1 — "Log Regression Channel: UP/DN": from the whole-window reading (end > start), text coloured channel_col.
  • Row 2 — "Logarithmic Regression: UP/DN": from the short-term reading (end > end[3]), text coloured by the gradient colour (trend_col), so its exact shade can vary with how strong the recent move has been, not just a flat teal/pink.

Outputs & their role in trading

  • The regression line: a log-growth trend estimate over the chosen window.
  • The channel boundaries + label: a volatility envelope and a quick whole-window direction read.
  • The X-marks: momentum turns in the line's own value, confirmed only on closed bars.
  • The table: a compact summary of the growth rate and both direction readings at a glance.
💡 Important technical notes:
  • Turning "Mid Line" off is likely to break the script. The code only creates the base line object when mid_disp is true; if it is false on the very first bar, the script instead falls into a branch that calls positioning methods on a still-undefined (na) line object, which Pine normally raises as a runtime error for. Test this setting on your own chart before relying on it; if the indicator stops plotting, this is almost certainly why.
  • "Channel Length" and "Lookback Period" are independent inputs that happen to share a default. The regression math is always computed over Lookback Period bars; the line is always drawn across Channel Length bars on the chart. If the two differ, the drawn line's visible steepness no longer matches the actual fitted slope — e.g. a Channel Length smaller than Lookback Period will make the line look steeper on the chart than the regression really is, and a larger one will make it look shallower.
  • The channel's shaded area is a thin frame, not a filled band. Only the 0.3-standard-deviation stripe at the very outer edge is coloured; the region between the centre line and the Channel Width boundary is open/unshaded. "Fill Band" does not change this — it only controls a separate, thin highlight along the main line itself.
  • per = i + 1 runs backwards in time (today = 1, oldest in the window = length), which is why end (today's fitted value) comes from per = 1 and start (the window's oldest fitted value) comes from per = length — the reverse of what the variable names might suggest if read as "start of time, end of time".
  • The channel width is measured in raw-price standard deviation, not log-price standard deviation, even though the centre line itself is a log-space fit — a mixed-domain design choice that is worth being aware of, particularly on instruments where price has grown by a large multiple over the lookback window (raw-price volatility will scale with price level, not with the log-growth rate).
  • The line and channel are not frozen intrabar. Both use the live, still-forming close on the current bar, so their position can shift tick by tick until the candle closes — only the X-mark signals are explicitly held back until barstate.isconfirmed.
  • No alerts, and a 10×10 table with only 3 cells used. Neither affects behaviour, just worth knowing if extending the script.
Zoom/Pan Layered Image
Background Overlay
− +

The indicator above just became a TRADING BOT — 1 AI click

📊Original indicator
→
🤖AI 1-click convert
→
⚙️Bot trading 24/7