//+------------------------------------------------------------------+
//|                                                      BarSize.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
//---- input parameters
extern int       ParamPer=15;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(3,ExtMapBuffer4);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int i,limit;
   double AvereageCandle;
   if (counted_bars==0) limit=Bars-ParamPer;
   if (counted_bars>0) limit=Bars-counted_bars;
   limit--;
   for (i=limit;i>=0;i--)
      {
      AvereageCandle=iMA(NULL,0,ParamPer,0,MODE_SMA,PRICE_HIGH,1)-iMA(NULL,0,ParamPer,0,MODE_SMA,PRICE_LOW,1);
      if (High[i]-Low[i]>AvereageCandle)
         {
         if (Close[i]>Open[i])
            {
            ExtMapBuffer1[i]=Open[i];
            ExtMapBuffer2[i]=Close[i];
            ExtMapBuffer3[i]=Low[i];
            ExtMapBuffer4[i]=High[i];
            }
         else
            {
            ExtMapBuffer1[i]=Open[i];
            ExtMapBuffer2[i]=Close[i];
            ExtMapBuffer3[i]=High[i];
            ExtMapBuffer4[i]=Low[i];
            }   
         }
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+