Пример #1
0
        private IndicatorDataItem FindIndicatorDataItem(Dictionary <int, IndicatorDataItem> indicatorDataItems, DateTime targetDate, ref int offset)
        {
            IndicatorDataItem result = null;

            for (int index = offset + 1; index < indicatorDataItems.Count; index++)
            {
                if (indicatorDataItems[index].Time == targetDate)
                {
                    result = indicatorDataItems[index];
                }
                else if (indicatorDataItems[index].Time > targetDate)
                {
                    break;
                }
                offset = index;
            }

            return(result);
        }
Пример #2
0
        public StrategyDataFrame GetStrategyDataFrame(DateTime targetDate, int frameSize)
        {
            strategyDataFrame.Clear();

            BarItem[] bars = pricebarCache.SelectBars(targetDate, frameSize);

            DateTime frameStartDate = bars[0].Time;
            DateTime frameEndDate   = bars[bars.Length - 1].Time;

            StrategyDataItem[] strategyDataItems = this.GetStrategies(frameStartDate, frameEndDate);
            Dictionary <string, Dictionary <int, IndicatorDataItem> > indicatorDataItems = new Dictionary <string, Dictionary <int, IndicatorDataItem> >();

            foreach (KeyValuePair <string, IndicatorCache> indicator in indicatorCacheList)
            {
                indicatorDataItems.Add(indicator.Key, indicator.Value.SelectIndicators(frameStartDate, frameEndDate, frameSize));
            }
            int signalOffset = 0;

            foreach (BarItem bar in bars)
            {
                List <StrategyDataItem> signals = FindStrategyDataItem(strategyDataItems, bar.Time, ref signalOffset);
                Dictionary <string, IndicatorDataItem> indicators = new Dictionary <string, IndicatorDataItem>();
                Dictionary <string, int> indicatorOffsets         = new Dictionary <string, int>();
                foreach (KeyValuePair <string, IndicatorCache> indicator in indicatorCacheList)
                {
                    indicatorOffsets.Add(indicator.Key, 0);
                }
                foreach (KeyValuePair <string, IndicatorCache> indicator in indicatorCacheList)
                {
                    int indicatorOffset = indicatorOffsets[indicator.Key];
                    IndicatorDataItem indicatorDataItem = FindIndicatorDataItem(indicatorDataItems[indicator.Key], bar.Time, ref indicatorOffset);
                    if (indicatorDataItem != null)
                    {
                        indicators.Add(indicator.Key, indicatorDataItem);
                    }
                    indicatorOffsets[indicator.Key] = indicatorOffset;
                }

                //strategyDataFrame.Add(bar.Time, new StrategyDataFrameItem(bar, signals, indicators));
            }

            return(strategyDataFrame);
        }