//+------------------------------------------------------------------+
//| Indicator Notes                                                  |
/*| */
//+------------------------------------------------------------------+

//Technical Indicator Comments
#property copyright "PureFX2016"



#property indicator_separate_window        //show the indicator in a separate window 
//
#property indicator_buffers 2

//the color for displaying line N, where N lies between 1 and 8
#property indicator_color1 clrRed
#property indicator_color2 clrWhite
//
               

string    indName="Heiken Accuracy";                     // Indicator Name
//---- buffers
double ExtMapBuffer0[];
double ExtMapBuffer1[];

extern int Bars_Look_Back = 700;
double var1 = 0;
double win = 0;
double cnt = 0;
double LastCheck =0;

int FixZeroD=0;

int init()
  {
//---- indicators setup

SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);

SetIndexBuffer(0,ExtMapBuffer0);

SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);

SetIndexBuffer(1,ExtMapBuffer1);

//
var1 = 0;
win = 0;
cnt = 0;
LastCheck =0;


IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));	   
   


   return(0);
  } 

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   Comment("");
//----
   return(0);
  }

  
  //--------------------------------------------------------------------
int start()                         
  {
   int i,Counted_bars;                 

//--------------------------------------------------------------------

   Counted_bars=IndicatorCounted();  
   i=Bars-Counted_bars-1; 
   if(Counted_bars == 0) 
       i = Bars -1 -FixZeroD; 
   double sum=0;
              
   while(i>=0)                      
     {
     
      double HaDown = iCustom(NULL,0,"Heiken Ashi",clrRed,clrWhite,clrRed,clrWhite,2,i+2);
      double HaUp = iCustom(NULL,0,"Heiken Ashi",clrRed,clrWhite,clrRed,clrWhite,3,i+2);
      double HaDownBody = iCustom(NULL,0,"Heiken Ashi",clrRed,clrWhite,clrRed,clrWhite,0,i+2);
      double HaUpBody = iCustom(NULL,0,"Heiken Ashi",clrRed,clrWhite,clrRed,clrWhite,1,i+2);
      
      
      if ((i <= Bars_Look_Back) && (Time[i] != LastCheck)) {
      
      if (HaUp < HaDownBody) {
      cnt++;
            if (Close[i+1] < Open[i+1]) { win++; }
      }
      
      if (HaDown < HaUpBody) {
      cnt++;
            if (Close[i+1] > Open[i+1]) { win++; }
      }
      
      if ((cnt != 0 ) && (win!=0)) { var1 = (100/cnt)*win; }

      LastCheck = Time[i];
      } 

     
      ExtMapBuffer0[i] = cnt;
      ExtMapBuffer1[i] = win;
      Comment("Accuracy : ",var1,"%");
                     
      i--;                          
     }
//--------------------------------------------------------------------
   return(0);                          
  }
//--------------------------------------------------------------------
