Garrett’s Extended Hours % AVOL Indicator for thinkorswim

smbcapitalGeneral Comments

Garrett’s Extended Hours % AVOL Indicator for thinkorswim


### inputs ###
input AVOL_length = 21;
input subtractFirstBarVolume = yes;

### daily AVOL ###
def daily_volume = volume(period = AggregationPeriod.DAY);
def AVOL = Average(daily_volume[1], AVOL_length);

# AfterHours Volume
def ah = getTime() > regularTradingEnd(getYYYYMMDD());
def firstAHVolume = if ah and !ah[1] then volume else firstAHVolume[1];
def ahVol = if ah and !ah[1]
            then if subtractFirstBarVolume then 0 else volume
            else if ah
            then ahVol[1] + volume - (if !ah[1] and subtractFirstBarVolume then firstAHVolume else 0)
            else ahVol[1];
plot AH_volume = if ah
                 then ahVol
                 else Double.NaN;
AH_volume.setdefaultcolor(color.cyan);

# PreMarket Volume
def pm = getTime() < regularTradingStart(getYYYYMMDD());
def pmVol = if pm and !pm[1]
            then volume
            else if pm
            then pmVol[1] + volume
            else pmVol[1];
plot PM_volume = if pm
                 then pmVol
                 else double.nan;
PM_volume.setdefaultcolor(color.magenta);

# Total ExtendedHours Volume
def comVol = if pm then ahVol + pmVol else comVol[1];
plot EH_volume = if pm then comVol else double.nan;
EH_volume.setstyle(curve.short_dash);
EH_volume.setdefaultcolor(color.light_gray);

Addlabel(1, "AH Volume = " + ahVol, color.cyan);
Addlabel(1, "PM Volume = " + pmVol, color.magenta);
Addlabel(1, "EH Volume = " + comVol, color.light_gray);
Addlabel(1, "AH %AVOL = " + round((ahVol/AVOL)*100), color.cyan);
Addlabel(1, "PM %AVOL = " + round((pmVol/AVOL)*100), color.magenta);
Addlabel(1, "EH %AVOL = " + round((comVol/AVOL)*100), color.light_gray);

plot percent_avol = if ah then round((ahVol/AVOL)*100) else round((comVol/AVOL)*100);
Addlabel(1, "%AVOL = " + percent_avol, color.yellow);


⬇️ Download the full ThinkScript file