How to Coding in order to count

314

Hi all

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

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++)
{
//      if(OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell)
if(OrderType() == OP_BUY || OrderType() == OP_SELL)
{
if(pair != OrderSymbol())
{
pair = OrderSymbol();
numords++;
}

}
}
return(numords);
}```
6122

Suttisak Boonla:

Hi all

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

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);
}```
6122

count each pair.

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

15917

 Mohamad Zulhairi Baba: I think it return the same result anyway.. maybe count by magic number for OrderSymbol()? Think again. There is no maybe.```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. Mohamad Zulhairi Baba (Hairi)'s post showed how to count a specific pair except it only counts open orders.
Moderator
10651

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++)
{
//      if(OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell)
{
pair=OrderSymbol();
for(int x=0;x<as;x++)
if(pair==symb[x])
{
ArrayResize(symb,as+1);
symb[as]=pair;
as++;
}
}
}
return(numords);
}

314

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++)
{
//      if(OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell)
{
pair=OrderSymbol();
for(int x=0;x<as;x++)
if(pair==symb[x])
{
ArrayResize(symb,as+1);
symb[as]=pair;
as++;
}
}
}
return(numords);
}

Thak you very much.

911

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)