McClellan Oscillator Visualizer For ThinkOrSwim

Popeious

New member
For those who track, use, and rely on the McClellan Oscillator for identifying over-sold conditions....

I made this script, to take the MOSC (aka NYMO), and allowing for a variety of user-defined parameters.. for visualizing it without taking up the lower-study area screen real estate.

This study is intended to alert you when the NYMO reaches a user-defined 'oversold' or 'overbought' level, and it also has a second threshold for when you consider it truly overbought or oversold.

The user-defined features allow you to determine if the labels are displayed regardless of symbol, or, only for symbols that are relevant to the NYMO calculations (ie; SPX, SPY, /ES, NDX, QQQ, /NQ).

You can show bubbles 'by the candle' or move the out of the way of the candles.
You can have it send an audible alert, or not.

I do intent to modify the script to determine if the symbol is SPX (related) or NDX related) and automatically change the exchange used in the NYMO calculation accordingly (instead of requiring the user to adjust it manually).

You get up pointing 'Green Arrows' indicating that the NYMO is at or well below the 'oversold' threshold. (implying, the low is deeply oversold and you should be looking up from here); or down pointing 'Red Arrows' indicating the NYMO is well 'overbought' and you should be careful with putting on too much risk.

You will get yellow up arrows or yellow down arrows.. as the 1st level of oversold or overbought conditions are met.

The ultimate form of this script would be for it to identify a divergence in price, relative to the direction of the NYMO; similar in fashion to an RSI Divergence; however, this seems to be rather difficult for ThinkScript to accomplish (for RSI, or NYMO).

Screen Capture Samples are attached.

The STANDARD McClellan Oscillator Study added to a 1y1d chart.

1737509337562.png
I lost too much screen real estate for something I only need to be aware of as it got close to being oversold, and then when it becomes oversold.

So I made my NYMO Extreme's Study to visualize the important details (for me) without losing a the screen space.
Then, I made it customizable... and intelligent.

1737509487404.png


Move the bubble (with the actual values of the NYMO out of the way of the candles.

1737509533758.png


Or... plot the bubbles close to the candles, but turn off the overbought conditions; since I'm more concerned with oversold conditions.

1737509610965.png


And.. Make it smart... so that, none of this appears on the screen, if the symbol is not relevant to the NYMO study itself.

But, if you want use it on a thumbnail... or zoomed in.. maybe you want to clean it up even more.

1737509795264.png



Code:
# Pope's NYMO Extremes with Symbol Filtering (V3.01) 2025-01-21
# Script that allows you to define 2 upside and 2 downside thresholds to provide arrows
# on your chart when the NYMO is approaching an oversold/overbought condition, and
# when it has arrived at an overbought/sold condition.
# Added label to be displayed in upper left corner of chart.
# Added logic to move the bubbles away from candles.
# Added logic to send a notification/audio or not.
# Added logic to filter arrows (tuned study off; if not SPX,SPY,/ES,NDX,QQQ,/NQ)
# Separated bubbles into overbought and oversold and made user defined.


input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input ratioAdjusted = yes;

input approach_over_bought = 60;
input over_bought = 80;
input approach_over_sold = -60;
input over_sold = -80;

input arrow_offset = 2;
input bubble_by_candles = yes;
input show_overbought_bubbles = no;
input show_oversold_bubbles = yes;
input show_labels = yes;
input enableAudibleAlerts = no;
input filter_symbols = yes;  # Enable/disable symbol filtering

# Define valid symbols based on the selected exchange
def isNYSE = exchange == exchange.NYSE and (GetSymbolPart(1) == "/ES:XCME" or GetSymbol() == "SPY" or GetSymbol() == "SPX");
def isNASDAQ = exchange == exchange.NASDAQ and (GetSymbolPart(1) == "/NQ:XCME" or GetSymbol() == "NDX" or GetSymbol() == "QQQ");
def isValidSymbol = isNYSE or isNASDAQ;

def symbolFilterCheck = (filter_symbols and isValidSymbol) or !filter_symbols;

# McClellan Oscillator Calculation
def McClellanOsc = reference McClellanSummationIndex(exchange = exchange, "fast length" = fastLength, "slow length" = slowLength, "ratio adjusted" = ratioAdjusted).mcClellanOsc;

def overboughtCondition1 = McClellanOsc >= approach_over_bought and McClellanOsc < over_bought;
def overboughtCondition2 = McClellanOsc >= over_bought;
def oversoldCondition1 = McClellanOsc <= approach_over_sold and McClellanOsc > over_sold;
def oversoldCondition2 = McClellanOsc <= over_sold;

def arrowPositionOverbought = HighestAll(high) - (arrow_offset * TickSize());
def arrowPositionOversold = LowestAll(low) + (arrow_offset * TickSize());

# Plotting Overbought and Oversold Arrows
plot overbought_yellow = if symbolFilterCheck and overboughtCondition1 then arrowPositionOverbought else Double.NaN;
plot overbought_red = if symbolFilterCheck and overboughtCondition2 then arrowPositionOverbought else Double.NaN;
plot oversold_yellow = if symbolFilterCheck and oversoldCondition1 then arrowPositionOversold else Double.NaN;
plot oversold_green = if symbolFilterCheck and oversoldCondition2 then arrowPositionOversold else Double.NaN;

overbought_yellow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
overbought_yellow.SetDefaultColor(Color.YELLOW);
overbought_red.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
overbought_red.SetDefaultColor(Color.RED);
oversold_yellow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
oversold_yellow.SetDefaultColor(Color.YELLOW);
oversold_green.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
oversold_green.SetDefaultColor(Color.GREEN);

# Bubble Logic
def bubbleOverboughtPosition = if bubble_by_candles then high - arrow_offset + 3 else  HighestAll(high) + arrow_offset + 3 ;
def bubbleOversoldPosition = if bubble_by_candles then  low - arrow_offset - 3 else LowestAll(low) - arrow_offset - 3;

AddChartBubble(symbolFilterCheck and show_overbought_bubbles and overboughtCondition1, bubbleOverboughtPosition, "NYMO " + ROUND(McClellanOsc, 1), Color.YELLOW, yes);
AddChartBubble(symbolFilterCheck and show_overbought_bubbles and overboughtCondition2, bubbleOverboughtPosition + 3, "NYMO " + ROUND(McClellanOsc, 1), Color.RED, yes);
AddChartBubble(symbolFilterCheck and show_oversold_bubbles and oversoldCondition1, bubbleOversoldPosition, "NYMO " + ROUND(McClellanOsc, 1), Color.YELLOW, no);
AddChartBubble(symbolFilterCheck and show_oversold_bubbles and oversoldCondition2, bubbleOversoldPosition - 3, "NYMO " + ROUND(McClellanOsc, 1), Color.GREEN, no);

# Label Logic
AddLabel(symbolFilterCheck and show_labels and overboughtCondition1, "NYMO at " + ROUND(McClellanOsc, 1), Color.YELLOW);
AddLabel(symbolFilterCheck and show_labels and overboughtCondition2, "NYMO at " + ROUND(McClellanOsc, 1) + " Extreme", Color.RED);
AddLabel(symbolFilterCheck and show_labels and oversoldCondition1, "NYMO " + ROUND(McClellanOsc, 1), Color.YELLOW);
AddLabel(symbolFilterCheck and show_labels and oversoldCondition2, "NYMO " + ROUND(McClellanOsc, 1) + " Extreme", Color.GREEN);

# Alert Logic
Alert(enableAudibleAlerts and symbolFilterCheck and overboughtCondition1, "NYMO > " + ROUND(McClellanOsc, 1), Alert.BAR, Sound.Bell);
Alert(enableAudibleAlerts and symbolFilterCheck and overboughtCondition2, "NYMO > " + ROUND(McClellanOsc, 1) + " Extreme", Alert.BAR, Sound.Chimes);
Alert(enableAudibleAlerts and symbolFilterCheck and oversoldCondition1, "NYMO < " + ROUND(McClellanOsc, 1), Alert.BAR, Sound.Bell);
Alert(enableAudibleAlerts and symbolFilterCheck and oversoldCondition2, "NYMO < " + ROUND(McClellanOsc, 1) + " Extreme", Alert.BAR, Sound.Chimes);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

For those who track, use, and rely on the McClellan Oscillator for identifying over-sold conditions....

I made this script, to take the MOSC (aka NYMO), and allowing for a variety of user-defined parameters.. for visualizing it without taking up the lower-study area screen real estate.

This study is intended to alert you when the NYMO reaches a user-defined 'oversold' or 'overbought' level, and it also has a second threshold for when you consider it truly overbought or oversold.

The user-defined features allow you to determine if the labels are displayed regardless of symbol, or, only for symbols that are relevant to the NYMO calculations (ie; SPX, SPY, /ES, NDX, QQQ, /NQ).

You can show bubbles 'by the candle' or move the out of the way of the candles.
You can have it send an audible alert, or not.

I do intent to modify the script to determine if the symbol is SPX (related) or NDX related) and automatically change the exchange used in the NYMO calculation accordingly (instead of requiring the user to adjust it manually).

You get up pointing 'Green Arrows' indicating that the NYMO is at or well below the 'overbought' threshold. (implying, the low is deeply oversold and you should be looking up from here); or down pointing 'Red Arrows' indicating the NYMO is well 'overbought' and you should be careful with putting on too much risk.

You will get yellow up arrows or yellow down arrows.. as the 1st level of oversold or overbought conditions is bet.
The ultimate form of this script would be for it to identify a divergence in price, relative to the direction of the NYMO; similar in fashion to an RSI Divergence; however, this seems to be rather difficult for ThinkScript to accomplish (for RSI, or NYMO).

Screen Capture Samples are attached.

The STANDARD McClellan Oscillator Study added to a 1y1d chart.

View attachment 23926I lost too much screen real estate for something I only need to be aware of as it got close to being oversold, and then when it becomes oversold.

So I made my NYMO Extreme's Study to visualize the important details (for me) without losing a the screen space.
Then, I made it customizable... and intelligent.

View attachment 23927

Move the bubble (with the actual values of the NYMO out of the way of the candles.

View attachment 23928

Or... plot the bubbles close to the candles, but turn off the overbought conditions; since I'm more concerned with oversold conditions.

View attachment 23929

And.. Make it smart... so that, none of this appears on the screen, if the symbol is not relevant to the NYMO study itself.

But, if you want use it on a thumbnail... or zoomed in.. maybe you want to clean it up even more.

View attachment 23930


Code:
# Pope's NYMO Extremes with Symbol Filtering (V3.01) 2025-01-21
# Script that allows you to define 2 upside and 2 downside thresholds to provide arrows
# on your chart when the NYMO is approaching an oversold/overbought condition, and
# when it has arrived at an overbought/sold condition.
# Added label to be displayed in upper left corner of chart.
# Added logic to move the bubbles away from candles.
# Added logic to send a notification/audio or not.
# Added logic to filter arrows (tuned study off; if not SPX,SPY,/ES,NDX,QQQ,/NQ)
# Separated bubbles into overbought and oversold and made user defined.


input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input ratioAdjusted = yes;

input approach_over_bought = 60;
input over_bought = 80;
input approach_over_sold = -60;
input over_sold = -80;

input arrow_offset = 2;
input bubble_by_candles = yes;
input show_overbought_bubbles = no;
input show_oversold_bubbles = yes;
input show_labels = yes;
input enableAudibleAlerts = no;
input filter_symbols = yes;  # Enable/disable symbol filtering

# Define valid symbols based on the selected exchange
def isNYSE = exchange == exchange.NYSE and (GetSymbolPart(1) == "/ES:XCME" or GetSymbol() == "SPY" or GetSymbol() == "SPX");
def isNASDAQ = exchange == exchange.NASDAQ and (GetSymbolPart(1) == "/NQ:XCME" or GetSymbol() == "NDX" or GetSymbol() == "QQQ");
def isValidSymbol = isNYSE or isNASDAQ;

def symbolFilterCheck = (filter_symbols and isValidSymbol) or !filter_symbols;

# McClellan Oscillator Calculation
def McClellanOsc = reference McClellanSummationIndex(exchange = exchange, "fast length" = fastLength, "slow length" = slowLength, "ratio adjusted" = ratioAdjusted).mcClellanOsc;

def overboughtCondition1 = McClellanOsc >= approach_over_bought and McClellanOsc < over_bought;
def overboughtCondition2 = McClellanOsc >= over_bought;
def oversoldCondition1 = McClellanOsc <= approach_over_sold and McClellanOsc > over_sold;
def oversoldCondition2 = McClellanOsc <= over_sold;

def arrowPositionOverbought = HighestAll(high) - (arrow_offset * TickSize());
def arrowPositionOversold = LowestAll(low) + (arrow_offset * TickSize());

# Plotting Overbought and Oversold Arrows
plot overbought_yellow = if symbolFilterCheck and overboughtCondition1 then arrowPositionOverbought else Double.NaN;
plot overbought_red = if symbolFilterCheck and overboughtCondition2 then arrowPositionOverbought else Double.NaN;
plot oversold_yellow = if symbolFilterCheck and oversoldCondition1 then arrowPositionOversold else Double.NaN;
plot oversold_green = if symbolFilterCheck and oversoldCondition2 then arrowPositionOversold else Double.NaN;

overbought_yellow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
overbought_yellow.SetDefaultColor(Color.YELLOW);
overbought_red.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
overbought_red.SetDefaultColor(Color.RED);
oversold_yellow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
oversold_yellow.SetDefaultColor(Color.YELLOW);
oversold_green.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
oversold_green.SetDefaultColor(Color.GREEN);

# Bubble Logic
def bubbleOverboughtPosition = if bubble_by_candles then high - arrow_offset + 3 else  HighestAll(high) + arrow_offset + 3 ;
def bubbleOversoldPosition = if bubble_by_candles then  low - arrow_offset - 3 else LowestAll(low) - arrow_offset - 3;

AddChartBubble(symbolFilterCheck and show_overbought_bubbles and overboughtCondition1, bubbleOverboughtPosition, "NYMO " + ROUND(McClellanOsc, 1), Color.YELLOW, yes);
AddChartBubble(symbolFilterCheck and show_overbought_bubbles and overboughtCondition2, bubbleOverboughtPosition + 3, "NYMO " + ROUND(McClellanOsc, 1), Color.RED, yes);
AddChartBubble(symbolFilterCheck and show_oversold_bubbles and oversoldCondition1, bubbleOversoldPosition, "NYMO " + ROUND(McClellanOsc, 1), Color.YELLOW, no);
AddChartBubble(symbolFilterCheck and show_oversold_bubbles and oversoldCondition2, bubbleOversoldPosition - 3, "NYMO " + ROUND(McClellanOsc, 1), Color.GREEN, no);

# Label Logic
AddLabel(symbolFilterCheck and show_labels and overboughtCondition1, "NYMO at " + ROUND(McClellanOsc, 1), Color.YELLOW);
AddLabel(symbolFilterCheck and show_labels and overboughtCondition2, "NYMO at " + ROUND(McClellanOsc, 1) + " Extreme", Color.RED);
AddLabel(symbolFilterCheck and show_labels and oversoldCondition1, "NYMO " + ROUND(McClellanOsc, 1), Color.YELLOW);
AddLabel(symbolFilterCheck and show_labels and oversoldCondition2, "NYMO " + ROUND(McClellanOsc, 1) + " Extreme", Color.GREEN);

# Alert Logic
Alert(enableAudibleAlerts and symbolFilterCheck and overboughtCondition1, "NYMO > " + ROUND(McClellanOsc, 1), Alert.BAR, Sound.Bell);
Alert(enableAudibleAlerts and symbolFilterCheck and overboughtCondition2, "NYMO > " + ROUND(McClellanOsc, 1) + " Extreme", Alert.BAR, Sound.Chimes);
Alert(enableAudibleAlerts and symbolFilterCheck and oversoldCondition1, "NYMO < " + ROUND(McClellanOsc, 1), Alert.BAR, Sound.Bell);
Alert(enableAudibleAlerts and symbolFilterCheck and oversoldCondition2, "NYMO < " + ROUND(McClellanOsc, 1) + " Extreme", Alert.BAR, Sound.Chimes);
Hi Popeious, can you please provide the codes for upper chart with bubble and arrows. The above does not show them. Thanks,
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
461 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top