# 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??

Thanks,

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

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

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

//**************************************************************************************************************
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_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() );
_SECTION_END();

//**************************************************************************************************************
//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);

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
**************************************************************************************************************/

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

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.