Two positions instead one through limit order
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);
}
Replies
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
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