OPEN-SOURCE SCRIPT
LSMA25 Trend Correction Continuation

## LSMA25 Trend Correction Continuation - Publishing Description
### Overview
This indicator highlights **trend continuation opportunities** using a **25-period LSMA (Least Squares Moving Average)** with a **slope/angle filter** and a simple **correction + re-entry** logic.
It is designed to mark:
* **Continuation entries** after a pullback (correction) and re-cross of LSMA in the direction of a strong trend
* **Strong-trend state** (subtle dots) when price stays on the trend side of LSMA with a steep angle, even without a fresh cross
### Core logic
1. **LSMA (25 by default)**
* Uses `ta.linreg(close, lsmaLen, 0)` as the LSMA line.
2. **Trend strength via angle (tick-normalized)**
* Computes 1-bar LSMA slope in **ticks**:
* `slopeTicks = (lsma - lsma[1]) / syminfo.mintick`
* Converts slope to an angle using `atan()` and a calibration input:
* `ticksPerBarFor45` approximates how many ticks per bar corresponds to ~45°
* Strong trend conditions:
* LONG trend strength when `angleDeg >= minAngleLongDeg`
* SHORT trend strength when `angleDeg <= minAngleShortDeg`
3. **Correction detection**
* LONG side: a correction exists if within the last `corrLookback` bars the close was **below** LSMA:
* `ta.barssince(close < lsma) <= corrLookback`
* SHORT side: correction exists if within the last `corrLookback` bars the close was **above** LSMA:
* `ta.barssince(close > lsma) <= corrLookback`
4. **Continuation signals**
* **Long Continuation (LC)** triggers when:
* Price **crosses above** LSMA (`ta.crossover(close, lsma)`)
* Angle indicates **strong uptrend**
* A recent **pullback below LSMA** occurred
* Optional ATR% filter passes
* **Short Continuation (SC)** triggers symmetrically on cross below.
5. **Strong trend markers**
* When price is on the trend side of LSMA and angle is strong:
* Uptrend: `close > lsma and strongUp`
* Downtrend: `close < lsma and strongDown`
* Drawn as small, semi-transparent circles (not entry signals by themselves).
### Plots and labels
* **LSMA line** plotted in yellow.
* **LC**: green triangle below bar (trend continuation long).
* **SC**: red triangle above bar (trend continuation short).
* **Dots**: tiny circles for strong-trend state when no fresh continuation signal is present.
### Inputs (how to tune)
* **LSMA length**
* Higher = smoother, fewer signals
* Lower = more responsive, more signals/noise
* **Ticks per bar ≈ 45°**
* Calibration control for angle scaling across different instruments/timeframes
* Increase it if angles look too “aggressive”; decrease it if angles look too “flat”
* **Min angle for LONG / Max angle for SHORT**
* Tighten to filter for only steep trends; loosen to allow more setups
* **Max correction bars back**
* Larger values allow older pullbacks to qualify
* Smaller values require a more recent correction
### Optional volatility filter (ATR%)
* When enabled, the script requires:
* `ATR% = (ATR / close) * 100 >= minAtrPct`
* Useful to avoid low-volatility chop (but can filter out valid trends on slow markets).
### How to use (practical)
* Use **LC/SC** as “trend continuation after pullback” markers:
* Prefer trading in the direction of higher timeframe bias (if applicable)
* Consider entries on LC/SC with your own risk rules (stops/targets are not included)
* Use the **strong-trend dots** as a regime filter:
* If dots persist, continuation setups have higher context quality
* If dots disappear frequently, market may be ranging/choppy
### Limitations (important)
* Angle is based on **LSMA 1-bar slope**, so it is sensitive to sudden changes and can vary across markets/timeframes.
* Correction logic is binary: it only checks whether price crossed to the other side of LSMA recently (not depth/structure of pullback).
* Signals depend on **close crossing LSMA**, not intrabar wick behavior.
* Not a full trading system: no position sizing, stops, or take profits.
### Alerts
Alerts fire only on **confirmed bars** (`barstate.isconfirmed`) for:
* “LSMA25 Long continuation”
* “LSMA25 Short continuation”
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.