Your existing code is written so that it reads the close from the daily aggregation period and from a ticker symbol other than the ticker symbol applied to the chart. This is used on an intraday chart to compute the difference between yesterday's close and today's close on the daily time frame for the ticker symbol selected via the user input named "SYMB". This is the line of code that reads from the daily time frame:
def AD = close (symbol = SYMB, period = AggregationPeriod.day) – close(symbol = SYMB, period = AggregationPeriod.day)[1];
Your request is to convert this code so that "...extended hours also so up.". Which means you need to remove the secondary aggregation from a portion of this code. To accomplish this we will leave the second part of code to remain as is, reading from daily time frame to get the previous day close of the selected symbol.
close(symbol = SYMB, period = AggregationPeriod.day)[1]
Then we change the first portion of the code to something that will read the current close (of the selected symbol) during extended hours and regular session hours.
close(symbol = SYMB)
This is what is looks like after we make this adjustment:
def AD = close (symbol = SYMB) – close(symbol = SYMB, period = AggregationPeriod.DAY)[1];
We put this altogether and we have the following result:
input tickerSymbol = “SPY”;
def netDailyChange = close (symbol = tickerSymbol) – close(symbol = tickerSymbol, period = AggregationPeriod.DAY)[1];
AddLabel(yes, “SPY: ” + netDailyChange, if netDailyChange >= -0.30 then Color.WHITE else Color.RED);