
Josh McCormick
20201117 17:31:52
0


Update!
It took some tapdancing, but I've managed to rid the chart of those unwanted vertical lines. Also, I don't have mathematical proof, but experimentation leads me to believe that the range of the Expected Move is more accurate when Implied Volatility is scaled to a period of 5.5 days instead of 7 calendar days. If you disagree, change Sqrt(5.5/365) to your desired value such as Sqrt(7/365).
Finally, I've seen that the high and low values of the expected range also tend to act as support and resistance on the intraday chart too! I'll whip up some code for that later. I'm also curious to see if any action happens at wellknown Fibonacci ratios of the expected move. Anyhow, enjoy!
I probably need to comb through this code another time or two in order to clear out some of the workarounds.
NEW! The blue Expected Move line turns a brighter AQUA on those dates where the Expected Move has been breached (above or below) by the actual price. Over the long term, every 32 out of 100 weeks should escape the predicted values.
UPDATED CODE FOR HISTORICAL CHART:
================================
// 
// IV (IMPLIED VOLATILITY) AND EM (EXPECTED MOVE)
//
// DEFAULTS TO: *68% probability* *one year from now* that the stock move will be less than or equal
// to the given number. Both the probability and the duration can be adjusted mathematically, but our
// code (below) only adjusts the duration. You probably want to leave it at a 68% probability so that
// you're using the same measuring stick as the rest of the market.
// INDICATES: How much the stock price is expected to move based on what is known & what is
// expected by the market. Unlike most indicators, this is forwardlooking and takes into account
// things like dividends, earning announcements, etc.
// STOCK STRATEGIES: Setting stop levels. Comparing forwardlooking risk/volatility between two securities.
// OPTION STRATEGIES: Iron Condors outside EM, Vertical Spreads outside EM, Butterflies on the EM edge
// NOTE: Estimates the MAGNITUDE of change. Not DIRECTION of change.
// 
symbol_name=Name(); // This allows me to substitute in $NDX $SPX etc where needed.
iv=GetData("iv","iv",last,symbol_name);
ivbarsago=barssince (iv!=ref(iv,1)); // How many bars ago was our (expected weekly) IV data?
ivbarsago=iff(ivbarsago==0,5,ivbarsago);
ivclose=ref(close,ivbarsago); // The closing price on that day
ivrange=ivclose*NanToZero(ref(iv,ivbarsago),1)*0.01*Sqrt(5.5/365); // Weekly IV percentage as handles (+/)
// There is a 68% probability that the price will move less than or equal to the predicted range.
// You can adjust the probability (confidence interval) by multiplying the ivrange as follows:
//
// 1.00x = 68.27% 1.645x = 90.0% 1.96x = 95.00% 2.0x = 95.45%
// 2.33x = 98.00% 2.58x = 99.0% 3.00x = 99.73% 4.0x = 99.99% 5.0x = 99.999%
// If this data is old, set it to the closing price so that we can hide it.
ivabove=ivclose+ivrange; // Highest expected weekly stock price based upon IV
ivbelow=ivcloseivrange; // Lowest expected weekly stock price based upon IV
ivbarsago=iff(ivbarsago==5,0,ivbarsago); // A quick hack for the following code.
Plot (Round(ivabove,2),"EM:".Round(ivbelow,2)." EM+",colorBlack,Chartnone,StyleOwnScaleStyleHideYAxisValueStyleHideValuesNan);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim title bar data (cannot hide)
Plot (round(ivrange,2),"EM",colorBlack,Chartnone,StyleOwnScaleStyleHideYAxisValueStyleHideValuesNan);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim old title bar data (cannot hide)
Plot (Ref(iv,1),"IV %",colorBlack,Chartnone,StyleOwnScaleStyleHideYAxisValue);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim old title bar data (cannot hide)
Plot (iff(ivbarsago==0,ref(ivabove,1),ivabove),"EM+",ColorBlack,ChartStep,StyleHideYAxisValueStyleHideValuesStyleBringToFront);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
Plot (iff(ivbarsago==0,ref(ivbelow,1),ivbelow),"EM",ColorBlack,ChartStep,StyleHideYAxisValueStyleHideValuesStyleBringToFront);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
Plot (iff(ivbarsago==0,ref(ivabove,1),ivabove),"EM+",ColorBlue,ChartStep,StyleHideYAxisValueStyleHideValuesStyleDottedStyleWidth4StyleBringToFront);
UpdateColor (high>ivabove,ColorAqua);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
Plot (iff(ivbarsago==0,ref(ivbelow,1),ivbelow),"EM",ColorBlue,ChartStep,StyleHideYAxisValueStyleHideValuesStyleDottedStyleWidth4StyleBringToFront);
UpdateColor (low<ivbelow,ColorAqua);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars

