ArraySetAsSeries() warning

 

I have a code and its working but it gives me warning and its too annoying. here is my code:

string Symbols[] = {"EURUSD","EURJPY","GBPUSD"};

ArraySetAsSeries(Symbols,true);
   
int size = ArraySize(Symbols);
   
for(int i=0;i<size;i++)     
{    
Alert(Symbols[i]);
}

this is the warning : "cannot be used for static allocated array"

how can I fix that? give me a simple code example. thanks

 
Elsa Hejazian: I have a code and its working but it gives me warning and its too annoying. here is my code: this is the warning : "cannot be used for static allocated array" how can I fix that? give me a simple code example. thanks

Just as the warning says ... it cannot be used on statically allocated arrays, So, use a dynamic array instead.

string Symbols[];

ArraySetAsSeries( Symbols, true );
ArrayResize( Symbols, 3 );

Symbols[0] = "EURUSD";
Symbols[1] = "EURJPY";
Symbols[2] = "GBPUSD";

However, why do you even want to set it as series type, when its not even going to be used for time-series data anyway?

Just leave it as a normal array and continue to use it as such.

 

I want to trade 28 pair currency pairs and I need to loop through these pairs like this:

for(int i=0;i<size;i++)     
{  
// do some things
CopyRates(Symbols[i],PERIOD_CURRENT,1,1,rates);
// do more thins
}

so I need to get symbol names as string  in a loop like this: Symbols[i] 

 
Elsa Hejazian: I want to trade 28 pair currency pairs and I need to loop through these pairs like this: so I need to get symbol names as string  in a loop like this: Symbols[i] 

You don't need to set it as a series to loop through the elements. Setting it as a series is for "special" use only like when working with indicator buffers or other types of time-series data where you want to index the most recent data from index 0.

It is not needed at all for normal standard array usage. Please don't confuse things for yourself. Leave the array as is, and don't try to set it as a series if it is not needed.

 
Right. Can you give a simple example code that loop through from currency pairs? I can't find any idea to do that except using series. somehow indexing the array or another idea.
 
Elsa Hejazian: Right. Can you give a simple example code that loop through from currency pairs? I can't find any idea to do that except using series. somehow indexing the array or another idea.

Why? You are already doing the loop correctly! Your own example is just fine. Just don't set the array as a series. That is all!

string Symbols[] = {"EURUSD","EURJPY","GBPUSD"};

// ArraySetAsSeries(Symbols,true); <-- Don't use this'
  
int size = ArraySize(Symbols);

for(int i=0;i<size;i++)     
{    
   // do some things
   int CopyCount = CopyRates(Symbols[i],PERIOD_CURRENT,1,1,rates);
   // do more thins
}
 
Elsa Hejazian: . Can you give a simple example code that loop through from currency pairs? I can't find any idea to do that except using series. somehow indexing the array or another idea.

You have the code in your original post. Just stop calling AsSeries.