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.

DISCLAIMER: I AM NOT A CERTIFIED FINANCIAL ADVISOR AND NOTHING IN THIS VIDEO OR TEXT IS AN ADVERTISEMENT OR RECOMMENDATION TO BUY OR SELL ANY FINANCIAL INSTRUMENT. NOR IS THIS VIDEO OR TEXT INTENDED TO INSTRUCT YOU ON HOW TO MAKE BUY OR SELL DECISIONS USING ANY OF THESE INDICATORS.

*Thinkorswim is a chart analysis platform offered by TD Ameritradewww.tdameritrade.com

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;
Buy_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy_signal.setdefaultColor(color.dark_GREEN);
Buy_signal.hidetitle();
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;
Sell_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
sell_signal.setDefaultColor(color.red);
Sell_signal.hidetitle();

About Pete Hahn

For those trying to contact me about our professional services you will find all those details here: https://www.hahn-tech.com/about/ 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: https://www.hahn-tech.com/thinkorswim-forum-topics/

Questions? Comments? Post a review?

204 thoughts on “Thinkorswim AutoTrade Almost

  • Khoa

    Pete, appreciate sharing the knowledge. I was looking for “wait until”, “wait for” condition in thinkscript and came across your video. For ex, if RSI crosses below oversold, wait for/until StochasticFast converges (K over D) for at least 2 green candles. I think in the video you use “within X candles” as the time period. What if that X isn’t long enough? We just have to specify X a big number? Is that the only way (i.e. no true wait until condition in thinkscript)?

    • Pete Hahn Post author

      1. Fully automated trading is not supported
      2. We cannot create a Conditional Order that uses Heiken-Ashi candles because those required the use of recursive variables. Which are not supported in Conditional Orders.

      • raviraj hiremath

        Ty. if we give you the requirements would be able to write the code on HA reversals. and how much would you charge?

      • Pete Hahn Post author

        Yes, there are many available platforms that support fully automated trading systems. Some of them are: TradeStation, Sierra Chart, Interactive Brokers, NinjaTrader and Esignal.

      • allen

        Hello Pete, Love the site and the videos!!! Do you know if it’s possible to create TOS Strategy using the conditional wizard? Every time I create a condition with the Condition Wizard, then I add ‘addOrder(OrderType.BUY_AUTO, no);’ the code turns red and it tells me the ‘Condition Wizard doesn’t recognize “addOrder”

        Thanks again for all you do

      • Pete Hahn Post author

        It is very odd that you are asking this question in the comments section of the very video that I would refer to in order to answer your question. I suggest you go back and view the video again and take your time to learn and practice using each of the examples I provided.

  • jerryravi1

    Thank you for the detailed explanation. I am looking for alerts when the price crosses over the lower Bollinger band and RSI crossing 25 and alerts on reversal at the higher BB. How can I do that?

    • Pete Hahn Post author

      Depends on the type of alert you are seeking. Thinkorswim has several: https://www.hahn-tech.com/ans/generate-alerts-from-macdstrat-chart-strategy/
      Aside from the chart study based alerts, most can be created very simply by using the Condition Wizard: https://www.hahn-tech.com/thinkorswim-condition-wizard/
      If you are seeking a chart study base alerts, then check the “Chart Studies” topic of our Q&A Forum for existing solutions: https://www.hahn-tech.com/ans/cat/studies/

      • Larry

        I really enjoyed watching your video on autotrade. I like autotrading. Please there is one thing I am still not clear with. At first you created the strategy for both entry and closing into one template but you sent the entry separate and the closing too separate. Is it not possible for both the entry and closing trades to be created one strategy name, such that when the conditions for placing the order are satisfied, the system will execute it and also close trade when conditions too are satisfied? Will be grateful for your response. Kind regards.

      • Pete Hahn Post author

        It is not possible to place both entry order and the exit order at the same time. This is the very reason the word “Almost” is included in the title of this video. Pretty sure I explained that in the video. I suggest you review the video again to make sure you didn’t miss any other important details.

  • Brett Lehmberg

    I used the method you showed in creating a conditional order and it produced “RSILaguerre().”RSI” crosses above 0.2″. In the conditional order screen in the bottom window it showed that it was functioning. When I paste the same code in the strategy creation screen it turns red and says “No such function: RSILaguerre”. Am I missing something?
    def signal = RSILaguerre().”RSI” crosses above 0.2 and RSILaguerre().”gamma” is less than 0.4;
    Thank you for your help!

    • Pete Hahn Post author

      Not much I can do from the comments section of the video. Did you include the template provided and make the changes demonstrated in the video to convert the code generated by the conditional order into code that runs as a chart strategy?

      • Brett Lehmberg

        Thank you for your response. Yes, I copied the line from the conditional order and placed it into the chart strategy just as you showed. In the chart strategy though, it is not recognizing RSILaguerre. I noticed that while in the chart strategy creation screen that the RSI Laguerre study is not in the drop down list on the right where I find all of the other studies. Could that be the problem?

      • Pete Hahn Post author

        The most likely reason for this is that there no such study that is included with Thinkorswim. You must have added this as a custom chart study. In most cases it is not advisable to reference custom study names because it often leads to unexpected results or entirely fails to work. So for custom chart studies it’s best to use the entire code instead of just a reference to it. But that is beyond the technical abilities of the average user.

      • Mario

        There is a way to make an entry and exit with TOS with one order. For example if you wanted to buy when the 9 SMA crosses over the 15 SMA and sell when the 9 SMA crosses under the 15 SMA. This can be made with one order and not creating two seperate orders.

      • Pete Hahn Post author

        Thinkorswim developers have intentionally disabled any known methods for achieving this. If you have a way to work around this issue I suggest you post the solution in the Q&A Forum so the rest of our viewers can evaluate your method and validate it for efficacy.

  • foda

    Pete, You are very talented and gracious in sharing your knowledge with us.

    I have had instances where I have had 4 conditions studies to a conditional order and they were 310 characters. When I saved the order and tried to use it again, TOS had truncated the condition to around 200 characters.

    Have you run into this issue and if so, how did you get around it?

    Keep up the excellent work.

    • Pete Hahn Post author

      This issue has already been posted in our Q&A Forum. Users of Thinkorswim have found that it is not possible to create a Conditional Order, save it as a template, and then use that saved order template to place an order for the same or another ticker symbol. This is an issue that should be submitted to TD Ameritrade support because there is no solution that can be implemented by the end user of the platform. (They have a bug in their platform and it needs to be fixed).

  • Bob

    Very nice presentation and well thought out. Thanks for doing this. But is there a way to save the order as a template so it will be valid for any stock? I’ve created the autotrade from your description and before hitting ‘Confirm and Send’, I saved a custom order template. But when I enter a different symbol and use the saved template (then click on the gear and change the symbol for the study), the order appears but will never execute. I’ve tried this with other studies as well. So my question is: Is there a way to save the order as a global template so all I have to do is select ‘Buy Custom’, select the custom order, select the gear icon, and change the symbol. I have a list of 50 stocks or so that I’d like to trigger if certain conditions are met, but it is way too time consuming to run through the process for each one. Another way to ask the question: Do I have to go through the entire process for each stock that I want to trade automatically?

    • Pete Hahn Post author

      This has already been discussed in the Q&A forum and unfortunately there does not seem to be a way to save a conditional order as a template and apply it to other ticker symbols. Perhaps this is something that should be submitted to TD Ameritrade as a feature request.

  • Richard S

    Hello Pete/ First off, thanks so much for all your generous contributions on this site. I’m trying to create a divergence code that simply compares highest high or lowest low to RSI and MACD histogram for a 20 day period. I was somewhat successful using the study alert in the marketwatch area, but after copying and pasting to the scan tab, it will not produce any results. Any thoughts on what I may be doing wrong?