Download MetaTrader 5

OrderModify error 130

To add comments, please log in or register
baharin
78
baharin  

hi..

I have got an error message as below:-

OrderModify error 130

Could somebody help me how to solve this problem ?... my code as below:

Thank you

extern double  TopProfit = 0;
extern double  lot = 0.1;
extern int     StopLost = 0;
...
...
...

void SetBuyStopLost() {
   if (OrderOpenPrice() - Ask > Point * StopLost) { 
           OrderModify(TicketNumber, OrderOpenPrice(),  Ask+Point*10, OrderTakeProfit(), 0, Blue); 
    }
}

void SetSellStopLost() {
        if (Bid - OrderOpenPrice() > Point * StopLost) { 
                OrderModify(TicketNumber, OrderOpenPrice(), Bid-Point*10, OrderTakeProfit(), 0, Red); 
        } 
}

void OpenBuy() {         
   if (TopProfit > 0) {
      TicketNumber = OrderSend(Symbol(),OP_BUY,lot,Ask,1,0,Ask+TopProfit*Point,"kambing",MagicNumber,0,Blue);      
   } else {
      TicketNumber = OrderSend(Symbol(),OP_BUY,lot,Ask,1,0,0,"kambing",MagicNumber,0,Blue);      
   }
}

void CloseSell() {   
   if (Symbol() == "GOLD") {
      OrderClose(TicketNumber, OrderLots(), Ask, 4, Red);
   } else {
      OrderClose(TicketNumber, OrderLots(), Bid, 4, Red);
   }
}

void OpenSell() {
   if (TopProfit > 0) {
      TicketNumber = OrderSend(Symbol(),OP_SELL,lot,Bid,1,0,Bid-TopProfit*Point,"kambing",MagicNumber,0,Red);       
   } else {
      TicketNumber = OrderSend(Symbol(),OP_SELL,lot,Bid,1,0,0,"kambing",MagicNumber,0,Red);       
   }
} 

void CloseBuy() { 
   if (Symbol() == "GOLD") {
      OrderClose(TicketNumber, OrderLots(), Bid, 4, Blue);         
   } else {
      OrderClose(TicketNumber, OrderLots(), Ask, 4, Blue);         
   }
}

int GetMagicNumber (int MagicNumber, string symbol, int timeFrame) {
   int isymbol = 0;
   if (symbol == "EURUSD")       isymbol = 1;
   else if (symbol == "GBPUSD")  isymbol = 2;
   else if (symbol == "USDJPY")  isymbol = 3;
   else if (symbol == "USDCHF")  isymbol = 4;
   else if (symbol == "AUDUSD")  isymbol = 5;
   else if (symbol == "USDCAD")  isymbol = 6;
   else if (symbol == "EURGBP")  isymbol = 7;
   else if (symbol == "EURJPY")  isymbol = 8;
   else if (symbol == "EURCHF")  isymbol = 9;
   else if (symbol == "EURAUD")  isymbol = 10;
   else if (symbol == "EURCAD")  isymbol = 11;
   else if (symbol == "GBPUSD")  isymbol = 12;
   else if (symbol == "GBPJPY")  isymbol = 13;
   else if (symbol == "GBPCHF")  isymbol = 14;
   else if (symbol == "GBPAUD")  isymbol = 15;
   else if (symbol == "GBPCAD")  isymbol = 16;
   else if (symbol == "GOLD")    isymbol = 17;
   else if (symbol == "EURGBP")  isymbol = 18;
   else                          isymbol = 19;
   
   return (MagicNumber + isymbol);
}

int init() {
       MagicNumber = GetMagicNumber( MagicNumber, Symbol(), Period() );      
       return (0);
}

int deinit() {
   return(0);
}

int start() {
   ...
   ...
   ...         
   if (Test > 0) {     
      if (OrderSelect(TicketNumber, SELECT_BY_TICKET) == true) {
         if (OrderType() == OP_SELL) {
            CloseSell();
            OpenBuy();
         }         
      } else { 
         OpenBuy();
      }      
      
      if (StopLost > 0 && OrdersTotal() > 0) {
         SetBuyStopLost();
      }
      
   } else if (Test < 0) {
      if (OrderSelect(TicketNumber, SELECT_BY_TICKET) == true) {
         if (OrderType() == OP_BUY) {
             CloseBuy();
             OpenSell();
          }
      } else {
         OpenSell();
      }

      if (StopLost > 0 && OrdersTotal() > 0) {
         SetSellStopLost();
      }

   }
   
   return(0);
}
 
Simon Gniadkowski
Moderator
18019
Simon Gniadkowski  
bh_hensem:

hi..

I have got an error message as below:-

OrderModify error 130

Could somebody help me how to solve this problem ?... my code as below:

Thank you

Did you try searing the forum ?

https://www.mql5.com/en/forum/148288

whroeder1
15331
whroeder1  
  1. Not adjusting for 4/5 digit brokers and minimum limits
  2. void SetBuyStopLost() {
       if (OrderOpenPrice() - Ask > Point * StopLost) { 
               OrderModify(TicketNumber, OrderOpenPrice(),  Ask+Point*10, OrderTakeProfit(), 0, Blue); 
    
    Do you really think you can set a stop lost ABOVE the market on a buy order?
  3. Using the wrong value in the calculation. You BUY at the ASK, the stops are relative to the BID.
  4. extern int     StopLost = 0;
To add comments, please log in or register