Download MetaTrader 5

How to Coding in order to count

To add comments, please log in or register
Suttisak Boonla
314
Suttisak Boonla  

Hi all

I have question about how to coding in order to count OrderSymbol()

I open trade 

buy  USDJPY ,EURUSD ,AUDUSD

sell  USDJPY ,AUDJPY ,USDCHF

I want EA to count only 5 pairs but my EA count 6 pair.

if that same pair just count 1.

Please kindly help I don't know what to do.


This my code.

int Count_Pair()
{   
   int total = OrdersTotal();
   int numords = 0;
    string pair;
   for(int cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);            
//      if(OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell)  
      if(OrderType() == OP_BUY || OrderType() == OP_SELL)
      {       
               if(pair != OrderSymbol())
               {
               pair = OrderSymbol();
               numords++;
               }


      
      }
   }   
   return(numords);
}
Mohamad Zulhairi Baba
6122
Mohamad Zulhairi Baba  
Suttisak Boonla:

Hi all

I have question about how to coding in order to count OrderSymbol()

I open trade 

buy  USDJPY ,EURUSD ,AUDUSD

sell  USDJPY ,AUDJPY ,USDCHF

I want EA to count only 5 pairs but my EA count 6 pair.

if that same pair just count 1.

Please kindly help I don't know what to do.


This my code.


count each pair.

int CountPair(string pair)
{   
   int count = 0;
   
   for(int cnt=0; cnt<OrdersTotal()-1; cnt++) 
   {        
      bool select = OrderSelect(cnt, SELECT_BY_POS);             
      if(select && (OrderType() == OP_BUY || OrderType() == OP_SELL) && pair==OrderSymbol()) count++; 
   }   
   return(count);
}
Mohamad Zulhairi Baba
6122
Mohamad Zulhairi Baba  
Mohamad Zulhairi Baba:


count each pair.


I think it return the same result anyway.. maybe count by magic number for OrderSymbol()?

whroeder1
15917
whroeder1  
Mohamad Zulhairi Baba: I think it return the same result anyway.. maybe count by magic number for OrderSymbol()?

Think again. There is no maybe.
  1. if(pair != OrderSymbol()){
       pair = OrderSymbol();
       numords++;
    }
    
    Pair is undefined. So it looks for any symbol and counts it, and earlier orders not the same. Bogus.
  2. Mohamad Zulhairi Baba (Hairi)'s post showed how to count a specific pair except it only counts open orders.
Keith Watford
Moderator
10651
Keith Watford  

Not compiled or tested, just quickly thrown together.

It may give you some ideas


int Count_Pair()
  {
   int total=OrdersTotal();
   int numords=0;
   string pair;
   string symb[];
   int as=0;
   for(int cnt=0; cnt<total; cnt++)
     {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      //      if(OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell)  
      if(OrderType()==OP_BUY || OrderType()==OP_SELL)
        {
         int count_add=1;
         pair=OrderSymbol();
         for(int x=0;x<as;x++)
            if(pair==symb[x])
               count_add=0;
         if(count_add==1)
           {
            ArrayResize(symb,as+1);
            symb[as]=pair;
            as++;
            numords+=count_add;
           }
        }
     }
   return(numords);
  }



Suttisak Boonla
314
Suttisak Boonla  
Keith Watford:

Not compiled or tested, just quickly thrown together.

It may give you some ideas


int Count_Pair()
  {
   int total=OrdersTotal();
   int numords=0;
   string pair;
   string symb[];
   int as=0;
   for(int cnt=0; cnt<total; cnt++)
     {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      //      if(OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell)  
      if(OrderType()==OP_BUY || OrderType()==OP_SELL)
        {
         int count_add=1;
         pair=OrderSymbol();
         for(int x=0;x<as;x++)
            if(pair==symb[x])
               count_add=0;
         if(count_add==1)
           {
            ArrayResize(symb,as+1);
            symb[as]=pair;
            as++;
            numords+=count_add;
           }
        }
     }
   return(numords);
  }




Thak you very much.

nicholishen
911
nicholishen  

Here is a simplified solution.

#include <Arrays\ArrayString.mqh>
int SymbolCount()
{
   CArrayString symbols;
   for(int i=0;i<OrdersTotal();i++)
      if(OrderSelect(i,SELECT_BY_POS) && (OrderType() == OP_BUY || OrderType() == OP_SELL))
         if(symbols.Search(OrderSymbol())<0)
            symbols.Add(OrderSymbol());
   return symbols.Total();
}
To add comments, please log in or register