VIX Indicator by jjfrost

barbaros

Administrator
Staff member
Platform
  1. Thinkorswim
Converted for discord chatroom request. Original TradingView indicator: https://www.tradingview.com/script/dOvHSQxB-VIX-INDICATOR/
There seems to be a difference between ToS and TradingView data. Although code matches, it won't display the same.

Code:
# Converted for b4indicators.com
# barbaros

declare lower;

input symb1 = "VIXMO";
input symb2 = "VIX3M";
input symb3 = "VVIX";
input symb4 = "VXST";

def MOD1 = close(symbol = symb1);
def MOD2 = close(symbol = symb2);
def MOD3 = close(symbol = symb3);
def MOD4 = close(symbol = symb4);

def C0 = MOD1 * MOD2 * MOD3 * MOD4;

input CLOSE0 = 21; # HINT: EMA Close
def KC0 = expAverage(C0, CLOSE0);

plot LongEMA_close = KC0;
LongEMA_close.SetPaintingStrategy(PaintingStrategy.LINE);
LongEMA_close.SetLineWeight(2);
LongEMA_close.SetDefaultColor(color.orange);

input CLOSE1 = 8; # HINT: shortEMA Close
def KC1 = expAverage(C0, CLOSE1);

plot shortEMA_close = KC1;
shortEMA_close.SetPaintingStrategy(PaintingStrategy.LINE);
shortEMA_close.SetLineWeight(2);
shortEMA_close.SetDefaultColor(color.blue);

input EnableBackgroundColor = yes;
AssignBackgroundColor(if EnableBackgroundColor then
    if C0 < KC1 then color.orange else color.black
    else Color.CURRENT
);

plot C0_Line = C0;
LongEMA_close.SetPaintingStrategy(PaintingStrategy.LINE);
LongEMA_close.SetLineWeight(3);
LongEMA_close.SetDefaultColor(color.cyan);

plot EMA_Short = KC1;
EMA_Short.SetPaintingStrategy(PaintingStrategy.LINE);
EMA_Short.SetLineWeight(3);
EMA_Short.AssignValueColor(if KC1>=KC0 then color.lime else color.red);

plot EMA_Long = KC0;
EMA_Long.SetPaintingStrategy(PaintingStrategy.LINE);
EMA_Long.SetLineWeight(3);
EMA_Long.AssignValueColor(if KC1>=KC0 then color.lime else color.red);

AddCloud(EMA_Short, EMA_Long, color.gray, color.gray);
 

barbaros

Administrator
Staff member
There is a problem with this. VXST doesn't load in Thinkorswim.

TradingView:
aF1Rpmy.png


Thinkorswim:
VceIce7.png
 
This might be the problem line 18 and line 19 have a 0(zero) after close

input CLOSE0 = 21; # HINT: EMA Close
def KC0 = expAverage(C0, CLOSE0);
 

barbaros

Administrator
Staff member
This might be the problem line 18 and line 19 have a 0(zero) after close

input CLOSE0 = 21; # HINT: EMA Close
def KC0 = expAverage(C0, CLOSE0);
Can’t you name a variable with a number at the end? But, yeah, it’s confusing. However, I don’t think that is the main problem though.
 
I don't know, never see close with a number, without the zero, I get it to display, no Background color and only Cyan, blue and white lines. if it ever works a label would be helpful.
 

barbaros

Administrator
Staff member
Changed, but result is the same. I think it is allowed to have number at the end of a reserved keyword to make it unique. However, issue is what I noted in port #2.


Code:
# Converted for b4indicators.com
# barbaros

declare lower;

input symb1 = "VIXMO";
input symb2 = "VIX3M";
input symb3 = "VVIX";
input symb4 = "VXST";

def MOD1 = close(symbol = symb1);
def MOD2 = close(symbol = symb2);
def MOD3 = close(symbol = symb3);
def MOD4 = close(symbol = symb4);

def C0 = MOD1 * MOD2 * MOD3 * MOD4;

input CL0 = 21; # HINT: EMA Close
def KC0 = expAverage(C0, CL0);

plot LongEMA_close = KC0;
LongEMA_close.SetPaintingStrategy(PaintingStrategy.LINE);
LongEMA_close.SetLineWeight(2);
LongEMA_close.SetDefaultColor(color.orange);

input CL1 = 8; # HINT: shortEMA Close
def KC1 = expAverage(C0, CL1);

plot shortEMA_close = KC1;
shortEMA_close.SetPaintingStrategy(PaintingStrategy.LINE);
shortEMA_close.SetLineWeight(2);
shortEMA_close.SetDefaultColor(color.blue);

input EnableBackgroundColor = yes;
AssignBackgroundColor(if EnableBackgroundColor then
    if C0 < KC1 then color.orange else color.black
    else Color.CURRENT
);

plot C0_Line = C0;
LongEMA_close.SetPaintingStrategy(PaintingStrategy.LINE);
LongEMA_close.SetLineWeight(3);
LongEMA_close.SetDefaultColor(color.cyan);

plot EMA_Short = KC1;
EMA_Short.SetPaintingStrategy(PaintingStrategy.LINE);
EMA_Short.SetLineWeight(3);
EMA_Short.AssignValueColor(if KC1>=KC0 then color.lime else color.red);

plot EMA_Long = KC0;
EMA_Long.SetPaintingStrategy(PaintingStrategy.LINE);
EMA_Long.SetLineWeight(3);
EMA_Long.AssignValueColor(if KC1>=KC0 then color.lime else color.red);

AddCloud(EMA_Short, EMA_Long, color.gray, color.gray);
 
Top