コード例 #1
0
ファイル: KadinaMain.cs プロジェクト: antonywu/tradelink
 void reset(bool reloadcurrentstudy)
 {
     try
     {
         // clear all GUIs
         _msg = new StringBuilder(10000);
         SimBroker = new Broker();
         debugControl1.Clear();
         dt.Clear();
         ptab.Clear();
         poslist.Clear();
         _tradelist.Clear();
         ot.Clear();
         ft.Clear();
         _tabs.Refresh();
         c = new ChartControl();
         _tr.Clear();
         if (it != null) 
         { 
             it.Clear(); 
             it.Columns.Clear(); 
             ig.Invalidate();
             SafeBindingSource.refreshgrid(ig, ibs,true);
         }
         unbindresponseevents();
         if (reloadcurrentstudy)
         {
             loadsim();
             loadboxname(resname);
         }
         else
         {
             epffiles.Clear();
             
         }
         nowtime = "0";
     }
     catch (Exception ex)
     {
         status("An error occured, try again.");
         debug("reset error: " + ex.Message + ex.StackTrace);
     }
 }
コード例 #2
0
ファイル: KadinaMain.cs プロジェクト: sopnic/larytet-master
 void reset()
 {
     try
     {
         // clear all GUIs
         _msg = new StringBuilder(10000);
         SimBroker.Reset();
         debugControl1.Clear();
         dt.Clear();
         ptab.Clear();
         poslist.Clear();
         _tradelist.Clear();
         ot.Clear();
         ft.Clear();
         _tabs.Refresh();
         c = new ChartControl();
         _tr.Clear();
         if (it != null) { it.Clear(); it.Columns.Clear(); ig.Invalidate(); }
         loadsim();
         loadboxname(resname);
     }
     catch (Exception ex)
     {
         status("An error occured, try again.");
         debug("reset error: " + ex.Message + ex.StackTrace);
     }
 }
コード例 #3
0
ファイル: TradeResults.cs プロジェクト: bluejack2000/core
 private static decimal GetPortfolioPlot(string title, decimal staticequity, int startdate, int starttime, int enddate, int endtime, ref ChartControl c)
 {
     var cureq = staticequity;
     c.NewBarList(new BarListImpl(title));
     // plot static line
     c.newPoint(title, cureq, starttime, startdate, 100);
     c.newPoint(title, cureq, endtime, enddate, 100);
     c.redraw();
     // set final equity
     return cureq;
 }
コード例 #4
0
ファイル: TradeResults.cs プロジェクト: bluejack2000/core
 public static decimal GetPortfolioPlot(string title,decimal start, int startdate, int starttime, int enddate, int endtime, List<Trade> trades, ref ChartControl c, decimal compershare)
 {
     var cureq = start;
     if (trades.Count == 0)
         return GetPortfolioPlot(title,start, startdate, starttime, enddate, endtime, ref c);
     c.NewBarList(new BarListImpl(title));
     var tradessorted = SortTrades(trades);
     c.newPoint(title, cureq, 0, tradessorted[0].xdate, 100);
     // plot money made
     PositionTracker pt = new PositionTracker();
     foreach (var t in tradessorted)
     {
         var grosspl = pt.Adjust(t);
         var netpl = grosspl - (compershare * Math.Abs(t.xsize));
         cureq += netpl;
         c.newPoint(title, cureq, t.xtime, t.xdate, 100);
     }
     c.redraw();
     // set final equity
     return cureq;
 }
コード例 #5
0
        public void Chart_Paint(object sender, PaintEventArgs e)
        {
            try
            {
                // get form
                ChartControl f = (ChartControl)sender;
                // get graphics
                g = e.Graphics;
                if ((bl == null) || (bl.Intervals.Length == 0) || (bl.Count == 0))
                {
                    g.DrawString(MissingDataMessage, new Font(FontFamily.GenericSerif, 10, FontStyle.Bold), Brushes.Black, new PointF(r.Width / 3, r.Height / 2));
                    return;
                }
                lock (bl)
                {
                    // get window
                    r = ClientRectangle;
                    // get title
                    Text   = Title;
                    border = (int)(g.MeasureString(bl.High()[0].ToString(), f.Font).Width);
                    // setup to draw

                    Pen p = new Pen(fgcol);
                    g.Clear(f.BackColor);
                    // get number of pixels available for each bar, based on screensize and barcount
                    pixperbar = (((decimal)r.Width - (decimal)border - ((decimal)border / 3)) / (decimal)barc);
                    // pixels for each time stamp
                    const int pixperbarlabel = 60;
                    // number of labels we have room to draw
                    int numbarlabels = (int)((double)(r.Width - border - ((double)border / 3)) / pixperbarlabel);
                    // draw a label every so many bars (assume every bar to star)
                    int labeleveryX = 1;
                    // if there's more bars than space
                    if (barc > numbarlabels)
                    {
                        labeleveryX = (int)Math.Round(((double)barc / numbarlabels));
                    }
                    // get dollar range for chart
                    decimal range = (highesth - lowestl);
                    // get pixels available for each dollar of movement
                    pixperdollar = range == 0 ? 0 : (((decimal)r.Height - hborder * 1.27m) / range);


                    // x-axis
                    g.DrawLine(new Pen(fgcol), (int)(border / 3), r.Height - hborder, r.Width - border, r.Height - hborder);
                    // y-axis
                    g.DrawLine(new Pen(fgcol), r.Width - border, r.Y + ((float)hborder / 3), r.Width - border, r.Height - hborder);

                    const int minxlabelwidth = 30;


                    int lastlabelcoord     = -500;
                    int lastmonthyearcoord = -500;

                    for (int i = 0; i < barc; i++)
                    {
                        // get bar color
                        Color bcolor = (bl.Close()[i] > bl.Open()[i]) ? UpBarColor : DownBarColor;
                        p = new Pen(bcolor);
                        try
                        {
                            if (isUsingShadedCloses)
                            {
                                // skip first bar
                                if (i > 0)
                                {
                                    // get close of previouc
                                    var pcx = getX(i - 1);
                                    var pcy = getY(bl.Close()[i - 1]);
                                    var cx  = getX(i);
                                    var cy  = getY(bl.Close()[i]);
                                    var pts = new Point[] {
                                        new Point(pcx, getY(lowestl)),
                                        new Point(pcx, pcy),
                                        new Point(cx, cy),
                                        new Point(cx, getY(lowestl))
                                    };

                                    g.FillPolygon(new SolidBrush(Color.CadetBlue), pts);
                                }
                            }

                            else
                            {
                                // draw high/low bar
                                g.DrawLine(p, getX(i), getY(bl.Low()[i]), getX(i), getY(bl.High()[i]));
                                // draw open bar
                                g.DrawLine(p, getX(i), getY(bl.Open()[i]), getX(i) - (int)(pixperbar / 3), getY(bl.Open()[i]));
                                // draw close bar
                                g.DrawLine(p, getX(i), getY(bl.Close()[i]), getX(i) + (int)(pixperbar / 3), getY(bl.Close()[i]));
                            }


                            // draw time labels (time @30min and date@noon)

                            // if interval is intra-day
                            if (bl.DefaultInterval != BarInterval.Day)
                            {
                                // every 6 bars draw the bartime
                                if ((i % labeleveryX) == 0)
                                {
                                    g.DrawString((bl.Time()[i] / 100).ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (f.Font.GetHeight() * 3));
                                }
                                // if it's noon, draw the date
                                if (bl.Time()[i] == 120000)
                                {
                                    g.DrawString(bl.Date()[i].ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (float)(f.Font.GetHeight() * 1.5));
                                }
                            }
                            else // otherwise it's daily data
                            {
                                // get date
                                int[] date        = Calc.Date(bl.Date()[i]);
                                int[] lastbardate = date;
                                // get previous bar date if we have one
                                if ((i - 1) > 0)
                                {
                                    lastbardate = Calc.Date(bl.Date()[i - 1]);
                                }
                                // if we have room since last time we drew the year
                                if ((getX(lastlabelcoord) + minxlabelwidth) <= getX(i))
                                {
                                    // get coordinate for present days label
                                    lastlabelcoord = i;
                                    // draw day
                                    g.DrawString(date[2].ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (f.Font.GetHeight() * 3));
                                }
                                // if it's first bar, a new month or new year
                                if ((i == 0) || (lastbardate[1] != date[1]) && ((getX(lastmonthyearcoord) + minxlabelwidth) <= getX(i)))
                                {
                                    // get coordinate for present month/year label
                                    lastmonthyearcoord = i;
                                    // get the month
                                    string ds = date[1].ToString();
                                    // if it first bar or the year has changed, add year to month
                                    if ((i == 0) || (lastbardate[0] != date[0]))
                                    {
                                        var yds = date[0].ToString();
                                        ds += '/' + yds.Substring(yds.Length - 2, 2);
                                    }
                                    // draw the month
                                    g.DrawString(ds, f.Font, new SolidBrush(fgcol), getX(i), r.Height - (float)(f.Font.GetHeight() * 1.5));
                                }
                            }
                        }
                        catch (OverflowException) { }
                    }

                    // DRAW YLABELS
                    // max number of even intervaled ylabels possible on yaxis
                    int numlabels = (int)((r.Height - ((double)hborder / 3)) / (f.Font.GetHeight() * 2));
                    // nearest price units giving "pretty" even intervaled ylabels
                    decimal priceunits = NearestPrettyPriceUnits(highesth - lowestl, ref numlabels);
                    // starting price point from low end of range, including lowest low in barlist
                    decimal lowstart  = lowestl - ((lowestl * 100) % (priceunits * 100)) / 100;
                    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);
                        if (price > highesth)
                        {
                            break;
                        }
                        var labx   = r.Width - border;
                        var pricey = getY(price);
                        var laby   = pricey - f.Font.GetHeight();
                        g.DrawString(price.ToString("C"), f.Font, new SolidBrush(fgcol), labx, laby);
                        g.DrawLine(priceline, border / 3, getY(price), labx, pricey);
                    }
                    if (DisplayInterval && (bl != null))
                    {
                        const int dix       = 3;
                        const int diy       = 3;
                        var       intstring = bl.DefaultInterval.ToString();
                        intervalstringendx = dix + (int)g.MeasureString(intstring, f.Font).Width;
                        g.DrawString(intstring, f.Font, new SolidBrush(fgcol), dix, diy);
                    }
                    else
                    {
                        intervalstringendx = 0;
                    }

                    DrawLabels();
                }
            }
            catch (Exception ex)
            {
                g.DrawString("Error, submit actions to community.tradelink.org " + ex.Message + ex.StackTrace, new Font(FontFamily.GenericSerif, 8, FontStyle.Bold), Brushes.Red, new PointF(r.Width / 3, r.Height / 2));
            }
        }
コード例 #6
0
        void Chart_Paint(object sender, PaintEventArgs e)
        {
            // get form
            ChartControl f = (ChartControl)sender;

            // get graphics
            g = e.Graphics;
            // get window
            r = ClientRectangle;
            // get title
            Text = Title;
            // check for data
            if ((bl == null) || (bl.Intervals.Length == 0) || (bl.Count == 0))
            {
                g.DrawString("Unknown symbol, or no data.", new Font(FontFamily.GenericSerif, 14, FontStyle.Bold), Brushes.Red, new PointF(r.Width / 3, r.Height / 2));
                return;
            }
            // setup to draw
            Pen p = new Pen(Color.Black);

            g.Clear(f.BackColor);
            // get number of pixels available for each bar, based on screensize and barcount
            pixperbar = (((decimal)r.Width - (decimal)border - ((decimal)border / 3)) / (decimal)barc);
            // pixels for each time stamp
            const int pixperbarlabel = 60;
            // number of labels we have room to draw
            int numbarlabels = (int)((double)(r.Width - border - ((double)border / 3)) / pixperbarlabel);
            // draw a label every so many bars (assume every bar to star)
            int labeleveryX = 1;

            // if there's more bars than space
            if (barc > numbarlabels)
            {
                labeleveryX = (int)Math.Round(((double)barc / numbarlabels));
            }
            // get dollar range for chart
            decimal range = (highesth - lowestl);

            // get pixels available for each dollar of movement
            pixperdollar = range == 0 ? 0 : (((decimal)r.Height - (decimal)border * 2) / range);


            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 = 30;

            int lastlabelcoord = -500;

            for (int i = 0; i < barc; i++)
            {
                // get bar color
                Color bcolor = (bl[i].Close > bl[i].Open) ? Color.Green : Color.Red;
                p = new Pen(bcolor);
                try
                {
                    // draw high/low bar
                    g.DrawLine(p, getX(i), getY(bl[i].Low), getX(i), getY(bl[i].High));
                    // draw open bar
                    g.DrawLine(p, getX(i), getY(bl[i].Open), getX(i) - (int)(pixperbar / 3), getY(bl[i].Open));
                    // draw close bar
                    g.DrawLine(p, getX(i), getY(bl[i].Close), getX(i) + (int)(pixperbar / 3), getY(bl[i].Close));
                    // draw time labels (time @30min and date@noon)

                    // if interval is intra-day
                    if (bl.DefaultInterval != BarInterval.Day)
                    {
                        // every 6 bars draw the bartime
                        if ((i % labeleveryX) == 0)
                        {
                            g.DrawString((bl[i].Bartime / 100).ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (f.Font.GetHeight() * 3));
                        }
                        // if it's noon, draw the date
                        if (bl[i].Bartime == 120000)
                        {
                            g.DrawString(bl[i].Bardate.ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (float)(f.Font.GetHeight() * 1.5));
                        }
                    }
                    else // otherwise it's daily data
                    {
                        // get date
                        int[] date        = Calc.Date(bl[i].Bardate);
                        int[] lastbardate = date;
                        // get previous bar date if we have one
                        if ((i - 1) > 0)
                        {
                            lastbardate = Calc.Date(bl[i - 1].Bardate);
                        }
                        // if we have room since last time we drew the year
                        if ((getX(lastlabelcoord) + minxlabelwidth) <= getX(i))
                        {
                            // get coordinate for present days label
                            lastlabelcoord = i;
                            // draw day
                            g.DrawString(date[2].ToString(), f.Font, new SolidBrush(fgcol), getX(i), r.Height - (f.Font.GetHeight() * 3));
                        }
                        // if it's first bar or a new month
                        if ((i == 0) || (lastbardate[1] != date[1]))
                        {
                            // get the month
                            string ds = date[1].ToString();
                            // if it sfirst bar or the year has changed, add year to month
                            if ((i == 0) || (lastbardate[0] != date[0]))
                            {
                                ds += '/' + date[0].ToString();
                            }
                            // draw the month
                            g.DrawString(ds, f.Font, new SolidBrush(fgcol), getX(i), r.Height - (float)(f.Font.GetHeight() * 1.5));
                        }
                    }
                }
                catch (OverflowException) { }
            }

            // 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();
        }