/// <summary>
        /// Action executed when Indicator needs to be recalculated
        /// </summary>
        /// <returns></returns>
        protected override bool TrueAction()
        {
            int size = _chartPanel._chartX.RecordCount;

            if (size == 0)
            {
                return(false);
            }

            double?[] values = new double?[size];

            StockChartX.CustomIndicatorNeedsDataEventArgs args =
                new StockChartX.CustomIndicatorNeedsDataEventArgs(this, values);

            for (int i = 0; i < size; i++)
            {
                values[i] = this[i].Value;
            }

            _chartPanel._chartX.FireCustomIndicatorNeedsData(args);

            int usersValuesLength = args.Values.Length;
            int minLength         = Math.Min(size, usersValuesLength);

            Clear();
            for (int i = 0; i < minLength; i++)
            {
                AppendValue(_chartPanel._chartX._dataManager.GetTimeStampByIndex(i), args.Values[i]);
            }

            _chartPanel._enforceSeriesSetMinMax = true;
            _chartPanel.SetMaxMin();

            return(_calculateResult = PostCalculate());
        }
Beispiel #2
0
        private void _stockChartX_CustomIndicatorNeedsData(object sender, StockChartX.CustomIndicatorNeedsDataEventArgs e)
        {
            double?[] data = new double?[_stockChartX.RecordCount];

            //do here some calculations and pass them back to the chart
            int    startValue = _r.Next(20, 40);
            double lastValue  = startValue;

            //e.Values has the values already calculated from previous call
            //Here we just re-fill the array with random values
            for (int i = 0; i < data.Length; i++)
            {
                if (_r.NextDouble() > 0.5)
                {
                    lastValue += _r.NextDouble() * 0.25;
                }
                else
                {
                    lastValue -= _r.NextDouble() * 0.25;
                }

                data[i] = lastValue;
            }
            //pass calculated values back to the chart
            e.Values = data;
        }