My EA ignores the volume

 

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. 

 
24h-worker   :

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?
 
nkhawaja   :
Does anyone have a working EA?


Check out http://paulsfxrandomwalk.blogspot.com/2009/10/my-first-mql5-expert-advisor.html
My first MQL5 Expert Advisor
  • 2009.10.26
  • Paul
  • paulsfxrandomwalk.blogspot.com
Update 12/1/2010: this forward test now replaced with a Virtual Order Manager equivalent coexisting with the Support_Resistance EA.  See statement here and live screenshot here.  All links below are still valid. This EA is a Moving Average Cross system using the Fractal Adaptive Moving Average.  It is almost certainly not a profitable EA...
 
phampton   :


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. 

Reason: