Beispiel #1
0
        private MinMaxValue GetMinMaxValues()
        {
            MinMaxValue _minmaxv = new MinMaxValue(1000000, -1000000);

            foreach (Bar b in Bars.Values)
            {
                if (b.hiTick.Price > _minmaxv.MaxValue)
                {
                    _minmaxv.MaxValue = b.hiTick.Price;
                }
                if (b.lowTick.Price < _minmaxv.MinValue)
                {
                    _minmaxv.MinValue = b.lowTick.Price;
                }
            }
            return(_minmaxv);
        }
Beispiel #2
0
        private void ClearWorkAreaGraph(double _pixelInPunkt)
        {
            graphC.Children.Clear();
            Rectangle gback = new Rectangle();

            gback.StrokeThickness     = 1;
            gback.Stroke              = Brushes.Black;
            gback.Fill                = Brushes.LightGray;
            gback.SnapsToDevicePixels = true;
            gback.Width               = graphC.ActualWidth - widthYArea;
            gback.Height              = graphC.ActualHeight - heightXArea;
            Canvas.SetLeft(gback, widthYArea);
            Canvas.SetTop(gback, 0);
            graphC.Children.Add(gback);

            MinMaxValue mm         = this.GetMinMaxValues();
            float       stepY      = mm.DeltaValue > 1600 ? 500 : 100;
            float       remainderY = mm.MaxValue % stepY;

            for (float y = mm.MaxValue - remainderY; y > mm.MinValue; y -= stepY)
            {
                Line horizontLine = new Line();
                horizontLine.X1                  = widthYArea;
                horizontLine.X2                  = graphC.ActualWidth;// -widthYArea;
                horizontLine.Y1                  = horizontLine.Y2 = (mm.MaxValue - y) * graphC.ActualHeight / mm.DeltaValue;
                horizontLine.Stroke              = Brushes.Black;
                horizontLine.StrokeThickness     = 1;
                horizontLine.SnapsToDevicePixels = true;
                graphC.Children.Add(horizontLine);
                TextBlock t = new TextBlock();
                t.Text     = y.ToString("### ###");
                t.FontSize = 9;
                graphC.Children.Add(t);
                Canvas.SetLeft(t, 25);
                Canvas.SetTop(t, (mm.MaxValue - y) * graphC.ActualHeight / mm.DeltaValue - 5);
            }
        }
Beispiel #3
0
        //
        // прорисовка графика со свечами
        //
        public void DrawGraph()
        {
            graphC.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                          (ThreadStart) delegate()
            {
                SolidColorBrush barBrushUp   = new SolidColorBrush();
                barBrushUp.Color             = Color.FromArgb(255, 90, 20, 255);
                SolidColorBrush barBrushDown = new SolidColorBrush();
                barBrushDown.Color           = Color.FromArgb(255, 255, 53, 50);

                MinMaxValue mm      = this.GetMinMaxValues();
                double widthBar     = (graphC.ActualWidth - widthYArea) / Bars.Count / 1.3;
                double pixelInPunkt = (mm.MaxValue - mm.MinValue) / (graphC.ActualHeight - heightXArea);
                if (widthBar > 5)
                {
                    widthBar = 5;
                }

                ClearWorkAreaGraph(pixelInPunkt);

                int i = -1;
                foreach (Bar b in Bars.Values)
                {
                    i++;
                    double topB    = (mm.MaxValue - b.hiTick.Price) / pixelInPunkt;
                    double leftB   = i * widthBar * 1.3 + widthYArea;
                    double heightB = (b.hiTick.Price - b.lowTick.Price) / pixelInPunkt;

                    Line currentShadow                = new Line();
                    currentShadow.X1                  = leftB + widthBar / 2;
                    currentShadow.X2                  = leftB + widthBar / 2;
                    currentShadow.Y1                  = topB;
                    currentShadow.Y2                  = topB + heightB;
                    currentShadow.Stroke              = Brushes.Black;
                    currentShadow.StrokeThickness     = 1;
                    currentShadow.SnapsToDevicePixels = true;

                    Rectangle currentBar = new Rectangle();
                    if (b.closeTick.Price >= b.openTick.Price)
                    {
                        currentBar.Fill = barBrushUp;
                    }
                    else
                    {
                        currentBar.Fill = barBrushDown;
                    }

                    currentBar.StrokeThickness     = 1;
                    currentBar.Stroke              = Brushes.Black;
                    currentBar.SnapsToDevicePixels = true;

                    currentBar.Width  = widthBar;
                    currentBar.Height = Math.Abs((b.openTick.Price - b.closeTick.Price) / pixelInPunkt);
                    Canvas.SetTop(currentBar, (mm.MaxValue - Math.Max(b.openTick.Price, b.closeTick.Price)) / pixelInPunkt);
                    Canvas.SetLeft(currentBar, leftB);

                    graphC.Children.Add(currentShadow);
                    graphC.Children.Add(currentBar);
                }
            });
        }