//+-----------------------------------------------------------------------+
//|                                            Contador PreciosMedios.mq4 |
//|  Este experto cuenta las barras desde que las medias se han cruzado.  |
//|                Indicador realizado para sistema Seguidor de Precios.  |
//+-----------------------------------------------------------------------+
#property  copyright "Copyright © enero 2010"
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window

#property  indicator_buffers 2
#property  indicator_color1  Orange
#property  indicator_width1  1
#property  indicator_color2  Magenta
#property  indicator_width2  1

//---- Medias
extern int Mxcorta= 3 ;
extern int MxLarga= 21 ;
       int TipoMA=2;
       int PrecioMA=6;

//---- indicator buffers
double     CuentaPOS[];
double     CuentaNEG[];
int A,B;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorShortName("SPC");
   IndicatorBuffers(2);
   IndicatorDigits(Digits+2);
 
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
  SetIndexBuffer(0,CuentaPOS);
   SetIndexLabel(0,"CuentaPOS");
   SetIndexStyle(1,DRAW_HISTOGRAM);
  SetIndexBuffer(1,CuentaNEG);
   SetIndexLabel(1,"CuentaNEG");

   

  
//---- initialization done
   return(0);
  }
//+-----------------------------------------------------------------------------------------------+
//| Inicio del indicador Contador de barras que el precio esta por encima o debajo d ela media    |
//+-----------------------------------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=counted_bars; i>0; i--)
       {
//------------------------------------------ 

   if( NormalizeDouble(iMA(NULL,0,Mxcorta,0,TipoMA,PrecioMA,i),5) > NormalizeDouble(iMA(NULL,0,MxLarga,0,TipoMA,PrecioMA,i),5) )
       {
         A=A+1;B=0;
       }
     else
       {
         B=B+1;A=0;
       }

   CuentaPOS[i]=A;
   CuentaNEG[i]=-B;

//------------------------------------------
       }
   return(0);
  }
//+------------------------------------------------------------------+

