Forex_Strategy_Builder.Instrument.DataHorizon C# (CSharp) Метод

DataHorizon() приватный Метод

Data Horizon - Cuts some data
private DataHorizon ( ) : int
Результат int
        int DataHorizon()
        {
            if (bars < Configs.MIN_BARS) return 0;

            int startBar = 0;
            int endBar   = bars - 1;
            DateTime startDate = new DateTime(startYear, startMonth, startDay);
            DateTime endDate   = new DateTime(endYear,   endMonth,   endDay);

            // Set the starting date
            if (useStartDate && aBar[0].Time < startDate)
            {
                for (int bar = 0; bar < bars; bar++)
                {
                    if (aBar[bar].Time >= startDate)
                    {
                        startBar  = bar;
                        break;
                    }
                }
            }

            // Set the end date
            if (useEndDate && aBar[bars - 1].Time > endDate)
            {   // We need to cut out the newest bars
                for (int bar = 0; bar < bars; bar++)
                {
                    if (aBar[bar].Time >= endDate)
                    {
                        endBar  = bar - 1;
                        break;
                    }
                }
            }

            if (endBar - startBar > maxBars - 1)
            {
                startBar = endBar - maxBars + 1;
            }

            if (endBar - startBar < Configs.MIN_BARS)
            {
                startBar = endBar - Configs.MIN_BARS + 1;
                if (startBar < 0)
                {
                    startBar = 0;
                    endBar = Configs.MIN_BARS - 1;
                }
            }

            // Cut the data
            if (startBar > 0 || endBar < bars - 1)
            {
                Bar[] aBarCopy = new Bar[bars];
                aBar.CopyTo(aBarCopy, 0);

                int newBars = endBar - startBar + 1;

                aBar = new Bar[newBars];
                for (int bar = startBar; bar <= endBar; bar++)
                    aBar[bar - startBar] = aBarCopy[bar];

                bars   = newBars;
                timeUpdate = aBar[newBars - 1].Time;
                isCut  = true;
            }

            return 0;
        }