OPEN-SOURCE SCRIPT

Logarithmic Moving Average (LMA) [QuantAlgo]

365
🟢 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®
w = 1.0 / math.pow(math.log(i + steepness), 2)
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®
lmaSlope = (lma - lma[10]) / lma[10] * 100
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®
signal = lmaSlope * (0.5 + rSquared * 0.5)
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
快照
  • 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.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。