private static void ConvertAndResampleSymbol(string sourceDir, string destDir, string symbol, TimeSpan frequency)
        {
            string sourcePath = Path.Combine(sourceDir, $"{symbol}.txt");

            var resampler = new BarDataResampler(frequency);

            resampler.AddRange(Kibot.EnumerateBars(sourcePath));
            resampler.Finish();

            var barData = new List <BarData>();

            foreach (var bar in resampler.Data)
            {
                if (barData.Count > 0 && bar.Timestamp.Year != barData[0].Timestamp.Year)
                {
                    string destPath = Path.Combine(destDir, $"{symbol}_{barData[0].Timestamp.Year}.bar");
                    Zorro.Save(destPath, barData, Zorro.DataFormat.Bar);
                    barData.Clear();
                }

                barData.Add(bar);
            }

            if (barData.Count > 0)
            {
                var destPath = Path.Combine(destDir, $"{symbol}_{barData[0].Timestamp.Year}.bar");
                Zorro.Save(destPath, barData, Zorro.DataFormat.Bar);
            }
        }
Beispiel #2
0
        public void Run()
        {
            var pointValues = new Dictionary <string, double>();

            pointValues.Add("EURUSD", 0.00001);
            pointValues.Add("AUDUSD", 0.00001);
            pointValues.Add("GBPUSD", 0.00001);
            pointValues.Add("NZDUSD", 0.00001);
            pointValues.Add("USDCAD", 0.00001);
            pointValues.Add("USDCHF", 0.00001);
            pointValues.Add("USDJPY", 0.001);

            pointValues.Add("AUDJPY", 0.001);
            pointValues.Add("CHFJPY", 0.001);
            pointValues.Add("EURCAD", 0.00001);
            pointValues.Add("EURCHF", 0.00001);
            pointValues.Add("EURGBP", 0.00001);
            pointValues.Add("EURJPY", 0.001);
            pointValues.Add("GBPCHF", 0.00001);
            pointValues.Add("GBPJPY", 0.001);
            pointValues.Add("NZDJPY", 0.001);

            var symbols = new string[]
            {
                "EURUSD"
            };

            var dukascopy = new Dukascopy(@"E:\HistoricalData\Dukascopy");

            foreach (var symbol in symbols)
            {
                DateTime fromDateTime = new DateTime(2001, 1, 1);
                DateTime toDateTime   = DateTime.UtcNow;

                //////////////////////////////////////////////////
                // Resample data

                // Load bid prices and resample to M1 bars
                Console.WriteLine($"Loading and resampling bid bars for {symbol}");
                var resampler1 = new BarDataResampler(new TimeSpan(0, 1, 0));
                resampler1.AddRange(dukascopy.LoadBars(symbol, pointValues[symbol], fromDateTime, toDateTime, bidPrices: true));
                resampler1.Finish();
                var bidBars = resampler1.Data;

                // Load ask prices and resample to M1 bars
                Console.WriteLine($"Loading and resampling ask bars for {symbol}");
                var resampler2 = new BarDataResampler(new TimeSpan(0, 1, 0));
                resampler2.AddRange(dukascopy.LoadBars(symbol, pointValues[symbol], fromDateTime, toDateTime, bidPrices: false));
                resampler2.Finish();
                var askBars = resampler2.Data;

                // Compute spread
                var spread = new List <BarData>();
                for (int i = 0; i < bidBars.Count; i++)
                {
                    double value = askBars[i].Close - bidBars[i].Close;
                    spread.Add(new BarData()
                    {
                        Timestamp = askBars[i].Timestamp, Open = value, High = value, Low = value, Close = value
                    });
                }

                //////////////////////////////////////////////////
                // Save data to Zorro format

                string zorroDir = @"E:\HistoricalData\Zorro";
                Directory.CreateDirectory(zorroDir);

                // Save to Zorro .bar format.
                Console.WriteLine($"Saving Zorro .bar data for {symbol}");
                Helper.SaveZorroBarData(zorroDir, symbol, askBars, Zorro.DataFormat.Bar);

                // Save spread data to Zorro .bar format for special symbol.
                Console.WriteLine($"Saving Zorro .bar spread data for {symbol}s");
                Helper.SaveZorroBarData(zorroDir, symbol + "s", spread, Zorro.DataFormat.Bar);

                //// Save to Zorro T1 format (price + spread)
                //Console.WriteLine($"Saving Zorro T1 data for {symbol}");
                //SaveZorroT1Data(dukascopy, symbol, pointValues[symbol]);

                //////////////////////////////////////////////////
                // Save data to ForexTester format

                // Save to ForexTester format (can be easily loaded in MT4)
                //Console.WriteLine($"Saving ForexTester M1 data for {symbol}");
                //Directory.CreateDirectory("ForexTester");
                //ForexTester.Save(Path.Combine("ForexTester", symbol + ".csv"), symbol, bidBars);
            }
        }