Hi, I've been trying to create a watchlist custom column that calculates the percent change betweeen 2 specific times (for example compare the opening price at 930am and closing price at 1030am and calculate the % change) . My problem is that if there's no trade activity at the specific time/s my code returns an error. Is there a way to change it so that it picks up the last closing price before the specified time ? Thanks. Here's my code for now.
Code:
def openPrice = if SecondsTillTime(0930) == 0 then open else openPrice[1];
def closePrice = if SecondsTillTime(1030) == 0 then open else closePrice[1];
plot pctChange = round(100*(closePrice - OpenPrice) / OpenPrice,1);
AssignBackgroundColor(if(pctChange<0)then Color.DARK_RED else Color.DARK_GREEN);