Exemple #1
0
        public void Waves1()
        {
            var statName  = System.Reflection.MethodBase.GetCurrentMethod().Name;
            var dateStart = DateTime.Parse("07/20/2009 12:00");
            var dateEnd   = dateStart.AddHours(0.5);
            var context   = new ForexEntities();
            var a         = typeof(t_Stat).GetCustomAttributes(typeof(EdmEntityTypeAttribute), true).Cast <EdmEntityTypeAttribute>();

            context.ExecuteStoreCommand("DELETE " + a.First().Name + " WHERE Name={0}", statName);

            var ticks = o2g.GetTicks(o2g.Pair, 12000);
            var t1    = o2g.GetTicks(o2g.Pair, 900);

            ticks = ticks.Union(t1).OrderBars().ToArray();
            ticks.ToList().ForEach(t => t.StartDate = t.StartDate.AddMilliseconds(-t.StartDate.Millisecond));
            var rates = ticks.Cast <Rate>().OrderBars().ToArray();

            Stopwatch timer = Stopwatch.StartNew();

            foreach (var tick in rates.OrderBarsDescending())
            {
                tick.Trend.Volume = rates.Where(TimeSpan.FromMinutes(1), tick).Count();
            }
            Debug.WriteLine("Volumes:" + timer.Elapsed);

            var rsiTicks  = 250;
            var rsiPeriod = TimeSpan.FromMinutes(14);

            timer = Stopwatch.StartNew();
            rates.FillRsis(rsiTicks);
            Debug.WriteLine("FillRsi 1:" + timer.Elapsed);

            timer = Stopwatch.StartNew();
            rates.Rsi(rsiTicks, (r, v) => r.PriceAvg1 = (double)v, r => r.PriceAvg1);
            Debug.WriteLine("FillRsi 2:" + timer.Elapsed);

            timer = Stopwatch.StartNew();
            var rsiStats = rates.RsiStats();

            Debug.WriteLine("RsiStats:" + timer.Elapsed + " " + string.Format("{0:n0}/{1:n0}", rsiStats.Sell, rsiStats.Buy));


            timer = Stopwatch.StartNew();
            rates.SkipWhile(t => !t.PriceRsi.HasValue).ToArray().SetCMA(t => t.PriceRsi.GetValueOrDefault(), 2);
            Debug.WriteLine("CMA:" + timer.Elapsed);


            //var ticks = context.v_Tick.Where(t => t.StartDate >= dateStart && t.StartDate <= dateEnd)
            //  .ToArray().Select((t, i) =>
            //    new Tick(t.StartDate, t.Ask, t.Bid, i, true) { Trend = new BarBase.TrendInfo() { Volume = t.Count.Value } }).ToArray();

            var stats = context.t_Stat;

            rates.Where(t => t.PriceRsi.HasValue && !double.IsNaN(t.PriceRsi.Value)).ToList().ForEach(t =>
                                                                                                      stats.AddObject(new t_Stat()
            {
                Time     = t.StartDate, Name = statName, Price = t.PriceAvg
                , Value1 = t.PriceAvg1
                , Value2 = 0
                ,
                Value3 = t.PriceRsi.Value
            }));
            context.SaveChanges();


            //timer = Stopwatch.StartNew();
            //var waves = ticks.FindWaves(3);
            //Debug.WriteLine("FindWaves(3):"+timer.Elapsed);

            //waves.ToList().ForEach(w => Debug.WriteLine(w));
        }