Example #1
0
        public void UpdateBar(int index, Bar bar)
        {
            if (index >= Bars) throw new IndexOutOfRangeException("index");

            Time[index] = bar.Time;
            Open[index] = bar.Open;
            High[index] = bar.High;
            Low[index] = bar.Low;
            Close[index] = bar.Close;
            Volume[index] = bar.Volume;
        }
Example #2
0
        /// <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);
            int cutWrongTimeBars = 0;
            LoadingNote = string.Empty;

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

                DateTime time = ParseTime(match);

                if (!CheckTimePeriod(time, period))
                {
                    cutWrongTimeBars++;
                    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("Could not count the data bars!");

            if (cutWrongTimeBars > 0)
                LoadingNote += string.Format("Cut off {0} bars with wrong time.\r\n", cutWrongTimeBars);

            return barList;
        }