//+------------------------------------------------------------------+
//|                                                     Ticks v1.mq4 |
//|                                                      Nicholishen |
//|                                              www.tradingintl.com |
//+------------------------------------------------------------------+
#property copyright "Nicholishen"
#property link      "www.tradingintl.com"

#property indicator_separate_window
//#property indicator_minimum -100
//#property indicator_maximum 100
#property indicator_buffers 2

//#property indicator_color1 Lime
#property indicator_color1 Yellow
#property indicator_color2 Purple
//---- buffers
extern int TicksToAvg=20;
double ExtMapBuffer1[],ExtMapBuffer2[];
int bar;int LastTick,tt;
int Range[50];
double vv,pv,ff,LastAsk,ticks;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 //  ArrayInitialize(ExtMapBuffer1,0.0);
    SetIndexStyle(0,DRAW_HISTOGRAM);
    SetIndexStyle(1,DRAW_LINE);
   // SetIndexStyle(1,DRAW_HISTOGRAM);
    SetIndexBuffer(0,ExtMapBuffer1);
    SetIndexBuffer(1,ExtMapBuffer2);
   // SetIndexBuffer(0,Vol);
//----
   SetLevelValue(0,0);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  int avg;
   int    counted_bars=IndicatorCounted();
//----
   if(bar!=Bars){ff=0;pv=0;vv=0;bar=Bars;}
   
   for(int i=0; i<1;i++){
      if(LastAsk!=0){
         if(Ask>LastAsk){vv=vv+1*Point;ff=ff+1*Point;pv=pv+(Ask-LastAsk);}
         else if(Ask<LastAsk){vv=vv+1*Point;ff=ff-1*Point;pv=pv-(LastAsk-Ask);}
         
      }
      
      //if(ticks<=2)ff=0;
      ExtMapBuffer1[i]=ff;
      ExtMapBuffer2[i]=pv;
     // Vol[i]=vv;
   }
   ticks++;
   //Tick[0]=ticks;
   
   int Tick=GetTickCount();
   if(Ask!=LastAsk){
      tt++;
      for(i=49;i>0;i--){
         Range[i]=Range[i-1];
      }
      Range[0]=Tick-LastTick;
   }
   if(tt>TicksToAvg){
      for(i=0;i<TicksToAvg;i++){
         avg+=Range[i];
      }
      int av2=avg/TicksToAvg;
   }  
   Comment("\n","Ticks (",ticks,")  ",(Tick-LastTick)*0.001," seconds","\n","Average Tick Time [",TicksToAvg,"] :",av2*0.001," S");
//----
   LastTick=Tick;
   LastAsk=Ask;
   //if(!init){
   return(0);
  }
//+------------------------------------------------------------------+