```
def isAfter = HasEarnings(EarningTime.AFTER_MARKET);
def isBefore = HasEarnings() and !isAfter;
def vol = imp_volatility();
def beforevol = if isAfter then vol else if isBefore then vol[1] else 0;
def aftervol = if isAfter then vol[-1] else if isBefore then vol else 0;
#Calculates % change of IV from day prior to the earnings date to the day after the report.
def volcalc = if beforevol == 0 then 0 else (aftervol - beforevol) / beforevol;
def volcalcpositive = if beforevol == 0 then 0 else Max(0,(aftervol - beforevol) / beforevol);
def volcalcnegative = if beforevol == 0 then 0 else Min(0,(aftervol - beforevol) / beforevol);
#Defines # of positive or negative vol crush after earnings.
def negvolcalc = volcalc < 0;
def posvolcalc = volcalc > 0;
AddChartBubble(negvolcalc, high[1], "IVChng " + AsPercent(volcalc), Color.RED);
AddChartBubble(posvolcalc, high[1], "IVChng " + AsPercent(volcalc), Color.GREEN);
#Find number of up events
def barUpCount = IF (volcalc > 0) THEN IF IsNaN(barUpCount[1]) THEN 1 ELSE barUpCount[1] + 1 ELSE barUpCount[1];
#Find number of down events
def barDownCount = IF (volcalc < 0) THEN IF IsNaN(barDownCount[1]) THEN 1 ELSE barDownCount[1] + 1 ELSE barDownCount[1];
AddLabel(1, "IVUp " + AsPercent(TotalSum(volcalcpositive)/(barUpCount)), Color.white);
AddLabel(1, "IVDown " + AsPercent(TotalSum(volcalcnegative)/(barDownCount)), Color.white);
AddLabel(1,"Up/Down " + aspercent(barUpCount/(barUpCount + barDowncount)));
AddLabel(1,barUpCount);
AddLabel(1,barDownCount);
```