Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        private void AddOrUpdateBuyOrders(double desiredLongPosition)
        {
            OrderGroupTestTest nextOrders1 = new OrderGroupTestTest();
            OrderGroupTestTest nextOrders2 = new OrderGroupTestTest();
            OrderGroupTestTest nextOrders3 = new OrderGroupTestTest();

            nextOrders1.MyOrder = EnterLongLimit(0, true, quantityToPurchase, desiredLongPosition - 0.00, "BuyStuff1");
            nextOrders2.MyOrder = EnterLongLimit(0, true, quantityToPurchase, desiredLongPosition - 0.01, "BuyStuff2");
            nextOrders3.MyOrder = EnterLongLimit(0, true, quantityToPurchase, desiredLongPosition - 0.02, "BuyStuff3");
            EntryOrders.Add(nextOrders1);
            EntryOrders.Add(nextOrders2);
            EntryOrders.Add(nextOrders3);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates current open orders to have the desired Price BH:Chase price
        /// </summary>
        private void UpdateCurrentOrders(double desiredLongPosition)
        {
            for (int i = 0; i < EntryOrders.Count; i++)
            {
                OrderGroupTestTest orderToCheck = EntryOrders[i];
                if (orderToCheck != null &&
                    orderToCheck.MyOrder != null)
                {
                    // update the order to have our desired position.
                    switch (orderToCheck.MyOrder.Name)
                    {
                    case "BuyStuff1":
                        if (desiredLongPosition - orderToCheck.MyOrder.LimitPrice > 0.001 && orderToCheck.MyOrder.Filled != orderToCheck.MyOrder.Quantity)
                        {
                            EnterLongLimit(0, true, orderToCheck.MyOrder.Quantity, desiredLongPosition - 0.00, orderToCheck.MyOrder.Name);
                        }
                        break;

                    case "BuyStuff2":
                        if (desiredLongPosition - orderToCheck.MyOrder.LimitPrice > 0.011 && orderToCheck.MyOrder.Filled != orderToCheck.MyOrder.Quantity)
                        {
                            EnterLongLimit(0, true, orderToCheck.MyOrder.Quantity, desiredLongPosition - 0.01, orderToCheck.MyOrder.Name);
                        }
                        break;

                    case "BuyStuff3":
                        if (desiredLongPosition - orderToCheck.MyOrder.LimitPrice > 0.021 && orderToCheck.MyOrder.Filled != orderToCheck.MyOrder.Quantity)
                        {
                            EnterLongLimit(0, true, orderToCheck.MyOrder.Quantity, desiredLongPosition - 0.02, orderToCheck.MyOrder.Name);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (lastbarcount < Bars.Count)  // BH:Checks to see if Current Bar is same as last bar processed
            {
                // BH:Calculates Current Account Value
                double currentAccountValue = myAccountValue // BH:parameter that holds starting account value
                                             + Performance.RealtimeTrades.TradesPerformance.GrossProfit
                                             + Performance.RealtimeTrades.TradesPerformance.GrossLoss
                                             - Performance.RealtimeTrades.TradesPerformance.Commission;

                // BH:Calculates desired quantity to buy based off 1.5% of Current Account Value
                quantityToPurchase = Convert.ToInt32((currentAccountValue * .015) / GetCurrentBid());

                // Calculate the position we want to be in.
                // double desiredLongPosition = Math.Min(Low[0], GetCurrentBid());

                // BH:Remove EntryOrder if in a Final State
                for (int i = 0; i < EntryOrders.Count; i++)
                {
                    OrderGroupTestTest orderToCheck = EntryOrders[i];
                    if (orderToCheck != null)
                    {
                        if (orderToCheck.MyOrder != null)
                        {
                            if (orderToCheck.MyOrder.OrderState == OrderState.Cancelled ||
                                orderToCheck.MyOrder.OrderState == OrderState.Rejected ||
                                orderToCheck.MyOrder.OrderState == OrderState.Unknown ||
                                (orderToCheck.MyOrder.OrderState == OrderState.Filled &&
                                 Position.MarketPosition != MarketPosition.Long))
                            {
                                EntryOrders.Remove(orderToCheck);
                            }
                        }
                        else
                        {
                            EntryOrders.Remove(orderToCheck);
                        }
                    }
                    else
                    {
                        EntryOrders.Remove(orderToCheck);
                    }
                }

                //Cancel Entry Orders Not Being Filled
                if (Position.MarketPosition == MarketPosition.Long)
                {
                    for (int i = 0; i < EntryOrders.Count; i++)
                    {
                        OrderGroupTestTest orderToCheck = EntryOrders[i];
                        if (orderToCheck != null)
                        {
                            if (orderToCheck.MyOrder != null)
                            {
                                if (orderToCheck.MyOrder.OrderState != OrderState.PartFilled &&
                                    orderToCheck.MyOrder.OrderState != OrderState.Filled)
                                {
                                    CancelOrder(orderToCheck.MyOrder);
                                }
                            }
                            else
                            {
                                EntryOrders.Remove(orderToCheck);
                            }
                        }
                        else
                        {
                            EntryOrders.Remove(orderToCheck);
                        }
                    }
                }

                // Add new EntryOrders
                if (Low[0] < Low[1] &&              // just went down
                    EntryOrders.Count == 0 &&
                    Position.MarketPosition != MarketPosition.Long)
                {
                    AddOrUpdateBuyOrders(GetCurrentBid());
                }

                // BH:Chase Price
                UpdateCurrentOrders(GetCurrentBid());
            }
            lastbarcount = Bars.Count;
        }