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
31,641
First release
Last update
Rating
5.00 star(s) 1 ratings

More resources from BenTen

Latest reviews

Excellent, concise, and logical presentation of Alerts, their purpose and how to implement without too much wasteful code. Thank you

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top