# test_option_pricenone_01
declare lower;
def na = double.nan;
def dura = 10;
input PutStrike = 165;
input CallStrike = 176;
input underlyingEXP = ".GLD220318";
input agg = AggregationPeriod.MIN;
input priceType1 = PriceType.BID;
input priceType2 = PriceType.ASK;
input priceType3 = PriceType.MARK;
# few prices with last
#input priceType4 = PriceType.last;
input strike_offsets = 5;
def cls = close;
def atm_strike = round(cls, 0);
input strike_type = { default offset , separate_numbers };
def hi_strike;
def lo_strike;
# call strike is higher / put strike is lower
switch (strike_type) {
case offset:
hi_strike = atm_strike + strike_offsets;
lo_strike = atm_strike - strike_offsets;
case separate_numbers:
hi_strike = CallStrike;
lo_strike = putStrike;
}
# call strike is higher , put strike is lower
addlabel(1, "strikes", color.yellow);
addlabel(1, hi_strike, color.yellow);
#addlabel(1, "atm " + atm_strike, color.yellow);
addlabel(1, lo_strike, color.yellow);
addlabel(1, "--", color.black);
# -------------------------------------
def call_mark1 = close(Concat(underlyingEXP, Concat("C", hi_strike)), period = agg, priceType = priceType3);
def call_mark2 = if isnan(call_mark1) then call_mark2[1] else call_mark1;
input show_call_plots = yes;
plot c_mark = if show_call_plots then call_mark2 else na;
c_mark.setdefaultcolor(color.cyan);
addlabel(1, Concat(underlyingEXP, Concat("C", hi_strike)), color.cyan);
addlabel(1, "--", color.black);
# -------------------------------------
def put_mark1 = close(concat(underlyingEXP, concat("P", lo_strike)), period = agg, priceType = priceType3);
def put_mark2 = if isnan(put_mark1) then put_mark2[1] else put_mark1;
input show_put_plots = yes;
plot p_mark = if show_put_plots then put_mark2 else na;
p_mark.setdefaultcolor(color.yellow);
addlabel(1, Concat(underlyingEXP, Concat("P", lo_strike)), color.yellow);
addlabel(1, "--", color.black);
# -------------------------------------
def avg = Average((call_mark2 + put_mark2), dura);
plot zavg = avg;
zavg.setdefaultcolor(color.magenta);
addlabel(1, "average", color.magenta);
# -------------------------------------
#plot z = 0;
# -------------------------------------
# original
#plot avg = Average(close(concat(underlyingEXP, concat("C",CallStrike)), period = AggregationPeriod.MIN, priceType = PriceType.MARK)+close(concat(underlyingEXP, concat("P",PutStrike)), period = AggregationPeriod.MIN, priceType = PriceType.MARK),dura);
#