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:
sound default value:
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:
Now some examples! This code will call an alert once on every single 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;
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
A slightly less ADD version would be to alert only once per bar, like so:
And finally, if you only wanted the first +1000 tick of the day, you could use
If you have any cool uses of Thinkscript alerts, feel free to share in the comments!