Reputation: 249
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
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?
Upvotes: 0
Views: 767
Reputation: 1
what i understand is the minutes in the reqired data are multiples of 5, so can use the 'Where' in stead of 'GroupBy'
Upvotes: -1