OrdersTotal() function in Strategy Tester

 

Good evening.

In my first EA I used the OrdersTotal() function to check whether there are open orders or not:


if(OrdersTotal()==0) DoTrade = 1;

if(DoTrade == 1 && (TipoOperazione==OP_BUY || TipoOperazione==OP_SELL))
{

[code to open 1 order]

}


But when testing it I found out that after the first order is closed OrdersTotal() still returns 1 and no more orders are sent, as you can see in the attached pics.








It looks like I solved the problem substituing the original OrdersTotal() function with this one:


int OpenOrdersNumber()
{
int number = 0;
for(int i = 0; i<OrdersTotal();i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==false) break;
if(OrderCloseTime() == 0) number++;
}

return(number);
}


But is it right OrdersTotal() counts also closed orders?

 
michelesmiderle wrote >>

Good evening.

In my first EA I used the OrdersTotal() function to check whether there are open orders or not:

if(OrdersTotal()==0) DoTrade = 1;

if(DoTrade == 1 && (TipoOperazione==OP_BUY || TipoOperazione==OP_SELL))
{

[code to open 1 order]

}

But when testing it I found out that after the first order is closed OrdersTotal() still returns 1 and no more orders are sent, as you can see in the attached pics.

It looks like I solved the problem substituing the original OrdersTotal() function with this one:

int OpenOrdersNumber()
{
int number = 0;
for(int i = 0; i<OrdersTotal();i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==false) break;
if(OrderCloseTime() == 0) number++;
}

return(number);
}

But is it right OrdersTotal() counts also closed orders?

your solution also include OrdersTotal() !

But is it right OrdersTotal() counts also closed orders?

No. Returns market and pending orders count.

It's OrderHistoryTotal().

 
Matutin:

your solution also include OrdersTotal() !

But is it right OrdersTotal() counts also closed orders?

No. Returns market and pending orders count.

It's OrderHistoryTotal().

Includes OrdersTotal(), but I also check that close time is different from 0. Otherwise, as you can see in the pictures, OrdersTotal() returns 1 even when there are no open orders.

So, if as i thought it is not right that OrdersTotal() counts closed orders, what problem is it? And how can I solve it?

Note that when used live, OrdersTotal() works fine: it returns ONLY the number of open orders. It's only in Strategy Tester that I get this problem.

 
Are you returning from start?
 
WHRoeder:
Are you returning from start?

Yes. The start() function is called and stopped correctly: in fact, the first order is opened.

Data analysis is also carried on correctly (in a test I printed iStochastic values to check).