EA entering only sporadically on Alpari UK

 

I'm testing an EA on an Alpari UK demo account and I'm seeing some very strange behaviour. Some times a market entry is triggered, which i can confirm via a print statement just prior to OrderSend(), but the order does not go through for some reason; it's as if it was never placed (no error messages either). Then other times, the order goes through just fine.

What's strange is that the same EA is running on CMS-FX and all intended entries execute flawlessly. It must be something on Alpari's side, but i can't figure out what it is and there are no messages in the log. I heard that Alpari UK is notorious for requotes, delays and bad slips. Could this be causing this behaviour?

I already set the slip to 30 (5 digit broker), and the order is being sent with 0 TP and 0 SL. Do requotes prevent an EA from executing a trade? I thought it would just enter higher. Do i need to set my slip higher, say to 5 pips or so? If there anything else that is making these entry orders be ignored?

 
has no one really seen this before?
 

Do you have the source?

Anyway update it to something similar to...

int order = -1;
      if(IsTradeAllowed()){
         order = OrderSend(Symbol(), orderType, volume, NormalizeDouble(price,Digits), 5, 0, 0, comment, PROGRAM_NMBR, 0, Magenta);
      }else{
         Print("Trading thread currently in use.");
      }
      if(order < 0){ // error happened

         int lastError = GetLastError();
         switch(lastError){
            case 136: Print("Order off quotes"); break;
            case 146: Print("Trade context busy"); break;
            default: Print(StringConcatenate("Error while executing a trade, code = ",lastError, "; type = ", orderType, "; price = ", DoubleToStr(price,Digits), "; sl = ", DoubleToStr(stopLoss, Digits), "; tp = ", DoubleToStr(takeProfit,Digits), "; vol = ", volume, "; stoplevel = ", MarketInfo(Symbol(), MODE_STOPLEVEL))); break;
         }
         
      }
 

Thanks a lot. My code is more like this:

EnterLong(){
Print ("Long Entry Attempted");
ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 30, 0, 0, comment, magicnumber, 0, Green);
}

I can see the "Long Entry Attempted" statement, and then nothing; no trade, no errors, nothing in the log. And what's worse, this happens most of the time, and then an entry occurs sporadically so the error is not repeatable. Again, this only happens with Alpari UK.

I'll try the error checking routine you suggested and see what comes up. Thanks again.

By the way, looking through the documentation, I found this:

   int check=GetLastError();
   if(check!=ERR_NO_ERROR) Print("Error: ",ErrorDescription(check));

I was not aware of ErrorDescription(). That could be useful as well.

 
gatornuke:

I can see the "Long Entry Attempted" statement, and then nothing;

All the more important you try the error handling routines. Keep us updated.
 
Will do. I'll try that when I get home from work today and let you know.
 
gatornuke:

I was not aware of ErrorDescription(). That could be useful as well.

Lol neither was I :))) Seems it's part of a standard MT4 package, function is found in stdlib.mq4 library. Lol, useful, I need to implement this to my programs :))))))
 

One hint, beside the name, GetLastError() this function resets also the the error variable, be sure you store the return value and use the stored variable.

BTW, i am also live and demotrading with alpari uk. For me it's working fine, I use always slippage=0, and around 90% of my trades don't get reqoted. Also the demo account and the live account behave nearly the same. I had way bigger problems with other brokers. And to your original questions, yes, reqoute rejects the trade and you have to resend it. But in general this should trow an error.

@forexCoder: case 146: Print("Trade context busy"); break; is a bad way to handle trade context error. The better way is to use a combination of isTradeContextBusy() and a mutex in form of a global variable.

 

Thanks, i know :) I didnt know about IsTradeContextBusy when I was writing this code.

Slippage 0 is good to know :)

 

Ok, so the error it's giving me is "invalid price" I don't see how that can be, when I'm inputting the Ask on buy and Bid on short. Do I need to do a RefreshRates right before OrderSend? I'd try it right now but there's an open position in play, besides, if that were the issue I'd expect to see this in CMS-FX as well.

One curious thing is that the failed entries seem to be filtering out some bad trades. The other copy of this EA running on CMS-FX with unimpeded execution is not performing quite as well, but then again it's probably just luck.

 
gatornuke:
Ok, so the error it's giving me is "invalid price" I don't see how that can be, when I'm inputting the Ask on buy and Bid on short. Do I need to do a RefreshRates right before OrderSend? I'd try it right now but there's an open position in play, besides, if that were the issue I'd expect to see this in CMS-FX as well.
  1. order = OrderSend(Symbol(), orderType, volume, NormalizeDouble(price,Digits), 5, 0, 0, 
    The normalize isn't necessary. What is price, when and what is it set to? Post the rest of the code.

  2. You only need refresh rates between server calls or very long calculations between start() and the call. You will need one after the send if you're going to set TP/SL. Can't hurt anything.
  3. For ECN brokers you must orderSend and then set the TP/SL. For 5 digit brokers you must modify TP, SL, and slippage. A 1/2 pip slippage may result in errors
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  4. For the context is busy, you shouldn't see this with one EA. Use a mutex
Reason: