Automated Trading in Thinkorswim
Did you know that you can set up algorithmic trading in Thinkorswim? Yes, you can set up conditional orders in Thinkorswim that will fill automatically when certain pre-defined conditions are met. You can just enter your orders and let the code do all the work for you. You don't even need to be logged into the platform for it to work! It's perfect for traders who want to remove emotions from their strategies, or for traders who work full-time and can't trade during the day.
To demonstrate how it works, we will walk through a very simple example of buying a pullback when price retraces to a moving average, with a profit target and stop loss to manage the trade. Setting up this example will not require any coding whatsoever.
Before we get to the example, there are a couple of points to keep in mind. First, note that Thinkorswim does not support fully automated trading, so we have to make do with semi-automated conditional orders. Second, please test all conditional orders in the PaperMoney simulated trading environment before trading with your live account.
To set up conditional orders, first ensure that "auto send" is turned off. This will prevent the order from being submitted before you have a chance to set up the conditions properly.
Next, set up a long OCO bracket order. An OCO bracket means that once the initial entry order is filled, there will be two subsequent orders that will exit the trade - a profit target and a stop loss. If one of these orders is filled, the other one will automatically be cancelled.
Next, on the order entry window, click the settings gear icon on the far right side of the screen for the buy order. This will bring up the order rules window.
Once this window is open, change the price rules to Market. Alternatively, you could use a limit order that is linked to the bid, ask, mid, last, or mark.
Next, under the "Conditions" section, click in the empty space under "Symbol" (where it says "/ESM20" in this screenshot). This space will be empty until you click here. Then click "MARK", select "STUDY" and click "Edit..."
Next, using the Condition Wizard, you can edit the order conditions. There will already be a condition pre-populated. Click "Edit" on the right side to change the condition.
Since we want to buy when price pulls back to a moving average, the condition we're looking for is when the low price crosses below the SMA.
To set this up, click the drop down menu and select "Price". Then locate "low" in the list of prices.
Next, select "crosses below" in the middle column. In the right column, click the drop down menu to select a condition. Pick "Study" and then search for "SimpleMovingAvg" in the list of studies.
In the inputs section for the simple moving average, change the parameters of the SMA. In this case, we want to use a 200 day moving average, so we changed the length to 200.
After clicking save, this is what it should look like. Remember to use the correct time frame by clicking the dropdown menu at the top of this page. In this case, we want to use a daily chart, so we will leave it set to "D".
If you would rather use the thinkScript editor, you can copy and paste this code and bypass the previous steps that used the Condition Wizard.
low crosses below SimpleMovingAvg("length" = 200)."SMA"
That takes care of the entry order. For the exit orders, we will use simple limits and stops. These can be linked to the entry price so that they are offset by a certain amount or percent from the entry price. Remember to change the time-in-force to GTC for all three orders, so that you don't need to re-enter the order every day.
Since setting up this trade took a few minutes, you will probably want to save the order template to make it easier and quicker the next time you want to set up a similar trade. You can save the order template by clicking the icon to the left of the "Delete" button.
While this may seem like a long and time-consuming process, you will soon get the hang of the steps and be able to do them quickly. And saving the order template will cut out a lot of the set up time.
In this example, the profit target and stop loss orders are simple limit and stop orders. However, they can be set up as conditional orders too using the same method as with the original entry order. Also, the conditional order in this example was based on just one Thinkorswim study. But you can also set up conditional orders that are based on multiple studies, or even based on custom scripts.
If you want to set up conditional orders based on custom scripts, please keep in mind that not all custom scripts will work. The conditional order functionality is somewhat limited, so scripts must be relatively simple. Conditional orders will not work with a custom script if it is too complex.
Conditional order trading in Thinkorswim works great with swing trading and some types of intraday trading. For example, I use conditional orders for swing trading to buy automatically at pullbacks, and I also use automated trading for intraday strategies such as the London breakout, filling the gap, and extreme $TICK fades.
Creating custom scripts for semi-automated trading systems in Thinkorswim is my specialty. If you have an idea for a trading system in Thinkorswim and need help setting it up, please contact us to make a request.
If you set up conditional orders, please make sure your systems works the way you're expecting by testing it first in the PaperMoney simulated trading environment before trading it with your real account.