Help with pending orders?

Created at 17 Oct 2017, 06:35
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!
AR

armstr.tradie

Joined 30.03.2016

Help with pending orders?
17 Oct 2017, 06:35


Hi there,

 

I'm working on a grid system bot where I would like the robot to avoid doubling up on trades at or near the same price level. It creates a series of pending orders (depending on market direction) and as the bid/ask moves through them it will execute them. But, the problem is that the bot will place pending orders near or on the same price level as existing open positions. For example: it places two sell orders at the same level or within 20 pips of one another.

 

Below is the code I have come up with thus far to remove any pending orders occurring at the same level as current open positions. But I would also like to close pending orders that are within 20 pips of an existing open position.

 

Any help would be greatly appreciated. 

 

protected void PositionExistsSell()
        {
            var shortPosition = Positions.Find(Label, Symbol, TradeType.Sell);

            foreach (var order in PendingOrders)
            {
                if (order.TradeType == TradeType.Sell)
                {
                    if (order == shortPosition)
                        CancelPendingOrderAsync(order);
                }
            }
        }
        protected void PositionExistsBuy()
        {
            var longPosition = Positions.Find(Label, Symbol, TradeType.Buy);

            foreach (var order in PendingOrders)
            {
                if (order.TradeType == TradeType.Buy)
                {
                    if (order > longPosition)
                        CancelPendingOrderAsync(order);
                }
            }
        }

 


@armstr.tradie