how to get the last 5 minutes open high low close of a particular stock
to implement an algo trading strategy
Hello,
You can get data for 1 minute time interval and then convert it into 5 minute interval data. Here is the below code in C# to convert 1 minute interval data to 5 minute interval data.
public static List<Ohlcv> ConvertTo5MinuteCandles(List<Ohlcv> candles)
{
return candles
.GroupBy(c => new DateTime(c.Time.Year, c.Time.Month, c.Time.Day, c.Time.Hour, c.Time.Minute / 5 * 5, 0))
.Select(group => new Ohlcv
{
Time = group.Key,
Open = group.First().Open,
High = group.Max(c => c.High),
Low = group.Min(c => c.Low),
Close = group.Last().Close,
Volume = group.Sum(c => c.Volume)
})
.OrderBy(c => c.Time)
.ToList();
}
Hope it helps.
Thanks
3 Likes
Thakyou so much for your guidance