//+------------------------------------------------------------------+
//|                                         Correlation^%change2.mq4 |
//|                                                         Schmurex |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Schmurex"
#property link      ""


#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
#property indicator_color3 Coral
#property indicator_color4 DarkKhaki
#property indicator_color5 Magenta
#property indicator_color6 Turquoise
#property indicator_color7 LightSalmon
#property indicator_color8 Khaki


#property indicator_separate_window

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];


extern int barcount = 1000;
extern int BCNT = 48;
extern string pair1 = "GBPUSD";
extern string pair2 = "EURUSD";
extern string pair3 = "AUDUSD";
extern string pair4 = "NZDUSD";
extern string pair5 = "GBPJPY";
extern string pair6 = "EURJPY";
extern string pair7 = "AUDJPY";
extern string pair8 = "NZDJPY";
extern string totalXXXUSD = "totalXXXUSD";
extern string totalXXXJPY = "totalXXXJPY";
extern string TOTAL8PAIRS = "TOTAL8PAIRS";

extern bool sum = false;

extern bool pip = false;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
      SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
      SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
      SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
      SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
      SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,ExtMapBuffer5);
      SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,ExtMapBuffer6);
      SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,ExtMapBuffer7);
      SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,ExtMapBuffer8);   
      SetIndexStyle(8,DRAW_LINE);
  
  if (sum==true)
  {SetIndexLabel(0,totalXXXUSD);
  SetIndexLabel(1,totalXXXJPY); 
  SetIndexLabel(4,TOTAL8PAIRS);}
  else    
   {SetIndexLabel(0,pair1);
   SetIndexLabel(1,pair2);
   SetIndexLabel(2,pair3);
   SetIndexLabel(3,pair4);
   SetIndexLabel(4,pair5);
   SetIndexLabel(5,pair6); 
   SetIndexLabel(6,pair7);
   SetIndexLabel(7,pair8);}
   
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(),
   limit ;
   
   if(counted_bars>0)
   counted_bars--;
      
   
   limit=Bars-counted_bars;
   
   if(limit>barcount)
      limit=barcount;
  
   for(int i=limit-1; i>=0; i--)
    
     {

double Close1, Close_1, Result1, Close2, Close_2, Result2, Close3, Close_3, Result3, 
       Close4, Close_4, Result4, Close5, Close_5, Result5, Close6, Close_6, Result6,
       Close7, Close_7, Result7, Close8, Close_8, Result8, Close9, Close_9, Result9,
       total1, total2, total3, total4 ;



//---- Pairs ;

Close1 = iClose(pair1,0,i);
Close_1 = iClose(pair1,0,i+BCNT);

Close2 = iClose(pair2,0,i);
Close_2 = iClose(pair2,0,i+BCNT);

Close3 = iClose(pair3,0,i);
Close_3 = iClose(pair3,0,i+BCNT);

Close4 = iClose(pair4,0,i);
Close_4 = iClose(pair4,0,i+BCNT);

Close5 = iClose(pair5,0,i);
Close_5 = iClose(pair5,0,i+BCNT);

Close6 = iClose(pair6,0,i);
Close_6 = iClose(pair6,0,i+BCNT);

Close7 = iClose(pair7,0,i);
Close_7 = iClose(pair7,0,i+BCNT);

Close8 = iClose(pair8,0,i);
Close_8 = iClose(pair8,0,i+BCNT);


//---- Pairs END;




if (pip==true)
{
Result1 = Close1 - Close_1;
Result2 = Close2 - Close_2;
Result3 = Close3 - Close_3;
Result4 = Close4 - Close_4;
Result5 = (Close5 - Close_5)/100;
Result6 = (Close6 - Close_6)/100;
Result7 = (Close7 - Close_7)/100;
Result8 = (Close8 - Close_8)/100;

}
else
{
Result1 = (Close1 - Close_1)/Close1;
Result2 = (Close2 - Close_2)/Close2;
Result3 = (Close3 - Close_3)/Close3;
Result4 = (Close4 - Close_4)/Close4;
Result5 = (Close5 - Close_5)/Close5;
Result6 = (Close6 - Close_6)/Close6;
Result7 = (Close7 - Close_7)/Close7;
Result8 = (Close8 - Close_8)/Close8;

}
if (sum == true)
{
total1 = Result1 + Result2 + Result3 + Result4;
total2 = Result5 + Result6 + Result7 + Result8 ;
total3 = Result1 + Result2 + Result3 + Result4 + Result5 + Result6 + Result7 + Result8 ;
ExtMapBuffer1[i] = total1;
ExtMapBuffer2[i] = total2;
ExtMapBuffer5[i] = total3;
}
else
{
ExtMapBuffer1[i] = Result1;
ExtMapBuffer2[i] = Result2;
ExtMapBuffer3[i] = Result3;
ExtMapBuffer4[i] = Result4;
ExtMapBuffer5[i] = Result5;
ExtMapBuffer6[i] = Result6;
ExtMapBuffer7[i] = Result7;
ExtMapBuffer8[i] = Result8;
}

}
 return(0);
  }
  
//+------------------------------------------------------------------+