Hello everyone. I'm trying to reference an indicator value from the same timestamp but previous business day. For example, for 2023-01-05 11:35:03 I would like to pull the data from 2023-01-04 11:35:03.
I've searched the forums for this, but the previous posts seem to be about referencing the value from a specific time, by setting timenum() = 11:35:05 and then using ValueWhen() to reference that value. But I need the value from the same time (which would roll and change) and not a specific hardcoded time. Here are some things I've tried:
vol = StDev( C - Ref(C, -1) , 60);
dt = DateTime();
yesterday = DateTimeAdd(dt, -1, inDaily);
yesterdaysVolSameTime = ValueWhen(dt == yesterday, vol );
Plot( yesterdaysVolSameTime, "yesterdaysVolSameTime", ParamColor( "Color yesterdaysVolSameTime", colorWhite ), ParamStyle("Style yesterdaysVolSameTime", styleThick));
^ unfortunately it's coming up blank
vol = StDev( C - Ref(C, -1) , 60);
tn = TimeNum();
notSameDay = Now(6) != Day();
sameTime = Now(4) == tn;
yesterdaysVolSameTime = ValueWhen(sameTime AND notSameDay, vol );
Plot( yesterdaysVolSameTime, "yesterdaysVolSameTime", ParamColor( "Color yesterdaysVolSameTime", colorWhite ), ParamStyle("Style yesterdaysVolSameTime", styleThick));
^ I tried the Now() function but it seems to be referencing the current time as in the real time today and not the "current time" of the bar. It's also coming up empty as a result.
If it were a larger time interval like 15m or 30m I realize I could just use Ref(vol, -26) or something, but because of the granular timeframe (1s to 5s) there are a lot of data holes and so the number of bars would vary.
I'm sure it's very simple but I can't quite seem to figure it out so thanks in advance for any help and guidance.