Refrencing previous Array


I want to get the bars passed since 2 days ago, when i reference it by Ref(DateNum(),-2)
i still get the current datenum(). any help?

I understood the problem with Ref(Datenum(),-2), as i am in 5 minute chart. How will i reference Barssince 2 days back. currently i am using PDay2=BarsSince(DateNum()!=Ref(DateNum(),-1))+77
"77" being no of static bars in 5in time frame is there a better way?

You can get the number of bars by subtracting the BarIndex() of the two recent most Days.
then, just Ref() those many bars so 77 is hardcoded, you can calculate with formula.

bi = BarIndex();
nd = Day() != Ref( Day(), -1);    // New Day
pbi = ValueWhen( nd, bi, 1);
obi = ValueWhen( nd, bi, 2);    // You may change to 3 
           // depending on how you imply 2 days ago :)

barsInDay = LastValue( pbi - obi );

printf("%g", barsInDay);

In the same formula, if you replaced pbi with bi then you get total bars since two days.
Hope you get the idea of using ValueWhen() here.

1 Like

thanks @travick. it helps.