Cant get OrdersOpenPrice()

 
for(i = 1; i<=OrdersTotal(); i++)
      {
         bool ref = OrderSelect(i,SELECT_BY_POS);//,MODE_TRADES);
         buy_trade[i-1] = OrderOpenPrice();
         Print("b of i=",buy_trade[i-1]);

      }

I used above code to get all open prices in an array. But all I got was zero stored in that array. 

Anyone can help me? Thanks in advance. 

Note: I had 10 open trades in the terminal.

2013.06.10 15:12:21 array_Sroting_test GBPUSD,H1: b of i=0

 
krishna_gopal_2:

I used above code to get all open prices in an array. But all I got was zero stored in that array. 

Anyone can help me? Thanks in advance. 

Note: I had 10 open trades in the terminal.

2013.06.10 15:12:21 array_Sroting_test GBPUSD,H1: b of i=0

Your loop is wrong, why are you starting from 1 ?  the first position in the Order Pool is 0  the last is OrdersTotal() - 1  so if you have 4 orders their position are;  0, 1, 2, 3

Read this for more info:   Loops and Closing or Deleting Orders

 
RaptorUK:

Your loop is wrong, why are you starting from 1 ?  the first position in the Order Pool is 0  the last is OrdersTotal() - 1  so if you have 4 orders their position are;  0, 1, 2, 3

Read this for more info:   Loops and Closing or Deleting Orders


2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: Array_Size = 4
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 3 = 0
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 2 = 0
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 1 = 0
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 0 = 0

int array_size = OrdersTotal();
   Print("Array_Size = ",array_size);
   for(i = 0; i<OrdersTotal(); i++)
      {
         bool ref = OrderSelect(i,SELECT_BY_POS);
         buy_trade[i] = OrderOpenPrice();
         Print("b of ",i," = ",buy_trade[i]);
      }

 Still same 0's.


 
krishna_gopal_2:

2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: Array_Size = 4
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 3 = 0
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 2 = 0
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 1 = 0
2013.06.10 16:55:41 array_Sroting_test GBPUSD,M5: b of 0 = 0

 Still same 0's.


Show your line of code where you declared the array  buy_trade[]
 
RaptorUK:
Show your line of code where you declared the array  buy_trade[]


double buy_trade[];
double next_buy;
int init(){return(0);}
int deinit(){return(0);}
int start()
  {
//----
   int i, j = 0;
   double temp;
   int array_size = OrdersTotal();
   Print("Array_Size = ",array_size);
   for(i = 0; i<OrdersTotal(); i++)
      {
         bool ref = OrderSelect(i,SELECT_BY_POS);//,MODE_TRADES);
         buy_trade[i] = OrderOpenPrice();
         Print("b of ",i," = ",buy_trade[i]);
      }

      for (i = 0; i < (array_size - 1); i++)
      {
            for (j = 0; j < array_size - 1 - i; j++ )
            {
               if (buy_trade[j] > buy_trade[j+1])
                  {
                     temp = buy_trade[j+1];
                     buy_trade[j+1] = buy_trade[j];
                     buy_trade[j] = temp;
                  }
            }
      }
      Print("Sorted Array is \n");
      for(i = 0; i<OrdersTotal(); i++)
      {
         bool ref = OrderSelect(i,SELECT_BY_POS);//,MODE_TRADES);
         buy_trade[i] = OrderOpenPrice();
         Print("b of ",i," = ",buy_trade[i]);
      }
   return(0);
  }
 
double buy_trade[];
So how big is the array?
 
krishna_gopal_2:


Your array has a size of zero elements . . .  

double buy_trade[];

 

 this one has a size of 10 elements

double buy_trade[10];

 

 this one is resized to 20 elements . . .

double buy_trade[];

ArrayResize(buy_trade, 20);

 

Why do even need the array . . .  keep your test code simple . . . 

   for(i = 0; i<OrdersTotal(); i++)
      {
      if(OrderSelect(i,SELECT_BY_POS))
         Print("b of ",i," = ", OrderOpenPrice());
      }
 
RaptorUK:

Why do even need the array . . .  keep your test code simple . . . 

 


I am trying to sort the array in an ascending order. And I did it.

 
krishna_gopal_2:


I am trying to sort the array in an ascending order. And I did it.

After spending so much time in sorting an array and done it, I found the function ArraySort().

What a waste of time!

https://docs.mql4.com/array/ArraySort

Reason: