Пример #1
0
        protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
                                                  Cbi.MarketPosition marketPosition, string orderId, DateTime time)
        {
            if (PrintDetails)
            {
                Print(string.Format("{0} | OEU | execution | {1} | {2}", Times[1][0], time, execution.ToString()));
            }

            if (execution.Order.OrderState != OrderState.Filled)
            {
                return;
            }

            // when the entry order fully fills, place the profit target and stop loss
            if (entryOrder != null && execution.Order == entryOrder)
            {
                ocoString = Guid.NewGuid().ToString();

                if (UseProfitTarget)
                {
                    if (PrintDetails)
                    {
                        Print(string.Format("{0} | OEU | placing profit target", execution.Time));
                    }

                    // calculate  a price for the profit target using the secondary series ticksize
                    currentPtPrice = execution.Order.AverageFillPrice + ProfitTargetDistance * tickSizeSecondary;
                    profitTarget   = placeHolderOrder;
                    SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.Limit, execution.Order.Filled, currentPtPrice, 0, ocoString, "profit target");
                }

                if (UseStopLoss)
                {
                    if (PrintDetails)
                    {
                        Print(string.Format("{0} | OEU | placing stop loss", execution.Time));
                    }

                    currentSlPrice = execution.Order.AverageFillPrice - StopLossDistance * tickSizeSecondary;
                    stopLoss       = placeHolderOrder;
                    SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, currentSlPrice, ocoString, "stop loss");
                }
            }
        }
Пример #2
0
        protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
                                                  Cbi.MarketPosition marketPosition, string orderId, DateTime time)
        {
            if (PrintDetails)
            {
                Print(string.Format("{0} | OEU | execution | {1} | {2}", Times[1][0], time, execution.ToString()));
            }

            if (execution.Order.OrderState != OrderState.Filled)
            {
                return;
            }

            // when the entry order fills, place the profit target and stop loss
            if (entryOrder != null && execution.Order == entryOrder)
            {
                if (UseProfitTarget)
                {
                    if (PrintDetails)
                    {
                        Print(string.Format("{0} | OEU | placing profit target", execution.Time));
                    }

                    // setting initial profit target
                    if (isLongTrade)
                    {
                        // calculate  a price for the profit target using the secondary series ticksize
                        // currentPtPrice = execution.Order.AverageFillPrice + ProfitTargetDistance * tickSizeSecondary;
                        currentPtPrice = execution.Order.AverageFillPrice + profiltsTaking * tickSizeSecondary;
                        profitTarget   = placeHolderOrder;
                        ExitLongLimit(1, true, entryOrder.Quantity, currentPtPrice, "profit target", "entry");
                    }
                    else
                    {
                        // calculate  a price for the profit target using the secondary series ticksize
                        // currentPtPrice = execution.Order.AverageFillPrice - ProfitTargetDistance * tickSizeSecondary;
                        currentPtPrice = execution.Order.AverageFillPrice - profiltsTaking * tickSizeSecondary;
                        profitTarget   = placeHolderOrder;
                        ExitShortLimit(1, true, entryOrder.Quantity, currentPtPrice, "profit target", "entry");
                    }
                }

                if (UseStopLoss)
                {
                    if (PrintDetails)
                    {
                        Print(string.Format("{0} | OEU | placing stop loss", execution.Time));
                    }

                    //setting initial stop loss
                    if (isLongTrade)
                    {
                        // currentSlPrice = execution.Order.AverageFillPrice - StopLossDistance * tickSizeSecondary;
                        currentSlPrice = execution.Order.AverageFillPrice - stopLossVal * tickSizeSecondary;
                        stopLoss       = placeHolderOrder;
                        ExitLongStopMarket(1, true, entryOrder.Quantity, currentSlPrice, "stop loss", "entry");
                    }
                    else
                    {
                        // currentSlPrice = execution.Order.AverageFillPrice + StopLossDistance * tickSizeSecondary;
                        currentSlPrice = execution.Order.AverageFillPrice + stopLossVal * tickSizeSecondary;
                        stopLoss       = placeHolderOrder;
                        ExitShortStopMarket(1, true, entryOrder.Quantity, currentSlPrice, "stop loss", "entry");
                    }
                }
            }
        }