Positions not netting

Created at 20 Dec 2017, 12:02
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DA

daniel.skipper

Joined 20.12.2017

Positions not netting
20 Dec 2017, 12:02


Hi,

I have an algo that set two limit orders, a sell and a buy, on the open of each bar.

       protected override void OnBar()
        {
            // cancel any working orders
            foreach (var order in PendingOrders)
                if (order.Label == TradeLabel)
                    CancelPendingOrderAsync(order);

            // find any open positions and close them
            var thisPosition = Positions.FindAll(TradeLabel);

            foreach (var thePosition in thisPosition)
            {
                ClosePositionAsync(thePosition);

            }


            // set limit orders
            PlaceLimitOrderAsync(TradeType.Buy, Symbol, VolumeInUnits, buyprice, TradeLabel);
            PlaceLimitOrderAsync(TradeType.Sell, Symbol, VolumeInUnits, sellprice, TradeLabel);

}

I have two quesions:-

1) on the open of the bar the algo closes any open positions and cancels any pending order before setting the new limits.  Is there anyway i can do this before the close of the current bar rather at the beginning of the next?

2) If both limit orders are hit, they are not netting out and are being reported as an open position on the open of the next bar then being closed both the buy and sell at market.  Do i need to do anything in the code to enable both limit orders to net out and leave me with no position?

 

Thanks in advance.

Dan


@daniel.skipper