Download MetaTrader 5
To add comments, please log in or register
Find out how your rating can be improved
trader201
404
trader201 2014.06.18 15:07 

error 131. This is the ordersend:


OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-500*Point,Ask+500*Point,NULL,0,0, clrNONE);


Somebody know what is the error?

Drazen Penic
2405
Drazen Penic 2014.06.18 15:27  

From here :

 

#define ERR_INVALID_TRADE_VOLUME                    131

 

Your broker does not allow 0.01 lot. 

To find minimum lot use MarketInfo():

Print("Minimum permitted amount of a lot=",MarketInfo(Symbol(),MODE_MINLOT));
trader201
404
trader201 2014.06.19 14:14  
drazen64:

From here :

 

 

Your broker does not allow 0.01 lot. 

To find minimum lot use MarketInfo():

 

 

 



Thank you drazen64. But the broker allows me to trade 0.01. So, here other thing: When I do a testing with "print gest last error," appears in the diary "Error 4051". When I open one of those error messages, says "error 131".

This is the code:


void OnTick()
  {
   double TEND1, TEND2;
 
   TEND1= iADX(NULL,14,PERIOD_CURRENT,PRICE_CLOSE, MODE_PLUSDI,1);
   TEND2= iADX(NULL,14,PERIOD_CURRENT,PRICE_CLOSE, MODE_PLUSDI,2);
//---
   if (OrdersTotal()==0 && TEND1>TEND2)
      {
      int ticket=OrderSend(Symbol(),OP_BUY,0.01, Ask, 10, Ask-500*Point, Ask+500*Point, NULL, 0, 0, clrNONE);
     
      }
   Print("error", GetLastError());
  }
//+------------------------------------------------------------------+

Drazen Penic
2405
Drazen Penic 2014.06.19 14:30  

First, use "SRC" when posting code (you can edit your post)

Move error printing inside if statement so that you are sure that GetLastError reports OrderSend() eventual error: 

void OnTick()
  {
   double TEND1, TEND2;
  
   TEND1= iADX(NULL,14,PERIOD_CURRENT,PRICE_CLOSE, MODE_PLUSDI,1);
   TEND2= iADX(NULL,14,PERIOD_CURRENT,PRICE_CLOSE, MODE_PLUSDI,2);
//---
   if (OrdersTotal()==0 && TEND1>TEND2)
      {
      int ticket=OrderSend(Symbol(),OP_BUY,0.01, Ask, 10, Ask-500*Point, Ask+500*Point, NULL, 0, 0, clrNONE);
      if(ticket < 0)
        Print("error", GetLastError());  // to be sure that error is from OrderSend      
      }
   
  }
//

 

Some of reasons OrderSend can fail are if SL and TP are to close to the price, you work with ECN broker - you should not send SL and TP. 

Drazen Penic
2405
Drazen Penic 2014.06.19 14:36  


First fix iADX calls.   Error 4051 is probably because you missed second parameter - it should be timeframe constant, but you put 14: 

TEND1= iADX(NULL,14,PERIOD_CURRENT,PRICE_CLOSE, MODE_PLUSDI,1);

 

double  iADX(
   string       symbol,        // symbol
   int          timeframe,     // timeframe
   int          period,        // averaging period
   int          applied_price, // applied price
   int          mode,          // line index
   int          shift          // shift
   );

trader201
404
trader201 2014.06.19 17:47  

Ok. This is the right way:


   TEND1= iADX(NULL,PERIOD_M15,14,PRICE_CLOSE, MODE_PLUSDI,1);

   TEND2= iADX(NULL,PERIOD_M15,14,PRICE_CLOSE, MODE_PLUSDI,2);


The problem was the lot size (I do not know why because my broker allow to trade 0.01 lot). I guess maybe not in testing and EAs.

Thanks to all.

/
To add comments, please log in or register