LightningChart JS TraderMoving Average Envelope Strategy (MAE) Technical Indicator
ArticleMoving Average Envelope is a technical indicator used in stock and forex markets. Learn its technical implementation with Lightningchart JS.
Written by a human | Updated on April 24th, 2025
The Moving Average Envelope Strategy for Financial Trading
The Moving Average Envelope (MAE) is a powerful technical indicator widely used in financial trading, particularly in stock and forex markets. By incorporating moving averages and trading envelopes, this indicator helps traders identify potential buy and sell points in fluctuating markets. Unlike other moving average indicators that only smooth price data, the MAE creates bands around the moving average, providing a clear view of market volatility and price deviation.
The MAE is particularly advantageous for traders looking to take advantage of envelope trading strategies that depend on upper and lower bands to anticipate market reversals. As a volatility-based indicator, the MAE adapts to market conditions, giving traders insights into price trends, momentum, and reversals.
By understanding the core components of the moving average envelope strategy, businesses and traders alike can make informed decisions when executing trades. This blog delves into the theory behind the MAE and demonstrates how to create it using LightningChart JS Trader, specifically leveraging the interactive charting library for real-time trading analysis.
What is the Moving Average Envelope (MAE) Indicator?
The Moving Average Envelope (MAE) is a technical indicator used in financial trading to help identify potential buy and sell opportunities. It consists of three lines:
- A middle line, which is a moving average of the price.
- The upper envelope, is calculated by adding a fixed percentage to the moving average.
- Lower envelope, calculated by subtracting the same percentage from the moving average.
These bands create a price channel, or envelope, around the price movements of an asset. The primary purpose of the MA envelope is to help traders visualize when security is overbought or oversold. This helps traders to anticipate potential price reversals, making it easier to set entry and exit points.
How is the Moving Average Envelope Indicator Used in Trading?
The MAE indicator is most often used for identifying:
- Overbought conditions: When the price touches or exceeds the upper envelope, it is often considered overbought, signaling a potential downward reversal.
- Oversold conditions: When the price touches or drops below the lower envelope, the asset may be oversold, suggesting a possible upward reversal.
Traders use this indicator to follow trends or identify short-term market extremes, which helps with both scalping strategies and long-term trend trading.
How does the Moving Averages Envelope indicator work?
The Moving Average Envelope consists of a moving average that tracks the trend of a security’s price over a set period, and the upper and lower bands are placed around this moving average. The percentage deviation used to create the envelope bands determines the width of the channel around the price movement.
The moving average serves as a baseline to smooth out the fluctuations in the price, while the upper envelope and lower envelope indicate boundaries within which the price is expected to fluctuate during normal market conditions. When the price moves beyond these bands, it often signals that the market is at an extreme, either overbought or oversold.
Upper and Lower Envelopes and Their Purpose
The upper and lower envelopes act as key markers in the MAE strategy:
- Upper envelope: The upper band represents a threshold for overbought conditions. When the price touches or surpasses this level, it suggests that the security’s price is overextended, and traders might expect a downward correction.
- Lower envelope: The lower band signifies the oversold threshold. If the price drops below this line, it implies that the security may be undervalued, and a potential reversal to the upside could occur.
These envelopes help traders determine when the price of an asset is moving too far from its moving average, indicating a reversion to the mean is likely.
MAE vs. Other Moving Averages: Key Differences
The Moving Average Envelope should not be confused with other moving average indicators such as Bollinger Bands or simple moving averages (SMA). While Bollinger Bands also use upper and lower bands, they are based on standard deviations from the moving average, making them more responsive to volatility. MA Envelopes, on the other hand, use a fixed percentage, providing a more consistent channel, irrespective of market volatility.
Additionally, traditional moving averages like the SMA or EMA only provide a smoothed line that represents the average price over a given period, without giving any insight into overbought or oversold levels. The MA Envelope adds this additional layer of analysis by incorporating the bands, which highlight potential turning points in the market.
Volatility-Based Envelopes
The width of the MA Envelopes can be adjusted based on the asset’s volatility. In periods of high volatility, traders may choose to widen the envelopes by increasing the percentage applied to the moving average. This ensures that the envelope bands do not generate too many false signals in a highly volatile market. Conversely, during periods of low volatility, the percentage can be reduced to tighten the bands and capture more subtle price movements.
Formula and Applications
The Moving Average Envelope is calculated using a simple formula. The middle line is the moving average of the price over a specified period. The upper envelope is calculated by adding a percentage to the moving average, and the lower envelope is calculated by subtracting the same percentage. This creates a price channel around the moving average.
Upper Envelope = Moving Average + (Moving Average * Percentage)
Lower Envelope = Moving Average – (Moving Average * Percentage)
Calculation Examples
If the moving average of a stock is $100, and the percentage for the envelope is set to 2%, the upper envelope would be calculated as:
Upper Envelope = 100 + (100 * 0.02) = $102
The lower envelope would be:
Lower Envelope = 100 – (100 * 0.02) = $98
These envelopes would create a trading range where the upper band is $102, and the lower band is $98. The stock price fluctuating outside this range would suggest overbought or oversold conditions.
Interpretation of Results
- When the price rises above the upper envelope, it may be interpreted as overbought, and traders might consider selling the asset.
- When the price falls below the lower envelope, the asset may be considered oversold, offering a potential buying opportunity.
Traders often use the Moving Average Envelope in combination with other indicators to confirm these signals and avoid false breakouts or trends.
Moving Average Envelope in Forex
In FOREX trading, Moving Average Envelopes are commonly used due to the highly volatile nature of currency pairs. Traders can adjust the percentage of the envelopes based on the specific currency pair being traded, allowing them to capture price deviations in both highly volatile pairs like GBP/USD or in more stable ones like EUR/USD.
The forex envelope strategy involves buying when a currency price touches or moves below the lower band and selling when it reaches or exceeds the upper band. This strategy can be very effective in capturing price reversals and taking advantage of short-term price deviations in the currency market.
What Are the Scalper Strategies?
The MAE profit system is often used by scalpers, traders who seek to profit from small price movements. Scalping strategies with Moving Average Envelopes focus on:
- Buying, when the price touches or falls below the lower envelope and quickly selling as the price moves back toward the middle or upper envelope.
- Selling, when the price exceeds the upper envelope, capturing small profits as the price reverts toward the middle or lower envelope.
The envelope scalper strategy relies on frequent trades and quick decision-making, as scalpers capitalize on short-term price fluctuations. This method is most effective in volatile markets where price movements frequently touch or breach the envelope bands.
The Role of LightningChart JS Trader in Financial Analysis
Financial analysis involves examining historical data to forecast future trends, make informed decisions, and assess risk. In this domain, applications like LightningChart JS Trader serve a critical role by providing real-time, high-performance data visualization tools that help traders and analysts better interpret complex datasets. It enables traders to track market trends using built-in indicators.
The platform’s ability to handle large datasets and real-time updates makes it essential for fast decision-making in dynamic markets. Additionally, its customization options allow users to create tailored charts and apply statistical indicators, enhancing both the precision of analysis and risk management. This tool helps streamline financial analysis and supports more informed, data-driven trading strategies.
Implementation with LightningChart JS Trader
Advanced charting platforms like LightningChart JS offer traders a range of technical indicators, including the Moving Average Envelope indicator. LightningChart JS allows traders to create interactive, high-performance charts, ensuring real-time data visualization. This platform is particularly useful for traders who rely on technical indicators such as the Moving Average Envelope Channels indicator to make quick, informed decisions.
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 Moving Average Envelope 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 Moving Average Envelope indicator into your chart setup. The interactive examples will guide you through the process of setting up the Moving Average Envelope indicator, from importing the necessary modules to modifying the chart settings.
Step 3: Code Explanation
In this step, we will break down the code that creates the chart with the Moving Average Envelope indicator, as shown in the image, using LightningChart JS Trader. The code demonstrates how to initialize a trading chart, apply the Moving Average Envelope indicator, and customize its appearance.
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 is used for general charting functionality.
- Themes: A property within lcjs that provides access to pre-built themes. In this case, we are using the
darkGoldtheme 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. In this example:
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, grid lines, and other visual elements.
C. Adding and Customizing the Indicator
// Add a Moving Average Envelope indicator
const mae = tradingChart.indicators().addMovingAverageEnvelopes()
mae.setMovingAverageType(2)
mae.setPeriodCount(10)
mae.setPercentage(5)
mae.setLineColor('#FFFF00')
mae.setLineWidth(2)
addMovingAverageEnvelopes(): This method adds a Moving Average Envelope (MAE) indicator to the chart. The MAE consists of an upper and lower band, which are calculated by applying a percentage offset to a moving average. It is used to identify overbought or oversold conditions in the market based on deviations from the moving average.
**setMovingAverageType(2): This method sets the type of moving average to be used for the MAE. In this case, 2 represents the Simple Moving Average (SMA), which calculates the average of the last price points, without giving more weight to recent data points.
setPeriodCount(10): This defines the number of periods used to calculate the moving average. A smaller period count makes the indicator more sensitive to short-term price movements, while a larger count smooths out the fluctuations.
setPercentage(5): This sets the percentage offset for the upper and lower bands of the envelope. Here, the bands are placed 5% above and below the moving average, creating a visual boundary to detect price breakouts.
setLineColor('#FFFF00'): This method specifies the color of the lines representing the MAE bands. The color is set to yellow (#FFFF00) for clear visibility on the chart.
setLineWidth(2): This adjusts the width of the indicator lines to 2 pixels, making them thicker and more noticeable on the chart for easier analysis.
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.
** Enumeration of Moving Average Types in LC JS Trader:
- Exponential Moving Average (EMA): 0
- None: 1 (No moving average applied)
- Simple Moving Average (SMA): 2
- Time Series Moving Average (TSMA): 3
- Triangular Moving Average (TMA): 4
- Variable Moving Average (VMA): 5
- Variable Index Dynamic Average (VIDYA): 6
- Volume Weighted Moving Average (VWMA): 7
- Weighted Moving Average (WMA): 8
- Welles Wilder’s Smoothing (WWS): 9
Advantages and Limitations
Advantages:
- Clarity in Price Extremes: The MAE indicator visually highlights overbought and oversold conditions, allowing traders to make informed decisions.
- Adaptability: The percentage deviation used to calculate the envelopes can be adjusted according to market conditions, making it versatile for different asset classes and volatility levels.
- Trend Following and Reversal Identification: MAE allows traders to follow trends and identify potential reversal points when the price deviates too far from the moving average.
Limitations:
- Lagging Indicator: Like all moving averages, the MAE lags behind real-time price movements, potentially missing short-term reversals.
- Fixed Percentage: Since the bands are based on a fixed percentage, they may not adapt as quickly to sudden changes in market volatility, leading to false signals in highly dynamic markets.
- Not Effective in Sideways Markets: In low-volatility or range-bound markets, the price may frequently touch the upper and lower envelopes, generating false signals and leading to unprofitable trades.
Conclusion
The Moving Average Envelope (MAE) strategy is an essential tool for traders aiming to capture trends, identify overbought and oversold conditions, and capitalize on market reversals. By using a moving average with upper and lower envelope bands, the MAE provides clear signals for potential entry and exit points, making it highly effective for various trading strategies, from scalping to long-term trend following.
The use of LightningChart JS Trader significantly enhances the effectiveness of the MAE and other technical indicators. With real-time performance, high customizability, and interactive visualizations, LightningChart JS Trader allows traders to better interpret the market data and make more accurate trading decisions.
Its ability to seamlessly integrate with trading platforms further ensures that traders can efficiently execute their strategies without delays or technical limitations. By using LightningChart JS Trader, traders can fully utilize the potential of the Moving Average Envelope and other indicators, improving both trading accuracy and performance.
Key Takeaways:
- Moving Average Envelopes (MAE) consist of a central moving average with upper and lower bands calculated as a percentage of the average, helping traders identify overbought and oversold conditions.
- The upper and lower envelopes serve as key signals for potential price reversals, aiding in timely buy and sell decisions.
- LightningChart JS Trader enhances the utility of MAE by providing real-time, customizable, and interactive charting tools, offering a seamless integration with trading platforms that improves trading strategies and execution.
HTML
Written by a human | Updated on April 9th, 2025HTML Charts with JavaScript HTML charts are standard and suitable for all-level developers with a simple implementation. The issue with basic HTML 5 charts is their limited functionalities and performance...
Volumetric Data Visualization
This article provides an overview of Volume Data, and the techniques which can be used to visualize it.
JavaScript Data Visualization With LightningChart JS
Written by a human | Updated on April 9th, 2025LightningChart JS LightningChart JS is the top contestant for next-generation JavaScript data visualization tools for web and mobile applications. From the start, it has been engineered to deal with maximum-size...

