Stochastic Vix Fix SVIX For ThinkOrSwim

Rajesuja

New member
VIP
Author states: The Stochastic Vix or Stochastic VixFix (SVIX), just like the Williams VixFix, is a realized volatility indicator, and can help in finding market bottoms as well as tops without requiring bollinger bands or any other construct, as the SVIX is bounded between 0-100 which allows for an objective thresholding regardless of the past.

Mathematically, SVIX is the complement of the original Stochastic Oscillator, with such a simple transform reproducing Williams' VixFix and the VIX index signals of high volatility and hence of market bottoms quite accurately but within a bounded 0-100 range. Having a predefined range allows to find markets bottoms without needing to compare to past prices using a bollinger band (Chris Moody on TradingView) nor a moving average (Hesta 2015), as a simple threshold condition (by default above 80) is sufficient to reliably signal interesting entry points at bottoming prices.

Having a predefined range allows to find markets bottoms without needing to compare to past prices using a bollinger band (Chris Moody on TradingView) nor a moving average (Hesta 2015), as a simple threshold condition (by default above 80) is sufficient to reliably signal interesting entry points at bottoming prices.

Indeed, as Williams describes in his paper, markets tend to find the lowest prices during times of highest volatility, which usually accompany times of highest fear.

Although the VixFix originally only indicates market bottoms, the Stochastic VixFix can also indicate good times to exit, when SVIX is at a low value (default: below 20), but just like the original VixFix and VIX index, exit signals are as usual much less reliable than long entries signals, because: 1) mature markets such as SP500 tend to increase over the long term, 2) when market fall, retail traders panic and hence volatility skyrockets and bottom is more reliably signalled, but at market tops, no one is panicking, price action only loses momentum because of liquidity drying up.

3yOCJjI.png


Here is the original Tradingview code:
https://www.tradingview.com/script/NbFQ85ud-Stochastic-Vix-Fix-SVIX-Tartigradia/

For the new ThinkOrSwim code, you must scroll down to the next post
 
Last edited by a moderator:
@samer800, can you please convert this Stochastic Vix Fix SVIX
Link : https://www.tradingview.com/script/NbFQ85ud-Stochastic-Vix-Fix-SVIX-Tartigradia/
Thanks in advance.

@samer800, can you please convert this Stochastic Vix Fix SVIX
check the below:

CSS:
#// Indicator for TOS
#// @Tartigradia
#//indicator(title='Stochastic Vix Fix SVIX (Tartigradia)', shorttitle='SVIX_TG'
#Hint UseChartSymbol: If enabled, will use the currently selected symbol in TradingView chart to calculate VixFix. If disabled, you can select a symbol below.
#Hint customSymbol: Symbol to calculate vixfix from. Select SPX to reproduce the VIX index.
#Hint LookBackPeriod: Default: 20 period in the original SVIX that reproduces the original VIX and VixFix according to the authors, showing periods of overreactions. Set 50 period if you want a market cycle indicator.
#Hint showCloudShort: Exit signals are as usual much less reliable than long entry signals, because: 1) mature markets such as SP500 tend to increase over the long term, 2) when market fall, retail traders panic and hence volatility skyrockets and bottom is more reliably signalled, but at market tops, no one is panicking, price action only loses momentum because of liquidity drying up.
#Hint cloudBasedOn: SVIX is the raw SVIX (k in the Stochastic Oscillator), SVIX_MA is the first-level moving averaged SVIX, SVIX_MA_2ND is the second-level moving averaged SVIX, ie, MA(MA(SVIX)). In the original indicator, the raw SVIX is used. By default, the SVIX is used, as in the original paper, as it provides all entries signals, but alternatively the 14-period ZLMA smoothed SVIX is recommended, to reduce false positives and improve entry timing (enter after more falling instead of too early), but at the expense of missing some potential entries.

# Converted by Sam4Cok@Samer800    - 03/2025

declare lower;

input timeframe = AggregationPeriod.MIN;
input UseChartSymbol = yes; # 'Use current chart symbol instead of the selected one below?'
input customSymbol = "SPX"; # 'Index symbol'
input LookBackPeriod = 20;  # 'LookBack Period'
input cloudBasedOn = {default "SVIX", "SVIX_MA", "SVIX_MA_2ND"}; # 'Highlight based on SVIX or the smoothed SVIX?'
input longThreshold = 80;   # 'Entry threshold', group=grp2, tooltip='Default: 80 for the original SVIX threshold.')
input shortThreshold = 20;  # 'Exit threshold', group=grp2, tooltip='Default: 20 for the original SVIX threshold.')
input showCloudLong = yes;  # 'Highlight long entries (above the entry threshold)?'
input showCloudShort = yes; # 'Highlight exits/shorts (below the exit threshold)?
input MovAvgType1 = {"sma", "ema", "rma", "wma", "vwma", "swma", "hma", "alma", default "zlma", "approximate_sma", "median"};
input MovAvgLength1 = 14; #, "Moving Average Length"
input MovAvgType2 = {"sma", "ema", "rma", "wma", "vwma", "swma", "hma", "alma", default "zlma", "approximate_sma", "median"};
input MovAvgLength2 = 20; # "Moving Average Length second-level"



def na = Double.NaN;
def last = isNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def GAP = GetAggregationPeriod();
def tf = Max(GAP, timeframe);
#input sym = index_current ? syminfo.tickerid : index_symbol  // select symbol: current or another symbol selected by user?
script ALMA {
    input Data = close;
    input Window = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = (Offset * (Window - 1));
    def s = Window / Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(Data, (Window - 1) - y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    plot ALMA = SumVectorData / SumVector;
}

script VWMA {
    input src = close;
    input len = 14;
    input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    plot result = VWMA;
}
script zema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def d = ema1 - ema2;
    def zlema = ema1 + d;
    plot out = zlema;
}
#// @function Approximate Standard Moving Average
script approximate_sma {
    input src = close;
    input len = 14;
    def avg = Average(src, len);
    def sma = if IsNaN(sma[1]) then avg else if !sma[1] then avg else
              sma[1] - (sma[1] / len) + src;
    plot out = sma;
}
Script swma {
input x = close;
    def swma = x[3] * 1 / 6 + x[2] * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6;
    plot out = swma;
}
#// @function Generalized moving average selector
script f_maSelect {
    input serie = close;
    input ma_type = "zlma";
    input ma_length = 14;
    input vol = volume;
    def ma =
        if ma_type == "sma" then Average(serie, ma_length) else
        if ma_type == "ema" then ExpAverage(serie, ma_length) else
        if ma_type == "rma" then WildersAverage(serie, ma_length) else
        if ma_type == "wma" then WMA(serie, ma_length) else
        if ma_type == "vwma" then vwma(serie, ma_length, vol) else
        if ma_type == "swma" then swma(serie) else
        if ma_type == "hma" then HullMovingAvg(serie, ma_length) else
        if ma_type == "alma" then alma(serie, ma_length, 0.85, 6) else
        if ma_type == "zlma" then zema(serie, ma_length) else
        if ma_type == "approximate_sma" then approximate_sma(serie, ma_length) else
        if ma_type == "median" then Median(serie, ma_length) else zema(serie, ma_length);
    plot out = ma;
}

#// Load data
def source_close;
def source_open;
def source_high;
def source_low;
def source_vol;
if UseChartSymbol {
    source_close = close(Period = tf);
    source_open = open(Period = tf);
    source_high = high(Period = tf);
    source_low = low(Period = tf);
    source_vol = low(Period = tf);
} else {
    source_close = close(customSymbol, Period = tf);
    source_open = open(customSymbol, Period = tf);
    source_high = high(customSymbol, Period = tf);
    source_low = low(customSymbol, Period = tf);
    source_vol = low(customSymbol, Period = tf);
}
def highest_close = highest(source_close, LookBackPeriod);
def lowest_close = lowest(source_close, LookBackPeriod);
def highest_high = highest(source_high, LookBackPeriod);
def lowest_low = lowest(source_low, LookBackPeriod);

#/ Stochastic Vix Fix = mathematical complement of original Stochastic Oscillator
def svix = (1 - (source_close - lowest_low) / (highest_high - lowest_low)) * 100;
#// Moving averages
def d = f_maSelect(svix, MovAvgType1, MovAvgLength1, source_vol);
def d2 = f_maSelect(d, MovAvgType2, MovAvgLength2, source_vol);

#/ Raw SVIX and moving averages plots
plot d2Line = if !last then d2 else na; #, title='SVIX_MA_2ND (smoothed D aka D2)'
plot dLine = if !last then d else na; #, title='SVIX_MA (smoothed SVIX aka D)'
plot svixLine = if !last then svix else na; # title='SVIX'
svixLine.SetLineWeight(2);
svixLine.SetDefaultColor(Color.YELLOW);
dLine.SetDefaultColor(Color.CYAN);
d2Line.SetDefaultColor(Color.MAGENTA);

#// Levels
plot lvl1 = if !last then longThreshold else na;
plot mid = if !last then 50 else na;
plot lvl2 = if !last then shortThreshold else na;

lvl1.SetPaintingStrategy(PaintingStrategy.DASHES);
mid.SetStyle(Curve.SHORT_DASH);
lvl2.SetPaintingStrategy(PaintingStrategy.DASHES);
lvl1.SetDefaultColor(Color.GRAY);
mid.SetDefaultColor(Color.DARK_GRAY);
lvl2.SetDefaultColor(Color.GRAY);

#-- Bg
def thr_val;
Switch(cloudBasedOn) {
Case "SVIX_MA": thr_val = d;
Case "SVIX_MA_2ND": thr_val = d2;
Default: thr_val = svix;
}
#// Detect if SVIX is beyond thresholds
def osT = showCloudLong and thr_val > longThreshold;
def obT = showCloudShort and thr_val < shortThreshold;

AddCloud(if (osT or osT[-1]) then pos else na, neg, Color.DARK_GREEN);
AddCloud(if (obT or obT[-1]) then pos else na, neg, Color.DARK_RED);


#-- END of CODE
 

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
803 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