All indicators

RSI MACD with conditional MA indicator backtesting

Oct 4, 2018

Static chart image
SignalsOscillatorsDashboardMoving Averages

The RSI MACD with conditional MA indicator backtesting tool provides a comprehensive framework for evaluating a strategy that combines Relative Strength Index (RSI), Moving Average Convergence Divergence (MACD) logic, and multiple Moving Averages (MA) to identify trend reversals and momentum shifts. It aims to offer a robust backtesting environment for traders looking to validate entries based on the convergence of price-based and momentum-based filters.

Usage

The script is primarily used to backtest long-only strategies by analyzing the interaction between RSI-derived MACD lines and price-based Moving Averages. A buy signal is generated when momentum (RSI MACD) crosses upward while price remains above key trend filters, such as a long-term control MA or a shorter-period MA cross.

Example scenarios include:

  • Momentum Entry: Buying when the MACD line (derived from RSI) crosses over its signal line, provided the price is above the Control MA.
  • Trend Entry: Buying when a short-term Moving Average crosses above the Control MA or a long-term Moving Average.
  • Exit Logic: The strategy closes positions when a bearish MACD signal occurs or when price-based stop-loss conditions (like a bearish MA crossunder) are met.

Details

The script executes logic by first calculating a standard RSI. It then applies MACD calculations (Fast MA - Slow MA) directly to the RSI values rather than raw price, creating a momentum oscillator that is bounded and normalized.

Simultaneously, it tracks three distinct Moving Averages on the price (OHLC4):

  1. Short MA: Based on the fast length setting.
  2. Long MA: Based on the slow length setting.
  3. Control MA: A higher-period baseline used as a primary trend filter.

The strategy filters momentum entries based on the "maHist" (Short MA - Control MA), ensuring trades are only taken when the immediate price trend is positive relative to the control baseline.

Settings

Backtest Window

  • Backtest Start/Stop Year/Month/Day: Defines the specific date range for the strategy simulation.
  • Color Background?: Highlights the active backtesting period on the chart for visual clarity.

Momentum Settings

  • Length: The lookback period for the base RSI calculation.
  • Fast Length: The period for the fast RSI-based moving average.
  • Slow Length: The period for the slow RSI-based moving average.
  • Signal Length: The smoothing period for the RSI MACD signal line.

Trend Settings

  • Control MA: The period for the primary trend-filtering Moving Average.
  • Buy on crossover control MA?: A toggle to enable or disable entries specifically triggered by the price crossing above the Control MA.

FAQ

How do I interpret the histograms and lines?

The blue line represents the RSI-based MACD, while the histogram shows the difference between the MACD and its signal line. Values above 50 generally indicate bullish momentum in this specific implementation.

What causes a stop-loss exit?

The strategy triggers a "stop" exit if the Short MA crosses under either the Long MA or the Control MA, acting as a trend-following safety mechanism.

How can I access this tool?

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.