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
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
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.
Still same 0's.
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?
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()); }
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.
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!
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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