Exemple #1
0
        private void AddIndicator(ChartIndicatorElement element)
        {
            var series = (CandleSeries)_bufferedChart.GetSource(element);

            if (series == null)
            {
                return;
            }

            if (_sourceElements.ContainsKey(series.Security))
            {
                return;
            }

            List <RefPair <DateTimeOffset, IDictionary <IChartElement, object> > > allValues;

            lock (_syncRoot)
            {
                allValues = series
                            .GetCandles <TimeFrameCandle>()
                            .Take(_candlesCount)
                            .Select(candle => new RefPair <DateTimeOffset, IDictionary <IChartElement, object> >(candle.OpenTime, new Dictionary <IChartElement, object>
                {
                    { element, CreateIndicatorValue(element, candle) }
                }))
                            .ToList();

                _skipElements.Remove(element);
            }

            _bufferedChart.Reset(new[] { element });
            _bufferedChart.Draw(allValues);
        }
Exemple #2
0
        public CandleChartPanel()
        {
            InitializeComponent();

            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            cmdSvc.Register <ChartDrawCommand>(this, false, cmd => _bufferedChart.Draw(cmd.Values));
            cmdSvc.Register <ChartAddAreaCommand>(this, false, cmd => _bufferedChart.AddArea(cmd.Area));
            cmdSvc.Register <ChartRemoveAreaCommand>(this, false, cmd => _bufferedChart.RemoveArea(cmd.Area));
            cmdSvc.Register <ChartAddElementCommand>(this, false, cmd => _bufferedChart.AddElement(cmd.Area, cmd.Element));
            cmdSvc.Register <ChartRemoveElementCommand>(this, false, cmd => _bufferedChart.RemoveElement(cmd.Area, cmd.Element));
            cmdSvc.Register <ChartClearAreasCommand>(this, false, cmd => _bufferedChart.ClearAreas());
            cmdSvc.Register <ChartResetElementsCommand>(this, false, cmd => _bufferedChart.Reset(cmd.Elements));
            cmdSvc.Register <ChartAutoRangeCommand>(this, false, cmd => _bufferedChart.IsAutoRange = cmd.AutoRange);
            cmdSvc.Register <ResetedCommand>(this, true, cmd => OnReseted());
            cmdSvc.Register <BindStrategyCommand>(this, true, cmd =>
            {
                if (!cmd.CheckControl(this))
                {
                    return;
                }

                if (_strategy == cmd.Source)
                {
                    return;
                }

                _strategy = cmd.Source;

                SetChart(true);

                ChartPanel.IsInteracted = _strategy != null && _strategy.GetIsInteracted();

                if (_settingsStorage != null)
                {
                    ChartPanel.Load(_settingsStorage);
                }

                TryCreateDefaultSeries();
            });

            ChartPanel.SettingsChanged           += () => new ControlChangedCommand(this).Process(this);
            ChartPanel.RegisterOrder             += order => new RegisterOrderCommand(order).Process(this);
            ChartPanel.SubscribeCandleElement    += OnChartPanelSubscribeCandleElement;
            ChartPanel.SubscribeIndicatorElement += OnChartPanelSubscribeIndicatorElement;
            ChartPanel.SubscribeOrderElement     += OnChartPanelSubscribeOrderElement;
            ChartPanel.SubscribeTradeElement     += OnChartPanelSubscribeTradeElement;
            ChartPanel.UnSubscribeElement        += OnChartPanelUnSubscribeElement;

            var indicatorTypes = ConfigManager
                                 .GetService <IAlgoService>()
                                 .IndicatorTypes;

            ChartPanel.MinimumRange = 200;
            ChartPanel.IndicatorTypes.AddRange(indicatorTypes);

            _bufferedChart = new BufferedChart(ChartPanel);

            WhenLoaded(() => new RequestBindSource(this).SyncProcess(this));
        }