//+------------------------------------------------------------------+
//|                                             Spread_Indicator.mq4 |
//|                                  Copyright © 2010, Kenny Hubbard |
//|                                       http://www.compu-forex.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Kenny Hubbard"
#property link      "http://www.compu-forex.com"

#property indicator_separate_window

#property indicator_buffers 2
#property indicator_color1 DeepPink
#property indicator_color2 Yellow

double 
   Max_Spread[],
   Min_Spread[],
   Pip,
   lMax,
   lMin;
string
   cmt;   

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   Pip = Point;
//---- indicators
   IndicatorShortName("Spread_Monitor");
   SetIndexBuffer(0,Max_Spread);
   SetIndexBuffer(1,Min_Spread);
   IndicatorDigits(1);
   SetIndexDrawBegin(0, Bars-2);
   SetIndexDrawBegin(1, Bars-2);
   if(Digits == 3||Digits == 5)Pip *=10;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
int    
   New_Bar = Bars-IndicatorCounted()-1;
double
   Spread = NormalizeDouble((Ask - Bid)/Pip,1);
//----
   if(New_Bar > 1){
      lMax = NormalizeDouble((Ask - Bid)/Pip,1);
      lMin = lMax;
   }
   if(Spread > lMax)lMax = Spread;
   if(Spread < lMin)lMin = Spread;

   for(int i=0;i<=New_Bar;i++){
      Max_Spread[i] = lMax;
      Min_Spread[i] = lMin;
   }
      if(New_Bar == 1){
      lMax = NormalizeDouble((Ask - Bid)/Pip,1);
      lMin = lMax;
   }
   cmt = "Current Spread = " + DoubleToStr(Spread,1) + "\n";
   Comment(cmt);
//----
   return(0);
  }
//+------------------------------------------------------------------+