Thinkscript Tip: Creating Alerts Using Thinkscript in Think or Swim

The newest Think or Swim release brings us the ability to create alerts from Thinkscript code! Here’s how to use them.

The syntax of the “alert” function is as below:

alert(condition, text, alert type, sound);

The required arguments are Condition and Text. The other two are optional, but have defaults if you don’t supply them:

alert type default value: Alert.ONCE
sound default value: Sound.NoSound

Condition is the logical value that will trigger the alert, and should be calculated to either 1 or 0 (true or false).
Text is the text string that will appear in the alert window when it is triggered.
Alert Type tells the alert how often it can trigger. The different ‘alert type’ parameters are:

Alert.ONCE – alert can be triggered only once after adding study
Alert.BAR – alert can be triggered only once per bar
Alert.TICK – alert can be triggered after each tick

Sound tells the alert what sound to play (if any). The different ‘sound’ parameters are:

Sound.Bell,
Sound.Chimes,
Sound.Ding,
Sound.NoSound,
Sound.Ring

Now some examples! This code will call an alert once on every single bar:

alert(1,”hello”,alert.BAR);

If you wanted an alert on RSI(2)>80 for example, you could use

def condition=if RSIWilder(2)>80 then 1 else 0;
alert(condition,”text”,alert.BAR);

If you had a plot of the NYSE TICK and wanted an alert every single time that a tick comes across as above 1000 or below -1000 (and didn’t value your sanity), you could use

alert(close>1000,”High TICK!”,alert.TICK,sound.DING);
alert(close<-1000,"Low TICK!",alert.TICK,sound.DING);

A slightly less ADD version would be to alert only once per bar, like so:

alert(close>1000,”High TICK!”,alert.BAR,sound.DING);
alert(close<-1000,"Low TICK!",alert.BAR,sound.DING);

And finally, if you only wanted the first +1000 tick of the day, you could use

alert(close>1000,”High TICK!”,alert.ONCE,sound.DING);

If you have any cool uses of Thinkscript alerts, feel free to share in the comments!

Tags: , ,

60 Responses to “Thinkscript Tip: Creating Alerts Using Thinkscript in Think or Swim”

  1. M B Says:

    Is there a way to set up alarm for PPS study?
    reference pps.”BuySignal” does not return anything…
    Thanks!

  2. Prospectus Says:

    I tried and I couldn’t access the signal for PPS either. They’ve got it locked up tight. Sorry!

  3. Dan Robbins Says:

    The revised PPS study seems to be using the 4sma (using H/L/C for price type) and the 7sma (close) (the original was 6 and 8).

    I’ve got code to paint arrows for the crossovers, but it paints every crossover, not just the first one in each direction. Prospectus – can you code it to only paint for the initial crossover?

  4. Prospectus Says:

    Dan, I sure can. Send me an email.

  5. Dan Robbins Says:

    Arrggg. I went to review my code and compare it against the revised PPS but it looks like they did some more tweaking to it, so my code isn’t replicating it as closely as they did before. They did mention a few weeks back that PPS would be an available option in the new Prodigio, so lets see how that rollout goes…

    I like the PPS on the hourly and 4 hour FX charts, and on the 1600tick ES charts. Oh, and heck, it’s pretty nice on the daily charts with pivots set to Opt Exp (instead of monthly). Have fun!

  6. Kirill Says:

    Instead of
    def condition=if RSIWilder(2)>80 then 1 else 0;
    alert(condition,”text”,alert.BAR);
    you can just use
    def condition = RSIWilder(2) > 80;
    alert(yes, “text”, alert.BAR);

  7. Kirill Says:

    Sorry, correct code is
    def condition = RSIWilder(2) > 80;
    alert(condition, “text”, alert.BAR);

  8. Prospectus Says:

    Thanks, that’s a cool shortcut! If you really wanted to compress it, you could even write it in one line: alert(RSIWilder(2) > 80, “text”, alert.BAR);

  9. Kirill Says:

    I just want to notice, that there is no sense to use “if” for “condition” def, because it only produces redundant calculations.
    And there is sense to define this variable if you want to reuse this def with other functions (to reduce number of calculations):
    def condition = RSIWilder(2) > 80;
    alert(condition, “text”, alert.BAR);
    assignBackgroundColor(if condition then Color.Red else Color.CURRENT);
    Otherwise, it’s better to use your version in the last comment

  10. Kirill Says:

    I wanted to notice in my last comment, that there is no sense to use “if” for “condition” def, because it only produces redundant calculations.

    Also there is a case, when it would be better not to compress it. It’s reusing this def with other functions (to reduce number of calculations):
    def condition = RSIWilder(2) > 80;
    alert(condition, “text”, alert.BAR);
    assignBackgroundColor(if condition then Color.Red else Color.CURRENT);

    BTW, thanks for your useful posts.

  11. Prospectus Says:

    Exactly! Thanks for the comments.

  12. KumoBob Says:

    declare lower;
    def condition = RSIWilder(2) > 80;
    alert(condition, “text”, alert.BAR);
    plot data = close;

    What am I doing wrong?

    I get this error
    Invalid statement: alert at 3:1

  13. Prospectus Says:

    The problem is the quotation marks on “text”. You need to delete them and actually retype them inside of your thinkscript editor.

    This happens when you copy and paste from some WordPress blogs. That open quote is not really a quotation mark. It’s some other ASCII character that is visually rendered as a double quote in thinkscript editor, but the compiler doesn’t recognize it. This is why I release all my indicators in plain text files instead of in a blog post.

  14. HR Says:

    Great expertise and thanks for sharing it.

  15. HR Says:

    I would appreciate any input on how to ADD different sounds to TOS that can then be accessed on the ALERTS page instead of the default set provided by TOS. _____

  16. HR Says:

    I figured out how to add alternate sounds for TOS Alerts that are accessed at the TOS Alerts page by pointing to other personal “.wav” files. No further response needed. Thanks.

  17. shaheen Says:

    does any one know how to create an alert for a list of symbols…
    i created a custom colums and i want to be alerted if the value of the colums reach the condition
    .. called td cs but they dont really know much ??

  18. Prospectus Says:

    I’ll make a tutorial for it

  19. TickRick Says:

    Hey how did you add custom sound for TOS alert.sound???

  20. J Swanson Says:

    I was wondering how custom sounds are put in, as well (if possible). Any ideas?

  21. max Says:

    Prospectus, is there a way to add “% change from the opening price” when having a stock watch list. They have some options like “%change from previous days close”. I really appreciate it. Just found your blog and you are doing a ton of great work here. thank you

  22. oz Says:

    Hello,

    I would like to write a code for when 2 moving averages crossing each other ( fast one and slow One) and want to add an alert to this.

    Great Job with all these posts. Any help much appreciated.

    Thank you,

  23. Eric Says:

    Thanks for the instructions! They work like a charm.
    Problem, though. Can alerts from a strategy appear on ToS blackberry/ipod apps?

    When I go to the marketwatch tab and manually create an alert, when it gets triggered – this appears on my ipod/blackberry

    But when I have a strategy running on my ToS workstation and an alert is triggered, it does not appear on my blackberry/ipod.

    Is there a way to change this so I can receive alerts on my ipod/blackberry? Secondly, is it possible to have alerts sms’ed to a cell phone?

  24. Prospectus Says:

    I’m working on this.

  25. Tom Says:

    I too am trying to get alerts triggered in my studies to generate an email. Is that possible? Thanks.

  26. Prospectus Says:

    I’ve been in contact with the TOS developers, and they know we want the email alert. It’s a matter of time now, as they are understaffed on thinkscript devs.

  27. Clint Says:

    I would also love to get an sms when an alert triggers!!!!!

  28. Popeious Says:

    I saw that some figured out how to reference the ‘custom’ sounds… it’d be great if that information was shared here..

  29. wonderberger Says:

    I would appreciate seeing a real example of how to use local “.wav” files.
    this works:
    alert(close>1000,”High TICK!”,alert.TICK,sound.DING);

    this does not:
    alert(close>1000,”High TICK!”,alert.TICK,c:/aasound/ringin.wav);

  30. jcardo Says:

    I have created this study, it plots and sounds buy and sell PPS signals.

    # pps buy signal
    plot ppsBuy = pps().buySignal;
    ppsBuy.SetPaintingStrategy(PaintingStrategy.arrow_up);
    ppsBuy.AssignValueColor(color.DARK_GREEN);
    alert(ppsBuy, “PPS Buy Signal”,alert.BAR, sound.Ring);

    # pps sell signal
    plot ppsSell = pps().sellSignal;
    ppsSell.SetPaintingStrategy(PaintingStrategy.arrow_down);
    ppsSell.AssignValueColor(color.LIGHT_ORANGE);
    alert(ppsSell, “PPS Sell Signal”,alert.BAR, sound.Ring);

  31. KumoBob Says:

    # PPS_R1V1
    # R1V0 2010.11.17:11:27 jcardo
    # Thinkscript Tip: Creating Alerts Using Thinkscript in Think or Swim
    # http://readtheprospectus.wordpress.com/2009/12/08/thinkscript-tip-creating-alerts-using-thinkscript-in-think-or-swim/
    # R1V1 2010.11.17:11:30 KumoBob
    # Nice jacardo!
    # Added a space between arrows and candle
    # Added option to plot only today
    # Added Option to turn alerts On/Off
    # * Note * I was not able to create an AssignPriceColor option.

    Input AlertsOn = yes;
    Input ShowTodayOnly = yes;

    Def Today = if !ShowTodayOnly then 1 else if getday() == getLastDay() then 1 else 0;
    def space = average(high-low)/3;

    # pps buy signal
    plot ppsBuy = If !Today then Double.NaN else pps().buySignal-space;
    ppsBuy.SetPaintingStrategy(PaintingStrategy.arrow_up);
    ppsBuy.AssignValueColor(color.WHITE);
    alert(AlertsOn && ppsBuy, “PPS Buy Signal”,alert.BAR, sound.Ring);

    # pps sell signal
    plot ppsSell = If !Today then Double.NaN else pps().sellSignal+space;
    ppsSell.SetPaintingStrategy(PaintingStrategy.arrow_down);
    ppsSell.AssignValueColor(color.WHITE);
    alert(AlertsOn && ppsSell, “PPS Sell Signal”,alert.BAR, sound.Ring);

  32. KumoBob Says:

    jcardo,

    PPS is not listed in the ThinkOrSwim Resource Center.

    How did you figure out the Parameter names?

  33. Dan Robbins Says:

    Also, this bit on scanning using PPS is at the thinkscript group at yahoo:

    http://finance.dir.groups.yahoo.com/group/TOS_thinkscript/message/4829?threaded=1&p=8

  34. jcardo Says:

    I got the idea from:

    http://finance.dir.groups.yahoo.com/group/TOS_thinkscript/message/4829?threaded=1&p=8

  35. Joe Says:

    Here’s a way to get TOS to send you a text message when an alert is triggered. Have them send an e-mail to your phone number! Check it:
    http://20somethingfinance.com/how-to-send-text-messages-sms-via-email-for-free/

  36. Prospectus Says:

    Yes, that works for alerts from the alert tab. But there’s still no way to do it from a thinkscript chart. Not yet, anyway. I’ve told the TOS devs that we want that.

  37. cybertrader Says:

    Hi Prospectus,

    How to apply the alert created by thinkscript to a watchlist and send out email in real time?

    Thanks.

  38. Paul Says:

    Re this: would the alert show up on the alerts tab on the web version? I would be satisfied with that.
    Then I could run the web version in the background at work, and get an alert there. I can’t run the desktop because we have a firewall, but this way I could still see the alert even though I’m not home on the desktop version.
    Ditto, by the way, for the cell phone app. That might actually be better.

  39. dhabud Says:

    Any updates on alert. Can some one tell me how to create conditions like pps in prodigio? So far I am using persons pivot sma of 5 days to create pps like signal. But like prospectus said pps is little be more tweaked.

    Any suggestions.

    Any update on getting email or web alert for pps.

    Regards
    Dhabud

  40. Prospectus Says:

    No updates on email alerts yet

  41. Eric Says:

    any way to add an alert with a sound wav. with a recording that will let you know when “the market is open in 2 minutes” or “London is closing in 2 minutes” or “inventory announcement in 2 minutes” or “the trading day is over turn the computer off” at 2:30 for example and is not tied to a study. Thanks Eric

  42. Brian Says:

    Does TOS allow the use of custom sounds via the “alert” function, or are we limited to just the 5 “Sound” constants? I know that you can do custom alert sounds through the “Alerts” tab of the “MarketWatch” tab, but those custom sounds aren’t valid parameters in the “alert” function. Thanks for your help, Brian

  43. keyword2 Says:

    keyword2…

    [...]Thinkscript Tip: Creating Alerts Using Thinkscript in Think or Swim « Read the Prospectus[...]…

  44. retrobeast Says:

    I have the same question Brian had.
    How can I create a custom alert for a custom study such as a MA crossover? I know you can set custom alerts under Market Watch but I do not think these work within a study added to a chart.
    I want more than Ding, Chime, Ring. I want to add the sound I want.
    Thanks
    p.s. please email if there is an answer
    sweatyburrito yahoo

  45. Jody Porter Says:

    Does anyone know how to write an alert for a new low?

  46. Prospectus Says:

    A new low in what context? New low for a bar, for the day, etc?

  47. فرفشة Says:

    it’s nice
    thank u

  48. roger456 Says:

    I’m using the Pro_MACDDivergencev3 indicator in TOS and would like to add a sound alert each time the arrow prints on my charts. Have tried to figure this out on my own but I need help. Thanks!

  49. Michael Says:

    I have a custom scan I run on TOS intraday, and I view the scan in TOS in realtime as a watchlist. However, I cannot figure out how to get an alert or sort when a stock on the list hits a new intraday high or intraday low. Theres about 30 stocks so its a pain to keep scrolling through throughout the day. Is there a way to do this via alerts?

  50. Alan Says:

    I have been trying to implement the syntax (alert.TICK) because I don’t want to set the alert again and again. Once I selected my studies under MarketWatch > Study Alert > Condition Wizard, I typed the words alert.Tick in the thinkScript Editior box but I always got an error. Could someone please show me the correct steps and what buttons / boxes to enter the syntax alert(condition, text, alert type, sound) ?

    I am currently trying the PaperMoney account (build 1824.13)

  51. Prospectus Says:

    What does the error say specifically?

  52. Alan Says:

    The error reads: “Invalid statement: .at 1:94″

    Is the built-in Alert under MarketWatch different from the Alert we are talking here? If it is, do I just copy and paste the syntax alert(condition, text, alert type, sound); at the end of my customs study to make the alert work? Thanks a lot!

  53. Prospectus Says:

    Email me your code so I can see what is on that line. Readtheprospectus at gmail.

    The other question, I don’t follow what you are asking. The alert functionality on the market watch tab is limited compared to that you can program in a Thinkscript chart.

  54. Alan Says:

    I finally figured it out: I put the syntax inside my custom studies instead of the MarketWatch Alert. It worked! Thanks prospectus for the help =)

  55. Stan Says:

    Is there a way to create an Alert just once and apply it to a watch list, rather than creating it over and over again for every single stock in the watch list? So each time I update my watch list, the alert will be automatically applied to the updated watch list.

  56. gsrogers1 Says:

    I second the question Stan asked, but looks like this forum is dead since no new posts since 10/19/12. Anyone out there?

  57. Prospectus Says:

    I’m here. I haven’t looked at alerts in a while. I need to go back and see if they’ve changed things to allow this.

    On Apr 4, 2013, at 11:27 AM, Read the Prospectus

  58. gsrogers1 Says:

    I want to set an alert in the implied volatility column I’ve put in the watch list. Seems like TOS would allow an alert that applies to every stock on the watch list without having to individually set each one. Thanks for looking into this.

  59. fpinero Says:

    Hello, running TOS in linux we have no sound when an order is filled. Does anyone know how can I use “alert” to play a sound when my order is filled?

    Thanks in advance.

  60. Mike Says:

    No but in return my question is why they cannot make custom sound choices available in the studies? All you get is ding, ring, beep, or bell. I want to add my own sound (in the study).

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 )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 77 other followers

%d bloggers like this: