Skip to content
All library documents

Numerically Stable Moving Averages with Anchors and Fractional Lengths

Article TradingView scripts

Summary

This Pine library implements a collection of moving averages and related filters, emphasizing constant-time updates, numerical stability, optional reset anchors, and support for fractional or effectively unbounded lengths. Its documented functions include simple, exponential, and Wilder-style recursive averages, along with additional smoothing and adaptive methods. Fractional lengths are handled through interpolation or adjusted update rules, while anchors restart calculations from a chosen condition.

The code can use built-in platform averages when parity is requested and supported, and switches to custom streaming calculations for cases such as re-anchoring or extended lengths. It includes validation and warm-up logic, plus helpers for session boundaries and smoothing transitions after resets. This is an implementation library, not a trading strategy or empirical study: it provides no entry or exit rules, market tests, or evidence that any filter improves returns. Correct behavior depends on understanding each function's reset, initialization, and length conventions when integrating it into an indicator or strategy.

Key ideas

  • The library provides several average types with anchor-based resets and fractional length support.
  • Custom streaming updates are designed to keep calculation work constant per bar.
  • Built-in platform functions can be used where supported to preserve mathematical parity.
  • Warm-up and error-compensation logic address initialization and numerical precision.
  • The library includes adaptive smoothing utilities but provides no trading performance evidence.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.