Order rejected with Error 4756 in MetaTrader

The code works in strategy tester, but when using in real trade, I get Error 4756 (Trade request sending failed) and retcode 10006 (Request rejected).

Anyone has any idea why this could not work? the SYMBOL_FILLING_MODE is 3 and the SYMBOL_EXPIRATION_MODE is 2. I can buy and sell normally if I use the “new order” thing from Metatrader. Please, any idea would be greatly appreciated. I ran out of ideas I could try to make it work.

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
   MqlTradeRequest mrequest;  
   MqlTradeResult mresult;    
   ZeroMemory(mrequest);     
   //----          
   mrequest.action = TRADE_ACTION_DEAL;                              
   mrequest.type_filling = ORDER_FILLING_FOK;                          
   mrequest.sl=0;
   mrequest.tp=0;
   mrequest.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   mrequest.symbol = _Symbol;                                         
   mrequest.volume = 1;                                            
   mrequest.magic = 0;                                        
   mrequest.type = ORDER_TYPE_BUY;                                
   mrequest.deviation=10;                                         
   mrequest.type_time=ORDER_TIME_DAY;
   //--- send order        
   if(!OrderSend(mrequest,mresult))
   {
    Alert(__FUNCTION__,": error ",GetLastError(),", retcode = ",mresult.retcode);
   }     
   Sleep(30000);
   }

this will generate in log the following lines:

11:36:36.695 Trades ‘1000015025’: exchange buy 1.00 WDON15 at market

11:36:36.763 Trades ‘1000015025’: rejected exchange buy 1.00 WDON15 at market

if I use the “new order” tool from Metatrader (that works), it generates these lines:

11:09:31.155 Trades ‘1000015025’: exchange buy 1.00 WDON15 at market
11:09:31.207 Trades ‘1000015025’: exchange buy 1.00 WDON15 at market placed for execution in 51 ms (Order received. Sending to OMS.)
11:09:32.459 Trades ‘1000015025’: deal #4204115 buy 1.00 WDON15 at 3129.000 done (based on order #4913284)

Thanks

Not sure it helps, but some fields are not needed for a BUY with Market execution, try to remove them.

void OnTick()
  {
   MqlTradeRequest mrequest;  
   MqlTradeResult mresult;    
   ZeroMemory(mrequest);     
   //----          
   mrequest.action = TRADE_ACTION_DEAL;                              
   mrequest.type_filling = ORDER_FILLING_FOK;                          
   mrequest.sl=0;
   mrequest.tp=0;
   mrequest.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   mrequest.symbol = _Symbol;                                         
   mrequest.volume = 1;                                            
   mrequest.magic = 0;                                        
   mrequest.type = ORDER_TYPE_BUY;                                
   mrequest.deviation=10;                                         
   mrequest.type_time=ORDER_TIME_DAY;
   //--- send order        
   if(!OrderSend(mrequest,mresult))
   {
    Alert(__FUNCTION__,": error ",GetLastError(),", retcode = ",mresult.retcode);
   }     
   Sleep(30000);
   }

Hello @vcommings24 , thank you very much for you reply.

I tried your suggestion but unfortunately the error still persists. But since a veteran like you see no problem with that code, at least I am sure now that the issue is probably caused by the broker and not by the code. Thank you

If you have any other ideas I could try, please let me know.

I also tried changing the filling type and deleting the sl, tp and magic lines. Always the same error.

I can only suggest you to check ACCOUNT_TRADE_EXPERT.

Please report the solution here if you find it.

Another idea, can you try to set volume to 1.0 instead of 1.

And if that doesn’t change, try with a double variable : double myvolume=1.0; mrequest.volume=myvolume

i am not sure if it matters in the mqltraderequest structure but you can also try to change the order.

In the initialisation list, members can go in any order, but all members of the class will be initialised according to the order of their announcement.This should be taken into account in cases where the initialisation of some members of the class depends on the values in other class members.

Market Execution

This is a trade order to open a position in the Market Execution mode. It requires to specify the following 5 fields:

action
symbol
volume
type
type_filling

i am not saying this should get rid of the error but i always tend to follow the same order as explained in the docs.

The ACCOUNT_TRADE_EXPERT returns 1.

Setting the volume that way did not show changes on the error, but that could be because the symbol will stop trading in less than 30 minutes counting from now, and when that happens the broker closes all trades from Metatrader (on my broker, metatrader is only to be used as a daytrade tool). So, to be sure I will have to try that again on monday.

I appreciate the time you are spending trying to help me.

If I find the solution I will make sure to make it known here.

The broker offers an expert advisor (a gui) to do trades(but they don’t give the source code, only the ex), and it works, so there has to be a way.

If you have any other ideas, please share them with me, even if you think that they might not work. Thank you

@rpenright25 I didn’t think about that! Thank you!

It pains me that I will have to wait until monday to test it! I will let you know if it works or not.

If anyone else has other suggestions that have a chance to work, please let me know!

thanks

Guys! omg! I figured it out! You won’t believe what actually solved the issue!

As I said before, my broker offered an EA (only the .Ex, not the source code). And when I made a trade with it, it worked. So, there was something that EA was doing that mine wasn’t. Then I decided to use some mql5 functions to get all the info on the order it was generating and then I just copied all that info to my EA order and it worked. Then, when removing lines to try to figure out what was actually causing the order to be rejected before I found that it was the lack of the mrequest.comment line! (who could guess!)

So I just put the mrequest.comment line exactly like it was in the EA from the broker and the order actually went through!

Thanks for the support guys!

You need to add a comment for an order request to work ? What’s that !!!

Which comment by the way ?

Exactly!!! I would never have figured out that if I didn’t try everything!!

the line is mrequest.comment=“Turbo”; (Turbo is the name of the EA that the broker offers) (if I remove that line, the same error will appear again)

My guess is that my broker didn’t want inexperienced users to use random EA’s out there so they restricted the EA with that requirement, idk. (they are still working on the demo account thing and didn’t release demo accounts yet)

HAHA !! does it mean the comment on every trade has to be “Turbo” ?

thats kinda weird that is very hard to find out i think you did a great job at finding this issue !!

Thanks man :slight_smile: . But if you guys didn’t say that my original EA was supposed to be working, then I would have a much harder time figuring it out. If it was supposed to be working but it was not, then it must be something very unusual, like that

And yes, It’s exactly as you say. I just tried changing the comment to “Turba” and the error came back lol. The broker really wanted the ppl to only use their EA and not another!

Hello @ydeans23 I think you’re talking about CLEAR-PRD, a Brazilian broker. Please ask the broker’s IT personnel about restrictions while running expert advisors on this broker.

As far as I know, expert advisors are temporarily blocked on this broker, as they do some IT-related improvements on the server-side.

Regards,

@kmedina27

eu também sou cliente XP aqui no Brasil e este problema está acontecendo comigo também somente na conta real. Na conta demo está funcionando normalmente. Já li alguns posts seus e você é daqui do Brasil também, correto? Poderia me informar o que pode está acontecendo com o meu código? O servidor da XP chega a aceitar minha ordem, conforme mensagens da captura de tela que anexei na imagem abaixo. Mas me parece que o OMS cancela minha ordem pendente em milésimos de segundo. Agradeço se me der uma caminho. Amanhã estarei entrando em contato com eles para saber se há algum bloqueio semelhante ao amigo acima da CLEAR.

double volume=Lots;
         string symbol=_Symbol;    // specify the symbol, at which the order is placed
         double point=SymbolInfoDouble(symbol,SYMBOL_POINT);         // point
         double ask=SymbolInfoDouble(symbol,SYMBOL_ASK);             // current buy price
         double bid=SymbolInfoDouble(symbol,SYMBOL_BID);             // current sell price
         double price_buy=bid;                                 // preço de compra não normalizado
         double price_sell=ask;                                 // preço de venda não normalizado
         price_buy=NormalizeDouble(price_buy,2);                      // normalizing open price
         price_sell=NormalizeDouble(price_sell,2);                      // normalizing open price
         double SL_BuyLimit=price_buy-SL+point;  // Stop Loss não normalizado das ordens BuyLimit
         double SL_SellLimit=price_sell+SL*point;  // Stop Loss não normalizado das ordens SellLimit
         SL_BuyLimit=NormalizeDouble(SL_BuyLimit,2);  // Stop Loss normalizado das ordens BuyLimit
         SL_SellLimit=NormalizeDouble(SL_SellLimit,2);  // Stop Loss normalizado das ordens SellLimit
         double TP_BuyLimit=price_buy+TP*point;  // Stop Loss não normalizado das ordens BuyLimit
         double TP_SellLimit=price_sell-TP*point;  // Stop Loss não normalizado das ordens SellLimit
         TP_BuyLimit=NormalizeDouble(TP_BuyLimit,2);  // Stop Loss normalizado das ordens BuyLimit
         TP_SellLimit=NormalizeDouble(TP_SellLimit,2);  // Stop Loss normalizado das ordens SellLimit
         datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_D1);
         string comment_buy=StringFormat("Buy Limit %s, lote de %d ações a %f, SL=%f TP=%f",
                               symbol,volume,
                               DoubleToString(price_buy,2),
                               DoubleToString(SL_BuyLimit,2),
                               DoubleToString(TP_BuyLimit,2));
         string comment_sell=StringFormat("Sell Limit %s, lote de %d ações a %f, SL=%f TP=%f",
                               symbol,volume,
                               DoubleToString(price_sell,2),
                               DoubleToString(SL_SellLimit,2),
                               DoubleToString(TP_SellLimit,2));
                               
         //--- Todas as variaveis prontas, enviando ordens pendentes de BuyLimit e SellLimit ao servidor
         if(!Trade.BuyLimit(volume,price_buy,symbol,SL_BuyLimit,TP_BuyLimit,ORDER_TIME_GTC,expiration,comment_buy))
           {
           //--- Mensagem caso a ordem BuyLimit falhe
           Print("BuyLimit() method failed. Return code=",Trade.ResultRetcode(),
                 ". Descrição do código: ",Trade.ResultRetcodeDescription());
           }
         else
           {
           //--- Mensagem caso a ordem seja executada com sucesso
           Print("BuyLimit() method executed successfully. Return code=",Trade.ResultRetcode(),
                 " (",Trade.ResultRetcodeDescription(),") and Ticket order=", Trade.ResultOrder());
           buylimit_order=Trade.ResultOrder();
           }                      
         if(!Trade.SellLimit(volume,price_sell,symbol,SL_SellLimit,TP_SellLimit,ORDER_TIME_GTC,expiration,comment_buy))
           {
           //--- Mensagem caso a ordem BuyLimit falhe
           Print("SellLimit() method failed. Return code=",Trade.ResultRetcode(),
                 ". Descrição do código: ",Trade.ResultRetcodeDescription());
           }
         else
           {
           Print("SellLimit() method executed successfully. Return code=",Trade.ResultRetcode(),
                 " (",Trade.ResultRetcodeDescription(),") and Ticket order=", Trade.ResultOrder());
           selllimit_order=Trade.ResultOrder();
           }  

13

14

Please post in English on this forum.

Translation:

I am also XP client in Brazil and this problem is happening to me also only the real account. In the demo account it is operating normally. I’ve read some of your posts and you are here in Brazil too, right? Could you tell me what’s going on can with my code? The XP server comes to take my order as screenshot of messages that have attached the image below. But it seems that the WHO cancel my pending order in milliseconds. I appreciate if you give me one way. Tomorrow I will be contacting them to find out if there are any similar blocking his friend above the CLEAR.

sorry. I am new here in this forum and did not realize that. Thanks!

I am also CLEAR user and I am getting the same error: orders are rejected without an error message. I also tried using “Turbo” comment and then I started receiving “Expert not authorized!” error.

The EA works perfect using DEMO account, but in PROD don’t.

@cdrinkel2d
Did you ask to your broker ?

Yes. About 3 minutes ago they answered my e-mail saying PROD server does not allow automated trades using Meta Trader. It requires risk management and tools that they do not have available. I thought: WTF???

So, if you are reading this and planning to sign up a contract to use Meta Trader with Clear, you will only have DEMO mode.

At this time I am closing my account at Clear Broker.