Issue with Lot value in OrderSend

 

Hello,

   I am using MQL4. The situation goes like this: from CSV file I get a list of Lot values, and put them to double array, then according to market, using it for OrderSend. The problem is, that I get error for OrderSend 4051,  invalid lots amount for OrderSend function. When I manualy change value for the same as it is in CSV file, OrderSend works just fine. NormalizeDouble does not help either. More information bellow:

double LotArray[3];

fill it with double values from CSV file, values are: 0.01; 0.01; 0.01

Try order send with LotArray[0], 4051 error.

Manualy set 0.01 for LotArray[0] = 0.01, try OrderSend, works just fine.

When I Print(LotArray[0]) filled from CSV, I get 0.0100000

When I manualy set 0.01 for first the array element and then Print(LotArray[0]), I get 0.01

Notice, as I dont use DoubleToStr() inside print on purpose, to see the difference between what should be equal values.

Any thoughts ?


Thanks in advance,

Giedrius

Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
Trade Functions / OrderSend - Documentation on MQL5
 
Giedrius:

Hello,

   I am using MQL4. The situation goes like this: from CSV file I get a list of Lot values, and put them to double array, then according to market, using it for OrderSend. The problem is, that I get error for OrderSend 4051,  invalid lots amount for OrderSend function. When I manualy change value for the same as it is in CSV file, OrderSend works just fine. NormalizeDouble does not help either. More information bellow:



How do you use the function NormalizeDouble ()? Can you show that?
 
Rosh:
How do you use the function NormalizeDouble ()? Can you show that?

Hi Rosh,

  All is fine, it seams. I get good values and OrderSend works, if I let expert to run on live market. But, if I run it on test, I still get 4051 error, and expert does not open any orders.

Example of log I get on live market:

2012.03.15 22:16:37    liudas001 EURUSD,H1: open #4021062 buy stop 0.01 EURUSD at 1.3106 sl: 1.3087 tp: 1.3216 ok
2012.03.15 22:16:37    liudas001 EURUSD,H1: A TP: 0.01100000
2012.03.15 22:16:37    liudas001 EURUSD,H1: A LOT: 0.01000000
2012.03.15 22:16:37    liudas001 EURUSD,H1: Order Modify Succesfull !
2012.03.15 22:16:37    liudas001 EURUSD,H1: modify #4021061 sell 0.01 EURUSD at 1.3086 sl: 1.3106 tp: 1.2986 ok
2012.03.15 22:16:36    liudas001 EURUSD,H1: open #4021061 sell 0.01 EURUSD at 1.3086 ok
2012.03.15 22:16:36    liudas001 EURUSD,H1: A TP: 0.01000000
2012.03.15 22:16:36    liudas001 EURUSD,H1: A LOT: 0.01000000
2012.03.15 22:16:36    liudas001 EURUSD,H1: open #4021060 sell stop 0.01 EURUSD at 1.3066 sl: 1.3090 tp: 1.2966 ok
2012.03.15 22:16:36    liudas001 EURUSD,H1: A TP: 0.01000000
2012.03.15 22:16:36    liudas001 EURUSD,H1: A LOT: 0.01000000
2012.03.15 22:16:36    liudas001 EURUSD,H1: Order Modify Succesfull !
2012.03.15 22:16:36    liudas001 EURUSD,H1: modify #4021059 buy 0.01 EURUSD at 1.3089 sl: 1.3066 tp: 1.3189 ok
2012.03.15 22:16:35    liudas001 EURUSD,H1: open #4021059 buy 0.01 EURUSD at 1.3089 ok
2012.03.15 22:16:33    liudas001 EURUSD,H1: A TP: 0.01000000
2012.03.15 22:16:33    liudas001 EURUSD,H1: A LOT: 0.01000000
2012.03.15 22:16:10    liudas001 EURUSD,H1: initialized

A TP: 0.01000000  and  A LOT: 0.01000000  is Print() of Lot and TakeProfit values, which are read from file, and put to double array. It works just fine. (As I use Easy-Forex, I have to modify life orders)

Now, if I use Expert on Tester it prints:

2012.03.15 22:42:59    2012.02.29 12:42  liudas001 GBPUSD,H1: OrderSend error 4051
2012.03.15 22:42:59    2012.02.29 12:42  liudas001 GBPUSD,H1: invalid lots amount for OrderSend function
2012.03.15 22:42:59    2012.02.29 12:42  liudas001 GBPUSD,H1: A TP: 0.00000000
2012.03.15 22:42:59    2012.02.29 12:42  liudas001 GBPUSD,H1: A LOT: 0.00000000

Meaning, that on Tester, values become 0.0 for some unknow reason for me, and SendOrder() just fails.

Any thoughts, why it works on live market, but not on test ?

Thanks,

Giedrius

Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
Trade Functions / OrderSend - Documentation on MQL5
 

It's hard to guess the problem if there is no code to see.
 

Hello,

   yes, here is the code, I read CSV content inside init() function, by using the functions bellow:

// arrays for Lot and TakeProfit values
double LotsArray[1000];
double TakeProfitArray[1000];

// now comes 2 functions for reading data from files, it is separete for now, as I am still testing them, but they can be easily be combined into one

// read CSV file, fill data to double array
void ReadCSVFileTakeProfit() {
   
   int handle;
   handle=FileOpen(TakeProfitFileName ,FILE_CSV|FILE_READ, ';');
      
   if(handle > 0) {
      for (int c=0; !FileIsEnding(handle) && c<1000; c++) {
         double tempValue = 0.0;
         tempValue = StrToDouble(FileReadString(handle));
         TakeProfitArray[c] = tempValue * Point;
         if (FileIsEnding(handle)) break;
      }
      FileClose(handle);
   } else {
      Print("ERROR. File not found.");
   }
}

// read CSV file, fill data to double array
void ReadCSVFileLot() {
   
   int handle;
   handle=FileOpen(LotFileName ,FILE_CSV|FILE_READ, ';');
      
   if(handle > 0) {
      for (int c=0; !FileIsEnding(handle) && c<1000; c++)  {
         double tempValue = 0.0;
         tempValue = StrToDouble(FileReadString(handle));
         LotsArray[c] = tempValue;
         if (FileIsEnding(handle)) break;
      }
      FileClose(handle);
   } else {
      Print("ERROR. File not found.");
   }
}

// now the actual OrderSend

thisStepLots = LotsArray[StepNumber];
thisStepTP = TakeProfitArray[StepNumber];
Print("A LOT: " + thisStepLots);
Print("A TP: " + thisStepTP);
buyPrice = Ask;
         
int ticket001 = OrderSend(Symbol(), OP_BUY, thisStepLots, buyPrice, Slippage, 0, 0, "ID: " + Expert_ID + " Step: " + (StepNumber+1), Expert_ID, 0, Yellow);

if(ticket001 > 0) {
  if(OrderSelect(ticket001, SELECT_BY_TICKET)==true) {               
     bool status1 = OrderModify(ticket001, OrderOpenPrice(), Line01L, OrderOpenPrice() + thisStepTP, 0, Green);
  }
}


When this Expert runs on live market (Demo account), it works just fine. Order is opened, Modify is success as well. Now, when I try to run this on Terminal Tester, it fails all the time. As "Print("A LOT: " + thisStepLots);" and "Print("A TP: " + thisStepTP);" prints "A TP: 0.00000000" and "A LOT: 0.00000000"

Any insights ?
 

Hi,

Do you place the csv file correctly inside the strategy tester folder? You should already know that strategy tester has different file folder location to the normal trading mode. Please confirm it.

Regards,

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
Reason: