Options Premium Median ATM 0DTE, with symbol & expiration override
Code:
declare lower;
input expirationDate1 = 0;#231215;
input overrideSymbol = "SPY";
input showPutCallPremium = No;
def yyMMdd = if(expirationDate1 > 0, expirationDate1, GetYYYYMMDD() - 20000000);
rec priceCalls;
rec volcalls;
rec pricePuts;
rec volPuts;
if overrideSymbol <> "" {
priceCalls = close("." + overrideSymbol + AsText(yyMMdd, "%1$.0f") + "C" + Round(open(overrideSymbol), 0));
volcalls = volume("." + overrideSymbol + AsText(yyMMdd, "%1$.0f") + "C" + Round(open(overrideSymbol), 0));
pricePuts = close("." + overrideSymbol + AsText(yyMMdd, "%1$.0f") + "P" + Round(open(overrideSymbol), 0));
volPuts = volume("." + overrideSymbol + AsText(yyMMdd, "%1$.0f") + "P" + Round(open(overrideSymbol), 0));
} else {
priceCalls = close("." + GetUnderlyingSymbol() + AsText(yyMMdd, "%1$.0f") + "C" + Round(open(overrideSymbol), 0));
volcalls = volume("." + GetUnderlyingSymbol() + AsText(yyMMdd, "%1$.0f") + "C" + Round(open(overrideSymbol), 0));
pricePuts = close("." + GetUnderlyingSymbol() + AsText(yyMMdd, "%1$.0f") + "P" + Round(open(overrideSymbol), 0));
volPuts = volume("." + GetUnderlyingSymbol() + AsText(yyMMdd, "%1$.0f") + "P" + Round(open(overrideSymbol), 0));
}
plot premiumMedian = 100 * (priceCalls * volcalls - pricePuts * volPuts) / 2;
plot premiumATMCalls = if (showPutCallPremium, priceCalls * 100 * volcalls, Double.NaN);
plot premiumATMputs = if (showPutCallPremium, -pricePuts * 100 * volPuts, Double.NaN);
premiumMedian.AssignValueColor(if premiumMedian > 0 then Color.GREEN else if premiumMedian < 0 then Color.RED else Color.GRAY);
premiumMedian.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
premiumMedian.SetLineWeight(5);
premiumATMCalls.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
premiumATMCalls.SetDefaultColor(Color.DARK_GREEN);
premiumATMCalls.SetLineWeight(5);
premiumATMCalls.HideBubble();
premiumATMCalls.HideTitle();
premiumATMputs.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
premiumATMputs.SetDefaultColor(Color.DARK_RED);
premiumATMputs.SetLineWeight(5);
premiumATMputs.HideBubble();
premiumATMputs.HideTitle();
AddLabel(1, " " + AsText(yyMMdd, "%1$.0f") + " ", color.gray);
AddLabel(premiumATMCalls, " " + Concat(Round(premiumATMCalls, 0), " "), Color.DARK_GREEN);
AddLabel(premiumATMputs, " " + Concat(Round (-premiumATMputs, 0), " "), Color.DARK_RED);
AddLabel(1, "Median: " + Concat(Round (premiumMedian, 0), " "), if premiumMedian > 0 then Color.GREEN else if premiumMedian < 0 then Color.RED else Color.GRAY);
Last edited by a moderator: