Tutorial: Creating Study Alerts and Auto-Trades in Think or Swim

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):

SA_1

The screen that comes up is your Study Alert editor:

SA_2

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:

SA_3

Then choose the 5min aggregation:

SA_4

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:

SA_5

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:

SA_6

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…

To:

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:

SA_7

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:

SA_8

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):

SA_9

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”:

SA_10

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:

SA_11

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”:

SA_12

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!

Tags: , , ,

15 Responses to “Tutorial: Creating Study Alerts and Auto-Trades in Think or Swim”

  1. ThinkScripter Says:

    Fantastic article Pro! Thanks from all of us TOS Heads for putting this together.
    -Eric

  2. jack Says:

    very nice, i like it . thanks

  3. Todd Says:

    You have some very nice stuff here man, and I like what you’re doing. Any chance that TOS will let you automate custom Indicators like the ones you’ve created?

  4. Prospectus Says:

    I think so. They are working on automation stuff, it’s just a matter if time. I would be surprised if we went another year without having it. Of course, you can automate in Ninja Trader now. That’s what I have mostly been working on in my development work (for others, not my own trading).

  5. Bill Says:

    Hi,

    What is the actual code that goes in the Complex Formula window? I can’t make it out.

    Thanks

  6. Prospectus Says:

    Bill,

    It’s “hullmovingavg(close,5,0)-hullmovingavg(close,20,0)”

    You should be able to click that screenshot and get a larger view of the text.

  7. trader Says:

    How can you make the alert trigger multiple times instead of just one time?

  8. Prospectus Says:

    You set it to alert.bar or alert.tick. Alert.once only triggers once. Alert.bar alerts once per bar if the condition is met. Alert.tick alerts every tick if the condition is true.

  9. trader Says:

    Can you do that with the default studies that are available without writing the thinkscript? I mean is it possible to create an alert from UI that is available on TOS that triggers multiple times. It is weird that I cannot even reset the alert to make it active when it is triggered once from the UI. Thanks.

  10. Prospectus Says:

    If you use their built-in alerts tab, I think it only fires once and then you have to reset manually. Kind of a pain.

  11. Bill Says:

    Great article…I’m relatively new to TOS…as I follow your screenshots under the automation portion, my “order conditions” do not look the same as yours…I have very few conditions to adjust…basically it’s just “cancel order at a specified moment/date”.

    How do I get “Submit at Specified Market Condition”??

    Thanks…

  12. http://tinyurl.com/yadk-8153939078 Says:

    “Tutorial: Creating Study Alerts and Auto-Trades in Think or Swim Read
    the Prospectus” was in fact truly engaging and insightful!
    Within todays society that’s very hard to do. With thanks, Edwardo

  13. marc gendron Says:

    Hi, I am Marc. Where can I find someone to help me or write a code for me in TOS?

    Thx,
    MG

  14. Brettcravaliat.Bravesites.com Says:

    I like the helpful information yoou prrovide iin your articles.
    I’ll bookmmark your weblog and chedck again here frequently.
    I’m quite certain I will learn a lot of new stuff right here!
    Besst of luck for tthe next!

  15. Prudence Says:

    Using the black background is irrational. Who reads books white on black? I have read this on Win 7, Win 8 and Safari and wasted a lot of time unnecessarily even though I use black on my TOS charts, because of TOS their limited choices, I prefer the softer colors offered on my Trade Station.

    I guess the Geeks, who are notoriously poor traders, like to operate in darken rooms and just don’t get the speculators analytical needs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 107 other followers

%d bloggers like this: