Setting USEFUL Technical Alerts in TOS Platform

  1. Background
  2. Getting Started
  3. Create an Oscillator Study which crosses a fixed reference (like 0)
  4. Some Advanced Tricks
  5. Three Green Arrows
  6. High of Low Day and Low of High Day (Price Chart Only)
To understand this you need to understand basic algebra to the extent of using a symbol to represent a formula and then substituting that formula in the end...  If you can balance a check book then you can probably figure out these instructions.  Any time you see My****Study below you simply put in the script for the study you want to use...  Script Text is Emphasized.

Disclaimer:  The following is intended to provide guidance to the suitably advanced trader using the Think Or Swim trading platform.  If you do not completely understand what you are doing, then don't use it.  We accept no responsibility whatsoever if you make the decision to enter a trade because you set an improper trigger condition.  We describe alerts below, and while you CAN you this same formulaic instruction as guidance to create trade triggers you must ask yourself if you SHOULDYou are fully and solely responsible for the action you take from here...


The initial release of TOS with technical study alerts only allowed comparison of a limited set of technical studies (like Simple Moving Average) to be compared to a fixed price.  As technical traders we really don't care what the price of a moving average is, we want to know when the price of the stock crosses a moving average.  While the initial release allowed using an oscillator study such as MACD or Stochastic, and many others for that matter, we simply could not trigger based on the cross of a moving average.  MACD did allow Exponential Moving Average crossover studies, but nothing available allowed testing for price crossing the moving average.  While tantalizing for many of us, it just was not really useful.  This has changed!

The August 1, 2009 release of TOS allows the long awaited use of custom studies using Think Script.  On the surface it looks like we still cannot compare price to moving average, but with the ability to create complex custom studies there are several ways to overcome these apparent limitations.  You do need to understand how to re-arrange equations.  If you can do this then you can use think script to create just about any technical study you can imagine.  And most of these can be arranged into a form that can be used to trigger alerts and even trades.

Since most of the TOS people have a floor trading background, they just don't use technical triggers for their trading.  Because of this the results you get from TOS will depend on who you are asking.  But if you go through support you can rely that your request for information and help will be routed to someone who will be able to help you get the solution you want.  If you can't figure it out they will certainly have someone who is interested, who knows it well, and can help - or at the very least help you get started.

Think Script is the language you need to learn on the TOS platform to do this.  This is a pretty simple programming language and has very logical and simple functions to get you all the building blocks for basically any technical study you could want to create.  Now we cannot argue logical, the functions available are the best fundamental building blocks for technical indicators.  You can argue about the simplicity of Think Script, but take it from an experienced software engineer, this is really simple.  It was designed so that someone with no real software background, but with the ability to formulate the technical studies they want to see on a chart, will be able to create scripts to produce their studies with a minimal learning curve.

Getting Started

Now, I suggest you start with a TOS Chart Study where you pick one of the above as MyPriceStudy below...  If you have not done this before then follow these instructions:

Using TOS Charts (This is not for Prophet Charts) create a single chart with no studies and go to Edit Studies.  Find the study MovAvgExponential, right-click, and select view-source.  This is a very simple study and can provide an example for you to work from.

You can also COPY this study into a new script and make changes to it.  I suggest this path so you can start from something that works. Below the list of studies, is a button New Study and you can use this to create a new study from scratch.

By default the name will be NewStudy1 and you should create your own study name.  In this case perhaps calling it E5BarBreakdown.

Delete the default plot and insert your first study by replacing it with  for this example.

plot E5BarSupport = ExpAverage(low,5);

Save this study, click OK on the Edit Studies dialog box, and you see your new study...


  1. I usually call my chart studies something starting with 'A' so they are near the top of the list...
  2. I use the term Bar here because it will work on any time scale you set onto the chart...

Create your upper chart study with the following:

plot E5BarSupport = ExpAverage(low,5);

If you look at a strong trend, you should see the plot line running below the lows right up the trend...

Now, let's make this an oscillator study...  Just make the following change:

declare lower;
E5DSupport = close-(ExpAverage(low,5));

Now you see a lower chart study where 0.0 is your study ExpAverage(low,5) and the line is the closing price...  Consider the math for this, for a moment.  The expression close-X is positive if close>X and is negative when close<X, of course 0 when close=X.  So the resulting study is zero when equal to your study, and the line is above zero when close>X.

Now, just one more complication for convenience, I don't want that lower study to read in price, I want it to read in percent, make the following change:

declare lower;
E5DSupport = (100/close[+1])*(close-(ExpAverage(low,5)));

Now you get essentially the same line, but each 'count' on the value is 1% of the stock price (using the previous day close for the percent base scale).

So, in the above, you have MyPriceStudy is ExpAverage(low,5).

If you like a slower moving average, then use 20 days instead of 5 resulting in:  close-(ExpAverage(low,20)).

There are several studies we like for Support and Resistance Breaks:

Support:  (Breakdown, long stops)

Resistance:  (Breakout, long entry)

Note in all of these candle formulas the use of [+1] which forces the script to use the previous candle.  You cannot  use the high of the low day but you can use yesterday's high or R3.  Often this is good enough when there is really a reversal.  We don't have scripts for specific candle patterns, but if you see a pattern then you can set an alert for the appropriate trigger...

Create an Oscillator Study which crosses a fixed reference (like 0)

To make this an oscillator study with the ZERO line the same as your study you plot close-(MyPriceStudy) as a lower chart study.

If you want that scaled as percent instead of price then use (100/close[+1])*(close-(MyPriceStudy)) as a lower chart study.

Now, let's say I want to be alerted when the stock I own drops more than 1% below the 5 day EMA of the low prices, here's my study:

The alert study is (100/close[+1])*(close-(ExpAverage(low,5))) and I trigger when BELOW the value of -1.0. (Note negative/minus 1.0)

If I want to alert when the price is 25 cents below the study then I use the study close-(ExpAverage(low,5)) and trigger when BELOW the value of -0.25.  (Note negative/minus 0.25)

I can do this for any chart study I want to use to create a useful trigger which works for any security at any price...

During the demonstration on 2009/08/18 I found we cannot enter negative price or percent thresholds for alerts.  This is a bug on the TOS platform and I have sent a description of the problem to Support so Tom and his folks can get working on a fix.  In the mean time, we need another algebra refresher:

(Update on that Note:  I spoke with TOS today and the bug only exists if you enter the alert edit dialog in a particular way, it is a boundary condition problem and will be fixed soon)

If we want to have an alert when (100/close[+1])*(close-(MyPriceStudy)) < -1.0 and we cannot enter a negative number we need to swap the "close-(MyPriceStudy)" part.

So now we want an alert when (100/close[+1])*((MyPriceStudy)-close) > 1.0. in swapping those terms the oscillator has flipped over, try it in a chart to see this visually.

For my demonstration I created 2 think scripts  AAATestPrice and AAATestOsc for illustration.  I also had an upper price study which has everything:  AAAAlertsUpperChart

Some Advanced Tricks

I know the above is probably advanced for some of you, but with practice you'll get the hang of it.

You can lock in the best price by using MyBestBuyPrice = Lowest(MyResistanceStudy,5) or MyBestStopPrice = Highest(MySupportStudy,5) which will hold the best value for your trade for 5 bars, you can use any number of bars you want to use to lock in the best price for a stop or for a buy price...

Let's say I want to buy at 25 cents above the lowest high in the last 5 days:  The study is Lowest(High[+1],5) and the trigger is when ABOVE the value of 0.25.

You also know we usually want a buffer around the price, I showed how to use 1% below the level above, but I like to use an offset which scales to the price and volatility of a security.  One pleasing value for most ETF securities and many stocks is the AverageTrueRange(15)/3 which scales to price and volatility.

For broken support I might use MySupportStudy-AverageTrueRange(15)/3, and for broken resistance I might use MyResistanceStudy+AverageTrueRange(15)/3.

If I want the lowest resistance then I use Lowest(MyResistanceStudy+AverageTrueRange(15)/3,5).

You can set trade triggers on these studies.  We prefer to set alerts and watch the price action, then usually trade late in the day if the alert condition holds...

Three Green Arrows

Here's the code for the 3 Green Arrows (really it is 4) alert:

(MACD(fastLength = 8, slowLength = 17).Diff > 0.0)+
(StochasticSlow(DPeriod = 5, KPeriod = 14).SlowD > 20)+
(SimpleMovingAvg(length = 30) > SimpleMovingAvg(length = 30)[+1])+
(close > SimpleMovingAvg(length = 30))

Enter when the study is > 3.5 (have all 4 arrows)
Exit when the study is < 0.5 (have 0 arrows) -- exit on your choice, really...

This study creates a BOOL condition for each Green Arrow.  BOOL is either 0(FALSE) or 1(TRUE), so the expression adds up to 4 when all arrows are green or TRUE.

The first arrow is the MACD Histogram; when the histogram is above zero is when the first arrow is true.  The second arrow is the (Slow) Stochastic; when the smoothed slow stochastic line is above 20% is when the second arrow is true.  The third arrow is the 30-Bar Simple Moving Average; when the moving average is ticking up is the third green arrow.  The fourth arrow is when the close (the current price) is above the 30-Bar EMA.  We learned 3GA with the instructor emphasizing that the moving average should be trending upward, so there are really 4 conditions.

High of Low Day and Low of High Day (Price Chart Only)

Well, we cannot set alerts on these at this time, but we can have the chart price studies. 

input NDays = 5;

rec HiOfLoDay = if low[+1] == Lowest(low, NDays) then high[+1] else HiOfLoDay[+1];
rec LoOfHiDay = if high[+1] == Highest(high, NDays) then low[+1] else LoOfHiDay[+1];

plot Entry = HiOfLoDay;
plot EStop = Lowest(low,NDays);
plot HStop = LoOfHiDay;

The names presume a bullish perspective, of course.

Because the study alerts currently presume a single PLOT statement we cannot use REC in study alerts at this time...  So, tell TOS Support you need it?