MACD edit

fabriciom

New member
Hi,

I'm looking to edit the MACD indicator to add some sort of signal (maybe the pointer) when the macd values crosses a certain value.

Can the builtin studies be edited?

Or can this be done with having to touch the code? I don't seem to find a way.

Thanks
 
Solution
Hi,

How can I access the code of the built in studies?

I have coding experience but new to thinkorswim

Thanks.

Step 1
Capture.jpg

Step 2
Capture.jpg
Hi,

I'm looking to edit the MACD indicator to add some sort of signal (maybe the pointer) when the macd values crosses a certain value.

Can the builtin studies be edited?

Or can this be done with having to touch the code? I don't seem to find a way.

Thanks

You can make a copy of the built-in code, create a new study and paste the ccde there. You can then modify it as you would like. Look at built-in scripts with crossovers or here in the search area, on how to code these. If you need more help, come back with a more specific request.
 
You can make a copy of the built-in code, create a new study and paste the ccde there. You can then modify it as you would like. Look at built-in scripts with crossovers or here in the search area, on how to code these. If you need more help, come back with a more specific request.

Hi,

How can I access the code of the built in studies?

I have coding experience but new to thinkorswim

Thanks.
 
Ruby:
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

# show macd value signals 20/06/2022
input macdHigh = 15;
input macdLow = -15;

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, 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;

# show macd value signals 20/06/2022
plot UpSignalMacdValue = if Value >= macdHigh then Value else Double.NaN;
plot DownSignalMacdValue = if Value <= macdLow then Value else Double.NaN;

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);

# show macd value signals 20/06/2022
UpSignalMacdValue.SetDefaultColor(Color.UPTICK);
UpSignalMacdValue.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignalMacdValue.SetDefaultColor(Color.DOWNTICK);
DownSignalMacdValue.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
I've done my mod. Not sure if this is useful to anyone but I'll share it.

It adds a signal when the MACD value goes above/below a previously set value for high and low.
 
Last edited by a moderator:
I've done my mod. Not sure if this is useful to anyone but I'll share it.

It adds a signal when the MACD value goes above/below a previously set value for high and low.



declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

# show macd value signals 20/06/2022
input macdHigh = 15;
input macdLow = -15;

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, 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;

# show macd value signals 20/06/2022
plot UpSignalMacdValue = if Value >= macdHigh then Value else Double.NaN;
plot DownSignalMacdValue = if Value <= macdLow then Value else Double.NaN;

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);

# show macd value signals 20/06/2022
UpSignalMacdValue.SetDefaultColor(Color.UPTICK);
UpSignalMacdValue.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignalMacdValue.SetDefaultColor(Color.DOWNTICK);
DownSignalMacdValue.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Thanks for sharing!!

As the MACD has very low values, I changed your variables to:

# show macd value signals 20/06/2022
input macdHigh = .15;
input macdLow = -.15;

Giving interesting signals as shown in the lower panel:
Capture.jpg
 

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
469 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