//+------------------------------------------------------------------
//|
//|
//| volumeReversalHook
//|
//|
//+------------------------------------------------------------------
#property copyright "alToronto"
#property link      "www.gmail.com"

#property indicator_chart_window
#property indicator_buffers    2
#property indicator_color1     DeepSkyBlue
#property indicator_color2     PaleVioletRed
#property indicator_width1     2
#property indicator_width2     2

//
//
//
//
//

extern int    TimeFrame      = 0;
extern int    length         = 50;
extern int    highLevel      = 0.1;
extern int    lowLevel       = -1;
extern double Tolerance      = 200;
extern double offset         = 2;

double signUp[];
double signDown[];
double condition1[];
double condition2[];
double condition3[];
double condition4[];
double condition5[];
double condition6[];

//+------------------------------------------------------------------
//|                                                                  
//+------------------------------------------------------------------
//
//
//
//
//

int init()
{
   IndicatorBuffers(8);
      SetIndexBuffer(0,signUp);   SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,159);
      SetIndexBuffer(1,signDown); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,159);
      SetIndexBuffer(2,condition1);
      SetIndexBuffer(3,condition2);
      SetIndexBuffer(4,condition3);
      SetIndexBuffer(5,condition4);
      SetIndexBuffer(6,condition5);
      SetIndexBuffer(7,condition6);
   return(0);
}
int deinit() { 
   Comment("");
   return(0); 
}

//+------------------------------------------------------------------
//|                                                                  
//+------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int i,limit,counted_bars=IndicatorCounted();

   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //

   for(i=limit; i>=0; i--)
   {
      condition1[i] = iCustom(NULL,TimeFrame,"Volumen Reversal V1",length,0,i);
      condition2[i] = iCustom(NULL,TimeFrame,"Volumen Reversal V1",length,0,i+1);
      condition3[i] = iCustom(NULL,TimeFrame,"Volumen Reversal V1",length,0,i+2);
      condition4[i] = iCustom(NULL,TimeFrame,"Volumen Reversal V1",length,1,i);
      condition5[i] = iCustom(NULL,TimeFrame,"Volumen Reversal V1",length,1,i+1);
      condition6[i] = iCustom(NULL,TimeFrame,"Volumen Reversal V1",length,1,i+2);
     
      
         //
         //
         //
         //
         //
         subPrintDetails();
         
         signUp[i]   = EMPTY_VALUE;
         signDown[i] = EMPTY_VALUE;
            if ((condition2[i] > highLevel) && (condition3[i] < condition2[i]) && (condition2[i] > condition1[i])) signDown[i] = High[i] +iATR(NULL,0,10,i)/offset;
            if ((condition5[i] < lowLevel) && (condition6[i] > condition5[i]) && (condition4[i] > condition5[i])) signUp[i]   = Low[i]-iATR(NULL,0,10,i)/offset;
   }
   return(0);
}

void subPrintDetails()
{
   string sComment   = "";
   string sp         = "----------------------------------------\n";
   string NL         = "\n";
	string sDirection = "";
   sComment = sComment + "blue=" + DoubleToStr(condition1[1],Digits) + NL;
   sComment = sComment + "red=" + DoubleToStr(condition4[1],Digits) + NL;
   sComment = sComment + sp;  
   Comment(sComment);
}