/// <summary> /// Create a box-info instance from an existing BarList /// </summary> /// <param name="bl">The barlist.</param> /// <returns>a BoxInfo</returns> public static BoxInfo FromBarList(BarList bl) { BoxInfo bi = new BoxInfo(); if (!bl.HasBar()) { return(bi); } bi.High = BarMath.HH(bl); bi.Low = BarMath.LL(bl); bi.Open = bl[0].Open; return(bi); }
public Stock ToStock() { if (!HasBar()) { throw new Exception("Can't generate a stock instance from an empty barlist!"); } Stock s = new Stock(Symbol, this.RecentBar.Bardate); s.DayHigh = BarMath.HH(this); s.DayLow = BarMath.LL(this); s.DayOpen = this[0].Open; s.DayClose = this.RecentBar.Close; return(s); }
void Chart_Paint(object sender, PaintEventArgs e) { if (bl != null) { highesth = BarMath.HH(bl); lowestl = BarMath.LL(bl); barc = bl.Count; } if ((bl == null) || (bl.Count == 0)) { return; } Text = Title; r = ClientRectangle; pixperbar = (((decimal)r.Width - (decimal)border - ((decimal)border / 3)) / (decimal)barc); pixperdollar = (((decimal)r.Height - (decimal)border * 2) / (highesth - lowestl)); Pen p = new Pen(Color.Black); g = e.Graphics; Form f = (Form)sender; g.Clear(f.BackColor); Color fgcol = (f.BackColor == Color.Black) ? Color.White : Color.Black; // x-axis g.DrawLine(new Pen(fgcol), (int)(border / 3), r.Height - border, r.Width - border, r.Height - border); // y-axis g.DrawLine(new Pen(fgcol), r.Width - border, r.Y + border, r.Width - border, r.Height - border); const int minxlabelwidth = 15; int lastlabelcoord = -500; for (int i = 0; i < barc; i++) { Color bcolor = (bl.Get(i).Close > bl.Get(i).Open) ? Color.Green : Color.Red; p = new Pen(bcolor); // draw high/low bar g.DrawLine(p, getX(i), getY(bl.Get(i).Low), getX(i), getY(bl.Get(i).High)); // draw open bar g.DrawLine(p, getX(i), getY(bl.Get(i).Open), getX(i) - (int)(pixperbar / 3), getY(bl.Get(i).Open)); // draw close bar g.DrawLine(p, getX(i), getY(bl.Get(i).Close), getX(i) + (int)(pixperbar / 3), getY(bl.Get(i).Close)); // draw time labels (time @30min and date@noon) if (bl.Int != BarInterval.Day) { if ((i % 6) == 0) { g.DrawString(bl.Get(i).Bartime.ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (f.Font.GetHeight() * 3)); } if (bl.Get(i).Bartime == 1200) { g.DrawString(bl.Get(i).Bardate.ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (float)(f.Font.GetHeight() * 1.5)); } } else { int[] date = BarMath.Date(bl.Get(i).Bardate); int[] lastbardate = date; if ((i - 1) > 0) { lastbardate = BarMath.Date(bl.Get(i - 1).Bardate); } if ((getX(lastlabelcoord) + minxlabelwidth) <= getX(i)) { lastlabelcoord = i; g.DrawString(date[2].ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (f.Font.GetHeight() * 3)); } if ((i == 0) || (lastbardate[1] != date[1])) { string ds = date[1].ToString(); if ((i == 0) || (lastbardate[0] != date[0])) { ds += '/' + date[0].ToString(); } g.DrawString(ds, f.Font, new SolidBrush(fgcol), getX(i), r.Height - (float)(f.Font.GetHeight() * 1.5)); } } } // DRAW YLABELS // max number of even intervaled ylabels possible on yaxis int numlabels = (int)((r.Height - border * 2) / (f.Font.GetHeight() * 1.5)); // nearest price units giving "pretty" even intervaled ylabels decimal priceunits = NearestPrettyPriceUnits(highesth - lowestl, numlabels); // starting price point from low end of range, including lowest low in barlist decimal lowstart = lowestl - ((lowestl * 100) % (priceunits * 100)) / 100; // original "non-pretty" price units calc //decimal priceunits = (highesth-lowestl)/numlabels; Pen priceline = new Pen(Color.BlueViolet); priceline.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; for (decimal i = 0; i <= numlabels; i++) { decimal price = lowstart + (i * priceunits); g.DrawString(price.ToString("C"), f.Font, new SolidBrush(fgcol), r.Width - border, getY(price) - f.Font.GetHeight()); g.DrawLine(priceline, border / 3, getY(price), r.Width - border, getY(price)); } DrawLabels(); }