Main Chart Disappears -- code included

 

Hey everyone:  I'm wrote a function that evaluates Pearson Coefficient.  I tested the formula and it's 100% correct with results.  I'm trying to calculate the coefficient on Close and the % changes from one candle to the other.  I'm trying to show coefficient in a separate window with red and white lines.  However metatrader doesn't want to play ball.  Every time I insert the indicator I get either the red lines or the white lines.  I don't get both.  Can someone check my code?

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 White
#property indicator_level1 1.0
#property indicator_level2 -1.0

//--- input parameters
extern   bool   UseCompletedBars = true;
extern string    Symbol1           = "GBPUSD";
extern string  Symbol2        = "EURUSD";
extern int     Periods        = 5;        //number of periods going backwards
extern string  CompFactor     = "iClose"; //iClose, iOpen, iHigh, or iLow
double         Line_0[], Line_1[];
datetime       CurrTime = 0;
datetime       PrevTime = 0;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   IndicatorBuffers(2);
   SetIndexBuffer(0, Line_0);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexDrawBegin(Line_0, 1);
   SetIndexBuffer(1, Line_1);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexDrawBegin(Line_1, 1);
 
   return;
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  }

int start()
  {
   int      counted_bars=IndicatorCounted();
   int      handle, size, mode;
   double   array1[], array2[], array3[], array4[];
   double   correlationcoefficient;
  
  
//----
 

   if( UseCompletedBars )
  
   {
    CurrTime = iTime(Symbol1, 0, 1 );
      if( CurrTime == PrevTime )
      {
        return(0);
      }
    //---- Update Vars
    PrevTime = CurrTime;
   }
 

   if (CompFactor == "iClose")
      mode = 3;
   else if (CompFactor == "iOpen")
      mode = 0;
   else if (CompFactor == "iHigh")
      mode = 2;
   else if (CompFactor == "iLow")
      mode = 1;
  
 
   ArrayCopySeries(array1, mode, Symbol1, 0);
   ArrayCopySeries(array2, mode, Symbol2, 0);
   ArrayCopySeries(array3, mode, Symbol1, 0);
   ArrayCopySeries(array4, mode, Symbol2, 0);
  
   if (ArraySize(array1) < ArraySize (array2))
      size = ArraySize(array2);
   else
      size = ArraySize(array1);
   
   for (int x = 1; x<Bars; x++) {
      if (array1[x+1] && array2[x+1] != 0)
         {
         array3[x] = (array1[x] - array1[x+1])/ (array1[x+1]);
         array4[x] = (array2[x] - array2[x+1])/ (array2[x+1]);
         }
     
      }
  
   for (int i = 1; i<Bars; i++) {
      Line_0[i]= GetCoefficient(array1, array2, i, i+Periods);
      Line_1[i]= GetCoefficient(array3, array4, i, i+Periods);
      }
  
   WindowRedraw();
  
 

   return(0);
}
 
RaptorUK:

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

Good tip.  Redone.  See above.  thank you.