Ejemplo n.º 1
0
        private void ChartUpdateTimerOnTick(object sender, EventArgs eventArgs)
        {
            if (IsRealtime.IsChecked == true && _lastPrice != 0m)
            {
                var step  = PriceStep.Value ?? 10;
                var price = Round(_lastPrice + (decimal)((RandomGen.GetDouble() - 0.5) * 5 * step), (decimal)step);
                AppendTick(_security, new ExecutionMessage
                {
                    ServerTime = _lastTime,
                    TradePrice = price,
                    Volume     = RandomGen.GetInt(50) + 1
                });
                _lastTime += TimeSpan.FromSeconds(10);
            }

            TimeFrameCandle[] candlesToUpdate;
            lock (_updatedCandles.SyncRoot)
            {
                candlesToUpdate = _updatedCandles.OrderBy(p => p.Key).Select(p => p.Value).ToArray();
                _updatedCandles.Clear();
            }

            _allCandles.AddRange(candlesToUpdate);

            candlesToUpdate.ForEach(c =>
            {
                BoxChart.Draw(c.OpenTime, new Dictionary <IChartElement, object>
                {
                    { _candleElement1, c },
                    { _bvElement, c }
                });

                ClusterChart.Draw(c.OpenTime, new Dictionary <IChartElement, object>
                {
                    { _candleElement2, c },
                    { _cpElement, c }
                });
            });
        }
Ejemplo n.º 2
0
        private void InitCharts()
        {
            BoxChart.ClearAreas();
            ClusterChart.ClearAreas();

            _areaComb = new ChartArea();
            _areaBVR1 = new ChartArea();
            _areaBVR2 = new ChartArea();

            _areaComb.YAxises.Add(new ChartAxis
            {
                Id            = _chartMainYAxis,
                AutoRange     = false,
                AxisType      = ChartAxisType.Numeric,
                AxisAlignment = ChartAxisAlignment.Right,
            });

            _areaBVR2.YAxises.Add(new ChartAxis
            {
                Id            = _chartMainYAxis,
                AutoRange     = false,
                AxisType      = ChartAxisType.Numeric,
                AxisAlignment = ChartAxisAlignment.Right,
            });

            BoxChart.AddArea(_areaComb);

            ClusterChart.AddArea(_areaBVR1);
            ClusterChart.AddArea(_areaBVR2);

            _timeframe = int.Parse((string)((ComboBoxItem)Timeframe.SelectedItem).Tag);
            var step = (decimal)PriceStep.Value.Value;

            var series = new CandleSeries(
                typeof(TimeFrameCandle),
                _security,
                TimeSpan.FromMinutes(_timeframe));

            _candleElement1 = new ChartCandleElement {
                FullTitle = "Candles", YAxisId = _chartMainYAxis
            };
            BoxChart.AddElement(_areaComb, _candleElement1, series);

            _bvElement = new ChartBoxVolumeElement(_timeframe, step)
            {
                FullTitle = "BoxVolume", YAxisId = _chartMainYAxis
            };
            BoxChart.AddElement(_areaComb, _bvElement);

            _cpElement = new ChartClusterProfileElement(_timeframe, step)
            {
                FullTitle = "Cluster profile"
            };
            ClusterChart.AddElement(_areaBVR1, _cpElement);

            _candleElement2 = new ChartCandleElement {
                FullTitle = "Candles", YAxisId = _chartMainYAxis
            };
            ClusterChart.AddElement(_areaBVR2, _candleElement2, series);

            var ns = typeof(IIndicator).Namespace;

            var rendererTypes = typeof(Chart).Assembly
                                .GetTypes()
                                .Where(t => !t.IsAbstract && typeof(BaseChartIndicatorPainter).IsAssignableFrom(t))
                                .ToDictionary(t => t.Name);

            var indicators = typeof(IIndicator).Assembly
                             .GetTypes()
                             .Where(t => t.Namespace == ns && !t.IsAbstract && typeof(IIndicator).IsAssignableFrom(t))
                             .Select(t =>
            {
                var name = t.Name;
                var p    = rendererTypes.TryGetValue(name + "Painter");
                if (p == null)
                {
                    if (t.Name.EndsWith("Indicator"))
                    {
                        name = name.Substring(0, name.Length - "Indicator".Length);
                    }

                    p = rendererTypes.TryGetValue(name + "Painter");
                }

                return(new IndicatorType(t, p));
            })
                             .ToArray();

            BoxChart.IndicatorTypes.AddRange(indicators);
            ClusterChart.IndicatorTypes.AddRange(indicators);
        }