Prasad Gavande
Prasad Gavande

Reputation: 249

Convert one minute candle data to five minute candle with C#

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

enter image description here

but I cross checked with broker data, values does not get matches

enter image description here

Am I missing something or there might be other way of converting one minute candle to five minutes candle?

Upvotes: 0

Views: 767

Answers (1)

小小东
小小东

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

Related Questions