# VIX_FIX v3 Major Update
# Based on Larry Williams' Vix Fix
# Assembled by BenTen at useThinkScript.com
# Converted from
https://www.tradingview.com/script/pJpXG5JH-CM-Williams-Vix-Fix-V3-Ultimate-Filtered-Alerts/
# Video intro:
https://vimeopro.com/user32804960/tradingview-indicators/video/115973132
# Discussion:
https://usethinkscript.com/threads/williams’-vix-fix-indicator-for-thinkorswim.145/post-5467
input pd = 22;
input bbl = 20;
input mult = 2.0;
input lb = 50;
input ph = 0.85;
input pl = 1.01;
# Downtrend Criterias
input ltLB = 40;
input mtLB = 14;
input str = 3;
# Williams Vix Fix Formula
def wvf = ((highest(close, pd) - low) / (highest(close, pd))) * 100;
def sDev = mult * stdev(wvf, bbl);
def midLine = SimpleMovingAvg(wvf, bbl);
def lowerBand = midLine - sDev;
def upperBand = midLine + sDev;
def rangeHigh = (highest(wvf, lb)) * ph;
# Filtered Bar Criteria
def upRange = low > low[1] and close > high[1];
def upRange_Aggr = close > close[1] and close > open[1];
# Filtered Criteria
def filtered = ((wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and(wvf<upperBand and wvf<rangeHigh));
def filtered_Aggr = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]);
# Alerts Criteria
def alert1 = wvf >= upperBand or wvf >= rangeHigh;
def alert2 = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand and wvf < rangeHigh);
def alert3 = upRange and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered;
def alert4 = upRange_Aggr and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered_Aggr;
plot signal1 = alert4;
signal1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal1.SetDefaultColor(Color.magenta);
plot signal2 = alert3;
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal2.SetDefaultColor(Color.blue);
plot signal3 = ((wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand and wvf < rangeHigh));
signal3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal3.SetDefaultColor(Color.cyan);
plot signal4 = (wvf >= upperBand or wvf >= rangeHigh);
signal4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal4.SetDefaultColor(Color.lime);