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: alerts, Thinkscript, thinkscript_tip
December 8, 2009 at 2:12 pm
Is there a way to set up alarm for PPS study?
reference pps.”BuySignal” does not return anything…
Thanks!
December 8, 2009 at 3:07 pm
I tried and I couldn’t access the signal for PPS either. They’ve got it locked up tight. Sorry!
December 8, 2009 at 9:34 pm
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?
December 8, 2009 at 9:46 pm
Dan, I sure can. Send me an email.
December 8, 2009 at 10:21 pm
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!
December 10, 2009 at 7:28 am
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);
December 10, 2009 at 7:29 am
Sorry, correct code is
def condition = RSIWilder(2) > 80;
alert(condition, “text”, alert.BAR);
December 10, 2009 at 8:02 am
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);
December 10, 2009 at 11:48 am
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
December 10, 2009 at 3:13 pm
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.
December 10, 2009 at 3:16 pm
Exactly! Thanks for the comments.
December 15, 2009 at 8:25 pm
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
December 15, 2009 at 9:06 pm
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.
March 7, 2010 at 2:47 am
Great expertise and thanks for sharing it.
April 8, 2010 at 11:09 am
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. _____
April 10, 2010 at 5:38 am
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.
May 19, 2010 at 12:56 am
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 ??
May 19, 2010 at 6:23 am
I’ll make a tutorial for it
June 22, 2010 at 8:12 pm
Hey how did you add custom sound for TOS alert.sound???
July 6, 2010 at 12:54 pm
I was wondering how custom sounds are put in, as well (if possible). Any ideas?
July 7, 2010 at 12:49 pm
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
July 27, 2010 at 7:35 pm
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,
August 8, 2010 at 11:57 pm
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?
August 9, 2010 at 8:30 am
I’m working on this.
September 27, 2010 at 9:56 pm
I too am trying to get alerts triggered in my studies to generate an email. Is that possible? Thanks.
September 27, 2010 at 11:51 pm
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.
October 13, 2010 at 10:15 pm
I would also love to get an sms when an alert triggers!!!!!
October 14, 2010 at 6:18 am
I saw that some figured out how to reference the ‘custom’ sounds… it’d be great if that information was shared here..
October 19, 2010 at 4:19 pm
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);
November 17, 2010 at 11:27 am
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);
November 17, 2010 at 2:39 pm
# PPS_R1V1
# R1V0 2010.11.17:11:27 jcardo
# Thinkscript Tip: Creating Alerts Using Thinkscript in Think or Swim
# https://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);
November 17, 2010 at 4:27 pm
jcardo,
PPS is not listed in the ThinkOrSwim Resource Center.
How did you figure out the Parameter names?
November 17, 2010 at 7:02 pm
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
November 17, 2010 at 8:56 pm
I got the idea from:
http://finance.dir.groups.yahoo.com/group/TOS_thinkscript/message/4829?threaded=1&p=8
November 18, 2010 at 2:20 pm
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/
November 18, 2010 at 2:22 pm
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.
December 8, 2010 at 8:44 pm
Hi Prospectus,
How to apply the alert created by thinkscript to a watchlist and send out email in real time?
Thanks.
January 16, 2011 at 3:37 pm
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.
March 28, 2011 at 8:19 pm
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
March 28, 2011 at 8:53 pm
No updates on email alerts yet
August 22, 2011 at 7:20 pm
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
August 29, 2011 at 6:42 pm
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
November 25, 2011 at 6:21 pm
keyword2…
[…]Thinkscript Tip: Creating Alerts Using Thinkscript in Think or Swim « Read the Prospectus[…]…
January 5, 2012 at 4:36 pm
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
April 2, 2012 at 7:28 am
Does anyone know how to write an alert for a new low?
April 3, 2012 at 10:44 pm
A new low in what context? New low for a bar, for the day, etc?
April 6, 2012 at 10:38 pm
it’s nice
thank u
April 9, 2012 at 10:26 am
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!
April 22, 2012 at 2:54 pm
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?
September 13, 2012 at 9:42 am
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)
September 13, 2012 at 9:47 am
What does the error say specifically?
September 13, 2012 at 10:03 am
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!
September 13, 2012 at 10:06 am
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.
September 14, 2012 at 4:16 am
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 =)
October 19, 2012 at 4:58 am
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.
April 4, 2013 at 11:27 am
I second the question Stan asked, but looks like this forum is dead since no new posts since 10/19/12. Anyone out there?
April 4, 2013 at 12:02 pm
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
April 4, 2013 at 1:05 pm
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.
April 16, 2013 at 4:08 pm
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.
April 16, 2013 at 7:14 pm
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).
September 25, 2013 at 3:18 pm
Steps for generating Custom Audio Alerts, Text Messages, etc. (Mac users) from Alerts triggered in TOS.
1. Create/Paste custom code with embedded Alert function that are conditional to your custom function.
2. Activate TOS Email notifications via Email.
3. Go to your Mail App settings on your Mac.
4. Generate new Rule to run an “AppleScript” when you recieve an email from TOS alerts (alerts@thinkorswim.com)
5. Select customized AppleScript to generate text message, activate select Song from your iTunes Library, activate Siri and make her tell you that an Alert has been triggered within TOS, etc. If your creating custom thinkscript criteria for generating alerts, then you should be able to handle AppleScript. It’s beyond easy with the syntax reading like a letter to your Grandmother than a comptuer programming language.
6. Share your success stories.
March 23, 2014 at 1:26 am
hellooo just wanted ask …
how to set up alert whenever arrow indicator shows up ???????
March 23, 2014 at 1:27 am
hellooo just wanted ask …
how to set up alert whenever arrow indicator shows up ?????
August 14, 2015 at 3:50 pm
Any email alert support yet?
November 16, 2015 at 10:17 pm
Hello group,
Wondering if someone can help with this; I Need code to perform the TOS Push notification that is sent to TOS Mobile phone app, through the ThinkorSwim System. So I can place the script in my scan have that push notification as the signal sent to my phone. This notification has the push sigh logo, sound and it vibrates. It’s the same one sent when you create an alert through the Market Watch tab in thinkorswim; desktop
I would just copy it but I can’t find the script on the system
I’m willing to donate, If anyone can complete a working Script for this signal
I’m at (the1stoven@yahoo.com)
Thanks,
Cee
January 26, 2016 at 8:45 am
Hi thinkscripters! Maybe you can help me with this… I have some experience creating my own studies and strategies in TOS. I try to add an alert to my new strategy but i figure that it only reproduces the sound the first time… There ir a way that the sound plays each time?
Alert(diff crosses BELOW 0 AND DIFF2<0, ”Long!”, Alert.tick, Sound.Ring);
February 18, 2016 at 11:18 am
Does anyone know how to set an alert to Ehlers simple decycler?
I was looking to be alerted once the high is 6 pips or closer to the upperband and the opposite, 6 pips from the lower band.
February 18, 2016 at 12:21 pm
You could use the “referencen” keyword to get the Ehlers decycler high and low and then set your alert up from there. See here: http://tlc.thinkorswim.com/center/charting/thinkscript/reference/Reserved-Words/reference.html
August 5, 2016 at 7:40 am
Can custom alert code be saved somewhere in TOS? I have a few different alerts but the window that pops up when you select Study for an alert only gives me 6 choices for custom alerts. I have a Word file where I copy and paste the alert code from then into the alert code window and go from there. Works but can be cumbersome. Would rather save the alert code as a file in TOS.
August 5, 2016 at 8:39 am
I haven’t seen anywhere to do that unfortunately.
>
August 12, 2016 at 12:54 pm
does anyone know to write code for allowing me to:
Condition 1. paint chart bar GREEN if macd(12,26,9) is >=50 AND Slow Stochastics (14,3) %D is >=50 AND RSI(7) is >= 50
Condition 2.. paint chart bar RED if MACD (12,26,9) is <=50 AND Slow Stochastics (14,3) % D is <= 50 and RSI(7) is <=50
Condition 3, paint chart bar black if none of the conditions 1 and 2 apply
August 12, 2016 at 12:58 pm
correction: for condition 1…..paint chart bar GREEN if macd(12,26,9) fast line crosses above slow line
correction for condition 2: paint chart bar RED if macd(12,26,9) fast line crosses below slow line
August 16, 2016 at 9:48 pm
I have quite a few scans i use on TOS platform. I save the scans and load them as watchlists on TOS platform or on my iPhone App to view dynamic results. What i am looking for is get these dynamic results emailed or text to my phone, since i m not in front of my computer all the time or not constantly checking my phone. So essentially if the scan is running in the background and if a ticker meets the scan criteria and pops up as a result, i need a text or email message to alert me instantly.
Is this possible ?
October 25, 2016 at 8:23 pm
I have a few auto scans like Vish, and I looking for a way to accumulate the symbols in watchlists.
How insert a Symbol (using thinkscript) to an existing watchlist in TOS.
I guess if the symbols can be accumulated in respective watchlist, I should be able to review them on the phone when I login to the TOS app.
December 15, 2016 at 8:43 pm
Hi, I have the same request Brian and retrobeast has:
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.
I have already uploaded 6 custom sounds to TOS, Which I could use for Alerts in MarketWatch. So how do I reference those sounds in my study code. Meaning instead of DING what should I put in this line
Alert(pLow, “Stock Low Alert”, Alert.BAR, Sound.DING);
Thanks
August 28, 2017 at 11:24 am
Really cool feature, Thanks for explaining it!
Since in the example you posted,
alert(1,”hello”,alert.BAR);
an alert is generated everytime a new bar paints, I would think that in the following example:
alert(1,”hello”,alert.TICK);
an alert would be generated every time a bar updated, so I would expect multiple alerts per bar, if the price moves several times per bar.
But that’s not what I’m seeing. The two examples (alert.BAR, and alert.TICK) return exactly the same result: An alert is generated only when a new bar appears, and only once per bar (exactly when the clock advances to the next minute).
Is my expectation of the TICK option behavior incorrect?
Thank you in advance!
August 28, 2017 at 12:22 pm
That’s not what I would expect. Are you running one chart with both alert styles? I can see that the alert.bar might silence all other alerts for that bar. Try taking that out and just use alert.tick and see what happens.
>
August 28, 2017 at 4:13 pm
I was running one chart with one alert style, but what I was doing wrong (apparently), was that I saved the alert signal inside of a strategy, not a study. Once I saved it inside of a study, it started acting exactly as I would expect it to. Thanks for helping me, I would have never thought of doing this if I wasn’t thinking about your suggestion. Cheers! Fantastic blog!
August 28, 2017 at 7:07 pm
Instead of a sound can the occurrence of the alert save it to the local drive (directly or indirectly). If someone knows how to write this thinkscript code, I don’t mind paying for it.
October 21, 2017 at 8:53 am
Doesn’t the chart have to be open for the study alert to trigger though? Also, the alert script can only be applied to one symbol at a time, right?