Check out both lower and upper chart code below. Added color bars and a magenta line where volatility is low which signals extended bullishness, and potential spot for a reversal, and a cyan line indicating high levels of volatility signaling downward pressure.
The original code for the lower indicator is here. https://www.tradingview.com/script/MQsliRxJ/
Here is the Upper chart version.
The original code for the lower indicator is here. https://www.tradingview.com/script/MQsliRxJ/
Code:
#Williams_Vix_Fix_BollingerBand
#Original code https://www.tradingview.com/script/MQsliRxJ/
#Converted and modified by Chewie 12/10/2025
#Added a magenta sell line where volatility is low
#Added a cyan buy line where volatility is high
#Blue color indicates price is still in high volatility, but it is weakening
declare lower;
input src = close; # Source (not actually used in original Pine WVF)
input pd = 22; # Period for Highest Close
input length = 20; # SMA Length
input mult = 2.0; # StdDev Multiplier
# --- WVF Calculation ---
def highestClose = Highest(close, pd);
def WVF = (highestClose - low) / highestClose * 100;
# --- Bollinger Bands on WVF ---
def basis = Average(WVF, length);
def dev = mult * StDev(WVF, length);
def upper = basis + dev;
def lower = basis - dev;
# --- Plot Bands ---
plot UpperBand = upper;
UpperBand.SetDefaultColor(Color.BLUE);
UpperBand.SetLineWeight(2);
plot LowerBand = lower;
LowerBand.SetDefaultColor(Color.RED);
LowerBand.SetLineWeight(2);
# --- Buy / Sell Signals ---
def Buy = WVF crosses above upper;
def Sell = WVF crosses below lower;
plot BuySignal = if Buy then WVF else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.SetDefaultColor(Color.GREEN);
plot SellSignal = if Sell then WVF else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.SetDefaultColor(Color.RED);
# ---------------------------------------------------------
# --- Regression Level-
# ---------------------------------------------------------
input sellline = 0.33;
input buyline = 2.0;
input lookback = 400;
# Regression approximation allowed in lower studies
def regApprox = Inertia(WVF, length);
def regAvg = if BarNumber() > lookback
then Average(regApprox, lookback)
else regApprox;
def isLastBar = IsNaN(regAvg[-1]) and !IsNaN(regAvg);
def regCapture = if isLastBar then regAvg else Double.NaN;
def regFlat = HighestAll(regCapture);
# Flat line at the regression average
plot PercentLine = regFlat * sellline;
PercentLine.SetPaintingStrategy(PaintingStrategy.LINE);
PercentLine.SetDefaultColor(Color.magenta);
PercentLine.SetLineWeight(2);
plot PercentLineUP = regFlat * buyline;
PercentLineUP.SetPaintingStrategy(PaintingStrategy.LINE);
PercentLineUP.SetDefaultColor(Color.cyan);
PercentLineUP.SetLineWeight(2);
# --- Color Logic (Green = High, Red = Low, Gray = Neutral) ---
plot WVFcol = WVF;
WVFcol.SetLineWeight(4);
WVFcol.AssignValueColor(
if WVF >= upper then Color.GREEN
else if WVF <= lower then Color.RED
else if WVF < PercentLine then color.magenta
else if WVF > PercentLineUP and WVF < WVF[1] then color.blue
else if WVF > PercentLineUP then color.cyan
else Color.DARK_GRAY
);
WVFcol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#ColorBar
input colorbar = no;
def g = WVF >= upper;
def r = WVF <= lower;
def m = WVF < PercentLine;
def b = WVF > PercentLineUP and WVF < WVF[1];
def c = WVF > PercentLineUP;
AssignPriceColor(if !colorbar then Color.CURRENT else if g then Color.GREEN else if r then Color.RED else if m then color.magenta else if b then color.blue else if c then color.cyan else Color.GRAY);
Here is the Upper chart version.
Code:
#Williams Vix Fix Bollinger Band Upper chart
#Assembled by Chewie 12/10/2025
declare upper;
input pd = 22;
input length = 20;
input mult = 2.0;
input offset = 0.2; # vertical offset relative to price (adjust to taste)
# --- WVF Calculation ---
def highestClose = Highest(close, pd);
def WVF_raw = (highestClose - low) / highestClose * 100;
# --- Normalize WVF to overlay on chart ---
# Normalize relative to chart price range
def hiP = Highest(high, 100);
def loP = Lowest(low, 100);
def rangeP = hiP - loP;
def WVF = loP + (WVF_raw / 100) * rangeP * offset;
# --- Bollinger Bands on WVF ---
def basis_raw = Average(WVF_raw, length);
def dev_raw = mult * StDev(WVF_raw, length);
def upper_raw = basis_raw + dev_raw;
def lower_raw = basis_raw - dev_raw;
# Convert raw bands into overlay scale
def Upper = loP + (upper_raw / 100) * rangeP * offset;
def Lower = loP + (lower_raw / 100) * rangeP * offset;
# --- Plot Bands ---
plot UpperBand = Upper;
UpperBand.SetDefaultColor(Color.BLUE);
UpperBand.SetLineWeight(2);
plot LowerBand = Lower;
LowerBand.SetDefaultColor(Color.RED);
LowerBand.SetLineWeight(2);
# --- WVF Histogram (overlaid) ---
plot WVFcol = WVF;
WVFcol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
WVFcol.SetLineWeight(4);
WVFcol.AssignValueColor(
if WVF_raw >= upper_raw then Color.GREEN
else if WVF_raw <= lower_raw then Color.RED
else Color.dark_GRAY
);
Last edited: