Williams Vix Fix Bollinger Band Upper and Lower Indicator for ThinkorSwim

chewie76

Well-known member
VIP
VIP Enthusiast
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/

1765469990111.png


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.

1765470076890.png



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:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
655 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top