Isolated Scroll Container

1. Bollinger Bands Regression Forecast Strategy Description

Standard Bollinger Bands plus a forward-extrapolated "forecast cone", an illustrative zigzag+random-walk price path threading through that cone, and an independent mean-reversion signal engine that fires when price gets rejected at the upper/lower band.

1.1 Indicator Concept

The indicator's core is standard Bollinger Bands (basis = SMA, bands = basis ± multiplier × standard deviation). On top of that, it adds a "forecast cone": by estimating the slope (trend) of the basis, standard deviation, and ATR via linear regression over a separate lookback, then extrapolating those slopes forward using a smoothing (easing) curve instead of a blunt straight line, it produces a prediction of what the Bollinger Bands might look like over the next N bars.

The indicator lets you choose between 5 different forecasting philosophies - from raw trend continuation (Trend), to a smooth S-curve glide (Curved), a volatility "breathing" effect with a partial pull back toward current levels (Bollinger style), width driven entirely by ATR instead of standard deviation (ATR style), to the most heavily smoothed variant (Smoothed).

  • Illustrative Price Path: a single zigzag line, optionally blended with a deterministic (reproducible with the same seed) pseudo-random walk, threading through the forecast cone - this is JUST ONE of countless illustrative possible routes, NOT a statistically grounded prediction.
  • Independent mean-reversion signals: a signal engine completely separate from the forecast, detecting the classic "price wicks past the band then gets rejected, closes back inside, still on the correct side of the basis" pattern - this is actually the indicator's tradeable output.

1.2 Indicator Features

  • Current Bollinger Bands: basis/upper/lower + fill between the two bands, like a standard BB indicator.
  • Forecast Cone: a projected basis (eased curve or straight, depending on mode) + projected width/multiplier, drawn as a CHAIN of connected line segments (each forecast step is its own separate line object, not one continuous line) - 5 selectable modes, with an optional fill.
  • Projected Price Path: a single zigzag line (optionally blended with random walk) threading through the cone, with configurable swing count/amplitude/decay, its own line style and color completely separate from the forecast bands.
  • Signal Markers: layered up/down triangles (a small solid one + a larger, faded one creating a "glow" effect), placed above/below the bands with a padding distance of EMA(ATR,200), sharing one cooldown for both directions, plus an optional MA-bias filter; the filter MA can also be displayed on the chart.

1.3 How to Use the Indicator

  • Use the CURRENT bands (not the forecast cone) for actual trading decisions: the cone and price path only redraw on the last bar and are illustrative, not a validated statistical forecast.
  • Pick "Forecast Band Mode" based on the market-regime assumption you want to visualize: "Trend" for raw continuation; "Curved" for a smooth decelerating glide; "Bollinger style" if you want to see a volatility "breathing" effect paired with a pull back toward mean; "ATR style" to fully decouple the width forecast from standard deviation and drive it with ATR instead; "Smoothed" for the least jagged, most heavily lagged look.
  • Treat the zigzag/random-walk price path as ONE illustrative route, not a forecast with edge: it's built from a decaying zigzag plus a seeded random walk, not from any predictive model; changing "Random Walk Seed" produces a completely different-looking but equally "valid" (equally arbitrary) path.
  • Use the triangle markers as the indicator's actual tradeable output: they fire on the "wicked past the band then rejected, closed back inside on the correct side of the basis" pattern, with a "Length"-bar cooldown shared across both directions.
  • Enable "Filter Signals" to only accept signals aligned with the slower MA bias - reducing counter-trend catch-the-falling-knife attempts during a strong trend.
  • Because mEnd (the multiplier at the forecast's endpoint) is hard-clamped to [2.0, 5.0], keep "Multiplier" within (or reasonably close to) that range if you want the cone's ending width to track your chosen multiplier smoothly, avoiding a visible jump at the seam between the current band and the first forecast segment.

1.4 How the Indicator Works

Inputs & Roles

  • src ("Source", default: close): the price series underlying the Bollinger basis AND the entire forecast.
  • length ("Length", Integer, default: 20): the Bollinger lookback (SMA + stdev). Also doubles as the minimum cooldown bar count between two signals (see Flow 8).
  • baseMult ("Multiplier", Float, default: 2.0): the standard-deviation multiplier for the CURRENT Bollinger bands, and also the starting point (step=0) for the forecast multiplier.
  • projBars ("Forecast Bars", Integer, default: 50, 5-100): number of bars the forecast cone is drawn into the future.
  • trendLen ("Trend Length", Integer, default: 50, min 10): the lookback used to estimate the slope (via linear regression, ta.linreg) of the basis/deviation/ATR.
  • projMode ("Forecast Band Mode", options: Trend/Curved/ Bollinger style/ATR style/Smoothed, default: "Curved"): selects the forecast width formula (see Flow 5 - the forecast basis is identical for 4 of the 5 modes).
  • projStyleOpt / projWidth: line style & width for the forecast bands.
  • projBasisCol/projUpperCol/projLowerCol/projFillCol/projFillOn: colors + fill toggle for the forecast cone.
  • swings ("Price ZigZags", Integer, default: 3, 1-10): number of zigzag swings in the illustrative price path (vertex count = swings×2+1).
  • zzAmpUnits ("Amplitude", Float, default: 1.1): zigzag amplitude measured in the forecast cone's half-width units at that point.
  • zzDecay ("Decay", Float, default: 0.75): the geometric decay factor applied to the zigzag amplitude each swing (next swing = previous × zzDecay).
  • pathStyleOpt/pathWidth/pathCol: style/width/color for the illustrative price path, fully separate from the forecast bands' style.
  • rwOn ("Blend Random Walk into ZigZag", Boolean, default: true): toggles blending a pseudo-random walk into the zigzag path.
  • rwMix ("(0=none, 1=strong)", Float, default: 0.8): the weight of the random-walk component in the final path.
  • rwStepUnits ("Amplitude", Float, default: 0.35): the size of each random-walk step, in band-width units.
  • rwStepDecay ("Decay", Float, default: 0.90): the decay factor applied to the random-walk step size each swing.
  • rwSeed ("Random Walk Seed", Integer, default: 1337): the seed for the pseudo-random sequence - the same seed + same bar_index always produces the SAME path (see the Note below on the actual scope of "stability").
  • sigShow/sigFilterMA/sigMaType/sigMaLen: toggle signals, toggle the MA-bias filter, the filter MA's type and length.
  • sigBullCol/sigBearCol/sigShowMA/sigMaCol: bullish/bearish signal colors, and toggle + color for displaying the filter MA on the chart.
💡 Note 1 - 4 of 5 modes share ONE basis formula: the basisAt() function has only 2 branches: "Trend" uses a straight line (bbBasis + bSlope×step), while ALL 4 other modes (Curved, Bollinger style, ATR style, Smoothed) use the EXACT SAME eased S-curve formula toward bEnd. The difference between modes mostly lives in the WIDTH formula (halfWidthAt()), not the basis path - the one exception is "Smoothed", which reuses the exact same raw linear width formula as "Trend", but then applies an extra recursive EMA-style smoothing layer (0.35 per step, compounding step-to-step) inside the drawing loop - THAT is the real source of its smoothness, not a different trend formula.

Main Logic Blocks

🎯 Flow 1: Current Bollinger Bands

  • bbBasis = SMA(src, length), bbDev = stdev(src, length), bbW = baseMult × bbDev, bbUpper/bbLower = bbBasis ± bbW - standard Bollinger Bands, plotted and filled like a normal BB indicator.

📐 Flow 2: Slope Estimation via Linear Regression

  • For each of the 3 series (basis, standard deviation, ATR14): takes the linear regression value (ta.linreg, NOT the raw value) at the current bar and 1 bar back, the difference is the slope (bSlope/dSlope/aSlope) - using linreg instead of a raw difference gives a smoother, less noisy slope.
  • The standard deviation series also gets an extra devAccel - an approximate second derivative (the difference of consecutive differences) - measuring whether volatility's RATE OF CHANGE is itself accelerating, used exclusively by "Bollinger style" mode.

🎚️ Flow 3: Endpoint & Multiplier Interpolation

  • bEnd/dEnd = linear extrapolation of basis/deviation out to projBars bars (dEnd floored at 0). ratio = dEnd/bbDev (how much volatility is expected to expand/contract, in %). mEndRaw = baseMult × (1 + ratio - 1) - the multiplier AT THE ENDPOINT also gets scaled by that same expected % change in volatility.
  • mEnd = clamp(mEndRaw, 2.0, 5.0) - ALWAYS hard-clamped into [2, 5] regardless of baseMult. multAt(step) smoothly interpolates (easeInOut) from baseMult (step=0) to mEnd (step=projBars), and re-clamps into [2,5] at EVERY intermediate step too, not just the endpoint.
  • Example: bbBasis=1.2600, bSlope=0.0002/bar, projBars=50 → bEnd=1.2600+0.0002×50=1.2700. bbDev=0.0050, dSlope=0.00005/bar → dEnd=0.0050+0.00005×50=0.0075. ratio=0.0075/0.0050=1.5. If baseMult=1.0 → mEndRaw=1.0×1.5=1.5 → mEnd=clamp(1.5,2,5)=2.0 (clamped UP, creating a visible jump versus the current band's baseMult=1.0).

📈 Flow 4: Forecast Basis

  • basisAt(step): if mode="Trend" → a straight line bbBasis + bSlope×step. Every other mode → the curved bbBasis + (bEnd-bbBasis)×easeInOut(step/projBars) - a smooth S-curve from the current basis to bEnd, accelerating then decelerating (not linear).

📏 Flow 5: Forecast Half-Width by Mode

  • "ATR style": completely IGNORES bbDev/multAt - extrapolates + eases ATR14 separately to aEnd, width = aF × 2.0 (a fixed multiplier, unrelated to baseMult).
  • "Bollinger style": accelTerm = 0.25×devAccel×step² (a quadratic term driven by volatility's acceleration - the further into the future, the more this term's influence grows quadratically); dBreathe = dTrend + accelTerm (floored at 0); then it gets PULLED BACK partially (up to 90% at t=1) toward the current bbDev - combining acceleration-driven "breathing" WITH a mean-reversion pull; multiplied by multAt(step).
  • "Curved": the deviation is also smoothly eased (same style as the basis formula) from bbDev to dEnd, multiplied by multAt(step).
  • "Trend" and "Smoothed": share the simplest formula - a linear extrapolation of bbDev to dTrend at that step, multiplied by multAt(step) (no separate easing for the width - "Smoothed"'s smoothness comes from Flow 6, not here).
  • Example ("Bollinger style"): step=25/50, devAccel=0.00002 → accelTerm=0.25×0.00002×625=0.003125. Suppose dTrend at step 25 = 0.0060 → dBreathe=0.009125. t=0.5 → dMR=0.009125-(0.009125-0.0050)×0.45≈0.007269. This gets multiplied further by multAt(25).

🖊️ Flow 6: Drawing the Forecast Cone (last bar only)

  • Runs inside the if barstate.islast block: first wipes every old forecast line/fill, then loops step = 1 to projBars, drawing one SEGMENT per step (not one continuous line) linking the previous step's endpoint to the new point - a total of 3×projBars segments for the 3 bands (basis/upper/lower), which is why max_lines_count=500 is declared at the top of the file.
  • If mode="Bollinger style": applies an extra 50% EMA-style smoothing layer to the WIDTH only (smW := smW + (wRaw-smW)×0.5), based on the already-smoothed smW value from the PREVIOUS step (recursive, compounding across steps). If mode="Smoothed": applies a 35% EMA-style smoothing layer to BOTH basis and width, also recursively - this is exactly where "Smoothed" becomes visually distinct from "Trend" despite sharing the same raw formula.
  • If projFillOn: also creates a linefill between the upper/lower segment for EACH step (the fill zone is also chained segment-by-segment, not one continuous shape).

〰️ Flow 7: Drawing the Illustrative Price Path (ZigZag + Random Walk)

  • pts = swings×2+1 vertices, spaced evenly by proportional position (stepK) along the projBars axis. The starting point = the CURRENT src price (not bbBasis) at the current bar_index.
  • At each vertex: z = zigOffset(k-1) = alternating direction (+1/-1) × geometrically decaying amplitude (zzAmpUnits × zzDecay^(k-1)). pZ = bA + wA×z (the pure zigzag point, using the projected basis/width AT that specific stepK - which gets the same kind of smoothing as Flow 6 if mode="Bollinger style"/"Smoothed", but this time anchored to the FIXED current bbBasis/bbW, NOT a recursive accumulator carried across vertices like in Flow 6 - two genuinely different smoothing mechanisms despite similar-looking formulas).
  • If rwOn is on: computes one deterministic pseudo-random value from rwSeed + bar_index×0.001 + k×17.0 + stepK×0.13 via the hashSigned() function (based on sin()), multiplies by the amplitude and decay, then ACCUMULATES it into rwAcc (a genuine random walk - each step adds to a running total, not independent noise each time). Final price = pZ + rwMix×rwAcc×wA.
  • Illustrative example (hash value is illustrative only): rwSeed=1337, bar_index=10000, k=1, stepK=17 → key≈1366.21. Suppose hashSigned(key)≈0.42 → step=0.42×0.35×0.90⁰=0.147 → rwAcc=0.147. This vertex's price shifts an extra 0.8×0.147×wA away from the pure zigzag point.

🎯 Flow 8: Mean-Reversion Signal Detection (every bar)

  • bearHit: current high < bbUpper (pulled back inside) AND high[1] ≥ bbUpper[1] (the previous bar had touched/exceeded ITS OWN upper band) AND close > bbBasis (still in the upper half) AND at least length bars have passed since the last signal (BOTH directions share one cooldown counter, lastSigBar). bullHit is symmetric using the lower band.
  • If sigFilterMA is on: bearHit additionally requires close < sigMA; bullHit requires close > sigMA.
  • Example: bbUpper=1.2650 at bar 500. Bar 499: high[1]=1.2655 ≥ bbUpper[1]=1.2648. Bar 500: high=1.2645 < 1.2650, close=1.2620 > bbBasis=1.2600, and 500-450=50 ≥ length=20 → bearHit=true. If sigFilterMA is on and close(1.2620) < sigMA(1.2630) → confirmed, sigDn=true, lastSigBar:=500.

🔺 Flow 9: Drawing Signal Markers

  • sigOffset = EMA(ATR14, 200) - a very slow-moving (200-bar) padding distance, used to offset the triangles away from the band lines to avoid overlap.
  • Each direction draws 2 layered plotshapes at the SAME coordinates: one small, solid triangle + one larger, more transparent one (60% transparent) - creating a soft "glow" effect around the signal. Down is placed at bbUpper+sigOffset, Up at bbLower-sigOffset.

Outputs & Usage Roles

  • Current Bollinger Bands: the standard foundation for reading relative price position.
  • Forecast cone: a visual illustration of "what the bands might look like" if the current basis/volatility trend continues under the chosen formula - NOT a statistical commitment or probability.
  • Zigzag/random-walk price path: ONE possible illustrative route through the cone, carrying no independent predictive information.
  • Triangle signal markers: the indicator's actual tradeable output - pinpoint exactly when a band-rejection pattern occurred, with a cooldown and optional bias filter.
💡 Note 2 - the real scope of random-walk "stability": the original tooltip describes the seed as staying "stable on redraws" - this is only true WITHIN the SAME bar_index (i.e. repaints of the exact same live, still-forming last bar - e.g. multiple ticks within one unclosed bar). The moment a NEW bar becomes the last bar, bar_index changes → every hash key changes → a completely different-looking "random" path (though still fully deterministic and reproducible) gets drawn. Don't read "stable" as "permanently fixed over time".
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