OrdersTotal() question

 
I am creating an expert that uses OrdersTotal()==0 to signal new positions. If a position is already opened this function should return 1 right?

Here is a script I created to test the OrdersTotal() function:


//Script Tester

//Copyright © 2005 Sergey T.

extern double lots = 1;

extern double stoploss = 10;

extern int i = 0;

int start()

{

int ticket;

int totalhist=HistoryTotal();

int totalorders=OrdersTotal();

if(i<1)

{

Print("Expert Initiated, Open Orders=",totalorders);

i++;

}

 

if(totalhist==0)

{

if(totalorders==0)

     {

     ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,0,0,"Initial Buy",1,0,Green);

     Print("Buy Order placed, Open Orders=",totalorders); 

     }

}

 

return(0);

}





During testing after the buy position has been opened, the totalorders function still returns 0! Is there something I'm missing here?

 

During testing after the buy position has been opened, the totalorders function still returns 0!

What totalorders function?
 
int totalorders=OrdersTotal();
 
I used your script above and it is working for me, but I'm also still using the old Build 186.

(I can't believe there are multiple builds of the same number).
 
int totalorders=OrdersTotal();


totalorders is a variable which stores the value returned by OrderTotal().
I guess that the variable is assigned with 0 just once when the counter is zero. The code above gives no other chance to change it.
More than that the code has a condition that makes sure that the value of totalorders is printed only if either the variable or the counter (which assures that totalorders is 0 too) is equal to 0.
 
when the variable is instantiated, it is initialized to whatever OrdersTotal() returns. The counter has nothing to do with it since totalorders is initialized outside the if statement. The counter does not assume totalorders is 0. I don't know why that counter was even used, but it doesn't effect the totalorders variable. The only thing affected is the Print() function.

If the value returned is 0 when there is in fact an open order, than there is a problem. But when I run this code, it correctly returns the proper number of orders. But, like I said, I have the old Build 186.
 
when the variable is instantiated, it is initialized to whatever OrdersTotal() returns. The counter has nothing to do with it since totalorders is initialized outside the if statement. The counter does not assume totalorders is 0. I don't know why that counter was even used, but it doesn't effect the totalorders variable. The only thing affected is the Print() function.

Correct!
Print outputs totalorders if it's 0 only.
Reason: