Exemplo n.º 1
0
        void ImportBarFile(JForex_Data_Files file)
        {
            StreamReader streamReader = new StreamReader(file.FilePath);
            StreamWriter streamWriter = new StreamWriter(file.FileTargetPath);

            string dateFormat;

            dateFormat = "yyyy.MM.dd HH:mm:ss";

            char            fieldSplitter  = ',';
            IFormatProvider formatProvider = System.Globalization.CultureInfo.InvariantCulture;
            string          line           = "";
            int             bars           = 0;

            try
            {
                while (!streamReader.EndOfStream)
                {
                    line = streamReader.ReadLine();
                    if (line.StartsWith("Time"))
                    {
                        continue; // Skips annotation line.
                    }
                    string[] data = line.Split(new char[] { fieldSplitter });

                    DateTime time   = DateTime.ParseExact(data[0], dateFormat, formatProvider);
                    double   open   = StringToDouble(data[1]);
                    double   high   = StringToDouble(data[2]);
                    double   low    = StringToDouble(data[3]);
                    double   close  = StringToDouble(data[4]);
                    int      volume = (int)StringToDouble(data[5]);

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

            streamWriter.Close();
            streamReader.Close();
            SetInfoText(file.Symbol + " " + Data.DataPeriodToString((DataPeriods)file.Period) + " - " +
                        (Language.T("Bars")).ToLower() + ": " + bars.ToString() + Environment.NewLine);
        }
Exemplo n.º 2
0
        void ReadJForexFiles()
        {
            if (!Directory.Exists(txbDataDirectory.Text))
            {
                return;
            }

            string[] dataFiles = Directory.GetFiles(txbDataDirectory.Text);
            foreach (string filePath in dataFiles)
            {
                if (Path.GetExtension(filePath) == ".csv")
                {
                    JForex_Data_Files file = new JForex_Data_Files(filePath);
                    if (file.IsCorrect)
                    {
                        files.Add(file);
                    }
                }
            }
        }
Exemplo n.º 3
0
        void ImportTicks(JForex_Data_Files file)
        {
            StreamReader streamReader = new StreamReader(file.FilePath);
            FileStream   outStream    = new FileStream(file.FileTargetPath, FileMode.Create);
            BinaryWriter binaryWriter = new BinaryWriter(outStream);

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

            string dateFormat = "yyyy.MM.dd HH:mm:ss";

            char fieldSplitter = ',';

            IFormatProvider formatProvider = System.Globalization.CultureInfo.InvariantCulture;
            string          line           = "";

            try
            {
                DateTime tickTime;
                double   bid;
                while (!streamReader.EndOfStream)
                {
                    line = streamReader.ReadLine();
                    if (line.StartsWith("Time"))
                    {
                        continue; // Skips annotation line.
                    }
                    string[] data = line.Split(new char[] { fieldSplitter });
                    DateTime t    = DateTime.ParseExact(data[0], dateFormat, formatProvider);
                    tickTime = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute, 0);
                    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 && bid != reccord[reccord.Count - 1])
                    {
                        reccord.Add(bid);
                    }

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

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

            volume--;
            totalVolume--;
            count1MinBars--;

            SetInfoText(file.Symbol + " " + Language.T("Ticks") + " - " + (Language.T("Ticks")).ToLower() + ": " + totalVolume.ToString()
                        + " - 1M " + (Language.T("Bars")).ToLower() + ": " + count1MinBars.ToString() + Environment.NewLine);
        }
        void ReadJForexFiles()
        {
            if (!Directory.Exists(txbDataDirectory.Text))
                return;

            string[] dataFiles = Directory.GetFiles(txbDataDirectory.Text);
            foreach (string filePath in dataFiles)
            {
                if(Path.GetExtension(filePath) == ".csv")
                {
                    JForex_Data_Files file = new JForex_Data_Files(filePath);
                    if (file.Period > -1)
                        files.Add(file);
                }
            }
        }
        void ImportTicks(JForex_Data_Files file)
        {
            StreamReader streamReader = new StreamReader(file.FilePath);
            FileStream   outStream    = new FileStream(file.FileTargetPath, FileMode.Create);
            BinaryWriter binaryWriter = new BinaryWriter(outStream);

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

            string dateFormat = "yyyy.MM.dd HH:mm:ss";

            char fieldSplitter = ',';

            IFormatProvider formatProvider = System.Globalization.CultureInfo.InvariantCulture;
            string line = "";

            try
            {
                DateTime tickTime;
                double bid;
                while (!streamReader.EndOfStream)
                {
                    line = streamReader.ReadLine();
                    if (line.StartsWith("Time"))
                        continue; // Skips annotation line.
                    string[] data = line.Split(new char[] { fieldSplitter });
                    DateTime t = DateTime.ParseExact(data[0], dateFormat, formatProvider);
                    tickTime = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute, 0);
                    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 && bid != reccord[reccord.Count - 1])
                    {
                        reccord.Add(bid);
                    }

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

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

            volume--;
            totalVolume--;
            count1MinBars--;

            SetInfoText(file.Symbol + " " + Language.T("Ticks") + " - " + (Language.T("Ticks")).ToLower() + ": " + totalVolume.ToString()
                 + " - 1M " + (Language.T("Bars")).ToLower() + ": " + count1MinBars.ToString() + Environment.NewLine);
        }
        void ImportBarFile(JForex_Data_Files file)
        {
            StreamReader streamReader = new StreamReader(file.FilePath);
            StreamWriter streamWriter = new StreamWriter(file.FileTargetPath);

            string dateFormat;
            dateFormat = "yyyy.MM.dd HH:mm:ss";

            char fieldSplitter = ',';
            IFormatProvider formatProvider = System.Globalization.CultureInfo.InvariantCulture;
            string line = "";
            int bars = 0;

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

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

                    DateTime time   = DateTime.ParseExact(data[0], dateFormat, formatProvider);
                    double   open   = StringToDouble(data[1]);
                    double   high   = StringToDouble(data[2]);
                    double   low    = StringToDouble(data[3]);
                    double   close  = StringToDouble(data[4]);
                    int      volume = (int)StringToDouble(data[5]);

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

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