//+--------------------------------------------------------------------------+
//|              WPR_3Sum mq4                                                |
//|              Copyright © 2011, Robert Hill                               |
//+--------------------------------------------------------------------------+


#property copyright "Copyright © 2011, Robert Hill"
#property link      "NONE"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 White

#property indicator_width1  1
#property indicator_width2  1
#property indicator_width3  1
#property indicator_width4  2


extern int WPR_Period1 = 7;
extern int WPR_Period2 = 14;
extern int WPR_Period3 = 21;
extern bool Show_WPR = false;

double WPR1[];
double WPR2[];
double WPR3[];
double WPRTot[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, WPR1);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, WPR2);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, WPR3);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(3, WPRTot);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
 {
   
   int limit, i;
   double wpr_1, wpr_2, wpr_3, wpr_tot;
   
   int counted_bars=IndicatorCounted();
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   
   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++)
   {
      wpr_1 = iWPR(NULL, 0, WPR_Period1, i);
      wpr_2 = iWPR(NULL, 0, WPR_Period2, i);
      wpr_3 = iWPR(NULL, 0, WPR_Period3, i);
      wpr_tot = wpr_1 + wpr_2 + wpr_3;
      if (Show_WPR)
      {
         WPR1[i] = wpr_1;
         WPR2[i] = wpr_2;
         WPR3[i] = wpr_3;
      }
      WPRTot[i] = wpr_tot;
   }
      
   return(0);
 }

