All indicators

MACD With Filter: Visual Backtest Module Sample

Dec 16, 2020

Static chart image
SignalsDashboardMoving AveragesVolatility

The MACD With Filter: Visual Backtest Module Sample indicator provides a comprehensive template for traders to test MACD crossover strategies integrated with multi-layered trend filters. It simplifies the process of validating trade ideas by offering a visual backtesting environment directly on the chart, allowing users to assess the viability of MACD signals when combined with Moving Average and ADX trend filters.

Usage

The indicator can be used to identify trend-following entry points by combining MACD crossovers with secondary filters. A common example is identifying a buy signal when the MACD line crosses above the signal line below the zero level, provided price is above the specified Moving Average and the ADX is above a chosen threshold. Users can toggle the Visual Backtest Module to see entry prices, stop losses, and take profit targets plotted historically, facilitating a rapid assessment of strategy performance without coding a full strategy script.

Details

The script functions as a modular template for strategy development. It utilizes a Moving Average (EMA, SMA, WMA, RMA, or VWMA) to define the primary trend direction and an ADX filter to ensure trade entries only occur during periods of sufficient trend strength. The MACD logic is specifically tuned to catch reversals within a trend: buy signals occur on crossovers below the zero line, and sell signals occur on crossunders above the zero line. The backtesting engine handles one trade at a time, calculating dynamic Stop Loss levels based on ATR or recent High/Low wicks.

Settings

Filter Parameter

  • Use MA Filter: Enables or disables the Moving Average trend filter.
  • MA Filter Type: Selects the smoothing method (EMA, SMA, WMA, RMA, VWMA).
  • MA Filter Length: Sets the lookback period for the trend MA.
  • Use ADX Filter: Enables or disables the ADX strength filter.
  • ADX Filter Length: Sets the lookback for ADX calculations.
  • ADX Filter Threshold: The minimum ADX value required to validate a trade signal.

Signal Parameter

  • MACD Fast Length: The period for the fast EMA in the MACD calculation.
  • MACD Slow Length: The period for the slow EMA in the MACD calculation.
  • MACD Signal Smoothing: The period for the MACD signal line.

Backtest Parameter

  • Enable Visual Backtest Module?: Toggles the display of historical trade simulations.
  • Backtest Type: Restricts the backtest to Buy, Sell, or both directions.
  • Stop Loss Type: Sets the SL calculation method (ATR, Fixed Point, or X Bar High/Low).
  • TP Reward to Risk Ratio: Determines the Take Profit level relative to the initial risk.

Alert Parameter

  • Enable Alert?: Enables TradingView alerts for the generated signals.
  • Alert Type: Filters which signals (Buy, Sell, or both) trigger an alert.

FAQ

How do I use the Stop Loss "X bar high/low" setting?

When selected, the indicator looks back at the specified number of previous bars and places the stop loss at the highest wick (for sells) or lowest wick (for buys), with an optional fixed point offset.

Can I run multiple trades at once in the backtest?

No, the current template is designed for preliminary testing and supports only one active trade at a time.

How do I access MACD With Filter: Visual Backtest Module Sample?

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.