#property copyright "Sajid Islam"
#property link      "www.ksa.org.pk"

#property indicator_chart_window
#property indicator_buffers 8

#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 Blue
#property indicator_color4 Blue
#property indicator_color5 Orange
#property indicator_color6 Orange
#property indicator_color7 Orange
#property indicator_color8 Orange
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 3
#property indicator_width8 3
double b1[],b2[],b3[],b4[],b5[],b6[],b7[],b8[];
int bull=1;
int bear=-1;
int pig=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
 SetIndexStyle(0,DRAW_HISTOGRAM);
 SetIndexBuffer(0,b1);
 SetIndexStyle(1,DRAW_HISTOGRAM);
 SetIndexBuffer(1,b2);
 SetIndexStyle(2,DRAW_HISTOGRAM);
 SetIndexBuffer(2,b3);
 SetIndexStyle(3,DRAW_HISTOGRAM);
 SetIndexBuffer(3,b4);
 SetIndexStyle(4,DRAW_HISTOGRAM);
 SetIndexBuffer(4,b5);
 SetIndexStyle(5,DRAW_HISTOGRAM);
 SetIndexBuffer(5,b6);
 SetIndexStyle(6,DRAW_HISTOGRAM);
 SetIndexBuffer(6,b7);
 SetIndexStyle(7,DRAW_HISTOGRAM);
 SetIndexBuffer(7,b8);
//----
 return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
 return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{   
 int pos,imax,counted_bars=IndicatorCounted();
 if(counted_bars>0) imax=Bars-IndicatorCounted();
 else imax=Bars-1;    
//----
 for(pos=imax;pos>0;pos--) 
 {
  ResetBuffers(pos);
  int Sig=Signal(pos);
  Print(Sig);
  if (Sig!=0)
   {
   double low,high,close,open;
   low=Low[pos];
   high=High[pos];
   close=Close[pos];
   open=Open[pos];
   if(Sig==1)
     {
       b1[pos] = iHigh(NULL,0,pos);
       b2[pos] = iLow(NULL,0,pos);  
       b3[pos] = iOpen(NULL,0,pos);
       b4[pos] = iClose(NULL,0,pos);  
     }
   if(Sig==-1)
     {
   b5[pos] = iHigh(NULL,0,pos);
   b6[pos] = iLow(NULL,0,pos);  
   b7[pos] = iOpen(NULL,0,pos);
   b8[pos] = iClose(NULL,0,pos);
     }
 }
 } 
//----
 return(0);
}

void ResetBuffers(int shift) 
{
 b1[shift] = EMPTY_VALUE;
 b2[shift] = EMPTY_VALUE;
 b3[shift] = EMPTY_VALUE;
 b4[shift] = EMPTY_VALUE;
 b5[shift] = EMPTY_VALUE;
 b6[shift] = EMPTY_VALUE;
 b7[shift] = EMPTY_VALUE;
 b8[shift] = EMPTY_VALUE;
 return;
}
//+------------------------------------------------------------------+
 int Signal(int pos)
{
  int Precding=pos+2;
  int Deceding=pos+1;
  double signalCandleClose=Close[pos];
  if((iClose(Symbol(),PERIOD_D1,Precding)<iOpen(Symbol(),PERIOD_D1,Precding))
   && (iClose(Symbol(),PERIOD_D1,Deceding)>iOpen(Symbol(),PERIOD_D1,Deceding))
   &&
   !(
    (iClose(Symbol(),PERIOD_D1,Precding+1)>iOpen(Symbol(),PERIOD_D1,Precding+1))
   && (iClose(Symbol(),PERIOD_D1,Deceding+1)<iOpen(Symbol(),PERIOD_D1,Deceding+1))
   )
   )
    return 1;
  else if( (iClose(Symbol(),PERIOD_D1,Precding)>iOpen(Symbol(),PERIOD_D1,Precding))
   && (iClose(Symbol(),PERIOD_D1,Deceding)<iOpen(Symbol(),PERIOD_D1,Deceding))
    &&
   !(
    (iClose(Symbol(),PERIOD_D1,Precding+1)<iOpen(Symbol(),PERIOD_D1,Precding+1))
   && (iClose(Symbol(),PERIOD_D1,Deceding+1)>iOpen(Symbol(),PERIOD_D1,Deceding+1))
   )
   
   )
   return -1 ;
  else return 0;
}//------------END FUNCTION-------------
