Two positions instead one through limit order

Created at 14 May 2020, 12:54
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!
acnestis's avatar

acnestis

Joined 11.04.2019

Two positions instead one through limit order
14 May 2020, 12:54


Hello! I'm using following code for open a limit order and there we check if we have zero orders (via PendingOrders.Count) or zero positions (Positions.FindAll) then we can place the limit order. So, sometime I see that algo openening 2 positions (not orders) instead 1 and I just not sure why this happened. Can someone help with this? This happened not everytime but sometime. Broker is IC Markets.

//Count Open Long Positions
var numberOfLongPositions = Positions.FindAll(Magic, SymbolName, TradeType.Buy);

//Count Open Short Positions
var numberOfShortPositions = Positions.FindAll(Magic, SymbolName, TradeType.Sell);

//Count Long Limit Orders
var numberOfLongLimit = PendingOrders.Count(item => item.OrderType == PendingOrderType.Limit && item.TradeType == TradeType.Buy && item.Label == Magic && item.SymbolName == Symbol.Name);

//Count Short Limit Orders
var numberOfShortLimit = PendingOrders.Count(item => item.OrderType == PendingOrderType.Limit && item.TradeType == TradeType.Sell && item.Label == Magic && item.SymbolName == Symbol.Name);

//If there is no a buy limit order or buy position place a buy limit order
if (BuyLim <= Symbol.Ask && numberOfLongLimit == 0 && numberOfLongPositions.Length == 0)
{
    PlaceLimitOrder(TradeType.Buy, Symbol.Name, OpenLot, BuyLim, Magic, 0, TPpips);
}

//If there is not a sell limit order or sell position place a sell limit order
if (SellLim >= Symbol.Bid && numberOfShortLimit == 0 && numberOfShortPositions.Length == 0)
{                
    PlaceLimitOrder(TradeType.Sell, Symbol.Name, OpenLot, SellLim, Magic, 0, TPpips);
}

 


@acnestis
Replies

PanagiotisCharalampous
14 May 2020, 14:21

Hi robustby,

Is this reproduced on backtesting? If yes, please post the complete cBot code and instructions how to reproduce this behavior.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

genappsforex
15 May 2020, 20:33

RE:

What is requested (time,volume,TradeType)?
What did you get
(time,volume,TradeType)?

Using Magic??? really forget MT4!


@genappsforex