//+------------------------------------------------------------------+
//|                                                       zscore.mq4 |
//|                                                        modulatum |
//+------------------------------------------------------------------+
#property copyright "Mod"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DeepSkyBlue
#property indicator_color2 DeepSkyBlue
#property indicator_color3 DeepSkyBlue
//#property indicator_level1 0
//---- input parameters
extern int       barsToCount = 200;
//extern int       DaysBack = 1;
int       MaLen = 100;
//---- buffers
double zscore[];
double zscore1[];
double zscore2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,zscore);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,zscore1);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,zscore2);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit = barsToCount;
   
//----
   
   for(int i = 0 ;i <= limit-20 ;i++)
   {  
      double ADRTotal = ((iCustom("EURUSD", 1440 , "Val_Bands", 22 , 1 , 0, i)/10) * iCustom("EURUSD", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0)) + ((iCustom("EURGBP", 1440 , "Val_Bands", 22 , 1 , 0, i)/10) * iCustom("EURGBP", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0)) + ((iCustom("GBPUSD", 1440 , "Val_Bands", 22 , 1 , 0, i)/10) * iCustom("GBPUSD", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0));
      double EURUSDWt = (1 / ((((iCustom("EURUSD", 1440 , "Val_Bands", 22 , 1 , 0, i)/10) * iCustom("EURUSD", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0)))/ADRTotal))/10;
      double EURGBPWt = (1 / ((((iCustom("EURGBP", 1440 , "Val_Bands", 22 , 1 , 0, i)/10) * iCustom("EURGBP", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0)))/ADRTotal))/10;
      double GBPUSDWt = (1 / ((((iCustom("GBPUSD", 1440 , "Val_Bands", 22 , 1 , 0, i)/10) * iCustom("GBPUSD", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0)))/ADRTotal))/10;
//      double EURUSDp = MarketInfo("EURUSD", MODE_POINT);
//      double EURGBPp = MarketInfo("EURGBP", MODE_POINT);
//      double GBPUSDp = MarketInfo("GBPUSD", MODE_POINT);
//      double EURUSDdiff = ((((iClose("EURUSD", 0, i) - iClose("EURUSD", 0, i+DaysBack))/EURUSDp)/10)*EURUSDWt) * iCustom("EURUSD", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0);
//      double EURGBPdiff = ((((iClose("EURGBP", 0, i+DaysBack) - iClose("EURGBP", 0, i))/EURGBPp)/10)*EURGBPWt) * iCustom("EURGBP", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0);
//      double GBPUSDdiff = ((((iClose("GBPUSD", 0, i+DaysBack) - iClose("GBPUSD", 0, i))/GBPUSDp)/10)*GBPUSDWt) * iCustom("GBPUSD", 0 , "pipvaluecalculatorv1_02-Buf", 1 , 0, 0);
//      if (ADRTotal > 0)
//      if (iStdDev(NULL,0,MaLen,0,0,0,i)!=0)
      zscore[i] =   EURUSDWt;                                                //(EURUSDdiff + EURGBPdiff + GBPUSDdiff);
      zscore1[i] =  EURGBPWt;
      zscore2[i] =  GBPUSDWt;
//      zscore[i] = (iClose(NULL,0,i)-iMA(NULL,0,MaLen,0,0,0,i))/iStdDev(NULL,0,MaLen,0,0,0,i);
//      else zscore[i]==0; 
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
