I have open, low, close, high, volume and dateTime of one minute candle, I want to convert that one minute candle to five minute candle
My initial thought about converting one minute candle data to five minute is as below, take 5 candle's of one minute
- 5 minute candle open = first candle's open value
- 5 minute candle high = Max of high values in one minute's 5 candles
- 5 minute candle low = Min of high values in one minute's 5 candles
- 5 minute candle open = last candle's close value
- 5 minute candle volume = sum of all one minute candle's volume
I have created below function to convert the candle
public static List<CandleData> ConvertCandlesTimeFrame1(List<CandleData> candleData, int minutes)
{
return candleData
.GroupBy(x => new DateTime(x.Date.Year, x.Date.Month, x.Date.Day, x.Date.Hour, x.Date.Minute / minutes * minutes, 0))
.Select(g => new CandleData
{
Date = g.Key,
Open = g.First().Open,
High = g.Max(x => x.High),
Low = g.Min(x => x.Low),
Close = g.Last().Close,
Volume = g.Sum(x => x.Volume)
})
.ToList();
}
Above program gives correct output as per my expectations as below
but I cross checked with broker data, values does not get matches
Am I missing something or there might be other way of converting one minute candle to five minutes candle?


what i understand is the minutes in the reqired data are multiples of 5, so can use the 'Where' in stead of 'GroupBy'