Cool Scripts: Bollinger Band-ing Volatility

Cool Scripts: Bollinger Band-ing Volatility

Volatility may not tell you which way is up, but it can point to possible trading signals. Let’s create a thinkScript® in TD Ameritrade’s thinkorswim® trading platform that uses Bollinger Bands to simultaneously analyze price and implied volatility to generate possible trading signals.

Our goal? Let’s have thinkorswim color a price bar a different color when the implied volatility of the underlying is outside its own set of Bollinger bands—covering 95% of volatility’s normal range of movement, or in geek-speak, two standard deviations. The indicator is designed to point out time where a trader may want to get long (below the lower band), or short (above the upper band) volatility.

The Script*

Cut and paste each of the following lines into your Script editor. But be sure not to include the line numbers.

1. #Hint: Bollinger Bands for IV

2. declare lower;

3. declare hide_on_intraday;

4. input length = 10;

5. input NumberofDevs = 2;

6. def data = ImpVolatility();

7. def up = close > open;

8. def down = close < open;

9. def offset = NumberofDevs * Stdev(data, length);

10. #The plots that will be drawn on the chart

11. plot IV = data;

12. plot MidLine = Average(data, length);

13. plot UpperBand = MidLine + offset;

14. plot LowerBand = MidLine – offset;

15. #Changing the color of the chart to make it pop and significant time

16. AssignPriceColor(if data > upperBand and down then Color.YELLOW else if data < lowerBand and up then color.BLUE else color.current);

The Skinny

Line 1. Recall that the hash tag “#” creates a note in your script to create hints or to keep track of what you’re coding.

Line 2-3. Next, two declarations. Declaring something applies to how the script can or should be used. In this case, we declare this a lower study, and also hide this on any intraday aggregation.

Line 4. Length defines how many periods should be used to calculate average and standard deviation.

Line 5. NumberofDevs defines the number of standard deviation moves the band will be drawn away from the implied vol.

Line 6. We’re defining our data as implied volatility. You can also define up-price bars and down-price bars to be used later.

Lines 7-9. This is perhaps the most important piece of the script, the logic on which Bollinger Bands are based.

Lines 11-14. Here is where we tell the script what to plot. The Midline is simply the average of what we define as data (implied volatility) for our chosen number of periods, then we add the upper and lower bands of the Bollinger band.

Line 16. The kicker. This line checks if the implied vol is above or below the bands around the average. It also monitors if significant moves are on down-price moves or up-price moves. If there’s an increase in implied vol and the price moves up, the bar is painted yellow. If implied volatility is above the upper band on a down move, the bar is painted blue. This draws your attention to a point you can define as important. Normally, when a price moves down, implied volatility increases. So an up move in price, above when implied volatility is out of its normal range, indicates a price trend could be changing. This same idea translates to a down move in price when implied volatility remains lower than normal. 

Cool Scripts: Bollinger Band-ing Volatility


This cool script turns the first bars a custom color after a breach of extreme volatility. For illustrative purposes only. 

*Script Share

Skip the coding yourself and download David’s thinkScript straight into thinkorswim.

Leave a comment