This one is fun. It uses the bollinger bandwidth as a measure of volatility.
The scan setup is simple:
Here is the indicator:
The scan setup is simple:
- High Average Bandwidth > 30 (This implies very high volatility. For instance the 60 day average bandwidth on TSLA is 43 compared to SPY which is 8)
- Current Bandwidth < 15 (A low volatility state in a high volatility stock means squeeze is coming, the lower the volatility the better)
Here is the indicator:
Code:
declare lower;
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_Up = 2.0;
input BulgeLength = 150;
input SqueezeLength = 150;
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;
plot Bandwidth = (upperBand - lowerBand) / midLine * 100;
Bandwidth.SetDefaultColor(Color.GREEN);
plot Bulge = Highest(Bandwidth, BulgeLength);
Bulge.SetDefaultColor(GetColor(8));
Bulge.setStyle(Curve.SHORT_DASH);
plot Squeeze = Lowest(Bandwidth, SqueezeLength);
Squeeze.SetDefaultColor(GetColor(8));
Squeeze.setStyle(Curve.SHORT_DASH);
#Bandwidth Label
AddLabel(Bandwidth, Concat("CurrentVolatility = ", Bandwidth), color.GREEN);
#Moving Average Volatility
def var = Bandwidth;
input len = 7;
input len1 = 14;
input len2 = 60;
input len3 = 120;
def displace1 = 0;
plot AvgVolatility7 = ExpAverage(var[-displace], len);
plot AvgVolatility14 = ExpAverage(var[-displace], len1);
plot AvgVolatility60 = ExpAverage(var[-displace], len2);
plot AvgVolatility120 = ExpAverage(var[-displace], len3);
AvgVolatility7.SetDefaultColor(Color.Dark_Green);
AvgVolatility14.SetDefaultColor(Color.Yellow);
AvgVolatility60.SetDefaultColor(Color.Blue);
AvgVolatility120.SetDefaultColor(Color.Magenta);
#Average Volatility Labels
AddLabel(AvgVolatility7, Concat("7VolatilityAverage = ", AvgVolatility7), color.DARK_GREEN);
AddLabel(AvgVolatility14, Concat("14VolatilityAverage = ", AvgVolatility14), color.YELLOW);
AddLabel(AvgVolatility60, Concat("60VolatilityAverage = ", AvgVolatility60), color.BLUE);
AddLabel(AvgVolatility120, Concat("120VolatilityAverage = ", AvgVolatility120), color.MAGENTA);
Last edited by a moderator: