I have a vector of stock prices throughout the day:
> head(bidStock)
[,1]
[1,] 1179.754
[2,] 1178.000
[3,] 1178.438
[4,] 1178.367
[5,] 1178.830
[6,] 1178.830
I want to find two things. As I the algorithm goes through the day. I want it to find how far the current point is from the historical minimum and maxim throughout the day.
There is a function called 'mdd' in the 'stocks' package which finds the maximum draw down throughout the day (i.e. the lowest value which corresponds to a point being the farthest from the historical maximum of the day). However, I don't want just the lowest value, I want a vector. I have come up with the code below to do that. However, I need a way to do with how far a point is from the running historical minimum as well.
mddVec<-rep(NA,1)
for (i in 1: length(bidStock)){
mddVec[i]<-mdd(bidStock[1:i])
}
Finally, typical price is calculated by (max(day) + min(day) + closing price)/3. Is there a way to make that work like a running average using running historical min and max throughout the day.
Thanks for your help in advance