To count the number of open BUY and SELL orders in MT4, you can use the OrdersTotal() function to get the total number of current orders. Then, loop through each order and check its type to count how many are BUY or SELL.
Here is a simple example:
int Totalorder(string type) { int i=0; for(int a=0; a<=OrdersTotal(); a++)//> { if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY && type== "OP_BUY") { i++; } if(OrderType()==OP_SELL && type== "OP_SELL") { i++; } } } return i; } [sourcecode language="R"] Comment("\n\nSo lenh Buy: ", Totalorder("OP_BUY"),"\nSo lenh Sell: ", Totalorder("OP_SELL"));
In this example, we use a for loop to iterate through each order. In each iteration, the OrderSelect() function selects the order at position a (using SELECT_BY_POS), and checks whether the selection is successful. If successful, we use the OrderType() function to determine the type of the order and increment the corresponding counter.
After looping through all orders, we use the Comment() function to print out the number of open Buy and Sell orders.
If anything is unclear or if you have questions, feel free to leave a comment below. BDOFOREX will do our best to answer everything we know to help you.