Newbie Alert!! OrderModify help needed, please!

 

Hi,

I have created an ea with an OrderModify to add a Stop Loss to an open order, but every time it is executed, I receive a 141 error (too many requests). I don't know why.

Can you help me, please?

Thank you

 
landmeister:

Hi,

I have created an ea with an OrderModify to add a Stop Loss to an open order, but every time it is executed, I receive a 141 error (too many requests). I don't know why.

Can you help me, please?

Thank you

Only do it once . . . .  don't keep trying to Modify the same order . . .
 
RaptorUK:
Only do it once . . . .  don't keep trying to Modify the same order . . .

Hi RaptorUK,

 

But I'm trying to do a trailing stop in my ea, so I must modify the order every time it is needed. Anyway, the first modify already shows this error.

 

Thank you 

 
landmeister:

Hi RaptorUK,

 But I'm trying to do a trailing stop in my ea, so I must modify the order every time it is needed. Anyway, the first modify already shows this error. 

The first modify will not show that error unless you are already making too many requests for some other reason,  for example, repeated RefreshRates()  and if that is the case your error reporting is suspect because you are then reporting the error for something other than the OrderModify() . . . .   if you need specific help with your code you need to show it/some of it.
 

This is part of the code:

  <SNIP>

This is the first time OrderModify is used. Then, every tick, if the stop loss has to be moved, a new OrderModify (in a function executed later in the code) is executed.

 

Thank you 

 

landmeister: This is the first time OrderModify is used. Then, every tick, if the stop loss has to be moved, a new OrderModify (in a function executed later in the code) is executed.


  1. For large amounts of code, attach it
  2. Here is your code simplified.
    Stop_Loss_b=Busqueda_Fractal(superior);
    tb=Lanzar_Operacion(OP_BUY,num_lotes,0,TP,compra);
    :
    if (OrderSelect(tb,SELECT_BY_TICKET))
       {
       SL_b=OrderOpenPrice();
       :   
          OrderModify(tb,SL_b,Stop_Loss_b,0,0);
    
    Where are you checking if the current values are equal/not equal to the new ones?
  3. You would never write IF( (2+2) == 4) == true) would you? Then don't write IF( bool == true). IF(bool) and IF(!bool) is sufficient, simpler, and more readable.
 
landmeister:

This is part of the code:

  <SNIP>

This is the first time OrderModify is used. Then, every tick, if the stop loss has to be moved, a new OrderModify (in a function executed later in the code) is executed. 

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

 
landmeister:

This is part of the code:

This is the first time OrderModify is used. Then, every tick, if the stop loss has to be moved, a new OrderModify (in a function executed later in the code) is executed.

Your error checking is not valid,  if your OrderModify() fails,  then call GetLastError() and report the error . . . .  if you call GetLastError() when you don't need to you do two things,  you clear the error held by GetLastError() and you also run the risk of reporting the incorrect error at a later stage in your code. 


Read this for more info:  What are Function return values ? How do I use them ?
 

Thank you for your replies.

 

Ok, I didn't know there was a button to insert the code. I will use it from now on.

 

As I already said, I check the values later on my code, and this is done every tick. I just post this piece of the code to show that the first time I modify the order, the error shows.

 

I know that GetLastError should be used only when OrderModify fails but still I don't see why I have error 141. If I use GetLastError as you said, should the error change?

 

Thank you again 

 
landmeister: but still I don't see why I have error 141. 
I showed you why #2
 

Hi, I did the changes you told me:

 

1) I simplified the "if" statement.

2) I used GetLastError() only when OrderModify is not valid.

 

And still the same 141 error as soon as the stop loss is added.

 

I attach the simplified code.

 

Regards,  

Reason: