OrderModify sometimes returning ERROR 130

 
How code below I am sending the function OrderModify to platform and some times the platform is returning code ERROR 130, this error is abour STOP LOSS values,
for me is this OK, I cant understand why is returning it some times.

Can help me to resolve it ?

Inside a loop with 'for'

if(OrderSymbol() == Symbol()){
        
        profit=NormalizeDouble(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE),0);
        
        if(TO == OP_BUY){
           BuyTotalOrdersOpen++;
           if((profit > 50) && (TotalOrdersOpened() == 1) && (NormalizeDouble((OrderOpenPrice()+20*Point),Digits) != OrderStopLoss())){
                  if(OrderModify(ticket,OrderOpenPrice(),NormalizeDouble((OrderOpenPrice()+20*Point),Digits),OrderOpenPrice()+185*Point,0,Green)){// retorno da funcao OrderModify true ou false implicito.
                         Print("StopLoss da ordem de compra modificado para 20 pontos de profit!!!" );
                  }else{
                         Print("Error: ", GetLastError());
                  }
           }
        }
}

int TotalOrdersOpened(){
   int i, ticket, TO;
   int TotalOrdersOpen=0;
   for (i = 0; i < OrdersTotal(); i++){
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
         ticket=OrderTicket();
         TO=TipoOrdem(ticket);
         
         if(OrderSymbol() == Symbol()){            
            if(TO == OP_SELL){
               TotalOrdersOpen++;
            }
         }
         if(OrderSymbol() == Symbol()){            
            if(TO == OP_BUY){
               TotalOrdersOpen++;
            }
         }
      }
   }
   return(TotalOrdersOpen);   
}
 
lmoraes:
How code below I am sending the function OrderModify to platform and some times the platform is returning code ERROR 130, this error is abour STOP LOSS values,
for me is this OK, I cant understand why is returning it some times.

Can help me to resolve it ?

Inside a loop with 'for'

<CODE REMOVED>

Please read some other posts before posting . . .

Please edit your post or your thread will be removed . . . please use the SRC button to post code: How to use the SRC button.


 
Explains error 130 here. Also see document here.
 
lmoraes: NormalizeDouble((OrderOpenPrice()+20*Point),Digits) != OrderStopLoss())){

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

  2. The == operand. - MQL4 forum
 

I cant use the operator != do this ?


if (a != b)
if (MathAbs(a - b) > Point / 2.)


I should use it?

 
lmoraes:

I cant use the operator != do this ?



I should use it?

read this and you will have your answer: The == operand. - MQL4 forum
 
I changed the code removing the NormalizeDouble in the 'if' operators and put the function checkDoubles, but the error 130 continue happening.

The code now is:

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


int TotalOrdersOpened(){
   int i, ticket, TO;
   int TotalOrdersOpen=0;
   for (i = 0; i < OrdersTotal(); i++){
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
         ticket=OrderTicket();
         TO=TipoOrdem(ticket);
         
         if(OrderSymbol() == Symbol()){            
            if(TO == OP_SELL){
               TotalOrdersOpen++;
            }
         }
         if(OrderSymbol() == Symbol()){            
            if(TO == OP_BUY){
               TotalOrdersOpen++;
            }
         }
      }
   }
   return(TotalOrdersOpen);   
}

bool checkDoubles(double a, double b, string check){
        if(check==">"){
                if (a - b > Point / 2)return(1);else return (0);
        }else if(check=="<"){
                if (b - a > Point / 2)return(1);else return (0);
        }else if(check==">="){
                if (a - b > -Point)return(1);else return (0);
        }if(check=="<="){
                if (b - a > -Point)return(1);else return (0);
        }else if(check=="!="){
                if (MathAbs(a - b) > Point / 2)return(1);else return (0);
        }else {
                Print("Sorry you've entered a wrong check value");
        }
        return (0);
}

For me is the same problem yet.

 

You are modifying your order when it hits 100 Points profit

You are not checking to see if it has already been modified

Next tick, if profit remains at more than 100 Points, the program will try to modify the order again with the same values.

This will return the error.

 
GumRai:

You are modifying your order when it hits 100 Points profit

You are not checking to see if it has already been modified

Next tick, if profit remains at more than 100 Points, the program will try to modify the order again with the same values.

This will return the error.


Not exactly

The check below ensure that the order already been modified. And the error 130 is not about it, if you the in the table ERROR this error say: Stops are too close, or prices are ill-calculated or unnormalized ....

(checkDoubles((OrderOpenPrice()+50*Point), OrderStopLoss(), "!=") == true) 
 
lmoraes:


Not exactly

The check below ensure that the order already been modified. And the error 130 is not about it, if you the in the table ERROR this error say: Stops are too close, or prices are ill-calculated or unnormalized ....

If you want to avoid error 130 there is a correct way to do it . . . ensure that your Orders meet these requirements: Requirements and Limitations in Making Trades
 
lmoraes:


Not exactly

The check below ensure that the order already been modified. And the error 130 is not about it, if you the in the table ERROR this error say: Stops are too close, or prices are ill-calculated or unnormalized ....


Sorry about that.

To be honest, with a name like checkDoubles(), I thought that it was some kind of checking normalise double function, so I didn't look too closely at it.

Especially as you wrote in your post "I changed the code removing the NormalizeDouble in the 'if' operators and put the function checkDoubles, but the error 130 continue happening."

Reason: