• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!
Resource icon

How to Add Alert Script to ThinkorSwim Indicators

Say you have a custom ThinkorSwim study and want to get alerted for when a signal appears or a condition becomes true, here's how.

Usage

Code:
Alert(conditional statement, text alert, alert type, sound);

Examples

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#

input fastLength = 50;
input slowLength = 200;
input averageType = AverageType.SIMPLE;

plot FastMA = MovingAverage(averageType, close, fastLength);
plot SlowMA = MovingAverage(averageType, close, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));

def goldencross = FastMA crosses above SlowMA;

# Alert
Alert(goldencross, "50/200 Crossover", Alert.Bar, Sound.Chimes);

The alert script above will notify you every time there's a golden cross (the 50 SMA crossing above the 200 SMA).

Here is another one where we utilize two different alert sounds. You'll hear a chime when there is an up arrow and a bell sound when there is a down arrow.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#

input price = close;
input length = 9;
input displace = 0;

plot AvgExp = ExpAverage(price[-displace], length);
plot UpSignal = price crosses above AvgExp;
plot DownSignal = price crosses below AvgExp;

AvgExp.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

# Alerts
Alert(UpSignal, "Price crossing above 9 EMA", Alert.Bar, Sound.Chimes);
Alert(DownSignal, "Price crossing below 9 EMA", Alert.Bar, Sound.Bell);

Additional scripts related to Alert

Useful Notes from the thinkScript Lounge

thinkScript Alert() function. Platform and chart have to be open. [source]

15:42 Nick Name NAG®: Stash, just to be clear. There are 2 ways to do alerts.

1) thinkScript Alert() function. Platform and chart have to be open.
2) Platform alert, found on Marketwatch -> Alerts. Platform doesn't have to be open and you can get email/SMS. You can use thinkscript, with some limitations. The Alert() function is irrelevant to a platform alert.

For the former, the types are: Alert.ONCE, .BAR, .TICK. Once = one time only, first time the condition is met. BAR = one time on each bar when the condition is met. TICK = every time the condition is true. Once you set the type, it should hold unless changed in the script or gui settings.

I am not sure how the platform alert works in this regard, those have their own rules. My testing shows the Alert() function is working correctly, other than the bug I mentioned earlier. That might have just been general wonkiness as it was within the last couple minutes of /ES before 1615. All that is to say if you are using Alert.BAR and getting multiple alerts per bar, it's not because the Alert() function is broken.

Alert for an entire watchlist [source]

By Cindy Faber TOS: to set an alert for an entire watch list, you have to create a custom chart study with alert built into the ThinkScript for the custom chart study then open a grid of charts with each containing the custom study with alert, and click on top right Symbols to select the watch list

IMPORTANT - you can detach the grid and move it until almost off your screen but do NOT minimize (chart alerts will only trigger if chart is open, even if chart is hiding near edge of the screen)

TOS platform tip/trick - How to set an earnings warning Alert [source]

(1) go to top right Setup- Application Settings- Notifications tab and enter email and/or cell phone and follow instructions
(2) go to MarketWatch tab- Alerts subtab
(3) click on Bid or Ask for the stock
(4) change alert to ABOVE and price to 0.01 one penny
(5) select How to Notify choices
(6) select Options, Submit and change to last trading day BEFORE earnings and time during market hours
(7) add note such as EARNINGS BMO tomorrow (before market open) NOTE: use the same steps on SPX above 0.01 to set a general alert such as “My Anniversary is tomorrow” … or “Market close in 1 hour” etc.
Author
BenTen
Views
2,523
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from BenTen

Top