private void OnNewIndicator(IndicatorBar indicator) //Следующий точка графика
        {
            double   y0, y1, y2, y3;
            double   y00, y10, y20, y30;
            DateTime localDate = DateTime.Now;
            Random   rng       = new Random();

            y0  = 0.5 - rng.NextDouble();
            y00 = 27.74 + y0;

            Random rng0 = new Random();

            y1  = 0.5 - rng0.NextDouble();
            y10 = 1008.33 + y1;

            Random rng1 = new Random();

            y2  = 0.5 - rng1.NextDouble();
            y20 = 41.06 + y2;

            Random rng2 = new Random();

            y3  = 0.5 - rng2.NextDouble();
            y30 = 57.77 + y3;

            // Убедитесь, что одновременно с многопоточным таймером обрабатывается только одно обновление
            lock (this)
            {
                // Добавление или обновление точки графика?
                var ds0 = (IXyDataSeries <DateTime, double>)_seriesViewModels[0].DataSeries; //Температура
                var ds1 = (IXyDataSeries <DateTime, double>)_seriesViewModels[1].DataSeries; //Давление
                var ds2 = (IXyDataSeries <DateTime, double>)_seriesViewModels[2].DataSeries; //Приблизительная высота
                var ds3 = (IXyDataSeries <DateTime, double>)_seriesViewModels[3].DataSeries; //Влажность

                if (_lastindicator != null && _lastindicator.DateTime == indicator.DateTime)
                {
                    ds0.Update(localDate, y00);
                    ds1.Update(localDate, y10);
                    ds2.Update(localDate, y20);
                    ds3.Update(localDate, y30);
                }
                else
                {
                    ds0.Append(localDate, y00);
                    ds1.Append(localDate, y10);
                    ds2.Append(localDate, y20);
                    ds3.Append(localDate, y30);

                    if (XVisibleRange.Max > ds0.Count)
                    {
                        var existingRange = _xVisibleRange;
                        var newRange      = new IndexRange(existingRange.Min + 1, existingRange.Max + 1);
                        XVisibleRange = newRange;
                    }
                }

                _lastindicator = indicator;
            }
        }
예제 #2
0
        private IndicatorBar GetUpdatedData()
        {
            double num       = _lastIndicatorBar.Close + ((_random.NextDouble() - 0.48) * (_lastIndicatorBar.Close / 100.0));
            double high      = (num > _lastIndicatorBar.High) ? num : _lastIndicatorBar.High;
            double low       = (num < _lastIndicatorBar.Low) ? num : _lastIndicatorBar.Low;
            long   volumeInc = (long)((_random.NextDouble() * 30000 + 20000) * 0.05);

            _lastIndicatorBar = new IndicatorBar(_lastIndicatorBar.DateTime, _lastIndicatorBar.Open, high, low, num, _lastIndicatorBar.Volume + volumeInc);

            return(_lastIndicatorBar);
        }
예제 #3
0
        public RandomIndicatorsDataSource(int candleIntervalMinutes, bool simulateDateGap, double timerInterval, int updatesPerPrice, int randomSeed, double startingPrice, DateTime startDate)
        {
            _candleIntervalMinutes = candleIntervalMinutes;
            _simulateDateGap       = simulateDateGap;
            _updatesPerPrice       = updatesPerPrice;

            _timer = new Timer(timerInterval)
            {
                Enabled   = false,
                AutoReset = true,
            };
            _timer.Elapsed      += TimerElapsed;
            _initialIndicatorBar = new IndicatorBarInfo
            {
                Close    = startingPrice,
                DateTime = startDate
            };
            _lastIndicatorBar = new IndicatorBar(_initialIndicatorBar.DateTime, _initialIndicatorBar.Close, _initialIndicatorBar.Close, _initialIndicatorBar.Close, _initialIndicatorBar.Close, 0L);
            _random           = new Random(randomSeed);
        }
예제 #4
0
        private IndicatorBar GetNextRandomPriceBar()
        {
            double       close     = _lastIndicatorBar.Close;
            double       num       = (_random.NextDouble() - 0.9) * _initialIndicatorBar.Close / 30.0;
            double       num2      = _random.NextDouble();
            double       num3      = _initialIndicatorBar.Close + _initialIndicatorBar.Close / 2.0 * Math.Sin(7.27220521664304E-06 * _currentTime) + _initialIndicatorBar.Close / 16.0 * Math.Cos(7.27220521664304E-05 * _currentTime) + _initialIndicatorBar.Close / 32.0 * Math.Sin(7.27220521664304E-05 * (10.0 + num2) * _currentTime) + _initialIndicatorBar.Close / 64.0 * Math.Cos(7.27220521664304E-05 * (20.0 + num2) * _currentTime) + num;
            double       num4      = Math.Max(close, num3);
            double       num5      = _random.NextDouble() * _initialIndicatorBar.Close / 100.0;
            double       high      = num4 + num5;
            double       num6      = Math.Min(close, num3);
            double       num7      = _random.NextDouble() * _initialIndicatorBar.Close / 100.0;
            double       low       = num6 - num7;
            long         volume    = (long)(_random.NextDouble() * 30000 + 20000);
            DateTime     openTime  = _simulateDateGap ? EmulateDateGap(_lastIndicatorBar.DateTime) : _lastIndicatorBar.DateTime;
            DateTime     closeTime = openTime.AddMinutes(_candleIntervalMinutes);
            IndicatorBar candle    = new IndicatorBar(closeTime, close, high, low, num3, volume);

            _lastIndicatorBar = new IndicatorBar(candle.DateTime, candle.Open, candle.High, candle.Low, candle.Close, volume);
            _currentTime     += _candleIntervalMinutes * 60;
            return(candle);
        }
예제 #5
0
 private void OnTimerElapsed()
 {
     if (_currentUpdateCount < _updatesPerPrice)
     {
         _currentUpdateCount++;
         IndicatorBar updatedData = GetUpdatedData();
         if (UpdateData != null)
         {
             UpdateData(updatedData);
         }
     }
     else
     {
         _currentUpdateCount = 0;
         IndicatorBar nextData = GetNextData();
         if (NewData != null)
         {
             NewData(nextData);
         }
     }
 }
예제 #6
0
        public IndicatorBar GetNextData()
        {
            IndicatorBar nextRandomPriceBar = GetNextRandomPriceBar();

            return(nextRandomPriceBar);
        }