Daily Volatality Results different in 5 mins Vs Daily Charts

I am trying to caluclate daily volatality . Getting different results in daily chart vs intra . Please advise where i am doing wrong

TimeFrameSet(inDaily);
DayO = O;
DailyC= C;

TimeFrameRestore();


DailyClose =TimeFrameExpand(DailyC,inDaily,expandLast);

DailyOpen =TimeFrameExpand(DayO,inDaily,expandLast);

 
Logreturns_C =  ln ( DailyClose/Ref (DailyClose, -1)) ;
 
DailyVolatility  = StDev(Logreturns_C, 90)     ; //90 day Volatility (D)
                                               
 

 

 

_N(Title = ""+EncodeColor(colorGreen)+ "Log Returns (C) ="+WriteVal (Logreturns_C ,1.4)  
  +EncodeColor(colorLavender)+"\n"+"Daily Volatiliy = " +WriteVal (DailyVolatility ,1.6)  
  
 );

Daily chart

image

Intra day chart for the same thing showing different value

image

Appreciate your time and help

Debug this line. You are using ExpandLast Argument in TFExpand()

When you Expand Daily to intra TF, all the same day bars will have same DailyClose value.
Essentially a long Array of ln( 1 ) with few decimals when the day changed.

3 Likes

To expand on what @travick said, it would be easiest if you calculated the volatility while still inside the TimeFrameSet()...TimeFrameRestore() portion of your code, then just use TimeFrameExpand() to expand the DailyVolatility array back to your intraday timeframe.

1 Like

Thanks @travick and @mradtke