get Order Modify() Error 130

 

hi guys.

i have this type of error in this function, why happening?


 void tpsl ()
{
   double tp = 0;
   double sl= 0;
   for(int i=0;i< OrdersTotal () ; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
            if(OrderType()== OP_BUY)
            {  
               sl = OrderOpenPrice()-StopLoss*pt; 
               tp = OrderOpenPrice()+TakeProfit*pt;
               OrderModify(OrderTicket(),OrderOpenPrice(),sl ,tp,0,0);              
            }
             if(OrderType()== OP_SELL)
            {
               sl = OrderOpenPrice()+StopLoss*pt;
               tp = OrderOpenPrice()-TakeProfit*pt;               
               OrderModify(OrderTicket(),OrderOpenPrice(),sl ,tp,0,0);
            }           
        }
     }
}




 
farzin:

hi guys.

i have this type of error in this function, why happening?





Hi,

You could get help from this codebase :

https://www.mql5.com/en/code/18011

Regards.

Modify SL TP
Modify SL TP
  • www.mql5.com
This script is used to modify the Stop Loss and Take Profit of current symbol positions. The new Stop Loss and Take Profit are based on the market price. If the inputs are 0, there will be no modification. It is useful to update all positions with the same SL/TP. LRDegrees MT4...
 

Hello my friend,

MQL can't see your ticket number atm. Your telling it only total orders and not the ticket number. Also if you checked OrderModify it would have resulted a false "bool" value.

Hint: OrderModify Needs new values to change.

 void tpsl ()
{
   double tp = 0;
   double sl= 0;
   for(int i=0;i< OrdersTotal () ; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
            if(OrderType()== OP_BUY)
            {  
               sl = OrderOpenPrice()-StopLoss*pt; 
               tp = OrderOpenPrice()+TakeProfit*pt;
               OrderModify(OrderTicket(),OrderOpenPrice(),sl ,tp,0,0);              
            }
             if(OrderType()== OP_SELL)
            {
               sl = OrderOpenPrice()+StopLoss*pt;
               tp = OrderOpenPrice()-TakeProfit*pt;               
               OrderModify(OrderTicket(),OrderOpenPrice(),sl ,tp,0,0);
            }           
        }
     }
}
 
SL or TP must be greater than STOP LEVEL , MarketInfo(NULL,MODE_STOPLEVEL)
Basic Principles - Trading Operations - MetaTrader 5
Basic Principles - Trading Operations - MetaTrader 5
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 
farzin:

hi guys.

i have this type of error in this function, why happening?





 void tpsl ()
{
   double tp = 0;
   double sl= 0;
   double pt=0;
   for(int i=0;i< OrdersTotal () ; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
        pt=MarketInfo(OrderSymbol(),MODE_POINT);
            if(OrderType()== OP_BUY)
            {  
               sl = NormalizeDouble(OrderOpenPrice()-StopLoss*pt,MarketInfo(OrderSymbol(),MODE_DIGITS)); 
               tp = NormalizeDouble(OrderOpenPrice()+TakeProfit*pt,MarketInfo(OrderSymbol(),MODE_DIGITS));
               OrderModify(OrderTicket(),OrderOpenPrice(),sl ,tp,0,clrNONE);              
            }
             if(OrderType()== OP_SELL)
            {
               sl = NormalizeDouble(OrderOpenPrice()+StopLoss*pt,MarketInfo(OrderSymbol(),MODE_DIGITS));
               tp = NormalizeDouble(OrderOpenPrice()-TakeProfit*pt,MarketInfo(OrderSymbol(),MODE_DIGITS));               
               OrderModify(OrderTicket(),OrderOpenPrice(),sl ,tp,0,clrNONE);
            }           
        }
     }
}