Previously used Lotsize in OrderSend not recognized anymore

 

Hello everyone, 

I use a function to calculate the optimal lotsize for any trade, the return value is as seen below. This function is supposed to deliver a 0.XX double so that the OrderSend function can properly open an order.

double optimalLotSizeRounded = MathRound(optimalLotSize/MarketInfo(_Symbol,MODE_LOTSTEP))*MarketInfo(_Symbol,MODE_LOTSTEP);


In the main code, I call the function twice to recieve two lotsizes, one small and one big, 0.25 percent and 0.75 percent respectively.

LotsSmall = OptimalLotSize(0.0025, 1.5);
LotsBig = OptimalLotSize(0.0075, 1.5);


I add these two together and save them in the global variable "Lots", which I then use to open the order using OrderSend().

Lots = (LotsSmall+LotsBig);


The whole idea of this LotsSmall and LotsBig splitting is that I take the LotsBig portion off at a certain distance and then let the LotsSmall portion run. I select a trade, then filter using use OrderLots()==Lots and then use OrderClose to close the LotsBig portion.  

This seems to work about 95% of the time. However sometimes it does happen that the order is not recognized by OrderLots()==Lots even though the OrderSend(...,Lots,... ) was just placed one tick before. Does anyone have an idea why this happens sometimes?