Calculate Daily close, Moving Average, RSI from intraday data

Hi ,

I only have 1 min intraday historical data with me.

The daily closing price(settlement price) is the weighted average of all prices during the last 30 minutes of the trading hours & not the last traded price.Therefore, I tried using VWAP of last 30 mins to find out the Daily Close.

I am getting incorrect Moving Average and RSI; both on daily basis in my code.

Could anyone suggest what mistake am I making?
Also, is there any other way of working around the closing price??


tn= TimeNum();
dn= DateNum();
Fc= dn != Ref (dn,-1);	// todays date != ydays date, first candle
Lc= dn != Ref (dn,1);	//todays date != tomm date, last candle

count = BarsSince(Fc) + 1;

cond = tn==091500 AND count == 2 ;

O= IIf(cond,Ref(O,-1),O); // If preopen candle, Market open == Preopen candle's open

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

//Get daily Closing Price -->( Settlement price) 

function SumSinceInclusive( condition, array )
  return SumSince( condition, array ) + ValueWhen( condition, array );

Last_30min_Volume = SumSinceInclusive( tn==150000, Volume); 

printf("Last_30min_Volume is %g\n", Last_30min_Volume);

vWap = SumSinceInclusive( tn==150000, (H + L + C) / 3 * Volume); 
vWap = vWap / Max(Last_30min_Volume, 0.00001);

Plot(IIf(TimeNum() < 150000,null,vWap),"vWap",colorYellow,styleLine | styleThick);

CDC = ValueWhen(Lc, vWap); // Current Day's Close

PDC = ValueWhen(Lc, CDC, 2); 	// Previous day's Closing Price
PDC_2 = ValueWhen(Lc, CDC, 3);	// Day before yesterday's's Closing Price
CDO= TimeFrameGetPrice("Open", inDaily, 0, expandFirst); // Current day's Open
chg = (PDC - PDC_2)/PDC_2*100;  // Percentage change in closing price

printf("CDC is %g\n", CDC);
printf("PDC is %g\n", PDC);
printf("PDC_2 is %g\n", PDC_2);
printf("CDO is %g\n", CDO);
printf("Change is %g\n", chg);

define daily MA AND RSI 

MA_daily = MA(CDC,200);
RSI_daily= RSIa( CDC, 5); 

MA_daily= TimeFrameExpand(MA_daily, inDaily, expandLast);
RSI_daily = TimeFrameExpand(RSI_daily, inDaily, expandLast);

printf("MA_daily % g\n", MA_daily);
printf("RSI_daily %g\n", RSI_daily);

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.