- **Similar:** [LSMA](../lsma/lsma.md), [LinReg](../../statistics/linreg/LinReg.md) | **Complementary:** R² for forecast reliability | **Trading note:** Time Series Forecast; linear regression extrapolated one bar ahead. Predictive MA.
TSF projects the least-squares regression line one bar forward, providing a statistically grounded forecast of the next bar's value. Unlike simple moving averages that smooth past data, TSF answers the question: "If the current trend continues, where will price be next?" This makes it inherently leading rather than lagging, though the forecast degrades quickly beyond one step.
## Historical Context
Time Series Forecast originates from classical linear regression applied to financial time series. The concept appeared in TA-Lib as `TA_TSF` and has been a standard offering in technical analysis software since the 1990s. Tushar Chande's *The New Technical Trader* (1994) formalized several regression-based indicators including the closely related Chande Forecast Oscillator (CFO), which measures the percentage error between the current price and the TSF value.
TSF is mathematically identical to the Least Squares Moving Average (LSMA) evaluated one step beyond the window endpoint. Where LSMA answers "what is the trend value now?", TSF answers "what will the trend value be next bar?" The relationship is exact: `TSF = LSMA + slope`, where slope is the per-bar rate of change of the regression line.
## Architecture & Physics
### 1. O(1) Incremental Linear Regression
The implementation uses running sums (`SumY`, `SumXY`) with a reversed-x convention where `x=0` corresponds to the newest bar. This allows O(1) updates without maintaining the full regression matrix.
The O(1) running-sum algorithm is inherently serial due to data dependencies. Batch mode uses `stackalloc` for small buffers (≤256 elements) to avoid heap allocation.
| Timeliness | 10 | Leading indicator (projects forward) |
| Overshoot | 7 | Extrapolation amplifies noise |
| Smoothness | 5 | Less smooth than LSMA (forecast adds slope) |
## Validation
| Library | Status | Notes |
|---------|--------|-------|
| LSMA(offset=1) | ✅ | Mathematical identity, exact match |
| TA-Lib | 🔲 | `TA_TSF` available in TALib.NETCore |
| Skender | ❌ | No direct TSF method |
## Common Pitfalls
1.**TSF is not LSMA.** LSMA = regression value at the current bar. TSF = one step ahead. The difference equals the regression slope. Using TSF as a smoothing average will produce systematically biased results.
2.**Single-step forecast only.** TSF projects exactly one bar forward. Multi-step extrapolation (TSF at offset=2, 3, ...) accumulates error quadratically. For multi-step forecasting, use AFIRMA or dedicated time-series models.
3.**Warmup = period bars.** The indicator needs a full window of data before regression is meaningful. During warmup, TSF returns raw input values.
4.**Noise amplification.** Because TSF adds the slope to the endpoint value, it amplifies short-term noise. Use longer periods (20+) for less noisy forecasts, or combine with a smoother like LSMA.
5.**Bar correction support.** The `isNew=false` pathway correctly rolls back state using the `_ps` (previous state) pattern. Always use `isNew=false` for intra-bar updates in live trading.
6.**Resync interval.** Running sums are recomputed every 1000 ticks to prevent floating-point drift. This adds negligible overhead but ensures long-running accuracy.