Beispiel #1
0
        private MovArgRobotTag GetTrendSide(string symbol)
        {
            // получить открытые ордера
            List <MarketOrder> openedOrders;

            GetMarketOrders(out openedOrders);
            openedOrders = openedOrders ?? new List <MarketOrder>();
            openedOrders = openedOrders.Where(o => o.Symbol == symbol &&
                                              o.ExpertComment == ExpertComment).ToList();

            if (openedOrders.Count > 0 && !enterWhileOpened)
            {
                return(new MovArgRobotTag(0, 0));
            }

            // получить еще и закрытые ордера - нужно 5 последних
            List <MarketOrder> closedOrders;

            robotContext.GetOrdersByFilter(robotContext.AccountInfo.ID,
                                           true, new OrderFilterAndSortOrder
            {
                filterMagic         = Magic,
                filterTicker        = symbol,
                takeCount           = Math.Max(dealsToChangeTrend, MartingaleChainLength),
                filterExpertComment = ExpertComment,
                sortByTimeEnter     = true,
                sortAscending       = false
            }, out closedOrders);
            openedOrders.AddRange(closedOrders ?? new List <MarketOrder>());
            if (openedOrders.Count == 0)
            {
                return(new MovArgRobotTag());
            }
            openedOrders = openedOrders.OrderByDescending(o => o.TimeEnter).ToList();

            var sideLength = 1;
            var lastTag    = MovArgRobotTag.ParseComment(openedOrders[0].Comment);

            for (var i = 1; i < openedOrders.Count; i++)
            {
                var tag = MovArgRobotTag.ParseComment(openedOrders[i].Comment);
                if (tag.Trend != lastTag.Trend)
                {
                    break;
                }
                sideLength++;
            }
            var newTrend       = sideLength < dealsToChangeTrend ? lastTag.Trend : -lastTag.Trend;
            var martinChainNum = (openedOrders[0].IsClosed && openedOrders[0].ResultDepo > 0) ? 1
                : lastTag.MartinChainNum + 1;

            return(new MovArgRobotTag(newTrend, martinChainNum));
        }