EMA values from previous days end

I am trying to check 2 EMA values of 2nd last candles from last trading day, but not getting desired result using the below code.
`BI = BarIndex();
DaysFirstBar = TimeFrameExpand( TimeFrameCompress( BI, inDaily, compressOpen ), inDaily, expandFirst );

EMA_Comp = Ref(EMA(C,5),-(SelectedValue(DaysFirstBar)+2)) > Ref(EMA(C,25), -(SelectedValue(DaysFirstBar)+2)); `

Any help will be greatly appreciated

Trying with the below changes, but exploration is repeating the same set of EMA values across different past days of last 2 years

BI = BarIndex();
DaysFirstBar = TimeFrameExpand( TimeFrameCompress( BI, inDaily, compressOpen ), inDaily, expandFirst );

EMA_Comp = Ref(EMA(C,5),-(DaysFirstBar+2)) > Ref(EMA(C,25), -(DaysFirstBar+2));  `

I want EMA of 2nd last candle from the previous day whenever my BI changes from 0 to 77 to 153 and so on.... in a 5 min chart. But the above code is repeating the same set of EMA from BI =0 and calculating from the first day's closed price.

What if you just compute the EMA as usual.
Since you are fixed at 2nd last candle, just Ref() that array by 2 bars.
Now you have it aligned with NewDay.

Then just do a ValueWhen() with NewDay condition as expression and the value of your Ref'd array.

Thanks @travick for your suggestion, it worked instantly and solved my problem. Appreciate :+1: