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.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının yaratıcısı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının yaratıcısı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.