Thinkorswim Strategy Guide MTF 30

Multiple Time Frame Based Strategy of the MACD

Backtesting a Multiple Time Frame indicator using Thinkorswim Strategies. The MTF MACD has been revised to

Thinkorswim Strategy Guide MTF

Thinkorswim Strategy Guide MTF

make it suitable for backtesting. This video includes links to download the revised MTF MACD indicator as well as it’s Strategy counterpart. In this video you will learn two methods of multiple time frame analysis. You will understand why one method is nearly impossible to backtest, while the other method is perfectly suited for backtesting.

After a brief slide show explaining the differences, you will see how to use the MTF MACD Strategy to extract theoretical trades from Thinkorswim into a spreadsheet for analysis. Thinkorswim Strategy Guide MTF is a more advanced version of previous videos published on this topic. In order to get the most out of this video you are encouraged to also view the following videos in this series:

Thinkorswim Strategy Guide

The original Thinkorswim Strategy Guide goes into a bit more detail on how to work with strategies and extract data.

The other video to watch is Thinkorswim Strategy Analysis

The Thinkorswim Strategy Analysis video goes into great detail showing how to extract the trade data into Excel. Step by step instructions are shown for organizing the trade data into Excel, calculating the P/L and even displaying the results in a graph.

Link to strategy file: Strat_MTF_MACD_LE_v2STRATEGY.ts

For Advanced Users Only:

Take this knowledge to the next level and learn how to automate your trades on Thinkorswim

Thinkorswim AutoTrade Almost

Thinkorswim Automated Round-Trip Trades


*Thinkorswim is a chart analysis platform offered by TD

TD Ameritrade provides financial services including the trading of Stocks, Futures, Options and Forex.

Please be sure to share this page with your friends and colleagues. Leaving comments below is the best way to help make the content of this site even better.

Watch the video, Thinkorswim Strategy Guide MTF below:

About Pete Hahn

For those trying to contact me about our professional services you will find all those details here: Any questions not related to our professional services or premium indicators should be directed to the comment section of the applicable video or you may post a question in our Q&A Forum:

Questions? Comments? Post a review?

30 thoughts on “Thinkorswim Strategy Guide MTF

  • Scott D.

    I am having trouble finding the V2 indicator as a study. I have loaded the strategy, but am having trouble finding the v2 study.
    I did turn on floating P&L, however I missing the buy signals.

    • Pete Hahn Post author

      The portion of the code which controls whether the signals can repaint is found much further upstream than “diff > diff[1]”. If you want to see where that repainting issue is addressed, check out the lines of code which form the following variables:

      For to complex to describe here. But those lines of code hold the key to signals which repaint or do not repaint.

  • marlon

    i searched the website to see if the v1 strategy code exists so i can have the ability to compare the code between the two to understand better the repainting version versus the non repainting.

    looking at the code for v2 alone, i see you are comparing diff > diff[1] for the entry, which, since i’m pretty sure TOS is processing “diff” at the close of the most recent bar, makes sense that it DOES NOT repaint. what would be the comparison for the repainting version? diff[-1] > diff ?

      • marlon

        that is a rather vague and unhelpful answer. i am not a newbie to thinkscript and hope not to be treated as such. its a pretty simple question i think — just looking to confirm that my thinking is correct.

        please correct me if i’m wrong, but in comparing your v1 indicator vs v2 strategy, you are comparing the exact same things in both versions on all three timeframes, always [0] vs [1]. what would be the significant difference in the code for the v1 if it were a strategy which would be making it repaint? i can not catch the difference myself, but am very interested to know. thank you.

      • Pete Hahn Post author

        Sorry if you took offense. I provided the link to the code believing you wanted to check for yourself. That is what you requested. But I supposed I misunderstood.

        Your original thought of how this is handled was incorrect. Here is your answer:

        As you compare the original version to V2, you will find the your answer by comparing the code from lines 46 and 47 of the original version to lines 41 and 42 of V2. Similar differences will also bee seen by comparing lines 56 and 57 of the original to lines 51 and 52 of V2. That is the technical answer to your question.

        There is a possibility that line numbers may be off so I will also provide the variable names where this repainting issue is handled in V2:
        def midTermFastAvg
        def midTermSlowAvg
        def longTermFastAvg
        def longTermSlowAvg

      • marlon

        unless the difference is simply that you’re using open[-1] (open of next bar) as the entry price rather than a current bar entry?

      • marlon

        got it. i see the difference now. thank you!

        so does midtermfastavg[1] refer to the previous mid timeframe bar or to the previous bar on the primary timeframe which is shown on the chart?

      • Pete Hahn Post author

        I do not see any instances of “midTermFastAvg[1]” being used in either versions. So I take this to mean you are wondering what would happen if you did try to use that. So I will try to explain things in a bit more detail:
        “midTermFastAvg” already references the previous bar from the higher time frame because of the following section of code which is used to compute it’s values:
        “close(period = midTermPeriod)[1]”

        If you were to use “midTermFastAvg[1]” you would be referencing two bars back on the higher time frame. (The bar prior to the previous bar).

        If you are trying to learn how to do this for yourself, you can probably find a much simpler example to use.

        The following plot statement will plot the previous day’s close on an intraday chart:
        plot close(period = AggregationPeriod.DAY)[1];

        The previous day close is always a fixed point of reference. Which means any signals or values computed from it, would be stable, and not subject to repainting.

        Start with that, and build more complexity as your imagination dictates.

      • marlon

        i apologize, i did not write it correctly. i meant to write a shorthand version of this line of code:

        def midTermFastAvg = ExpAverage(close(period = middleAggregation)[1] , midTermFastLength);

        very confusing, totally my fault.

        i was referring to your use of the [1] there for the ExpAverage in the above line of code as it appears to be the primary difference between v1 and v2.

        my question is, does that [1] represent the “previous bar” on the current primary timeframe shown on the chart or does it reference the “previous bar” on the midterm timeframe?

        thx for your patience and help thus far!

      • Pete Hahn Post author

        Ah, ok. Got it. However you have blended elements from both versions there. Be careful you don’t mix those up. That same line of code in V2 is as follows:

        def midTermFastAvg = ExpAverage(close(period = midTermPeriod)[1] , midTermFastLength);

        You copied the equivalent line from the original version, which does not have the “[1]”.

        Having cleared that up….

        So the “[1]” ALONG WITH “(period = midTermPeriod)” are working together. The “[1]” is referencing the previous data point of “close” and the “(period = midTermPeriod)” is referencing whatever higher time frame has been selected for the input named “midTermPeriod”. The default value of that user input being “AggregationPeriod.WEEK”

        Ok, that’s about all the time I can afford to spend on this conversation. I need to keep the bills paid and must limit the amount of free advice I provide in the comments section of a video. But this has been an interesting conversation and I thank you for that.

      • marlon

        appreciate it Pete, as always. know that i’ve donated multiple times via your donation link on the sidebar of the website, because i’ve always found your resources here to be extremely helpful.

        i’ll post my last question in relation to this convo and if you ever have time, i’d love a reply:

        in general, if one were interested in using the mid and/or long term timeframe indicator values AT THE MOMENT each primary timeframe bar closes (regardless of how the mid or long term TF indicator values end up closing), for a strategy to determine entries, would they have to use v1 style with the repainting?

        or is there another way to code it to be able to check the mid and long term indicator values at the close of each primary TF bar and use those to determine entries/exits without repainting?

        thx again

      • Pete Hahn Post author

        I appreciate you support, thank you. The answer to your question is that it is not possible to back-test any strategy which attempts to reference current higher time frame data. Simple as that.

        Consider this to be an immutable law of trading. There is no way to work around this. In fact it may help you to accept this as an immutable law by considering that Thinkorswim is the only trading platform lacking safegaurds which prevent folks from build a strategy which breaks this immutable law. If you attempt to read current higher time frame data using TradeStation or NinjaTrader you will find it is completely impossible. Those platforms were designed to make sure its impossible.

        Why? Another way of thinking about this… The only way you can back-test a setup which references the current higher time frame data point is to build a time machine which allows you to travel into the future and know where those higher time frame candles are going to close, before they close.

        In back-testing terminology, this is referred to as a “future leak”. Look it up if you are curious to learn more.

        And once you understand this important concept you will be better prepared to avoid this mistake when building your own trading tools.

        And if I haven’t lost you yet I will add a bit more. The ONLY way to test the performance of a setup which reads current higher time frame data is by use of the Walk-Forward analysis. That’s another term you can lookup if your are interested. On Thinkorswim, there is no way to automate a Walk-Forward analysis. It must be completed manually, one bar and one trade at a time.

      • marlon

        thank you for the detailed reply, and it does make sense and it is the answer i expected.

        however, it does seem possible (likely not with TOS, but ninjatrader for sure) to fetch the indicator values for the mid and long term only once at the close of each primary bar. so for example, if using a 5 min primary chart timeframe, a 15 min mid, and 1 hour long, at the closing tick of each 5 min bar i could grab the indicator values for the 15 and the 1 hour, despite them not having closed yet, but rather PURPOSELY obtaining “snapshot” values to give an idea of their progress so far (understanding full well that they have NOT closed yet).

        once those mid and longterm “snapshot” values are grabbed, they could be compared with their own previous “snapshot” values at the close of the previous 5 min bar.

        am i totally incorrect in thinking that this scenario is possible?

      • Pete Hahn Post author

        totally impossible. Trust me on this. I have tried to break through that wall and they have covered every last detail. In fact NinjaTrader is even more strict than TradeStation in this regard. Besides all of this, it is breaking an immutable law of trading. You can trade such a setup in live markets. But it’s impossible to back-test them, without breaking the physical laws of the universe. Please make sure you get that part. We are not talking about manipulating data with code. We are talking about breaking the laws of physics. And at this point in time, no one has come forward and proved they can travel into the future and use data that was collected in a process that is operating in the present.

      • Pete Hahn Post author

        And I have one last concept to demonstrate the problem. The fact that Thinkorswim allows me to create the original version of the MTF MACD is an indication that Thinkorswim is BROKEN. No other trading platform allows this. In Thinkorswim, I can create a variable, and on the very next line I can write a statement which plots the value of that variable from the last bar of the chart, even if the code is reading from the very first bar of the chart. No other trading platform allows this. It is against the “law”.

  • Gabriel

    Hey Pete, awesome tutorials, thanks so so much for sharing. I’m wondering, is it possible to add sell signals for possible trades on the sell side?

    • Pete Hahn Post author

      Sure it’s possible. Far too complicated to address in the comments section of a video. I suggest you check the Q&A Forum because I am pretty sure someone has already posted a request for that in the forum.

    • Pete Hahn Post author

      Sorry but I do not. TradeStation has a very inflexible solution for MTF studies. Possible, but far less user friendly then Thinkorswim.

  • Charles

    Hi Pete,

    I hope you don’t mind I made some change your MTF MACD, I increase from three MTF to four MTF I mainly trade on the 4Hrs therefore the MTF I look for are (Daily, Two_Days, Four_Days). Just in case anyone here are interested here are Pete update script. Thank You

    The code has been removed. I do not have time to evaluate the code and ensure it works as the original.

  • Walker


    I am not getting the annotation on the chart that shows an entry or exit, which means I am unable to download the trade summary.

    Thanks for any help.


    • Pete Hahn Post author

      Without seeing your chart and the settings used it is impossible to assist you. If you are still having this issue I suggest you post a request in our Q&A forum so you can provide a screenshot of your entire chart. Thanks!

  • TJ

    I do not see the link to download the TOS code for this MTF strategy. Is it located somewhere else on the web page.
    Thanks, JK

    • Pete Hahn Post author

      Just as most of our other videos, the link is presented within the video. It is presented after the instructional portion of video, inside a white rectangle. Just click on it when it appears.

      • Donovan

        Hi Pete, I am able to get Chart_MTF_MACD_v2 in my chart. But the Strat_MTF_MACD_LE_v2 though located in my folder and downloads the Think or Swim is not locating it to do the import. It there anyway you can assist me with this? I enjoy watching your videos and learned a lot. and been sharing it Thank you!

      • Pete Hahn Post author

        Seems this question is related to an entirely different video then they one you posted this comment too. The chart strategies are listed under a different tab. The import process has to be completed from the tab in which the chart strategies are listed.