T

#### theloneytrader

##### New member

Hi Hi, first time here.

Been reading through and have not yet found anything dealing with how to edit code to work after thinkorswim changed their futures symbol taxonomy. Code is posted below the tear-line. Can someone help a brother out? I've tried but cannot seem to make it work.

----------------------------------------

Been reading through and have not yet found anything dealing with how to edit code to work after thinkorswim changed their futures symbol taxonomy. Code is posted below the tear-line. Can someone help a brother out? I've tried but cannot seem to make it work.

----------------------------------------

Code:

```
# Display Contango relationship between the Front and Back Month VX futures
#wizard text: Inputs: flavor: 0: commulative value, 1: relative commulative difference, 2: absolute difference
input bubles = 0;
input flavor = 3; # 0 for cumulative value, #1 for relative difference with respect to Front month, 2 for absolute difference.
# 3, for Contango % thresholds, from (BM-FM)*100/FM.
input Threshold_shortVol = 6.77;
input Threshold_longVol = 2.90;
declare lower;
#hidepriceplot(close);
#hide();
# Below flags the date for expiring Front Month VX futures per CBOE specs
# Note: Regarding the Holidays, only one occurrence since 2010, which is
# hard coded in line below.
# For some unknown reason, TOS does not respond to daily VX futures per
# specification before August 2010, so data seems valid after Aug 2010
# In debugging observed TOS sometimes misses
# complete trading days, the "/VX" reference in TOS does not
# match the CBOE spec for settlement and TOS "opportunities"
# seem to be dynamic (not static bugs)
# TOS inferred no trading of "/VX" between 7/16/2013 and 7/22/2016. (Missing 3 days of trading)
script VXexp {
def date = GetYYYYMMDD();
def isholiday = date == 20140319; # Manual injection of holiday on 4/18/14 which alters VX settlement date in March.
def n3rdfa = Next3rdFriday(1);
def n3rdfb = Next3rdFriday(2);
def n3rdf = if (n3rdfa < 4) then n3rdfb else n3rdfa; # Pick Next month's expiration, not this month.
plot VXexp = if (isholiday) then 1 else ((n3rdf == 30) and !isholiday[1]);#and (dow == 3);
} # End of script for VXexp
# LsD extracts least significant digit of the number (date)
script LsD {
input date = 20100101;
plot LsD = (date - RoundDown(date / 10, 0) * 10);
} # End of script for LsD
def InContango;
def NotContango;
def ContangoBias;
def fm;
def bm;
def date = GetYYYYMMDD();
def dom = GetDayOfMonth(date);
def newmo = dom < dom[1];
def incmo = if newmo then 0 else if VXexp() then 1 else incmo[1];
def Y_ = GetYear();
def Y = LsD(Y_);
def MM = GetMonth();
fm = if (MM + incmo) > 12 then 1 else (MM + incmo) ;
def fmchange = fm != fm[1];
def fmY = if fmchange then (if (MM + incmo) > 12 then LsD(Y + 1) else Y) else fmY[1];
bm = if (fm + 1) > 12 then 1 else (fm + 1) ;
def bmY = if fmchange then (if (bm < 3) then LsD(Y + 1) else Y) else bmY[1];
def fmp = close( "/VX" + (if fm == 1 then "F" else
if fm == 2 then "G" else
if fm == 3 then "H" else
if fm == 4 then "J" else
if fm == 5 then "K" else
if fm == 6 then "M" else
if fm == 7 then "N" else
if fm == 8 then "Q" else
if fm == 9 then "U" else
if fm == 10 then "V" else
if fm == 11 then "X" else
if fm == 12 then "Z" else " ") + fmY);
def bmp = close( "/VX" + (if bm == 1 then "F" else
if bm == 2 then "G" else
if bm == 3 then "H" else
if bm == 4 then "J" else
if bm == 5 then "K" else
if bm == 6 then "M" else
if bm == 7 then "N" else
if bm == 8 then "Q" else
if bm == 9 then "U" else
if bm == 10 then "V" else
if bm == 11 then "X" else
if bm == 12 then "Z" else " ") + bmY);
# TOS may miss some vx futures quotes, so if this occurs
# re-use the prior day close for the missing entry.
# The filter below accomplishes this.
def fmpfiltered = if IsNaN(fmp) then fmpfiltered[1] else fmp;
def bmpfiltered = if IsNaN(bmp) then bmpfiltered[1] else bmp;
def reladj = if (bmpfiltered > 0) then bmpfiltered else 1;
#def fmpfiltered = if isnan(fmp) then if (fmpfiltered[1]>0) then fmpfiltered[1] else double.nan else fmp;
#def bmpfiltered = if isnan(bmp) then if (bmpfiltered[1]>0) then bmpfiltered[1] else double.nan else bmp;
def AbsDiffContango = if (BarNumber() < 5) then 0 else (if (flavor == 1) then (bmpfiltered - fmpfiltered) / reladj else (bmpfiltered - fmpfiltered));
ContangoBias = if (BarNumber() < 5) then 0 else ContangoBias[1] + (if (flavor == 1) then (bmpfiltered - fmpfiltered) / reladj else (bmpfiltered - fmpfiltered));
plot FmBmContango = if IsNaN(fmp) then Double.NaN else if (flavor == 2) then
AbsDiffContango else if (flavor == 3) then Double.NaN else ContangoBias;
def ContangoPerCentage = 100 * AbsDiffContango / fmpfiltered;
FmBmContango.DefineColor("green", Color.GREEN);
FmBmContango.DefineColor("red", Color.RED);
FmBmContango.DefineColor("white", Color.WHITE);
plot Cper = if ((flavor == 3) and (IsNaN(fmp) == 0)) then ContangoPerCentage else Double.NaN;
Cper.DefineColor("green", Color.GREEN);
Cper.DefineColor("red", Color.RED);
Cper.DefineColor("white", Color.WHITE);
Cper.AssignValueColor(if (ContangoPerCentage > Threshold_shortVol) then Cper.Color("green") else if (ContangoPerCentage > Threshold_longVol) then Cper.Color("white") else Cper.Color("red"));
Cper.SetPaintingStrategy(PaintingStrategy.POINTS);
def Direction = ContangoBias > ContangoBias[1];
def DirectionChanges = if (BarNumber() == 1) then 0 else if (Direction != Direction[1]) then DirectionChanges[1] + 1 else DirectionChanges[1];
FmBmContango.AssignValueColor(if (ContangoBias > ContangoBias[1]) then FmBmContango.Color("green") else if (ContangoBias == ContangoBias[1]) then FmBmContango.Color("white") else FmBmContango.Color("red"));
FmBmContango.SetPaintingStrategy(PaintingStrategy.POINTS);
InContango = if ((BarNumber() == 1) or (DirectionChanges < 1)) then 0 else InContango[1] + (bmpfiltered > fmpfiltered);
NotContango = if ((BarNumber() == 1) or (DirectionChanges < 1)) then 0 else NotContango[1] + (bmpfiltered <= fmpfiltered);
plot UpperThreshold = if (flavor == 3) then Threshold_shortVol else Double.NaN;
plot LowerThreshold = if (flavor == 3) then Threshold_longVol else Double.NaN;
AddChartBubble(bubles and Direction and !Direction[1], ContangoBias, DirectionChanges, Color.GRAY, 1);
AddChartBubble(bubles and !Direction and Direction[1], ContangoBias, DirectionChanges, Color.YELLOW, 0);
AddVerticalLine(VXexp(), "VX" + (if bm == 1 then "F" else
if bm == 2 then "G" else
if bm == 3 then "H" else
if bm == 4 then "J" else
if bm == 5 then "K" else
if bm == 6 then "M" else
if bm == 7 then "N" else
if bm == 8 then "Q" else
if bm == 9 then "U" else
if bm == 10 then "V" else
if bm == 11 then "X" else
if bm == 12 then "Z" else " ") + bmY
+ " - VX" + (if fm == 1 then "F" else
if fm == 2 then "G" else
if fm == 3 then "H" else
if fm == 4 then "J" else
if fm == 5 then "K" else
if fm == 6 then "M" else
if fm == 7 then "N" else
if fm == 8 then "Q" else
if fm == 9 then "U" else
if fm == 10 then "V" else
if fm == 11 then "X" else
if fm == 12 then "Z" else " ") + fmY, Color.DARK_GREEN);#color.light_orange);
```

Last edited by a moderator: