OrderModify sometimes returning ERROR 130 - page 3

 

Please post your entire code as relates to modifying the order.

Everytime we find a possible cause of your problem, you add an additional piece of code.

If you expect those willing to help you to scroll back and open new tabs to see what your functions do, you will probably be disappointed.

 
GumRai:

Please post your entire code as relates to modifying the order.

Everytime we find a possible cause of your problem, you add an additional piece of code.

If you expect those willing to help you to scroll back and open new tabs to see what your functions do, you will probably be disappointed.


Sorry, this is the entire code:

extern double volume=0.20;
int openorders=0;

int init(){
   return(0);
}

int deinit(){
   return(0);
}

int start(){
   RefreshRates();
   int BuyTotalOrdersOpen=0;
   int i;
   int ticket;
   int profit;
   int TO;

   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());
                  }
               }
            }
         }
      }
   }
}

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);   
}
   
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);
}

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);
}
 
up
 
RaptorUK:
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

Do your trades and modifications comply with the requirements ?