Download MetaTrader 5

Help with parallel arrays

To add comments, please log in or register
tim 2014.12.31 08:11 


 After opening a specified number of limitorders using a script I am trying to close them after they are activated with OrderClose using the ticket number of the first filled order to avoid FIFO errors.  I am trying to use parallel arrays to get a valid ticket number into OrderClose.  However the: ordersTicketArr[firstInIndex] array is getting filled with a 3 digit number instead of a 9 digit ticket number and the error code is 4108.  Any help would be much appreciated.  Thank you.   

#property show_inputs
extern int orders = 0;
void OnStart()
   double ordersTicketArr[20];
   datetime ordersOpenTimeArr[20];
   int firstInIndex = 0;
   for ( int g = 0; g < orders; g++ )          // puts order tickets into ordersTicketArr      
      OrderSelect(g, SELECT_BY_POS);               // loading arrays                              
      ordersTicketArr[g]    = OrderTicket();                                                                   
      ordersOpenTimeArr[g]  = OrderOpenTime();  
   firstInIndex = ArrayMinimum(ordersOpenTimeArr, WHOLE_ARRAY, 0);
   Print(ordersOpenTimeArr[0], " " , ordersOpenTimeArr[9], " ", ordersTicketArr[firstInIndex]);
   OrderClose(ordersTicketArr[firstInIndex], 0.01, Bid, 3, CLR_NONE);
whroeder1 2014.12.31 15:47  
   for ( int g = 0; g < orders; g++ ) // puts order tickets into ordersTicketArr      
      OrderSelect(g, SELECT_BY_POS);  // loading arrays             
  1. Check your return codes (OrderSelect and OrderClose) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Not filtering by magic number and symbol makes your EA incompatible with every other EA (including itself) and manual trading. order accounting - MQL4 forum
  3. If you close an order or closed externally (SL, TP or manual) then orders is out of date.
  4. If the order is not a buy, then Bid is an invalid price. Use OrderClosePrice()
To add comments, please log in or register