Pearson Correlation Indicator For MT5

Pearson Correlation Indicator For MT5

The Pearson Correlation Indicator For MT5 shows the correlation of the symbol of the actual price chart with another symbol which you can freely configure in the parameters of the indicator. You can define different colors for the min and max correlation. You can also define the period and the applied price which should be compared.

FREE Pearson correlation indicator Indicator

Download the FREE Pearson correlation indicator Indicator for MT5.

To receive my email 100% sure: 
Put my email on your whitelist!

 

Partially Automated Trading Besides Your Day Job

Alerts In Real-Time When Divergences Occur

My Recommended MT4/MT5 Broker

 

Installing the Pearson Correlation Indicator For MT5

After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file correlation.mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.

Parameters of the Pearson Correlation Indicator For MT5

The Pearson Correlation Indicator For MT5 has 5 parameters to configure.

input string _SecondSymbol="EURUSD";                   // Second symbol
input int _SettPeriod=20;                              // Period
input ENUM_APPLIED_PRICE _AppliedPrice=PRICE_WEIGHTED; // Price
input color _Color1=clrBlack;                          // Min correlation
input color _Color2=clrFireBrick;                      // Max correlation

Buffers of the Pearson Correlation Indicator For MT5

The Pearson Correlation Indicator For MT5 provides 6 buffers.

SetIndexBuffer(0,buf);
SetIndexBuffer(1,colors1,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,buf2);
SetIndexBuffer(3,colors2,INDICATOR_COLOR_INDEX);
SetIndexBuffer(4,arr1,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,arr2,INDICATOR_CALCULATIONS);

Main Parts Of The Code

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i,j,c,limit,bars1,bars2;
   double averX1=0,averX2=0,v1=0,v2=0,v3=0;
   double a1[1],a2[1];
   datetime tm[1];
   bool cont=false;
//---
   if(prev_calculated gt rates_total || 
      prev_calculated lt =0)
     {
      limit=_SettPeriod-1;
      //---
      ArrayInitialize(buf,0);
      ArrayInitialize(buf2,0);
      //--- check symbol
      if(!SymbolSelect(_SecondSymbol,true))
        {
         printf("Wrong symbol! [ %s ]",_SecondSymbol);
         return 0;
        }
      //--- check for data
      bars1=Bars(_Symbol,0);
      bars2=Bars(_SecondSymbol,0);
      if(bars1==0 || bars2==0)
        {
         Print("The data is not formed yet! Wait...");
         return 0;
        }
      else if(bars1 lt _SettPeriod || 
         bars2 lt _SettPeriod)
           {
            Print("Bars is not enough to calculate!");
            return 0;
           }
         if(BarsCalculated(h1) lt bars1)
           {
            printf("Not all data of MA is calculated. Error %i. [ %s ]",GetLastError(),_Symbol);
            return 0;
           }
      if(BarsCalculated(h2) lt bars2)
        {
         printf("Not all data of MA is calculated. Error %i. [ %s ]",GetLastError(),_SecondSymbol);
         return 0;
        }
      //--- synchronization bars
      if(CopyTime(_SecondSymbol,0,bars2-1,1,tm) lt =0)
        {
         Print("Error copying time.");
         return 0;
        }
      for(i=0;i lt bars1;i++)
        {
         if(time[i] gt =tm[0])
           {
            limit=i+_SettPeriod-1;
            break;
           }
        }
     }
   else
      limit=prev_calculated-1;
//---     
   for(i=limit;i lt rates_total;i++)
     {
      averX1=0;
      averX2=0;
      for(j=0;j lt _SettPeriod;j++)
        {
         if(CopyBuffer(h1,0,time[i-j],1,a1) lt =0 ||
            CopyBuffer(h2,0,time[i-j],1,a2) lt =0)
           {
            i+=_SettPeriod-j-1;
            cont=true;
            break;
           }
         a3[j]=a1[0];
         a3[_SettPeriod+j]=a2[0];
         averX1+=a1[0]/_SettPeriod;
         averX2+=a2[0]/_SettPeriod;
        }
      if(cont)
        {
         cont=false;
         continue;
        }
      v1=0;
      v2=0;
      v3=0;
      for(j=0;j lt _SettPeriod;j++)
        {
         v1+=(a3[j]-averX1)*(a3[_SettPeriod+j]-averX2);
         v2+=pow((a3[j]-averX1),2);
         v3+=pow((a3[_SettPeriod+j]-averX2),2);
        }
      if(v1==0 || v2==0 || v3==0)
         return 0;
      buf[i]=v1/sqrt(v2*v3);
      buf2[i]=buf[i];
      c=getPlotColor(buf[i]);
      colors1[i]=c;
      colors2[i]=c;
     }
   return rates_total;
  }
//+------------------------------------------------------------------+
//| setPlotColor                                                     |
//+------------------------------------------------------------------+
void setPlotColor(int plot,color col1,color col2)
  {
   int i;
   CRGB c1,c2;
   double dr,dg,db;
   string s;
//---    
   PlotIndexSetInteger(plot,PLOT_COLOR_INDEXES,MAX_COL);
   ColorToRGB(col1,c1);
   ColorToRGB(col2,c2);
   dr=(double)(c2.r-c1.r)/MAX_COL;
   dg=(double)(c2.g-c1.g)/MAX_COL;
   db=(double)(c2.b-c1.b)/MAX_COL;
   for(i=0;i lt MAX_COL;i++)
     {
      s=StringFormat("%i,%i,%i",
                     c1.r+(int)NormalizeDouble(dr*(i+1),0),
                     c1.g+(int)NormalizeDouble(dg*(i+1),0),
                     c1.b+(int)NormalizeDouble(db*(i+1),0));
      PlotIndexSetInteger(plot,PLOT_LINE_COLOR,i,StringToColor(s));
     }
  }
//+------------------------------------------------------------------+
//| getPlotColor                                                     |
//+------------------------------------------------------------------+
int getPlotColor(double current)
  {
   return((int)NormalizeDouble((MAX_COL-1)*fabs(current),0));
  }
//+------------------------------------------------------------------+
//| ColorToRGB                                                       |
//+------------------------------------------------------------------+
void ColorToRGB(color col,CRGB &res)
  {
   string s,s2;
   int n;
//---
   s=ColorToString(col);
   n=StringFind(s,",");
   s2=StringSubstr(s,0,n);
   res.r=(int)StringToInteger(s2);
   s=StringSubstr(s,n+1);
   n=StringFind(s,",");
   s2=StringSubstr(s,0,n);
   res.g=(int)StringToInteger(s2);
   s=StringSubstr(s,n+1);
   s2=StringSubstr(s,0);
   res.b=(int)StringToInteger(s2);
  }
//+------------------------------------------------------------------+

 

About Me

I'm Mike Semlitsch the owner of PerfectTrendSystem.com. My trading career started in 2007. Since 2013 I have helped thousands of traders to take their trading to the next level. Many of them are now constantly profitable traders. 

The following performance was achieved by me while trading live in front of hundreds of my clients:

Connect With Me:  

Results From 5 Months!
This service starts soon! Be the first who get's notified when it begins!

This FREE Indicator Can Transform
Your Trading!

FREE Indicator + Telegram Group


Request the Ultimate Double Top/Bottom Indicator which is used by 10,000+ traders.