Create a Scan Based on Multiple Time Frame MACD
This is just a quick article (no video). I received several requests from viewers to demonstrate how to create a custom scan based on the Multi Time-Frame MACD indicator. This MTF MACD indicator is available free via the link embedded in the video located HERE, in a post called Thinkorswim MTF MACD Indicator. You will not need the indicator to build this scan, but be sure to go get it so you can plot it on your charts.
One more thing before we jump right in. If you are not familiar with building custom scans in the Thinkorswim platform, be sure to check out these posts to get up to speed: Thinkorswim Custom Scan Stochastic MACD, Thinkorswim Scan TTM Squeeze Histogram, Thinkorswim Scan MACD RSI Part Two. Everything presented here assumes you’ve already viewed at least one of these videos. So if you feel lost… take the few minutes to watch them and get up to speed.
Ok, here it is. As long as you’ve seen the previous videos, I can show you how to build this scan in two screen shots.
This first screen shot is the Scan tab on the Thinkorswim platform. It shows I’ve added three custom study filters. These are added by pressing the button titled “Add Study Filter”. Make sure you set each of the three to your desired time frame. In this case I’ve got mine set to Monthly, Weekly, and Daily. In the next step, you need to click the pencil icon for each of the three studies. The pencil icon opens up the code editing dialog box. I will provide the code here in this post. Scroll down to the next screen shot.
Ok, here is the code dialog box. I’ve clicked to select the tab titled “thinkscript Editor”. Just copy the code from this post into this screen on your platform. Notice the annotations in this screenshot indicate you can flip this from long to short by moving the “#’ symbol. Scroll down for the code to copy into your platform.
There are two DIFFERENT blocks of code here. This first one is to be placed into the two higher time frames. So for this example, I would have this first code block pasted into my Monthly and Weekly time frames.
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
plot scan = Diff[1] > Diff[2];
# OR
#plot scan = Diff[1] < Diff[2];
This second code block is to be pasted into the lowest time frame. In this example, I have this code pasted into my Daily time frame.
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
plot scan = Diff[1] >= Diff[2];
# OR
#plot scan = Diff[1] <= Diff[2];
Don’t go anywhere yet. Here are some important tips:
Ok, that’s it. You’re done. Be sure to save the scan before you close the platform or it will be lost and you’ll have to rebuild it. Please note the code for this scan will ensure your higher time frames have at least one candle closed in the desired direction. This is important as it will remove any false signals (as are present in the current version of the MTF MACD Indicator). An updated indicator will be published in the near future. The other thing to note is the code for the lowest time frame is designed to pick only the very first signal in a series. So this scan is not going to pick up signals from 2-3 or more days ago. It’s going to pick up current signals only. So be sure to run it every day (if you are using the time frames displayed here).
Lean More:
Would you like to learn how to master the custom scan tools on Thinkorswim?
Click here: Thinkorswim Scans Beginner to Advanced
Learn how to build custom scans without writing any code: Thinkorswim Condition Wizard
Pete,
Thank you for building the indicator and the scan, I am loving the indicator for swing trades. 1D,3D and week. The back testing is producing solid results. I have loaded the scan, I just have one problem, the scan is giving plenty of results that are deep in to the trend and not day 1 or day 2 entries, as I was hoping the scan would produce. Is there something I need to add to the code?
Thanks in advance,
Scott
Your observations are correct. The scan is picking up each and every bar in which the conditions are true. The higher time frames will be true for several bars after the initial entry signal. Which means each signal will span multiple bars on the lower time frame.
So you will need to examine the each stock in the results list and determine which ones are presenting their very first bar of the signal which spans multiple bars. I wish we could be more precise, but Thinkorswim requires that we separate each time frame in it’s own study filter. So there is no way for the scan to know if it is the first signal in a series or the last signal in a series. It just knows there is a valid signal on the current lower time frame bar.
Thank you very much sir for the quick reply. I tried to add in the code I found in the condition wizard for other studies “If true within 2 bars” and variations of that, but could not get it. I am sure as I scan daily, I will be able to quickly bypass those that have been on the scan previous days. Or I can make an excel document filter to only tickers not showing in the previous X number of columns.
Could a scan be created similar to this one but to 5min, 30min,1,2,4,hour, and DAY
Yes, just change the time frames on the various study filters. Add and remove study filters as needed. Did you read the article prior to posting this question? The reason I ask is that after watching this video your question should have already been answered.
Hi Pete, Thanks for the instruction. How can you make those studies appear in the scan result as columns? (right now they do not show up when trying to customize the scan result columns)
Like this: https://pbs.twimg.com/media/EaHkI_mUMAAGYla?format=jpg&name=large
The columns displayed in the results section of a scan can be modified just the same as any watchlist. However this video did not included any code for custom watchlist columns.
great study! works perfect on the chart. how can this be turned into a scanner as well so we can scan to see which stocks have all 3 times frames the same (when all 3 are green or all 3 are red)?
Um…. that is precisely what this article describes how to do???
Hi Pete,
A small question I want to know how to use this scan to get stock where in weekly or daily chart it will be just 1-2 bars before the MACD crossover. Now this scan is showing the stock after the MACD crossover I want stock scan just before the crossover.
“just before the crossover”. How exactly do you define that? Because 1-2 bars before the crossover, there is no crossover. It is impossible to read the future.
this scan result gives me the stocks list that don’t show “green” signal in chart as per MTF MACD study – https://www.hahn-tech.com/thinkorswim-mtf-macd-indicator. What am I missing?
Without any other details it is impossible to know “what you are missing”. There are many different settings you can adjust and any one of them may lead to inaccurate results. But the first you should do is make sure you get the most current version of the MTF MACD chart study. The scan is designed to match the second version of the MTF MACD I published. Which is located here: https://www.hahn-tech.com/thinkorswim-strategy-guide-mtf/
Pete, can you show me how to create a display that extracted scan data to show number of stocks in percentage above 50EMA, 100EMA, 200EMA? So can help to tell how strong or weak is the market. Thanks
It will not be possible to assist you in this matter through the comment section of a video. I suggest you post this request in the Q&A forum. We have a topic set up specifically for stock scanners: https://www.hahn-tech.com/ans/cat/scans/
I am playing with this and trying to create a scan on an hourly basis. I find it is an early indicator for options and buying stocks before it shows on the daily. I am wanting 13/30/200 hourly and then look for crosses above and below the 200. Any thoughts?
Nope, I actually have no clue what you are requesting here. The context here is the MTF MACD study. Your question seems to be related to a series of 3 moving averages. If that is the case then this is the wrong place to enter this request. Try our Q&A forum.
I am a bit confused on what the MTF scans for? Today’s scan(2-17-17) pulled up AAPL for the first one. It has neither a red or green dot. I set up my scan the exact way you have posted except for the MACD, I like 8,17,9. Other than that identical. Can you tell me what I did wrong? Is there a way to scan for red/green dots on the histogram? I also have the second version of the indicator as well, it seems the first version gives much faster signals.
Also, The MACD stochastics scan, I’ve set it up like you did in the video and it works great. I tried reversing what I thought was needed to pull up the short trades but had no luck. Any tips on what I should switch to pull up the opposite for short trades? Thanks for your help.
I’ll be able to provide much more detailed response if you post your question in our Q&A forum. As for your question about getting the results of the MTF MACD scan to match the indicator, be sure you are comparing it to version two and not the original. Version two is located here: Thinkorswim Strategy Guide MTF
Hi Pete,
I like the Multiple time frame approach and I am seeing it is pretty accurate for stocks (I added a few more indicators). I am applying a similar strategy to Futures. So lets take for example /CL with 133 tick, 233 tick, 1 min and 2 min. So to make it simple, when the SMA Crosses over the EMA and there is a confluence over all 4 charts, how can I get a SINGLE ALERT. (I dont mind keeping all the charts open in detached windows). Currently I am able to get 4 alerts (one for each chart).
Thanks and Happy Holidays
Hil
Unfortunately the 133 and 233 tick time frames are not supported for scans or multiple time frame studies. 1 min is the lowest time frame supported.
Thats cool. If it were just time frames(1min and 2 mins) would I be able to get a single alert?
Thanks Pete
We could definitely provide more assistance if this were posted to the Q&A forum. So it sounds like y0u would like a chart based study using 4 time frames that would give you audible and visual alerts while the chart is open. If that is the case, then the solution is a bit more complex than we could provide in the Q&A forum. You should consider submitting this as a custom thinnkscript project using the contact form at the bottom of the “About” page.