Question about OrdersTotal() and OrderSelect()

 

Say I attach the same EA to two charts, EUR/USD and GBP/USD. The Start() function in each EA will be called only for the currency pair of the chart it is attached to, right? One EA will receive ticks only for EUR/USD, and the other EA will receive ticks only for GBP/USD, right? So, if that is the case, what happens when the EA attached to the EUR/USD chart calls OrdersTotal()? Will the function return the total number of orders, including both EUR/USD and GBP/USD, or will OrdersTotal() return only the number of orders for EUR/USD? Now say that same EA calls OrderSelect(0, SELECT_BY_POS, MODE_TRADES). Does that function select both EUR/USD and GBP/USD open trades, or does it select only EUR/USD trades?

If OrdersTotal() and OrderSelect() return information about all orders, regardless of the currency pair of the chart it is attached to, then I need to include code in my EA which differentiates orders as to currency pair, so as to make the EA deal only with the currency pair of the chart to which the EA is attached. Have I got that right?

 

It selects both EUR and GBP orders. You will have to use if /else statements to ensure that the selected order belongs to the symbol you want to work with.

Attached is an example where I count the number of sells that are open

int CountShorts(int Magic)

{

int count=0;

int trade;

for(trade=OrdersTotal()-1;trade>=0;trade--)

{

OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=Magic)

continue;

if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)

if(OrderType()==OP_SELL )

count++;

}//for

return(count);

}