|
Josh McCormick
2020-11-17 17:31:52
0
|
|
Update!
It took some tap-dancing, 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 well-known 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 forward-looking and takes into account
// things like dividends, earning announcements, etc.
// STOCK STRATEGIES: Setting stop levels. Comparing forward-looking 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=ivclose-ivrange; // 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,StyleOwnScale|StyleHideYAxisValue|StyleHideValuesNan);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim title bar data (cannot hide)
Plot (round(ivrange,2),"EM",colorBlack,Chartnone,StyleOwnScale|StyleHideYAxisValue|StyleHideValuesNan);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim old title bar data (cannot hide)
Plot (Ref(iv,1),"IV %",colorBlack,Chartnone,StyleOwnScale|StyleHideYAxisValue);
UpdateColor (ivbarsago>4,ColorLightGray); // Dim old title bar data (cannot hide)
Plot (iff(ivbarsago==0,ref(ivabove,1),ivabove),"EM+",ColorBlack,ChartStep,StyleHideYAxisValue|StyleHideValues|StyleBringToFront);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
Plot (iff(ivbarsago==0,ref(ivbelow,1),ivbelow),"EM-",ColorBlack,ChartStep,StyleHideYAxisValue|StyleHideValues|StyleBringToFront);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
Plot (iff(ivbarsago==0,ref(ivabove,1),ivabove),"EM+",ColorBlue,ChartStep,StyleHideYAxisValue|StyleHideValues|StyleDotted|StyleWidth4|StyleBringToFront);
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,StyleHideYAxisValue|StyleHideValues|StyleDotted|StyleWidth4|StyleBringToFront);
UpdateColor (low<ivbelow,ColorAqua);
UpdateColor (ivbarsago==0 or ivbarsago>4,ColorTransparent); // Hide old data and vertical bars
|
|