Beispiel #1
0
		public bool AppendTick(Tick tick)
		{
			if ((Ticks.Any() && tick.DateTime <= Ticks[Ticks.Count - 1].DateTime))
				throw new Exception("Appended tick time is lower then last");

			if ((tick.DateTime - Ticks.First().DateTime).TotalMinutes > PeriodMins)
				return true;
				//throw new Exception("Too long ticks interval");

			Ticks.Add(tick);

			High = Math.Max(tick.Value, High);
			Low = Math.Min(tick.Value, Low);
			Close = tick.Value;

			return false;
		}
        public Candle AddTick(Tick tick)
        {
            try
            {
                if (candle.AppendTick(tick))
                {
                    var res = candle;
                    candle = new Candle(new List<Tick> { tick }, periodMins);
                    return res;
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex);
            }

            return candle;
        }
        public static List<Tick> ReadTicks(string filename)
        {
            var readed = File.ReadAllLines(filename);
            var result = new List<Tick>();
            var lastTick = new Tick(new DateTime(), 0);

            foreach (var row in readed)
            {
                var nextTick = ParseTick(row);

                if (nextTick.Equals(lastTick))
                    continue;

                lastTick = nextTick;
                result.Add(nextTick);
            }

            return result;
        }
        private static Tick ParseTick(string row)
        {
            var fields = row.Split('\t');

            var dateTime = ParseDateTime(fields[0], fields[1]);

            var nextTick = new Tick(dateTime, (int)decimal.Parse(fields[2], new CultureInfo("en-us")));
            return nextTick;
        }