Если кому надо – индикатор опционных объемов. На рисунке ниже показан пример для SPY:

option

Как выбирать настройки:

  • 1 – префикс серии опциона (как выбрать на рисунке показано)
  • 2 – страйк опциона
  • 3 – шаг опциона – разница между двумя ближними страйками
  • 4 – вариант отображения данных
  • 5 – количество страйков учитываемых для рассчета

option2

Ну и собственно сам код индикатора:

declare lower;
input optionSeriesPrefix = “.SPY140930”;
input strike = 199.0;
input strikeSpacing = 0.50;
input mode = {default volume, totalVolume, openInterest, volumePercentOI};
input totalStrikes = {default Five, Three, One};

def showThree = if mode == mode.volume and totalStrikes == totalStrikes.Three then 1 else 0;
def showFive = if mode == mode.volume and totalStrikes == totalStrikes.Five then 1 else 0;

addLabel(yes, optionSeriesPrefix, color.red);
addLabel(yes, concat(strike, “P”), color.red);
addLabel(showThree or showFive, concat(strike – strikeSpacing, “P”), color.magenta);
addLabel(showThree or showFive, concat(strike + strikeSpacing, “P”), color.orange);
addLabel(showFive, concat(strike – strikeSpacing – strikeSpacing, “P”), color.pink);
addLabel(showFive, concat(strike + strikeSpacing + strikeSpacing, “P”), color.gray);
addLabel(yes, concat(strike, “C”), color.green);
addLabel(showThree or showFive, concat(strike – strikeSpacing, “C”), color.cyan);
addLabel(showThree or showFive, concat(strike + strikeSpacing, “C”), color.blue);
addLabel(showFive, concat(strike – strikeSpacing – strikeSpacing, “C”), color.lime);
addLabel(showFive, concat(strike + strikeSpacing + strikeSpacing, “C”), color.white);

def putOptionVolume = if isNAN(volume(concat(optionSeriesPrefix,concat(“P”,strike)))) then 0 else volume(concat(optionSeriesPrefix,concat(“P”,strike)));
rec cumPutVolume = cumPutVolume[1] + putOptionVolume;
def totalputOptionVolume = volume(concat(optionSeriesPrefix,concat(“P”,strike)),”DAY”);
def putOptionOI = open_interest(concat(optionSeriesPrefix,concat(“P”,strike)),”DAY”);
def callOptionVolume = if isNAN(volume(concat(optionSeriesPrefix,concat(“C”,strike)))) then 0 else volume(concat(optionSeriesPrefix,concat(“C”,strike)));
rec cumCallVolume = cumCallVolume[1] + callOptionVolume;
def totalcallOptionVolume = volume(concat(optionSeriesPrefix,concat(“C”,strike)),”DAY”);
def callOptionOI = open_interest(concat(optionSeriesPrefix,concat(“C”,strike)),”DAY”);

def putOptionVolume1 = if isNAN(volume(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing)));
rec cumPutVolume1 = cumPutVolume1[1] + putOptionVolume1;
def totalputOptionVolume1 = volume(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing)),”DAY”);
def putOptionOI1 = open_interest(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing)),”DAY”);
def callOptionVolume1 = if isNAN(volume(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing)));
rec cumCallVolume1 = cumCallVolume1[1] + callOptionVolume1;
def totalcallOptionVolume1 = volume(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing)),”DAY”);
def callOptionOI1 = open_interest(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing)),”DAY”);

def putOptionVolume2 = if isNAN(volume(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing)));
rec cumPutVolume2 = cumPutVolume2[1] + putOptionVolume2;
def totalputOptionVolume2 = volume(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing)),”DAY”);
def putOptionOI2 = open_interest(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing)),”DAY”);
def callOptionVolume2 = if isNAN(volume(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing)));
rec cumCallVolume2 = cumCallVolume2[1] + callOptionVolume2;
def totalcallOptionVolume2 = volume(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing)),”DAY”);
def callOptionOI2 = open_interest(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing)),”DAY”);

def putOptionVolume3 = if isNAN(volume(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing-strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing-strikeSpacing)));
rec cumPutVolume3 = cumPutVolume3[1] + putOptionVolume3;
def totalputOptionVolume3 = volume(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing-strikeSpacing)),”DAY”);
def putOptionOI3 = open_interest(concat(optionSeriesPrefix,concat(“P”,strike-strikeSpacing-strikeSpacing)),”DAY”);
def callOptionVolume3 = if isNAN(volume(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing-strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing-strikeSpacing)));
rec cumCallVolume3 = cumCallVolume3[1] + callOptionVolume3;
def totalcallOptionVolume3 = volume(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing-strikeSpacing)),”DAY”);
def callOptionOI3 = open_interest(concat(optionSeriesPrefix,concat(“C”,strike-strikeSpacing-strikeSpacing)),”DAY”);

def putOptionVolume4 = if isNAN(volume(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing+strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing+strikeSpacing)));
rec cumPutVolume4 = cumPutVolume4[1] + putOptionVolume4;
def totalputOptionVolume4 = volume(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing+strikeSpacing)),”DAY”);
def putOptionOI4 = open_interest(concat(optionSeriesPrefix,concat(“P”,strike+strikeSpacing+strikeSpacing)),”DAY”);
def callOptionVolume4 = if isNAN(volume(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing+strikeSpacing)))) then 0 else volume(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing+strikeSpacing)));
rec cumCallVolume4 = cumCallVolume4[1] + callOptionVolume4;
def totalcallOptionVolume4 = volume(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing+strikeSpacing)),”DAY”);
def callOptionOI4 = open_interest(concat(optionSeriesPrefix,concat(“C”,strike+strikeSpacing+strikeSpacing)),”DAY”);

plot zero = 0;
zero.SetDefaultColor(color.white);
zero.HideTitle();

plot datap4;
plot datac4;
switch (mode){
case volume:
datap4 = -putoptionVolume4 * showFive;
datac4 = calloptionVolume4 * showFive;
case totalVolume:
datap4 = double.nan;
datac4 = double.nan;
case openInterest:
datap4 = double.nan;
datac4 = double.nan;
case volumePercentOI:
datap4 = double.nan;
datac4 = double.nan;
}
datap4.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datac4.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datap4.SetDefaultColor(color.gray);
datac4.SetDefaultColor(color.white);
datap4.SetLineWeight(3);
datac4.SetLineWeight(3);
datap4.HideTitle();
datac4.HideTitle();
datap4.HideBubble();
datac4.HideBubble();

plot datap3;
plot datac3;
switch (mode){
case volume:
datap3 = -putoptionVolume3 * showFive – putOptionVolume4 * showFive;
datac3 = calloptionVolume3 * showFive + callOptionVolume4 * showFive;
case totalVolume:
datap3 = double.nan;
datac3 = double.nan;
case openInterest:
datap3 = double.nan;
datac3 = double.nan;
case volumePercentOI:
datap3 = double.nan;
datac3 = double.nan;
}
datap3.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datac3.SetPaintingStrategy(paintingStrategy.HISTOGRAM);

datap3.SetDefaultColor(color.pink);
datac3.SetDefaultColor(color.lime);

datap3.SetLineWeight(3);
datac3.SetLineWeight(3);
datap3.HideTitle();
datac3.HideTitle();
datap3.HideBubble();
datac3.HideBubble();

plot datap2;
plot datac2;
switch (mode){
case volume:
datap2 = -putOptionVolume2 * (showThree or showFive) – putoptionVolume3 * showFive – putOptionVolume4 * showFive;
datac2 = +callOptionVolume2 * (showThree or showFive) + calloptionVolume3 * showFive + callOptionVolume4 * showFive;
case totalVolume:
datap2 = double.nan;
datac2 = double.nan;
case openInterest:
datap2 = double.nan;
datac2 = double.nan;
case volumePercentOI:
datap2 = double.nan;
datac2 = double.nan;
}
datap2.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datac2.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datap2.SetDefaultColor(color.orange);
datac2.SetDefaultColor(color.blue);
datap2.SetLineWeight(3);
datac2.SetLineWeight(3);
datap2.HideTitle();
datac2.HideTitle();
datap2.HideBubble();
datac2.HideBubble();

plot datap1;
plot datac1;
switch (mode){
case volume:
datap1 = -putOptionVolume1 * (showThree or showFive) – putOptionVolume2 * (showThree or showFive) – putoptionVolume3 * showFive – putOptionVolume4 * showFive;
datac1 = callOptionVolume1 * (showThree or showFive) + callOptionVolume2 * (showThree or showFive) + calloptionVolume3 * showFive + callOptionVolume4 * showFive;
case totalVolume:
datap1 = double.nan;
datac1 = double.nan;
case openInterest:
datap1 = double.nan;
datac1 = double.nan;
case volumePercentOI:
datap1 = double.nan;
datac1 = double.nan;
}
datap1.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datac1.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datap1.SetDefaultColor(color.magenta);
datac1.SetDefaultColor(color.cyan);
datap1.SetLineWeight(3);
datac1.SetLineWeight(3);
datap1.HideTitle();
datac1.HideTitle();
datap1.HideBubble();
datac1.HideBubble();

plot datap;
plot datac;
switch (mode){
case volume:
datap = -putoptionVolume – putOptionVolume1 * (showThree or showFive) – putOptionVolume2 * (showThree or showFive) – putoptionVolume3 * showFive – putOptionVolume4 * showFive;
datac = calloptionVolume + callOptionVolume1 * (showThree or showFive) + callOptionVolume2 * (showThree or showFive) + calloptionVolume3 * showFive + callOptionVolume4 * showFive;
case totalVolume:
datap = -totalputoptionVolume;
datac = totalcalloptionVolume;
case openInterest:
datap = -putoptionOI;
datac = callOptionOI;
case volumePercentOI:
datap = -putoptionVolume * 100 / putoptionOI;
datac = callOptionVolume * 100 / callOptionOI;
}
datap.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datac.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
datap.SetDefaultColor(color.red);
datac.SetDefaultColor(color.green);
datap.SetLineWeight(3);
datac.SetLineWeight(3);
datap.HideTitle();
datac.HideTitle();
datap.HideBubble();
datac.HideBubble();