Option Heatmap and OI Strikes For ThinkOrSwim

# TS_OptionVolumeHeatmap
# (c) 2013 ThinkScripter, LLC
# http://www.thinkscripter.com
# [email protected]
# Last Update 23 April 2013
# Next3rdFriday code (c) thinkorswim


declare lower;

input period = 20;
input gain = 1.0;
input calculation_voodoo = {default a, b};

# Next3rdFriday excerpt
input series = 1;
input show_label = yes;

def CurrentYear = GetYear();
def CurrentMonth = GetMonth();
def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());

def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1);
def FirstFridayDOM1 = if Day1DOW1 < 6
then 6 - Day1DOW1
else if Day1DOW1 == 6
then 7
else 6;
def RollDOM = FirstFridayDOM1 + 14;
def ExpMonth1 = if RollDOM > CurrentDOM
then CurrentMonth + series - 1
else CurrentMonth + series;
def ExpMonth2 = if ExpMonth1 > 12
then ExpMonth1 - 12
else ExpMonth1;
def ExpYear = if ExpMonth1 > 12
then CurrentYear + 1
else CurrentYear;
def Day1DOW = GetDayOfWeek(ExpYear * 10000 + ExpMonth2 * 100 + 1);
def FirstFridayDOM = if Day1DOW < 6
then 6 - Day1DOW
else if Day1DOW == 6
then 7
else 6;
def ExpDOM = FirstFridayDOM + 15;


def maxStrikeSpacing = 25;
def centerSpacingDenominator = if close > 150 then 10 else if close > 50 then 5 else 1;

def centerStrike = RoundDown(close / centerSpacingDenominator, 0) * centerSpacingDenominator;
def strikeSpacingC = fold i = 1 to maxStrikeSpacing with spacing = 0 do if !IsNaN( volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + (maxStrikeSpacing - i)))))) then maxStrikeSpacing - i else spacing;

def strikeSpacing = strikeSpacingC ;

AddLabel(show_label, Concat("Expiration: ", Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM))), Color.WHITE);
AddLabel(show_label, Concat("Strike Spacing: ", strikeSpacing), Color.CYAN);


DefineGlobalColor("L10", CreateColor(255, 255, 0));
DefineGlobalColor("L09", CreateColor(255, 204, 0));
DefineGlobalColor("L08", CreateColor(255, 153, 0));
DefineGlobalColor("L07", CreateColor(255, 102, 0));
DefineGlobalColor("L06", CreateColor(255, 51, 0));
DefineGlobalColor("L05", CreateColor(255, 0, 0));
DefineGlobalColor("L04", CreateColor(204, 0, 0));
DefineGlobalColor("L03", CreateColor(153, 0, 0));
DefineGlobalColor("L02", CreateColor( 51, 0, 0));
DefineGlobalColor("L01", CreateColor( 0, 0, 0));

DefineGlobalColor("H10", CreateColor(0, 255, 255));
DefineGlobalColor("H09", CreateColor(0, 204, 255));
DefineGlobalColor("H08", CreateColor(0, 153, 255));
DefineGlobalColor("H07", CreateColor(0, 102, 255));
DefineGlobalColor("H06", CreateColor(0, 51, 255));
DefineGlobalColor("H05", CreateColor(0, 0, 255));
DefineGlobalColor("H04", CreateColor(0, 0, 204));
DefineGlobalColor("H03", CreateColor(0, 0, 153));
DefineGlobalColor("H02", CreateColor(0, 0, 51));
DefineGlobalColor("H01", CreateColor(0, 0, 0));

def barWeight = 5;

def c1_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike ))));
def c2_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing))));
def c3_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 2))));
def c4_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 3))));
def c5_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing))));
def c6_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 2))));
def c7_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 3))));
def c8_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 4))));
def c9_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 4))));
def c10_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 5))));
def c11_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 5))));

def c12_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 6))));
def c13_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 6))));
def c14_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 7))));
def c15_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 7))));
def c16_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 8))));
def c17_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 8))));
def c18_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike - strikeSpacing * 9))));
def c19_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("C", AsPrice(centerStrike + strikeSpacing * 9))));

def p1_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike))));
def p2_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing))));
def p3_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 2))));
def p4_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 3))));
def p5_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing))));
def p6_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 2))));
def p7_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 3))));
def p8_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 4))));
def p9_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 4))));
def p10_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 5))));
def p11_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 5))));

def p12_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 6))));
def p13_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 6))));
def p14_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 7))));
def p15_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 7))));
def p16_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 8))));
def p17_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 8))));
def p18_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike - strikeSpacing * 9))));
def p19_V_d = volume(Concat(Concat(".", Concat(GetSymbolPart(), Concat(Concat(ExpYear - 2000, if ExpMonth2 <= 9 then Concat("0", ExpMonth2) else Concat("", ExpMonth2)), if ExpDOM <= 9 then Concat("0", ExpDOM) else Concat("", ExpDOM)))), Concat("P", AsPrice(centerStrike + strikeSpacing * 9))));

def c1_V = if !IsNaN(c1_V_d) then c1_V_d else 0;
def c2_V = if !IsNaN(c2_V_d) then c2_V_d else 0;
def c3_V = if !IsNaN(c3_V_d) then c3_V_d else 0;
def c4_V = if !IsNaN(c4_V_d) then c4_V_d else 0;
def c5_V = if !IsNaN(c5_V_d) then c5_V_d else 0;
def c6_V = if !IsNaN(c6_V_d) then c6_V_d else 0;
def c7_V = if !IsNaN(c7_V_d) then c7_V_d else 0;
def c8_V = if !IsNaN(c8_V_d) then c8_V_d else 0;
def c9_V = if !IsNaN(c9_V_d) then c9_V_d else 0;
def c10_V = if !IsNaN(c10_V_d) then c10_V_d else 0;
def c11_V = if !IsNaN(c11_V_d) then c11_V_d else 0;

def c12_V = if !IsNaN(c12_V_d) then c12_V_d else 0;
def c13_V = if !IsNaN(c13_V_d) then c13_V_d else 0;
def c14_V = if !IsNaN(c14_V_d) then c14_V_d else 0;
def c15_V = if !IsNaN(c15_V_d) then c15_V_d else 0;
def c16_V = if !IsNaN(c16_V_d) then c16_V_d else 0;
def c17_V = if !IsNaN(c17_V_d) then c17_V_d else 0;
def c18_V = if !IsNaN(c18_V_d) then c18_V_d else 0;
def c19_V = if !IsNaN(c19_V_d) then c19_V_d else 0;

def p1_V = if !IsNaN(p1_V_d) then p1_V_d else 0;
def p2_V = if !IsNaN(p2_V_d) then p2_V_d else 0;
def p3_V = if !IsNaN(p3_V_d) then p3_V_d else 0;
def p4_V = if !IsNaN(p4_V_d) then p4_V_d else 0;
def p5_V = if !IsNaN(p5_V_d) then p5_V_d else 0;
def p6_V = if !IsNaN(p6_V_d) then p6_V_d else 0;
def p7_V = if !IsNaN(p7_V_d) then p7_V_d else 0;
def p8_V = if !IsNaN(p8_V_d) then p8_V_d else 0;
def p9_V = if !IsNaN(p9_V_d) then p9_V_d else 0;
def p10_V = if !IsNaN(p10_V_d) then p10_V_d else 0;
def p11_V = if !IsNaN(p11_V_d) then p11_V_d else 0;

def p12_V = if !IsNaN(p12_V_d) then p12_V_d else 0;
def p13_V = if !IsNaN(p13_V_d) then p13_V_d else 0;
def p14_V = if !IsNaN(p14_V_d) then p14_V_d else 0;
def p15_V = if !IsNaN(p15_V_d) then p15_V_d else 0;
def p16_V = if !IsNaN(p16_V_d) then p16_V_d else 0;
def p17_V = if !IsNaN(p17_V_d) then p17_V_d else 0;
def p18_V = if !IsNaN(p18_V_d) then p18_V_d else 0;
def p19_V = if !IsNaN(p19_V_d) then p19_V_d else 0;

def c1t = Max(Max(Max(Max(c1_V, c2_V), c3_V), c4_V), c5_V);
def c2t = Max(Max(Max(Max(Max(c6_V, c7_V), c8_V), c9_V), c10_V), c11_V);

def c3t = Max(Max(Max(Max(Max(c12_V, c13_V), c14_V), c15_V), c16_V), c17_V);
def c4t = Max(c18_V, c19_V);

def p1t = Max(Max(Max(Max(p1_V, p2_V), p3_V), p4_V), p5_V);
def p2t = Max(Max(Max(Max(Max(p6_V, p7_V), p8_V), p9_V), p10_V), p11_V);

def p3t = Max(Max(Max(Max(Max(p12_V, p13_V), p14_V), p15_V), p16_V), p17_V);
def p4t = Max(p18_V, p19_V);


def c_V_max = Max(Max(Max(c1t, c2t), c3t), c4t);
def p_V_max = Max(Max(Max(p1t, p2t), p3t), p4t);
def V_max = c_V_max + p_V_max;

def cVT = c1_V + c2_V + c3_V + c4_V + c5_V + c6_V + c7_V + c8_V + c9_V + c10_V + c11_V + c12_V + c13_V + c14_V + c15_V + c16_V + c17_V + c18_V + c19_V;

def cVTt = c1_V + c2_V + c3_V + c4_V + c5_V + c6_V + c7_V + c8_V + c9_V;

def pVT = p1_V + p2_V + p3_V + p4_V + p5_V + p6_V + p7_V + p8_V + p9_V + p10_V + p11_V + p12_V + p13_V + p14_V + p15_V + p16_V + p17_V + p18_V + p19_V;

def tVT = cVT + pVT;
def oVT = if calculation_voodoo == calculation_voodoo.a then Average(V_max, period) else Average(tVT, period);

def c1RS = (c1_V / oVT) * 10.0 * gain;
def c2RS = (c2_V / oVT) * 10.0 * gain;
def c3RS = (c3_V / oVT) * 10.0 * gain;
def c4RS = (c4_V / oVT) * 10.0 * gain;
def c5RS = (c5_V / oVT) * 10.0 * gain;
def c6RS = (c6_V / oVT) * 10.0 * gain;
def c7RS = (c7_V / oVT) * 10.0 * gain;
def c8RS = (c8_V / oVT) * 10.0 * gain;
def c9RS = (c9_V / oVT) * 10.0 * gain;
def c10RS = (c10_V / oVT) * 10.0 * gain;
def c11RS = (c11_V / oVT) * 10.0 * gain;
def c12RS = (c12_V / oVT) * 10.0 * gain;
def c13RS = (c13_V / oVT) * 10.0 * gain;
def c14RS = (c14_V / oVT) * 10.0 * gain;
def c15RS = (c15_V / oVT) * 10.0 * gain;
def c16RS = (c16_V / oVT) * 10.0 * gain;
def c17RS = (c17_V / oVT) * 10.0 * gain;
def c18RS = (c18_V / oVT) * 10.0 * gain;
def c19RS = (c19_V / oVT) * 10.0 * gain;

def p1RS = (p1_V / oVT) * 10.0 * gain;
def p2RS = (p2_V / oVT) * 10.0 * gain;
def p3RS = (p3_V / oVT) * 10.0 * gain;
def p4RS = (p4_V / oVT) * 10.0 * gain;
def p5RS = (p5_V / oVT) * 10.0 * gain;
def p6RS = (p6_V / oVT) * 10.0 * gain;
def p7RS = (p7_V / oVT) * 10.0 * gain;
def p8RS = (p8_V / oVT) * 10.0 * gain;
def p9RS = (p9_V / oVT) * 10.0 * gain;
def p10RS = (p10_V / oVT) * 10.0 * gain;
def p11RS = (p11_V / oVT) * 10.0 * gain;
def p12RS = (p12_V / oVT) * 10.0 * gain;
def p13RS = (p13_V / oVT) * 10.0 * gain;
def p14RS = (p14_V / oVT) * 10.0 * gain;
def p15RS = (p15_V / oVT) * 10.0 * gain;
def p16RS = (p16_V / oVT) * 10.0 * gain;
def p17RS = (p17_V / oVT) * 10.0 * gain;
def p18RS = (p18_V / oVT) * 10.0 * gain;
def p19RS = (p19_V / oVT) * 10.0 * gain;


def o1RS = Max(c1RS, p1RS);
def o1M = if c1RS > p1RS then 1 else 0;
def o2RS = Max(c2RS, p2RS);
def o2M = if c2RS > p2RS then 1 else 0;
def o3RS = Max(c3RS, p3RS);
def o3M = if c3RS > p3RS then 1 else 0;
def o4RS = Max(c4RS, p4RS);
def o4M = if c4RS > p4RS then 1 else 0;
def o5RS = Max(c5RS, p5RS);
def o5M = if c5RS > p5RS then 1 else 0;
def o6RS = Max(c6RS, p6RS);
def o6M = if c6RS > p6RS then 1 else 0;
def o7RS = Max(c7RS, p7RS);
def o7M = if c7RS > p7RS then 1 else 0;
def o8RS = Max(c8RS, p8RS);
def o8M = if c8RS > p8RS then 1 else 0;
def o9RS = Max(c9RS, p9RS);
def o9M = if c9RS > p9RS then 1 else 0;
def o10RS = Max(c10RS, p10RS);
def o10M = if c10RS > p10RS then 1 else 0;
def o11RS = Max(c11RS, p11RS);
def o11M = if c11RS > p11RS then 1 else 0;
def o12RS = Max(c12RS, p12RS);
def o12M = if c12RS > p12RS then 1 else 0;
def o13RS = Max(c13RS, p13RS);
def o13M = if c13RS > p13RS then 1 else 0;
def o14RS = Max(c14RS, p14RS);
def o14M = if c14RS > p14RS then 1 else 0;
def o15RS = Max(c15RS, p15RS);
def o15M = if c15RS > p15RS then 1 else 0;
def o16RS = Max(c16RS, p16RS);
def o16M = if c16RS > p16RS then 1 else 0;
def o17RS = Max(c17RS, p17RS);
def o17M = if c17RS > p17RS then 1 else 0;
def o18RS = Max(c18RS, p18RS);
def o18M = if c18RS > p18RS then 1 else 0;
def o19RS = Max(c19RS, p19RS);
def o19M = if c19RS > p19RS then 1 else 0;

plot price = close;

plot C1 = centerStrike ;
C1.SetLineWeight(5);
C1.SetDefaultColor(Color.BLACK);
C1.AssignValueColor(if o1M == 1 then (if o1RS <= 1 then GlobalColor("L01") else if o1RS <= 2 then GlobalColor("L02") else if o1RS <= 3 then GlobalColor("L03") else if o1RS <= 4 then GlobalColor("L04") else if o1RS <= 5 then GlobalColor("L05") else if o1RS <= 6 then GlobalColor("L06") else if o1RS <= 7 then GlobalColor("L07") else if o1RS <= 8 then GlobalColor("L08") else if o1RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o1RS <= 1 then GlobalColor("H01") else if o1RS <= 2 then GlobalColor("H02") else if o1RS <= 3 then GlobalColor("H03") else if o1RS <= 4 then GlobalColor("H04") else if o1RS <= 5 then GlobalColor("H05") else if o1RS <= 6 then GlobalColor("H06") else if o1RS <= 7 then GlobalColor("H07") else if o1RS <= 8 then GlobalColor("H08") else if o1RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C2 = centerStrike - strikeSpacing;
C2.SetLineWeight(5);
C2.SetDefaultColor(Color.BLACK);
C2.AssignValueColor(if o2M == 1 then (if o2RS <= 1 then GlobalColor("L01") else if o2RS <= 2 then GlobalColor("L02") else if o2RS <= 3 then GlobalColor("L03") else if o2RS <= 4 then GlobalColor("L04") else if o2RS <= 5 then GlobalColor("L05") else if o2RS <= 6 then GlobalColor("L06") else if o2RS <= 7 then GlobalColor("L07") else if o2RS <= 8 then GlobalColor("L08") else if o2RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o2RS <= 1 then GlobalColor("H01") else if o2RS <= 2 then GlobalColor("H02") else if o2RS <= 3 then GlobalColor("H03") else if o2RS <= 4 then GlobalColor("H04") else if o2RS <= 5 then GlobalColor("H05") else if o2RS <= 6 then GlobalColor("H06") else if o2RS <= 7 then GlobalColor("H07") else if o2RS <= 8 then GlobalColor("H08") else if o2RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));


plot C3 = centerStrike - strikeSpacing * 2;
C3.SetLineWeight(5);
C3.SetDefaultColor(Color.BLACK);
C3.AssignValueColor(if o3M == 1 then (if o3RS <= 1 then GlobalColor("L01") else if o3RS <= 2 then GlobalColor("L02") else if o3RS <= 3 then GlobalColor("L03") else if o3RS <= 4 then GlobalColor("L04") else if o3RS <= 5 then GlobalColor("L05") else if o3RS <= 6 then GlobalColor("L06") else if o3RS <= 7 then GlobalColor("L07") else if o3RS <= 8 then GlobalColor("L08") else if o3RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o3RS <= 1 then GlobalColor("H01") else if o3RS <= 2 then GlobalColor("H02") else if o3RS <= 3 then GlobalColor("H03") else if o3RS <= 4 then GlobalColor("H04") else if o3RS <= 5 then GlobalColor("H05") else if o3RS <= 6 then GlobalColor("H06") else if o3RS <= 7 then GlobalColor("H07") else if o3RS <= 8 then GlobalColor("H08") else if o3RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C4 = centerStrike - strikeSpacing * 3;
C4.SetLineWeight(5);
C4.SetDefaultColor(Color.BLACK);
C4.AssignValueColor(if o4M == 1 then (if o4RS <= 1 then GlobalColor("L01") else if o4RS <= 2 then GlobalColor("L02") else if o4RS <= 3 then GlobalColor("L03") else if o4RS <= 4 then GlobalColor("L04") else if o4RS <= 5 then GlobalColor("L05") else if o4RS <= 6 then GlobalColor("L06") else if o4RS <= 7 then GlobalColor("L07") else if o4RS <= 8 then GlobalColor("L08") else if o4RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o4RS <= 1 then GlobalColor("H01") else if o4RS <= 2 then GlobalColor("H02") else if o4RS <= 3 then GlobalColor("H03") else if o4RS <= 4 then GlobalColor("H04") else if o4RS <= 5 then GlobalColor("H05") else if o4RS <= 6 then GlobalColor("H06") else if o4RS <= 7 then GlobalColor("H07") else if o4RS <= 8 then GlobalColor("H08") else if o4RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));


plot C5 = centerStrike + strikeSpacing;
C5.SetLineWeight(5);
C5.SetDefaultColor(Color.BLACK);
C5.AssignValueColor(if o5M == 1 then (if o5RS <= 1 then GlobalColor("L01") else if o5RS <= 2 then GlobalColor("L02") else if o5RS <= 3 then GlobalColor("L03") else if o5RS <= 4 then GlobalColor("L04") else if o5RS <= 5 then GlobalColor("L05") else if o5RS <= 6 then GlobalColor("L06") else if o5RS <= 7 then GlobalColor("L07") else if o5RS <= 8 then GlobalColor("L08") else if o5RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o5RS <= 1 then GlobalColor("H01") else if o5RS <= 2 then GlobalColor("H02") else if o5RS <= 3 then GlobalColor("H03") else if o5RS <= 4 then GlobalColor("H04") else if o5RS <= 5 then GlobalColor("H05") else if o5RS <= 6 then GlobalColor("H06") else if o5RS <= 7 then GlobalColor("H07") else if o5RS <= 8 then GlobalColor("H08") else if o5RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C6 = centerStrike + strikeSpacing * 2;
C6.SetLineWeight(5);
C6.SetDefaultColor(Color.BLACK);

C6.AssignValueColor(if o6M == 1 then (if o6RS <= 1 then GlobalColor("L01") else if o6RS <= 2 then GlobalColor("L02") else if o6RS <= 3 then GlobalColor("L03") else if o6RS <= 4 then GlobalColor("L04") else if o6RS <= 5 then GlobalColor("L05") else if o6RS <= 6 then GlobalColor("L06") else if o6RS <= 7 then GlobalColor("L07") else if o6RS <= 8 then GlobalColor("L08") else if o6RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o6RS <= 1 then GlobalColor("H01") else if o6RS <= 2 then GlobalColor("H02") else if o6RS <= 3 then GlobalColor("H03") else if o6RS <= 4 then GlobalColor("H04") else if o6RS <= 5 then GlobalColor("H05") else if o6RS <= 6 then GlobalColor("H06") else if o6RS <= 7 then GlobalColor("H07") else if o6RS <= 8 then GlobalColor("H08") else if o6RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C7 = centerStrike + strikeSpacing * 3;
C7.SetLineWeight(5);
C7.SetDefaultColor(Color.BLACK);

C7.AssignValueColor(if o7M == 1 then (if o7RS <= 1 then GlobalColor("L01") else if o7RS <= 2 then GlobalColor("L02") else if o7RS <= 3 then GlobalColor("L03") else if o7RS <= 4 then GlobalColor("L04") else if o7RS <= 5 then GlobalColor("L05") else if o7RS <= 6 then GlobalColor("L06") else if o7RS <= 7 then GlobalColor("L07") else if o7RS <= 8 then GlobalColor("L08") else if o7RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o7RS <= 1 then GlobalColor("H01") else if o7RS <= 2 then GlobalColor("H02") else if o7RS <= 3 then GlobalColor("H03") else if o7RS <= 4 then GlobalColor("H04") else if o7RS <= 5 then GlobalColor("H05") else if o7RS <= 6 then GlobalColor("H06") else if o7RS <= 7 then GlobalColor("H07") else if o7RS <= 8 then GlobalColor("H08") else if o7RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C8 = centerStrike - strikeSpacing * 4;
C8.SetLineWeight(5);
C8.SetDefaultColor(Color.BLACK);

C8.AssignValueColor(if o8M == 1 then (if o8RS <= 1 then GlobalColor("L01") else if o8RS <= 2 then GlobalColor("L02") else if o8RS <= 3 then GlobalColor("L03") else if o8RS <= 4 then GlobalColor("L04") else if o8RS <= 5 then GlobalColor("L05") else if o8RS <= 6 then GlobalColor("L06") else if o8RS <= 7 then GlobalColor("L07") else if o8RS <= 8 then GlobalColor("L08") else if o8RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o8RS <= 1 then GlobalColor("H01") else if o8RS <= 2 then GlobalColor("H02") else if o8RS <= 3 then GlobalColor("H03") else if o8RS <= 4 then GlobalColor("H04") else if o8RS <= 5 then GlobalColor("H05") else if o8RS <= 6 then GlobalColor("H06") else if o8RS <= 7 then GlobalColor("H07") else if o8RS <= 8 then GlobalColor("H08") else if o8RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C9 = centerStrike + strikeSpacing * 4;
C9.SetLineWeight(5);
C9.SetDefaultColor(Color.BLACK);

C9.AssignValueColor(if o9M == 1 then (if o9RS <= 1 then GlobalColor("L01") else if o9RS <= 2 then GlobalColor("L02") else if o9RS <= 3 then GlobalColor("L03") else if o9RS <= 4 then GlobalColor("L04") else if o9RS <= 5 then GlobalColor("L05") else if o9RS <= 6 then GlobalColor("L06") else if o9RS <= 7 then GlobalColor("L07") else if o9RS <= 8 then GlobalColor("L08") else if o9RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o9RS <= 1 then GlobalColor("H01") else if o9RS <= 2 then GlobalColor("H02") else if o9RS <= 3 then GlobalColor("H03") else if o9RS <= 4 then GlobalColor("H04") else if o9RS <= 5 then GlobalColor("H05") else if o9RS <= 6 then GlobalColor("H06") else if o9RS <= 7 then GlobalColor("H07") else if o9RS <= 8 then GlobalColor("H08") else if o9RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C10 = centerStrike - strikeSpacing * 5;
C10.SetLineWeight(5);
C10.SetDefaultColor(Color.BLACK);

C10.AssignValueColor(if o10M == 1 then (if o10RS <= 1 then GlobalColor("L01") else if o10RS <= 2 then GlobalColor("L02") else if o10RS <= 3 then GlobalColor("L03") else if o10RS <= 4 then GlobalColor("L04") else if o10RS <= 5 then GlobalColor("L05") else if o10RS <= 6 then GlobalColor("L06") else if o10RS <= 7 then GlobalColor("L07") else if o10RS <= 8 then GlobalColor("L08") else if o10RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o10RS <= 1 then GlobalColor("H01") else if o10RS <= 2 then GlobalColor("H02") else if o10RS <= 3 then GlobalColor("H03") else if o10RS <= 4 then GlobalColor("H04") else if o10RS <= 5 then GlobalColor("H05") else if o10RS <= 6 then GlobalColor("H06") else if o10RS <= 7 then GlobalColor("H07") else if o10RS <= 8 then GlobalColor("H08") else if o10RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C11 = centerStrike + strikeSpacing * 4;
C11.SetLineWeight(5);
C11.SetDefaultColor(Color.BLACK);

C11.AssignValueColor(if o11M == 1 then (if o11RS <= 1 then GlobalColor("L01") else if o11RS <= 2 then GlobalColor("L02") else if o11RS <= 3 then GlobalColor("L03") else if o11RS <= 4 then GlobalColor("L04") else if o11RS <= 5 then GlobalColor("L05") else if o11RS <= 6 then GlobalColor("L06") else if o11RS <= 7 then GlobalColor("L07") else if o11RS <= 8 then GlobalColor("L08") else if o11RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o11RS <= 1 then GlobalColor("H01") else if o11RS <= 2 then GlobalColor("H02") else if o11RS <= 3 then GlobalColor("H03") else if o11RS <= 4 then GlobalColor("H04") else if o11RS <= 5 then GlobalColor("H05") else if o11RS <= 6 then GlobalColor("H06") else if o11RS <= 7 then GlobalColor("H07") else if o11RS <= 8 then GlobalColor("H08") else if o11RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));


plot C12 = centerStrike - strikeSpacing * 6;
C12.SetLineWeight(5);
C12.SetDefaultColor(Color.BLACK);

C12.AssignValueColor(if o12M == 1 then (if o12RS <= 1 then GlobalColor("L01") else if o12RS <= 2 then GlobalColor("L02") else if o12RS <= 3 then GlobalColor("L03") else if o12RS <= 4 then GlobalColor("L04") else if o12RS <= 5 then GlobalColor("L05") else if o12RS <= 6 then GlobalColor("L06") else if o12RS <= 7 then GlobalColor("L07") else if o12RS <= 8 then GlobalColor("L08") else if o12RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o12RS <= 1 then GlobalColor("H01") else if o12RS <= 2 then GlobalColor("H02") else if o12RS <= 3 then GlobalColor("H03") else if o12RS <= 4 then GlobalColor("H04") else if o12RS <= 5 then GlobalColor("H05") else if o12RS <= 6 then GlobalColor("H06") else if o12RS <= 7 then GlobalColor("H07") else if o12RS <= 8 then GlobalColor("H08") else if o12RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C13 = centerStrike + strikeSpacing * 6;
C13.SetLineWeight(5);
C13.SetDefaultColor(Color.BLACK);

C13.AssignValueColor(if o13M == 1 then (if o13RS <= 1 then GlobalColor("L01") else if o13RS <= 2 then GlobalColor("L02") else if o13RS <= 3 then GlobalColor("L03") else if o13RS <= 4 then GlobalColor("L04") else if o13RS <= 5 then GlobalColor("L05") else if o13RS <= 6 then GlobalColor("L06") else if o13RS <= 7 then GlobalColor("L07") else if o13RS <= 8 then GlobalColor("L08") else if o13RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o13RS <= 1 then GlobalColor("H01") else if o13RS <= 2 then GlobalColor("H02") else if o13RS <= 3 then GlobalColor("H03") else if o13RS <= 4 then GlobalColor("H04") else if o13RS <= 5 then GlobalColor("H05") else if o13RS <= 6 then GlobalColor("H06") else if o13RS <= 7 then GlobalColor("H07") else if o13RS <= 8 then GlobalColor("H08") else if o13RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C14 = centerStrike - strikeSpacing * 7;
C14.SetLineWeight(5);
C14.SetDefaultColor(Color.BLACK);

C14.AssignValueColor(if o14M == 1 then (if o14RS <= 1 then GlobalColor("L01") else if o14RS <= 2 then GlobalColor("L02") else if o14RS <= 3 then GlobalColor("L03") else if o14RS <= 4 then GlobalColor("L04") else if o14RS <= 5 then GlobalColor("L05") else if o14RS <= 6 then GlobalColor("L06") else if o14RS <= 7 then GlobalColor("L07") else if o14RS <= 8 then GlobalColor("L08") else if o14RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o14RS <= 1 then GlobalColor("H01") else if o14RS <= 2 then GlobalColor("H02") else if o14RS <= 3 then GlobalColor("H03") else if o14RS <= 4 then GlobalColor("H04") else if o14RS <= 5 then GlobalColor("H05") else if o14RS <= 6 then GlobalColor("H06") else if o14RS <= 7 then GlobalColor("H07") else if o14RS <= 8 then GlobalColor("H08") else if o14RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C15 = centerStrike + strikeSpacing * 7;
C15.SetLineWeight(5);
C15.SetDefaultColor(Color.BLACK);

C15.AssignValueColor(if o15M == 1 then (if o15RS <= 1 then GlobalColor("L01") else if o15RS <= 2 then GlobalColor("L02") else if o15RS <= 3 then GlobalColor("L03") else if o15RS <= 4 then GlobalColor("L04") else if o15RS <= 5 then GlobalColor("L05") else if o15RS <= 6 then GlobalColor("L06") else if o15RS <= 7 then GlobalColor("L07") else if o15RS <= 8 then GlobalColor("L08") else if o15RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o15RS <= 1 then GlobalColor("H01") else if o15RS <= 2 then GlobalColor("H02") else if o15RS <= 3 then GlobalColor("H03") else if o15RS <= 4 then GlobalColor("H04") else if o15RS <= 5 then GlobalColor("H05") else if o15RS <= 6 then GlobalColor("H06") else if o15RS <= 7 then GlobalColor("H07") else if o15RS <= 8 then GlobalColor("H08") else if o15RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C16 = centerStrike - strikeSpacing * 8;
C16.SetLineWeight(5);
C16.SetDefaultColor(Color.BLACK);

C16.AssignValueColor(if o16M == 1 then (if o16RS <= 1 then GlobalColor("L01") else if o16RS <= 2 then GlobalColor("L02") else if o16RS <= 3 then GlobalColor("L03") else if o16RS <= 4 then GlobalColor("L04") else if o16RS <= 5 then GlobalColor("L05") else if o16RS <= 6 then GlobalColor("L06") else if o16RS <= 7 then GlobalColor("L07") else if o16RS <= 8 then GlobalColor("L08") else if o16RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o16RS <= 1 then GlobalColor("H01") else if o16RS <= 2 then GlobalColor("H02") else if o16RS <= 3 then GlobalColor("H03") else if o16RS <= 4 then GlobalColor("H04") else if o16RS <= 5 then GlobalColor("H05") else if o16RS <= 6 then GlobalColor("H06") else if o16RS <= 7 then GlobalColor("H07") else if o16RS <= 8 then GlobalColor("H08") else if o16RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C17 = centerStrike + strikeSpacing * 8;
C17.SetLineWeight(5);
C17.SetDefaultColor(Color.BLACK);

C17.AssignValueColor(if o17M == 1 then (if o17RS <= 1 then GlobalColor("L01") else if o17RS <= 2 then GlobalColor("L02") else if o17RS <= 3 then GlobalColor("L03") else if o17RS <= 4 then GlobalColor("L04") else if o17RS <= 5 then GlobalColor("L05") else if o17RS <= 6 then GlobalColor("L06") else if o17RS <= 7 then GlobalColor("L07") else if o17RS <= 8 then GlobalColor("L08") else if o17RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o17RS <= 1 then GlobalColor("H01") else if o17RS <= 2 then GlobalColor("H02") else if o17RS <= 3 then GlobalColor("H03") else if o17RS <= 4 then GlobalColor("H04") else if o17RS <= 5 then GlobalColor("H05") else if o17RS <= 6 then GlobalColor("H06") else if o17RS <= 7 then GlobalColor("H07") else if o17RS <= 8 then GlobalColor("H08") else if o17RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C18 = centerStrike - strikeSpacing * 9;
C18.SetLineWeight(5);
C18.SetDefaultColor(Color.BLACK);

C18.AssignValueColor(if o18M == 1 then (if o18RS <= 1 then GlobalColor("L01") else if o18RS <= 2 then GlobalColor("L02") else if o18RS <= 3 then GlobalColor("L03") else if o18RS <= 4 then GlobalColor("L04") else if o18RS <= 5 then GlobalColor("L05") else if o18RS <= 6 then GlobalColor("L06") else if o18RS <= 7 then GlobalColor("L07") else if o18RS <= 8 then GlobalColor("L08") else if o18RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o18RS <= 1 then GlobalColor("H01") else if o18RS <= 2 then GlobalColor("H02") else if o18RS <= 3 then GlobalColor("H03") else if o18RS <= 4 then GlobalColor("H04") else if o18RS <= 5 then GlobalColor("H05") else if o18RS <= 6 then GlobalColor("H06") else if o18RS <= 7 then GlobalColor("H07") else if o18RS <= 8 then GlobalColor("H08") else if o18RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

plot C19 = centerStrike + strikeSpacing * 9;
C19.SetLineWeight(5);
C19.SetDefaultColor(Color.BLACK);

C19.AssignValueColor(if o19M == 1 then (if o19RS <= 1 then GlobalColor("L01") else if o19RS <= 2 then GlobalColor("L02") else if o19RS <= 3 then GlobalColor("L03") else if o19RS <= 4 then GlobalColor("L04") else if o19RS <= 5 then GlobalColor("L05") else if o19RS <= 6 then GlobalColor("L06") else if o19RS <= 7 then GlobalColor("L07") else if o19RS <= 8 then GlobalColor("L08") else if o19RS <= 9 then GlobalColor("L09") else GlobalColor("L10")) else
(if o19RS <= 1 then GlobalColor("H01") else if o19RS <= 2 then GlobalColor("H02") else if o19RS <= 3 then GlobalColor("H03") else if o19RS <= 4 then GlobalColor("H04") else if o19RS <= 5 then GlobalColor("H05") else if o19RS <= 6 then GlobalColor("H06") else if o19RS <= 7 then GlobalColor("H07") else if o19RS <= 8 then GlobalColor("H08") else if o19RS <= 9 then GlobalColor("H09") else GlobalColor("H10")));

C1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C13.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C15.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C16.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C17.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C18.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
C19.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


price.SetPaintingStrategy(PaintingStrategy.DASHES);
price.SetDefaultColor(Color.WHITE);
price.setLineWeight(2);
The code is here.
 
Nice setup :) How do I do this manual setup to make it work for a particular stock? It's not obvious to me. Please show what to do.
 
copy these settings

EqfJJf1.png
0efTOVx.png
 

Attachments

  • EqfJJf1.png
    EqfJJf1.png
    70.8 KB · Views: 1,187
Okay thanks Angry. Much appreciated. That worked :)

It's very useful for multi-day option assessment.

If anybody wants to fine-tune this further, I would suggest
1 adding more option call & put strike prices
2 modifying this setup for intraday use
 
Ok I kind of fixed the date part for the heat map!

Can someone please help with adding an auto plot current price as a line and is there a way to fetch and plot more historical data? maybe TOS limitations.

bx3n8gg.png

@
 
Thanks everyone, this thing is pretty much 80% done.

Finalizing things
1. Need to expand the range of strikes from 19 to 60 for open interest profile.
2. Need an auto plot function for current price for heatmap as a line
3. Need manual mode for heatmap for weekly exp.
4. Need to fetch historical data for heatmap.

Original from @melarue on twitter (Claimed that he programmed himself, I highly doubt it, went private on twitter as soon as I asked him)

FOlIJqyVEAMJS7T


New (old code from thinkscripter and modified by friends here)

http://tos.mx/8XZQOG3 (Open Interest Profile)
http://tos.mx/BpXAtTN (Heatmap)

sMWWAA4.png
 
Last edited:
Figured ut how to change date... date fix. Honestly, preferred the original method of just typing in the date as shown in AngryBear's original study, is there a reason why the date fix is preferred?
 
Figured ut how to change date... date fix. Honestly, preferred the original method of just typing in the date as shown in AngryBear's original study, is there a reason why the date fix is preferred?
usually the calculator is off by only one or two days.easier to just click up or down -- if you liked manual entry you can add it back in
 
Do you have the code for the "OptionsVolumeOpenInterest" lower study? Looks very intriguing to me.

Ok I kind of fixed the date part for the heat map!

Can someone please help with adding an auto plot current price as a line and is there a way to fetch and plot more historical data? maybe TOS limitations.

bx3n8gg.png

@
 
Ok I kind of fixed the date part for the heat map!

Can someone please help with adding an auto plot current price as a line and is there a way to fetch and plot more historical data? maybe TOS limitations.

bx3n8gg.png

@
Love these concepts and tool - Beats looking to the table to try and eyeball these key data points!
Could you explain the display colors or use of the Option CI Heat Map ?
Thanks so much!
 
Love these concepts and tool - Beats looking to the table to try and eyeball these key data points!
Could you explain the display colors or use of the Option CI Heat Map ?
Thanks so much!
the heat map is kind of weird. it will only plot a certain range. also im not sure what the colors mean -- does red mean lots of change in oi or does it mean standing oi at that time --- the black lines also obscure other studies if you want to mix them
 
Love these concepts and tool - Beats looking to the table to try and eyeball these key data points!
Could you explain the display colors or use of the Option CI Heat Map ?
Thanks so much!
still trying to figure that one out, my guess would be more blue = bullish, more red= bearish.
 
Also I found that this script for labeling open interest which is given free every day by https://www.quanttradingapp.com/discord_pub/thinkscript_open_interest. Don't know if this helps


Code:
#
# Plot Hightest OI Levels on Chart
# Only Valid For: Friday, April 08, 2022
#
# Script Generated: 2022-04-08 08:00:12 AM
# Free Tickers Included: AAPL,AMZN,DIA,DIS,FB,GLD,GOOGL,IWM,NFLX,QQQ,SPY,TSLA,NVDA,AMD
# Total Tickers: 14
#
# Credit: Quant Trading App (c) 2021-2022
# Discord: https://quanttradingdiscord.com
#

def aggregationPeriod = AggregationPeriod.DAY;def LastPrice = close(priceType = PriceType.LAST);def total_call_premium;def total_put_premium;
plot oi_call_1;plot oi_call_2;plot oi_call_3;plot oi_call_4;plot oi_call_5;plot oi_put_1;plot oi_put_2;plot oi_put_3;plot oi_put_4;plot oi_put_5;
if (GetSymbol() == "AAPL") {total_call_premium = 382730.57;total_put_premium = 237766.65;oi_call_1 = 180;oi_call_2 = 175;oi_call_3 = 170;oi_call_4 = 177.5;oi_call_5 = 185;oi_put_1 = 170;oi_put_2 = 160;oi_put_3 = 175;oi_put_4 = 167.5;oi_put_5 = 165;}else if (GetSymbol() == "AMZN") {total_call_premium = 829120.56;total_put_premium = 3294755.32;oi_call_1 = 3300;oi_call_2 = 3400;oi_call_3 = 3500;oi_call_4 = 3200;oi_call_5 = 3600;oi_put_1 = 3000;oi_put_2 = 3100;oi_put_3 = 3015;oi_put_4 = 2950;oi_put_5 = 3490;}else if (GetSymbol() == "DIA") {total_call_premium = 38061.73;total_put_premium = 23450.76;oi_call_1 = 344;oi_call_2 = 354;oi_call_3 = 356;oi_call_4 = 349;oi_call_5 = 348;oi_put_1 = 329;oi_put_2 = 348;oi_put_3 = 315;oi_put_4 = 341;oi_put_5 = 342;}else if (GetSymbol() == "DIS") {total_call_premium = 4571.37;total_put_premium = 46655.94;oi_call_1 = 145;oi_call_2 = 144;oi_call_3 = 140;oi_call_4 = 133;oi_call_5 = 142;oi_put_1 = 128;oi_put_2 = 130;oi_put_3 = 134;oi_put_4 = 127;oi_put_5 = 129;}else if (GetSymbol() == "FB") {total_call_premium = 692845.36;total_put_premium = 102656.41;oi_call_1 = 200;oi_call_2 = 240;oi_call_3 = 250;oi_call_4 = 222.5;oi_call_5 = 230;oi_put_1 = 200;oi_put_2 = 190;oi_put_3 = 215;oi_put_4 = 220;oi_put_5 = 225;}else if (GetSymbol() == "GLD") {total_call_premium = 28848.77;total_put_premium = 24817.19;oi_call_1 = 198;oi_call_2 = 181;oi_call_3 = 185;oi_call_4 = 190;oi_call_5 = 180;oi_put_1 = 176;oi_put_2 = 179;oi_put_3 = 177;oi_put_4 = 180;oi_put_5 = 175;}else if (GetSymbol() == "GOOGL") {total_call_premium = 146315.7;total_put_premium = 310393.9;oi_call_1 = 2800;oi_call_2 = 2900;oi_call_3 = 3000;oi_call_4 = 2850;oi_call_5 = 2930;oi_put_1 = 2700;oi_put_2 = 2600;oi_put_3 = 2750;oi_put_4 = 2650;oi_put_5 = 2800;}else if (GetSymbol() == "IWM") {total_call_premium = 41415.24;total_put_premium = 293727.4;oi_call_1 = 211;oi_call_2 = 210;oi_call_3 = 201;oi_call_4 = 204;oi_call_5 = 207;oi_put_1 = 190;oi_put_2 = 204;oi_put_3 = 195;oi_put_4 = 194;oi_put_5 = 198;}else if (GetSymbol() == "NFLX") {total_call_premium = 55214.35;total_put_premium = 107048.6;oi_call_1 = 390;oi_call_2 = 425;oi_call_3 = 400;oi_call_4 = 410;oi_call_5 = 420;oi_put_1 = 360;oi_put_2 = 355;oi_put_3 = 350;oi_put_4 = 340;oi_put_5 = 365;}else if (GetSymbol() == "QQQ") {total_call_premium = 397452.26;total_put_premium = 1020109.49;oi_call_1 = 358;oi_call_2 = 355;oi_call_3 = 375;oi_call_4 = 370;oi_call_5 = 365;oi_put_1 = 350;oi_put_2 = 355;oi_put_3 = 345;oi_put_4 = 360;oi_put_5 = 340;}else if (GetSymbol() == "SPY") {total_call_premium = 935513.52;total_put_premium = 640624.12;oi_call_1 = 460;oi_call_2 = 450;oi_call_3 = 455;oi_call_4 = 465;oi_call_5 = 457;oi_put_1 = 440;oi_put_2 = 445;oi_put_3 = 425;oi_put_4 = 442;oi_put_5 = 435;}else if (GetSymbol() == "TSLA") {total_call_premium = 4085952.2;total_put_premium = 2404942.68;oi_call_1 = 1200;oi_call_2 = 1150;oi_call_3 = 1100;oi_call_4 = 1250;oi_call_5 = 1300;oi_put_1 = 1000;oi_put_2 = 950;oi_put_3 = 900;oi_put_4 = 1100;oi_put_5 = 1020;}else if (GetSymbol() == "NVDA") {total_call_premium = 156427.48;total_put_premium = 947041.4;oi_call_1 = 300;oi_call_2 = 240;oi_call_3 = 250;oi_call_4 = 275;oi_call_5 = 260;oi_put_1 = 240;oi_put_2 = 230;oi_put_3 = 250;oi_put_4 = 260;oi_put_5 = 255;}else if (GetSymbol() == "AMD") {total_call_premium = 44227.37;total_put_premium = 348995.29;oi_call_1 = 110;oi_call_2 = 115;oi_call_3 = 120;oi_call_4 = 125;oi_call_5 = 112;oi_put_1 = 110;oi_put_2 = 100;oi_put_3 = 85;oi_put_4 = 95;oi_put_5 = 90;}else {oi_call_1 = Double.NaN;oi_call_2 = Double.NaN;oi_call_3 = Double.NaN;oi_call_4 = Double.NaN;oi_call_5 = Double.NaN;oi_put_1 = Double.NaN;oi_put_2 = Double.NaN;oi_put_3 = Double.NaN;oi_put_4 = Double.NaN;oi_put_5 = Double.NaN;total_call_premium = 0;total_put_premium = 0;};oi_call_1.SetDefaultColor(CreateColor(0,236,59));oi_call_2.SetDefaultColor(CreateColor(0,197,49));oi_call_3.SetDefaultColor(CreateColor(0,158,39));oi_call_4.SetDefaultColor(CreateColor(0,119,29));oi_call_5.SetDefaultColor(CreateColor(0,79,20));oi_call_1.SetLineWeight(5);oi_call_2.SetLineWeight(4);oi_call_3.SetLineWeight(3);oi_call_4.SetLineWeight(2);oi_call_5.SetLineWeight(1);oi_put_1.SetDefaultColor(CreateColor(255,17,17));oi_put_2.SetDefaultColor(CreateColor(255,56,56));oi_put_3.SetDefaultColor(CreateColor(213,0,0));oi_put_4.SetDefaultColor(CreateColor(173,0,0));oi_put_5.SetDefaultColor(CreateColor(134,0,0));oi_put_1.SetLineWeight(5);oi_put_2.SetLineWeight(4);oi_put_3.SetLineWeight(3);oi_put_4.SetLineWeight(2);oi_put_5.SetLineWeight(1);addLabel (total_call_premium, "Calls: $"+ total_call_premium +" | Puts: $"+ total_put_premium, color.LIGHT_GRAY);

qta_tos_oi.jpg
 

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