In Think Desktop, it is possible to set up an alert triggered by certain indicators. It is also possible to automatically send trade orders when your alert fires. Here’s a tutorial on how to do both!
First, the bad news: As of the current time, you can only create alerts and send trades from selected built-in Think or Swim indicators. If you want to take your complicated custom study and fire alerts from it, you’re out of luck at the moment. Hopefully this will come in future releases from ToS.
To start, go to the MarketWatch –> Alerts tab in Think Desktop. Enter your ticker symbol in the field at top left, and click the “Study Alert” button (all screenshots that follow are linked to a larger, clearer version if you click them):
The screen that comes up is your Study Alert editor:
You’ll see several fields and options. Here’s what they do:
Trigger Type: Either “Study Value”, which uses one built-in indicator output, or “Complex Formula”, where you can calculate combinations of the built-in indicators. We’ll start with “Study Value”.
Study: Pull down list of available studies you can use.
Plot: Which output of the study to use (if there are more than one, like in the MACD indicator, that has MACD, the histogram value and the signal line)
Trigger If: Four choices here. At or Above, At or Below, Above, or Below.
Threshhold: This is the value that you are checking if your study is At or Above, Below, or whatever you chose for “Trigger If”. If the padlock is open, it will freely float until you create the alert, and if you click it closed, the value stays frozen.
Aggregation: This is the timeframe of plot that your study will be calculated against.
Parameters: Here you can change the input values of your study to whatever you want them to be.
There is also a Condition Preview plot in a lower pane, so you can see what you are specifying.
Here’s an example: Say I want to create an alert that tells me if the value of the Hull Moving Average (20) on a 5 minute chart is above a certain market price. I would choose that study from the pulldown:
Then choose the 5min aggregation:
The “Threshhold” value is unlocked, so it’s choosing the current floating price of the ES futures. If that’s the level you want, you’re good. If not, change it to what you want to check against, and then click “Create Alert” in the bottom right corner. Your alert is created. Since the value of that Hull MA was above the ES price when I created the alert, my alert triggers immediately, and I see the pop-up and hear a sound:
In this example, the outcome of the study alert was compared to some constant value. This is great if you want to check if RSI(10) is above 80, for example, or if the market price reaches some level you have in mind. What if you want to check something more complex, like adding two indicators together, like $ADVN + $DECN? Then when you create your alert, you select “Complex Formula” from the “Trigger Type” dropdown:
You’ll notice the fields have changed. Now you have a Thinkscript code window instead of the study dropdown. Here you can write code, but you’re basically limited to a single “line” of Thinkscript. Imagine that your code window has an implicit “def studyalertvalue = “, and you are just adding the rest of the code. As before, there are only some of the studies available to you (same ones as there were for the “Study Value” option). You can see them in a dropdown if you check the “Show Tools Window” box. But the real shame is that once you set up your complex formula code, you can only compare the outcome to a constant value like before. So if you want to know something like if HullMovingAvg(5) is greater than HullMovingAvg(20), then you’re stuck. But before you jump off a bridge, know that all is not lost!! You can rewrite your equation algebraically to a form that will work.
In this example, we just go from:
If HullMovingAvg(5)>HullMovingAvg(20) then…
If HullMovingAvg(5)-HullMovingAvg(20)>0 then…
Those statements say exactly the same thing, mathematically. With the simple algebra, instead of comparing the two directly, we compare the difference to zero. Since zero is a constant, we can have both of our comparison variables be dynamically calculated and still work within the Think Desktop constraint. And you thought you would never use algebra after high school! 😉
So say we want to check for HMA(5) above HMA(20) on a 15 minute chart. Here’s what the example in this case would look like:
After you set that up, click “Create Alert” as before. Once your alert is set up, you’ll get notified when the conditions trigger. You can see your alert patiently waiting in the alerts window:
Note that each alert is a one-shot deal. Once it fires, you have to go set it up again if you want to be notified next time. Now you can stop there with alerts only, or move on to the auto-trading realm… If you dare!
***SPOOKY CATASTROPHIC LOSSES WARNING*** Before you let any computer take trades for you in a real money account, make SURE that you have tested it using a paper money account first, and that you understand what your alert code is doing!! Then read this warning again, and again.
To choose to send an order when your alert fires, you first have to create the study alert through the process above. After your alert is created, you go to the Trade tab. Then you need to create an order, but DO NOT submit it yet! Example: If I wanted my HMA study alert to send an order to go long ES, I go to the trade tab and click the ask price (step 1). A buy order is created (I could click the bid to create a sell order instead). The next step is to left-click on the “gear” icon in the order entry pane (step 2):
After you do that, you’ll see the “Order Rules” window. Here is where you can place conditions on when your order is sent. In the top frame, you can choose whether it’s a buy or sell, the quantity, and whether it is a day order or GTC. The lower frame is where we set up the study alert trade. There are options to put in a time to submit the order, a time to cancel it, and then the paydirt: “Submit at Specified Market Condition”:
First, click in the symbol column. The trade instrument is automatically added. Then you click in the method column, choose “Study”, and then choose the study alert you created previously (in our example it is the HMA option on top). After you choose the alert to use, then VERIFY that what you have told the computer to do is actually what you wanted the computer to do:
Then click “OK”. The order is still sitting there, waiting to be sent. Click “Confirm and Send”, and go through the steps to enter the trade as any normal trade. Once it’s accepted, it will show in your order book as a working order, with the status “WAIT COND”:
It will wait there until the order expires (if a day order for example), or until the alert fires. Once the alert fires, then the trade goes live and is executed according to the rules you set up. As before, once the alert trade fires, you must go set it all up again if you want to trade the next signal. The alert is held on the ToS servers, so you don’t even have to be logged in–it’s always working. However, be careful–these alerts I entered on ES actually fired in the after market and I was “filled”, so be aware of the time in force of your order or you could get filled outside of market hours, depending on what it is (options, stocks, futures, forex, etc). Make sure you test before doing anything live!
Congratulations! You are now auto-trading in Think or Swim! If this tutorial is useful to you, and you make some sweet moolah off of a trade, please consider throwing me a piece of the action:
Leave a comment if you have any questions, tips or observations!