Moving Average Crossover Strategy
May 17, 2022

The Moving Average Crossover strategy indicator provides a comprehensive backtesting framework that utilizes three distinct moving averages to identify and execute long and short trading opportunities. By allowing users to customize crossover triggers and apply secondary filters like RSI, Volume, and Volatility, this tool enables the systematic evaluation of trend-following methodologies.
Usage
The Usage section describes how the script can be used to simulate trading performance. Users can define specific crossing pairs among the three included moving averages to trigger entries and exits. For example, a common setup involves entering a long position when the "Fast" EMA crosses above the "Slow" SMA, while ensuring the price remains above the "Trend" SMA.
The script supports both long and short directions, which can be toggled independently. Users can also simulate risk management by enabling fixed or trailing stop losses and take profit targets. The strategy defaults to an initial capital of $100,000, allocating 10% of equity per trade to project potential profitability over historical data.
Details
The script's execution is based on three specific moving average components:
- Fast EMA: An Exponential Moving Average typically used as the primary signal generator.
- Slow SMA: A Simple Moving Average serving as a signal baseline or secondary trigger.
- Trend SMA: A longer-period Simple Moving Average used to define the primary market direction.
A unique "Dynamic" feature allows the Fast and Slow averages to adjust their source based on the trend; if the price is above the Trend SMA, the MAs can calculate based on the "Low" price, and if below, the "High" price. This is designed to create a more responsive signal environment during trending markets.
Settings
Moving Averages
- Fast EMA: Sets the period for the shortest moving average (Exponential).
- Dynamic Exponential Moving Average?: When enabled, shifts the EMA source between High/Low based on the trend.
- Slow SMA: Sets the period for the signal line (Simple).
- Dynamic Simple Moving Average?: When enabled, shifts the SMA source between High/Low based on the trend.
- Trend Determining SMA: Sets the period for the long-term trend filter.
Entry/Exit Conditions
- Allowed Entries: Toggles for Long and Short trade execution.
- Buy/Sell when: Dropdown to select which moving average crossover (Fast-Slow, Fast-Trend, or Slow-Trend) triggers an entry.
- In trend: If checked, entries only occur when the averages are in sequential order (e.g., Fast > Slow > Trend for longs).
- Close long/short when: Dropdown to select the crossover event that triggers a position exit.
Filters
- Apply Filters to: Selects whether filters apply to Long entries, Short entries, or Exits.
- Relative Volume Filter: Requires the current volume to be a specified multiple of the N-period average volume.
- Volatility Filter: Requires a short-term ATR to be higher than a long-term ATR.
- Overbought/Oversold Filter: Restricts entries to when the RSI (14) is within a specific numerical range.
Stop Loss / Take Profit
- SL / TP: Enables fixed percentage-based stop loss and take profit levels.
- Trailing: Converts the fixed stop loss into a trailing stop that follows price movement.
FAQ
How do I adjust the capital used for backtesting? You can modify the initial capital and trade size in the "Properties" tab of the script settings menu on your charting platform.
What does the "Dynamic" setting do? The dynamic setting changes the price source (High, Low, or Close) of the moving averages depending on whether the price is currently above or below the Trend SMA, aiming to reduce lag or noise.
How can I access the Moving Average Crossover strategy? 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.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.