Error #130

To add comments, please log in or register
Hannan Nussbaum
199
Hannan Nussbaum  

I keep getting error #130. I understand that it has to do with sl or tp however I tried many combinations including atr based and nothing works:


OrderSend Sell failed with error-130 symbol=EURTRY Lots=0.01 price=4.54817 sl=4.55851 tp=4.52749

OrderSend Sell failed with error-130 symbol=USDZAR Lots=0.01 price=13.46761 sl=13.46911 tp=13.46461

OrderSend Sell failed with error-130 symbol=USDMXN Lots=0.01 price=18.77151 sl=18.77301 tp=18.76851

OrderSend Buy failed with error-130 symbol=GBPPLN Lots=0.01 price=4.78105 sl=4.77955 tp=4.78405

OrderSend Sell failed with error-130 symbol=GBPJPY Lots=0.01 price=150.917 sl=151.067 tp=150.617

OrderSend Buy failed with error-130 symbol=USDHKD Lots=0.01 price=7.81448 sl=7.81298 tp=7.81748

Sergey Golubev
Moderator
106121
Sergey Golubev  

If you post your code so the people may help

Forum on trading, automated trading systems and testing trading strategies

Strategy tester error 130

whroeder1, 2011.07.30 18:16

I had problems when I tried using buystops with tp/sl. I thought it was comparing current price vs stops but couldn't ever verify. Could also be ECN, open first THEN set stops.

Hannan Nussbaum
199
Hannan Nussbaum  
extern double Take_Profit=300; // 5 digit broker?
extern double Stop_Loss=150;

void Buy(string symbol,string comment)
{
   double point,ask,bid,minstoplevel; 
   double stoploss,takeprofit;
   int i,digits,ticket;
   bool order_already_exists=false,res;
   double atr;
   
   for(i=OrdersTotal()-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==Expert_Id)
            if(OrderType()==OP_BUY)
               if(OrderSymbol()==symbol) order_already_exists=true;
   }
   
   if(!order_already_exists)
   {
      ask=MarketInfo(symbol,MODE_ASK);
      bid=MarketInfo(symbol,MODE_BID);
      point=MarketInfo(symbol,MODE_POINT); 
      digits=MarketInfo(symbol,MODE_DIGITS);   
      
      stoploss=NormalizeDouble(ask-Stop_Loss*point,digits); 
      takeprofit=NormalizeDouble(ask+Take_Profit*point,digits); 
      
      ticket=OrderSend(symbol,OP_BUY,Lots,ask,Slippage,0,0,comment,Expert_Id,0,Green);      
      
      if(ticket<0) 
      { 
         Print("OrderSend Buy failed with error-",GetLastError()," symbol=",symbol," Lots=",Lots," price=",ask," sl=",stoploss," tp=",takeprofit); 
      } 
      else
      { 
         res = OrderModify(ticket, 0, stoploss, takeprofit, 0);
         if(!res) {Print("OrderModify Error: ", GetLastError());
                   Print("IMPORTANT: ORDER #", ticket, " HAS NO STOPLOSS AND TAKEPROFIT");}
      }
   }
}
//+------------------------------------------------------------------+
void Sell(string symbol,string comment)
{
   double point,ask,bid,minstoplevel; 
   double stoploss,takeprofit;
   int i,digits,ticket;
   bool order_already_exists=false,res;
   double atr;
   
   for(i=OrdersTotal()-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==Expert_Id)
            if(OrderType()==OP_SELL)
               if(OrderSymbol()==symbol) order_already_exists=true;
   }
   
   if(!order_already_exists)
   {
      ask=MarketInfo(symbol,MODE_ASK);
      bid=MarketInfo(symbol,MODE_BID);
      point=MarketInfo(symbol,MODE_POINT); 
      digits=MarketInfo(symbol,MODE_DIGITS);   
      
      stoploss=NormalizeDouble(bid+Stop_Loss*point,digits); 
      takeprofit=NormalizeDouble(bid-Take_Profit*point,digits); 
      
      ticket=OrderSend(symbol,OP_BUY,Lots,bid,Slippage,0,0,comment,Expert_Id,0,Green);      
            
      if(ticket<0) 
      { 
         Print("OrderSend Sell failed with error-",GetLastError()," symbol=",symbol," Lots=",Lots," price=",bid," sl=",stoploss," tp=",takeprofit); 
      } 
      else 
      { 
         res = OrderModify(ticket, 0, stoploss, takeprofit, 0);
         if(!res) {Print("OrderModify Error: ", GetLastError());
                   Print("IMPORTANT: ORDER #", ticket, " HAS NO STOPLOSS AND TAKEPROFIT");}
      }  
   }       
}
soubra2003
31843
soubra2003  
You haven't given the 'minstopleve'l any value!
Make a simple calculation of your sl/tp then they should be >= it.

double point,ask,bid,minstoplevel; 
whroeder1
17944
whroeder1  
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. res = OrderModify(ticket, 0, stoploss, takeprofit, 0);
    
    Of course you get error 130, you can't modify the open price to zero. (Select the order and use actual price.)

  3. extern double Take_Profit=300; // 5 digit broker?
    extern double Stop_Loss=150;
    
          stoploss=NormalizeDouble(bid+Stop_Loss*point,digits); 
          takeprofit=NormalizeDouble(bid-Take_Profit*point,digits); 
    Using Points means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong

To add comments, please log in or register