Exemplo n.º 1
0
        private static BarList DayFromURL(string url, string Symbol, bool appendAMEXonfail)
        {
            BarListImpl bl = new BarListImpl(BarInterval.Day, Symbol);

            if (Symbol == "")
            {
                return(bl);
            }
            System.Net.WebClient wc = new System.Net.WebClient();
            string res = "";

            try
            {
                res = wc.DownloadString(url + Symbol);
            }
            catch (Exception)
            {
                if (appendAMEXonfail)
                {
                    return(DayFromURL(url, Symbol + AMEX, false));
                }
                return(bl);
            }
            string[] line = res.Split(Environment.NewLine.ToCharArray());
            for (int i = line.Length - 1; i > 0; i--)
            {
                if (line[i] != "")
                {
                    addbar(bl, BarImpl.FromCSV(line[i]), 0);
                }
            }
            return(bl);
        }
Exemplo n.º 2
0
        /// <summary>
        /// insert a bar at particular place in the list.
        /// REMEMBER YOU MUST REHANDLE GOTNEWBAR EVENT AFTER CALLING THIS.
        /// </summary>
        /// <param name="bl"></param>
        /// <param name="b"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public static BarListImpl InsertBar(BarList bl, Bar b, int position)
        {
            BarListImpl copy = new BarListImpl(bl);

            for (int j = 0; j < bl.CustomIntervals.Length; j++)
            {
                if (bl.CustomIntervals[j] != b.Interval)
                {
                    continue;
                }
                int count = bl.IntervalCount(b.Interval);
                if (count != 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (i == position)
                        {
                            addbar(copy, b, j);
                        }
                        addbar(copy, bl[i, (BarInterval)b.Interval], j);
                    }
                }
                else
                {
                    addbar(copy, b, 0);
                }
            }
            return(copy);
        }
Exemplo n.º 3
0
        static void wc_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {
            string          res = string.Empty;
            BarListDownload bld = (BarListDownload)e.UserState;

            if (!bld.isValid)
            {
                return;
            }
            if (e.Cancelled || (e.Error != null))
            {
                if (bld.AppendAMEXonFail)
                {
                    DayFromGoogleAsync(bld.Symbol + AMEX, bld.DoResults, false);
                    return;
                }
                bld.DoResults(new BarListImpl(BarInterval.Day, bld.Symbol));
                return;
            }
            res = e.Result;
            BarListImpl bl = new BarListImpl(BarInterval.Day, bld.Symbol);

            string[] line = res.Split(Environment.NewLine.ToCharArray());
            for (int i = line.Length - 1; i > 0; i--)
            {
                if (line[i] != "")
                {
                    addbar(bl, BarImpl.FromCSV(line[i]), 0);
                }
            }
            bld.DoResults(bl);
        }
Exemplo n.º 4
0
        /// <summary>
        /// insert one barlist into another barlist
        /// REMEMBER: You must re-handle the GotNewBar event after calling this method.
        /// You should also ensure that inserted barlist has same intervals/types as original barlist.
        /// </summary>
        /// <param name="bl"></param>
        /// <param name="insert"></param>
        /// <returns></returns>
        public static BarListImpl InsertBarList(BarList bl, BarList insert)
        {
            BarListImpl copy = new BarListImpl(bl);

            for (int j = 0; j < bl.CustomIntervals.Length; j++)
            {
                for (int k = 0; k < insert.CustomIntervals.Length; k++)
                {
                    if (bl.CustomIntervals[j] != insert.CustomIntervals[k])
                    {
                        continue;
                    }
                    for (int l = 0; l < insert.Count; l++)
                    {
                        for (int m = 0; m < bl.Count; m++)
                        {
                            if (l == m)
                            {
                                addbar(copy, insert[l, (BarInterval)insert.CustomIntervals[k]], j);
                            }
                            addbar(copy, bl[m], j);
                        }
                    }
                }
            }
            return(copy);
        }
Exemplo n.º 5
0
        public void Hours()
        {

            System.IO.StreamReader sr = new System.IO.StreamReader("TestWAG.txt");
            sr.ReadLine();
            sr.ReadLine();

            BarListImpl bl = new BarListImpl(BarInterval.Hour, "WAG");
            Tick k = new TickImpl();
            int tickcount = 0;
            while (!sr.EndOfStream) 
            {
                k = eSigTick.FromStream(bl.Symbol, sr);
                if (tickcount == 0)
                {
                    Assert.IsTrue(k.isValid);
                    Assert.AreEqual(20070926041502, k.datetime);
                    Assert.AreEqual(20070926, k.date);
                    Assert.AreEqual(041502, k.time);
                    Assert.AreEqual(43.81m, k.bid);
                    Assert.AreEqual(51.2m, k.ask);
                    Assert.AreEqual(1, k.bs);
                    Assert.AreEqual(1, k.os);
                    Assert.IsTrue(k.be.Contains("PSE"));
                    Assert.IsTrue(k.oe.Contains("PSE"));
                }
                tickcount++;
                bl.newTick(k);
            }
            // hour is what we asked for
            Assert.AreEqual(BarInterval.Hour,bl.DefaultInterval);
            // there are 4 trades on hour intervals, 6/7/8/9
            Assert.AreEqual(4,bl.Count);

        }
Exemplo n.º 6
0
        /// <summary>
        /// attempts to get year worth of daily data from google, if fails tries yahoo.
        /// </summary>
        /// <param name="symbol"></param>
        /// <returns></returns>
        public static BarList DayFromAny(string symbol)
        {
            BarList bl = BarListImpl.DayFromGoogle(symbol);

            if (bl.Count == 0)
            {
                bl = BarListImpl.DayFromYahoo(symbol);
            }
            return(bl);
        }
Exemplo n.º 7
0
 internal static void addbar(BarListImpl b, Bar mybar, int instdataidx)
 {
     b._intdata[instdataidx].Count++;
     b._intdata[instdataidx].closes.Add(mybar.Close);
     b._intdata[instdataidx].opens.Add(mybar.Open);
     b._intdata[instdataidx].dates.Add(mybar.Bardate);
     b._intdata[instdataidx].highs.Add(mybar.High);
     b._intdata[instdataidx].lows.Add(mybar.Close);
     b._intdata[instdataidx].vols.Add(mybar.Volume);
     b._intdata[instdataidx].times.Add(mybar.Bartime);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Build a barlist using an EPF file as the source
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns>barlist</returns>
        public static BarList FromEPF(string filename)
        {
            System.IO.StreamReader sr = new System.IO.StreamReader(filename);
            SecurityImpl           s  = eSigTick.InitEpf(sr);
            BarList b = new BarListImpl(s.Symbol);

            while (!sr.EndOfStream)
            {
                b.newTick(eSigTick.FromStream(s.Symbol, sr));
            }
            return(b);
        }
Exemplo n.º 9
0
 /// <summary>
 /// give any ticks to this symbol and tracker will create barlists automatically 
 /// </summary>
 /// <param name="k"></param>
 public void newTick(Tick k)
 {
     BarListImpl bl;
     if (!_bdict.TryGetValue(k.symbol, out bl))
     {
         bl = new BarListImpl(k.symbol,_requested);
         bl.DefaultInterval = _default;
         bl.GotNewBar+=new SymBarIntervalDelegate(bl_GotNewBar);
         _bdict.Add(k.symbol, bl);
     }
     bl.newTick(k);
 }
Exemplo n.º 10
0
        public static BarList FromTIK(string filename)
        {
            SecurityImpl s = SecurityImpl.FromTIK(filename);

            s.HistSource.gotTick += new TickDelegate(HistSource_gotTick);
            _fromepf              = new BarListImpl(s.Symbol);
            while (s.HistSource.NextTick())
            {
                ;
            }
            return(_fromepf);
        }
Exemplo n.º 11
0
        /// <summary>
        /// add any data point to bar
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="p"></param>
        /// <param name="time"></param>
        /// <param name="date"></param>
        /// <param name="size"></param>
        public void newPoint(string symbol, decimal p, int time, int date, int size)
        {
            BarListImpl bl;

            if (!_bdict.TryGetValue(symbol, out bl))
            {
                bl = new BarListImpl(symbol, _requested, _reqtype);
                bl.DefaultCustomInterval = _default;
                bl.GotNewBar            += new SymBarIntervalDelegate(bl_GotNewBar);
                _bdict.Add(symbol, bl);
            }
            bl.newPoint(p, time, date, size);
        }
Exemplo n.º 12
0
        /// <summary>
        /// give any ticks (trades) to this symbol and tracker will create barlists automatically
        /// </summary>
        /// <param name="k"></param>
        public void newTick(Tick k)
        {
            BarListImpl bl;

            if (!_bdict.TryGetValue(k.symbol, out bl))
            {
                bl = new BarListImpl(k.symbol, _requested, _reqtype);
                bl.DefaultCustomInterval = _default;
                bl.GotNewBar            += new SymBarIntervalDelegate(bl_GotNewBar);
                _bdict.Add(k.symbol, bl);
            }
            bl.newTick(k);
        }
Exemplo n.º 13
0
        /// <summary>
        /// downloads yearly charts for a list of symbols
        /// (source: google finance)
        /// </summary>
        /// <param name="symbols"></param>
        /// <returns></returns>
        public static BarList[] FetchCharts(string[] symbols)
        {
            List <BarList> l = new List <BarList>();

            foreach (string sym in symbols)
            {
                BarList bl = BarListImpl.DayFromGoogle(sym);
                if (bl.isValid)
                {
                    l.Add(bl);
                }
            }
            return(l.ToArray());
        }
Exemplo n.º 14
0
        /// <summary>
        /// create barlist from a tik file using given intervals/types
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="uselast"></param>
        /// <param name="usebid"></param>
        /// <param name="intervals"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public static BarList FromTIK(string filename, bool uselast, bool usebid, int[] intervals, BarInterval[] types)
        {
            _uselast = uselast;
            _usebid  = usebid;
            SecurityImpl s = SecurityImpl.FromTIK(filename);

            s.HistSource.gotTick += new TickDelegate(HistSource_gotTick);
            _fromepf              = new BarListImpl(s.Symbol, intervals, types);
            while (s.HistSource.NextTick())
            {
                ;
            }
            return(_fromepf);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Create a barlist from a succession of bar records provided as comma-delimited OHLC+volume data.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="file">The file containing the CSV records.</param>
        /// <returns></returns>
        public static BarListImpl FromCSV(string symbol, string file)
        {
            BarListImpl b = new BarListImpl(BarInterval.Day, symbol);

            string[] line = file.Split(Environment.NewLine.ToCharArray());
            for (int i = line.Length - 1; i > 0; i--)
            {
                if (line[i] != string.Empty)
                {
                    addbar(b, BarImpl.FromCSV(line[i]), 0);
                }
            }
            return(b);
        }
Exemplo n.º 16
0
        /// <summary>
        /// find the bar # that matches a given time
        /// </summary>
        /// <param name="bl"></param>
        /// <param name="time"></param>
        /// <param name="bint"></param>
        /// <returns></returns>
        public static int GetNearestIntraBar(BarList bl, int time, BarInterval bint)
        {
            long             barid = TimeIntervalData.getbarid(time, bl.RecentBar.Bardate, (int)bint);
            BarListImpl      bli   = (BarListImpl)bl;
            TimeIntervalData tid   = (TimeIntervalData)bli._intdata[bli._intdataidx[(int)bint]];

            for (int i = 0; i < tid.Count(); i++)
            {
                if (tid.ids[i] == barid)
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemplo n.º 17
0
        /// <summary>
        /// gets barlist for a given symbol.   will return an invalid barlist if no ticks have been received for symbol
        /// </summary>
        /// <param name="sym"></param>
        /// <returns></returns>
        public BarList this[string sym]
        {

            get
            {
                BarListImpl bl;
                if (_bdict.TryGetValue(sym, out bl))
                    return (BarList)bl;
                bl = new BarListImpl(sym,_requested);
                bl.DefaultInterval = _default;
                bl.GotNewBar += new SymBarIntervalDelegate(bl_GotNewBar);
                _bdict.Add(sym, bl);
                return bl;
            }
        }
Exemplo n.º 18
0
 public BarList this[string sym, int interval]
 {
     get
     {
         BarListImpl bl;
         if (_bdict.TryGetValue(sym, out bl))
         {
             return((BarList)bl);
         }
         bl = new BarListImpl(sym, _requested, _reqtype);
         bl.DefaultCustomInterval = interval;
         bl.GotNewBar            += new SymBarIntervalDelegate(bl_GotNewBar);
         _bdict.Add(sym, bl);
         return(bl);
     }
 }
Exemplo n.º 19
0
 public void BarMath()
 {
     // get tickdata
     Tick[] tape = SampleData();
     // create bar
     BarList bl = new BarListImpl(BarInterval.Minute);
     // pass ticks to bar
     foreach (Tick k in tape)
         bl.newTick(k);
     // verify HH
     Assert.AreEqual(16, Calc.HH(bl));
     // verify LL
     Assert.AreEqual(10, Calc.LL(bl));
     // verify average
     Assert.AreEqual(11.888888888888888888888888889m, Calc.Avg(bl.Open()));
 }
Exemplo n.º 20
0
        /// <summary>
        /// gets a quandl data object directly from url
        /// </summary>
        /// <param name="qurl"></param>
        /// <param name="TryCache"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        public static RootObject Get(string qurl, bool TryCache, DebugDelegate d)
        {
            if (_d == null)
            {
                _d = d;
            }
            var path = BarListImpl.GetDBLoc(PROGRAM, qurl.GetHashCode().ToString(), 7, DateTime.Now, getformatext(DefaultQuadlFormat));

            if (TryCache)
            {
                if (System.IO.File.Exists(path))
                {
                    try
                    {
                        var raw    = Util.getfile(path, d);
                        var dataok = !string.IsNullOrWhiteSpace(raw) && (raw.Length > 0);
                        if (dataok)
                        {
                            var data = isCacheCompressed ? GZip.Uncompress(raw) : raw;
                            return(json.Deserialize2Root(data, false, d));
                        }
                    }
                    catch (Exception ex)
                    {
                        debug("Will ignore cache and repull as error reading cache for: " + qurl + " , err: " + ex.Message + ex.StackTrace);
                    }
                }
            }
            // pull data
            var urldata     = Util.geturl(qurl, d);
            var isurldataok = !string.IsNullOrWhiteSpace(urldata) && (urldata.Length > 0);

            if (isurldataok)
            {
                var compdata = isCacheCompressed ? GZip.Compress(urldata) : urldata;
                if (Util.setfile(path, compdata))
                {
                    v("Cached " + urldata.Length.ToString("N0") + " bytes of qurl: " + qurl);
                }
                else
                {
                    v("Error caching: " + qurl + ", will repull next time.");
                }
            }

            return(json.Deserialize2Root(urldata, false, d));
        }
Exemplo n.º 21
0
        public void Basics()
        {
            const string sym = "TST";
            const int d = 20080509;
            const int t = 93500;
            const string x = "NYSE";
            TickImpl[] ticklist = new TickImpl[] { 
                TickImpl.NewTrade(sym,d,t,10,100,x),
                TickImpl.NewTrade(sym,d,t+100,10,100,x),
                TickImpl.NewTrade(sym,d,t+200,10,100,x),
                TickImpl.NewTrade(sym,d,t+300,10,100,x),
                TickImpl.NewTrade(sym,d,t+400,15,100,x), // blade up
                TickImpl.NewTrade(sym,d,t+500,16,100,x), // new bar (blades reset)
                TickImpl.NewTrade(sym,d,t+600,16,100,x),
                TickImpl.NewTrade(sym,d,t+700,10,100,x), // blade down
                TickImpl.NewTrade(sym,d,t+700,10,100,x), // still a blade down (same bar)
                TickImpl.NewTrade(sym,d,t+800,15,100,x), 
                TickImpl.NewTrade(sym,d,t+1500,15,800,x), // volume spike
                TickImpl.NewTrade(sym,d,t+2000,15,100,x), 
                TickImpl.NewTrade(sym,d,t+2500,15,100,x), 
            };

            BarListImpl bl = new BarListImpl(BarInterval.FiveMin,sym);
            Blade b = new Blade();
            Assert.That(b.BladePercentage != 0);
            b = new Blade(.2m); // 20 percent move is a blade
            int up=0,down=0,newbar=0,bigvol=0;

            foreach (TickImpl k in ticklist)
            {
                bl.newTick(k);
                b.newBar(bl);
                if (bl.NewBar) newbar++;
                if (b.isBladeUP) up++;
                if (b.isBladeDOWN) down++;
                if (b.isBigVolume) bigvol++;
            }

            Assert.AreEqual(1, up);
            Assert.AreEqual(2,down);
            Assert.AreEqual(5, newbar);
            Assert.AreEqual(1,bigvol);

        }
Exemplo n.º 22
0
 /// <summary>
 /// load previous days bar data from tick files located in tradelink tick folder
 /// </summary>
 /// <param name="PreviousDay"></param>
 /// <param name="syms"></param>
 /// <param name="AttemptToLoadPreviousDayBars"></param>
 /// <param name="_blt"></param>
 /// <param name="NewBarEvents"></param>
 /// <param name="deb"></param>
 /// <returns></returns>
 public static bool LoadPreviousBars(int PreviousDay, string[] syms, bool AttemptToLoadPreviousDayBars, ref BarListTracker _blt, SymBarIntervalDelegate NewBarEvents, DebugDelegate deb)
 {
     if (AttemptToLoadPreviousDayBars)
     {
         bool errors = false;
         foreach (string sym in syms)
         {
             string fn = Util.TLTickDir + "\\" + sym + PreviousDay + TikConst.DOT_EXT;
             if (System.IO.File.Exists(fn))
             {
                 try
                 {
                     BarList test = BarListImpl.FromTIK(fn);
                     _blt[sym]            = BarListImpl.FromTIK(fn, true, false, _blt[sym].CustomIntervals, _blt[sym].Intervals);
                     _blt[sym].GotNewBar += NewBarEvents;
                     if (deb != null)
                     {
                         deb(sym + " loaded historical bars from: " + fn);
                     }
                 }
                 catch (Exception ex)
                 {
                     errors = true;
                     if (deb != null)
                     {
                         deb(sym + " error loading historical bars from: " + fn);
                         deb(ex.Message + ex.StackTrace);
                     }
                 }
             }
             else
             {
                 errors = true;
                 if (deb != null)
                 {
                     deb(sym + " starting from zero, no historical bar data at: " + fn);
                 }
             }
         }
         return(!errors);
     }
     return(true);
 }
Exemplo n.º 23
0
        public Image DrawBarList(BarListImpl bl, BarInterval bi,Color up, Color down)
        {
            bl.DefaultInterval = bi;
            Bitmap sl = new Bitmap(w, h);
            Graphics g = Graphics.FromImage(sl);
            high = Calc.HH(bl);
            low = Calc.LL(bl);
            decimal range = high - low;
            int pixperdollar = range != 0 ? (int)(h / range) : 0;
            int pixperbar = bl.Count != 0 ? (int)(w / (decimal)bl.Count) : 0;
            for (int i = 0; i< bl.Count; i++)
            {
                Bar b = bl[i,bi];
                Pen p = new Pen(b.Close>=b.Open ? up : down);
                g.DrawLine(p, i * pixperbar, h-(int)((b.Low - low) * pixperdollar), i * pixperbar, h-(int)((b.High - low) * pixperdollar));
            }
            return sl;

        }
Exemplo n.º 24
0
        public void PointFiveMin()
        {
            // get some sample data to fill barlist
            Tick[] ticklist = SampleData();
            // prepare barlist
            BarListImpl bl = new BarListImpl(BarInterval.FiveMin);
            bl.GotNewBar += new SymBarIntervalDelegate(bl_GotNewBar);
            // reset count
            newbars = 0;
            // create bars from all ticks available
            foreach (TickImpl k in ticklist)
            {
                /// add tick to bar
                bl.newPoint(k.symbol,k.trade,k.time,k.date,k.size);
            }

            // verify we had expected number of bars
            Assert.AreEqual(3, bl.Count);
        }
Exemplo n.º 25
0
        /// <summary>
        /// gets specific date range of bars from google
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="startdate"></param>
        /// <param name="enddate"></param>
        /// <returns></returns>
        public static BarList DayFromGoogle(string symbol, int startdate, int enddate)
        {
            const string AMEX = ":AMEX";

            if ((symbol == null) || (symbol == string.Empty))
            {
                return(new
                       BarListImpl());
            }
            string      url = @"http://finance.google.com/finance/historical?
histperiod=daily&startdate=" + startdate + "&enddate=" + enddate + "&output=csv&q=" + symbol;
            BarListImpl bl  = new BarListImpl(BarInterval.Day, symbol);

            System.Net.WebClient wc = new System.Net.WebClient();
            string res = "";

            try
            {
                res = wc.DownloadString(url);
            }
            catch (Exception)
            {
                if (!symbol.Contains(AMEX))
                {
                    DayFromGoogle(symbol + AMEX, startdate, enddate);
                }
                return(bl);
            }
            string[] line = res.Split(Environment.NewLine.ToCharArray());
            for (int i = line.Length - 1; i > 0; i--)
            {
                if (line[i] == "")
                {
                    continue;
                }
                Bar b = BarImpl.FromCSV(line[i]);
                foreach (Tick k in BarImpl.ToTick(b))
                {
                    bl.newTick(k);
                }
            }
            return(bl);
        }
Exemplo n.º 26
0
        public Image DrawBarList(BarListImpl bl, BarInterval bi, Color up, Color down)
        {
            bl.DefaultInterval = bi;
            Bitmap   sl = new Bitmap(w, h);
            Graphics g  = Graphics.FromImage(sl);

            high = Calc.HH(bl);
            low  = Calc.LL(bl);
            decimal range        = high - low;
            int     pixperdollar = range != 0 ? (int)(h / range) : 0;
            int     pixperbar    = bl.Count != 0 ? (int)(w / (decimal)bl.Count) : 0;

            for (int i = 0; i < bl.Count; i++)
            {
                Bar b = bl[i, bi];
                Pen p = new Pen(b.Close >= b.Open ? up : down);
                g.DrawLine(p, i * pixperbar, h - (int)((b.Low - low) * pixperdollar), i * pixperbar, h - (int)((b.High - low) * pixperdollar));
            }
            return(sl);
        }
Exemplo n.º 27
0
        public void OneMinute()
        {
            // prepare barlist
            BarList bl = new BarListImpl(BarInterval.Minute);
            // reset count
            int newbars = 0;
            // build bars from ticks available
            foreach (TickImpl k in SampleData())
            {
                // add tick to bar
                bl.newTick(k);
                // count if it's a new bar
                if (bl.RecentBar.isNew)
                    newbars++;
            }
            // verify expected # of bars are present
            Assert.AreEqual(9, newbars);
            // verify barcount is same as newbars
            Assert.AreEqual(newbars, bl.Count);

        }
Exemplo n.º 28
0
        public void QuoteOnlyTest()
        {
            TickImpl[] timesales = new TickImpl[] {
                TickImpl.NewBid("TST",100m,100),
                TickImpl.NewAsk("TST",100.1m,200),
            };

            Blade b = new Blade();
            BarListImpl bl = new BarListImpl(BarInterval.FiveMin,"TST");

            foreach (TickImpl k in timesales)
            {
                bl.newTick(k);
                b.newBar(bl);
            }

            // average volume should be zero bc
            // with only quotes we should have no bars to process
            Assert.That(b.AvgVol(bl) == 0, b.AvgVol(bl).ToString());
            Assert.That(!bl.Has(1), bl.ToString());
        }
Exemplo n.º 29
0
 public static int GetNearestIntraBar(BarList bl, int time, BarInterval bint, DebugDelegate debug)
 {
     try
     {
         long             barid = TimeIntervalData.getbarid(time, bl.RecentBar.Bardate, (int)bint);
         BarListImpl      bli   = (BarListImpl)bl;
         TimeIntervalData tid   = (TimeIntervalData)bli._intdata[bli._intdataidx[(int)bint]];
         for (int i = 0; i < tid.Count(); i++)
         {
             if (tid.ids[i] == barid)
             {
                 return(i);
             }
         }
     }
     catch (Exception ex)
     {
         if (debug != null)
         {
             debug("error getting nearest bar from: " + bl.Symbol + " at: " + time + " for: " + bint + " error: " + ex.Message + ex.StackTrace);
         }
     }
     return(-1);
 }
Exemplo n.º 30
0
        public void FiveMin()
        {
            // get some sample data to fill barlist
            Tick[] ticklist = SampleData();
            // prepare barlist
            BarListImpl bl = new BarListImpl(BarInterval.FiveMin);
            bl.GotNewBar+=new SymBarIntervalDelegate(bl_GotNewBar);
            // reset count
            newbars = 0;
            // create bars from all ticks available
            foreach (TickImpl k in ticklist)
            {
                /// add tick to bar
                bl.newTick(k);
            }

            // verify we had expected number of bars
            Assert.AreEqual(3,newbars);
            // verify symbol was set
            Assert.AreEqual(sym, bl.Symbol);
            // verify each bar symbol matches barlist
            foreach (Bar b in bl)
                Assert.AreEqual(bl.Symbol, b.Symbol);
        }
Exemplo n.º 31
0
 static Basket verify_equitysymbol(Basket b, bool googleyahoo, DebugDelegate d)
 {
     debs = d;
     b    = RemoveDupe(b);
     if (googleyahoo)
     {
         Basket v = new BasketImpl();
         foreach (Security s in b)
         {
             BarList bl = BarListImpl.DayFromAny(s.symbol, sdebug);
             if (bl.Count > 0)
             {
                 v.Add(s.symbol);
                 sdebug("verified google/yahoo: " + s.symbol + " bars: " + bl.Count);
             }
             else
             {
                 sdebug("ignoring, not verified google/yahoo: " + s.symbol + " bars: " + bl.Count);
             }
         }
         return(v);
     }
     return(b);
 }
Exemplo n.º 32
0
 internal static void addbar(BarListImpl b, Bar mybar, int instdataidx)
 {
     b._intdata[instdataidx].addbar(mybar);
 }
Exemplo n.º 33
0
 /// <summary>
 /// insert one barlist into another barlist
 /// REMEMBER: You must re-handle the GotNewBar event after calling this method.
 /// You should also ensure that inserted barlist has same intervals/types as original barlist.
 /// </summary>
 /// <param name="bl"></param>
 /// <param name="insert"></param>
 /// <returns></returns>
 public static BarListImpl InsertBarList(BarList bl, BarList insert)
 {
     BarListImpl copy = new BarListImpl(bl);
     for (int j = 0; j < bl.CustomIntervals.Length; j++)
     {
         for (int k = 0; k < insert.CustomIntervals.Length; k++)
         {
             if (bl.CustomIntervals[j] != insert.CustomIntervals[k])
                 continue;
             for (int l = 0; l < insert.Count; l++)
             {
                 for (int m = 0; m < bl.Count; m++)
                 {
                     if (l == m)
                     {
                         addbar(copy, insert[l, (BarInterval)insert.CustomIntervals[k]], j);
                     }
                     addbar(copy, bl[m], j);
                 }
             }
         }
     }
     return copy;
 }
Exemplo n.º 34
0
        public static BarList DayFromEuronext(string isin, DateTime?startDate, DateTime?endDate)
        {
            string market;
            string urlTemplate =
                @"http://www.euronext.com/tools/datacentre/dataCentreDownloadExcell.jcsv?cha=2593&lan=EN&fileFormat=txt&separator=.&dateFormat=dd/MM/yy" +
                "&isinCode=[symbol]&selectedMep=[market]&indexCompo=&opening=on&high=on&low=on&closing=on&volume=on&dateFrom=[startDay]/[startMonth]/[startYear]&" +
                "dateTo=[endDay]/[endMonth]/[endYear]&typeDownload=2";

            if (!endDate.HasValue)
            {
                endDate = DateTime.Now;
            }
            if (!startDate.HasValue)
            {
                startDate = DateTime.Now.AddYears(-5);
            }
            if (isin == null || !Regex.IsMatch(isin, "[A-Za-z0-9]{12}"))
            {
                throw new ArgumentException("Invalid ISIN: " + isin);
            }

            /* ugly hack to get the market number from the isin (not always valid..) */
            CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

            if (myComp.IsPrefix(isin, "BE"))
            {
                market = "3";
            }
            else if (myComp.IsPrefix(isin, "FR"))
            {
                market = "1";
            }
            else if (myComp.IsPrefix(isin, "NL"))
            {
                market = "2";
            }
            else if (myComp.IsPrefix(isin, "PT"))
            {
                market = "5";
            }
            else
            {
                market = "1";
            }

            string startMonth = startDate.Value.Month.ToString();
            string startDay   = startDate.Value.Day.ToString();
            string startYear  = startDate.Value.Year.ToString();

            string endMonth = endDate.Value.Month.ToString();
            string endDay   = endDate.Value.Day.ToString();
            string endYear  = endDate.Value.Year.ToString();

            urlTemplate = urlTemplate.Replace("[symbol]", isin);
            urlTemplate = urlTemplate.Replace("[market]", market);
            urlTemplate = urlTemplate.Replace("[startMonth]", startMonth);
            urlTemplate = urlTemplate.Replace("[startDay]", startDay);
            urlTemplate = urlTemplate.Replace("[startYear]", startYear);

            urlTemplate = urlTemplate.Replace("[endMonth]", endMonth);
            urlTemplate = urlTemplate.Replace("[endDay]", endDay);
            urlTemplate = urlTemplate.Replace("[endYear]", endYear);

            BarListImpl bl = new BarListImpl(BarInterval.Day, isin);

            System.Net.WebClient wc = new System.Net.WebClient();
            StreamReader         res;

            try
            {
                res = new StreamReader(wc.OpenRead(urlTemplate));
                int    skipCount = 0;
                string tmp       = null;
                do
                {
                    tmp = res.ReadLine();
                    if (skipCount++ < 7)
                    {
                        continue;
                    }
                    tmp = tmp.Replace(";", ",");
                    Bar b = BarImpl.FromCSV(tmp, isin, (int)BarInterval.Day);
                    foreach (Tick k in BarImpl.ToTick(b))
                    {
                        bl.newTick(k);
                    }
                } while (tmp != null);
            }
            catch (Exception)
            {
                return(bl);
            }

            return(bl);
        }
Exemplo n.º 35
0
 public Image DrawBarList(BarListImpl bl, BarInterval bi) { return DrawBarList(bl, bi, Color.Green, Color.Red); }
Exemplo n.º 36
0
 public Image DrawBarListBlack(BarListImpl bl, BarInterval bi) { return DrawBarList(bl, bi, Color.Black,Color.Black); }
Exemplo n.º 37
0
 /// <summary>
 /// creates tracker for specified number of standard intervals
 /// </summary>
 /// <param name="intervals"></param>
 public BarListTracker(BarInterval[] intervals)
 {
     _requested = BarListImpl.BarInterval2Int(intervals);
     _reqtype   = intervals;
     _default   = (int)intervals[0];
 }
Exemplo n.º 38
0
 public Image DrawBarList(BarListImpl bl)
 {
     return(DrawBarList(bl, BarInterval.FiveMin, Color.Green, Color.Red));
 }
Exemplo n.º 39
0
 public Image DrawBarListBlack(BarListImpl bl)
 {
     return(DrawBarList(bl, BarInterval.FiveMin, Color.Black, Color.Black));
 }
Exemplo n.º 40
0
 public void PointHour()
 {
     // get data
     Tick[] tape = SampleData();
     // count new hour bars
     newbars = 0;
     // setup hour bar barlist
     BarListImpl bl = new BarListImpl(BarInterval.Hour, sym);
     // handle new bar events
     bl.GotNewBar += new SymBarIntervalDelegate(bl_GotNewBar);
     // add ticks to bar
     foreach (Tick k in tape)
     {
         // add ticks
         bl.newPoint(k.trade,k.time,k.date,k.size);
     }
     // make sure we have at least 1 bars
     Assert.IsTrue(bl.Has(1));
     // make sure we actually have two bars
     Assert.AreEqual(2, bl.Count);
 }
Exemplo n.º 41
0
 public void DefaultIntervalAndReset()
 {
     // get some data
     Tick[] tape = SampleData();
     // setup an hour barlist
     BarList bl = new BarListImpl();
     bl.DefaultInterval = BarInterval.Hour;
     // build the barlist
     foreach (Tick k in tape)
         bl.newTick(k);
     // make sure we have 2 hour bars
     Assert.AreEqual(2, bl.Count);
     // switch default
     bl.DefaultInterval = BarInterval.FiveMin;
     // make sure we have 3 5min bars
     Assert.AreEqual(3, bl.Count);
     // reset it
     bl.Reset();
     // verify we have no data
     Assert.AreEqual(0, bl.Count);
 }
Exemplo n.º 42
0
        public virtual bool GotMessage(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            long lv = 0;

            switch (type)
            {
            case MessageTypes.CLOSEPRICE:
            {
                if ((GotClosePrice != null) && long.TryParse(response, out lv))
                {
                    GotClosePrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.OPENPRICE:
            {
                if ((GotOpenPrice != null) && long.TryParse(response, out lv))
                {
                    GotOpenPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.DAYHIGH:
            {
                if ((GotHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.DAYLOW:
            {
                if ((GotLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.NYSEDAYHIGH:
            {
                if ((GotNyseHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotNyseHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.NYSEDAYLOW:
            {
                if ((GotNyseLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotNyseLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.INTRADAYHIGH:
            {
                if ((GotIntraHighPrice != null) && long.TryParse(response, out lv))
                {
                    GotIntraHighPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.INTRADAYLOW:
            {
                if ((GotIntraLowPrice != null) && long.TryParse(response, out lv))
                {
                    GotIntraLowPrice(request, WMUtil.unpack(lv));
                }
                return(true);
            }

            case MessageTypes.BROKERNAME:
            {
                if (GotProvider != null)
                {
                    try
                    {
                        Providers p = (Providers)Enum.Parse(typeof(Providers), response);
                        GotProvider(p);
                    }
                    catch (Exception ex)
                    {
                        debug("Unknown provider: " + response);
                        debug(ex.Message + ex.StackTrace);
                        return(false);
                    }
                }
                return(true);
            }

            case MessageTypes.FEATURERESPONSE:
            {
                if (GotFeatures != null)
                {
                    string[]            r = response.Split(',');
                    List <MessageTypes> f = new List <MessageTypes>();
                    foreach (string rs in r)
                    {
                        try
                        {
                            MessageTypes mt = (MessageTypes)Enum.Parse(typeof(MessageTypes), rs);
                            f.Add(mt);
                        }
                        catch { continue; }
                    }
                    if (f.Count > 0)
                    {
                        GotFeatures(f.ToArray());
                    }
                }
                return(true);
            }

            case MessageTypes.BARRESPONSE:
            {
                try
                {
                    // get bar
                    Bar b = BarImpl.Deserialize(response);
                    // quit if bar is invalid
                    if (!b.isValid)
                    {
                        return(true);
                    }
                    // notify bar was received
                    if (GotNewBar != null)
                    {
                        GotNewBar(b.Symbol, b.Interval);
                    }
                    // update blt if desired
                    if (BLT != null)
                    {
                        // get bar list
                        BarList bl = BLT[b.Symbol, b.Interval];
                        //cjyu
                        //return if bar already exists
                        //if (BarListImpl.BarExists(bl, b))
                        //  return true;

                        // get nearest intrday bar
                        int preceed = BarListImpl.GetBarIndexPreceeding(bl, b.Bardate, b.Bartime);
                        // increment by one to get new position
                        int newpos = preceed + 1;
                        // insert bar
                        BLT[b.Symbol] = BarListImpl.InsertBar(bl, b, newpos);
                    }
                }
                catch (Exception ex)
                {
                    debug("error receiving bardata: " + response + " err: " + ex.Message + ex.StackTrace);
                    return(false);
                }
                return(true);
            }
            break;
            }
            return(false);
        }
Exemplo n.º 43
0
        static string  GetData(IQuandlRequest req, string sym, string dataset, FileFormats form, bool checkcache, bool compressedcache, DebugDelegate d)
        {
            if (_d == null)
            {
                _d = d;
            }
            try
            {
                var path = BarListImpl.GetDBLoc(PROGRAM, dataset + "_" + sym, 30, DateTime.Now, getformatext(form));
                if (checkcache)
                {
                    if (System.IO.File.Exists(path))
                    {
                        try
                        {
                            var cached = Util.getfile(path, null);
                            if (compressedcache)
                            {
                                var cacheddata = GZip.Uncompress(cached);
                                v(sym + " " + dataset + " found " + cacheddata.Length.ToString("N0") + " bytes of cached data.");
                                return(cacheddata);
                            }
                        }
                        catch (Exception ex)
                        {
                            debug("Ignoring cache (will pull directly) after cache error for: " + dataset + " on " + sym + " err: " + ex.Message + ex.StackTrace);
                        }
                    }
                }
                var con      = new QuandlConnection();
                var data     = con.Request(req);
                var isdataok = !qh.isQdlUnderMaintence(data);
                if (isdataok)
                {
                    v(sym + " " + dataset + " retrieved " + data.Length.ToString("N0") + " bytes of " + dataset + " data.");
                    // save it for later caching
                    if (Util.setfile(path, compressedcache ? GZip.Compress(data) : data))
                    {
                        v(sym + " " + dataset + " cached " + data.Length.ToString("N0") + " bytes of " + dataset + " data.");
                    }
                    else
                    {
                        v(sym + " " + dataset + " error caching " + data.Length.ToString("N0") + " bytes of " + dataset + " data.  Will be re-pulled on next attempt.");
                    }
                }
                else
                {
                    debug(sym + " " + dataset + " can't be retrieved because quandl is down.");
                    return(string.Empty);
                }

                return(data);
            }
            catch (Exception ex)
            {
                if (isVerboseDebugging)
                {
                    debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + " using url: " + req.ToRequestString());
                    debug("Error for " + dataset + " on symbol: " + sym + ": " + ex.Message + ex.StackTrace);
                }
                else
                {
                    debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + ", err: " + ex.Message + ex.StackTrace);
                }
                return(string.Empty);
            }
        }
Exemplo n.º 44
0
 /// <summary>
 /// get a barlist from tick data and optionally use bid/ask data to construct bars
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="uselast"></param>
 /// <param name="usebid"></param>
 /// <returns></returns>
 public static BarList FromTIK(string filename, bool uselast, bool usebid)
 {
     _uselast = uselast;
     _usebid = usebid;
     SecurityImpl s = SecurityImpl.FromTIK(filename);
     s.HistSource.gotTick += new TickDelegate(HistSource_gotTick);
     _fromepf = new BarListImpl(s.Symbol);
     while (s.HistSource.NextTick()) ;
     s.HistSource.Close();
     return _fromepf;
 }
Exemplo n.º 45
0
        public void NewBarEvent()
        {
            // get tickdata
            Tick[] tape = SampleData();
            // reset bar count
            newbars = 0;
            // request hour interval
            BarList bl = new BarListImpl(BarInterval.Hour, sym);
            // handle new bars
            bl.GotNewBar += new SymBarIntervalDelegate(bl_GotNewBar);

            foreach (TickImpl k in tape)
                bl.newTick(k);

            Assert.AreEqual(2, newbars);
        }
Exemplo n.º 46
0
        private static BarList DayFromURL(string url,string Symbol,bool appendAMEXonfail)
        {
            BarListImpl bl = new BarListImpl(BarInterval.Day,Symbol);
            if (Symbol == "") return bl;
            System.Net.WebClient wc = new System.Net.WebClient();
            string res = "";
            try
            {
                res = wc.DownloadString(url + Symbol);
            }
            catch (Exception)
            {
                if (appendAMEXonfail)
                    return DayFromURL(url, Symbol + AMEX, false);
                return bl;

            }
            string[] line = res.Split(Environment.NewLine.ToCharArray());
            for (int i = line.Length - 1; i > 0; i--)
            {
                if (line[i] != "")
                    addbar(bl,BarImpl.FromCSV(line[i]),0);
            }
            return bl;
        }
Exemplo n.º 47
0
 public void VolInterval()
 {
     // request 300 volume bars
     const int MYINTERVAL = 300;
     BarList bl = new BarListImpl(sym, MYINTERVAL, BarInterval.CustomVol);
     // verify custom interval
     Assert.AreEqual(MYINTERVAL, bl.DefaultCustomInterval);
     Assert.AreEqual(MYINTERVAL, bl.CustomIntervals[0]);
     // iterate ticks
     foreach (Tick k in SampleData())
         bl.newTick(k);
     // count em
     Assert.AreEqual(4, bl.Count);
 }
Exemplo n.º 48
0
 static void wc_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
 {
     string res = string.Empty;
     BarListDownload bld = (BarListDownload)e.UserState;
     if (!bld.isValid)
         return;
     if (e.Cancelled || (e.Error != null))
     {
         if (bld.AppendAMEXonFail)
         {
             DayFromGoogleAsync(bld.Symbol + AMEX, bld.DoResults,false);
             return;
         }
         bld.DoResults(new BarListImpl(BarInterval.Day, bld.Symbol));
         return;
     }
     res = e.Result;
     BarListImpl bl = new BarListImpl(BarInterval.Day, bld.Symbol);
     string[] line = res.Split(Environment.NewLine.ToCharArray());
     for (int i = line.Length - 1; i > 0; i--)
     {
         if (line[i] != "")
             addbar(bl, BarImpl.FromCSV(line[i]), 0);
     }
     bld.DoResults(bl);
 }
Exemplo n.º 49
0
 public void CustomInterval()
 {
     // request 5 second bars
     const int MYINTERVAL = 5;
     BarList bl = new BarListImpl(sym, MYINTERVAL);
     // verify custom interval
     Assert.AreEqual(MYINTERVAL, bl.DefaultCustomInterval);
     Assert.AreEqual(MYINTERVAL, bl.CustomIntervals[0]);
     // iterate ticks
     foreach (Tick k in SampleData())
         bl.newTick(k);
     // count em
     Assert.AreEqual(10, bl.Count);
 }
Exemplo n.º 50
0
        public static BarList DayFromEuronext(string isin, DateTime? startDate, DateTime? endDate)
        {
            string market;
            string urlTemplate =
                @"http://www.euronext.com/tools/datacentre/dataCentreDownloadExcell.jcsv?cha=2593&lan=EN&fileFormat=txt&separator=.&dateFormat=dd/MM/yy" +
                "&isinCode=[symbol]&selectedMep=[market]&indexCompo=&opening=on&high=on&low=on&closing=on&volume=on&dateFrom=[startDay]/[startMonth]/[startYear]&" +
                "dateTo=[endDay]/[endMonth]/[endYear]&typeDownload=2";

            if (!endDate.HasValue) endDate = DateTime.Now;
            if (!startDate.HasValue) startDate = DateTime.Now.AddYears(-5);
            if (isin == null || !Regex.IsMatch(isin, "[A-Za-z0-9]{12}"))
                throw new ArgumentException("Invalid ISIN: " + isin);

            /* ugly hack to get the market number from the isin (not always valid..) */
            CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;
            if (myComp.IsPrefix(isin, "BE")) market = "3";
            else if (myComp.IsPrefix(isin, "FR")) market = "1";
            else if (myComp.IsPrefix(isin, "NL")) market = "2";
            else if (myComp.IsPrefix(isin, "PT")) market = "5";
            else market = "1";

            string startMonth = startDate.Value.Month.ToString();
            string startDay = startDate.Value.Day.ToString();
            string startYear = startDate.Value.Year.ToString();

            string endMonth = endDate.Value.Month.ToString();
            string endDay = endDate.Value.Day.ToString();
            string endYear = endDate.Value.Year.ToString();

            urlTemplate = urlTemplate.Replace("[symbol]", isin);
            urlTemplate = urlTemplate.Replace("[market]", market);
            urlTemplate = urlTemplate.Replace("[startMonth]", startMonth);
            urlTemplate = urlTemplate.Replace("[startDay]", startDay);
            urlTemplate = urlTemplate.Replace("[startYear]", startYear);

            urlTemplate = urlTemplate.Replace("[endMonth]", endMonth);
            urlTemplate = urlTemplate.Replace("[endDay]", endDay);
            urlTemplate = urlTemplate.Replace("[endYear]", endYear);

            BarListImpl bl = new BarListImpl(BarInterval.Day, isin);
            System.Net.WebClient wc = new System.Net.WebClient();
            StreamReader res;
            try
            {
                res = new StreamReader(wc.OpenRead(urlTemplate));
                int skipCount = 0;
                string tmp = null;
                do
                {
                    tmp = res.ReadLine();
                    if (skipCount++ < 7)
                        continue;
                    tmp = tmp.Replace(";", ",");
                    Bar b = BarImpl.FromCSV(tmp, isin, (int)BarInterval.Day);
                    foreach (Tick k in BarImpl.ToTick(b))
                        bl.newTick(k);
                } while (tmp != null);
            }
            catch (Exception)
            {
                return bl;
            }

            return bl;
        }
Exemplo n.º 51
0
 public Image DrawBarListBlack(BarListImpl bl, BarInterval bi)
 {
     return(DrawBarList(bl, bi, Color.Black, Color.Black));
 }
Exemplo n.º 52
0
        /// <summary>
        /// gets specific date range of bars from google
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="startdate"></param>
        /// <param name="enddate"></param>
        /// <returns></returns>
        public static BarList DayFromGoogle(string symbol, int startdate, int enddate)
        {
            const string AMEX = ":AMEX";
            if ((symbol == null) || (symbol == string.Empty)) return new
            BarListImpl();
            string url = @"http://finance.google.com/finance/historical?
            histperiod=daily&startdate=" + startdate + "&enddate=" + enddate + "&output=csv&q=" + symbol;
            BarListImpl bl = new BarListImpl(BarInterval.Day, symbol);
            System.Net.WebClient wc = new System.Net.WebClient();
            string res = "";
            try
            {
                res = wc.DownloadString(url);
            }
            catch (Exception)
            {
                if (!symbol.Contains(AMEX))
                    DayFromGoogle(symbol + AMEX, startdate, enddate);
                return bl;

            }
            string[] line = res.Split(Environment.NewLine.ToCharArray());
            for (int i = line.Length - 1; i > 0; i--)
            {
                if (line[i] == "") continue;
                Bar b = BarImpl.FromCSV(line[i]);
                foreach (Tick k in BarImpl.ToTick(b))
                    bl.newTick(k);
            }
            return bl;
        }
Exemplo n.º 53
0
 public Image DrawBarList(BarListImpl bl, BarInterval bi)
 {
     return(DrawBarList(bl, bi, Color.Green, Color.Red));
 }
Exemplo n.º 54
0
 /// <summary>
 /// Create a barlist from a succession of bar records provided as comma-delimited OHLC+volume data.
 /// </summary>
 /// <param name="symbol">The symbol.</param>
 /// <param name="file">The file containing the CSV records.</param>
 /// <returns></returns>
 public static BarListImpl FromCSV(string symbol, string file)
 {
     BarListImpl b = new BarListImpl(BarInterval.Day, symbol);
     string[] line = file.Split(Environment.NewLine.ToCharArray());
     for (int i = line.Length - 1; i > 0; i--)
     {
         if (line[i] != string.Empty)
             addbar(b,BarImpl.FromCSV(line[i]),0);
     }
     return b;
 }
Exemplo n.º 55
0
 public Image DrawBarListBlack(BarListImpl bl) { return DrawBarList(bl, BarInterval.FiveMin, Color.Black, Color.Black); }
Exemplo n.º 56
0
 /// <summary>
 /// Build a barlist using an EPF file as the source
 /// </summary>
 /// <param name="filename">The filename.</param>
 /// <returns>barlist</returns>
 public static BarList FromEPF(string filename)
 {
     System.IO.StreamReader sr = new System.IO.StreamReader(filename);
     SecurityImpl s = eSigTick.InitEpf(sr);
     BarList b = new BarListImpl(s.Symbol);
     while (!sr.EndOfStream)
         b.newTick(eSigTick.FromStream(s.Symbol, sr));
     return b;
 }
Exemplo n.º 57
0
 public Image DrawBarList(BarListImpl bl) { return DrawBarList(bl, BarInterval.FiveMin, Color.Green, Color.Red); }
Exemplo n.º 58
0
 /// <summary>
 /// create barlist from a tik file using given intervals/types
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="uselast"></param>
 /// <param name="usebid"></param>
 /// <param name="intervals"></param>
 /// <param name="types"></param>
 /// <returns></returns>
 public static BarList FromTIK(string filename, bool uselast, bool usebid, int[] intervals, BarInterval[] types)
 {
     _uselast = uselast;
     _usebid = usebid;
     SecurityImpl s = SecurityImpl.FromTIK(filename);
     s.HistSource.gotTick += new TickDelegate(HistSource_gotTick);
     _fromepf = new BarListImpl(s.Symbol,intervals,types);
     while (s.HistSource.NextTick()) ;
     return _fromepf;
 }
Exemplo n.º 59
0
 /// <summary>
 /// insert a bar at particular place in the list.
 /// REMEMBER YOU MUST REHANDLE GOTNEWBAR EVENT AFTER CALLING THIS.
 /// </summary>
 /// <param name="bl"></param>
 /// <param name="b"></param>
 /// <param name="position"></param>
 /// <returns></returns>
 public static BarListImpl InsertBar(BarList bl, Bar b, int position)
 {
     BarListImpl copy = new BarListImpl(bl);
     for (int j = 0; j < bl.CustomIntervals.Length; j++)
     {
         if (bl.CustomIntervals[j] != b.Interval)
             continue;
         int count = bl.IntervalCount(b.Interval);
         if (count != 0)
         {
             for (int i = 0; i < count; i++)
             {
                 if (i == position)
                 {
                     addbar(copy, b, j);
                 }
                 addbar(copy, bl[i, (BarInterval)b.Interval], j);
             }
         }
         else
             addbar(copy, b, 0);
     }
     return copy;
 }
Exemplo n.º 60
0
 internal static void addbar(BarListImpl b, Bar mybar, int instdataidx)
 {
     b._intdata[instdataidx].addbar(mybar);
 }