Пример #1
0
        /// <summary>
        /// fill bars with arbitrary price data for a symbol
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="prices"></param>
        /// <param name="startdate"></param>
        /// <param name="blt"></param>
        /// <param name="interval"></param>
        /// <param name="debugs"></param>
        /// <returns></returns>
        public static bool backfillbars(string sym, decimal[] prices, int startdate, ref BarListTracker blt, int interval, DebugDelegate debugs)
        {
            // ensure we have closing data
            if (prices.Length == 0)
            {
                if (debugs != null)
                {
                    debugs(sym + " no price data provided/available, will have to wait until bars are created from market.");
                }
                return(false);
            }
            // get start day
            int date = startdate;
            // make desired numbers of ticks
            DateTime n  = DateTime.Now;
            bool     ok = true;

            for (int i = prices.Length - 1; i >= 0; i--)
            {
                // get time now - exitlen*60
                int  nt = Util.ToTLTime(n.Subtract(new TimeSpan(0, i * interval, 0)));
                Tick k  = TickImpl.NewTrade(sym, date, nt, prices[i], 100, string.Empty);
                ok &= k.isValid && k.isTrade;
                blt.newTick(k);
            }
            if (ok && (debugs != null))
            {
                debugs(sym + " bars backfilled using: " + Calc.parray(prices));
            }
            return(ok);
        }
Пример #2
0
        /// <summary>
        /// convert a bar into an array of ticks
        /// </summary>
        /// <param name="bar"></param>
        /// <returns></returns>
        public static Tick[] ToTick(Bar bar)
        {
            if (!bar.isValid)
            {
                return(new Tick[0]);
            }
            List <Tick> list = new List <Tick>();

            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime, bar.Open,
                                       (int)((double)bar.Volume / 4), string.Empty));
            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime,
                                       bar.High, (int)((double)bar.Volume / 4), string.Empty));
            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime, bar.Low,
                                       (int)((double)bar.Volume / 4), string.Empty));
            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime,
                                       bar.Close, (int)((double)bar.Volume / 4), string.Empty));
            return(list.ToArray());
        }