Thinkorswim AutoTrade Almost 204

As Close As We Can Get To Auto-Trading on Thinkorswim

In this video we show how to build your own code using a point and click condition wizard. The condition wizard

Thinkorswim AutoTrade Almost

Thinkorswim AutoTrade Almost

makes it very simple to build your own set of rules for trade execution. However you may not realize the code generated by the condition wizard can be very easily inserted into a template to form a Strategy and/or Custom Chart Study. We supply the templates, and show you how to put it all together. You will learn how to build your code using the condition wizard and you will learn how to convert that into a Strategy file. And Using tools we provided in previous videos you will then be able to analyze the performance of those Strategies.

We also show you how to use the condition wizard to generate orders that will execute in the same way as those theoretical orders generated by the custom Strategies.
AutoTrades are not fully supported on Thinkorswim as on other platforms. However if you learn how to connect the pieces you can place conditional orders that await the signal created by a set of defined rules. Once the conditions are satisfied, the order is released from hold and becomes a live order.


*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 AutoTrade Almost below:


This is the code for the Strategy Template:

input tradeSize = 100;
def signal = 0;
addOrder(OrderType.BUY_TO_OPEN, signal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
def exit = 0;
addOrder(OrderType.SELL_TO_CLOSE, exit, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);

This is the code for the Study Template:

declare lower;
plot signal = 0;
plot exit = 0;

This is the code for the revised SLM Ribbons study:

input price = close;
input superfast_length = 8;
input fast_length = 13;
input slow_length = 21;
input displace = 0;
def mov_avg8 = ExpAverage(price[-displace], superfast_length);
def mov_avg13 = ExpAverage(price[-displace], fast_length);
def mov_avg21 = ExpAverage(price[-displace], slow_length);
#moving averages
Plot Superfast = mov_avg8;
plot Fast = mov_avg13;
plot Slow = mov_avg21;
def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;
def stopbuy = mov_avg8 <= mov_avg13;
def buynow = !buy[1] and buy;
plot Buy_Signal = buynow and !stopBuy;
def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;
def stopsell = mov_avg8 >= mov_avg13;
def sellnow = !sell[1] and sell;
Plot Sell_Signal = sellNow and !stopSell;

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?

204 thoughts on “Thinkorswim AutoTrade Almost


    Im assuming that script dosent really work for futures you entered value of 25 well isnt the value going to be different for futures

    • Pete Hahn Post author

      My apologies but I published this video almost 7 years ago and I do not recall “entering a value of 25”. Please provide the exact time stamp in the video in which you saw this and I will attempt to answer your question.

  • Mel

    Pete thank you for all the tutorials you provide. I just finished the “almost” video and was struck by the coding required. I saw the study code for SLM and not the strategy for SLM. I don’t know if I just missed it or if it hasn’t been posted yet. Please advise.

    • Pete Hahn Post author

      After reviewing the video to refresh my memory I see that I showed a chart strategy for the SLM Ribbon on my chart but only the chart study has been provided.

      1. The chart study needs to be added as a new custom chart study.
      2. Then you can reference it in the Conditional Order tool as demonstrated in the video.
      3. In order to build a chart strategy from that custom chart study you can use the techniques described earlier in the video, in which I show how to use the strategy templates to convert your conditional order statements into a chart strategy.
      So yes, everything is provided, but it takes a while to learn how to put all these pieces together.

    • Pete Hahn Post author

      Nothing has changed since this video was first published. The instructions provided in the link you included are the same as what I demonstrate in this video. However if you read through the earlier comments on this page you will find one of our users discovered a way to place a round-trip conditional order. I have plans to publish an updated video to show how that looks on the platform. But the “Almost” clause is still very much in place. Which mean we cannot perform fully automated trading natively in Thinkorswim.

  • T

    Hello Pete. Thanks so much for posting all of your tutorials, very helpful! Question: How do you get your orders to continue in wait condition after they have been fired/executed? For example, once my buy order is executed/filled it disappears (same with sell order). How do I get the orders to continue to stay in wait condition mode so that when the buy order condition is met again, the order will be filled and same for sell order.

    One other note — Someone will want to wait to make sure the buy order is filed first if they are intending a long side sequence. If the sell order is filled first, the sequence would be inversed to a short order sequence. Does that make sense and I stated that clearly?

    Thanks in advance!

    • Pete Hahn Post author

      The short answer is simple. You don’t. That’s exactly why the word “Almost” is included in the title of this video. Pretty sure I explained this in the video too. And that should answer part two of your question as well. It’s largely a manual process. We have very limited automation features in Thinkorswim.

      • T

        Thanks for your fast response Pete!! I apologize, I knew you said it was almost but I guess I missed the part where the orders would not persist. I did think it was very cleaver to embed code into the orders to make them a little “smarter”. Question — Have you considered or looked into using the TDAmeritrade developer’s APIs to have the orders continue to be placed? I was directed to the by TDAmeritrade and am beginning to study it but not sure if it will handle the part that is missing for automation. I see that some folks out there are selling automated products for ThinkorSwim, so I am hopeful. Again, thank you for all your hard work and sharing all of your knowledge. I would not have made the progress I have made without you and your work!

      • Pete Hahn Post author

        The very best answer I have for this question. Why go through the trouble of modifying a Corvette to plow your fields when you can simply use a tractor? In this analogy, Thinkorswim is the Corvette. If you want a fully automated trading system the answer is very simple. Move to a trading platform that supports this functionality right out of the box. The list of such trading platforms is very broad.

      • T

        Thanks Pete! I have always liked ThinkorSwim, but I understand what you are saying. Are there any ones you would recommend? Again, thanks so much!!

      • Pete Hahn Post author

        I have created fully automated trading systems in Sierra Chart and TradeStation. I believe that TradeStation provides a more flexible and robust trading platform than Sierra Chart.

  • Tim

    Hi Pete. Just watched this last night…very informative. Thank you for sharing. Is there a way to change the time interval and aggregation period in the chart that is displayed in the condition wizard? I would like to see it at the 5 minute level, not the day level and have not been able to figure out how to change it in the condition wizard. Thanks in advance.