Simple Moving Average + ADX + DMI + Time Range Test
Nov 20, 2020

The Simple Moving Average + ADX + DMI + Time Range Test tool provides a comprehensive backtesting framework that combines moving average crossovers with trend strength filtering to identify high-probability trade entries and exits. By integrating the Average Directional Index (ADX) and Directional Movement Index (DMI), the script aims to reduce false signals during low-volatility periods while allowing users to isolate specific historical time windows for performance analysis.
Usage
The Usage section describes how the script can be used to validate trend-following strategies. Users typically look for the "Fast MA" (default 7) to cross above or below the "Slow MA" (default 14) to signal momentum shifts. However, to filter out "choppy" or sideways price action, the strategy requires the ADX to be above a specific "Key Level" (default 20), ensuring that a trend is sufficiently strong before a position is opened.
The strategy executes a Long entry when:
- The Fast MA is greater than the Slow MA.
- The DI+ is greater than the DI- (Positive Directional Index).
- The ADX value is above the user-defined Key Level.
The strategy closes the position when:
- The Fast MA falls below the Slow MA.
- The DI- is greater than the DI+ (Negative Directional Index).
- The ADX value is above the Key Level.
Details
The script utilizes a dual-layered filtering process. While Simple Moving Averages (SMA) are effective for identifying trend direction, they are prone to "whipsaws" in non-trending markets. To mitigate this, the implementation incorporates the DMI system developed by J. Welles Wilder. The DI+ and DI- components determine the trend's bias, while the ADX measures the intensity of that trend.
Additionally, the script includes a dedicated "Time Range" function. This allows quantitative traders to test the strategy's efficacy during specific market regimes, such as a known bull market year or a high-volatility economic period, by defining strict start and end timestamps.
Settings
- FastMA: Sets the period for the short-term Simple Moving Average.
- SlowMA: Sets the period for the long-term Simple Moving Average.
- ADX Smoothing: Determines the lookback period for calculating the ADX.
- DI Period: Sets the lookback period for the Positive (DI+) and Negative (DI-) Directional Indicators.
- Keylevel for ADX: The threshold value the ADX must exceed to confirm a trending market.
- From Month/Day/Year: Defines the start date for the backtest range.
- Thru Month/Day/Year: Defines the end date for the backtest range.
- Show Date Range: Toggles a background visual highlight to indicate the active testing window.
FAQ
How do I adjust the strategy for different timeframes? Users can modify the FastMA and SlowMA settings to suit different chart periodicities; lower values generally respond faster to price changes, while higher values provide more smoothing.
What does the gray background represent? The gray background signifies the active "Time Range" defined in the settings. Strategy calculations and trade executions only occur within this highlighted window.
How can I access the Simple Moving Average + ADX + DMI + Time Range Test? 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.