//+------------------------------------------------------------------+
//|                                                                  |
//|         BAR-LENGTH                                               |
//|         by ANGUS.                                                |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2009"
#property link      "Angus of ForexFactory.com"

#property indicator_chart_window
 

extern int   Which_Cnr           = 0;
extern int   Shift_UP_DN         = 0;
extern int   Adjust_Side_to_side = 0;
extern color Prc_Up_Color        = MediumSeaGreen;
extern color Prc_Dn_Color        = DarkSalmon;
extern color CommentLabel_Colour  = White;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll(0,OBJ_LABEL); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    //Info 
   color  PrcColor;
   string PRC1;
   double Price1 = iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0);
   double xec=1; if(Digits==5||Digits==3){xec=10;}
   double PrcOpen = iOpen(NULL,0,0);
   double PrcClose = iClose(NULL,0,0);
     
    PRC1 = DoubleToStr(Price1,Digits);
    
    if (PrcOpen > PrcClose) PrcColor = Prc_Dn_Color;
    if (PrcOpen < PrcClose) PrcColor = Prc_Up_Color;
    if (PrcOpen == PrcClose) PrcColor = Silver;
          
// Price Label
  
   ObjectCreate("Price1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Price1",""+PRC1+"", 24, "Arial",  PrcColor);
   ObjectSet("Price1", OBJPROP_CORNER,Which_Cnr);
   ObjectSet("Price1", OBJPROP_XDISTANCE, 10+Adjust_Side_to_side);
   ObjectSet("Price1", OBJPROP_YDISTANCE, 10+Shift_UP_DN);     

   string TBAR="",PBAR="";
   color tbar_colour,pbar_colour;
   
   
   double TOPEN = iOpen(NULL,0,0);
   double TCLOSE = iClose(NULL,0,0);
   double TPOPEN = iOpen(NULL,0,1);
   double TPCLOSE = iClose(NULL,0,1);
  
   double point=1; if(Digits==5||Digits==3){point=10;}

   
   TBAR =  DoubleToStr(((TCLOSE-TOPEN)/point)/Point,0);
   PBAR =  DoubleToStr(((TPCLOSE-TPOPEN)/point)/Point,0);
      
     if (TCLOSE >= TOPEN) {tbar_colour = Lime;}
     if (TCLOSE < TOPEN) {tbar_colour = Red;}
     if (TPCLOSE >= TPOPEN) {pbar_colour = Lime;}
     if (TPCLOSE < TPOPEN) {pbar_colour = Red;}
     
//Info Labels
                  
              
               ObjectCreate("Info13", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info13","This Bar:", 10, "Arial",CommentLabel_Colour);
   ObjectSet("Info13", OBJPROP_CORNER,Which_Cnr);
   ObjectSet("Info13", OBJPROP_XDISTANCE, 10+Adjust_Side_to_side);
   ObjectSet("Info13", OBJPROP_YDISTANCE, 45+Shift_UP_DN);
    
   
               ObjectCreate("Info14", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info14",""+TBAR+"", 10, "Arial Bold", tbar_colour);
   ObjectSet("Info14", OBJPROP_CORNER,Which_Cnr);
   ObjectSet("Info14", OBJPROP_XDISTANCE, 70+Adjust_Side_to_side);
   ObjectSet("Info14", OBJPROP_YDISTANCE, 45+Shift_UP_DN);
    
   
               ObjectCreate("Info15", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info15","Prev Bar:", 10, "Arial",CommentLabel_Colour);
   ObjectSet("Info15", OBJPROP_CORNER,Which_Cnr);
   ObjectSet("Info15", OBJPROP_XDISTANCE, 10+Adjust_Side_to_side);
   ObjectSet("Info15", OBJPROP_YDISTANCE, 60+Shift_UP_DN);
    
   
               ObjectCreate("Info16", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info16",""+PBAR+"", 10, "Arial Bold", pbar_colour);
   ObjectSet("Info16", OBJPROP_CORNER,Which_Cnr);
   ObjectSet("Info16", OBJPROP_XDISTANCE, 70+Adjust_Side_to_side);
   ObjectSet("Info16", OBJPROP_YDISTANCE, 60+Shift_UP_DN); 



 //*****************************************************************

   return(0);
  }
//+------------------------------------------------------------------+