OPEN-SOURCE SCRIPT

Lorentzian Length Adaptive Moving Average [LLAMA]

68
スナップショット Adaptation of "Machine Learning: Lorentzian Classification" by [jdehorty]
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.

免責事項

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.