for(int j=NumberOfBuyOrders-1;j>=0;j++) { ArrayResize(BuyOpenPriceArray,NumberOfBuyOrders+1); BuyOpenPriceArray[j]=OrderOpenPrice();
You are storing the current selected order into all array elements.
Drop your loop. Enlarge the array and store once.
You are storing the current selected order into all array elements.
Drop your loop. Enlarge the array and store once.
Thank you for answering. I am a complete newbie.
By enlarging the array, you mean "ArrayResize", which I already did?
And for some reason, if I get rid of the "j" loop, the NumberOfBuyOrders function shows 0. With the loop, the NumberOfBuyOrders works as it should.
It seems I need to take a closer look at that function.
If you can give me a little code snippet to fix exactly how to fix it, I will greatly appreciate it. But I will take a closer look and post back later. It took me more than 36 hours of tinkering... before I posted here. But I will keep trying.
I just modified the code to get rid of the "j" Loop.
And I managed to fix the NumberOfBuyOrders Problem.
But, only j = 3 (BuyOpenPriceArray[3]) is filled with OpenPrices. None others are filled with prices.
Here's the revised code, please help:
for(int i=0;i<=OrdersTotal()-1;i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()==magic) { if(OrderType()==OP_BUY) //Newest Buy order is LARGEST Open Price { int j=NumberOfBuyOrders; Print("NumberOfBuyOrders: ", NumberOfBuyOrders); Print("j value: ",j); Print("OrdersTotal: ",OrdersTotal()); ArrayResize(BuyOpenPriceArray,NumberOfBuyOrders+1); BuyOpenPriceArray[j]=OrderOpenPrice(); Print("j is: ",j, "BuyOpenPriceArray[j]: ", BuyOpenPriceArray[j]); j--; } } } }
You enlarge the array to NumberOfBuyOrders+1 and then store. Where do you increase the variable?
ArrayResize(BuyOpenPriceArray,NumberOfBuyOrders+1)
And with each iteration of the loop, more Buy orders are discovered and thus NumberOfBuyOrders+1 also increases automatically?

- 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'd like to get the buy open orders of several orders into an array (like below):
OpenPrices:
BUY: 1.62181 (ticket:1)
Sell: 1.61282 (ticket: 2)
Buy: 1.59635 (ticket: 3)
Buy: 1.63566 (Ticket: 4)
Sell: 1.62332 (Ticket: 5)
I am trying to extract the Buy Open Prices to BuyOpenPriceArray[], such that:
BuyOpenPriceArray[0]: 1.63566 (Ticket:4)
BuyOpenPriceArray[1]: 1.59635 (Ticket:3)
BuyOpenPriceArray[2]: 1.62181 (Ticket:1)
And only BuyOpenPriceArray[2] is filled with changing the three Buy OpenPrices, one after another. [0] and [1] are not filled. What did I do wrong?