Wait for 2nd higher-timeframe bar of a new day to close

Hi guys,

Since I'm referencing previous bars' indicator values to generate entry signals, I want to avoid using the previous day's values, and so I need to wait for the first bar on each new day to close before generating a signal.

And since my periodicity is set at 1-second, and I'm referencing 30-second bars, I need to wait for the first 30-second bar of the day to close (keeping in mind that there's no exact time when the first 30-second bar is guaranteed to occur due to slight differences in market opening times).

There are a few examples of checking for a new day, of which I've used the following:

dn = TimeFrameExpand(DateNum(), timeFrameVal, expandLast);
newDay = dn != TimeFrameExpand(Ref(dn,-1), timeFrameVal, expandLast);
SecondBar = BarsSince(newDay) > 1;

Where timeFrameVal is 30-seconds in this case. This does achieve the desired result, however when backtesting it only returns a result for the most recent day. E.g. here are the results without the above code:
And here are the results with the above code:

(notice the 09/12/2019 result in the first image, which opened at 10:00:00, whereas it should open at 10:00:30 as this is after the first 30-second bar has closed).

Any help would be appreciated, thanks.