Previous Day COi

Hiii,
I'm trying to find cumulative open interest for previous day and add that in title. below is my code but somehow i'm getting COI of sameday.

Anyhelp will be highly appreciated.

	_SECTION_BEGIN("COI");
	Sym_F1 		= Name();
	Sym_F2 		= StrReplace(Name(), "-I.NFO", "-II.NFO");
	Sym_F3 		= StrReplace(Name(), "-I.NFO", "-III.NFO");

		SetForeign( Sym_F2 );
		NR_O = O;	NR_H = H;	NR_L = L;	NR_C = C;	NR_OI = OI;	NR_V = V;
		RestorePriceArrays();

		SetForeign( Sym_F3 );
		FR_O = O;	FR_H = H;	FR_L = L;	FR_C = C;	FR_OI = OI;	FR_V = V;
		RestorePriceArrays();
		
	COI		=	OI	+	NR_OI	+	FR_OI;

y_COI = TimeFrameGetPrice("C",inDaily,-1);
	P_day = Ref(Day(),-1);
	P_COI = ValueWhen(P_DAY,COI,1);

Have you tried running an exploration and see what values are being returned ?

This may help in determing what steps would need to be taken.

Just a suggestion.

You have to tell us what timeframe you are using.

If it is Daily, then
P_COI = Ref( COI, -1);
is enough.

If it is intraday, then

P_day = Day() != Ref( Day(), -1);
P_COI = ValueWhen( P_day, Ref( COI, -1), 1);

I'm shifting the COI Array by 1 bar and checking the value at new day to get the previous day's last bar total.

I did not run it but i'm thinking its ok.