Function for Correlated pair filter

 

Hi ,

      I am trying to get a  confirmation filter for the correlated pairs with the Array. It is not taking the array . can you help debugging it?


Example shows that I am looping through the correlated pairs and get a confirmation on their respective charts.

bool Positive_Correlated()
{
string AUDCAD_SP[] = {"AUDSGD","AUDUSD","NZDUSD"};
string ArraySymbol = Symbol()+ "_SP";

int ArrayLength = ArraySize(ArraySymbol[]);
bool result;

for(int i=0; i<ArrayLength; i++ )
{
    double MA140_current_1H = iMA(ArraySymbol[i],PERIOD_H1,140,0,MODE_EMA,PRICE_CLOSE,1);
    double MA80_current_1H = iMA(ArraySymbol[i],PERIOD_H1,80,0,MODE_EMA,PRICE_CLOSE,1);
    
    if(MA80_current_1H < MA140_current_1H)
    {
     result = true;
    }
    else
    {
   result = false;
    }    
}
 }
 
aroonzackie: Hi, I am trying to get a  confirmation filter for the correlated pairs with the Array. It is not taking the array . can you help debugging it? Example shows that I am looping through the correlated pairs and get a confirmation on their respective charts.

You are confusing arrays and strings.

string AUDCAD_SP[] = {"AUDSGD","AUDUSD","NZDUSD"};   // This is an array of 3 strings
string ArraySymbol = Symbol()+ "_SP";                // This is a single string (not an array)

Example, current symbol is "EURUSD", then the following

string ArraySymbol = Symbol()+ "_SP"; // Result: ArraySymbol = "EURUSD_SP"

This is because "ArraySymbol" is declared as a single string and not as an array.

 

Hi, 

     I got this. Thanks. Is there an any other way to do this and get the same input from array? 

     I thought about it and couldn't get any leads.

      

 
aroonzackie #:  I got this. Thanks. Is there an any other way to do this and get the same input from array?  I thought about it and couldn't get any leads.

      

It's not quite clear what you are trying to do so this is just a sample of how to iterate through an array of symbols ...

bool Positive_Correlated()
{
   string sSymbols[] = { "AUDSGD", "AUDUSD", "NZDUSD" };
   int    nSymbols   = ArraySize( sSymbols ),
          nCount     = 0;

   for( int i = 0; i < nSymbols; i++ )
   {
      double
         dbMA140 = iMA( sSymbols[ i ], PERIOD_H1, 140, 0, MODE_EMA, PRICE_CLOSE, 1 ),
         dbMA80  = iMA( sSymbols[ i ], PERIOD_H1,  80, 0, MODE_EMA, PRICE_CLOSE, 1 );
       
      if( dbMA80 < dbMA140 ) nCount++;
   };
   
   return nCount == nSymbols;
};
Reason: