OrderModify sometimes returning ERROR 130 - page 2

 
What does the function TipoOrdem() do?
 
GumRai:
What does the function TipoOrdem() do?

Return the order type of the ticket selected

int TipoOrdem(int ticket){
   int TO;
   if(OrderSelect(ticket,SELECT_BY_TICKET)==true){
      TO=OrderType();
   }else{
      Print("Error, invalid select order! Ticket: ", ticket);
      Print(GetLastError());
   }
   return (TO);
}


 
int TipoOrdem(int ticket){
   int TO;
   if(OrderSelect(ticket,SELECT_BY_TICKET)==true){
      TO=OrderType();
   }else{
      Print("Error, invalid select order! Ticket: ", ticket);
      Print(GetLastError());
   }
   return (TO);
}
This will return OP_BUY even when the OrderSelect() fails .... just in case you didn't know.
 
I briefly saw 130 when I tried to move the SL one point (1/10 pip, 5 digit broker) but couldn't reproduce it. Change your test to move the SL at least a pip.
 
ubzen:
This will return OP_BUY even when the OrderSelect() fails .... just in case you didn't know.


It is difficult to tell from the code, if TO is a Global scope variable, it would be unchanged, or would it? To be honest I don't know what happens when a Global scope variable is re-declared. Is it re-set to zero? In that case, you would certainly be correct.

Are "TO" and "ticket" Global scope variables ? They are both declared in 2 functions and referenced in start() with no declaration.

Why the need for the function TipoOrdem? It just makes the code more confusing, especially with variable being declared more than once.

I suspect that they are indeed Global scope and possibly the ticket number that the code is trying to modify is not the intended ticket number.

 
WHRoeder:
I briefly saw 130 when I tried to move the SL one point (1/10 pip, 5 digit broker) but couldn't reproduce it. Change your test to move the SL at least a pip.


My broker has 5 digits,

How I said, sometimes the OrderModify return OK, when the EA stop in this error its continue in a loop until lost the opportunity of lock the profit.

I am thinking in stop of use this function and use internal variable to control it, and then when I want to stop it I send an OrderClose(). Is a way, but not is a good way in my opinion.

 
GumRai:


It is difficult to tell from the code, if TO is a Global scope variable, it would be unchanged, or would it? To be honest I don't know what happens when a Global scope variable is re-declared. Is it re-set to zero? In that case, you would certainly be correct.

Are "TO" and "ticket" Global scope variables ? They are both declared in 2 functions and referenced in start() with no declaration.

Why the need for the function TipoOrdem? It just makes the code more confusing, especially with variable being declared more than once.

I suspect that they are indeed Global scope and possibly the ticket number that the code is trying to modify is not the intended ticket number.

int TipoOrdem(int ticket){
   int TO; <---- Declared Locally

It'll take priority over any global variable. By default Mt4 initializes it to 0 when declared like that. Can solve with something like int TO= -1;

The ticket in the function is the passed parameter. When he uses the function it'll only look at that value even if there's a global variable with the same name. Same goes for the TO.

Think about it like the variable i as in .. for( int i=0; i<OrdersTotal(); i++). People declare the i everywhere. Thats kinda what he's doing with his TO .. I'm guessing (haven't gone through all his codes).

 
GumRai:


It is difficult to tell from the code, if TO is a Global scope variable, it would be unchanged, or would it? To be honest I don't know what happens when a Global scope variable is re-declared. Is it re-set to zero? In that case, you would certainly be correct.

Are "TO" and "ticket" Global scope variables ? They are both declared in 2 functions and referenced in start() with no declaration.

Why the need for the function TipoOrdem? It just makes the code more confusing, especially with variable being declared more than once.

I suspect that they are indeed Global scope and possibly the ticket number that the code is trying to modify is not the intended ticket number.


"TO" and "ticket" is not Global scope variables. Both are reclared in fuctions start() and in TotalOrdersOpened()

Normally my EA work with two orders buy and sell with the same pair, and I use the function TipoOrdem to select the correct order that should apply it. Resuming is only to select the correct ticket.

 
lmoraes:


"TO" and "ticket" is not Global scope variables. Both are reclared in fuctions start() and in TotalOrdersOpened()

Normally my EA work with two orders buy and sell with the same pair, and I use the function TipoOrdem to select the correct order that should apply it. Resuming is only to select the correct ticket.


If they are not Global scope, what values will they have in your modify code?

 if(TO == OP_BUY){

//WHERE DOES TO GET ITS VALUE FROM????

           BuyTotalOrdersOpen++;
           if((profit > 100) && (TotalOrdersOpened() == 1) && (checkDoubles((OrderOpenPrice()+50*Point), OrderStopLoss(), "!=") == true)){
                  if(OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+50*Point,OrderOpenPrice()+185*Point,0,Green)){

                         //WHERE DOES TICKET GET ITS VALUE FROM?????

                         Print("StopLoss da ordem de compra modificado para 50 pontos de profit!!!" );
                  }else{
                         Print("Error: ", GetLastError());
 
GumRai:


If they are not Global scope, what values will they have in your modify code?


ticket is a variable defined in scope of function start()

The complete loop is:

   for (i = 0; i < OrdersTotal(); i++){
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
         ticket=OrderTicket();
         TO=TipoOrdem(ticket);
         
         if(OrderSymbol() == Symbol()){
            
            profit=NormalizeDouble(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE),0);
            
            if(TO == OP_BUY){
               BuyTotalOrdersOpen++;
               if((profit > 80) && (TotalOrdersOpened() == 1) && (checkDoubles((OrderOpenPrice()+40*Point), OrderStopLoss(), "!=") == true)){
                  if(OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+40*Point,OrderOpenPrice()+185*Point,0,Green)){// retorno da funcao OrderModify true ou false implicito.
                     Print("StopLoss da ordem de compra modificado para 40 pontos de profit!!!" );
                  }else{
                     Print("Error: ", GetLastError());
                  }
               }
            }
         }
      }
   }