# How to count positions of symbol(s)

Hi everyone, I'm designing a Multi-Symbol EA

and I tried to count every position of each symbol

method of symbol splitting

```input string TradeSymbols = "EURUSD,GBPJPY,AUDNZD,CADCHF";
string SymbolArray [];
int         SymbolsNo; // Number of Symbols

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

if (_Digits==4 || _Digits<=2) MyPoint=_Point;
if (_Digits==3 || _Digits==5) MyPoint=_Point*10;
return(INIT_SUCCEEDED);
}
```

To count buy positions of each symbol

```int Buys()
{
int B=0,i,j;
for ( i=0; i<PositionsTotal();  i++)
{
if
(

SymbolArray[j]  == PositionGetSymbol(i)
&& MagicNumber==PositionGetInteger(POSITION_MAGIC)
)

{ B++;}
}
return(B);
}```

I wanted to use the same variable (j) on my conditions in OnTick

```void OnTick()
{
for (int j=0; j<SymbolsNo; j++)
{
............conditions & functions of (j)'s
}
}```

Where's my mistake?

```int Buys(const string& symbol)
{
int B=0,i;
for ( i=0; i<PositionsTotal();  i++)
{
if ( symbol  == PositionGetSymbol(i)
&& MagicNumber==PositionGetInteger(POSITION_MAGIC)
{ B++; }
}
return(B);
}
```

or

```int Buys(int index)
{
int B=0,i;
for ( i=0; i<PositionsTotal();  i++)
{
if ( SymbolArray[index]  == PositionGetSymbol(i)
&& MagicNumber==PositionGetInteger(POSITION_MAGIC)
{ B++; }
}
return(B);
}```

Ernst Van Der Merwe #:

or

Thank you so much

the second cod is easier

I'm so glad for you help 💜

Reason: