5

I am getting once minute data (OHLC) from a data feed (lmax) and I want to re-sample this to a five minute data and ten, fifteen and thirty later on.

I'm using the following logic:

Open=first value of every 5 candles (1st candle open)

High=Highest value of 5 candle

Low=Lowest value of 5 candles

Close=Close of the last candle (5th candle)

Is this the correct way to re-sample data? I feel that this is logical but for some reason there are visible differences between the data feed on their site and my code. I feel that this is the case because I re-sampled it wrong; if i was using Python, I could refer to pandas but not in C# (to my knowledge).

This is the function which resamples the data:

private static List<List<double>> normalize_candles(List<List<double>> indexed_data, int n)
        {
            double open = 0;
            double high = 0;
            double low = 5;
            double close = 0;
            int trunc = 0;
            if (indexed_data.Count() % n != 0)
            {
                trunc = indexed_data.Count() % n;
                for (int i = 0; i < trunc; i++)
                {
                    indexed_data.RemoveAt(indexed_data.Count() - 1);
                }
            }
            {

            }
            List<List<double>> normal_candle_data = new List<List<double>>();
            for (int i = 0; i < indexed_data.Count() / n; i++)
            {
                high = 0;
                low = 100;
                open = indexed_data[i * n][0];
                close = indexed_data[(i * n) + (n - 1)][3];
                for (int j = 0; j < n; j++)
                {
                    if (high < indexed_data[(i * n) + j][1])
                    {
                        high = indexed_data[(i * n) + j][1];
                    }
                    if (low > indexed_data[(i * n) + j][2])
                    {
                        low = indexed_data[(i * n) + j][2];
                    }

                }
                normal_candle_data.Add(new List<double>());
                normal_candle_data[i].Add(open);
                normal_candle_data[i].Add(high);
                normal_candle_data[i].Add(low);
                normal_candle_data[i].Add(close);

            }
            Console.WriteLine("\n\n");
            foreach (var obj in normal_candle_data)
            {

                Console.WriteLine(obj[0] + "," + obj[1] + "," + obj[2] + "," + obj[3]);

            }
            Console.WriteLine("size of orignal data is : " + indexed_data.Count() + "\nSize of normalized data is : " + normal_candle_data.Count());
            return normal_candle_data;



        }
game coder
  • 129
  • 7

0 Answers0