Laguerre-Smoothed, Integrated-Regression LASIR For ThinkOrSwim

whoDAT

Active member
Plus
Laguerre-Smoothed, Integrated-Regression Trend Analysis - (aka "The LASIR")
The LaSIR (Laguerre Smoothed Integrated Regression), is a sophisticated trend-following indicator. It moves away from simple price action and instead measures the accumulated energy (the "area") between two smoothed regression lines.

nRIV4IO.png


Here is a breakdown of how the engine functions and what it signals.

1. The Core Components
The Laguerre Filter (The "Noise Canceller")


Before any math happens, the code applies a 4-pole Laguerre filter.
  • Purpose: Unlike a simple moving average, Laguerre filters are designed to provide high smoothing with very low lag.
  • The Gamma Factor: At the default 0.8, the script heavily filters out "market noise" to focus on the underlying price cycle.
The Regression Engine
The study calculates two lines (Slow and Fast) using a specific sequence:
  1. Log Transformation: It takes the natural log of the price to normalize percentage moves.
  2. Linear Regression (Inertia): It finds the "line of best fit" for the price over 45 periods.
  3. Exp Reversion: It converts the log values back to standard price units.
  4. Moving Average Smoothing: It applies a massive Weighted Moving Average (600 and 1200 periods) to the result.
The Integration (The "Area" Math)
This is the most unique part of the study. Instead of just looking at the FastLine crossing the SlowLine, it calculates the cumulative sum of the spread between them.
  • Every bar where the Fast line is above the Slow line adds to the "Area."
  • Every bar below subtracts from it.
  • The Reset: The "engine" resets its calculation only when a crossover occurs.

2. Trend Classification
The indicator categorizes the market into three states based on the AreaThreshold (default 5000):

StateConditionVisual ColorInterpretation
Bullish TrendArea > 5000CyanSignificant momentum has "built up" to the upside.
Bearish TrendArea < -5000YellowHeavy cumulative pressure to the downside.
ConsolidationBetween -5000 / 5000WhiteThe market lacks sufficient "integrated" momentum to confirm a trend.

3. Key Observations & Strategy Notes
  • Extreme Smoothing: With moving average lengths of 600 and 1200, this is a macro-trend tool. It is not designed for day trading or scalping; it is built to identify major regime shifts over weeks or months.
  • Momentum "Memory": Because it uses an areaInt (integrated area), the indicator has "memory." A small crossover won't immediately turn the trend Cyan or Yellow; the price must stay on one side of the regression long enough to "fill the tank" and cross the 5000 threshold.
  • The Zero-Line: The ZeroLine acts as the pivot. If the AreaPlot is moving toward zero, it suggests the current trend is exhausting, even if the label still says "TRENDING."
Summary for Use
The LaSIR is best used as a directional filter. If the Area is Cyan, you only look for long entries on lower-timeframe pullbacks. If it’s White, you expect "Chop" and might avoid trend-following strategies altogether until a threshold is breached.

Code:
# --- LAGUERRE SMOOTHED INTEGRATTED REGRESSION TREND ENGINE AKA THE LaSIR ---
# by whoDAT
# 4/2026

declare lower;

# --- INPUTS ---
input price = close;                  # <--- Dropdown: close, high, low, hl2, hlc3, ohlc4, open, etc.
#hint price: Select the base price type (raw price) to smooth with Laguerre

input gamma = 0.8;                   # Laguerre damping factor (0.2 = very responsive, 0.8 = smoother)
#hint gamma: Laguerre filter smoothing (lower = faster response, higher = smoother)

input regLength_Slow = 45;
input maLen_Slow = 1200;
input maType_Slow = AverageType.WEIGHTED;

input regLength_Fast = 45;
input maLen_Fast = 600;
input maType_Fast = AverageType.WEIGHTED;

input AreaThreshold = 5000.0;
input ShowTrendCloud = yes;

# --- LAGUERRE SMOOTHING ON RAW PRICE ---
# 4-pole Laguerre filter (standard Ehlers implementation)
def L0 = (1 - gamma) * price + gamma * L0[1];
def L1 = -gamma * L0 + L0[1] + gamma * L1[1];
def L2 = -gamma * L1 + L1[1] + gamma * L2[1];
def L3 = -gamma * L2 + L2[1] + gamma * L3[1];

def LaguerrePrice = (L0 + 2*L1 + 2*L2 + L3) / 6;   # Smoothed raw price

# --- MATH ENGINE (now using smoothed price) ---
def logPrice = log(LaguerrePrice);   # Log of the Laguerre-smoothed price

def SlowLine = MovingAverage(maType_Slow, exp(Inertia(logPrice, regLength_Slow)), maLen_Slow);
def FastLine = MovingAverage(maType_Fast, exp(Inertia(logPrice, regLength_Fast)), maLen_Fast);

# --- SPREAD & CROSSOVER ---
def rawSpread = FastLine - SlowLine;
def crossed = (rawSpread > 0 and rawSpread[1] <= 0) or (rawSpread < 0 and rawSpread[1] >= 0);

# --- AREA INTEGRATION ---
rec areaInt = if BarNumber() == 1 then 0
              else if crossed then rawSpread
              else areaInt[1] + rawSpread;

# --- PLOTS ---
plot AreaPlot = areaInt;
plot UpperLimit = AreaThreshold;
plot LowerLimit = -AreaThreshold;
plot ZeroLine = 0;

# --- TREND CONDITIONS ---
def isTrendingUp = areaInt > AreaThreshold;
def isTrendingDn = areaInt < -AreaThreshold;

# --- VISUALS ---
AreaPlot.SetLineWeight(2);
AreaPlot.AssignValueColor(if isTrendingUp then Color.CYAN
                          else if isTrendingDn then Color.YELLOW
                          else Color.WHITE);

UpperLimit.SetDefaultColor(Color.MAGENTA);
UpperLimit.SetStyle(Curve.SHORT_DASH);
LowerLimit.SetDefaultColor(Color.MAGENTA);
LowerLimit.SetStyle(Curve.SHORT_DASH);
ZeroLine.SetDefaultColor(Color.GRAY);

Added the following for better visuals:
# Optional Trend Clouds (uncomment if desired)
AddCloud(if ShowTrendCloud and isTrendingUp then AreaPlot else Double.NaN, UpperLimit, Color.BLUE, Color.CYAN);
AddCloud(LowerLimit, if ShowTrendCloud and isTrendingDn then AreaPlot else Double.NaN, Color.YELLOW, Color.DARK_RED);

# --- LABELS ---
AddLabel(yes, "Integrated Area: " + Round(areaInt, 2),
    if isTrendingUp then Color.CYAN
    else if isTrendingDn then Color.YELLOW
    else Color.WHITE);

AddLabel(isTrendingUp or isTrendingDn, "TRENDING", Color.GREEN);
AddLabel(!isTrendingUp and !isTrendingDn, "CONSOLIDATION / CHOP", Color.GRAY);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

after looking at several stocks, and none getting close to +-5000 levels, i disabled the +-5000 plots

white and cyan are too close in color for me, so i changed them to gray and yellow
AreaPlot.AssignValueColor(if isTrendingUp then Color.yellow
else if isTrendingDn then Color.YELLOW
else Color.gray);

fyi , this shows different slopes for different time frames.
 
after looking at several stocks, and none getting close to +-5000 levels, i disabled the +-5000 plots

white and cyan are too close in color for me, so i changed them to gray and yellow
AreaPlot.AssignValueColor(if isTrendingUp then Color.yellow
else if isTrendingDn then Color.YELLOW
else Color.gray);
The AreaThreshold input is to allow some headspace while a trend is occurring. At zero it will say "you're always in a uptrend or downtrend". Setting the threshold higher gives you headspace to also identify choppy market times.

The study was used for intraday Russell 2000 trend identification, so 5000 worked for that threshold.

Different time frames will have different slopes without optimizing the inputs. Changing from a 15-min to a 30-min timeframe (or any other) will require some optimization. This is due to the integration process. We're adding the sum of each timeframe, thus a 15-min chart will have twice the number of additions.

Added the following for better visuals:
# Optional Trend Clouds (uncomment if desired)
AddCloud(if ShowTrendCloud and isTrendingUp then AreaPlot else Double.NaN, UpperLimit, Color.BLUE, Color.CYAN);
AddCloud(LowerLimit, if ShowTrendCloud and isTrendingDn then AreaPlot else Double.NaN, Color.YELLOW, Color.DARK_RED);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1023 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top