I'm trying to calculate the Buying and selling volume in the premarket only from 4am to 9:25am. I have the below indicator that I'm using with the labels included but the issue with the script is, it doesn't stop calculating at 9:25am. It continues to show me buying and selling volume after 9:25am. Can you tell me where I went wrong in my script or can you provide me a corrected script?
declare lower;
declare Hide_On_Daily;
#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];
def O = open;
def h = high;
def l = low;
def c = close;
def V = volume;
def volsum = if bars == 1 then volume
else if SecondsTillTime(till) >= 0
then volsum[1] + volume
else Double.NaN;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);
def Avgbuy = round((buying[1] + buying[2] + buying[3]) / 3 / 1000, 0);
def AvgSell = round((selling[1] + selling[2] + selling[3]) / 3 / 1000, 0);
def Todayhigh = high(period = "Day");
def TodayLow = Low(period = "Day");
def TodaySelling = todayvol * (todayhigh-C)/(todayhigh - todaylow);
def TodayBuying = todayvol *(C - todaylow)/(Todayhigh - todaylow);
# Labels
input showlabel = yes;
DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;
AddLabel(Show_Labels, "Pre-M Buy Vol = " + Round(Buying / 1000, 0) + "K",
if buying/1000 > avgbuy and buying > selling then color.green else color.white);
AddLabel(Show_Labels, "Pre-M Sell Vol = " + Round(Selling / 1000, 0) + "K",
if selling/1000 > avgsell and Selling > Buying then color.red else color.white);
AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) , Color.white);
AddLabel(yes, "Pre-M Buys" + " " + round(todaybuying , 0) + " " ,if todaybuying * .5 > todayselling then color.green else color.white);
AddLabel(yes, "Pre-M Sells" + " " + round(todayselling , 0) + " " , if todayselling * .5 > todaybuying then color.red else color.white);
declare lower;
declare Hide_On_Daily;
#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];
def O = open;
def h = high;
def l = low;
def c = close;
def V = volume;
def volsum = if bars == 1 then volume
else if SecondsTillTime(till) >= 0
then volsum[1] + volume
else Double.NaN;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);
def Avgbuy = round((buying[1] + buying[2] + buying[3]) / 3 / 1000, 0);
def AvgSell = round((selling[1] + selling[2] + selling[3]) / 3 / 1000, 0);
def Todayhigh = high(period = "Day");
def TodayLow = Low(period = "Day");
def TodaySelling = todayvol * (todayhigh-C)/(todayhigh - todaylow);
def TodayBuying = todayvol *(C - todaylow)/(Todayhigh - todaylow);
# Labels
input showlabel = yes;
DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;
AddLabel(Show_Labels, "Pre-M Buy Vol = " + Round(Buying / 1000, 0) + "K",
if buying/1000 > avgbuy and buying > selling then color.green else color.white);
AddLabel(Show_Labels, "Pre-M Sell Vol = " + Round(Selling / 1000, 0) + "K",
if selling/1000 > avgsell and Selling > Buying then color.red else color.white);
AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) , Color.white);
AddLabel(yes, "Pre-M Buys" + " " + round(todaybuying , 0) + " " ,if todaybuying * .5 > todayselling then color.green else color.white);
AddLabel(yes, "Pre-M Sells" + " " + round(todayselling , 0) + " " , if todayselling * .5 > todaybuying then color.red else color.white);