/// <summary>
        /// Parses the input data file.
        /// </summary>
        /// <param name="dataFile">The data file as string.</param>
        /// <param name="regexDataFile">The compiled regex.</param>
        /// <param name="period">The period of data file.</param>
        /// <returns>Returns a parsed bar array.</returns>
        private List<Bar> ParseInput(string dataFile, Regex regexDataFile, int period)
        {
            var barList = new List<Bar>();

            string line;
            var stringReader = new StringReader(dataFile);

            while ((line = stringReader.ReadLine()) != null)
            {
                Match match = regexDataFile.Match(line);
                if (!match.Success) continue;

                int year = int.Parse(match.Groups["year"].Value);
                year = CorrectProblemYear2000(year);
                int month = int.Parse(match.Groups["month"].Value);
                int day   = int.Parse(match.Groups["day"].Value);
                int hour  = 0;
                int min   = 0;
                int sec   = 0;
                if (!isOptionalDataFile)
                {
                    hour = int.Parse(match.Groups["hour"].Value);
                    min  = int.Parse(match.Groups["min"].Value);
                    string seconds = match.Groups["sec"].Value;
                    sec  = (seconds == "" ? 0 : int.Parse(seconds));
                }
                var time = new DateTime(year, month, day, hour, min, sec);

                if (Configs.CutSatSunData && IsSatSun(time))
                    continue;
                if(!CheckTimePeriod(time, period))
                    continue;

                var bar = new Bar
                              {
                                  Time = time,
                                  Open = ParseDouble(match.Groups["open"].Value),
                                  High = ParseDouble(match.Groups["high"].Value),
                                  Low = ParseDouble(match.Groups["low"].Value),
                                  Close = ParseDouble(match.Groups["close"].Value),
                                  Volume = int.Parse(match.Groups["volume"].Value)
                              };
                barList.Add(bar);
            }

            stringReader.Close();

            if (barList.Count == 0)
                throw new Exception(Language.T("Could not count the data bars!"));

            return barList;
        }
        /// <summary>
        ///     Refines the market data
        /// </summary>
        private void RefineData()
        {
            // Fill In data gaps
            if (Configs.FillInDataGaps)
            {
                for (int bar = 1; bar < Bars; bar++)
                {
                    if (aBar[bar - 1].Time.DayOfWeek > DayOfWeek.Wednesday &&
                        aBar[bar].Time.DayOfWeek < DayOfWeek.Wednesday)
                        continue;
                    aBar[bar].Open = aBar[bar - 1].Close;
                    if (aBar[bar].Open > aBar[bar].High || aBar[bar].Close > aBar[bar].High)
                        aBar[bar].High = aBar[bar].Open > aBar[bar].Close ? aBar[bar].Open : aBar[bar].Close;
                    if (aBar[bar].Open < aBar[bar].Low || aBar[bar].Close < aBar[bar].Low)
                        aBar[bar].Low = aBar[bar].Open < aBar[bar].Close ? aBar[bar].Open : aBar[bar].Close;
                }
            }

            // Cuts off the bad data
            if (Configs.CutBadData)
            {
                int maxConsecutiveBars = 0;
                int maxConsecutiveBar = 0;
                int consecutiveBars = 0;
                int lastBar = 0;

                for (int bar = 0; bar < Bars; bar++)
                {
                    if (Math.Abs(aBar[bar].Open - aBar[bar].Close) < Data.InstrProperties.Point/2)
                    {
                        if (lastBar == bar - 1 || lastBar == 0)
                        {
                            consecutiveBars++;
                            lastBar = bar;

                            if (consecutiveBars > maxConsecutiveBars)
                            {
                                maxConsecutiveBars = consecutiveBars;
                                maxConsecutiveBar = bar;
                            }
                        }
                    }
                    else
                    {
                        consecutiveBars = 0;
                    }
                }

                if (maxConsecutiveBars < 10)
                    maxConsecutiveBar = 0;

                int firstBar = Math.Max(maxConsecutiveBar, 1);
                for (int bar = firstBar; bar < Bars; bar++)
                    if ((Time(bar) - Time(bar - 1)).Days > 5 && Period < 10080)
                        firstBar = bar;

                if (firstBar == 1)
                    firstBar = 0;

                if (firstBar > 0 && Bars - firstBar > Configs.MinBars)
                {
                    var aBarCopy = new Bar[Bars];
                    aBar.CopyTo(aBarCopy, 0);

                    aBar = new Bar[Bars - firstBar];
                    for (int bar = firstBar; bar < Bars; bar++)
                        aBar[bar - firstBar] = aBarCopy[bar];

                    Bars = Bars - firstBar;
                    Cut = true;
                }
            }
        }
        /// <summary>
        ///     Data Horizon - Cuts some data
        /// </summary>
        private void DataHorizon()
        {
            if (Bars < Configs.MinBars) return;

            int startBar = 0;
            int endBar = Bars - 1;

            // Set the starting date
            if (UseStartTime && aBar[0].Time < StartTime)
            {
                for (int bar = 0; bar < Bars; bar++)
                {
                    if (aBar[bar].Time >= StartTime)
                    {
                        startBar = bar;
                        break;
                    }
                }
            }

            // Set the end date
            if (UseEndTime && aBar[Bars - 1].Time > EndTime)
            {
                // We need to cut out the newest bars
                for (int bar = 0; bar < Bars; bar++)
                {
                    if (aBar[bar].Time >= EndTime)
                    {
                        endBar = bar - 1;
                        break;
                    }
                }
            }

            if (endBar - startBar > MaxBars - 1)
            {
                startBar = endBar - MaxBars + 1;
            }

            if (endBar - startBar < Configs.MinBars)
            {
                startBar = endBar - Configs.MinBars + 1;
                if (startBar < 0)
                {
                    startBar = 0;
                    endBar = Configs.MinBars - 1;
                }
            }

            // Cut the data
            if (startBar > 0 || endBar < Bars - 1)
            {
                var aBarCopy = new Bar[Bars];
                aBar.CopyTo(aBarCopy, 0);

                int newBars = endBar - startBar + 1;

                aBar = new Bar[newBars];
                for (int bar = startBar; bar <= endBar; bar++)
                    aBar[bar - startBar] = aBarCopy[bar];

                Bars = newBars;
                Update = aBar[newBars - 1].Time.AddMinutes(Period);
                Cut = true;
            }
        }
        /// <summary>
        /// Parses the input data file.
        /// </summary>
        /// <param name="dataFile">The data file as string.</param>
        /// <param name="regexDataFile">The compiled regex.</param>
        /// <param name="period">The period of data file.</param>
        /// <returns>Returns a parsed bar array.</returns>
        private List <Bar> ParseInput(string dataFile, Regex regexDataFile, int period)
        {
            var barList = new List <Bar>();

            string line;
            var    stringReader = new StringReader(dataFile);

            while ((line = stringReader.ReadLine()) != null)
            {
                Match match = regexDataFile.Match(line);
                if (!match.Success)
                {
                    continue;
                }

                int year = int.Parse(match.Groups["year"].Value);
                year = CorrectProblemYear2000(year);
                int month = int.Parse(match.Groups["month"].Value);
                int day   = int.Parse(match.Groups["day"].Value);
                int hour  = 0;
                int min   = 0;
                int sec   = 0;
                if (!isOptionalDataFile)
                {
                    hour = int.Parse(match.Groups["hour"].Value);
                    min  = int.Parse(match.Groups["min"].Value);
                    string seconds = match.Groups["sec"].Value;
                    sec = (seconds == "" ? 0 : int.Parse(seconds));
                }
                var time = new DateTime(year, month, day, hour, min, sec);

                if (Configs.CutSatSunData && IsSatSun(time))
                {
                    continue;
                }
                if (!CheckTimePeriod(time, period))
                {
                    continue;
                }

                var bar = new Bar
                {
                    Time   = time,
                    Open   = ParseDouble(match.Groups["open"].Value),
                    High   = ParseDouble(match.Groups["high"].Value),
                    Low    = ParseDouble(match.Groups["low"].Value),
                    Close  = ParseDouble(match.Groups["close"].Value),
                    Volume = int.Parse(match.Groups["volume"].Value)
                };
                barList.Add(bar);
            }

            stringReader.Close();

            if (barList.Count == 0)
            {
                throw new Exception(Language.T("Could not count the data bars!"));
            }

            return(barList);
        }