McGinley MACD For ThinkOrSwim

David45

Active member
2019 Donor
Hi Folks,

This version of the MACD uses the McGinley Dynamic Indicator. Credit goes to our dear friend Mobius. Enjoy!

Ruby:
# Mobius
# V01.03.12.2011
# Note: Arrows plotted are intra-trend indicators. So they may be couter trend or with trend.

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input data = close;
input AvgType = AverageType.Exponential;
input showBreakoutSignals = yes;

script McGinley
{
input data = close;
input n = 12;
def M = CompoundValue(1, M[1] + (data - M[1]) /
(n * Power((data / M[1]), 4)), data);
plot McG = M;
}
plot Value = McGinley(data, fastLength) - McGinley(data, slowLength);
plot Avg = MovingAverage(AvgType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
plot UpSignal = if Diff crosses above ZeroLine
then ZeroLine
else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine
then ZeroLine
else Double.NaN;

AddLabel(1, if Value < 0 and Value < Avg
then "Trend Down Accelerating"
else if Value < 0 and Value > Avg
then "Trend Down Slowing"
else if Value > 0 and Value > Avg
then "Trend Up Accelerating"
else if Value > 0 and Value < Avg
then "Trend Up Slowing"
else "?",
if Value < 0
then color.red
else color.green);
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Value.AssignValueColor(if Value > 0 then Color.DARK_GREEN else Color.RED);
 
Last edited by a moderator:
Any way to get this where it can be copied and pasted. I keep getting an error message. Thanks in advance !

This is what i copied and pasted

At the bottom it says
Identifier already used: Data at 63:80
Input cannot be modified: Data 63:80
The word Data is in red in the code portion

Ruby:
# Mobius
# V01.03.12.2011
# Note: Arrows plotted are intra-trend indicators. So they may be couter trend or with trend.

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input data = close;
input AvgType = AverageType.Exponential;
input showBreakoutSignals = yes;

script McGinley
{
input data = close;
input n = 12;
def M = CompoundValue(1, M[1] + (data - M[1]) /
(n * Power((data / M[1]), 4)), data);
plot McG = M;
}
plot Value = McGinley(data, fastLength) - McGinley(data, slowLength);
plot Avg = MovingAverage(AvgType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
plot UpSignal = if Diff crosses above ZeroLine
then ZeroLine
else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine
then ZeroLine
else Double.NaN;

AddLabel(1, if Value < 0 and Value < Avg
then "Trend Down Accelerating"
else if Value < 0 and Value > Avg
then "Trend Down Slowing"
else if Value > 0 and Value > Avg
then "Trend Up Accelerating"
else if Value > 0 and Value < Avg
then "Trend Up Slowing"
else "?",
if Value < 0
then color.red
else color.green);
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Value.AssignValueColor(if Value > 0 then Color.DARK_GREEN else Color.RED);plot Data = close;

Identifier already used: Data at 63:80
Input cannot be modified: Data 63:80
(The word Data in the code portion is in red)

To clarify
The word Data is in red when I go to paste it into the TOS "create" format
 
Last edited by a moderator:
Any way to get this where it can be copied and pasted. I keep getting an error message. Thanks in advance !
To clarify
The word Data is in red when I go to paste it into the TOS "create" format
When clicking create a new study.
There is a placeholder line of code:
Code:
plot Data = close;
This needs to be deleted before code is added.
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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