OPEN-SOURCE SCRIPT

McClellan A-D Volume Integration Model

The strategy integrates the McClellan A-D Oscillator with an adjustment based on the Advance/Decline (A-D) volume data. The McClellan Oscillator is calculated by taking the difference between the short-term and long-term exponential moving averages (EMAs) of the A-D line. This strategy introduces an enhancement where the A-D volume (the difference between the advancing and declining volume) is factored in to adjust the oscillator value.

Inputs:

• ema_short_length: The length for the short-term EMA of the A-D line.
• ema_long_length: The length for the long-term EMA of the A-D line.
• osc_threshold_long: The threshold below which the oscillator must drop for an entry signal to trigger.

• exit_periods: The number of periods after which the position is closed.
• Data Sources:
• ad_advance and ad_decline are the data sources for advancing and declining issues, respectively.

• vol_advance and vol_decline are the volume data for the advancing and declining issues. If volume data is unavailable, it defaults to na (Not Available), and the fallback logic ensures that the strategy continues to function.

McClellan Oscillator with Volume Adjustment:

• The A-D line is calculated by subtracting the declining issues from the advancing issues. Then, the volume difference is applied to this line, creating a “weighted” A-D line.

• The short and long EMAs are calculated for the weighted A-D line to generate the McClellan Oscillator.

Entry Condition:

• The strategy looks for a reversal signal, where the oscillator falls below the threshold and then rises above it again. The condition is designed to trigger a long position when this reversal happens.

Exit Condition:

• The position is closed after a set number of periods (exit_periods) have passed since the entry.

Plotting:

• The McClellan Oscillator and the threshold are plotted on the chart for visual reference.
• Entry and exit signals are highlighted with background colors to make the signals more visible.

Scientific Background:

The McClellan A-D Oscillator is a popular market breadth indicator developed by Sherman and Marian McClellan. It is used to gauge the underlying strength of a market by analyzing the difference between the number of advancing and declining stocks. The oscillator is typically calculated using exponential moving averages (EMAs) of the A-D line, with the idea being that crossovers of these EMAs indicate potential changes in the market’s direction.

The integration of A-D volume into this model adds another layer of analysis, as volume is often considered a leading indicator of price movement. By factoring in volume, the strategy becomes more sensitive to not just the number of advancing or declining stocks but also how significant those movements are based on trading volume, as discussed in Schwager, J. D. (1999). Technical Analysis of the Financial Markets. This enhanced version aims to capture stronger and more sustainable trends in the market, helping to filter out false signals.

Additionally, volume analysis is often used to confirm price movements, as described in Wyckoff, R. (1931). The Day Trading System. Therefore, incorporating the volume of advancing and declining stocks in the McClellan Oscillator offers a more robust signal for trading decisions.
Advance/Decline Lineeducationalstatistics

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer