I’ve been so busy, gotten sick, had work deadlines, that I’ve been away from the blog for ages. I’m making a renewed push at all my projects, so here’s an indicator that was requested by a reader: A MACD that follows an symbol independent of the symbol of the underlying chart. You could use this to plot the MACD of the VIX onto a chart of the VXX ETF for example. Or to plot the broad market SPY on an individual stock you are watching.
Anyway, here’s how to do it:
A MACD is just a distance between two moving averages. The histogram is a distance between the MACD line and a moving average of that line. So we will build our own MACD from scratch using data from the symbol we are interested in.
Traditionally, the MACD uses exponential moving averages. I don’t know that it matters, but I do prefer exponential over simple because of the way they blend out past data. So we start with the inputs for the symbol and the MACD periods:
Input symbol=”VIX”;
Input period1=12;
input period2=26;
input periodhist=9;
Next we create the two exponential averages for the MACD line:
Def exp1=expaverage(close(symbol),period1);
Def exp2=expaverage(close(symbol),period2);
Plot MACD=exp1-exp2;
Def macdma=average(MACD,periodhist);
Plot Hist=MACD-macdma;
Add some formatting and that’s it!
This indicator is free. You can download “AltMACDSTUDY.ts” from “Released Thinkscript Studies” on my Google site. Thanks for (hopefully still) reading!
Tags: macd, Thinkscript

September 22, 2010 at 7:52 am
Thank you! It seems like only one MA plotted into the code. How can i make standard MACD crossover?
September 22, 2010 at 8:03 am
Change the line that says Def macdma=average(MACD,periodhist);
To Plot macdma=average(MACD,periodhist);
September 22, 2010 at 8:18 am
Yes, there is crossover.
Thanks a lot P!
January 1, 2011 at 8:16 pm
How do I change the settings so that it loads the MACD for any given ticker, not the input in the study settings?
January 6, 2011 at 1:43 pm
Not sure what you’re asking, Deflator?