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


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!

Tags: , , ,

25 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.

  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:


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


  6. Prospectus Says:


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


  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?


  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.

  16. stocksusagroup Says:

    How can I write one bar confirmation with conditional orders. I mean once the condition meet wait for 1 full candle to form and executes on next bar formation. Thanks

  17. Prospectus Says:

    You can check for your signal two bars ago. Right at the bar open you have one full bar behind you, and the signal bar one behind that.


  18. KJ Says:

    Great work. Is there no way to create a reoccurring alert that notifies you each time the condition is met? And what about setting an alert for multiple underlyings?

  19. Prospectus Says:

    No to both of those so far.


  20. Mark Says:

    Hi There! Options Trading only works well if you place Limit Orders. So lets say we wanted to automate trades to go off on your Hull Cross signals – but we did NOT want to place (horrid) Market Orders. Is there ANY way to populate the limit order limit value with a current value (say Bid, Ask, Mark+0.05… etc.) or in other words is there a way to have a Variable as the limit value that gets assigned the updated bid or ask or mark or mark+0.05, and have that populate into a Limit Oder when it gets placed? Could limit values be passed from excel back to TOS for example, or could this be done within TOS itself? Placing market orders on SPX Index options would be suicide.

  21. warrensgoff Says:

    Is there anyway to apply Study Alerts to multiple stocks or do I have to key each script in individually which is tedious.

  22. Sunil Says:

    Does TOS allow complete automated trading where there is no human interaction. Orders are opened and closed automatically based on predefined strategy.

  23. Prospectus Says:

    No, it doesn’t yet


  24. GreenTrader Says:

    Great information! Too bad ToS doesn’t offer automated trading yet. Thanks for the info I’ll have to practice it then i can close out positions when i’m not at the computer. Do you know any platforms that allow automated trading on Range(Renko) bars?

  25. Prospectus Says:

    Ninjatrader can


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

%d bloggers like this: