OPEN-SOURCE SCRIPT
Lorentzian Length Adaptive Moving Average [LLAMA]

Gradient color by [chhagansinghmeena] base on work by [LuxAlgo]
LLAMA: A regime-aware adaptive moving average that bends with the market.
Start with a problem traders know:
*Traditional moving averages are either too slow (EMA200) or too fast (EMA9)
*Adaptive MAs exist, but they often hug price too tightly or smooth too much, failing to balance bias and tactics
LLAMA uses a Lorentzian distance function to adapt its length dynamically. Instead of a fixed smoothing window, it stretches or contracts depending on market conditions. This distortion reduces lag while still providing a clear bias line.
The indicator looks back at recent bars and measures how similar they are using a Lorentzian distance (a log‑scaled absolute difference). It keeps track of the “nearest neighbors” — bars that most resemble the current regime. Each neighbor carries a label (long, short, neutral) based on simple price comparisons. By averaging these labels, LLAMA predicts whether the market is leaning bullish or bearish. That prediction is then mapped into a dynamic length between [llamaMinLen] and [llamaMaxLen].
*Bullish bias -> length stretches toward max (smoother, more stable).
*Bearish bias -> length contracts toward min (snappier, more reactive).
During breakouts, LLAMA tightens and comes into contact with bars, giving actionable signals. During chop, it stretches to avoid false triggers. It covers both ends of the spectrum (bias and tactics) in one line, something static MA's can't do.
Think of LLAMA as a lens that bends with the market:
*Wide lens (max length) for big picture bias.
*Narrow lens (min length) for tactical precision.
The "Lorentzian Loop" is the math that decides when to widen or narrow.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.