//+------------------------------------------------------------------+
//|                                             BullBear_Pipsize.mq4 |
//|                                           BlueRainfx@hotmail.com |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window

extern int  barcount = 50;

extern string _PipText  = "----Set to show Pip Size Text";
extern color linecolor = clrYellow;
extern int  PipTextAngle = 60;

double point = Point;
string LabelID = "PipID_";
  double timeX = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{

 if((Digits==3) || (Digits==5))
     {
      point = Point*10;
     }
     

  
  if(Period()==1   )timeX=60;if(Period()==5    )timeX=300;if(Period()==15   )timeX=900;
  if(Period()==30  )timeX=1800;if(Period()==60   )timeX=3600;if(Period()==240  )timeX=14400;
  if(Period()==1440)timeX=86400;if(Period()==10080)timeX=604800;if(Period()==43200)timeX=2592000;
  
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{

 DeleteObjects();
     
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   
  
   DeleteObjects();
   WindowRedraw();
    
   int i,limit;
   if ( Bars < barcount ) return (-1);
   
   
   limit=barcount;
   
  
        
   double Range = 0;
   int largestindex = 0;
   double largestRange = 0;
   
   int lowest = iLowest(Symbol(),0,MODE_LOW,barcount,0);
   int highest = iHighest(Symbol(),0,MODE_HIGH,barcount,0);
   
            
   //draw now
    DrawLine(lowest, Time[barcount], Time[0]+ (datetime) timeX*5,Low[lowest],Low[lowest]);
    DrawLine(highest,Time[barcount], Time[0]+ (datetime) timeX*5,High[highest],High[highest]);
   
    
    
    
   
             
 
      
   
   
   
//----
   return(0);
}


void DrawPipNumbers(int i,double pip,color textcolor)
{
 double atr=iATR(NULL,0,100,i); 
  string sObjName=StringConcatenate( LabelID + ":Pip", IntegerToString(i));
  
  if (ObjectFind(sObjName) ) ObjectDelete(sObjName);
  
  ObjectCreate(sObjName, OBJ_TEXT, 0, Time[i], High[i]+atr);
  ObjectSet(sObjName, OBJPROP_ANGLE, PipTextAngle);
  ObjectSetText(sObjName,DoubleToStr(pip,2),10, "Corbel", textcolor);

}




void DrawHPipNumbers(int i,int count,double pip,color textcolor)
{
   

  string sObjName=StringConcatenate( LabelID + ":PipH", IntegerToString(i));
  
  if (ObjectFind(sObjName) ) ObjectDelete(sObjName);
  
  ObjectCreate(sObjName, OBJ_TEXT, 0, Time[i]+timeX*3,(High[i]+Low[i])/2);
  ObjectSet(sObjName, OBJPROP_ANGLE, 0);
  ObjectSetText(sObjName,DoubleToStr(pip,2) + "/" + IntegerToString(count)+"Bars" ,13, "Corbel", textcolor);

}


//+------------------------------------------------------------------+

void DeleteObjects()
{
   string lookFor       = LabelID;
   int    lookForLength = StringLen(lookFor);
   for (int i=ObjectsTotal()-1; i>=0; i--)
   {
      string objectName = ObjectName(i);
      if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
      
      WindowRedraw();
   }
}


void DrawLine(int i, datetime Time1, datetime Time2, double Price1, double Price2)
{
         
         double atr=iATR(NULL,0,100,i); 
         string name=StringConcatenate( LabelID + ":Line", IntegerToString(i),"_", TimeToStr(TimeCurrent()) ) ;
  
  
          if ( ObjectFind(name))  ObjectDelete(name);
          WindowRedraw(); 
            
          ObjectCreate(name,OBJ_TREND,0,Time1,0,Time2,0);
          ObjectSet(name,OBJPROP_COLOR,linecolor);
          ObjectSet(name,OBJPROP_WIDTH,2);
          
          ObjectSet(name,OBJPROP_STYLE,STYLE_SOLID);
          ObjectSet(name,OBJPROP_RAY,false);
          ObjectSet(name,OBJPROP_PRICE1,Price1);
          ObjectSet(name,OBJPROP_PRICE2,Price2);
          WindowRedraw();
          
                    

}  
