Download MetaTrader 5
To add comments, please log in or register
Do you need OpenCL? MQL5 can provide it!
Konstantinos Maleas
146
Konstantinos Maleas 2014.02.15 12:48 

Hello everybody

While I was trying to set up an error handling function into my EA for the first time I got this error … unlisted error.

My code is the following

if ( type >=0 && type <=30 )
{
   long_orders_array_ATF[store_long_position_4H][zz] = OrderSend(Symbol(), order_type, lot_size, 
   NormalizeDouble(entry_level,4),5, NormalizeDouble(long_sl,4), NormalizeDouble(take_profit_pips,4), order_comment,0,0,Green); 
}
if ( GetLastError() > 0 ) error_handler("Long",type,tf);

//--- Error Handler ---------------------------------------------------------------------------------------------------------------
void error_handler(string dir, int type, int tf)
{
   if ( dir == "Long" )  
   {
      if ( GetLastError() == 137 || GetLastError() == 138 ) order_send("Long",type,tf);
      if ( GetLastError() == 145 )  modify_orders("Long",type);
      if ( GetLastError() == 130 )  long_orders_array_ATF[store_long_position_4H][type] = 0;
   }   
   if ( dir == "Short" )
   {
      if ( GetLastError() == 137 || GetLastError() == 138 ) order_send("Short",type,tf);
      if ( GetLastError() == 145 )  modify_orders("Short",type);
      if ( GetLastError() == 130 )  short_orders_array_ATF[store_short_position_4H][type] = 0;
   }
}

Does anyone know why is this error appeared?

Thanks in advance.

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.15 13:10  
maleas_k:

Hello everybody

While I was trying to set up an error handling function into my EA for the first time I got this error … unlisted error.

My code is the following

Does anyone know why is this error appeared?

Thanks in advance.

Please wrap you code, you are making the page too wide . . .

Only check for an error when you have reason to do so . . . if(OrderSend() == failed) get the error and report it along with the relevant variables . . . don't forget that GetlastError() no longer clears the error, you need to use RestLastError()
Konstantinos Maleas
146
Konstantinos Maleas 2014.02.15 13:33  
RaptorUK:
Please wrap you code, you are making the page too wide . . .

Only check for an error when you have reason to do so . . . if(OrderSend() == failed) get the error and report it along with the relevant variables . . . don't forget that GetlastError() no longer clears the error, you need to use RestLastError()


If you mean that in the last version of MT4 is used the RestLastError(), my broker doesn't supported yet.

As for this ( Only check for an error when you have reason to do so ) i have a reason to check for errors after the order has been sent. I want to re-send the order or re-modify it.

You thing that my code is wrong ?

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.15 13:47  
maleas_k:

If you mean that in the last version of MT4 is used the RestLastError(), my broker doesn't supported yet.

As for this ( Only check for an error when you have reason to do so ) i have a reason to check for errors after the order has been sent. I want to re-send the order or re-modify it.

You thing that my code is wrong ?

Your code is not syntactically wrong, it's just that you are checking for an error when there isn't one . . . please read this: What are Function return values ? How do I use them ?

Having said that, you should be Buying at Ask and Selling at Bid . . . not at some other Normalized price
Konstantinos Maleas
146
Konstantinos Maleas 2014.02.15 15:23  

The GetLastError() returns error 130 but although i tried something else the problem still exists.

I could use some more help.

if ( type >=0 && type <=30 ) 
            {  
               long_orders_array_ATF[store_long_position_4H][zz] = OrderSend(Symbol(), order_type, lot_size, 
               NormalizeDouble(entry_level,4),5, NormalizeDouble(long_sl,4),NormalizeDouble(take_profit_pips,4), order_comment,0,0,Green); 
               if ( short_orders_array_ATF[store_short_position_4H][zz] < 0 ) error = GetLastError();//error_handler("Short",type,tf);
               Alert("error : ",error);
               if ( error == 130 ) error_handler("Long",type,tf,error);//error_handler("Long",type,tf);
            }
//--- Error Handler ---------------------------------------------------------------------------------------------------------------
void error_handler(string dir, int type, int tf,int errors)
{
   if ( dir == "Long" )  
   {
      if ( errors == 137 || error == 138 ) order_send("Long",type,tf);
      if ( errors == 145 )  modify_orders("Long",type);
      if ( errors == 130 )  long_orders_array_ATF[store_long_position_4H][type] = 0;
   }   
   if ( dir == "Short" )
   {
      if ( errors == 137 || error == 138 ) order_send("Short",type,tf);
      if ( errors == 145 )  modify_orders("Short",type);
      if ( errors == 130 )  short_orders_array_ATF[store_short_position_4H][type] = 0;
   }
}
Konstantinos Maleas
146
Konstantinos Maleas 2014.02.15 15:32  
RaptorUK:
Your code is not syntactically wrong, it's just that you are checking for an error when there isn't one . . . please read this: What are Function return values ? How do I use them ?

Having said that, you should be Buying at Ask and Selling at Bid . . . not at some other Normalized price

Sure I do buy at Ask and I Sell at Bid…

I am not that newbie and not that but coder. (Not Good either). :)

The price comes out of a calculation with more than 5 digits and the MT4 don’t allow this price. That is why Normalization is necessary.

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.15 16:15  
maleas_k:

Sure I do buy at Ask and I Sell at Bid…

I am not that newbie and not that but coder. (Not Good either). :)

The price comes out of a calculation with more than 5 digits and the MT4 don’t allow this price. That is why Normalization is necessary.

You can't calculate Bid or Ask . . . they are set . . . so use Bid or Ask, not

 NormalizeDouble(entry_level,4)

Modify your code to test the return value from your OrderSend() if the result is -1 it failed . . . THEN check the error.

Konstantinos Maleas
146
Konstantinos Maleas 2014.02.15 20:55  
RaptorUK:

You can't calculate Bid or Ask . . . they are set . . . so use Bid or Ask, not

Modify your code to test the return value from your OrderSend() if the result is -1 it failed . . . THEN check the error.

I really think that I have been misunderstood.

My problem is not the 130 error. I know what does it means and how to deal with it.

I tried to collect the error just after the OrderSend (), which I did, and send it to my function, the int error_handler(string dir, int type, int tf) and act by sending the order again or re-modify or just put 0 in the array position that the OrderSend puts -1 etc.

The main issue here is that when I tried to set up an error handler function the system started with the unlisted error message in journal and I don’t know who to resolve it.



//---- Here i collect the error ------------
if ( short_orders_array_ATF[store_short_position_4H][zz] < 0 ) error = GetLastError();
     Alert("error : ",error);
if ( error == 130 ) error_handler("Long",type,tf,error);
//---- Here is my Function -----------------
//--- Error Handler ------------------------
void error_handler(string dir, int type, int tf,int errors)
{
   if ( dir == "Long" )  
   {
      if ( errors == 137 || error == 138 ) order_send("Long",type,tf);
      if ( errors == 145 )  modify_orders("Long",type);
      if ( errors == 130 )  long_orders_array_ATF[store_long_position_4H][type] = 0;
   }   
   if ( dir == "Short" )
   {
      if ( errors == 137 || error == 138 ) order_send("Short",type,tf);
      if ( errors == 145 )  modify_orders("Short",type);
      if ( errors == 130 )  short_orders_array_ATF[store_short_position_4H][type] = 0;
   }
}

Just for the record this is how the entry_level is calculated…
entry_level= ds_array_ATF[2][0][6]  - (final_OSC *(take_profit_percent/100));
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.15 21:46  
maleas_k:

I really think that I have been misunderstood.

My problem is not the 130 error. I know what does it means and how to deal with it.

I tried to collect the error just after the OrderSend (), which I did, and send it to my function, the int error_handler(string dir, int type, int tf) and act by sending the order again or re-modify or just put 0 in the array position that the OrderSend puts -1 etc.

The main issue here is that when I tried to set up an error handler function the system started with the unlisted error message in journal and I don’t know who to resolve it.

Don't check for errors when there is no error to check for . . . read this and implement it. What are Function return values ? How do I use them ?
Konstantinos Maleas
146
Konstantinos Maleas 2014.02.16 16:15  
RaptorUK:
Don't check for errors when there is no error to check for . . . read this and implement it. What are Function return values ? How do I use them ?

I didn’t manage to resolve this but thanks for your help RaptorUK.

/
To add comments, please log in or register