Iván González

Laguerre Structure Levels

Category: Indicators By: Iván González Created: November 20, 2026, 10:55 AM
November 20, 2026, 10:55 AM
Indicators
0 Comments
Laguerre Structure Levels

Introduction

 

A trend filter tells you the direction; it does not tell you where to act. Laguerre Structure Levels by BOSWaves joins both. A four-stage Laguerre filter with a short ribbon defines the trend, and the swing structure around it is turned into a few support and resistance zones: a strong origin level at the swing that started each new trend, and lighter continuation levels at the pullbacks that formed close to the ribbon. Levels are removed when price closes through them, and the first return into a level after price has moved away is marked as a retest.

Theory Behind the Indicator

 

Laguerre filter. The Laguerre filter runs the price (typical price by default) through four chained stages controlled by one factor, gamma (0.72). The output is a weighted average of the four stages, (L0 + 2·L1 + 2·L2 + L3) / 6: a smooth line with much less lag than a simple average of the same smoothness. Higher gamma gives a smoother, slower line.

Ribbon and trend. The ribbon is an 8-bar EMA of the filter. The trend turns bullish when three things are true: the close is above the filter by more than 0.20 ATR, the filter is higher than it was 2 bars ago, and the filter is above the ribbon. The bearish flip is the mirror case. Between flips the trend keeps its direction, so small whipsaws around the line do not change it.

Origin levels. On a bullish flip, all bearish levels are cleared and the last swing low (a pivot with 5 bars on each side) becomes a solid origin level, as long as it is not older than 100 bars. On a bearish flip, the last swing high becomes a bearish origin level. This is the swing that the new trend started from.

Continuation levels. During a bullish trend, a new swing low that forms within 0.80 ATR of the ribbon becomes a dotted continuation level: a pullback that held near the trend line. Swing highs near the ribbon do the same in a bearish trend.

Zones, merging and removal. Each level is a zone of ±0.12 ATR around the swing price, with a stronger inner core and a line. A new level closer than 0.30 ATR to an existing level of the same side is not added, and only the 4 most recent levels are kept. A bullish level is removed when a candle closes below its zone by more than 0.08 ATR, a bearish one when a candle closes above it.

Retests. Once price has moved completely away from a level, the next touch of its zone, with the trend still pointing the same way, is marked with a diamond. Each move away arms the level again.

Key Features at a Glance

 

  • Laguerre trend line with an EMA ribbon and a two-layer glow.
  • Gradient fills between price and the trend line, and between the trend line and the ribbon.
  • Trend flips filtered by an ATR buffer, the slope of the filter and its position against the ribbon.
  • Origin levels at the swing that started each trend, continuation levels at pullbacks near the ribbon.
  • ATR based zone thickness, merge distance and break buffer.
  • Triangle markers on trend flips and diamond markers on level retests.

How to Read the Indicator

 

  • Green line and ribbon: bullish trend. Red line and ribbon: bearish trend.
  • Gradient between price and the line: the wider and stronger it is, the further price has stretched away from the trend line.
  • Solid level with a thick line: origin level, the swing low (or high) the current trend started from. A close through it is a strong sign that the trend has failed.
  • Dotted level: continuation level, a pullback that held near the ribbon. It is the next reference for pullbacks in the same trend.
  • Triangle: the bar where the trend flipped. Diamond: the first return into a level after price moved away from it.

Practical Applications

 

  • Pullback entries. In a bullish trend, a diamond on a green level marks price returning to a support that has already held. The far side of the zone plus the break buffer is a natural place for the stop.
  • Trend failure. When price closes through the origin level, the structure that defined the trend is gone even if the line has not flipped yet.
  • Trailing reference. As the trend develops, new continuation levels step up behind price; they can be used to trail a stop.
  • Filter for other signals. Take only the signals of your own system that agree with the colour of the trend line.

Indicator Configuration

 

  • gamma (default: 0.72): Laguerre smoothing factor, from 0.10 to 0.95.
  • ribbonLen (default: 8): EMA length of the ribbon.
  • atrLen (default: 14): ATR length used by every ATR distance.
  • flipBuffer (default: 0.20): ATR distance the close must clear beyond the trend line before the trend can flip.
  • slopeLookback (default: 2): bars back used to measure the slope of the trend line.
  • swingLen (default: 5): bars on each side of a swing pivot.
  • maxLevels (default: 4): maximum levels kept on the chart, from 1 to 10.
  • pullbackATR (default: 0.80): maximum ATR distance from the ribbon for a continuation level.
  • zoneATR (default: 0.12): zone thickness in ATR.
  • mergeATR (default: 0.30): minimum ATR distance between two levels of the same side.
  • breakATR (default: 0.08): ATR distance a close must clear beyond a zone to remove the level.
  • originMaxAge (default: 100): maximum age in bars of the swing used for an origin level.
  • showOrigin, showCont, showRetests (default: 1): origin levels, continuation levels and retest markers.
  • zoneExtend (default: 20): bars the levels are drawn beyond the last bar.
  • showPriceFill, showRibbon, showGlow, showSignals (default: 1): price gradient, ribbon, glow and flip markers.
  • The source is the typical price, set in the line src = typicalprice. The width of the trend line can be changed in the indicator properties.
  • Colour variables at the top of the code: bullish and bearish.

Code

 

//---------------------------------------------------------------
// PRC_Laguerre Structure
// version = 0
// 20.11.2026
// Iván González @ www.prorealcode.com
// Author: BOSWaves
// Sharing ProRealTime knowledge
//--------------------------------------------------------------------//
defparam drawonlastbaronly = true

// ===================== INPUTS
// --- Trend engine (source = typical price, (high + low + close) / 3)
gamma = 0.72           // Laguerre smoothing factor (0.10 to 0.95)
ribbonLen = 8          // EMA length of the trend ribbon
atrLen = 14            // ATR length
flipBuffer = 0.20      // ATR distance beyond the filter needed to flip the trend
slopeLookback = 2      // bars back used to measure the filter slope
// --- Structure levels
swingLen = 5           // pivot length (2 to 30)
maxLevels = 4          // maximum structure levels kept (1 to 10)
pullbackATR = 0.80     // max ATR distance from the ribbon for a continuation level
zoneATR = 0.12         // zone thickness in ATR
mergeATR = 0.30        // minimum ATR distance between two levels of the same side
breakATR = 0.08        // ATR distance beyond the zone that removes a level
originMaxAge = 100     // max age in bars of the swing that creates an origin level
showOrigin = 1         // trend origin levels
showCont = 1           // continuation levels
showRetests = 1        // level retest markers
zoneExtend = 20        // bars the levels are drawn past the last bar
// --- Signals and display
showPriceFill = 1      // gradient fill between price and the trend line
showRibbon = 1         // trend ribbon line and its fill
showGlow = 1           // glow around the trend line
showSignals = 1        // triangle markers on trend flips

// ===================== COLORS
bullR = 0
bullG = 255
bullB = 102
bearR = 255
bearG = 0
bearB = 102

// ===================== LAGUERRE ENGINE
src = typicalprice
IF barindex = 0 THEN
   pl0 = src
   pl1 = src
   pl2 = src
   pl3 = src
ELSE
   pl0 = l0[1]
   pl1 = l1[1]
   pl2 = l2[1]
   pl3 = l3[1]
ENDIF
l0 = (1 - gamma) * src + gamma * pl0
l1 = 0 - gamma * l0 + pl0 + gamma * pl1
l2 = 0 - gamma * l1 + pl1 + gamma * pl2
l3 = 0 - gamma * l2 + pl2 + gamma * pl3
filt = (l0 + 2 * l1 + 2 * l2 + l3) / 6

// ribbon: EMA of the filter seeded with its simple average
IF barindex = ribbonLen - 1 THEN
   ribbon = average[ribbonLen](filt)
ELSIF barindex >= ribbonLen THEN
   ribbon = ribbon[1] + (2 / (ribbonLen + 1)) * (filt - ribbon[1])
ENDIF
ribbonOk = barindex >= ribbonLen - 1
atrV = averagetruerange[atrLen](close)
atrOk = barindex >= atrLen - 1

bullReady = 0
bearReady = 0
IF ribbonOk AND atrOk AND barindex >= slopeLookback THEN
   IF close > filt + atrV * flipBuffer AND filt > filt[slopeLookback] AND filt > ribbon THEN
      bullReady = 1
   ENDIF
   IF close < filt - atrV * flipBuffer AND filt < filt[slopeLookback] AND filt < ribbon THEN
      bearReady = 1
   ENDIF
ENDIF

ONCE trend = 0
IF bullReady = 1 THEN
   trend = 1
ELSIF bearReady = 1 THEN
   trend = -1
ELSIF trend = 0 THEN
   IF ribbonOk AND filt >= ribbon THEN
      trend = 1
   ELSE
      trend = -1
   ENDIF
ENDIF
bullFlip = 0
bearFlip = 0
IF barindex > 0 THEN
   IF trend = 1 AND trend[1] = -1 THEN
      bullFlip = 1
   ENDIF
   IF trend = -1 AND trend[1] = 1 THEN
      bearFlip = 1
   ENDIF
ENDIF
IF trend = 1 THEN
   cR = bullR
   cG = bullG
   cB = bullB
ELSE
   cR = bearR
   cG = bearG
   cB = bearB
ENDIF

// ===================== SWING STRUCTURE
ONCE lastPH = 0
ONCE lastPL = 0
ONCE lastPHBar = -1
ONCE lastPLBar = -1
isPH = 0
isPL = 0
hhR = highest[swingLen](high)
llR = lowest[swingLen](low)
IF barindex >= 2 * swingLen THEN
   IF high[swingLen] > hhR AND high[swingLen] >= hhR[swingLen + 1] THEN
      isPH = 1
      phV = high[swingLen]
      lastPH = phV
      lastPHBar = barindex - swingLen
   ENDIF
   IF low[swingLen] < llR AND low[swingLen] <= llR[swingLen + 1] THEN
      isPL = 1
      plV = low[swingLen]
      lastPL = plV
      lastPLBar = barindex - swingLen
   ENDIF
ENDIF

// ===================== LEVEL STATE (double buffer by bar parity: arrays are not rewound between ticks)
// fields: price, top, bottom, direction, origin, armed, pivot bar, zone height
stride = 12
pb = barindex MOD 2
ob = pb * stride
oq = (1 - pb) * stride
ONCE nL = 0
IF barindex = 0 THEN
   nL = 0
ENDIF
IF nL > 0 THEN
   FOR i = 0 TO nL - 1 DO
      $lvP[ob + i] = $lvP[oq + i]
      $lvT[ob + i] = $lvT[oq + i]
      $lvB[ob + i] = $lvB[oq + i]
      $lvD[ob + i] = $lvD[oq + i]
      $lvO[ob + i] = $lvO[oq + i]
      $lvA[ob + i] = $lvA[oq + i]
      $lvX[ob + i] = $lvX[oq + i]
      $lvH[ob + i] = $lvH[oq + i]
   NEXT
ENDIF

// --- a trend flip clears the levels of the opposite side
clearDir = 0
IF bullFlip = 1 THEN
   clearDir = 1
ELSIF bearFlip = 1 THEN
   clearDir = -1
ENDIF
IF clearDir <> 0 AND nL > 0 THEN
   FOR i = nL - 1 DOWNTO 0 DO
      IF $lvD[ob + i] <> clearDir THEN
         IF i < nL - 1 THEN
            FOR j = i TO nL - 2 DO
               $lvP[ob + j] = $lvP[ob + j + 1]
               $lvT[ob + j] = $lvT[ob + j + 1]
               $lvB[ob + j] = $lvB[ob + j + 1]
               $lvD[ob + j] = $lvD[ob + j + 1]
               $lvO[ob + j] = $lvO[ob + j + 1]
               $lvA[ob + j] = $lvA[ob + j + 1]
               $lvX[ob + j] = $lvX[ob + j + 1]
               $lvH[ob + j] = $lvH[ob + j + 1]
            NEXT
         ENDIF
         nL = nL - 1
      ENDIF
   NEXT
ENDIF

// --- candidate levels of this bar, in the order the original adds them
nAdd = 0
IF bullFlip = 1 AND showOrigin = 1 AND lastPLBar >= 0 THEN
   IF barindex - lastPLBar <= originMaxAge THEN
      $adP[nAdd] = lastPL
      $adX[nAdd] = lastPLBar
      $adD[nAdd] = 1
      $adO[nAdd] = 1
      IF lastPLBar >= atrLen - 1 THEN
         $adAtr[nAdd] = atrV[barindex - lastPLBar]
      ELSE
         $adAtr[nAdd] = atrV
      ENDIF
      nAdd = nAdd + 1
   ENDIF
ENDIF
IF bearFlip = 1 AND showOrigin = 1 AND lastPHBar >= 0 THEN
   IF barindex - lastPHBar <= originMaxAge THEN
      $adP[nAdd] = lastPH
      $adX[nAdd] = lastPHBar
      $adD[nAdd] = -1
      $adO[nAdd] = 1
      IF lastPHBar >= atrLen - 1 THEN
         $adAtr[nAdd] = atrV[barindex - lastPHBar]
      ELSE
         $adAtr[nAdd] = atrV
      ENDIF
      nAdd = nAdd + 1
   ENDIF
ENDIF
IF showCont = 1 AND barindex >= swingLen + ribbonLen - 1 THEN
   IF barindex - swingLen >= atrLen - 1 THEN
      pivotAtr = atrV[swingLen]
   ELSE
      pivotAtr = atrV
   ENDIF
   ribTop = max(filt[swingLen], ribbon[swingLen])
   ribBot = min(filt[swingLen], ribbon[swingLen])
   IF isPL = 1 AND trend[swingLen] = 1 THEN
      IF plV < ribBot THEN
         distC = ribBot - plV
      ELSIF plV > ribTop THEN
         distC = plV - ribTop
      ELSE
         distC = 0
      ENDIF
      IF distC <= pivotAtr * pullbackATR THEN
         $adP[nAdd] = plV
         $adX[nAdd] = barindex - swingLen
         $adD[nAdd] = 1
         $adO[nAdd] = 0
         $adAtr[nAdd] = pivotAtr
         nAdd = nAdd + 1
      ENDIF
   ENDIF
   IF isPH = 1 AND trend[swingLen] = -1 THEN
      IF phV > ribTop THEN
         distC = phV - ribTop
      ELSIF phV < ribBot THEN
         distC = ribBot - phV
      ELSE
         distC = 0
      ENDIF
      IF distC <= pivotAtr * pullbackATR THEN
         $adP[nAdd] = phV
         $adX[nAdd] = barindex - swingLen
         $adD[nAdd] = -1
         $adO[nAdd] = 0
         $adAtr[nAdd] = pivotAtr
         nAdd = nAdd + 1
      ENDIF
   ENDIF
ENDIF

// --- add each candidate unless a level of the same side is closer than the merge distance
IF nAdd > 0 AND atrOk THEN
   FOR ai = 0 TO nAdd - 1 DO
      newP = $adP[ai]
      newD = $adD[ai]
      lvAtr = $adAtr[ai]
      addIt = 1
      IF nL > 0 THEN
         FOR i = 0 TO nL - 1 DO
            IF $lvD[ob + i] = newD AND abs($lvP[ob + i] - newP) <= lvAtr * mergeATR THEN
               addIt = 0
               BREAK
            ENDIF
         NEXT
      ENDIF
      IF addIt = 1 THEN
         // newest level goes first; the oldest one drops out past maxLevels
         IF nL > 0 THEN
            FOR i = nL - 1 DOWNTO 0 DO
               $lvP[ob + i + 1] = $lvP[ob + i]
               $lvT[ob + i + 1] = $lvT[ob + i]
               $lvB[ob + i + 1] = $lvB[ob + i]
               $lvD[ob + i + 1] = $lvD[ob + i]
               $lvO[ob + i + 1] = $lvO[ob + i]
               $lvA[ob + i + 1] = $lvA[ob + i]
               $lvX[ob + i + 1] = $lvX[ob + i]
               $lvH[ob + i + 1] = $lvH[ob + i]
            NEXT
         ENDIF
         zoneH = lvAtr * zoneATR
         $lvP[ob] = newP
         $lvT[ob] = newP + zoneH
         $lvB[ob] = newP - zoneH
         $lvD[ob] = newD
         $lvO[ob] = $adO[ai]
         $lvA[ob] = 0
         $lvX[ob] = $adX[ai]
         $lvH[ob] = zoneH
         nL = nL + 1
         IF nL > maxLevels THEN
            nL = maxLevels
         ENDIF
      ENDIF
   NEXT
ENDIF

// ===================== LEVEL LIFECYCLE
bullRetest = 0
bearRetest = 0
IF nL > 0 AND atrOk THEN
   FOR i = nL - 1 DOWNTO 0 DO
      IF $lvD[ob + i] = 1 THEN
         isInvalid = close < $lvB[ob + i] - atrV * breakATR
      ELSE
         isInvalid = close > $lvT[ob + i] + atrV * breakATR
      ENDIF
      IF isInvalid THEN
         IF i < nL - 1 THEN
            FOR j = i TO nL - 2 DO
               $lvP[ob + j] = $lvP[ob + j + 1]
               $lvT[ob + j] = $lvT[ob + j + 1]
               $lvB[ob + j] = $lvB[ob + j + 1]
               $lvD[ob + j] = $lvD[ob + j + 1]
               $lvO[ob + j] = $lvO[ob + j + 1]
               $lvA[ob + j] = $lvA[ob + j + 1]
               $lvX[ob + j] = $lvX[ob + j + 1]
               $lvH[ob + j] = $lvH[ob + j + 1]
            NEXT
         ENDIF
         nL = nL - 1
      ELSE
         IF $lvD[ob + i] = 1 THEN
            isOutside = low > $lvT[ob + i]
         ELSE
            isOutside = high < $lvB[ob + i]
         ENDIF
         isTouch = high >= $lvB[ob + i] AND low <= $lvT[ob + i]
         IF isOutside THEN
            $lvA[ob + i] = 1
         ELSIF $lvA[ob + i] = 1 AND isTouch AND trend = $lvD[ob + i] THEN
            $lvA[ob + i] = 0
            IF $lvD[ob + i] = 1 THEN
               bullRetest = 1
            ELSE
               bearRetest = 1
            ENDIF
         ENDIF
      ENDIF
   NEXT
ENDIF

// ===================== SIGNAL MARKERS (stored per event, redrawn on the last bar)
// a plain assignment indexed by a scalar is rewritten identically on every tick
ONCE nEv = 0
IF showSignals = 1 AND bullFlip = 1 THEN
   $evX[nEv] = barindex
   $evY[nEv] = low - atrV * 0.3
   $evK[nEv] = 1
   nEv = nEv + 1
ENDIF
IF showSignals = 1 AND bearFlip = 1 THEN
   $evX[nEv] = barindex
   $evY[nEv] = high + atrV * 0.3
   $evK[nEv] = 2
   nEv = nEv + 1
ENDIF
IF showRetests = 1 AND bullRetest = 1 THEN
   $evX[nEv] = barindex
   $evY[nEv] = low - atrV * 0.7
   $evK[nEv] = 3
   nEv = nEv + 1
ENDIF
IF showRetests = 1 AND bearRetest = 1 THEN
   $evX[nEv] = barindex
   $evY[nEv] = high + atrV * 0.7
   $evK[nEv] = 4
   nEv = nEv + 1
ENDIF

// ===================== FILLS
glow = atrV * 0.045
outerGlow = glow * 2.2
// price gradient: strong next to the trend line, fading toward price
pf1 = filt + (close - filt) * 0.25
pf2 = filt + (close - filt) * 0.50
pf3 = filt + (close - filt) * 0.75
IF showPriceFill = 1 THEN
   pa0 = 181
   pa1 = 135
   pa2 = 89
   pa3 = 43
ELSE
   pa0 = 0
   pa1 = 0
   pa2 = 0
   pa3 = 0
ENDIF
// ribbon gradient: strong next to the trend line, fading toward the ribbon
IF ribbonOk THEN
   ribEnd = ribbon
ELSE
   ribEnd = filt
ENDIF
rf1 = filt + (ribEnd - filt) * 0.25
rf2 = filt + (ribEnd - filt) * 0.50
rf3 = filt + (ribEnd - filt) * 0.75
IF showRibbon = 1 THEN
   ra0 = 187
   ra1 = 142
   ra2 = 98
   ra3 = 53
   ribLineA = 107
ELSE
   ra0 = 0
   ra1 = 0
   ra2 = 0
   ra3 = 0
   ribLineA = 0
ENDIF
IF atrOk THEN
   gOutU = filt + outerGlow
   gOutL = filt - outerGlow
   gInU = filt + glow
   gInL = filt - glow
ELSE
   gOutU = filt
   gOutL = filt
   gInU = filt
   gInL = filt
ENDIF
IF showGlow = 1 THEN
   goA = 18
   giA = 71
ELSE
   goA = 0
   giA = 0
ENDIF
COLORBETWEEN(filt, pf1, cR, cG, cB, pa0)
COLORBETWEEN(pf1, pf2, cR, cG, cB, pa1)
COLORBETWEEN(pf2, pf3, cR, cG, cB, pa2)
COLORBETWEEN(pf3, close, cR, cG, cB, pa3)
COLORBETWEEN(filt, rf1, cR, cG, cB, ra0)
COLORBETWEEN(rf1, rf2, cR, cG, cB, ra1)
COLORBETWEEN(rf2, rf3, cR, cG, cB, ra2)
COLORBETWEEN(rf3, ribEnd, cR, cG, cB, ra3)
COLORBETWEEN(gOutL, gOutU, cR, cG, cB, goA)
COLORBETWEEN(gInL, gInU, cR, cG, cB, giA)

// ===================== DRAWING (last bar only)
IF islastbarupdate THEN
   xEnd = barindex + zoneExtend
   IF nL > 0 THEN
      FOR i = 0 TO nL - 1 DO
         IF $lvD[ob + i] = 1 THEN
            zR = bullR
            zG = bullG
            zB = bullB
         ELSE
            zR = bearR
            zG = bearG
            zB = bearB
         ENDIF
         lvPx = $lvP[ob + i]
         lvX1 = $lvX[ob + i]
         innerH = $lvH[ob + i] * 0.42
         IF $lvO[ob + i] = 1 THEN
            DRAWRECTANGLE(lvX1, $lvT[ob + i], xEnd, $lvB[ob + i]) COLOURED(zR, zG, zB, 0) FILLCOLOR(zR, zG, zB, 31)
            DRAWRECTANGLE(lvX1, lvPx + innerH, xEnd, lvPx - innerH) COLOURED(zR, zG, zB, 0) FILLCOLOR(zR, zG, zB, 82)
            DRAWSEGMENT(lvX1, lvPx, xEnd, lvPx) COLOURED(zR, zG, zB, 242) STYLE(line, 2)
         ELSE
            DRAWRECTANGLE(lvX1, $lvT[ob + i], xEnd, $lvB[ob + i]) COLOURED(zR, zG, zB, 0) FILLCOLOR(zR, zG, zB, 20)
            DRAWRECTANGLE(lvX1, lvPx + innerH, xEnd, lvPx - innerH) COLOURED(zR, zG, zB, 0) FILLCOLOR(zR, zG, zB, 56)
            DRAWSEGMENT(lvX1, lvPx, xEnd, lvPx) COLOURED(zR, zG, zB, 199) STYLE(dottedline, 1)
         ENDIF
      NEXT
   ENDIF
   IF nEv > 0 THEN
      FOR ev = 0 TO nEv - 1 DO
         evType = $evK[ev]
         IF evType = 1 THEN
            DRAWTEXT("▲", $evX[ev], $evY[ev]) COLOURED(bullR, bullG, bullB, 255)
         ELSIF evType = 2 THEN
            DRAWTEXT("▼", $evX[ev], $evY[ev]) COLOURED(bearR, bearG, bearB, 255)
         ELSIF evType = 3 THEN
            DRAWTEXT("♦", $evX[ev], $evY[ev]) COLOURED(bullR, bullG, bullB, 255)
         ELSE
            DRAWTEXT("♦", $evX[ev], $evY[ev]) COLOURED(bearR, bearG, bearB, 255)
         ENDIF
      NEXT
   ENDIF
ENDIF

RETURN filt COLOURED(cR, cG, cB, 255) STYLE(line, 3) AS "Laguerre Trend", ribbon COLOURED(cR, cG, cB, ribLineA) STYLE(line, 2) AS "Ribbon"

Original author: BOSWaves, published open source under the Mozilla Public License 2.0.

Download
Filename: PRC_Laguerre-Structure.itf
Downloads: 14
Iván González
Iván González Legend
Currently debugging life, so my bio is on hold. Check back after the next commit for an update.
Author’s Profile

Comments

ProRealCode ProRealCode
Loading...