// **********************************************************************

        public void PutOwnTrade(OwnTrade trade)
        {
            // ------------------------------------------------------------

            int nq = this.Quantity + trade.Quantity;

            if (Math.Sign(nq) != Math.Sign(this.Quantity))
            {
                this.pricesum = trade.Price * nq;
            }
            else
            {
                this.pricesum += trade.Price * trade.Quantity;
            }

            this.Quantity = nq;

            // ------------------------------------------------------------

            if (stopOrderId != 0)
            {
                tmgr.KillStopOrder(stopOrderId);
                stopOrderId = 0;
            }

            if (takeProfit != null)
            {
                tmgr.CancelAction(takeProfit);
                takeProfit = null;
            }

            // ------------------------------------------------------------

            if (Quantity == 0)
            {
                Price = 0;
            }
            else
            {
                Price = pricesum / Quantity;

                if (Quantity > 0)
                {
                    if (cfg.u.StopOffset != 0)
                    {
                        stopOrderPrice = PredictFXCharts.Price.Ceil(Price - cfg.u.StopOffset);

                        stopOrderId = tmgr.CreateStopOrder(
                            stopOrderPrice,
                            stopOrderPrice - cfg.u.StopSlippage,
                            -Quantity);
                    }

                    if (cfg.u.TakeOffset != 0)
                    {
                        takeProfit = tmgr.ExecAction(new OwnAction(
                                                         TradeOp.Sell,
                                                         BaseQuote.Absolute,
                                                         PredictFXCharts.Price.Ceil(Price + cfg.u.TakeOffset),
                                                         Quantity));
                    }
                }
                else
                {
                    if (cfg.u.StopOffset != 0)
                    {
                        stopOrderPrice = PredictFXCharts.Price.Floor(Price + cfg.u.StopOffset);

                        stopOrderId = tmgr.CreateStopOrder(
                            stopOrderPrice,
                            stopOrderPrice + cfg.u.StopSlippage,
                            -Quantity);
                    }

                    if (cfg.u.TakeOffset != 0)
                    {
                        takeProfit = tmgr.ExecAction(new OwnAction(
                                                         TradeOp.Buy,
                                                         BaseQuote.Absolute,
                                                         PredictFXCharts.Price.Floor(Price - cfg.u.TakeOffset),
                                                         -Quantity));
                    }
                }
            }

            dataReceiver.PutPosition(Quantity, Price);
        }
Ejemplo n.º 2
0
        // **********************************************************************
        // *                               Сделки                               *
        // **********************************************************************

        public void PutOwnTrade(OwnTrade trade)
        {
            Position.PutOwnTrade(trade);
        }