Counting buy and sell orders of History and put into comment

 

Hi,

i tried to count buy and sell orders of History of an magic number.

I tried this out but it seems that it is not working well.


int count_order()
  {
   int count=OrdersHistoryTotal();
   for(int i=0;i<count;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)
        {
         if(OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic_Number)
           {
            count=count+1;
            //count++;
           }
        }
     }
   return(count);
  }

in the ontick function i add this.

           Comment("Buy Trades: ",count_order());  

It looks like it is counting all of the history. With open and close.

 
int count_order()
  {
   int count=0;
   int total=OrdersHistoryTotal();
   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)
        {
         if(OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic_Number)
           {
            count++;
           }
        }
     }
   return(count);
  }
 
Keith Watford:

Now its counting ALL BUY AND SELL. I want only get the BUY Orders and only SELL ORDERS

 
Raphael Schwietering:

Now its counting ALL BUY AND SELL. I want only get the BUY Orders and only SELL ORDERS

Wow! Then add an additional check for either buy or sell orders and count them. Use either Global variables or pass variables to the function.

 
Keith Watford:

Wow! Then add an additional check for either buy or sell orders and count them. Use either Global variables or pass variables to the function.

thanks now i have working it.

can you help me out how to get the profit of closed trades?i think there must be small changes

Reason: