예제 #1
0
        public Bars BarsLoadThreadSafe(DateTime startDate, DateTime endDate, int maxBars)
        {
            Bars barsAll = this.BarsLoadAllThreadSafe();

            //Assembler.PopupException("Loaded [ " + bars.Count + "] bars; symbol[" + this.Symbol + "] scaleInterval[" + this.BarsFolder.ScaleInterval + "]");
            if (startDate == DateTime.MinValue && endDate == DateTime.MaxValue && maxBars == 0)
            {
                return(barsAll);
            }

            string start = (startDate == DateTime.MinValue) ? "MIN" : startDate.ToString("dd-MMM-yyyy");
            string end   = (endDate == DateTime.MaxValue) ? "MAX" : endDate.ToString("dd-MMM-yyyy");
            Bars   bars  = new Bars(barsAll.Symbol, barsAll.ScaleInterval, barsAll.ReasonToExist + " [" + start + "..." + end + "]max[" + maxBars + "]");

            for (int i = 0; i < barsAll.Count; i++)
            {
                if (maxBars > 0 && i >= maxBars)
                {
                    break;
                }
                Bar  barAdding   = barsAll[i];
                bool skipThisBar = false;
                if (startDate > DateTime.MinValue && barAdding.DateTimeOpen < startDate)
                {
                    skipThisBar = true;
                }
                if (endDate < DateTime.MaxValue && barAdding.DateTimeOpen > endDate)
                {
                    skipThisBar = true;
                }
                if (skipThisBar)
                {
                    continue;
                }
                bars.BarAppendBindStatic(barAdding.CloneDetached());
            }
            return(bars);
        }