Alert

Alert ( String sound, IDataHolder condition, String text, int alert type, String sound);

Default values:

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

Description

Shows an alert message with the text and plays the sound when the condition is true. Note that you can create studies containing only alert function call without defining any plots.

Input parameters

Parameter Default value Description
condition - Defines condition upon which the alert is displayed.
text - Defines text of the alert message.
alert type Alert.ONCE Defines periodicity with which the alert is shown. This parameter accepts Alert constants as value.
sound Sound.NoSound Defines the alert sound. This parameter accepts Sound constants as value.

Example 1

Alert(Crosses(close, Average(close, 15), CrossingDirection.ABOVE), "Closing price crosses over SMA!");

This alert is triggered on the first cross of the Close price over the SMA with the length equal to 15. It can be triggered only once and does not play any sound, because it uses default values Alert.ONCE and Sound.NoSound for the alert type and sound.

Example 2

def condition = Crosses(Average(close, 15), Average(close, 30), CrossingDirection.ABOVE);
Alert(condition, "Bullish!", Alert.BAR);

This alert is triggered when the fast average crosses the slow average and shows the corresponding text message. It can be triggered once per bar and does not play any sound, because it uses Alert.BAR value for the alert type and default Sound.NoSound value for the sound.

Example 3

Alert(close >= 100 and close < 200, "100 <= Tick < 200!", Alert.TICK, Sound.Ding);
Alert(close >= 200, "Tick > 200!", Alert.TICK, Sound.Chimes);

First alert is triggered for each tick greater than 100, but less than 200 and the second alert - for each tick greater than 200. Both alerts also display a text and play sound other than default.

You may also like
thinkScript®: Q&A
What is thinkScript®? thinkScript® is a built-in programming language that gives you the ...
Condition Wizard
Condition Wizard is a special feature which allows you to build up conditions or logical ...
Study Alerts
Study Alerts are signals generated when a study-based condition is fulfilled. You can use both ...