public void test_IsPositionOnSignalOnClose_Negative()
        {
            ISignalContext context = new SignalContext();

            context.CurrentMarketPosition = 0;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_1Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_10Contract_5Complete(), "Buy Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell10Contract_5Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_10Contract_5Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell10Contract_5Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());
        }
Пример #2
0
        protected void checkExitOrderCompleted(Series <DateTime, MarketDataElement> series)
        {
            if (!execution.isPositionOnSignalOnClose())
            {
                return;
            }

            immediatePnLAfterPositionClose = 0;
            int index = execution.getIndexClosedAppOrder();

            log.Info("[Strategy] : Exit Strategy Executed!!!");
            if (index == 1)
            {
                log.Info("Executed Rule = " + execution.PendingOrder1.TriggerRule);
                log.Info("Executed Rule Remark = " + execution.PendingOrder1.Remark);
            }
            else
            {
                log.Info("Executed Rule = " + execution.PendingOrder2.TriggerRule);
                log.Info("Executed Rule Remark = " + execution.PendingOrder2.Remark);
            }
            log.Info("******************************************************************");
            lastExecutePrice = execution.getFilledPrice();
            lastSignalPrice  = execution.getSignalPriceForExecution();
            execution.completePendingSignal();
            stgHelper.cancelPendingTrades();
            execution.flushCompletSignal();
            if (execution.CurrentMarketPosition == 0)
            {
                immediatePnLAfterPositionClose = execution.PnL;
                execution.PnL = 0;
            }
            immediateOrderExit = true;
        }
Пример #3
0
        private void checkExitOrderCompleted(Series <DateTime, MarketDataElement> series)
        {
            if (!execution.isPositionOnSignalOnClose())
            {
                return;
            }
            int index = execution.getIndexClosedAppOrder();

            log.Info("[Strategy] : Exit Strategy Executed!!!");
            if (index == 1)
            {
                log.Info("Take Profit Executed!!!");
            }
            else
            {
                log.Info("Cutloss Executed!!!");
            }
            log.Info("******************************************************************");
            lastExecutePrice = execution.getFilledPrice();
            lastSignalPrice  = execution.getSignalPriceForExecution();
            execution.completePendingSignal();
            stgHelper.cancelPendingTrades();
            execution.flushCompletSignal();
        }