//+------------------------------------------------------------------+
//|                                          Correlation^%change1.mq4 |
//|                                                     Schmurex
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Schmurex"
#property link      ""


#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Silver
#property indicator_color4 White
#property indicator_separate_window

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];


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 pairref = "USDJPY";

extern bool sum = false;
extern bool histogram = true;
extern int histogramtype = 1;
extern bool pip = false;
extern bool ShowPairRef = True;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
      SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
      SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
      SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);
      SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
   
   SetIndexLabel(2,histogram);
   
   SetIndexLabel(0,pair1);
   SetIndexLabel(1,pair5);
   SetIndexLabel(3,pairref); 
   
   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 1,2,3,4;

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);

//---- Pairs 1,2,3,4 END



//---- Pairs 5,6,7,8;

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 5,6,7,8 END;


//----USDJPY PAIR ----//
Close9 = iClose(pairref,0,i);
Close_9 = iClose(pairref,0,i+BCNT);
//----            ----//


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;
Result9 = (Close9 - Close_9)/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;
Result9 = (Close9 - Close_9)/Close9;
}
if (sum == true)
{
total1 = Result1 + Result2 + Result3 + Result4;
total2 = (Result5 + Result6 + Result7 + Result8) ;
total3=Result9*4;
}
else
{
total1 = Result1 ;
total2 = Result5 ;
total3 = Result9 ;
}

ExtMapBuffer1[i] = total1;
ExtMapBuffer2[i] = total2;
if (ShowPairRef == True)
ExtMapBuffer4[i] = total3 ;


if (histogram == true)
if (histogramtype==1)
total4=total2-total1;
if (histogramtype==2)
total4=total2+total1;
if (histogramtype==3)
total4=total1-total2;
ExtMapBuffer3[i] = total4;
}
 return(0);
  }
  
//+------------------------------------------------------------------+