Exemple #1
0
        /// <summary>
        /// Determintes how to process the order (i.e. MOC, MOO, etc).
        /// </summary>
        private void fillOrder(TradeBar tradeBar, Order order)
        {
            //Makes sure we are supposed to be here
            if (order.Status != OrderStatus.New && order.Status != OrderStatus.Pending)
            {
                return;
            }

            //Put MOO orders in the QUEUE and exit the method. We will process them tommorow.
            if (order.OrderType == OrderType.MOO && order.Status == OrderStatus.New)
            {
                order.Status = OrderStatus.Pending;
                PendingOrderQueue.Add(order);
                return;
            }

            //Which price to use for fill?
            if (order.OrderType == OrderType.MOO)
            {
                //Use the current opening price of the tradebar
                order.FillPrice = tradeBar.Open;
            }
            else
            {
                //Use the current closing price of the tradebar
                order.FillPrice = tradeBar.Close;
            }

            //VALIDATION REQUIRED - make sure we can afford to buy the stock
            if (validateOrder(order) == false)
            {
                return;
            }

            //Update porfolio
            order.OrderType = OrderType.Market; // Convert all order to market orders
            order.FillDate  = tradeBar.Day;
            order.Status    = OrderStatus.Filled;

            updateHoldings(order);

            //Throw event
            if (OnOrder != null)
            {
                OnOrder(order, e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Processing order sitting in the queue when a new trade bar comes in (i.e. MOO orders)
        /// and updates the current value of stocks on our portfolio.
        /// Called from base algo.
        /// </summary>
        public void ProcessNewTradebar(TradeBar tradeBar)
        {
            //Pick up pending MOO orders placed yesterday
            for (int i = 0; i < PendingOrderQueue.Count; i++)
            {
                Order order = PendingOrderQueue[i];

                if (order.OrderType == OrderType.MOO && order.Status == OrderStatus.Pending)
                {
                    fillOrder(tradeBar, order);
                    PendingOrderQueue.RemoveAt(i);
                }
            }

            //Update current stock price of stocks in the portfolio
            if (IsHoldingStock(tradeBar.Symbol))
            {
                StockPortfolio.Find(p => p.Symbol == tradeBar.Symbol).CurrentPrice = tradeBar.Close;
            }

            //Update equity over time
            EquityOverTime.Add(tradeBar.Day, TotalEquity);
        }