McClellan Oscillator For ThinkOrSwim

Mike

Member
How can I plot Bollinger Bands (any length, any standard deviation) on the McClellan Oscillator regardless of what CASE e.g. NYSE, NASDAQ, etc. I'd like to chart in a subgraph? Scratching my head on this one after several hours. Thanks!
 

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

How can I plot Bollinger Bands (any length, any standard deviation) on the McClellan Oscillator regardless of what CASE e.g. NYSE, NASDAQ, etc. I'd like to chart in a subgraph? Scratching my head on this one after several hours. Thanks!

This is generally how one adds a bollinger band to another indicator.

Screenshot-2022-10-29-202623.png
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2022
#

declare lower;

input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input over_bought = 100;
input over_sold = -100;
input ratioAdjusted = No;

plot McClellanOsc = reference McClellanSummationIndex(exchange = exchange, "fast length" = fastLength, "slow length" = slowLength, "ratio adjusted" = ratioAdjusted).mcClellanOsc;
plot OverBought = over_bought;
plot OverSold = over_sold;
plot ZeroLine = 0;

McClellanOsc.SetDefaultColor(GetColor(1));
OverBought.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(3));

def price = mcclellanOsc;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

LowerBand.SetDefaultColor(GetColor(0));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));
 
Can this be done with keltner channel?

See if this helps

Screenshot-2022-10-30-110607.png
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2022
#

declare lower;

input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input over_bought = 100;
input over_sold = -100;
input ratioAdjusted = No;

plot McClellanOsc = reference McClellanSummationIndex(exchange = exchange, "fast length" = fastLength, "slow length" = slowLength, "ratio adjusted" = ratioAdjusted).mcClellanOsc;
plot OverBought = over_bought;
plot OverSold = over_sold;
plot ZeroLine = 0;

McClellanOsc.SetDefaultColor(GetColor(1));
OverBought.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(3));

def price = mcclellanOsc;
declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 20;

input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(price, price, price), length);

def average = MovingAverage(averageType, price, length);

plot Avg = average[-displace];
Avg.SetDefaultColor(GetColor(1));

plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));

plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));
 
This is generally how one adds a bollinger band to another indicator.
Is there a possibility to added a red color when McClellan goes below 0 and turns negative? I am using the standard one from thinkorswim, but when negative it shows the same color as possible. Thanks!
 
I have looked but can't seem to find a study that marks the price chart when the McClellan Osc. crosses above or below the zero line. Anything like this available? Thanks for any help.
 
Here you go:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2023
#

input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input over_bought = 100;
input over_sold = -100;
input ratioAdjusted = No;

def McClellanOsc = reference McClellanSummationIndex(exchange = exchange, "fast length" = fastLength, "slow length" = slowLength, "ratio adjusted" = ratioAdjusted).mcClellanOsc;
def OverBought = over_bought;
def OverSold = over_sold;
def ZeroLine = 0;

plot bullish = if McClellanOsc crosses above ZeroLine then low else double.nan;
plot bearish = if McClellanOsc crosses below ZeroLine then high else double.nan;
bullish.setPaintingStrategy(PaintingStrategy.ARROW_UP);
bearish.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Is there a possibility to added a red color when McClellan goes below 0 and turns negative? I am using the standard one from thinkorswim, but when negative it shows the same color as possible. Thanks!
I modified the standard indicator for the same reason.
Added capibility to plot it on intraday charts. Refer to "periodicity" to indicate multiple to make it equal to daily version eg. on 30 min chart use 13
------------------------------------------------------------------------------------------
declare lower;

input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input periodicity = 1;
input ratioAdjusted = Yes;
input isCumulative = Yes;

def advances;
def declines;
switch (exchange) {
case NYSE:
advances = close("$ADVN");
declines = close("$DECN");
case NASDAQ:
advances = close("$ADVN/Q");
declines = close("$DECN/Q");
case AMEX:
advances = close("$ADVA");
declines = close("$DECA");
}
def breadth;
def neutral_level;
def over_bought;
def over_sold;

if (ratioAdjusted) {
breadth = 1000 * (advances - declines) / (advances +
declines);
neutral_level = 0;
over_bought = 500;
over_sold = -500;
} else {
breadth = advances - declines;
neutral_level = 1000;
over_bought = Double.NaN;
over_sold = Double.NaN;
}

def emaFastCorr = ExpAverage(CompoundValue(1, if !IsNaN(breadth) then breadth else emaFastCorr[1], 0), fastLength*periodicity);
def emaSlowCorr = ExpAverage(CompoundValue(1, if !IsNaN(breadth) then breadth else emaSlowCorr[1], 0), slowLength*periodicity);
def mcClellanOsc = if !IsNaN(close) then emaFastCorr - emaSlowCorr else Double.NaN;
def mcClellanSummationIndex = mcClellanSummationIndex[1] + if !IsNaN(breadth) then mcClellanOsc else 0;

plot SummationIndex;
if IsNaN(close) {
SummationIndex = Double.NaN;
} else if (isCumulative) {
SummationIndex = neutral_level + mcClellanSummationIndex;
} else {
SummationIndex = neutral_level + mcClellanOsc - (10 * emaFastCorr + 20 * emaSlowCorr);
}
plot OverBought = over_bought;
plot OverSold = over_sold;
plot NeutralLevel = neutral_level;

SummationIndex.DefineColor("Up", GetColor(1));
SummationIndex.DefineColor("Down", GetColor(0));
SummationIndex.AssignValueColor(if SummationIndex > SummationIndex[1] then SummationIndex.color("Up") else SummationIndex.color("Down"));
OverBought.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));
NeutralLevel.SetDefaultColor(GetColor(7));

1691002934668.png
 
How do I make the McCellan Oscillator indicator cloud a solid color:

2023-11-11 06_13_09-Window.png



Code:
input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input over_bought = 100;
input over_sold = -100;
input ratioAdjusted = No;

def McClellanOsc = reference McClellanSummationIndex(exchange = exchange, "fast length" = fastLength, "slow length" = slowLength, "ratio adjusted" = ratioAdjusted).mcClellanOsc;
def OverBought = over_bought;
def OverSold = over_sold;
def ZeroLine = 0;

AddCloud(McClellanOsc, ZeroLine, Color.GREEN, Color.Red);

AddLabel(1, "McCellan: " + McClellanOsc , IF McClellanOsc > 0 then Color.GREEN else Color.RED);

#plot bullish = if McClellanOsc crosses above ZeroLine then low else double.nan;
#plot bearish = if McClellanOsc crosses below ZeroLine then high else double.nan;
#bullish.setPaintingStrategy(PaintingStrategy.ARROW_UP);
#bearish.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
339 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