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

  • Sasi

    Thank you very for the detailed video. This is just amazing. Loved it. I have issues around the order getting executed (I watched the video multiple times and may be blind sided on something).

    Here is my setup.
    1. I have a simple custom study that has two price points (lets say P1 and P2)
    2. I want to BUY if price is between P2 and P2 and Sell it when it goes above P2 or falls below P1
    3. I do have the Strategy and Conditions plot and they are working absolutely fine on the bars that I want the buy and sell order to happen.

    4. When I add that to the Order Conditions, somehow the order is sitting in WIAT COND state only.

    Here is me order condition (with offset set to 1 as well)

    BUY +1 /ESZ21:XCME MKT GTC WHEN /ESZ21:XCME STUDY ‘AA_Conditions_Plot().”buySignal” from 1 bars ago is true;3m’ IS TRUE [TO OPEN]

    Your input is absolutely appreciated.
    Thanks.

    • Pete Hahn Post author

      There is no way to determine the cause without examining the code you are using for the buy signal. (far too complex to address that in the comments section of a video). Please note the examples provided in this video used standard built-in chart studies. When I custom study is needed, you should be applying the entire code of the chart study to the Conditional Order. I notice you are referencing a custom chart study you named “AA_Conditions_Plot” rather than applying the entire code to the Conditional Order editor as we recommend in our Q&A Forum. I suggest you spend some time browsing solutions in the Strategy Guide topic of our Q&A Forum and see if there are any exist solutions that help you put the pieces together: https://www.hahn-tech.com/ans/cat/strategies/

  • Ravi Hi

    thanks for the strategy, how do we execute this strategy created.

    video is great butt doent mention how to use the auto trade strategy after bein created

    • Pete Hahn Post author

      This video shows ever step in the process and provides several examples and templates to help build your own custom signals. Since you are asking “how do we execute this strategy” I believe you have missed the most important parts of this video. HINT: This is the most advanced video available on this topic and most viewers find they need to watch it several times before they can apply the methods it demonstrates.

      • Ravi Hi

        Thanks Pete,

        I watched the video several times.

        you have created a strategy with buy and sell and never seen it the video where its executed.

        but you are using the condition wizard to buy and sell DVN,
        never really saw when the code but to open and exit strategy get executed from the strategy.

      • Pete Hahn Post author

        I don’t know what to tell you. You are asking a question that this entire video explains how to do, step-by-step, with several examples. If the video does not help you apply this knowledge than perhaps you are not able to understand my style of teaching, or perhaps you have an expectation that this should work in a way that the platform does not support. I suggest you move on to some other resources to achieve whatever goals you are trying to reach.

  • sam

    Hello Peter,
    I am new thought I know Thinkorswim but after learning beginner to advance on scan, and thinkorswim condition wizard opened my eyes that I have lot of home work to do. You are great teacher and exceptionally good and have thorough knowledge. I am so grateful to you. I am retired and spend time learning, was Aerospace and fiberoptic engineer. I am very much obliged .
    Thank you so much,
    Sam Sura

    • Pete Hahn Post author

      This video has nothing to do with custom scans so I am not sure why you posted this comment here. I suggest you spend some time viewing solutions in our Q&A Forum.

  • Jack

    Pete, as always, thank you in advance for all the information you provide. I’m looking at creating strategies for back testing and wondering if there is a way to enter a closing trade that either follows a trailing stop, ATR Stop or a physical stop “x” from the open?

    • Pete Hahn Post author

      There are several built-in chart strategies included with Thinkorswim that already provide similar functionality. Just add them to your chart, test them out and pick the one that works for your particular preferences.

  • David

    Great stuff, thank you!
    QUESTION:
    After setting up a buy order that triggers a sell order with the conditions in my strategy, is there any way to have ThinkOrSwim kick off another duplicate buy and triggered sell order if I saved the original buy and triggered sell order with the conditions as a template?

    Since my strategy kicks off multiple buy and sell combinations every day on a specific stock, I’d like for ThinkOrSwim to manage the day’s multiple buy and triggered sell orders instead of my babysitting all day for that stock.

    • Pete Hahn Post author

      Sorry but no. And that is the exact reason the word “Almost” is included in the title of the video. I did explain this in the video so be sure you watched the entire video before you start wondering about how you plan to apply this knowledge. Thinkorswim developers have purposefully made it impossible to create fully automated trading systems using the Conditional Order tool.

    • charleyc

      Hi David and Peter, I had the same question and I am trying a “1st Trgs Seq” order, under Advanced orders to set Triggered Condition orders. Peter has mentioned that conditions can not be automated but can it be triggered?
      I can’t find much on “1st Trgs Seq” in TOS education, I also have not found anything on Peter’s site. BTW, Peter thank you for your knowledge. I supported you with a donation.

      I first tested conditions, studies and strategies based on Peter’s video “Almost Auto” and exported to spread sheets and studied outcomes. Working nicely. I then wondered if I can use “1st Trgs Seq” under Advanced Orders to set triggered condition orders.

      I created the order (In Paper Money but have not executed in Real) by first setting a Buy condition order and under the Advanced Order tab, I set it as a “1st Trgs Seq” order. I then clicked on “Create an Opposite Order” by clicking on the dash icon to the right of the gear icon in the order entry line. It placed a Sell condition order to be triggered after the 1st order is filled. Confirm and edit your condition. I then clicked on “Create Duplicate Order” (right of gear icon) of the 1st Buy condition. It placed it as the third in the sequence. Lastly I duplicated the sell condition order as the fourth. So under Monitor it looks like this: 1st Buy condition (WAIT COND), 2nd Sell Condition (WAIT TRIG), 3rd Buy Condition (WAIT TRIG), 4th Sell Condition (WAIT TRIG).

      Unfortunately I can’t test condition orders in OnDemand or Paper Money (A BIG flaw in TOS – looking into Tradestation). I might try it in Real Money by buying one cheap stock in the condition and watch it.

      Thoughts?

      • Pete Hahn Post author

        Nope, sorry I have nothing to say here. Seems to me you are trying to find a way to remove the word “Almost” from the title of this video. Fully automated systems are not supported and Thinkorswim developers have intentionally made it impossible to create an automated system using this platform. It’s not an oversight or a accident. They intentionally removed any possibility of fully automating any trading system on Thinkorswim. You do not need to waste any more time trying to get that to work.

    • Mario

      So right click on TOS chart and go to buy custom and (with stop) will become an option.

      Click it and you will see buy and sell show.

      All they way to the right of the buy sell lines you will see the word (best) go one more box over and when you put your pointer in the box a gear will show for both buy and sell lines.

      Click the gear and put in your conditional order for both buy and sell.

      I have been using this with moving average crossovers and it triggers and triggered both buy and sell with one order on symbol SPXL (not stock advice).

      This is new information for me so I can’t give to much data but once the orders have triggered you will have to set it again.

      You can save the order so you can click buy custom and click your saved order. Pete tells you how to save your order in his video.

      This only works during regular market hours and not pre and post market. It has worked for me with the 9 and 15 SMA crossover buy and 9 and 15 cross under sell with real money but only one share for testing. I am also trying it with the Awesome Oscillator crossing the zero line and past value 1.0 and crossing under the zero line to sell. I will be working on/testing it with and OCO Bracket Order so you can have a conditional order stop and maybe a trailing stop as well for example. I hope this is explained well enough to help some people.
      Like Pete stated there is always risk involved so do this at your discretion.

      • Pete Hahn Post author

        Thanks for providing those details. I’m very interested to try this during live markets. I just tried it out during extended hours to see if Thinkorswim would except the order. I really did not believe it would. But it did. And I changed the Stop order to a Market order before hitting send. That would be the proper way to do this. Market orders for both buy and sell. If I can get this to work on my end I will be publishing an updated video on this topic for certain. At the very least I will post my results here in the comments section.

      • Mario

        Thank you for such fast replies and my answer! Can’t wait for the video with your results!

      • Pete Hahn Post author

        Just a quick followup. I tested this out and it worked using the PaperMoney side of Thinkorswim. I will schedule more testing and then begin formulating how to present this technique in a new video. Thanks for the heads up!

      • Mario

        I will be testing it out on a custom but simple script tomorrow to see if it works. I did use the Awesome Oscillator with it today and it worked. I have been using real money but only one share on most. But I did bump it up today to 100 shares on AAPL (not stock advice) and it worked nice on a 2 minute chart.

        Thanks for the update Pete!

      • evushka25

        Hello, Mario! You are doing EXACTLY what I’ve been trying to do for months now! But, my crossing lines were 9EMA over 20MA. I like yours more, just on a 5 min chart.
        I am running into a problem and can’t find the solution. I cannot find this part, “All they way to the right of the buy sell lines you will see the word (best) go one more box over and when you put your pointer in the box a gear will show for both buy and sell lines.” I see the lines, but not the word “best” or a box with a gear showing. What am I doing wrong?

      • evushka25

        Hello, again! No need to respond to my question! I found the answer to it. I had to reset my Thinkorswim to Default, it became a complicated maze and it was just too hard to find those order windows. Hard to explain, but I got it to work and looking forward to testing this out tomorrow during market hours! Thank you both, Pete and Mario!

      • Mario

        evushka25 sorry about the slow reply but I hope it works out for you! The EMA’s are just a starting point for me. I have a few custom scripts that are somewhat profitable but it seems TOS have most blocked saying they are to complicated with conditional orders or they just don’t trigger. Even after trying to simplify them none I want to use worked.

        If I want to create a new buy sell order I just right click on the chart and edit a order I have already made and just change the name and save it. TradeStation has complete auto trading but I just like TOS simplicity since I have had for a while. I hope to use Pete’s script above to learn how to write my own buy sell orders that are maybe a little more complex.

        The only problem I have ran into was I was using the 10 over 20 EMA buy sell and the down crossover took to long and was cutting my profits because of the low crossover. So I went to the smaller ones like 5&8 and 9&15 EMA’s. I might try a smaller EMA setup for my out. I will be trying the MACD sometime next week on the 5mn most likely. I will post what I come up with.

      • evushka25

        Hi Mario! Very happy to hear from you! I am curious how did your Awesome Oscilator trade go? I see that you traded that on auto with 100 share of AAPL. I never even heard about AO until I read your comment, so I looked it up and it seems that AO is better than MACD crossovers. What do you think? Though, can see how MACD cross overs would also work. I wish we can loop those trades to go again and again, but not so lucky… I tried TradeStation before. It was waaaaay too complicated for me. I took my money out of there and closed the account. I was also scared of their hidden fees… Also, our set up will work well on a swing strategy. If you look at AAPL or NIO, you will see on 4hr or Daily chart where MACD lines crossed below zero and often it’s when stock comes out of the oversold area on RSI. We can program it to buy then and then sell when MACD lines are crossing back (above zero? or just crossing).
        I want to encourage you to keep trying! This is truly something worth pursuing. I am all fired up and hopeful here.

      • Mario

        Thank you evushka25! Both AO trades went good but I had to catch Friday’s trade for a break even. Thursday on the over hand was nice. AAPL I had to buy at market open because it had already broke above value premarket (5mn) but I just put a sell on the break below zero line. The MACD is a scalper tool for me, sometimes you catch a run with it. When I use the AO I set it to break a certain value for example if it’s equal to or above 0.5 and buy on the next candle or sometimes the first candle. I still have my TradeStation but I use it for swings mostly (it’s under the PDT rule).

        AAPL on the 4hr for a swing you would have a better chance of catching it with a order the buys when your criteria is true rather than when it crosses a value or negative to positive. This is due to it possibly meeting your criteria premarket or postmarket (which these orders won’t fill). I haven’t seen anything that I can set to trade over and over other than some really technical orders. You still have to know direction for these to be profitable (at least for me so far).
        For the MACD crossover I set it for negative to positive is true to buy. I haven’t tried buy and sell on that yet (I will next week). MACD Histogram you can try up signal or down signal (haven’t tried it yet).

        I will definitely keep at it and hopefully help a few people on my way!

      • evushka25

        Hello, Mario!
        How is your progress?
        I automated 8 trades today: TSLA (green), AAPL (red), ALF (very very red), FULC (nice green), NAOV (red), NIO (barely green), PTIX, and VRPX (red). ALF was positive almost $400 at one point, but it closed very red…
        I noticed some very odd things that I wanted to share with you: When I looked at the trades when they opened and closed, there were two sets of stocks that opened and closed at EXACTLY the same time, to a second! TSLA opened as soon as market was opened, because that’s when the cross over happened, but the rest… Set of 2 and then a set of 3 stocks opened and closed at exactly the same time. Very odd and I am concerned. Some did not match the cross overs time at all.
        Overall I came out slightly green. My strategy was to BUY when 9EMA crossed over 20 EMA, and SELL when 9 EMA fell below 15 EMA – all on a 5 min chart.
        I wouldn’t call this a success. Tomorrow I am trying something different: I took 10 stocks from the Stock Movers list that had volume of 20 million and above for today and set this conditions in order:
        BUY when 9EMA crosses over 20 EMA and when price opens above VWAP.
        SELL with a trailing stop of 1%.
        Please, let me know how your progress is going! What new have you tried?

      • evushka25

        Hello, again! As soon as I sent you my comment I realized why the trades executed at the same time!!!
        So, to save time, before I sent the orders in – I saved them. I had two sets of orders – one for penny stocks of 1k shares and 1 for mid/large cap – 100 shares, (well, and the 3rd one – TSLA, 10 shares).
        Now, when I right click on the chart, I see those saved orders and I thought that just by clicking on it it will basically copy the conditions into this new trade on a different stock. But not so! It basically executes the orders on these new stocks when the original order executes!
        Gah! Am I so happy that I am doing this in a simulator??!! Live and learn!
        This means that I will have to run the same code again, the same strategy to see if will work. And that also means I have to go ahead and delete all my tomorrow’s orders and type them up individually.

      • Pete Hahn Post author

        Seems you have discovered something mentioned previously in the Q&A Forum. Which is that it’s not possible to save these conditional orders as a template and reuse them.

      • mario

        evushka25 Hello! So I have been using the 5 SMA crossing the 8 SMA which causes way more trades. But when the cross happens it can be at the top of the candle which will put you in at the top of the trade and unless it keeps moving it’s red. I used the 1mn on AAL TSLA and SPXL all green on the 1mn. Keep in mind you still have to note the overall direction of the symbol. I used the MACD histogram crossover neg to pos and the entries didn’t seem consistent to me. I caught most of the MACD trades and closed them green with the flatten button on the active trader. A few of the trades would have been red on a higher time frame because the candles are much bigger and put’s you in at the top, smaller time frame smaller candles but way more trades. The trades I closed myself would have been better with a trailing stop in addition as well as (I haven’t tried this yet). Again I have not seen anything I could set everyday on one symbol and it be profitable. I have also been using slower movers for example JBLU for testing as well. If it’s red it’s not by much but if it’s green it’s not by much either unless your using large share size. My average share size is around 500 for most trades, something like AAPL 200 or 300 and add if needed. Testing one share then I’ll add more if I like it. Also the AO did many break even trades or slightly red or green unless it triggered on a bull run. This can easily have a person over trading. I found myself in three trades at one time many times ( I have a four monitor setup though).

      • Pete Hahn Post author

        Not sure what “inbox a person” means. But I will delete that next comment where you posted your email address. Doing that on any website will ensure you are flooded with spam email and phishing attacks. They have bots that crawl every website looking for email addresses.

      • evushka25

        Pete,
        You can save orders and execute them on the same stock. Right before submitting the order, save it and next time you want that same order executed on that same stock, just follow what Mario said of right click on the chart, then click Custom Buy and you will see that saved order and just click on it. it will take 2 clicks to set that order up.
        What I thought this process would do is to make the same KIND of order on this new stock that I had a chart open on.
        I hope this helps!

      • Pete Hahn Post author

        If this is working now it’s because Thinkorswim developers fixed it. Up until a few months ago this did not work. The template did not retain the condition and worse yet, the saved templates were remembering the original ticker symbol instead of the ticker symbol to which the user applied the saved template order.

      • evushka25

        Mario, I posted my email address for you here, but looks like it wasn’t allowed. My name is Eve Loshinina, if you are on Facebook.

      • Pete Hahn Post author

        Comments with email addresses are held for moderation. You should never post your direct email address in any forum or comments section. They have bots that crawl these sites looking for emails to send spam and phishing attacks. I modified your comment to obfuscate your email address to avoid the bots from scraping it.

      • Mario

        Pete they didn’t fix it. I just click on one of my saved orders, edit it and save it as a new order. That’s all.

      • Pete Hahn Post author

        This did not work correctly just a couple months ago. If you can get it to work now, then yes, they did indeed fix this.

  • Khoa

    1. Is the purpose of studies and strategies just to see where those conditions shown up on the chart? We won’t know whether those strategies make profit or not unless we place the orders? That kind of defeat the purpose of verifying whether our strategy is good or not. It seems like I’m missing something obvious.
    2. When placing a sell order, how can we tell it to sell only if there are shares available? After I confirm a sell order, its status was “REJECTED. This stock can not be borrowed.” I assume this meant there are no available shares to sell.

    • Pete Hahn Post author

      1. Back testing is where you should have begun your learning. The following videos are prerequisites to this video:
      https://www.hahn-tech.com/thinkorswim-strategy-guide/
      https://www.hahn-tech.com/thinkorswim-strategy-analysis/
      But this was clearly explained in the video description.
      2. You are correct in that you must have an open position before you can create an order to close a position. It is impossible to enter the sell order before you have executed the buy order and hold those shares in your account. This is a fundamental and basic concept of trading.

      • Khoa

        It was a silly oversight. I turned off the study on the chart and didn’t remember until I watched your reference videos again!!! That was why the trade executions didn’t show up on the chart. I made a contribution. Your videos and explanation were great resources. Thanks again.