Ejemplo n.º 1
0
        private void Chart_OnSubscribeIndicatorElement(ChartIndicatorElement element, CandleSeries series, IIndicator indicator)
        {
            _dataThreadActions.Add(() =>
            {
                var oldReset = Chart.DisableIndicatorReset;
                try
                {
                    Chart.DisableIndicatorReset = true;
                    indicator.Reset();
                }
                finally
                {
                    Chart.DisableIndicatorReset = oldReset;
                }

                var chartData = new ChartDrawData();

                foreach (var candle in _allCandles.CachedValues)
                {
                    chartData.Group(candle.OpenTime).Add(element, indicator.Process(candle));
                }

                Chart.Reset(new[] { element });
                Chart.Draw(chartData);

                _indicators[element] = indicator;
            });
        }
Ejemplo n.º 2
0
        public static void SetChartViewModelIndicatorPaneData(IList <Candle> candles, ChartViewModel cvm, IIndicator indicator)
        {
            indicator.Reset();
            var indicatorDataSeries = new XyDataSeries <DateTime, double>();

            for (var i = 0; i < candles.Count; i++)
            {
                var time = new DateTime(candles[i].CloseTimeTicks, DateTimeKind.Utc).ToLocalTime();

                var v = indicator.Process(candles[i]);
                indicatorDataSeries.Append(time, v.IsFormed ? v.Value : float.NaN);
            }

            indicatorDataSeries.SeriesName = indicator.Name;

            var indicatorPaneVm = cvm.ChartPaneViewModels.Count > 1 ? cvm.ChartPaneViewModels[1] : null;

            if (indicatorPaneVm == null)
            {
                var indicatorPane = new ChartPaneViewModel(cvm, cvm.ViewportManager)
                {
                    IsFirstChartPane    = false,
                    IsLastChartPane     = true,
                    YAxisTextFormatting = "0.0000"
                };

                indicatorPane.ChartSeriesViewModels.Add(new ChartSeriesViewModel(indicatorDataSeries, new FastLineRenderableSeries
                {
                    AntiAliasing    = false,
                    SeriesColor     = Colors.DarkBlue,
                    StrokeThickness = 2
                }));

                cvm.ChartPaneViewModels.Add(indicatorPane);
            }
            else
            {
                indicatorPaneVm.ChartSeriesViewModels.Clear();
                var fastLineRenderableSeries = new FastLineRenderableSeries
                {
                    AntiAliasing    = false,
                    SeriesColor     = Colors.DarkBlue,
                    StrokeThickness = 2
                };

                indicatorPaneVm.ChartSeriesViewModels.Add(new ChartSeriesViewModel(indicatorDataSeries, fastLineRenderableSeries));
            }
        }