//+------------------------------------------------------------------+
//|                                                 Indicador_00.mq4 |
//|                                             Copyright 2012, ELO. |
//|                                           http://www.citrelo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, ELO."
#property link      "http://www.citrelo.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Green

#property indicator_level1 1.30
#property indicator_level2 1.20
#property indicator_level3 1.10

#define TIPO_VENTA  100
#define TIPO_COMPRA 101
#define TIPO_IGUAL  102

extern bool MostrarColor = false;

double ExtBufferPrecio[];
int    iExtIndice = 0;

double dPrecioAsk = 0;
double dPrecioBid = 0;   

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorDigits(5);
   SetIndexBuffer(0, ExtBufferPrecio);
   SetIndexStyle(0,DRAW_LINE,0,2);
   
   //-----
   IndicatorShortName("Price ELO");
   
   DibujarMenu();
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   ObjectDelete("Precio");      
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   //int counted_bars = IndicatorCounted();
   
   LeerDatos();
   ReDibujarMenu();
   
   return(0);
}

void LeerDatos()
{  
   int i = 0;
   int iTipo = 0; 
     
   //----- Tipo del Tick (Compra/Venta)
   if(dPrecioAsk == Ask)
   {
      if(MostrarColor) SetIndexStyle(0, DRAW_LINE, 0, 2, Yellow);
      iTipo = TIPO_IGUAL;   
   }
   if(dPrecioAsk > Ask)
   {
      if(MostrarColor) SetIndexStyle(0, DRAW_LINE, 0, 2, Red);
      iTipo = TIPO_VENTA;   
   }
   if(dPrecioAsk < Ask)
   {
      if(MostrarColor) SetIndexStyle(0, DRAW_LINE, 0, 2, Green);   
      iTipo = TIPO_COMPRA;
   }
   
   //----- Leer Precios
   dPrecioAsk = Ask;
   dPrecioBid = Bid;
   
   //----- Desplazar los valores. Ultimo precio a la derecha (Index = 0)
   for(i = iExtIndice; i >= 0; i--)
   {
      ExtBufferPrecio[i+1] = ExtBufferPrecio[i];    
   }
   //----- Nuevo nivel de precios
   ExtBufferPrecio[0] = dPrecioAsk;                                    

   //----- Sólo contemplamos 1000 valores
   iExtIndice++;
   if(iExtIndice > 1000)
      iExtIndice = 1000;                  
}

void DibujarMenu()
{
   ObjectCreate("Precio",OBJ_LABEL,0,0,0,0,0);        
   ObjectSetText("Precio", "Precio: " + DoubleToStr(dPrecioAsk, 5), 8, "Arial", Yellow);
   ObjectSet("Precio",OBJPROP_XDISTANCE, 3*8);     
   ObjectSet("Precio",OBJPROP_YDISTANCE, 10+1*(8+2));
   ObjectSet("Precio",OBJPROP_CORNER,1);             
}

void ReDibujarMenu()
{
   ObjectSetText("Precio", "Precio: " + DoubleToStr(dPrecioAsk, 5), 8, "Arial", Yellow);   
}
//+------------------------------------------------------------------+