Download MetaTrader 5
To add comments, please log in or register
Launch your trading signal. Make profit from paid subscription!
Yochanan Gerbi
519
Yochanan Gerbi 2014.12.31 15:46 

Hello freinds,

Here is a part  of my code:

            OrderSendResult = OrderSend(SymbolArray[i],OP_BUY,UseLots,MarketInfo(SymbolA,MODE_ASK),Slippage,0,0,"Adding to a long pos",MagicNumber,Blue);


            if (OrderSendResult <= 0) Print("OrderSend  ",SymbolArray[i],"  failed with error #",GetLastError());  

 I get the result:

2014.12.31 17:31:26.422 Meymadv39 GBPJPY,H1: OrderSend  NZDUSD  failed with error #0

 

I have no explanation for that.

Any idea?

Happy NEW Year 

whroeder1
13656
whroeder1 2014.12.31 21:45  
OrderSendResult = OrderSend(SymbolArray[i],OP_BUY,UseLots,MarketInfo(SymbolA,MODE_ASK) ...
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. You are opening an order for symbol SymbolArray[i] but using the Ask price for symbol SymbolA.
  3. What is the definition of OrderSendResult?
evertonbg
27
evertonbg 2015.01.01 14:54  

Hi.

Are you getting this error during a backtest session? Multi currency is not supported in this case. Refer to this topic for details.

Happy new year.

Yochanan Gerbi
519
Yochanan Gerbi 2015.01.01 20:05  
evertonbg:

Hi.

Are you getting this error during a backtest session? Multi currency is not supported in this case. Refer to this topic for details.

Happy new year.


Thanks evertonbg for your response.

No, it is not backtest. It is running of the expert.

Any idea? 

Keith Watford
Moderator
8017
Keith Watford 2015.01.01 20:52  

WHRoeder has already given some pointers, but you seem to have ignored them

WHRoeder:
  1. You are opening an order for symbol SymbolArray[i] but using the Ask price for symbol SymbolA.
  2. What is the definition of OrderSendResult?

 It is not clear whether an order is actually sent and actually fails as we do not know if your 2 lines of code are contained in the same block

I suspect that you have declared OrderSendResult  as a bool whereas the OrderSend function returns an integer 

 

  if(Condition)
     {
     int OrderSendResult=OrderSend(SymbolArray[i],OP_BUY,UseLots,MarketInfo(SymbolArray[i],MODE_ASK),Slippage,0,0,"A",MagicNumber,Blue);
     if (OrderSendResult <= 0) Print("OrderSend  ",SymbolArray[i],"  failed with error #",GetLastError());
     } 
Yochanan Gerbi
519
Yochanan Gerbi 2015.01.02 00:03  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. You are opening an order for symbol SymbolArray[i] but using the Ask price for symbol SymbolA.
  3. What is the definition of OrderSendResult?

Hello WHRoeder,

Thanks for your reply, the correct Code lines are:

   OrderSendResult = OrderSend(SymbolA,OP_BUY,UseLots,MarketInfo(SymbolA,MODE_ASK),Slippage,0,0,"Adding to a long pos",MagicNumber,Blue);

   if (OrderSendResult <= 0) Print("OrderSend  ",SymbolA,"  failed with error #",GetLastError());   

 So, we are still with the same problem, and I get back:

2014.12.31 17:31:26.422 Meymadv39 GBPJPY,H1: OrderSend  NZDUSD  failed with error #0

 I found the error # 0 is "No error", and I agree since the EA is running well, but sometimes it doesn't open a new trade.

WHY? 

GumRai, Response your guess - it is wrong. OrderSend Result is an Integer.

So we are still with the problem.

Any new Idea? 

Alain Verleyen
Moderator
28701
Alain Verleyen 2015.01.02 00:08  
crossy:

Hello WHRoeder,

Thanks for your reply, the correct Code lines are:

   OrderSendResult = OrderSend(SymbolA,OP_BUY,UseLots,MarketInfo(SymbolA,MODE_ASK),Slippage,0,0,"Adding to a long pos",MagicNumber,Blue);

   if (OrderSendResult <= 0) Print("OrderSend  ",SymbolA,"  failed with error #",GetLastError());   

 So, we are still with the same problem, and I get back:

2014.12.31 17:31:26.422 Meymadv39 GBPJPY,H1: OrderSend  NZDUSD  failed with error #0

 I found the error # 0 is "No error", and I agree since the EA is running well, but sometimes it doesn't open a new trade.

WHY? 

GumRai, Response your guess - it is wrong. OrderSend Result is an Integer.

So we are still with the problem.

Any new Idea? 

 

Please check your code. Error 0 means your if statement is executed while the OrderSend statement is not.

If you post code again, please use the SRC button, and a comprehensive excerpt including all trading block.

Yochanan Gerbi
519
Yochanan Gerbi 2015.01.02 09:54  

Thanks angevoyageur,

 You are correct.

the code line is:

   if (OrderSendResult <= 0) Print("OrderSend  ",SymbolA,"  failed with error #",GetLastError());    

and you can see that the IF statement is executed and the OrderSend is not. 

Here is the "whole" part of the EA:

          if ( i==0 || i==1 || i==2 || i==3 )

          {

            OrderSendResult = OrderSend(SymbolArray[i],OP_BUY,UseLots,MarketInfo(SymbolArray[i],MODE_ASK),Slippage,0,0,"Adding to a long pos",MagicNumber,Blue);

            if (OrderSendResult <= 0) Print("OrderSend  ",SymbolArray[i],"  failed with error #",GetLastError()); 

            Sleep(1000);

          }

 

and for your convenience here is the massage I get:

2014.12.31 17:31:26.422 Meymadv39 GBPJPY,H1: OrderSend  NZDUSD  failed with error #0 

 

I want to say that this massage appears just when the volatility of the market is very low (like on 31/12/2014 afternoon, or on 2/1/2015 (today) morning....) 

Alain Verleyen
Moderator
28701
Alain Verleyen 2015.01.03 10:25  
crossy:

Thanks angevoyageur,

 You are correct.

the code line is:

   if (OrderSendResult <= 0) Print("OrderSend  ",SymbolA,"  failed with error #",GetLastError());    

and you can see that the IF statement is executed and the OrderSend is not. 

Here is the "whole" part of the EA:

          if ( i==0 || i==1 || i==2 || i==3 )

          {

            OrderSendResult = OrderSend(SymbolArray[i],OP_BUY,UseLots,MarketInfo(SymbolArray[i],MODE_ASK),Slippage,0,0,"Adding to a long pos",MagicNumber,Blue);

            if (OrderSendResult <= 0) Print("OrderSend  ",SymbolArray[i],"  failed with error #",GetLastError()); 

            Sleep(1000);

          }

 

and for your convenience here is the massage I get:

2014.12.31 17:31:26.422 Meymadv39 GBPJPY,H1: OrderSend  NZDUSD  failed with error #0 

 

I want to say that this massage appears just when the volatility of the market is very low (like on 31/12/2014 afternoon, or on 2/1/2015 (today) morning....) 

Documentation says:

 Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional errorinformation, one has to call the GetLastError() function.

So you have to check if OrdersendResult is -1 and not <=0.

Is there anything else in the log at this time ? 

Yochanan Gerbi
519
Yochanan Gerbi 2015.01.07 09:45  
angevoyageur:

Documentation says:

So you have to check if OrdersendResult is -1 and not <=0.

Is there anything else in the log at this time ? 

Well, I found the source of the problem.

It is the broker. The broker has a limit of opened trades, and as it  exceed the limit, the EA can't open new trades.

Thanks, and I hope it helped to somebody. 

whroeder1
13656
whroeder1 2015.01.07 13:02  
crossy: Well, I found the source of the problem. It is the broker. The broker has a limit of opened trades, and as it  exceed the limit, the EA can't open new trades.
Then GetLastError should have returned 148 not zero

148

ERR_TRADE_TOO_MANY_ORDERS

The amount of open and pending orders has reached the limit set by the broker

Complain to the broker.
/
To add comments, please log in or register