$VIX

Solution
Worked on a new version.

I call it the VIX (market fear gauge/oscillator)... LOL

Is there a way to avoid the repaint? noted color changes after turning green or red.

Python:
# ########################################
# VIX (Market Fear Meter/Oscillator)
# Created by @rewardiaz
# v1.0 : 07/25/2024
# v2.0 : 08/07/2024

# ########################################
# Charting & Formatting
declare lower;
declare real_size;

# ########################################
# Chart Coloring
DefineGlobalColor("bull", CreateColor(0, 165, 0));
DefineGlobalColor("neutral", Color.DARK_ORANGE);
DefineGlobalColor("bear", CreateColor(225, 0, 0));

# ########################################
# Inputs
# Define the length for moving averages
input symbol = "VIX"...
Hope this helps other. I put something toguether.

Code:
# ########################################
# VIX

# ########################################
# Charting & Formatting
declare lower;
declare real_size;

def Periodv = GetAggregationPeriod();

input symbol = "VIX";
input Lengthv = 20;
input Lengthv1 = 50;
input AvgTypev = AverageType.EXPONENTIAL;
input priceclose = FundamentalType.CLOSE;

# ########################################
# Chart Coloring
DefineGlobalColor("rising",  CreateColor(0, 165, 0));
DefineGlobalColor("neutral", Color.dark_orange);
DefineGlobalColor("bear",  CreateColor(225, 0, 0));

def na = Double.NaN;
def vix = close("VIX");

def v20 = if IsNaN(MovingAverage(AvgTypev, Fundamental(priceclose, symbol, period = Periodv), Lengthv))
then v20[1]
else MovingAverage(AvgTypev, Fundamental(priceclose, symbol, period = Periodv), Lengthv);

def v50 = if IsNaN(MovingAverage(AvgTypev, Fundamental(priceclose, symbol, period = Periodv), Lengthv))
then v50[1]
else MovingAverage(AvgTypev, Fundamental(priceclose, symbol, period = Periodv), Lengthv1);

plot pVIX = if !isNaN(vix) then vix else
            if isNan(vix) then vix[1]
            else na;
pVIX.AssignValueColor(
    if v20 > v50 then GlobalColor("bear") else
    if v50 > v20 then GlobalColor("rising") else
    if v20 > v50 and vix < v20 or v20 < v50 and vix > v20 then GlobalColor("neutral")
    else GlobalColor("neutral"));
pVIX.SetLineWeight(2);

plot hLvl16 = 16;
hLvl16.SetDefaultColor(GlobalColor("neutral"));
hLvl16.SetLineWeight(2);

plot hLvl18 = 18;
hLvl18.SetDefaultColor(GlobalColor("neutral"));
hLvl18.SetLineWeight(2);

plot hLvl20 = 20;
hLvl20.SetDefaultColor(GlobalColor("neutral"));
hLvl20.SetLineWeight(2);

AddLabel(yes,
    if v20 > v50 then " VIX Bearish " else
    if v50 > v20 then " VIX Bullish " else
    if v20 > v50 and vix < v20 or v20 < v50 and vix > v20 then " VIXCHOP " else " VIXCHOP ",
    if v20 > v50 then GlobalColor("bear") else
    if v50 > v20 then GlobalColor("rising") else
    if v20 > v50 and vix < v20 or v20 < v50 and vix > v20 then GlobalColor("neutral") else GlobalColor("neutral"));
 
Worked on a new version.

I call it the VIX (market fear gauge/oscillator)... LOL

Is there a way to avoid the repaint? noted color changes after turning green or red.

Python:
# ########################################
# VIX (Market Fear Meter/Oscillator)
# Created by @rewardiaz
# v1.0 : 07/25/2024
# v2.0 : 08/07/2024

# ########################################
# Charting & Formatting
declare lower;
declare real_size;

# ########################################
# Chart Coloring
DefineGlobalColor("bull", CreateColor(0, 165, 0));
DefineGlobalColor("neutral", Color.DARK_ORANGE);
DefineGlobalColor("bear", CreateColor(225, 0, 0));

# ########################################
# Inputs
# Define the length for moving averages
input symbol = "VIX";
input VIXback = 14;
input smoothLength = 5;

# Historical Levels
input BullishLevel = 0.0;
input BearishLevel = 0.0;
input level1 = 16;
input level2 = 18;
input level3 = 20;
input level4 = 22;
input level5 = 25;
input level6 = 28;
input level7 = 30;
input level8 = 32;

# ########################################
# Globals
def na = Double.NaN;
def c = close("VIX");
def VIX = if !isNaN(c) then c else 
          if isNan(c) then c[1] else 
            na;

# ########################################
# Normalize the VIX data by calculating its Z-score
def meanVIX = if IsNaN(Average(VIX, VIXback))
              then meanVIX[1] 
              else Average(VIX, VIXback);
def stdDevVIX = if IsNan(StDev(VIX, VIXback))
                then stdDevVIX[1]
                else StDev(VIX, VIXback);
def normalizedVIX = (VIX - meanVIX) / stdDevVIX;

# ########################################
# Smooth the normalized VIX data using an exponential moving average (EMA)
def smoothNormalizedVIX = ExpAverage(normalizedVIX, smoothLength);

plot HV = 3;
HV.SetStyle(Curve.SHORT_DASH);

plot LV = -3;
LV.SetStyle(Curve.SHORT_DASH);

# Plot the sentiment oscillator
plot SO = smoothNormalizedVIX;
SO.AssignValueColor(if SO > SO[1] then GlobalColor("bear") else GlobalColor("bull"));
SO.SetLineWeight(3);
SO.HideBubble();
SO.HideTitle();

# Determine the level that VIX has crossed
def crossedAbove =  if VIX crosses above level1 && VIX > VIX[1] then level1 else 
                    if VIX crosses above level2 && VIX > VIX[1] then level2 else 
                    if VIX crosses above level3 && VIX > VIX[1] then level3 else 
                    if VIX crosses above level4 && VIX > VIX[1] then level4 else 
                    if VIX crosses above level5 && VIX > VIX[1] then level5 else 
                    if VIX crosses above level6 && VIX > VIX[1] then level6 else 
                    if VIX crosses above level7 && VIX > VIX[1] then level7 else 
                    if VIX crosses above level8 && VIX > VIX[1] then level8 else 
                    if VIX crosses above BullishLevel && VIX > VIX[1] then BullishLevel else 
                    if VIX crosses above BearishLevel && VIX > VIX[1] then BearishLevel
                    else na;

def crossedBelow =  if VIX crosses below level1 && VIX < VIX[1] then level1 else 
                    if VIX crosses below level2 && VIX < VIX[1] then level2 else 
                    if VIX crosses below level3 && VIX < VIX[1] then level3 else 
                    if VIX crosses below level4 && VIX < VIX[1] then level4 else 
                    if VIX crosses below level5 && VIX < VIX[1] then level5 else 
                    if VIX crosses below level6 && VIX < VIX[1] then level6 else 
                    if VIX crosses below level7 && VIX < VIX[1] then level7 else 
                    if VIX crosses below level8 && VIX < VIX[1] then level8 else 
                    if VIX crosses below BullishLevel && VIX < VIX[1] then BullishLevel else 
                    if VIX crosses below BearishLevel && VIX < VIX[1] then BearishLevel
                    else na;

plot hLevel = if crossedAbove or crossedBelow then smoothNormalizedVIX else na;
hLevel.SetPaintingStrategy(PaintingStrategy.POINTS);
hLevel.SetDefaultColor(GlobalColor("neutral"));
hLevel.SetLineWeight(3);
hLevel.HideBubble();
hLevel.HideTitle();

# Add bubbles for level crossings
AddChartBubble(crossedAbove, smoothNormalizedVIX, crossedAbove, GlobalColor("bear"), yes);
AddChartBubble(crossedBelow, smoothNormalizedVIX, crossedBelow, GlobalColor("bull"), no);

# Add alerts for level crossings
Alert(crossedAbove, "$VIX crossing above " + crossedAbove, Alert.BAR, Sound.Bell);
Alert(crossedBelow, "$VIX crossing below " + crossedBelow, Alert.BAR, Sound.Bell);

AddLabel(yes, 
    if SO > SO[1] then " $VIX " + VIX + " Bearish and rising. " else 
    if SO < SO[1] then " $VIX " + VIX + " Bullish and falling. " else 
    " VIXCHOP ",
    if SO > SO[1] then GlobalColor("bear") else 
    if SO < SO[1] then GlobalColor("bull") else 
    GlobalColor("neutral"));

AddLabel(crossedAbove, " $VIX crossing above " + crossedAbove + " level. ", GlobalColor("bear"));
AddLabel(crossedBelow, " $VIX crossing below " + crossedBelow + " level. ", GlobalColor("bear"));
 
Last edited:
Solution

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
353 Online
Create Post

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