OPEN-SOURCE SCRIPT
Logarithmic Moving Average (LMA) [QuantAlgo]

๐ข Overview
The Logarithmic Moving Average (LMA) uses advanced logarithmic weighting to create a dynamic trend-following indicator that prioritizes recent price action while maintaining statistical significance. Unlike traditional moving averages that use linear or exponential weights, this indicator employs logarithmic decay functions to create a more sophisticated price averaging system that adapts to market volatility and momentum conditions.

The indicator displays a smoothed signal line that oscillates around zero, with positive values indicating bullish momentum and negative values indicating bearish momentum. The signal incorporates trend quality assessment, momentum confirmation, and multiple filtering mechanisms to help traders and investors identify trend continuation and reversal opportunities across different timeframes and asset classes.
๐ข How It Works
The indicator's core innovation lies in its logarithmic weighting system, where weights are calculated using the formula:Pine Scriptยฎ The steepness parameter controls how aggressively recent data is prioritized over historical data, creating a dynamic weight decay that can be fine-tuned for different trading styles. This logarithmic approach provides more nuanced weight distribution compared to exponential moving averages, offering better responsiveness while maintaining stability.
The LMA calculation combines multiple sophisticated components. First, it calculates the logarithmic weighted average of closing prices. Then it measures the slope of this average over a 10-period lookback:Pine Scriptยฎ The system also incorporates trend quality assessment using R-squared correlation analysis of log-transformed prices, measuring how well the price data fits a linear trend model over the specified period.
The final signal generation uses the formula:Pine Scriptยฎ which combines the LMA slope with trend quality weighting. When momentum confirmation is enabled, the indicator calculates annualized log-return momentum and applies a multiplier when the momentum direction aligns with the signal direction, strengthening confirmed signals while filtering out weak or counter-trend movements.
๐ข How to Use
1. Signal Interpretation and Threshold Zones

2. Momentum Confirmation and Visual Analysis

3. Examples: Preconfigured Settings
The Logarithmic Moving Average (LMA) uses advanced logarithmic weighting to create a dynamic trend-following indicator that prioritizes recent price action while maintaining statistical significance. Unlike traditional moving averages that use linear or exponential weights, this indicator employs logarithmic decay functions to create a more sophisticated price averaging system that adapts to market volatility and momentum conditions.
The indicator displays a smoothed signal line that oscillates around zero, with positive values indicating bullish momentum and negative values indicating bearish momentum. The signal incorporates trend quality assessment, momentum confirmation, and multiple filtering mechanisms to help traders and investors identify trend continuation and reversal opportunities across different timeframes and asset classes.
๐ข How It Works
The indicator's core innovation lies in its logarithmic weighting system, where weights are calculated using the formula:
w = 1.0 / math.pow(math.log(i + steepness), 2)
The LMA calculation combines multiple sophisticated components. First, it calculates the logarithmic weighted average of closing prices. Then it measures the slope of this average over a 10-period lookback:
lmaSlope = (lma - lma[10]) / lma[10] * 100
The final signal generation uses the formula:
signal = lmaSlope * (0.5 + rSquared * 0.5)
๐ข How to Use
1. Signal Interpretation and Threshold Zones
- Positive Values (Above Zero): LMA slope indicating bullish momentum with upward price trajectory relative to logarithmic baseline
- Negative Values (Below Zero): LMA slope indicating bearish momentum with downward price trajectory relative to logarithmic baseline
- Zero Line Crosses: Signal transitions between bullish and bearish regimes, indicating potential trend changes
- Long Entry Threshold Zone: Area above positive threshold (default 0.5) indicating confirmed bullish signals suitable for long positions
- Short Entry Threshold Zone: Area below negative threshold (default -0.5) indicating confirmed bearish signals suitable for short positions
- Extreme Values: Signals exceeding ยฑ1.0 represent strong momentum conditions with higher probability of continuation
2. Momentum Confirmation and Visual Analysis
- Signal Color Intensity: Gradient coloring shows signal strength, with brighter colors indicating stronger momentum
- Bar Coloring: Optional price bar coloring matches signal direction for quick visual trend identification
- Position Labels: Real-time position classification (Bullish/Bearish/Neutral) displayed on the latest bar
- Momentum Weight Factor: When short-term log-return momentum aligns with LMA signal direction, the signal receives additional weight confirmation
- Trend Quality Component: R-squared values weight the signal strength, with higher correlation indicating more reliable trend conditions
3. Examples: Preconfigured Settings
- Default: Universally applicable configuration balanced for medium-term investing and general trading across multiple timeframes and asset classes.
- Scalping: Highly responsive setup with shorter period and higher steepness for ultra-short-term trades on 1-15 minute charts, optimized for quick momentum shifts.
- Swing Trading: Extended period with moderate steepness and increased smoothing for multi-day positions, designed to filter noise while capturing larger price swings on 1-4 hour and daily charts.
- Trend Following: Maximum smoothing with lower steepness for established trend identification, generating fewer but more reliable signals optimal for daily and weekly timeframes.
- Mean Reversion: Shorter period with high steepness for counter-trend strategies, more sensitive to extreme moves and reversal opportunities in ranging market conditions.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalitร . Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice รจ soggetta al nostro Regolamento.
๐ Access exclusive tools for trading & investing here (3-day FREE trial): whop.com/quantalgo/
๐ฉ DM if you need any custom-built indicators.
๐ฉ DM if you need any custom-built indicators.
Declinazione di responsabilitร
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalitร . Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice รจ soggetta al nostro Regolamento.
๐ Access exclusive tools for trading & investing here (3-day FREE trial): whop.com/quantalgo/
๐ฉ DM if you need any custom-built indicators.
๐ฉ DM if you need any custom-built indicators.
Declinazione di responsabilitร
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.