All indicators

Distance Weighted Moving Average

Jan 25, 2019

Static chart image
SignalsMoving Averages

The Distance Weighted Moving Average indicator provides a robust trend-following measure that minimizes the influence of price outliers by weighting data points based on their cumulative distance from other values within a specific lookback period.

Usage

The Usage section describes how the script can be used to identify market trends and potential reversal points. Because the DWMA assigns lower weights to price points that deviate significantly from the rest of the sample, it often produces a smoother output than a Simple Moving Average (SMA) during periods of high volatility or "flash" price spikes.

  • Trend Identification: Traders can observe the slope of the DWMA to determine the current market direction. A rising line suggests bullish momentum, while a falling line suggests bearish momentum.
  • Color-Coded Analysis: When the "Highlight Movements" setting is enabled, the indicator changes color based on its direction (e.g., green for up, red for down), allowing for quick visual confirmation of trend shifts.
  • Alert Integration: The script includes optimized alerts that trigger when the DWMA changes direction, assisting users who monitor multiple timeframes or assets simultaneously.

Details

The Distance Weighted Moving Average is based on research into robust filters, such as the Hampel Filter and Recursive Median Filter, which aim to provide more reliable statistical measures in the presence of "noisy" data. This specific implementation is adopted from concepts shared by Alex Orekhov (everget).

The calculation involves a nested loop where, for every price point in the selected window, the script calculates the sum of the absolute differences between that point and every other point in the window. This "distance sum" determines the weight: values that are closer to the general cluster of data points receive a higher weight, while outliers—values with a large total distance from the rest—receive a lower weight. The final output is the weighted average of these prices, ensuring the most representative data points drive the indicator's value.

Settings

General Settings

  • Length: Sets the lookback period for the calculation. A higher length increases smoothing but increases lag, while a lower length makes the indicator more responsive to recent price changes.
  • Highlight Movements: A toggle that enables or disables the directional coloring of the plot. If enabled, the plot changes color based on whether the DWMA is currently higher or lower than its previous value.
  • Source: Determines which price data is used for the calculation (e.g., Close, Open, High, Low, HL2).

FAQ

How does the DWMA handle market outliers compared to a standard SMA? The DWMA specifically penalizes outliers by assigning them a lower weight based on their distance from other data points in the window, whereas an SMA treats every data point equally, making it more susceptible to price spikes.

Can this indicator be used for crossover strategies? Yes, the DWMA can be used in conjunction with price or other moving averages to identify crossover signals, providing a filtered perspective on price action.

How can I access the Distance Weighted Moving Average? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.