Ejemplo n.º 1
0
        protected override void BindCore()
        {
            BollingerBandsIndicator indicator = this.Owner as BollingerBandsIndicator;
            int        period       = this.Period;
            double     deviations   = this.StandardDeviations;
            SizedQueue currentItems = new SizedQueue(period);

            int    currentIndex = 0;
            double stdDeviation = 0;

            foreach (var item in this.itemsSource)
            {
                object val = this.ValueBinding.GetValue(item);
                currentItems.EnqueueItem((double)val);
                double currentAverage = MovingAverageIndicatorDataSource.CalculateCurrentValue(currentItems);

                // TODO: Nested loop, possible performance degrade for large data
                stdDeviation = CalculateStandardDeviation(currentItems, currentAverage);

                CategoricalDataPoint point, secondPoint;
                if (indicator.Model.DataPointsInternal.Count > currentIndex)
                {
                    point       = this.Owner.Model.DataPointsInternal[currentIndex] as CategoricalDataPoint;
                    point.Value = currentAverage + (deviations * stdDeviation);

                    secondPoint       = indicator.lowerBandModel.DataPointsInternal[currentIndex] as CategoricalDataPoint;
                    secondPoint.Value = currentAverage - (deviations * stdDeviation);
                }
                else
                {
                    point       = this.GenerateDataPoint(item, -1) as CategoricalDataPoint;
                    point.Value = currentAverage + (deviations * stdDeviation);
                    indicator.model.DataPointsInternal.Add(point);

                    secondPoint       = this.GenerateDataPoint(item, -1) as CategoricalDataPoint;
                    secondPoint.Value = currentAverage - (deviations * stdDeviation);
                    indicator.lowerBandModel.DataPointsInternal.Add(secondPoint);
                }

                currentIndex++;
            }
        }
Ejemplo n.º 2
0
        private static void OnLowerBandStrokeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BollingerBandsIndicator indicator = d as BollingerBandsIndicator;

            indicator.lowerBandRenderer.strokeShape.Stroke = e.NewValue as Brush;
        }
Ejemplo n.º 3
0
        private static void OnStandardDeviationsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BollingerBandsIndicator presenter = d as BollingerBandsIndicator;

            (presenter.dataSource as BollingerBandsIndicatorDataSource).StandardDeviations = (int)e.NewValue;
        }