Crystal Ball S.A.

 

Crystal Ball S.A.

//+------------------------------------------------------------------+
//|                                                 Crystal Ball.mq4 |
//+------------------------------------------------------------------+
#property copyright   "http://www.FinanceWave.com™"

#property indicator_separate_window
#property indicator_buffers 8

extern bool LogChart = FALSE;
extern int BARS = 200;
extern color Present = Lime;
extern color Pass = DodgerBlue;
extern color Future = Red;
extern int ScaleBars = 1440;

double ExtBuffer[],ExtBuffer2[],ExtBuffer3[],ExtBuffer4[];
double black[];
double black2[];
double black3[];
double black4[];

color bg;

double OPEN[],HIGH[],LOW[],CLOSE[];
double open[],high[],low[],close[];

double meanxc = 0,meanyc = 0,summeanyc = 0;
double Ca[], Cb=0, Cab=0, Ca2[], Cb2=0;

int ibar,recnn,z,n,deep,i,nn,p,timef,nBARS,k,shift;
double error=0,recerror=100000,h1,h2,step,h,c,cor,MAX,MIN,max,min;

double rec=0;
int barsREC, dimension1REC,dimension2REC;
int bars, deep1, deep2;

int stop=0;
int Calcs=0;
int j;
double maxPlot,minPlot;
string ShortName;
int b;
int fast=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   ShortName="Crystal Ball";
   IndicatorShortName(ShortName);
   bg=(color)ChartGetInteger(ChartID(),CHART_COLOR_BACKGROUND);
   SetIndexStyle(0,DRAW_HISTOGRAM,0,4,Pass); SetIndexBuffer(0,ExtBuffer);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4,bg); SetIndexBuffer(1,black);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2,Pass); SetIndexBuffer(2,ExtBuffer2);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,2,bg); SetIndexBuffer(3,black2);
   SetIndexStyle(4,DRAW_HISTOGRAM,0,4,Future); SetIndexBuffer(4,ExtBuffer3);
   SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,4,bg); SetIndexBuffer(5,black3);
   SetIndexStyle(6,DRAW_HISTOGRAM,0,2,Future); SetIndexBuffer(6,ExtBuffer4);
   SetIndexStyle(7,DRAW_HISTOGRAM,STYLE_SOLID,2,bg); SetIndexBuffer(7,black4);

   ArraySetAsSeries(Ca,true);ArrayResize(Ca,Bars);
   ArraySetAsSeries(Ca2,true);ArrayResize(Ca2,Bars);
   ArraySetAsSeries(OPEN,true);ArrayResize(OPEN,Bars);
   ArraySetAsSeries(HIGH,true);ArrayResize(HIGH,Bars);
   ArraySetAsSeries(LOW,true);ArrayResize(LOW,Bars);
   ArraySetAsSeries(CLOSE,true);ArrayResize(CLOSE,Bars);

   ArraySetAsSeries(open,true);ArrayResize(open,Bars);
   ArraySetAsSeries(high,true);ArrayResize(high,Bars);
   ArraySetAsSeries(low,true);ArrayResize(low,Bars);
   ArraySetAsSeries(close,true);ArrayResize(close,Bars);

   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
   SetIndexLabel(6,NULL);
   SetIndexLabel(7,NULL);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() 
  {
   ObjectDelete(0,"Correlation");
   return(0);
  }
//+------------------------------------------------------------------+
//| Crystal Ball                                                     |
//+------------------------------------------------------------------+
int start()
  {

if(stop==0)
{

bars=BARS;
if( bars*2<=Bars )
{

deep1=1;
while( bars*deep1-(deep1-1) <=Bars )
{
////////////////////////////////////////////////////// CALCULUS 1
         for(i=0;i<bars;i++)
         {
         CLOSE[i]=iClose(NULL,0,i*deep1);
         }
               meanxc = 0;

               for(z=0;z<bars;z++)
                 {
                  meanxc = meanxc+CLOSE[z];
                 }
               meanxc=meanxc/floor(bars);

               for(z=0;z<bars;z++)
                 {
                  Ca[z]=CLOSE[z]-meanxc;
                  Ca2[z]=Ca2[z-1]+Ca[z]*Ca[z];
                 }
////////////////////////////////////////////////////// 
deep2=deep1;
while( Bars>= bars*deep2*2 - (deep2-1) )
{
////////////////////////////////////////////////////// CALCULUS 2
                        for(i=0;i<Bars;i++)
                        {
                        if(i*deep2+deep2-1>Bars-1){nBARS=i-1;break;}
                        CLOSE[i]=iClose(NULL,0,i*deep2);
                        }
                     summeanyc = 0;

                     for(n=bars;n<=nBARS-bars+1;n++)
                       {
                        meanyc = 0;

                        Cb=0;
                        Cab=0;
                        Cb2=0;

                        if(n==bars || fast==1)
                          {summeanyc = 0;
                           for(z=bars-1;z>=0;z--)
                             {
                              summeanyc = summeanyc+CLOSE[n+z];
                             }
                           meanyc=(summeanyc)/floor(bars);
                          }
                        else
                          {
                           summeanyc=(summeanyc-CLOSE[n-1]+CLOSE[n+bars-1]);
                           meanyc=(summeanyc)/floor(bars);
                          }

                        for(z=0;z<bars;z++)
                          {
                           Cb=CLOSE[n+z]-meanyc;
                           Cab=Cab+Ca[z]*Cb;
                           Cb2=Cb2+Cb*Cb;
                          }

                        if(Ca2[bars-1]>0 && Cb2>0)
                          {
                           cor=Cab/MathSqrt(Ca2[bars-1]*Cb2);
                           Calcs++;
                           
                           if(cor<0)
                           {fast=1;n=n+20;}
                           else{fast=0;}

                           if(cor>rec)
                           {
                           rec=cor;
                           ibar=n;
                           barsREC=bars;
                           dimension1REC=deep1;
                           dimension2REC=deep2;
                           }
                          }
                       }
deep2++;
}
deep1++;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
      ObjectCreate("Correlation",OBJ_LABEL,WindowFind(ShortName),0,0);
      ObjectSetText("Correlation","Correlação: "+rec,10,"Verdana",Red);
      ObjectSet("Correlation",OBJPROP_CORNER,0);
      ObjectSet("Correlation",OBJPROP_XDISTANCE,20);
      ObjectSet("Correlation",OBJPROP_YDISTANCE,20);

Print("Bars: ", barsREC," Deep1: ",dimension1REC, " Deep2: ",dimension2REC," ibar: ",ibar," Calcs: ",Calcs," Rec: ",rec);

int i1=ibar*dimension2REC+ (barsREC-1)*dimension2REC +(dimension2REC-1);
int i2=ibar*dimension2REC;
Print("Pass: ", TimeToStr(iTime(NULL,0,i1),TIME_DATE) ," to ",TimeToStr(iTime(NULL,0,i2),TIME_DATE));

int i3=(barsREC-1)*dimension1REC+(dimension1REC-1);
Print("Present: ", TimeToStr(iTime(NULL,0,i3),TIME_DATE) ," to ",TimeToStr(iTime(NULL,0,0),TIME_DATE));

Alert("FINISHED");

//////////////////// LE Picture
//ARRAY 1
deep1=dimension1REC;

for(i=0;i<=Bars-1;i++)
{
if(i*deep1+(deep1-1)>Bars-1){break;}
open[i]=iOpen(NULL,0,i*deep1+(deep1-1));
high[i]=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,deep1,i*deep1));
low[i]=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,deep1,i*deep1));
close[i]=iClose(NULL,0,i*deep1);
}
////////////////////////////////////////////////////// PAINT
//ARRAY 2
deep2=dimension2REC;

for(i=0;i<Bars;i++)
{
if(i*deep2+deep2-1>Bars-1){nBARS=i-1;break;}
OPEN[i]=iOpen(NULL,0,i*deep2+(deep2-1));
HIGH[i]=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,deep2,i*deep2));
LOW[i]=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,deep2,i*deep2));
CLOSE[i]=iClose(NULL,0,i*deep2);
}

// COMPARE ARRAY
bars=barsREC;

MIN=1000000000;
MAX=0;
for(k=0;k<bars;k++)
{
MAX=MathMax(MAX,HIGH[ibar+k]);
MIN=MathMin(MIN,LOW[ibar+k]);
}

h1 = MAX-MIN;

max=0;min=1000000;
for(j=0;j<bars;j++)
{
max=MathMax(max,high[j]);
min=MathMin(min,low[j]);
}

h2 = max-min;

h = h2/h1;

step = h2/1000;

for(nn=0;nn<=2000;nn++)
{
c = close[0]-(CLOSE[ibar]*h)+((-1000+nn)*step);

for(p = 0; p<bars;p++)
{
error = error + MathPow(high[p]-c-(HIGH[p+ibar]*h),2)+MathPow(low[p]-c-(LOW[p+ibar]*h),2)+MathPow(close[p]-c-(CLOSE[p+ibar]*h),2)+MathPow(open[p]-c-(OPEN[p+ibar]*h),2);
}
error = MathSqrt(error);

if(error<recerror)
{recerror=error;
recnn = nn;}
error=0;
}

c = close[0]-(CLOSE[ibar]*h)+((-1000+recnn)*step);

if(HIGH[ibar]-LOW[ibar]==0 || HIGH[ibar+bars-1]-LOW[ibar+bars-1]==0 )
{
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexStyle(7,DRAW_LINE);
}

if(LogChart==FALSE)
{
// BLUE
for(i=0;i<bars;i++)
{
ExtBuffer[i]=MathMax(c + (CLOSE[i+ibar]*h),c + (OPEN[i+ibar]*h));
black[i]=MathMin(c + (CLOSE[i+ibar]*h),c + (OPEN[i+ibar]*h));
ExtBuffer2[i]=c + (HIGH[i+ibar]*h);
black2[i]=c + (LOW[i+ibar]*h);
}

SetIndexShift(4,bars);
SetIndexShift(5,bars);
SetIndexShift(6,bars);
SetIndexShift(7,bars);

// RED
for(i=1;i<=bars;i++)
{
ExtBuffer3[bars-i]=MathMax(c + (CLOSE[ibar-i]*h),c + (OPEN[ibar-i]*h));
black3[bars-i]=MathMin(c + (CLOSE[ibar-i]*h),c + (OPEN[ibar-i]*h));
ExtBuffer4[bars-i]=c + (HIGH[ibar-i]*h);
black4[bars-i]=c + (LOW[ibar-i]*h);
}

// LIME
deep1=dimension1REC;

for(i=0;i<=Bars-1;i++)
{
if(i*deep1+(deep1-1)>Bars-1)
{
b = Bars-i*deep1;
if(b>0)
{
open[i]=iOpen(NULL,0,Bars-1);
high[i]=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,b,i*deep1));
low[i]=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,b,i*deep1));
close[i]=iClose(NULL,0,i*deep1);
}
nBARS=i-1;
break;
}
open[i]=iOpen(NULL,0,i*deep1+(deep1-1));
high[i]=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,deep1,i*deep1));
low[i]=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,deep1,i*deep1));
close[i]=iClose(NULL,0,i*deep1);
DrawPriceTrendLine(Time[i],Time[i],high[i],low[i],Present,STYLE_SOLID,0);
DrawPriceTrendLine2(Time[i],Time[i],close[i],open[i],Present,STYLE_SOLID,3);
}

maxPlot=0;minPlot=10000000;
for(i=0;i<bars;i++)
{maxPlot=MathMax(ExtBuffer2[i],maxPlot);
minPlot=MathMin(black2[i],minPlot);}
for(i=1;i<=bars;i++)
{maxPlot=MathMax(ExtBuffer4[bars-i],maxPlot);
minPlot=MathMin(black4[bars-i],minPlot);}
for(i=0;i<=ScaleBars;i++)
{if(i*deep1+(deep1-1)>Bars-1){break;}
maxPlot=MathMax(high[i],maxPlot);
minPlot=MathMin(low[i],minPlot);}

   IndicatorSetDouble(INDICATOR_MINIMUM,minPlot-(maxPlot-minPlot)*0.1);
   IndicatorSetDouble(INDICATOR_MAXIMUM,maxPlot+(maxPlot-minPlot)*0.1);
}

else
{
// BLUE
for(i=0;i<bars;i++)
{
ExtBuffer[i]=MathLog(MathMax(c + (CLOSE[i+ibar]*h),c + (OPEN[i+ibar]*h)));
black[i]=MathLog(MathMin(c + (CLOSE[i+ibar]*h),c + (OPEN[i+ibar]*h)));
ExtBuffer2[i]=MathLog(c + (HIGH[i+ibar]*h));
black2[i]=MathLog(c + (LOW[i+ibar]*h));
}

SetIndexShift(4,bars);
SetIndexShift(5,bars);
SetIndexShift(6,bars);
SetIndexShift(7,bars);

// RED
for(i=1;i<=bars;i++)
{
ExtBuffer3[bars-i]=MathLog(MathMax(c + (CLOSE[ibar-i]*h),c + (OPEN[ibar-i]*h)));
black3[bars-i]=MathLog(MathMin(c + (CLOSE[ibar-i]*h),c + (OPEN[ibar-i]*h)));
ExtBuffer4[bars-i]=MathLog(c + (HIGH[ibar-i]*h));
black4[bars-i]=MathLog(c + (LOW[ibar-i]*h));
}

// LIME
deep1=dimension1REC;

for(i=0;i<=Bars-1;i++)
{
if(i*deep1+(deep1-1)>Bars-1)
{
b = Bars-i*deep1;
if(b>0)
{
open[i]=MathLog(iOpen(NULL,0,Bars-1));
high[i]=MathLog(iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,b,i*deep1)));
low[i]=MathLog(iLow(NULL,0,iLowest(NULL,0,MODE_LOW,b,i*deep1)));
close[i]=MathLog(iClose(NULL,0,i*deep1));
}
nBARS=i-1;
break;
}
open[i]=MathLog(iOpen(NULL,0,i*deep1+(deep1-1)));
high[i]=MathLog(iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,deep1,i*deep1)));
low[i]=MathLog(iLow(NULL,0,iLowest(NULL,0,MODE_LOW,deep1,i*deep1)));
close[i]=MathLog(iClose(NULL,0,i*deep1));
DrawPriceTrendLine(Time[i],Time[i],high[i],low[i],Present,STYLE_SOLID,0);
DrawPriceTrendLine2(Time[i],Time[i],close[i],open[i],Present,STYLE_SOLID,3);
}

maxPlot=0;minPlot=10000000;
for(i=0;i<bars;i++)
{maxPlot=MathMax(ExtBuffer2[i],maxPlot);
minPlot=MathMin(black2[i],minPlot);}
for(i=1;i<=bars;i++)
{maxPlot=MathMax(ExtBuffer4[bars-i],maxPlot);
minPlot=MathMin(black4[bars-i],minPlot);}
for(i=0;i<=ScaleBars;i++)
{if(i*deep1+(deep1-1)>Bars-1){break;}
maxPlot=MathMax(high[i],maxPlot);
minPlot=MathMin(low[i],minPlot);}

   IndicatorSetDouble(INDICATOR_MINIMUM,minPlot-(maxPlot-minPlot)*0.1);
   IndicatorSetDouble(INDICATOR_MAXIMUM,maxPlot+(maxPlot-minPlot)*0.1);
}

stop=1;
}

   return(0);
  }
//+------------------------------------------------------------------+
void DrawPriceTrendLine(datetime x1,datetime x2,double y1,
                        double y2,color lineColor,double style,int wid)
  {
   string label="Abc"+x1;
   ObjectDelete(label);
   ObjectCreate(label,OBJ_TREND,WindowFind(ShortName),x1,y1,x2,y2,0,0);
   ObjectSet(label,OBJPROP_RAY,0);
   ObjectSet(label,OBJPROP_COLOR,lineColor);
   ObjectSet(label,OBJPROP_STYLE,style);
   ObjectSet(label,OBJPROP_WIDTH,wid);
  }
//+------------------------------------------------------------------+
void DrawPriceTrendLine2(datetime x1,datetime x2,double y1,
                        double y2,color lineColor,double style,int wid)
  {
   string label2="Abc2"+x1;
   ObjectDelete(label2);
   ObjectCreate(label2,OBJ_TREND,WindowFind(ShortName),x1,y1,x2,y2,0,0);
   ObjectSet(label2,OBJPROP_RAY,0);
   ObjectSet(label2,OBJPROP_COLOR,lineColor);
   ObjectSet(label2,OBJPROP_STYLE,style);
   ObjectSet(label2,OBJPROP_WIDTH,wid);
  }
//+------------------------------------------------------------------+
// ALL CHARTS
Files:
 

Bola de Cristal.mq4 (attached)

Fast Version with Volume picture, best regards!

 


Code:

//+------------------------------------------------------------------+
//|                                                 Crystal Ball.mq4 |
//+------------------------------------------------------------------+
#property copyright   "http://www.FinanceWave.com™"

#property indicator_separate_window
#property indicator_buffers 10

extern bool LogChart = FALSE;
extern color Present = Lime;
extern color Pass = DodgerBlue;
extern color Future = Red;
extern color PresentVol = Green;
extern color PassVol = Gold;

int ScaleBars = 1440;

color bg;
double ExtBuffer[],ExtBuffer2[],ExtBuffer3[],ExtBuffer4[],black[],black2[],black3[],black4[],ExtBuffer5[],ExtBuffer6[];
double OPEN[],HIGH[],LOW[],CLOSE[],open[],high[],low[],close[],volume1[],volume2[];
double meanxc=0,meanyc=0,summeanyc=0,meanxv=0,meanyv=0,summeanyv=0,Ca[],Cb=0,Cab=0,Ca2[],Cb2=0,Va[],Vb=0,Vab=0,Va2[],Vb2=0;
int ibar,recnn,z,n,i,j,k,nBARS,nn,p,dimension1REC,dimension2REC,i1,i2,i3,deep1,deep2,stop=0,Calcs=0,b,fast=0,AHA,KQJ,LOVE,People;
double error=0,recerror=100000,h1,h2,step,h,c,cor,MAX,MIN,max,min,rec=0,maxPlot,minPlot,corV=0;
string ShortName;
double hMaxVol,hMinVol,SomaVolume1,SomaVolume2,prop,VolMax,VolMin;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   ShortName="Crystal Ball";
   IndicatorShortName(ShortName);
   bg=(color)ChartGetInteger(ChartID(),CHART_COLOR_BACKGROUND);
   SetIndexStyle(0,DRAW_HISTOGRAM,0,4,Pass); SetIndexBuffer(0,ExtBuffer);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4,bg); SetIndexBuffer(1,black);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2,Pass); SetIndexBuffer(2,ExtBuffer2);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,2,bg); SetIndexBuffer(3,black2);
   SetIndexStyle(4,DRAW_HISTOGRAM,0,4,Future); SetIndexBuffer(4,ExtBuffer3);
   SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,4,bg); SetIndexBuffer(5,black3);
   SetIndexStyle(6,DRAW_HISTOGRAM,0,2,Future); SetIndexBuffer(6,ExtBuffer4);
   SetIndexStyle(7,DRAW_HISTOGRAM,STYLE_SOLID,2,bg); SetIndexBuffer(7,black4);
   SetIndexStyle(8,DRAW_HISTOGRAM,STYLE_SOLID,3,PresentVol); SetIndexBuffer(8,ExtBuffer5);
   SetIndexStyle(9,DRAW_HISTOGRAM,STYLE_SOLID,1,PassVol); SetIndexBuffer(9,ExtBuffer6); 

   ArraySetAsSeries(Ca,true);ArrayResize(Ca,5000);
   ArraySetAsSeries(Ca2,true);ArrayResize(Ca2,5000);
   ArraySetAsSeries(Va,true);ArrayResize(Va,5000);
   ArraySetAsSeries(Va2,true);ArrayResize(Va2,5000);
   ArraySetAsSeries(OPEN,true);ArrayResize(OPEN,5000);
   ArraySetAsSeries(HIGH,true);ArrayResize(HIGH,5000);
   ArraySetAsSeries(LOW,true);ArrayResize(LOW,5000);
   ArraySetAsSeries(CLOSE,true);ArrayResize(CLOSE,Bars);
   ArraySetAsSeries(open,true);ArrayResize(open,5000);
   ArraySetAsSeries(high,true);ArrayResize(high,5000);
   ArraySetAsSeries(low,true);ArrayResize(low,5000);
   ArraySetAsSeries(close,true);ArrayResize(close,5000);
   ArraySetAsSeries(volume1,true);ArrayResize(volume1,5000);
   ArraySetAsSeries(volume2,true);ArrayResize(volume2,5000);

   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
   SetIndexLabel(6,NULL);
   SetIndexLabel(7,NULL);
   SetIndexLabel(8,NULL);
   SetIndexLabel(9,NULL);
   
   return(INIT_SUCCEEDED);}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {return(0);}
//+------------------------------------------------------------------+
//| Crystal Ball                                                     |
//+------------------------------------------------------------------+
int start()
  {

if(stop==0)
{
if(400<=Bars)
{
deep1=1;
while(400*deep1<=Bars)
{
////////////////////////////////////////////////////// CALCULUS 1
for(i=0;i<200;i++)
{CLOSE[i]=iClose(NULL,0,i*deep1);}
               
meanxc=0;
for(z=0;z<200;z++)
{meanxc=meanxc+CLOSE[z];}
meanxc=meanxc/200;

Ca[0]=CLOSE[0]-meanxc;
Ca2[0]=Ca[0]*Ca[0];

for(z=1;z<200;z++)
{Ca[z]=CLOSE[z]-meanxc;
Ca2[z]=Ca2[z-1]+Ca[z]*Ca[z];}
//////////////////////////////////////////////////////
deep2=deep1;
while(Bars>=400*deep2)
{
////////////////////////////////////////////////////// CALCULUS 2
nBARS=floor(Bars/deep2)-1;
for(i=0;i<=nBARS;i++)
{CLOSE[i]=iClose(NULL,0,i*deep2);}
                     
summeanyc=0;
for(n=200;n<=nBARS-199;n++)
{meanyc=0;

Cb=0;
Cab=0;
Cb2=0;

if(n==200||fast==1)
{summeanyc=0;
for(z=199;z>=0;z--)
{summeanyc=summeanyc+CLOSE[n+z];}}
else
{summeanyc=(summeanyc-CLOSE[n-1]+CLOSE[n+199]);}
meanyc=summeanyc/200;

for(z=0;z<200;z++)
{Cb=CLOSE[n+z]-meanyc;
Cab=Cab+Ca[z]*Cb;
Cb2=Cb2+Cb*Cb;}

cor=Cab/(MathSqrt(5000*(Ca2[199]*Cb2))/MathSqrt(5000));
Calcs++;

if(Bars>5000)
{if(cor<0){fast=1;n=n+80;}
else if(cor<0.95){fast=1;n=n+80-floor(70*cor);}
else{fast=0;}

if(cor>rec)
{rec=cor;
ibar=n;
dimension1REC=deep1;
dimension2REC=deep2;}
}
}
deep2++;}
deep1++;}
////////////////////////////////////////////////////////////////////////////////////////////////////
      ObjectCreate("Correlation",OBJ_LABEL,WindowFind(ShortName),0,0);
      ObjectSetText("Correlation","Correlação: "+rec,10,"Verdana",Red);
      ObjectSet("Correlation",OBJPROP_CORNER,0);
      ObjectSet("Correlation",OBJPROP_XDISTANCE,20);
      ObjectSet("Correlation",OBJPROP_YDISTANCE,20);

i1=ibar*dimension2REC+199*dimension2REC+(dimension2REC-1);
i2=ibar*dimension2REC;
i3=199*dimension1REC+(dimension1REC-1);

// VOLUME CONFIRM?
for(LOVE=0;LOVE<200;LOVE++)
{People=0;
while(People<dimension1REC)
{volume1[LOVE]=volume1[LOVE]+Volume[LOVE*dimension1REC+People];People++;}
for(AHA=0;AHA<200;AHA++)
{KQJ=0;
while(KQJ<dimension2REC)
{volume2[AHA]=volume2[AHA]+Volume[i2+AHA*dimension2REC+KQJ];KQJ++;}}}
////////////////////////////////////////////////////// CALCULUS 1
meanxv=0; 
for(z=0;z<200;z++)
{meanxv=meanxv+volume1[z];}
meanxv=meanxv/200;
               
for(z=0;z<200;z++)
{Va[z]=volume1[z]-meanxv;
if(z!=0){Va2[z]=Va2[z-1]+Va[z]*Va[z];}else{Va2[z]=Va[z]*Va[z];}}
////////////////////////////////////////////////////// CALCULUS 2
summeanyv=0;
meanyv=0;

Vb=0;
Vab=0;
Vb2=0;

for(z=199;z>=0;z--)
{summeanyv=summeanyv+volume2[z];}
meanyv=summeanyv/200;

for(z=0;z<200;z++)
{Vb=volume2[z]-meanyv;
Vab=Vab+Va[z]*Vb;
Vb2=Vb2+Vb*Vb;}

corV=Vab/(MathSqrt(5000*(Va2[199]*Vb2))/MathSqrt(5000));

      ObjectCreate("Correlation2",OBJ_LABEL,WindowFind(ShortName),0,0);
      ObjectSetText("Correlation2","Volume: "+corV,10,"Verdana",Magenta);
      ObjectSet("Correlation2",OBJPROP_CORNER,0);
      ObjectSet("Correlation2",OBJPROP_XDISTANCE,20);
      ObjectSet("Correlation2",OBJPROP_YDISTANCE,40);
     
Print("Bars: ",200," Deep1: ",dimension1REC," Deep2: ",dimension2REC," Calcs: ",Calcs," Rec: ",rec," Volume: ",corV);
Print("Pass: ",TimeToStr(iTime(NULL,0,i1),TIME_DATE)," to ",TimeToStr(iTime(NULL,0,i2),TIME_DATE));
Print("Present: ",TimeToStr(iTime(NULL,0,i3),TIME_DATE)," to ",TimeToStr(iTime(NULL,0,0),TIME_DATE));
Alert("FINISHED");
//////////////////// LE Picture

// ARRAY 1
deep1=dimension1REC;
for(LOVE=0;LOVE<=1500;LOVE++)
{
if(LOVE*deep1+deep1-1>Bars-1){break;}
open[LOVE]=Open[LOVE*deep1+deep1-1];
high[LOVE]=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,deep1,LOVE*deep1));
low[LOVE]=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,deep1,LOVE*deep1));
close[LOVE]=Close[LOVE*deep1];
}

//ARRAY 2
deep2=dimension2REC;
for(AHA=0;AHA<400;AHA++)
{
OPEN[AHA]=Open[i2+(AHA-200)*deep2+deep2-1];
HIGH[AHA]=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,deep2,i2+(AHA-200)*deep2));
LOW[AHA]=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,deep2,i2+(AHA-200)*deep2));
CLOSE[AHA]=Close[i2+(AHA-200)*deep2];
}

////////////////////////////////////////////////////// PAINT

// COMPARE ARRAY
MIN=1000000000;MAX=0;
for(k=0;k<200;k++)
{MAX=MathMax(MAX,HIGH[k+200]);
MIN=MathMin(MIN,LOW[k+200]);}

max=0;min=1000000;
for(j=0;j<200;j++)
{max=MathMax(max,high[j]);
min=MathMin(min,low[j]);}

h1=MAX-MIN;
h2=max-min;
h=h2/h1;
step=h2/1000;

for(nn=0;nn<=2000;nn++)
{c=close[0]-(CLOSE[200]*h)+((-1000+nn)*step);

for(p=0;p<200;p++)
{error=error+MathPow(high[p]-c-(HIGH[p+200]*h),2)+MathPow(low[p]-c-(LOW[p+200]*h),2)+MathPow(close[p]-c-(CLOSE[p+200]*h),2)+MathPow(open[p]-c-(OPEN[p+200]*h),2);}
error=MathSqrt(error);

if(error<recerror)
{recerror=error;
recnn=nn;}
error=0;}

c=close[0]-(CLOSE[200]*h)+((-1000+recnn)*step);

if(HIGH[200]-LOW[200]==0 || HIGH[200+199]-LOW[200+199]==0)
{SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(3,DRAW_LINE);
SetIndexStyle(4,DRAW_LINE);
SetIndexStyle(5,DRAW_LINE);
SetIndexStyle(6,DRAW_LINE);
SetIndexStyle(7,DRAW_LINE);}

if(LogChart==FALSE)
{
// BLUE
for(i=0;i<200;i++)
{ExtBuffer[i]=MathMax(c+(CLOSE[i+200]*h),c+(OPEN[i+200]*h));
black[i]=MathMin(c+(CLOSE[i+200]*h),c+(OPEN[i+200]*h));
ExtBuffer2[i]=c+(HIGH[i+200]*h);
black2[i]=c+(LOW[i+200]*h);}

SetIndexShift(4,200);
SetIndexShift(5,200);
SetIndexShift(6,200);
SetIndexShift(7,200);

// RED
for(i=1;i<=200;i++)
{ExtBuffer3[200-i]=MathMax(c+(CLOSE[200-i]*h),c+(OPEN[200-i]*h));
black3[200-i]=MathMin(c+(CLOSE[200-i]*h),c+(OPEN[200-i]*h));
ExtBuffer4[200-i]=c+(HIGH[200-i]*h);
black4[200-i]=c+(LOW[200-i]*h);}

// LIME
deep1=dimension1REC;

for(i=0;i<=1500;i++)
{
if(i*deep1+deep1-1>Bars-1){break;}
DrawPriceTrendLine(Time[i],Time[i],high[i],low[i],Present,STYLE_SOLID,0);
DrawPriceTrendLine2(Time[i],Time[i],close[i],open[i],Present,STYLE_SOLID,3);
}

maxPlot=0;minPlot=10000000;
for(i=0;i<200;i++)
{maxPlot=MathMax(ExtBuffer2[i],maxPlot);
minPlot=MathMin(black2[i],minPlot);}
for(i=1;i<=200;i++)
{maxPlot=MathMax(ExtBuffer4[200-i],maxPlot);
minPlot=MathMin(black4[200-i],minPlot);}
for(i=0;i<=ScaleBars;i++)
{if(i*deep1+(deep1-1)>Bars-1){break;}
maxPlot=MathMax(high[i],maxPlot);
minPlot=MathMin(low[i],minPlot);}

IndicatorSetDouble(INDICATOR_MINIMUM,minPlot-(maxPlot-minPlot)*0.2);
IndicatorSetDouble(INDICATOR_MAXIMUM,maxPlot+(maxPlot-minPlot)*0.1);
}

else
{
// BLUE
for(i=0;i<200;i++)
{ExtBuffer[i]=100+MathLog(MathMax(c+(CLOSE[i+200]*h),c+(OPEN[i+200]*h)));
black[i]=100+MathLog(MathMin(c+(CLOSE[i+200]*h),c+(OPEN[i+200]*h)));
ExtBuffer2[i]=100+MathLog(c+(HIGH[i+200]*h));
black2[i]=100+MathLog(c+(LOW[i+200]*h));}

SetIndexShift(4,200);
SetIndexShift(5,200);
SetIndexShift(6,200);
SetIndexShift(7,200);

// RED
for(i=1;i<=200;i++)
{ExtBuffer3[200-i]=100+MathLog(MathMax(c+(CLOSE[200-i]*h),c+(OPEN[200-i]*h)));
black3[200-i]=100+MathLog(MathMin(c+(CLOSE[200-i]*h),c+(OPEN[200-i]*h)));
ExtBuffer4[200-i]=100+MathLog(c+(HIGH[200-i]*h));
black4[200-i]=100+MathLog(c+(LOW[200-i]*h));}

// LIME
deep1=dimension1REC;

for(i=0;i<=1500;i++)
{
if(i*deep1+deep1-1>Bars-1){break;}
DrawPriceTrendLine(Time[i],Time[i],100+MathLog(high[i]),100+MathLog(low[i]),Present,STYLE_SOLID,0);
DrawPriceTrendLine2(Time[i],Time[i],100+MathLog(close[i]),100+MathLog(open[i]),Present,STYLE_SOLID,3);}

maxPlot=0;minPlot=10000000;
for(i=0;i<200;i++)
{maxPlot=MathMax(ExtBuffer2[i],maxPlot);
minPlot=MathMin(black2[i],minPlot);}
for(i=1;i<=200;i++)
{maxPlot=MathMax(ExtBuffer4[200-i],maxPlot);
minPlot=MathMin(black4[200-i],minPlot);}
for(i=0;i<=ScaleBars;i++)
{if(i*deep1+(deep1-1)>Bars-1){break;}
maxPlot=MathMax(high[i],maxPlot);
minPlot=MathMin(low[i],minPlot);}

   IndicatorSetDouble(INDICATOR_MINIMUM,minPlot-(maxPlot-minPlot)*0.2);
   IndicatorSetDouble(INDICATOR_MAXIMUM,maxPlot+(maxPlot-minPlot)*0.1);
}

// DRAW VOLUME
hMaxVol=minPlot-(maxPlot-minPlot)*0.1;
hMinVol=minPlot-(maxPlot-minPlot)*0.175;

// Soma dos volumes
SomaVolume1=0;
SomaVolume2=0;
for(i=0;i<200;i++)
{
SomaVolume1=SomaVolume1+volume1[i];
SomaVolume2=SomaVolume2+volume2[i];
}

// Equalização do volume2
prop=SomaVolume1/SomaVolume2;

// Procura do valor mais alto entre o volume1 e o volume2
VolMax=MathMax(volume1[0],volume2[0]*prop); 
VolMin=MathMin(volume1[0],volume2[0]*prop);
for(i=1; i<200; i++)
{
VolMax=MathMax(MathMax(volume1[i],volume2[i]*prop),VolMax);
VolMin=MathMin(MathMin(volume1[i],volume2[i]*prop),VolMin);
}

// Plota volumes equalizados ao teto
for(i=0;i<200;i++)
{
ExtBuffer5[i]=hMinVol+((volume1[i]-VolMin)/(VolMax-VolMin))*(hMaxVol-hMinVol);
ExtBuffer6[i]=hMinVol+(((volume2[i]*prop)-VolMin)/(VolMax-VolMin))*(hMaxVol-hMinVol);
}

}

stop=1;
}
   return(0);
  }
//+------------------------------------------------------------------+
void DrawPriceTrendLine(datetime x1,datetime x2,double y1,
                        double y2,color lineColor,double style,int wid)
  {string label="Abc"+x1;
   ObjectDelete(label);
   ObjectCreate(label,OBJ_TREND,WindowFind(ShortName),x1,y1,x2,y2,0,0);
   ObjectSet(label,OBJPROP_RAY,0);
   ObjectSet(label,OBJPROP_COLOR,lineColor);
   ObjectSet(label,OBJPROP_STYLE,style);
   ObjectSet(label,OBJPROP_WIDTH,wid);}
//+------------------------------------------------------------------+
void DrawPriceTrendLine2(datetime x1,datetime x2,double y1,
                        double y2,color lineColor,double style,int wid)
  {string label2="Abc2"+x1;
   ObjectDelete(label2);
   ObjectCreate(label2,OBJ_TREND,WindowFind(ShortName),x1,y1,x2,y2,0,0);
   ObjectSet(label2,OBJPROP_RAY,0);
   ObjectSet(label2,OBJPROP_COLOR,lineColor);
   ObjectSet(label2,OBJPROP_STYLE,style);
   ObjectSet(label2,OBJPROP_WIDTH,wid);}
//+------------------------------------------------------------------+
// ✓
Files:
 

Wishful thinking is a common phenomenon.

What's in essence your question.

 

Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
          General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon.