//+------------------------------------------------------------------+
//|                                                      candlea.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert Deinizialiation Funtion                 |
//+------------------------------------------------------------------+
void OnDeinit (const int reason)
{


}
//+------------------------------------------------------------------+
//| Expert Funtion                 |
//+------------------------------------------------------------------+
void OnTick()
   {
      
               
      bool c1 = Bearis_Bullish(Open[1], Close[1]);
      bool c2 = Bearis_Bullish(Open[2], Close[2]);
      bool c3 = Bearis_Bullish(Open[3], Close[3]);
      
      double Upper_Distance1, Lower_Distance1, Body_Distance1, total1, UpperPer1, LowerPer1, BodyPer1;
      double Upper_Distance2, Lower_Distance2, Body_Distance2, total2, UpperPer2, LowerPer2, BodyPer2;
      double Upper_Distance3, Lower_Distance3, Body_Distance3, total3, UpperPer3, LowerPer3, BodyPer3;
      
      
      if(c1= true)
         {
            Upper_Distance1 = NormalizeDouble(MathAbs(High[1]-Close[1]), Digits);
            Lower_Distance1 = NormalizeDouble(MathAbs(Open[1]-Low[1]), Digits);
            Body_Distance1 = NormalizeDouble(MathAbs(Open[1]-Close[1]), Digits);
            total1 = NormalizeDouble(MathAbs(High[1]-Low[1]), Digits); 
            UpperPer1 = (Upper_Distance1*100)/total1;
            LowerPer1 = (Lower_Distance1*100)/total1;
            BodyPer1 =  (Body_Distance1*100)/total1;
            Display_Info("ABC55", "UpperPercentage " + UpperPer1, 95,20, Blue);
            Display_Info("ABC66", "LowerPercentage " + LowerPer1, 110,20, Blue);
            Display_Info("ABC77", "BodyPercentage " + BodyPer1, 125,20, Blue);
            
            Display_Info("ABC", "Previous Candle was Bullish", 20, 20, Red);
            Display_Info("ABC11", "UpperDistance " + Upper_Distance1 , 35, 20, Red);
            Display_Info("ABC22", "LowerDistance " + Lower_Distance1, 50, 20, Red);
            Display_Info("ABC33", "BodyDistance " + Body_Distance1, 65, 20, Red);
            Display_Info("ABC44", "TotalDistance " + total1, 80, 20, Red);
            
            WindowRedraw();
            }
            else if(c1==false)
               {
               Upper_Distance1 = NormalizeDouble(MathAbs(High[1]-Open[1]), Digits);
               Lower_Distance1 = NormalizeDouble(MathAbs(Close[1]-Low[1]), Digits);
               Body_Distance1 = NormalizeDouble(MathAbs(Open[1]-Close[1]), Digits);
               total1 = NormalizeDouble(MathAbs(High[1]-Low[1]), Digits); 
               UpperPer1 = (Upper_Distance1*100)/total1;
               LowerPer1 = (Lower_Distance1*100)/total1;
               BodyPer1 =  (Body_Distance1*100)/total1;
               Display_Info("ABC55", "UpperPercentage " + UpperPer1, 95, 20, Blue);
               Display_Info("ABC66", "LowerPercentage " + LowerPer1, 110, 20, Blue);
               Display_Info("ABC77", "BodyPercentage " + BodyPer1, 125, 20, Blue);
               
               Display_Info("ABC", "Previous Candle was Bearish", 20, 20, White);
               Display_Info("ABC11", "UpperDistance " + Upper_Distance1 , 35, 20, White);
               Display_Info("ABC22", "LowerDistance " + Lower_Distance1, 50, 20, White);
               Display_Info("ABC33", "BodyDistance " + Body_Distance1, 65, 20, White);
               Display_Info("ABC44", "TotalDistance " + total1, 80, 20, White);
               WindowRedraw();
               
               }
               
               else
               {
                  Upper_Distance1 = NormalizeDouble(MathAbs(High[1]-Close[1]), Digits);
                  Lower_Distance1 = NormalizeDouble(MathAbs(Open[1]-Low[1]), Digits);
                  Body_Distance1 = NormalizeDouble(MathAbs(Open[1]-Close[1]), Digits);
                  total1 = NormalizeDouble(MathAbs(High[1]-Low[1]), Digits); 
                  UpperPer1 = (Upper_Distance1*100)/total1;
                  LowerPer1 = (Lower_Distance1*100)/total1;
                  BodyPer1 =  (Body_Distance1*100)/total1;
                  Display_Info("ABC55", "UpperPercentage " + UpperPer1, 95, 20, Blue);
                  Display_Info("ABC66", "LowerPercentage " + LowerPer1, 110, 20, Blue);
                  Display_Info("ABC77", "BodyPercentage " + BodyPer1, 125, 20, Blue);
                  
                  Display_Info("ABC", "Previous Candle was Doji", 20, 20, White);
                  Display_Info("ABC11", "UpperDistance " + Upper_Distance1 , 35, 20, White);
                  Display_Info("ABC22", "LowerDistance " + Lower_Distance1, 50, 20, White);
                  Display_Info("ABC33", "BodyDistance " + Body_Distance1, 65, 20, White);
                  Display_Info("ABC44", "TotalDistance " + total1, 80, 20, White);
                  WindowRedraw();
                  }
               
      ////////
      
      if(c2==true)
      
         {
         
            Upper_Distance2 = NormalizeDouble(MathAbs(High[2]-Close[2]), Digits);
            Lower_Distance2 = NormalizeDouble(MathAbs(Open[2]-Low[2]), Digits);
            Body_Distance2 = NormalizeDouble(MathAbs(Open[2]-Close[2]), Digits);
            total2 = NormalizeDouble(MathAbs(High[2]-Low[2]), Digits); 
            UpperPer2 = (Upper_Distance2*100)/total2;
            LowerPer2 = (Lower_Distance2*100)/total2;
            BodyPer2 =  (Body_Distance2*100)/total2;
            Display_Info("ABC551", "UpperPercentage " + UpperPer2, 95, 350, Blue);
            Display_Info("ABC661", "LowerPercentage " + LowerPer2, 110, 350, Blue);
            Display_Info("ABC771", "BodyPercentage " + BodyPer2, 125, 350, Blue); 
                  
            Display_Info("ABC111", "UpperDistance " + Upper_Distance2 , 35, 350, Blue);
            Display_Info("ABC221", "LowerDistance " + Lower_Distance2, 50, 350, Blue);
            Display_Info("ABC331", "BodyDistance " + Body_Distance2, 65, 350, Blue);
            Display_Info("ABC441", "TotalDistance " + total2, 80, 350, Blue);
            Display_Info("ABC1", "Previous Candle was Bullish", 20, 350, Blue);
            WindowRedraw ();
         }
         
         else if(c2==false)
            {
            
               Upper_Distance2 = NormalizeDouble(MathAbs(High[2]-Open[2]), Digits);
               Lower_Distance2 = NormalizeDouble(MathAbs(Close[2]-Low[2]), Digits);
               Body_Distance2 = NormalizeDouble(MathAbs(Open[2]-Close[2]), Digits);
               total2 = NormalizeDouble(MathAbs(High[2]-Low[2]), Digits); 
               UpperPer2 = (Upper_Distance2*100)/total2;
               LowerPer2 = (Lower_Distance2*100)/total2;
               BodyPer2 =  (Body_Distance2*100)/total2;
               Display_Info("ABC551", "UpperPercentage " + UpperPer2, 95, 350, Blue);
               Display_Info("ABC661", "LowerPercentage " + LowerPer2, 110, 350, Blue);
               Display_Info("ABC771", "BodyPercentage " + BodyPer2, 125, 350, Blue);       
               Display_Info("ABC111", "UpperDistance " + Upper_Distance2 , 35, 350, Red);
               Display_Info("ABC221", "LowerDistance " + Lower_Distance2, 50, 350, Red);
               Display_Info("ABC331", "BodyDistance " + Body_Distance2, 65, 350, Red);
               Display_Info("ABC441", "TotalDistance " + total2, 80, 350, Red);
               Display_Info("ABC1", "Previous Candle was Bearish", 20, 350, Red);
               WindowRedraw ();
               
            }
            else
               {
                  Upper_Distance2 = NormalizeDouble(MathAbs(High[2]-Close[2]), Digits);
                  Lower_Distance2 = NormalizeDouble(MathAbs(Open[2]-Low[2]), Digits);
                  Body_Distance2 = NormalizeDouble(MathAbs(Open[2]-Close[2]), Digits);
                  total2 = NormalizeDouble(MathAbs(High[2]-Low[2]), Digits); 
                  UpperPer2 = (Upper_Distance2*100)/total2;
                  LowerPer2 = (Lower_Distance2*100)/total2;
                  BodyPer2 =  (Body_Distance2*100)/total2;
                  Display_Info("ABC551", "UpperPercentage " + UpperPer2, 95, 350, Blue);
                  Display_Info("ABC661", "LowerPercentage " + LowerPer2, 110, 350, Blue);
                  Display_Info("ABC771", "BodyPercentage " + BodyPer2, 125, 350, Blue);       
                  Display_Info("ABC111", "UpperDistance " + Upper_Distance2 , 35, 350, White);
                  Display_Info("ABC221", "LowerDistance " + Lower_Distance2, 50, 350, White);
                  Display_Info("ABC331", "BodyDistance " + Body_Distance2, 65, 350, White);
                  Display_Info("ABC441", "TotalDistance " + total2, 80, 350, White);
                  Display_Info("ABC1", "Previous Candle was Doji", 20, 350, White);
                  WindowRedraw ();
               }
               
               ////////
      
      if(c3==true)
      
         {
         
            Upper_Distance3 = NormalizeDouble(MathAbs(High[3]-Close[3]), Digits);
            Lower_Distance3 = NormalizeDouble(MathAbs(Open[3]-Low[3]), Digits);
            Body_Distance3 = NormalizeDouble(MathAbs(Open[3]-Close[3]), Digits);
            total3 = NormalizeDouble(MathAbs(High[3]-Low[3]), Digits); 
            UpperPer3 = (Upper_Distance2*100)/total3;
            LowerPer3 = (Lower_Distance2*100)/total3;
            BodyPer3 =  (Body_Distance2*100)/total3;
            Display_Info("ABC552", "UpperPercentage " + UpperPer3, 95, 680, Blue);
            Display_Info("ABC662", "LowerPercentage " + LowerPer3, 110, 680, Blue);
            Display_Info("ABC772", "BodyPercentage " + BodyPer3, 125, 680, Blue); 
                  
            Display_Info("ABC112", "UpperDistance " + Upper_Distance3 , 35, 680, Blue);
            Display_Info("ABC222", "LowerDistance " + Lower_Distance3, 50, 680, Blue);
            Display_Info("ABC332", "BodyDistance " + Body_Distance3, 65, 680, Blue);
            Display_Info("ABC442", "TotalDistance " + total3, 80, 680, Blue);
            Display_Info("ABC2", "Previous Candle was Bullish", 20, 680, Blue);
            WindowRedraw ();
         }
         
         else if(c3==false)
            {
            
               Upper_Distance3 = NormalizeDouble(MathAbs(High[3]-Open[3]), Digits);
               Lower_Distance3 = NormalizeDouble(MathAbs(Close[3]-Low[3]), Digits);
               Body_Distance3 = NormalizeDouble(MathAbs(Open[3]-Close[3]), Digits);
               total3 = NormalizeDouble(MathAbs(High[3]-Low[3]), Digits); 
               UpperPer3 = (Upper_Distance3*100)/total3;
               LowerPer3 = (Lower_Distance3*100)/total3;
               BodyPer3 =  (Body_Distance3*100)/total3;
               Display_Info("ABC552", "UpperPercentage " + UpperPer3, 95, 680, Blue);
               Display_Info("ABC662", "LowerPercentage " + LowerPer3, 110, 680, Blue);
               Display_Info("ABC772", "BodyPercentage " + BodyPer3, 125, 680, Blue);       
               Display_Info("ABC112", "UpperDistance " + Upper_Distance3 , 35, 680, Red);
               Display_Info("ABC222", "LowerDistance " + Lower_Distance3, 50, 680, Red);
               Display_Info("ABC332", "BodyDistance " + Body_Distance3, 65, 680, Red);
               Display_Info("ABC442", "TotalDistance " + total3, 80, 680, Red);
               Display_Info("ABC2", "Previous Candle was Bearish", 20, 680, Red);
               WindowRedraw ();
               
            }
            else
               {
                  Upper_Distance3 = NormalizeDouble(MathAbs(High[3]-Close[3]), Digits);
                  Lower_Distance3 = NormalizeDouble(MathAbs(Open[3]-Low[3]), Digits);
                  Body_Distance3 = NormalizeDouble(MathAbs(Open[3]-Close[3]), Digits);
                  total3 = NormalizeDouble(MathAbs(High[3]-Low[3]), Digits); 
                  UpperPer3 = (Upper_Distance3*100)/total3;
                  LowerPer3 = (Lower_Distance2*100)/total3;
                  BodyPer3 =  (Body_Distance2*100)/total3;
                  Display_Info("ABC552", "UpperPercentage " + UpperPer3, 95, 680, Blue);
                  Display_Info("ABC662", "LowerPercentage " + LowerPer3, 110, 680, Blue);
                  Display_Info("ABC772", "BodyPercentage " + BodyPer3, 125, 680, Blue);       
                  Display_Info("ABC112", "UpperDistance " + Upper_Distance3 , 35, 680, White);
                  Display_Info("ABC222", "LowerDistance " + Lower_Distance3, 50, 680, White);
                  Display_Info("ABC332", "BodyDistance " + Body_Distance3, 65, 680, White);
                  Display_Info("ABC442", "TotalDistance " + total3, 80, 680, White);
                  Display_Info("ABC2", "Previous Candle was Doji", 85, 680, White);
                  WindowRedraw ();
               }
               
}


void Display_Info(string label_, double digit_, int y_ , int x_ , color) 
{
 
 ObjectDelete (label_);
 ObjectCreate (label_, OBJ_LABEL, 0, 0, 0);
 ObjectSetText (label_, digit_ );
 ObjectSet (label_, OBJPROP_YDISTANCE, y_ );
 ObjectSet (label_, OBJPROP_XDISTANCE, x_ ); 

    
      
return;  
                  
}      
      
              ///////////////////////////////////////////////////////////
              ///////////////// Patterns Conditions /////////////////////
              
              
              /////////////////////// Engulfing Down ///////////////////////