Weighted Moving Average Formula, Calculation Examples, & Charts for Financial Trading

Article

A technical implementation guide of Weighted Moving Average Indicator using LightningChart JS Trader for developing Fintech applications.
Soroush Sohrabian

Ahmad Omid

Data Science Developer

LinkedIn icon
Weighted-Moving-Average-Formula-Cover

What is Weighted Moving Average?

The Weighted Moving Average (WMA) places more weight on recent data values by applying a weighting factor to each value within a chosen period. Each day’s price data contributes to the overall average, but the most recent prices carry more influence, allowing for a moving average that’s more responsive to current trends. This approach is especially useful in fast-paced markets, as it prioritizes recent movements and gives traders a more sensitive indicator to detect possible trend reversals.

Importance of Weighted Moving Average in Forecasting

By giving the latest data points a higher weight, Weighted Moving Averages (WMAs) help in accurately forecasting short-term price movements. This method, which emphasizes recent activity, can offer better insights into the current market trend and help traders identify key support and resistance levels. WMAs are effective for tracking trends, filtering out market “noise,” and determining potential entry or exit points based on real-time price shifts.

Formula for Weighted Moving Average

The Weighted Moving Average (WMA) formula considers both the price values and a predetermined set of weights for each data point. Typically, each data point’s weight increases as it gets closer to the current day within the specified period. Here’s how the WMA is generally calculated:

Weighted-Moving-Average-Formula

Where:

  • Pi represents the price on day i
  • Wi is the weighting factor assigned to each price
  • n is the total number of days in the moving average period

How to Calculate Weighted Moving Average

To calculate the weighted moving average, start by gathering price data for the chosen period (e.g., a set number of days, such as five). Each day’s price is then multiplied by its respective weight, with the most recent day carrying the highest weight. The steps are as follows:

  1. Gather price data over the chosen period.
  2. Assign weights to each day, with higher weights for more recent days.
  3. Multiply each day’s price by its weight.
  4. Sum the weighted values and divide by the sum of all weights to get the WMA.

This approach ensures the WMA is more sensitive to recent price changes, ideal for detecting short-term market trends.

Weighted Moving Average Calculation Step by Step

Let’s look at an example of a 5-day WMA calculation:

  • Let’s assume we have the following closing prices over five days:
Index
Source
Description
Index
0
Source
Open
Description
Calculations based on Open values.
Index
1
Source
High
Description
Calculations based on Median Price values, that is the arithmetical mean of High and Low. (High + Low) / 2
Index
2
Source
Low
Description
Calculations based on Low values.
Index
3
Source
Close
Description
Calculations based on Close values.
Index
4
Source
Hl2
Description
Calculations based on Median Price values, that is the arithmetical mean of High and Low. (High + Low) / 2
Index
5
Source
Oc2
Description
Calculations based on arithmetical mean of Open and Close values. (Open + Close) /2
Index
6
Source
Hlc3
Description
Calculations based on Typical Price values, that is the arithmetical mean of High, Low and Close. (High + Low + Close) / 3
Index
7
Source
Olhc4
Description
Calculations based on arithmetical mean of Open, High, Low and Close values. (Open + High + Low + Close) / 4
Index
8
Source
Hlcc4
Description
Calculations based on Weighted Close values. (Open + High + Close * 2) / 4
Index
9
Source
Indicator
Description
Calculations based on other indicator's values.

For this 5-day WMA, let’s assign weights from 1 to 5, with 5 for the most recent day (Day 5) and 1 for the oldest day (Day 1).

Step-by-Step Calculation:

  1. Assign Weights and Multiply Each Day’s Price by Its Weight:
    • Day 1: 45 × 1 = 45
    • Day 2: 47 × 2 = 94
    • Day 3: 50 × 3 = 150
    • Day 4: 52 × 4 = 208
    • Day 5: 55 × 5 = 275
  2. Sum the Weighted Prices:

45 + 94 + 150 + 208 + 275 = 772

  1. Calculate the Sum of Weights: Since our weights are 1, 2, 3, 4, and 5, the sum of these weights is:

1 + 2 + 3 + 4 + 5 = 15

4. Divide the Sum of Weighted Prices by the Sum of Weights:

WMA = 772/15 = 51.47

So, the 5-day Weighted Moving Average in this example is 51.47.

Types of Weighted Moving Averages and their Formulae

Linear Weighted Moving Average Formula

The Linear Weighted Moving Average (LWMA) assigns linear weights to each price point, making the most recent day the most influential in the average. This formula offers a direct approach where each day’s price has a weight proportional to its position in the chosen period.

Weighted-Moving-Average-Formula-LWMA

Where:

  • Pi: price on each day
  • i: weight for each day, increasing linearly from 1 to ? (e.g., 1, 2, 3…)
  • n: number of periods in the moving average
  • n(P× ): total of each price multiplied by its weight (numerator)
  • ni: total sum of weights (denominator), normalizing the average

In essence, the LWMA formula assigns a linear weight to each price point, making recent data more impactful in the final average, providing a clearer indication of short-term trends.

Exponentially Weighted Moving Average Formula

The Exponentially Weighted Moving Average (EWMA) is a version of WMA where the weights decrease exponentially, with the highest weight on the most recent data. The EWMA formula:

EXMAt = α × Pt + (1 – α) × EWMAt-1

Where:

  • α is the smoothing factor, usually between 0 and 1
  • Pt is the price at time ?

By prioritizing the most recent data exponentially, the EWMA is even more sensitive to sudden price shifts, making it popular for rapidly changing markets.

Volume Weighted Moving Average Overview

The VWMA calculation assigns weights to each price based on the volume for each time period, which increases the influence of high-volume price data in the average. Here’s how to calculate VWMA:

  1. Multiply each price by its corresponding volume over the defined period.
  2. Sum the resulting values.

Divide by the total volume for the period.

Weighted-Moving-Average-Formula-VWMA

As you see, the Volume Weighted Moving Average (VWMA) considers not only price but also volume, assigning more influence to prices during high-volume trading periods. It’s particularly useful for identifying levels where significant market activity occurred.

Elastic Volume Weighted Moving Average

The Elastic Volume Weighted Moving Average (EVWMA) is a refined version of the VWMA that adapts to changes in trading volume dynamically. Unlike the standard VWMA, which calculates based on a fixed period, EVWMA adjusts itself according to the volume fluctuations within the market.

In other words, when trading volume is high, the EVWMA becomes more sensitive to recent prices; when volume is low, it smooths out fluctuations, providing flexibility in diverse market conditions. This “elastic” quality allows it to be more responsive to sudden changes in trading volume, making it more adaptive to real-time market conditions.

How to Create the Technical Indicator Using LC JS Trader

Step 1: Get LightningChart JS Trader

To begin, you’ll need access to LightningChart JS Trader. This library provides the tools necessary to create advanced technical indicators, including the Weighted Moving Average (WMA) indicator. Visit the LightningChart JS Trader page to download the required components and review the documentation.

Step 2: Review the Interactive Example

LightningChart JS Trader includes interactive examples that demonstrate how to create custom technical indicators. Start by reviewing the documentation, focusing on how to integrate the Weighted Moving Average (WMA) into your chart setup. The interactive examples will guide you through the process of setting up the WMA, from importing the necessary modules to modify the chart settings.

Step 3: Code Explanation

In this step, we will break down the code that creates the chart with the Weighted Moving Average (WMA) indicator, as shown in the image, using LightningChart JS Trader. The code demonstrates how to initialize a trading chart, apply the WMA indicator, and customize its appearance.

Weighted-Moving-Average-Formula-Chart-Example

Here’s a detailed breakdown of each section:

A. Importing the Required Libraries:

   const lcjsTrader = require('@arction/lcjs-trader')
   const lcjs = require('@arction/lcjs')
   const { Themes } = lcjs
  • lcjsTrader: This library provides access to the LightningChart JS Trader functionalities, allowing you to create advanced financial charts.
  • lcjs: The main LightningChart JS library, used for general charting functionality.
  • Themes: A property within lcjs that provides access to pre-built themes. In this case, we are using the darkGold theme to style the chart.

B. Initializing the Trading Chart:

   lcjsTrader.trader(TRADER_LICENSE).then(async (trader) => {
    // Create a trading chart.
    const tradingChart = trader.tradingChart({ loadFromStorage: false, colorTheme: Themes.darkGold })
  • trader(TRADER_LICENSE): Initializes the LightningChart JS Trader with the provided license key (TRADER_LICENSE). This is required to access the charting functionalities for financial data.

Note you can request a LightningChart JS Trader trial license, which is free.

  • tradingChart(): This function creates a trading chart with certain options.
  • loadFromStorage: false: This disables the loading of previously stored chart data from local storage, ensuring a fresh chart setup.
  • colorTheme: Themes.darkGold: This applies the darkGold theme to the chart, which influences the background color, gridlines, and other visual elements.

C. Adding and Customizing the Indicator

    // Add a Weighted Moving Average Indicator
    const wma14 = tradingChart.indicators().addWeightedMovingAverage()
    wma14.setPeriodCount(14)
    wma14.setLineColor('#DA46DD')
    wma14.setLineWidth(3)
  • addWeightedMovingAverage(): WMA places more weight on recent data values by multiplying the previous day’s data value by a weighting factor, based on the moving average of a set number of days.
  • setPeriodCount(14): Sets the time period for the WMA to 14. This means the WMA will calculate the average based on the last 14 days.
  • setLineColor('# DA46DD'): Changes the color of the WMA line to pink, making it visually distinct on the chart.
  • wma14.setLineWidth(3): Increases the line thickness of the WMA to 3 pixels, making the line more prominent on the chart.

D. Loading Data from a CSV File

    // Reading data from a file.
    await fetch(`${document.head.baseURI}examples/assets/0000/Alphabet Inc (GOOGL).csv`).then((res) => res.text()).then((text) => {
        tradingChart.readCsvString(text, 'Alphabet Inc (GOOGL)')
    })
  • fetch(): This function retrieves a CSV file containing historical data for Alphabet Inc. (GOOGL). The CSV file includes pricing information for the company’s stock, which is plotted on the chart.
  • readCsvString(): This function reads the CSV data and interprets it as pricing data for Alphabet Inc. The second argument (‘Alphabet Inc (GOOGL)’) sets the label for the chart, as seen at the top of the chart image.

E. Setting the Currency for the Chart

    tradingChart.setCurrency('USD')
   })
  • setCurrency('USD'): This sets the currency of the chart to USD, ensuring that the pricing data is interpreted and displayed in US dollars.

Advantages and Limitations of the Indicator

The Weighted Moving Average (WMA) offers a few distinct advantages, particularly for traders who prioritize responsiveness to recent data. By placing higher importance on the latest prices, WMAs adapt more quickly to changes in the market.

This high responsiveness makes them ideal for identifying emerging trends sooner than traditional moving averages, giving traders an edge in fast-moving markets. Additionally, the WMA’s design, which allows traders to assign varying weights based on their preferences or goals, adds another layer of flexibility.

This customization enables traders to tweak the WMA to fit their specific strategies, choosing shorter or longer periods or experimenting with different weighting schemes to better capture price trends.

However, WMAs are not without their limitations. Despite reducing lag compared to simple moving averages, WMAs still trail behind the most current price, which means that during rapid price changes, there’s still a slight delay in the average’s response.

This sensitivity to recent data, while helpful in many cases, can also be a double-edged sword; in highly volatile markets, WMAs might generate misleading signals or noise, making it difficult for traders to distinguish genuine trends from short-lived price movements.

Additionally, calculating a WMA, especially with custom weights, requires more detailed work than simpler averages, which can make it feel complex or intimidating to some traders, particularly those newer to technical analysis.

Conclusion

The Weighted Moving Average (WMA), with its focus on recent data, is an invaluable tool for identifying short-term trends in financial markets. By allowing more recent prices to carry greater weight, WMAs provide traders with a responsive, adaptable approach to trend detection.

Different types of WMAs, such as the Linear Weighted Moving Average and the exponential weighted Moving Average, offer additional customization, letting traders adjust based on market conditions and their individual trading strategies. However, it’s crucial to balance this indicator’s benefits against its sensitivity to market volatility, as rapid price changes may occasionally lead to false signals.

The importance of using LightningChart JS Trader in this process cannot be overstated. This advanced charting tool enables traders to visualize WMAs and other technical indicators with high precision and interactive features, making it easier to spot trends, assess historical data, and customize the WMA settings.

LightningChart JS Trader is designed to handle large datasets without compromising performance, providing the accuracy and responsiveness essential for effective analysis in real-time markets.

Key Takeaways

  • The WMA is a dynamic, highly responsive indicator that highlights short-term price movements by assigning greater importance to recent data points.
  • Various types of WMAs allow for tailored analysis, adapting to specific trading goals and market environments.
  • Despite its benefits, the WMA’s sensitivity to volatility means it may occasionally produce false signals, so it’s best used alongside other tools.
  • LightningChart JS Trader supports WMA visualization with real-time data, making it an ideal platform for traders looking to apply WMAs effectively.

Continue learning with LightningChart