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!