//+------------------------------------------------------------------+
//|                                         .mq4 |
//|                         |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  
  +------------------------------------------------------------------+
*/   

#property indicator_minimum 0.0
#property indicator_maximum 1.5

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_width1 3
#property indicator_color2 Red
#property indicator_width2 3

input int TimeFrame = 240;
input int HalfLength = 24;

double CrossUp[];
double CrossDown[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators



   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, 3);

   SetIndexBuffer(1, CrossDown);
   SetIndexStyle(1, DRAW_HISTOGRAM, EMPTY, 3);


//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;

   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      for (counter=i ;counter<=i+9;counter++)
      
       CrossUp[i] = 0;
       CrossDown[i] = 0;
  


        double Bar_0, Bar_1, Bar_2;

        Bar_0 = iCustom(NULL,0 ,"TMA+CG mladen",TimeFrame,HalfLength, 2,i+0); 
        Bar_1 = iCustom(NULL,0 ,"TMA+CG mladen",TimeFrame,HalfLength, 2,i+1); 
        Bar_2 = iCustom(NULL,0 ,"TMA+CG mladen",TimeFrame,HalfLength, 2,i+2); 

 
 
       double Val1 = Bar_0 - Bar_1 ; 
       double Val2 = Bar_1 - Bar_2 ; 
       double Val;
       
              
             
   
       if(Val1 > 0 && Val2 > 0 ) 
           Val = 1;       


       if(Val1 < 0 && Val2 < 0 ) 
           Val = -1;       
      Val = -1;
             
      if (Val == 1 ) CrossUp[i] = 1;
      if (Val == -1) CrossDown[i] = 1;
                 

   }

}
   
