private void SetItemsSource(Point point, ISupportAxes2D series)
 {
     try
     {
         var    chartSeries = series as ChartSeries;
         double pointx      = Math.Truncate(ChartArea.PointToValue(series.ActualXAxis, point));
         double pointy      = Math.Truncate(ChartArea.PointToValue(series.ActualYAxis, point));
         if (chartSeries == null || (!(pointx >= 0) || !(pointx < chartSeries.DataCount)))
         {
             return;
         }
         customInfo = new ChartCustomInfo
         {
             LabelX = chartSeries.Label,
             LabelY = ChartArea.SecondaryAxis.Header.ToString()
         };
         var dataSource = chartSeries.ItemsSource as List <StockData>;
         if (dataSource != null)
         {
             customInfo.ValueX = dataSource[(int)pointx].TimeStamp.ToString("MM-dd-yyyy");
         }
         customInfo.ValueY       = pointy.ToString(series.ActualYAxis.LabelFormat, CultureInfo.CurrentCulture);
         customInfo.YValues      = GetYValuesBasedOnIndex(pointx, chartSeries);
         yCount                  = customInfo.YValues.Count;
         customInfo.LabelYValues = GetLabelYValues();
         customInfo.Visibility   = Visibility.Visible;
         PointInfos.Add(customInfo);
         PositionSummaryControl(pointx, chartSeries);
     }
     catch
     {
     }
 }
        private void OnIndicatorsSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            indicatorsCollection.Clear();
            this.SfChart.TechnicalIndicators.Clear();

            if (comboBox != null)
            {
                var indicator = Addindicator(comboBox.SelectedItem.ToString(), 1);
                if (indicator != null)
                {
                    indicatorsCollection.Add(indicator);
                }
            }

            foreach (var item in indicatorsCollection)
            {
                ISupportAxes2D indicatorAxis = item as ISupportAxes2D;
                if (indicatorAxis != null)
                {
                    this.SfChart.TechnicalIndicators.Add(item);
                    NumericalAxis axis = new NumericalAxis();
                    axis.OpposedPosition = true;
                    axis.ShowGridLines   = false;
                    axis.Visibility      = Visibility.Collapsed;
                    indicatorAxis.YAxis  = axis;
                }
            }
        }
        void IndicatorSource2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            indicatorsCollection.Clear();
            this.ChartArea.TechnicalIndicators.Clear();
            foreach (var indi in IndicatorSource2.SelectedItems)
            {
                var indicator = Addindicator((string)indi, 1);
                if (indicator != null)
                {
                    indicatorsCollection.Add(indicator);
                }
            }

            foreach (var item in indicatorsCollection)
            {
                ISupportAxes2D indicatorAxis = item as ISupportAxes2D;
                var            index         = SfChart.GetRow(indicatorAxis.YAxis);
                if (index == 0)
                {
                    this.ChartArea.TechnicalIndicators.Add(item);
                    NumericalAxis axis = new NumericalAxis();
                    axis.OpposedPosition = true;
                    axis.ShowGridLines   = false;
                    axis.Visibility      = Visibility.Collapsed;
                    indicatorAxis.YAxis  = axis;
                    SfChart.SetRow(indicatorAxis.YAxis, 0);
                }
            }
        }
        private FinancialTechnicalIndicator Addindicator(string value)
        {
            FinancialTechnicalIndicator indicator;

            switch (value)
            {
            case "Accumulation Distribution":
                indicator = new AccumulationDistributionIndicator();
                break;

            case "Average True Range":
                indicator = new AverageTrueRangeIndicator()
                {
                    Period = 1
                };
                break;

            case "Bollinger Band":
                indicator = new BollingerBandIndicator()
                {
                    UpperLineColor = Brushes.Green,
                    Period         = 3
                };
                break;

            case "Exponential Average":
                indicator = new ExponentialAverageIndicator();
                break;

            case "MACD":
                indicator = new MACDTechnicalIndicator()
                {
                    Period               = 5,
                    LongPeriod           = 12,
                    ShortPeriod          = 6,
                    ConvergenceLineColor = Brushes.Green
                };
                break;

            case "Momentum":
                indicator = new MomentumTechnicalIndicator()
                {
                    Period = 4
                };
                break;

            case "RSI":
                indicator = new RSITechnicalIndicator()
                {
                    Period         = 4,
                    UpperLineColor = Brushes.Green
                };
                break;

            case "Simple Average":
                indicator = new SimpleAverageIndicator();
                break;

            case "Stochastic":
                indicator = new StochasticTechnicalIndicator()
                {
                    UpperLineColor = Brushes.Green
                };
                break;

            case "Triangular Average":
                indicator = new TriangularAverageIndicator();
                break;

            default:
                return(null);
            }

            indicator.XBindingPath = "TimeStamp";
            indicator.High         = "High";
            indicator.Low          = "Low";
            indicator.Open         = "Open";
            indicator.Close        = "Last";
            indicator.Volume       = "Volume";
            Binding binding = new Binding();

            binding.Path   = new PropertyPath("Datas");
            binding.Source = this;
            binding.Mode   = BindingMode.TwoWay;
            indicator.SetBinding(FinancialTechnicalIndicator.ItemsSourceProperty, binding);

            ISupportAxes2D indicatorAxis = indicator as ISupportAxes2D;

            if (indicatorAxis != null)
            {
                NumericalAxis axis = new NumericalAxis();
                axis.OpposedPosition = true;
                axis.ShowGridLines   = false;
                axis.Visibility      = Visibility.Collapsed;
                indicatorAxis.YAxis  = axis;
            }

            return(indicator);
        }