Expected moved, probability cone
enter a date and it draws a parabola and calculates an expected move, using this equation.
expected move = price * iv * ( sqrt( days to expire / 365))
http://www.nishatrades.com/blog/mat...ected-move-using-a-probability-analysis-chart
if the chart time is more than day, the date has to be,
..if week , then a monday
..if month, then the 1st trading day of the month
WMT 30min 90day 400 expan bars
hal_cone
enter a date and it draws a parabola and calculates an expected move, using this equation.
expected move = price * iv * ( sqrt( days to expire / 365))
http://www.nishatrades.com/blog/mat...ected-move-using-a-probability-analysis-chart
if the chart time is more than day, the date has to be,
..if week , then a monday
..if month, then the 1st trading day of the month
Ruby:
# expected_move_cone_01
# expected move parabola
# cone starts on last bar
# halcyonguy
# 22-04-09
# http://www.nishatrades.com/blog/mathematically-calculating-expected-move-using-a-probability-analysis-chart
# nisha trades , described std dev
# expected move = price * iv * ( sqrt( days to expire / 365))
#----------------------------------
def price = close;
def iv2 = imp_volatility();
def iv = round(iv2,2);
def na = double.nan;
def bn = barnumber();
def lastbn = HighestAll(If(IsNaN(price), 0, bn));
def endbn = highestall(bn);
def lastbar = if lastbn == bn then 1 else 0;
# def lastbar = !isnan(close[0]) and isnan(close[-1]);
# expansion area, bars after last bar to right edge of chart
def expan_bars = (endbn - lastbn );
def expan_area = if (bn >= lastbn and bn <= endbn) then 1 else 0;
def lastcls = if bn < lastbn then na else if bn == lastbn then price else lastcls[1];
def lastiv = if bn < lastbn then na else if bn == lastbn then iv else lastiv[1];
def newday = if getday() != getday()[1] then 1 else 0;
#--------------------------------------------
def chartagg = GetAggregationPeriod();
def chartmin = (chartagg / 1000) / 60;
def daybarqty = roundup(390 / chartmin, 0);
def daysperbar = 1/daybarqty;
# for EM formula, need a qty of days that starts at 0 and counts up to the qty of days to target date
def cone_days_cnt_up = if bn == 1 then na else if lastbar then 0 else cone_days_cnt_up[1] + daysperbar;
# --------------------------------------------
# date of a trading day
input target_date_yyyymmdd = 20220520;
def dat = target_date_yyyymmdd;
def is_target_date = if (GetYYYYMMDD() == dat and newday) then 1 else 0;
# mobius
def data = dat;
def year = Round(data/10000, 0);
def month = Round((data % 10000) / 100, 0);
def day = (data % 100);
# this fixes the CountTradingDays() error , when it was in a normal if-then
def dayz5;
if GetYYYYMMDD() > dat then {
dayz5 = 0;
} else if lastbn == bn then {
dayz5 = CountTradingDays(GetYYYYMMDD(), dat );
} else {
dayz5 = dayz5[1];
}
# -------------------------------------
input vertical_line_target_date = yes;
addverticalline(vertical_line_target_date and is_target_date, " " + (month + " / " + day), color.yellow);
input em_factor = 1.0;
def em = round(em_factor * lastcls * lastiv * ( sqrt(cone_days_cnt_up/365)), 2);
def em_per = round((em/lastcls)*100, 1);
# get EM value on lastbar, so it will be displayed in a label
def em2b = if bn == 1 then 0 else if is_target_date then em else em2b[1];
def em2 = if isNaN(close[-1000]) then em2b[-1000] else Double.NaN;
# top half parabola
plot ztop = if expan_area then (lastcls + em) else na;
ztop.setdefaultcolor(color.yellow);
# bottom half parabola
plot zbot = if expan_area then (lastcls - em) else na;
zbot.setdefaultcolor(color.yellow);
input cone_horz_line = yes;
plot z2 = if (cone_horz_line and expan_area) then lastcls else na;
z2.setdefaultcolor(color.gray);
# -------------------------------------
# target date price bubbles
input show_price_bubbles = yes;
def vert = 0.99;
addchartbubble(show_price_bubbles and is_target_date, ztop, ztop , color.yellow, yes);
addchartbubble(show_price_bubbles and is_target_date, lastcls * vert, "$" + em + "\n" + em_per + "%" , color.yellow, yes);
addchartbubble(show_price_bubbles and is_target_date, zbot, zbot, color.yellow, no);
input show_date_bubble = yes;
addchartbubble(show_date_bubble and is_target_date, ztop*0.99, (month + "/" + day) , color.yellow, no);
# ===========================================
# labels
addlabel(1, "IV " + iv, color.orange);
input iv_label = yes;
AddLabel(iv_label, " " , Color.black);
input chart_stats_labels = no;
AddLabel(chart_stats_labels, "chartmin " + chartmin, Color.MAGENTA);
AddLabel(chart_stats_labels, "bars per day " + daybarqty, Color.MAGENTA);
input show_labels = yes;
addLabel(show_labels, "target date: " + month + "/" + day + "/" + AsPrice(year), color.yellow);
addlabel(show_labels, "trading days to target date " + dayz5, color.yellow);
addlabel(show_labels, "EM " + "$" + em2 , color.orange);
#
WMT 30min 90day 400 expan bars
hal_cone