Exemplo n.º 1
0
        private IndicatorDataItem FindIndicatorDataItem(Dictionary <long, IndicatorDataItem> indicatorDataItems, DateTime targetDate, ref long offset)
        {
            IndicatorDataItem result = null;

            foreach (long key in indicatorDataItems.Keys)
            {
                if (indicatorDataItems[key].Time == targetDate)
                {
                    result = indicatorDataItems[key];
                }
                else if (indicatorDataItems[key].Time > targetDate)
                {
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public SignalDataFrame GetSignalDataFrame(DateTime targetDate, int frameSize)
        {
            signalDataFrame.Clear();

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

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

            SignalDataItem[] signalDataItems = this.GetSignals(frameStartDate, frameEndDate);
            Dictionary <string, Dictionary <long, IndicatorDataItem> > indicatorDataItems = new Dictionary <string, Dictionary <long, 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 <SignalDataItem> signals = FindSignalDataItem(signalDataItems, bar.Time, ref signalOffset);
                Dictionary <string, IndicatorDataItem> indicators = new Dictionary <string, IndicatorDataItem>();
                Dictionary <string, long> indicatorOffsets        = new Dictionary <string, long>();
                foreach (KeyValuePair <string, IndicatorCache> indicator in indicatorCacheList)
                {
                    indicatorOffsets.Add(indicator.Key, 0);
                }
                foreach (KeyValuePair <string, IndicatorCache> indicator in indicatorCacheList)
                {
                    long 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;
                }

                signalDataFrame.Add(bar.Time, new SignalDataFrameItem(bar, signals, indicators));
            }

            return(signalDataFrame);
        }