Forex_Strategy_Builder.Backtester.ShortestMethod C# (CSharp) Метод

ShortestMethod() статический приватный Метод

Shortest route inside the bar Method
static private ShortestMethod ( int bar, BacktestEval eval, double &current, bool isTopReachable, bool isBottomReachable, bool isHigherPrice, bool isLowerPrice, double priceHigher, double priceLower, Order orderHigher, Order orderLower, bool isClosingAmbiguity ) : void
bar int
eval BacktestEval
current double
isTopReachable bool
isBottomReachable bool
isHigherPrice bool
isLowerPrice bool
priceHigher double
priceLower double
orderHigher Order
orderLower Order
isClosingAmbiguity bool
Результат void
        static void ShortestMethod(int bar, BacktestEval eval, ref double current,
            bool isTopReachable, bool isBottomReachable,
            bool isHigherPrice, bool isLowerPrice,
            double priceHigher, double priceLower,
            Order orderHigher, Order orderLower,
            bool isClosingAmbiguity)
        {
            double open  = Open[bar];
            double high  = High[bar];
            double low   = Low[bar];
            double close = Close[bar];

            bool isGoUpward;
            if (!session[bar].IsTopReached && !session[bar].IsBottomReached)
                isGoUpward = open > close;
            else if (session[bar].IsTopReached && !session[bar].IsBottomReached)
                isGoUpward = false;
            else if (!session[bar].IsTopReached && session[bar].IsBottomReached)
                isGoUpward = true;
            else
                isGoUpward = open > close;

            if (isLowerPrice && current - priceLower < micron)
                isGoUpward = false;
            if (isHigherPrice && priceHigher - current < micron)
                isGoUpward = true;

            if (eval == BacktestEval.None)
            {   // There is no more orders
                if (!session[bar].IsTopReached && !session[bar].IsBottomReached)
                {   // Neither the top nor the bottom was reached
                    if (isGoUpward)
                    {   // Hit the Top
                        current = high;
                        session[bar].SetWayPoint(high, WayPointType.High);
                        session[bar].IsTopReached = true;
                    }
                    else
                    {   // Hit the Bottom
                        current = low;
                        session[bar].SetWayPoint(low, WayPointType.Low);
                        session[bar].IsBottomReached = true;
                    }
                }
                else if (!session[bar].IsTopReached)
                {   // Hit the Top
                    current = high;
                    session[bar].SetWayPoint(high, WayPointType.High);
                    session[bar].IsTopReached = true;
                }
                else if (!session[bar].IsBottomReached)
                {   // Hit the Bottom
                    current = low;
                    session[bar].SetWayPoint(low, WayPointType.Low);
                    session[bar].IsBottomReached = true;
                }
            }
            if (eval == BacktestEval.Correct)
            {   // Hit the top/bottom or execute
                Order  theOrder = null;
                double thePrice = 0;
                if (isHigherPrice)
                {
                    theOrder = orderHigher;
                    thePrice = priceHigher;
                }
                else if (isLowerPrice)
                {
                    theOrder = orderLower;
                    thePrice = priceLower;
                }

                if (!session[bar].IsBottomReached && isBottomReachable && !isGoUpward)
                {   // Hit the Bottom
                    current = low;
                    session[bar].SetWayPoint(low, WayPointType.Low);
                    session[bar].IsBottomReached = true;
                }
                else if (!session[bar].IsTopReached && isTopReachable && isGoUpward)
                {   // Hit the Top
                    current = high;
                    session[bar].SetWayPoint(high, WayPointType.High);
                    session[bar].IsTopReached = true;
                }
                else
                {   // Execute the order
                    current = thePrice;
                    ExecOrd(bar, theOrder, thePrice, eval);
                }
            }
            else if (eval == BacktestEval.Ambiguous)
            {   // Ambiguous - two orders or order and bar closing
                if (!isClosingAmbiguity)
                {   // Execute the nearest order
                    Order  theOrder;
                    double thePrice;

                    if (isGoUpward)
                    {
                        theOrder = orderHigher;
                        thePrice = priceHigher;
                    }
                    else
                    {
                        theOrder = orderLower;
                        thePrice = priceLower;
                    }
                    current = thePrice;
                    ExecOrd(bar, theOrder, thePrice, eval);
                }
                else
                {   // Exit the bar
                    current = close;
                    session[bar].BacktestEval = BacktestEval.Ambiguous;
                    if (isHigherPrice)
                        orderHigher.OrdStatus = OrderStatus.Cancelled;
                    else if (isLowerPrice)
                        orderLower.OrdStatus = OrderStatus.Cancelled;
                }
            }

            return;
        }