Exemplo n.º 1
0
        public async Task CalculateUpToIndex(int upToIndex) // UNUSED
        {
#if !cAlgo
            bool failedToGetHistoricalData = false;

            //if (CalculatedCount == 0 && !Account.IsBacktesting)
            //{

            //    var minIndex = Math.Max(upToIndex, MarketSeries.LastIndex - Periods);
            //    //for (int index = MarketSeries.MinIndex; index < minIndex; index++)
            //    for (int index = MarketSeries.FirstIndex; index < upToIndex - 1; index++)
            //    {
            //        // Skip unneeded sections
            //        SetBlank(index); // MEMORYOPTIMIZE use sparse arrays instead of filling with blanks
            //    }
            //}
#endif

            var lastIndex = LastIndex == int.MinValue ? -1 : LastIndex;
            for (int index = lastIndex + 1; index <= upToIndex; index++)
            {
#if !cAlgo
                #region Get Historical Data if needed (REFACTOR to base class)

                var lookbackIndex = index - Periods;

                if (lookbackIndex < MarketSeries.FirstIndex)
                {
                    if (!failedToGetHistoricalData)
                    {
                        Debug.WriteLine($"[indicator for {MarketSeries}] Index needed: {lookbackIndex} + but MarketSeries.MinIndex: {MarketSeries.FirstIndex}.  Requesting {2 + MarketSeries.FirstIndex - lookbackIndex} bars from {MarketSeries.OpenTime.First()}");

                        await MarketSeries.EnsureDataAvailable(null, MarketSeries.OpenTime.First(), 2 + MarketSeries.FirstIndex - lookbackIndex).ConfigureAwait(false);
                    }
                    if (lookbackIndex < MarketSeries.FirstIndex)
                    {
                        failedToGetHistoricalData = true; // REVIEW
                                                          // Market data not available
                        SetBlank(index);
                        continue;
                    }
                }
                #endregion
#endif

                await CalculateIndex(index).ConfigureAwait(false);
            }
        }