'How do I get Buy orders into an array in mql4?
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?
`void OnTick()
{
double BuyOpenPriceArray[];
int BuyTicketNumberArray[];
int NumberOfBuyOrders=OrderTypeCounter(1);
int NumberOfSellOrders=OrderTypeCounter(2);
if((Open[1]<Close[1]) && OrdersTotal()==6) //Opens 4 orders (For OrdersTotal()== 0 to 3)
{
EnterTrade(OP_SELL, LotSize, clrDarkKhaki, magic);
}
if((Open[1]>Close[1]) && OrdersTotal()==5)
{
EnterTrade(OP_SELL, LotSize, clrDarkKhaki, magic);
}
if((Open[1]<Close[1]) && OrdersTotal()==4) //Opens 4 orders (For OrdersTotal()== 0 to 3)
{
EnterTrade(OP_BUY, LotSize, clrAqua, magic);
}
if((Open[1]>Close[1]) && OrdersTotal()==3)
{
EnterTrade(OP_BUY, LotSize, clrAqua, magic);
}
if((Open[1]<Close[1]) && OrdersTotal()==2) //Opens 4 orders (For OrdersTotal()== 0 to 3)
{
EnterTrade(OP_SELL, LotSize, clrDarkKhaki, magic);
}
if((Open[1]>Close[1]) && OrdersTotal()==1)
{
EnterTrade(OP_SELL, LotSize, clrDarkKhaki, magic);
}
if((Open[1]<Close[1]) && OrdersTotal()==0) //Opens 4 orders (For OrdersTotal()== 0 to 3)
{
EnterTrade(OP_BUY, LotSize, clrAqua, magic);
}
//------
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
{
for(int j=NumberOfBuyOrders-1;j>=0;j++)
{
ArrayResize(BuyOpenPriceArray,NumberOfBuyOrders+1);
BuyOpenPriceArray[j]=OrderOpenPrice();
Print("j is: ",j, "BuyOpenPriceArray[j]: ", BuyOpenPriceArray[j]);
break;
}
}
}
}
}
}
`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
