//+------------------------------------------------------------------+
//|                                                 Sin_RUIDO.mq4 |
//|                                  Miguel - Copyright © marzo 2009 |
//|                                                                  |
//+------------------------------------------------------------------+
/*
   Este indicador lo realizamos para el sistema de cuce de tres medias

*/




#property copyright "Miguel - Copyright © marzo 2009"
#property link      "ma3647@hotmail.com"

#property indicator_separate_window
//#property indicator_chart_window

#property indicator_buffers 3
#property indicator_color1 CadetBlue    
#property indicator_width1 3

#property indicator_color2 Red
#property indicator_color3 Orange
#property indicator_minimum 0
//#property indicator_maximum 30 
           


//---- buffers
double ExtMapBuffer0[];// Ask-bid
double ExtMapBuffer1[];// M10
double ExtMapBuffer2[];// M5



//-------------------  VARIABLES  --------------------

extern int BarrasDibujo=1000; // si se modifica este valor hay que modificar la dimension de las matrices en la subrrutina


int Tick;
double M1,M2,STC1,STC2,STC3,STC4,STC5,STC6,STC7,STC8,STC9,STC10,STC11,STC12,STC13,STC14,STC15,STC16;
double STC17,STC18,STC19,STC20,STC21,STC22,STC23,STC24,STC25,STC26,STC27,STC28,STC29,STC30,STC31,STC32,STC33,STC34;

//+------------------------------------------------------------------+
//| Custom indicator iNPtialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
   SetIndexLabel(0,"Spread");
   IndicatorShortName("Spread");
   IndicatorDigits(2);


   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexBuffer(0,ExtMapBuffer0);
  
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer1);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer2);


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deiNPtialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//---- TODO: add your code here
    
    
   //----Calculation---------------------------
   int  i,k,CurrentBar;
   int  counted_bars=IndicatorCounted();
   Tick=Tick+1;
   
//Recorremos desde Periodo hasta BarrasDibujo todos los puntos,  i es el indice del punto a dibujar
// for( i=0 ; i<=counted_bars ; i++ )
//***************************
if( Tick==1 )
   {
    for( i=0 ; i<=BarrasDibujo ; i++ )
      {
        ExtMapBuffer0[i]=(Ask-Bid)/Point;
        ExtMapBuffer1[i]=(Ask-Bid)/Point;
        ExtMapBuffer2[i]=(Ask-Bid)/Point;
      }
   }
 else
   {
//***************************
    for( i=BarrasDibujo ; i>0 ; i-- )
      {
        ExtMapBuffer0[i]=ExtMapBuffer0[i-1];
        ExtMapBuffer1[i]=ExtMapBuffer1[i-1];
        ExtMapBuffer2[i]=ExtMapBuffer2[i-1];
      }
//***************************
   }
//***************************
//***************************
//***************************

        STC11=STC10;      STC10=STC9;      STC9=STC8;      STC8=STC7;      STC7=STC6;     STC6=STC5;     
        STC5=STC4;        STC4=STC3;       STC3=STC2;      STC2=STC1;
        
        STC1=(Ask-Bid)/Point; if(STC1<2)STC1=STC2; 

        M1= (STC1+STC2+STC3+STC4+STC5+STC6+STC7+STC8+STC9+STC10+STC11)/11; 

        //---- ma_shift set to 0 because SetIndexShift called abowe
        ExtMapBuffer0[0]=STC1;
        ExtMapBuffer1[0]=M1;
        M2=(ExtMapBuffer1[0]+ExtMapBuffer1[1]+ExtMapBuffer1[2]+ExtMapBuffer1[3]+ExtMapBuffer1[4])/5;
        M2=M1/2;
        if(M2>1000)M2=ExtMapBuffer2[1];
        ExtMapBuffer2[0]=M2;

//***************************
//***************************
//***************************  
//----
   return(0);
  }
//+------------------------------------------------------------------+


