EA on MT4 - message in log: open #27107134 sell stop (instead of buy) 0.03 GBPUSD at 1.57395 sl: 1.57825 tp: 1.57145 ok

 

I am running the same EA on two charts and I have encountered this message a couple of times in the last week or two. This morning one instance was trying to place a buy order, the other a sell stop order. Each instance is using a different magic number and the program checks IsTradeAllowed prior to attempting to place the trade. What appeared to happen is this:

The sell stop trade was opened correctly

The buy trade was not opened but the trade server apparently came back with a return code of zero, as the EA performed the logic as though the trade had been successfully placed.

Here is the relevant piece of code from the EA:

if (!IsTradeAllowed())

{

status="Waiting for trade server to be free";

return(0);

}


int retCode = OrderSend(Symbol(),action,orderVolume,

openPrice,maxSlippage,stopLoss,takeProfit, "FNT "+modeStr,EA_ident,0,CLR_NONE);


if (retCode < 0)

{

tryCount++;

Print(Symbol(),": unable to open ", orderTypes[action]," trade at ",openPrice,", sl=",stopLoss,", tp=",takeProfit,

", volume=",orderVolume,", tryCount=",tryCount,", magic number=",EA_ident);


int err=GetLastError();

if (ignoreError(err) && tryCount < 50)

{

Print(Symbol(),": trade error (",err,"): ",ErrorDescription(err),": retrying");

return(0);

}

else

{

Alert(Symbol(),": trade error (",err,"): ",ErrorDescription(err));

status="Error opening pending trade";

tradingOk=false;

return(-1);

}

}


tryCount=0;


GlobalVariableSet(StringConcatenate(WindowExpertName(),EA_ident,"_lastTradeDate"),StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)));

GlobalVariableSet(StringConcatenate(WindowExpertName(),EA_ident,"_volume"),orderVolume);

I am running this EA on two different live broker accounts and, so far, I have only noticed the problem on one of them. Also, it doesn't happen everyday, just occasionally.

Any advice would be gratefully received.

Thanks,

Greg

Reason: