#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_style1 STYLE_SOLID

// Histogram style
#property indicator_type1 DRAW_HISTOGRAM

extern int Period = 22; // Lookback period
double WVFBuffer[];

int OnInit() {
   SetIndexBuffer(0, WVFBuffer);
   SetIndexLabel(0, "WVF Histogram");
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {

   for (int i = Period; i < rates_total; i++) {
      double highestClose = close[i];
      for (int j = 1; j < Period; j++) {
         if (close[i - j] > highestClose)
            highestClose = close[i - j];
      }

      WVFBuffer[i] = ((highestClose - low[i]) / highestClose) * 100;
   }

   return(rates_total);
}
