McClellan Oscillator
Calculate the McClellan Oscillator for a given price series.
The McClellan Oscillator is the difference between a short-term and a long-term exponential moving average of the daily advance/decline signal. Traditionally it is calculated from the number of advancing minus declining stocks across a market; here it is applied to each ticker’s own signal (+1 on a day it closed higher, -1 on a day it closed lower, 0 otherwise), so it measures how persistently that ticker has been rising or falling.
The formula is as follows:
\[\text{McClellan Oscillator} = \operatorname{EMA}(\text{Advance} / \text{Decline Signal},\; \text{short\_ema\_window}) - \operatorname{EMA}(\text{Advance} / \text{Decline Signal},\; \text{long\_ema\_window})\]Also known as: McClellan oscillator, market breadth.
McClellan Oscillator in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_mcclellan_oscillator as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
tickers=["EWJ", "EWG", "EWU", "EWQ", "EWZ", "INDA", "FXI", "EWC", "EWA", "EWY"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.technicals.get_mcclellan_oscillator().loc[:, ["EWJ", "EWG", "EWZ", "INDA", "FXI", "Benchmark"]].tail(5)
Or, after setting up the Finance Toolkit MCP, ask:
How did the McClellan Oscillator of the iShares MSCI Japan (EWJ), Germany (EWG), Brazil (EWZ), India (INDA) and China Large-Cap (FXI) ETFs, based on their daily up and down closes, move from 24 to 31 December 2025?
Which returns:
| Date | EWJ | EWG | EWZ | INDA | FXI | Benchmark |
|---|---|---|---|---|---|---|
| 2025-12-24 | -0.0357 | 0.1365 | -0.0693 | 0.0631 | 0.0419 | 0.0718 |
| 2025-12-26 | -0.0875 | 0.1604 | -0.0203 | -0.002 | 0.0863 | 0.0008 |
| 2025-12-29 | -0.0314 | 0.0801 | -0.0783 | -0.0576 | 0.0239 | -0.06 |
| 2025-12-30 | -0.0832 | 0.1111 | -0.0275 | -0.0049 | 0.0703 | -0.1116 |
| 2025-12-31 | -0.1272 | 0.037 | -0.0839 | 0.0402 | 0.0097 | -0.1552 |
Parameters
get_mcclellan_oscillator accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The time period to consider for historical data. Can be “intraday”, “daily”, “weekly”, “monthly”, “quarterly” or “yearly”. Defaults to “daily”. | "weekly" |
close_column | str | The name of the column containing the close prices. Defaults to “Adj Close”. | "Close" |
short_ema_window | int | The window size for the short-term EMA. Defaults to 19. | 10 |
long_ema_window | int | The window size for the long-term EMA. Defaults to 39. | 30 |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the indicator values. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |