#property indicator_separate_window
 
#property indicator_buffers 6
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
 
extern string sym1 = "EURUSD";
extern double wt1  = 1;
extern string sym2 = "EURGBP";
extern double wt2  = 1;
extern string sym3 = "EURCHF";
extern double wt3  = 1;
extern string sym4 = "EURJPY";
extern double wt4  = 1;
extern string sym5 = "EURAUD";
extern double wt5  = 1;
extern string sym6 = "EURNZD";
extern double wt6  = 1;
extern string sym7 = "EURCAD"; 
extern double wt7  = 1;
extern color UpColor = Green;
extern color DownColor = Red;
extern int MaxBars = 1000;
 
double high[];
double low[];
double nOpen[];
double nClose[];
double nLow[];
double nHigh[];

string sy[];
double wt[];
double wt_total = 0;

int numsym = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {
    string nulls = "";
    if (sym1 != nulls) numsym++;
    if (sym2 != nulls) numsym++;
    if (sym3 != nulls) numsym++;
    if (sym4 != nulls) numsym++;
    if (sym5 != nulls) numsym++;
    if (sym6 != nulls) numsym++;
    if (sym7 != nulls) numsym++;

    ArrayResize(sy,numsym);
    ArrayResize(wt,numsym);
    
    switch (numsym)
    {
      case 1: sy[0] = sym1; wt[0] = wt1; break;
      case 2: sy[0] = sym1; wt[0] = wt1;  sy[1] = sym2; wt[1] = wt2; break;
      case 3: sy[0] = sym1; wt[0] = wt1;  sy[1] = sym2; wt[1] = wt2;  sy[2] = sym3; wt[2] = wt3; break;
      case 4: sy[0] = sym1; wt[0] = wt1;  sy[1] = sym2; wt[1] = wt2;  sy[2] = sym3; wt[2] = wt3; sy[3] = sym4; wt[3] = wt4; break;
      case 5: sy[0] = sym1; wt[0] = wt1;  sy[1] = sym2; wt[1] = wt2;  sy[2] = sym3; wt[2] = wt3; sy[3] = sym4; wt[3] = wt4; sy[4] = sym5; wt[4] = wt5; break;
      case 6: sy[0] = sym1; wt[0] = wt1;  sy[1] = sym2; wt[1] = wt2;  sy[2] = sym3; wt[2] = wt3; sy[3] = sym4; wt[3] = wt4; sy[4] = sym5; wt[4] = wt5; sy[5] = sym6; wt[5] = wt6; break;
      case 7: sy[0] = sym1; wt[0] = wt1;  sy[1] = sym2; wt[1] = wt2;  sy[2] = sym3; wt[2] = wt3; sy[3] = sym4; wt[3] = wt4; sy[4] = sym5; wt[4] = wt5; sy[5] = sym6; wt[5] = wt6; sy[6] = sym7; wt[6] = wt7; break;
      default: Print("Error: ",numsym);
   }
   
   for (int i = 0; i<numsym; i++)
   {
      wt_total += wt[i];
   }
   Print ("WT _T = ",wt[i]);   
    
    SetIndexBuffer(0, high);
    SetIndexBuffer(1, low);
    SetIndexStyle(0, DRAW_LINE);
    SetIndexStyle(1, DRAW_LINE);
    
    SetIndexBuffer(2, nOpen);
    SetIndexBuffer(3, nClose);
    SetIndexStyle(2, DRAW_NONE);
    SetIndexStyle(3, DRAW_NONE);
    
    SetIndexBuffer(4, nLow);
    SetIndexBuffer(5, nHigh);
    SetIndexStyle(4, DRAW_NONE);
    SetIndexStyle(5, DRAW_NONE);    
    
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start(){
  
   string basename = "test";
   IndicatorShortName(basename);
   int window = WindowFind(basename);
   color col;
   
   
    
   int counted_bars = IndicatorCounted();
   int uncounted = Bars - counted_bars;
   if (uncounted > MaxBars) uncounted = MaxBars;
   
   for (int i = uncounted-1; i >= 0; i--){
  
      
      nOpen[i] = 0;
      nClose[i] =0;
      nHigh[i] = 0;
      nLow[i] = 0;
      
      for (int k = 0; k<numsym; k++)
      {
         
         nOpen[i] += iOpen(sy[k],0,i)*wt[k];
         nClose[i]+= iClose(sy[k],0,i)*wt[k];
         nHigh[i] += iHigh(sy[k],0,i)*wt[k];
         nLow[i]  += iLow (sy[k],0,i)*wt[k];
 
      }
   
      nOpen[i] = nOpen[i]/wt_total;
      nClose[i] = nClose[i]/wt_total;   
      nHigh[i] = nHigh[i]/wt_total;   
      nLow[i]  = nLow[i]/wt_total;
      
     
       // these two indexes are used to control the size of the subwindow
       // they are not visible
      high[i] = nHigh[i];
      low[i] = nLow[i];
      
      if (nOpen[i]>nClose[i]) col = DownColor;
      if (nOpen[i]<nClose[i]) col = UpColor;
      
      string name = basename+i;
      if(ObjectFind(name) != -1) ObjectDelete(name);
          ObjectCreate(name, OBJ_TREND, window, Time[i], nHigh[i], Time[i], nLow[i]);
          ObjectSet(name,OBJPROP_COLOR,col);
          ObjectSet(name, OBJPROP_RAY, 0);
      
      
      name = basename+"Body"+i;
      if(ObjectFind(name) != -1) ObjectDelete(name);
          ObjectCreate(name, OBJ_TREND, window, Time[i], nOpen[i], Time[i], nClose[i]);
          ObjectSet(name, OBJPROP_WIDTH, 6);
          ObjectSet(name,OBJPROP_COLOR,col);
          ObjectSet(name, OBJPROP_RAY, 0);

  }
  

   
  
   return(0);
 }