Only one trade per symbol

 
guys i have this code that calculates the total no of trades online for the current symbol. Somehow it only works when z == 0. If z>0 then the code does not stop and it continues to run.

void OnTick() 

   
   {  int total,z,j;
   
  
   total = OrdersTotal();
  
   for(j=0;j<total;j++)

   { 
   OrderSelect(j,SELECT_BY_POS, MODE_TRADES);
   if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magicnumber)
   z++;
   
   } 
  if(z == 0){
   Print(" order count is ", OrdersTotal());
    return ;}

// my code here //

   
 
Use the </> code button to insert your code.
 
sk123:
guys i have this code that calculates the total no of trades online for the current symbol. Somehow it only works when z == 0. If z>0 then the code does not stop and it continues to run.

// my code here //

   
void OnTick() 

   
   {  int total,z,j;
   
  
   total = OrdersTotal();
  
   for(j=0;j<total;j++)

   { 
   OrderSelect(j,SELECT_BY_POS, MODE_TRADES);
   if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magicnumber)
   z++;
   
   } 
  if(z == 0){
   Print(" order count is ", OrdersTotal());
    return ;}

Do not forget to check the returned value from OrderSelect(), what happens if it fails?

Currently, if(z != 0), this program will output nothing and just run.
And if(z == 0), it will print OrdersTotal(), which is not filtered by Symbols.

If you want this to Print the Order Count, Print your Variable "z" without any if conditions.
Do not forget to Typecast the integer "z" when you print it.

 
  1. Initialize z to zero before the loop.
  2. sk123: . If z>0 then the code does not stop and it continues to run.
    That is what you coded it to do. You only stop if z is zero.