public override T GetValue(int index) { ITimeSeries series = TimeSeries; if (series == null) { // Series is null; the indicator doesn't need cache. // (e.g. simple computation of the value) // --> Calculating the value return(Calculate(index)); } // Series is not null int removedTicksCount = series.GetRemovedBarsCount(); int maximumResultCount = series.GetMaximumBarCount(); T result; if (index < removedTicksCount) { // Result already removed from cache increaseLengthTo(removedTicksCount, maximumResultCount); HighestResultIndex = removedTicksCount; result = _results[0]; if (Equals(result, default(T))) { // It should be "result = calculate(removedTicksCount);". // We use "result = calculate(0);" as a workaround // to fix issue #120 (https://github.com/mdeverdelhan/ta4j/issues/120). result = Calculate(0); _results[0] = result; } } else { increaseLengthTo(index, maximumResultCount); if (index > HighestResultIndex) { // Result not calculated yet HighestResultIndex = index; result = Calculate(index); _results[_results.Count - 1] = result; } else { // Result covered by current cache int resultInnerIndex = _results.Count - 1 - (HighestResultIndex - index); result = _results[resultInnerIndex]; if (Equals(result, default(T))) { result = Calculate(index); } _results[resultInnerIndex] = result; } } return(result); }
public BaseTimeSeries(ITimeSeries defaultSeries, int seriesBeginIndex, int seriesEndIndex) : this(defaultSeries.Name, defaultSeries.GetBarData().ToList(), seriesBeginIndex, seriesEndIndex, true) { if (defaultSeries.GetBarData() == null || defaultSeries.GetBarData().isEmpty()) { throw new ArgumentException("Cannot create a constrained series from a time series with a null/empty list of bars"); } if (defaultSeries.GetMaximumBarCount() != int.MaxValue) { throw new ArgumentException("Cannot create a constrained series from a time series for which a maximum bar count has been set"); } }