コード例 #1
0
ファイル: Chart.cs プロジェクト: SuffArt/BitWhiskey
        void DrawPrice()
        {
            Dictionary <int, PriceCandle> pricedata = data.GetNormalizeData();
            List <int> keys = data.GetKeys();

            float pos = draww;

            selectedPriceKey = -1;

            for (int n = lasttick; n > starttick; n--)
            {
                Pen   pen   = style.barUp;
                Brush brush = style.barUpBrush;

                int         key1   = keys[n - 1];
                int         date1  = key1;
                PriceCandle price1 = pricedata[key1];
                int         key2   = keys[n];
                int         date2  = key2;
                PriceCandle price2 = pricedata[key2];
                bool        fill   = false;
                if (price2.close < price2.open)
                {
                    pen   = style.barDown;
                    brush = style.barDownBrush;
                    fill  = true;
                }
                float barspace = 0;

                if (mousedrawx != -1)
                {
                    if (mousedrawx >= pos - barsizex && mousedrawx < pos)
                    {
                        pen              = new Pen(Color.Yellow);
                        brush            = new SolidBrush(Color.Yellow);
                        selectedPriceKey = key2;
                    }
                }

                if (barsizex > 2)
                {
                    barspace = 2;
                    float  realbarsize = barsizex - barspace;
                    PointF p           = new PointF(pos - barsizex, (float)Math.Min(price2.close, price2.open));
                    PointF size        = new PointF(realbarsize, (float)Math.Abs(price2.close - price2.open));
                    AreaDrawRectangle(pen, brush, p, size, fill);

                    PointF p1 = new PointF(pos - barsizex / 2 - barspace / 2, (float)price2.high);
                    PointF p2 = new PointF(pos - barsizex / 2 - barspace / 2, (float)Math.Max(price2.close, price2.open));
                    AreaDrawLine(pen, p1, p2);

                    p1 = new PointF(pos - barsizex / 2 - barspace / 2, (float)price2.low);
                    p2 = new PointF(pos - barsizex / 2 - barspace / 2, (float)Math.Min(price2.close, price2.open));
                    if (p1.X == p2.X && p1.Y == p2.Y)
                    {
                        p2.X += 1;
                    }
                    AreaDrawLine(pen, p1, p2);

/*
 *                  if(price2.high==price2.low)
 *                  {
 *                      p1 = new PointF(pos - barsizex / 2 - barspace / 2-1, (float)price2.close);
 *                      p2 = new PointF(pos - barsizex / 2 - barspace / 2+1, (float)price2.close);
 *                      AreaDrawLine(pen, p1, p2);
 *                  }
 */
                }
                else
                {
                    PointF p1 = new PointF(pos - barsizex / 2, (float)price2.low);
                    PointF p2 = new PointF(pos - barsizex / 2, (float)price2.high);
                    if (p1.X == p2.X && p1.Y == p2.Y)
                    {
                        p2.Y += 1;
                    }
                    AreaDrawLine(pen, p1, p2);
                }
                pos -= barsizex;
            }
        }
コード例 #2
0
        void DrawPrice()
        {
            Dictionary <int, PriceCandle> pricedata = data.GetNormalizeData();
            List <int> keys = data.GetKeys();

            float pos = draw.draww;

            selectedPriceKey = -1;

            Dictionary <int, PriceCandle> realData = data.GetData();
            PriceCandle lastPrice    = realData.Last().Value; //[keys[lasttick]];
            string      strLastPrice = Helper.PriceToString(lastPrice.close);

            draw.DrawString(style.strLastPriceBrush, style.strLastPriceFont, new PointF(draw.draww - 80, draw.areaymax), strLastPrice);

            for (int n = lasttick; n > starttick; n--)
            {
                Pen   pen   = style.barUp;
                Brush brush = style.barUpBrush;

                Pen   volpen   = style.volbarUp;
                Brush volbrush = style.volbarUpBrush;

                int         key1   = keys[n - 1];
                int         date1  = key1;
                PriceCandle price1 = pricedata[key1];
                int         key2   = keys[n];
                int         date2  = key2;
                PriceCandle price2 = pricedata[key2];
                bool        fill   = false;
                if (price2.close < price2.open)
                {
                    pen      = style.barDown;
                    brush    = style.barDownBrush;
                    volpen   = style.volbarDown;
                    volbrush = style.volbarDownBrush;
                    fill     = true;
                }
                float barspace = 0;

                if (mousedrawx != -1)
                {
                    if (mousedrawx >= pos - barsizex && mousedrawx < pos)
                    {
                        pen              = new Pen(Color.Yellow);
                        brush            = new SolidBrush(Color.Yellow);
                        selectedPriceKey = key2;
                    }
                }

                if (barsizex > 2)
                {
                    barspace = 2;
                    float realbarsize = barsizex - barspace;

                    PointF p;
                    PointF size;
                    // volume
                    if (drawVolume)
                    {
                        p    = new PointF(pos - barsizex - 1, (float)0);
                        size = new PointF(realbarsize + 1, (float)price2.volume);
                        draw.AreaDrawRectangle(volpen, volbrush, p, size, true);
                    }
                    // price
                    p    = new PointF(pos - barsizex, (float)Math.Min(price2.close, price2.open));
                    size = new PointF(realbarsize, (float)Math.Abs(price2.close - price2.open));
                    draw.AreaDrawRectangle(pen, brush, p, size, fill);

                    PointF p1 = new PointF(pos - barsizex / 2 - barspace / 2, (float)price2.high);
                    PointF p2 = new PointF(pos - barsizex / 2 - barspace / 2, (float)Math.Max(price2.close, price2.open));
                    draw.AreaDrawLine(pen, p1, p2);

                    p1 = new PointF(pos - barsizex / 2 - barspace / 2, (float)price2.low);
                    p2 = new PointF(pos - barsizex / 2 - barspace / 2, (float)Math.Min(price2.close, price2.open));
                    if (p1.X == p2.X && p1.Y == p2.Y)
                    {
                        p2.X += 1;
                    }
                    draw.AreaDrawLine(pen, p1, p2);
                }
                else
                {
                    PointF p1;
                    PointF p2;

                    // volume
                    if (drawVolume)
                    {
                        p1 = new PointF(pos - barsizex / 2, (float)0);
                        p2 = new PointF(pos - barsizex / 2, (float)price2.volume);
                        if (p1.X == p2.X && p1.Y == p2.Y)
                        {
                            p2.Y += 1;
                        }
                        draw.AreaDrawLine(volpen, p1, p2);
                    }

                    // price
                    p1 = new PointF(pos - barsizex / 2, (float)price2.low);
                    p2 = new PointF(pos - barsizex / 2, (float)price2.high);
                    if (p1.X == p2.X && p1.Y == p2.Y)
                    {
                        p2.Y += 1;
                    }
                    draw.AreaDrawLine(pen, p1, p2);
                }

                pos -= barsizex;
            }
        }