Exemple #1
0
        private void ReadJForexFiles()
        {
            if (!Directory.Exists(tbxDataDirectory.Text))
            {
                return;
            }

            string[] dataFiles = Directory.GetFiles(tbxDataDirectory.Text);
            foreach (string filePath in dataFiles)
            {
                if (Path.GetExtension(filePath) != ".csv")
                {
                    continue;
                }
                var file = new JForexDataFiles(filePath, tbxDestFolder.Text);
                if (file.IsCorrect)
                {
                    files.Add(file);
                }
            }
        }
Exemple #2
0
        private void ImportTicks(JForexDataFiles file)
        {
            var streamReader = new StreamReader(file.FilePath);
            var outStream    = new FileStream(file.FileTargetPath, FileMode.Create);
            var binaryWriter = new BinaryWriter(outStream);

            DateTime time          = DateTime.MinValue;
            int      volume        = 0;
            var      reccord       = new List <double>();
            int      count1MinBars = 1;
            int      totalVolume   = 0;

            string dateFormat = "#";
            char   delimiter  = '#';

            try
            {
                while (!streamReader.EndOfStream)
                {
                    string line = streamReader.ReadLine();
                    if (line != null && line.StartsWith("Time"))
                    {
                        continue; // Skips annotation line.
                    }
                    if (line != null)
                    {
                        if (delimiter == '#')
                        {
                            delimiter = FindDelimiter(line);
                        }

                        string[] data = line.Split(new[] { delimiter });

                        if (dateFormat == "#")
                        {
                            dateFormat = FindDateFormat(data[0] + " " + data[1]);
                        }

                        DateTime t        = ParseDateWithoutSeconds(data[0] + " " + data[1], dateFormat);
                        var      tickTime = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute, 0);
                        double   bid      = StringToDouble(data[2]);

                        if (tickTime.Minute != time.Minute || volume == 0)
                        {
                            if (volume > 0 && !IsWeekend(time))
                            {
                                FilterReccord(reccord);
                                SaveReccord(binaryWriter, time, volume, reccord);
                                count1MinBars++;
                            }

                            time   = tickTime;
                            volume = 0;
                            reccord.Clear();
                            reccord.Add(bid);
                        }
                        else if (reccord.Count > 0 && Math.Abs(bid - reccord[reccord.Count - 1]) > 0.000001)
                        {
                            reccord.Add(bid);
                        }
                    }

                    volume++;
                    totalVolume++;
                }
                if (volume > 0 && !IsWeekend(time))
                {
                    FilterReccord(reccord);
                    SaveReccord(binaryWriter, time, volume, reccord);
                    count1MinBars++;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            streamReader.Close();
            binaryWriter.Close();
            outStream.Close();

            totalVolume--;
            count1MinBars--;

            SetInfoText(file.Symbol + " " + Language.T("Ticks") + " - " + (Language.T("Ticks")).ToLower() + ": " +
                        totalVolume + " - 1M " + (Language.T("Bars")).ToLower() + ": " + count1MinBars +
                        Environment.NewLine);
        }
Exemple #3
0
        private void ImportBarFile(JForexDataFiles file)
        {
            var    streamReader = new StreamReader(file.FilePath);
            var    streamWriter = new StreamWriter(file.FileTargetPath);
            string dateFormat   = "#";
            char   delimiter    = '#';
            int    bars         = 0;

            try
            {
                while (!streamReader.EndOfStream)
                {
                    string line = streamReader.ReadLine();
                    if (line == null)
                    {
                        continue;
                    }
                    if (line.StartsWith("Time"))
                    {
                        continue; // Skips annotation line.
                    }
                    if (delimiter == '#')
                    {
                        delimiter = FindDelimiter(line);
                    }

                    string[] data = line.Split(new[] { delimiter });

                    string timeInput = data.Length == 6 ? data[0] : data[0] + " " + data[1];

                    if (dateFormat == "#")
                    {
                        dateFormat = FindDateFormat(timeInput);
                    }


                    DateTime time   = ParseDateWithoutSeconds(timeInput, dateFormat);
                    double   open   = StringToDouble(data[data.Length - 5]);
                    double   high   = StringToDouble(data[data.Length - 4]);
                    double   low    = StringToDouble(data[data.Length - 3]);
                    double   close  = StringToDouble(data[data.Length - 2]);
                    var      volume = (int)StringToDouble(data[data.Length - 1]);

                    if (Math.Abs(open - high) < 0.000001 &&
                        Math.Abs(open - low) < 0.000001 &&
                        Math.Abs(open - close) < 0.000001)
                    {
                        continue;
                    }

                    streamWriter.WriteLine(time.ToString("yyyy-MM-dd\tHH:mm") + "\t" +
                                           open + "\t" + high + "\t" + low + "\t" + close + "\t" + volume);
                    bars++;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            streamWriter.Close();
            streamReader.Close();
            SetInfoText(file.Symbol + " " + Data.DataPeriodToString((DataPeriod)file.Period) + " - " +
                        (Language.T("Bars")).ToLower() + ": " + bars + Environment.NewLine);
        }
        private void ReadJForexFiles()
        {
            if (!Directory.Exists(tbxDataDirectory.Text))
                return;

            string[] dataFiles = Directory.GetFiles(tbxDataDirectory.Text);
            foreach (string filePath in dataFiles)
            {
                if (Path.GetExtension(filePath) != ".csv") continue;
                var file = new JForexDataFiles(filePath, tbxDestFolder.Text);
                if (file.IsCorrect)
                    files.Add(file);
            }
        }
        private void ImportTicks(JForexDataFiles file)
        {
            var streamReader = new StreamReader(file.FilePath);
            var outStream = new FileStream(file.FileTargetPath, FileMode.Create);
            var binaryWriter = new BinaryWriter(outStream);

            DateTime time = DateTime.MinValue;
            int volume = 0;
            var reccord = new List<double>();
            int count1MinBars = 1;
            int totalVolume = 0;

            string dateFormat = "#";
            char delimiter = '#';

            try
            {
                while (!streamReader.EndOfStream)
                {
                    string line = streamReader.ReadLine();
                    if (line != null && line.StartsWith("Time"))
                        continue; // Skips annotation line.
                    if (line != null)
                    {
                        if (delimiter == '#')
                            delimiter = FindDelimiter(line);

                        string[] data = line.Split(new[] {delimiter});

                        if (dateFormat == "#")
                            dateFormat = FindDateFormat(data[0] + " " + data[1]);

                        DateTime t = ParseDateWithoutSeconds(data[0] + " " + data[1], dateFormat);
                        var tickTime = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute, 0);
                        double bid = StringToDouble(data[2]);

                        if (tickTime.Minute != time.Minute || volume == 0)
                        {
                            if (volume > 0 && !IsWeekend(time))
                            {
                                FilterReccord(reccord);
                                SaveReccord(binaryWriter, time, volume, reccord);
                                count1MinBars++;
                            }

                            time = tickTime;
                            volume = 0;
                            reccord.Clear();
                            reccord.Add(bid);
                        }
                        else if (reccord.Count > 0 && Math.Abs(bid - reccord[reccord.Count - 1]) > 0.000001)
                        {
                            reccord.Add(bid);
                        }
                    }

                    volume++;
                    totalVolume++;
                }
                if (volume > 0 && !IsWeekend(time))
                {
                    FilterReccord(reccord);
                    SaveReccord(binaryWriter, time, volume, reccord);
                    count1MinBars++;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            streamReader.Close();
            binaryWriter.Close();
            outStream.Close();

            totalVolume--;
            count1MinBars--;

            SetInfoText(file.Symbol + " " + Language.T("Ticks") + " - " + (Language.T("Ticks")).ToLower() + ": " +
                        totalVolume + " - 1M " + (Language.T("Bars")).ToLower() + ": " + count1MinBars +
                        Environment.NewLine);
        }
        private void ImportBarFile(JForexDataFiles file)
        {
            var streamReader = new StreamReader(file.FilePath);
            var streamWriter = new StreamWriter(file.FileTargetPath);
            string dateFormat = "#";
            char delimiter = '#';
            int bars = 0;

            try
            {
                while (!streamReader.EndOfStream)
                {
                    string line = streamReader.ReadLine();
                    if (line == null) continue;
                    if (line.StartsWith("Time"))
                        continue; // Skips annotation line.

                    if (delimiter == '#')
                        delimiter = FindDelimiter(line);

                    string[] data = line.Split(new[] {delimiter});

                    string timeInput = data.Length == 6 ? data[0] : data[0] + " " + data[1];

                    if (dateFormat == "#")
                        dateFormat = FindDateFormat(timeInput);

                    DateTime time = ParseDateWithoutSeconds(timeInput, dateFormat);
                    double open = StringToDouble(data[data.Length - 5]);
                    double high = StringToDouble(data[data.Length - 4]);
                    double low = StringToDouble(data[data.Length - 3]);
                    double close = StringToDouble(data[data.Length - 2]);
                    var volume = (int) StringToDouble(data[data.Length - 1]);

                    if (Math.Abs(open - high) < 0.000001 &&
                        Math.Abs(open - low) < 0.000001 &&
                        Math.Abs(open - close) < 0.000001) continue;

                    streamWriter.WriteLine(time.ToString("yyyy-MM-dd\tHH:mm") + "\t" +
                                           open + "\t" + high + "\t" + low + "\t" + close + "\t" + volume);
                    bars++;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            streamWriter.Close();
            streamReader.Close();
            SetInfoText(file.Symbol + " " + Data.DataPeriodToString((DataPeriod) file.Period) + " - " +
                        (Language.T("Bars")).ToLower() + ": " + bars + Environment.NewLine);
        }