Download MetaTrader 5

Error 129/130 help

To add comments, please log in or register
sayo
45
sayo  
void LOAD_PENDING_TRADES()
{
   
  // Get signal
  string signal = HTTP_GET(StringConcatenate("http://example.com/api/getTrades?act=", fx_account_no));
  
  if(signal != "NONE" && signal != "INVALID_ACCOUNT")
  {
  
     ushort separator = StringGetCharacter(":", 0);
     string result[];
     
     // Retrieve individual signals
     int the_split = StringSplit(signal, separator, result);
     
     if(the_split > 0)
     {
          for(int i=0; i < the_split; i++)
          {
           
            // Split the signal into usable parts
            string signalItem = result[i];
            ushort itemSeparator = StringGetCharacter(",", 0);
            string getSignalItem[];
            int split_signalItem = StringSplit(signalItem, itemSeparator, getSignalItem);
            
            // Define all required parameters
            string   symbol            = getSignalItem[1];
            string   orderType         = getSignalItem[2];
            double   orderVolume;
            int      slippage          = 5;
            double   entryPrice        = (double) StrToDouble(getSignalItem[3]);
            double   stoploss          = (double) getSignalItem[5];
            double   takeProfit        = (double) getSignalItem[6];
            string   comment           = "Trade Signal";
            color    colour            = clrNONE;
            datetime expiryTime        = getSignalItem[8];
            int      MAGIC_NO          = getSignalItem[0];
            
            int      pairDigits        = (int) MarketInfo(symbol, MODE_DIGITS);
            double   pairPoint         = MarketInfo(symbol,MODE_POINT); 
            double   STOP_DIFFERENCE   = entryPrice - stoploss;
            double   stoploss_in_point;
            datetime expiry;
            
            
            // Prevent double entry of the same trade
            // Utilize the magic number to prevent this
            // Magic Number should be considered unique
            // Check if the order was previously opened
            if(ORDER_EXIST(symbol, MAGIC_NO) == true) continue;
            
            // Invalid point value
            // Return to next loop item
            if(pairPoint == 0) continue;
            
            // Calculate stop loss value in points
            stoploss_in_point = NormalizeDouble(MathAbs(STOP_DIFFERENCE/pairPoint),0);
            
            // Calculate order volume
            orderVolume = VerifyLotSize(calculateLotSize(true, 2, stoploss_in_point, symbol),symbol);
            
            // Check expiry date
            if(expiryTime == "0000-00-00")
            {
               expiry = 0;
            }
            else
            {
               expiry = StrToTime(expiryTime);
            }
            
            
            // Check if MT4 is busy & pause until free
            while(IsTradeContextBusy()) Sleep(10);
              
            // Submit order
            int Ticket = OrderSend( symbol, orderType,  orderVolume, NormalizeDouble(entryPrice, pairDigits), slippage, 0, 0, comment, MAGIC_NO, expiry, colour );
             
             // Do some checks to log errors
             if(Ticket == -1)
             {
               int ErrorCode = GetLastError();
               // Alert(ErrorCode);
               // string ErrDesc = ErrorDescription(ErrorCode);
               string ErrAlert = StringConcatenate("ERROR_CODE: ", ErrorCode, " | SYMBOL: ", symbol, 
                                                   " | ORDER TYPE: ", orderType, " | ", "PRICE: ", entryPrice, 
                                                   " | ", "STOP: ", stoploss, " | ", "TAKE PROFIT: ", takeProfit, " | ",
                                                    "MAGIC NO: ", MAGIC_NO);
               Print(ErrAlert); 
             }
            
            
          }
     }
     
   }  
}



I am new to MQL and code above is supposed to produce an order but I keep getting either error 130 (invalid stops) or 129 (invalid price).

Anyone help please.

Carl Schreiber
7087
Carl Schreiber  
Well as you wrote the prices aren't correct. You have to compare them to the actual Close[0] and s/l and t/p has to have (broker dependent) a minimal distance.
sayo
45
sayo  
The prices are correct and they are all pending orders
Carl Schreiber
7087
Carl Schreiber  
If so you wouldn't get the error. Print them out?
sayo
45
sayo  
2014.10.23 15:04:07.606    EURUSD,H1: ERROR_CODE: 129 | SYMBOL: AUDUSD | ORDER TYPE: OP_BUYSTOP | PRICE: 0.99 | STOP: 0.982 | TAKE PROFIT: 1.042 | MAGIC NO: 138
Carl Schreiber
7087
Carl Schreiber  

??????

int Ticket = OrderSend( symbol, orderType,  orderVolume, NormalizeDouble(entryPrice, pairDigits), slippage, 0, 0, comment, MAGIC_NO, expiry, colour );

1) In your program s/l and t/p are  0!

2) Print out: Symbol, iClose(symbol,0), your normalized Entry price.

3) There are minimal price differences set by your broker - do you know them?

4) Did you consider the spread?

sayo
45
sayo  
gooly:

??????

1) In your program s/l and t/p are  0!

2) Print out: Symbol, iClose(symbol,0), your normalized Entry price.

3) There are minimal price differences set by your broker - do you know them?

Yes. I deliberately set s/l and t/p to 0 for test reasons. Trying suggestion 2 now.

I really cannot just figure out what the heck is the problem!

Using this exact figures on Ordersend as standalone outside the function above works!

sayo
45
sayo  

Result of iClose(symbol,PERIOD_H1, 0)

2014.10.23 16:16:24.898    EURUSD,H1: ERROR_CODE: 129 | SYMBOL: AUDUSD | ORDER TYPE: OP_BUYSTOP | PRICE: 0.99 | STOP: 0.982 | TAKE PROFIT: 1.042 | MAGIC NO: 138 | iclose: 0.878

Carl Schreiber
7087
Carl Schreiber  

3) There are minimal price differences set by your broker - do you know them? May be STOP: 0.982is to close...

4) What is the value of

NormalizeDouble(entryPrice, pairDigits)

5) What is

pairDigits
sayo
45
sayo  

Value of

NormalizeDouble(entryPrice, pairDigits)

= 0.99


pairDigits

int      pairDigits        = (int) MarketInfo(symbol, MODE_DIGITS);


3) There are minimal price differences set by your broker - do you know them? May be STOP: 0.982is to close...

This is a pending trade with the following values:

SYMBOL: AUDUSD
ORDER TYPE: OP_BUYSTOP
PRICE: 0.99
STOP LOSS: 0.982

TAKE PROFIT: 1.042

(On a good day, entering this into the terminal ought not to produce error with entry price)

sayo
45
sayo  
Alert(OrderSend("AUDUSD", OP_BUYSTOP, 0.01, 0.99, 5, 0.982, 1.042, "comment", 138, 0, clrNONE));
Same information here & successful. Really confussed
12
To add comments, please log in or register