I determinated my EA to open a position with volume = 1.0
Sometimes he will do that, sometimes he add a second order, so that the volume is 2.0
Did anyone had the same problem ?
Maybe I have a mistake in my code, but with MQL4 I have not this problem.
Yes, I have had the same issue. OrderSend can return control to the EA before the position size has changed. So if you query position size immediately after an OrderSend, it may not indicate the change. I think this can occur even when the RetCode from the OrderSend is TRADE_RETCODE_DONE.
For the moment, I am using this code to poll for the change in position size as a result of the OrderSend.
int nCurrentLots=OpenLots(); if(!OrderSend(MtRequest,MtResult)) { Print("PositionChangeSizeAtServer() error: Problem with OrderSend, return code "+RetCodeToStr(MtResult.retcode)); return(false); } Print("PositionChangeSizeAtServer() result of OrderSend to server: "+RetCodeToStr(MtResult.retcode)); int nRepeatCount=20; while(OpenLots()==nCurrentLots && nRepeatCount>0) { Sleep(1000); nRepeatCount--; Print("PositionChangeSizeAtServer() retrying #"+(string)nRepeatCount); } if(nRepeatCount==0) { Print("PositionChangeSizeAtServer() error: Order failed to complete after "+(string)nRepeatCount+" seconds"); return(false); }
This function returns +/- position volume*1000 for the above code
int OpenLots() { int nLots=0; if(PositionSelect(Symbol())) { switch(PositionGetInteger(POSITION_TYPE)) { case POSITION_TYPE_BUY: nLots=(int)MathRound(PositionGetDouble(POSITION_VOLUME)*1000); break; case POSITION_TYPE_SELL: nLots=-(int)MathRound(PositionGetDouble(POSITION_VOLUME)*1000); break; default: Print("Problem with POSITION_TYPE in OpenLots()"); } } return(nLots); }
Paul
http://paulsfxrandomwalk.blogspot.com/
Does anyone have a working EA?
- 2009.10.26
- Paul
- paulsfxrandomwalk.blogspot.com
Yes, I have had the same issue. OrderSend can return control to the EA before the position size has changed. So if you query position size immediately after an OrderSend, it may not indicate the change. I think this can occur even when the RetCode from the OrderSend is TRADE_RETCODE_DONE.
For the moment, I am using this code to poll for the change in position size as a result of the OrderSend.
This function returns +/- position volume*1000 for the above code
Paul
http://paulsfxrandomwalk.blogspot.com/
At the moment if I want to open an order with Volumen = 1, I set the value to 0.5.
In 80 Percent of the trades the EA opens 2 orders, so the volume is as expected.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I determinated my EA to open a position with volume = 1.0
Sometimes he will do that, sometimes he add a second order, so that the volume is 2.0
Did anyone had the same problem ?
Maybe I have a mistake in my code, but with MQL4 I have not this problem.