//+------------------------------------------------------------------+
//|                                              SpreadoMeter_v2.mq4 |
//|                                Copyright © 2009, TrendLaboratory |
//|                          Many Thanks to Rosh for Ticks indicator |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                   E-mail: igorad2003@yahoo.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, TrendLaboratory"
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"


#property indicator_separate_window
#property indicator_buffers   3
#property indicator_color1    DodgerBlue
#property indicator_width1    3
#property indicator_color2    Tomato
#property indicator_width2    3
#property indicator_color3    Yellow
#property indicator_minimum 0

double Up[];
double Dn[];
double Spread[];

int      tickCounter=0;
string   short_name;
double   smax = 0, smin = 10000;
double   _Point;
datetime pTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0, Up);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1, Dn);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,4);
   SetIndexBuffer(2, Spread);
   
   IndicatorDigits(2);
   short_name="SpreadoMeter_v2";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"Max Spread ");
   SetIndexLabel(1,"Min Spread");
   SetIndexLabel(2,"Spread");
   
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   
   _Point   = MarketInfo(Symbol(),MODE_POINT)*MathPow(10,Digits%2);   
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
   return(0);
}

bool isNewBar()
{
   bool res=false;
   if (Time[0]!=pTime)
   {
   res=true;
   pTime=Time[0];
   }   

   return(res);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i,cnt_bars = IndicatorCounted();
       
   if (cnt_bars < 1) 
      for(i=Bars-1;i > 0;i--) 
      {
      Spread[i]=0.0;
      Up[i]=0.0;
      Dn[i]=0.0;
      }
   
    
   Spread[0]= (Ask - Bid)/_Point;
   
   if (isNewBar()) {smax = Spread[0]; smin = smax;}
   else
   {
   smax = MathMax(Spread[0],smax);
   smin = MathMin(Spread[0],smin);
   } 
   
   Up[0] = smax;
   Dn[0] = smin;  
       
//----
   return(0);
}
//+------------------------------------------------------------------+

