//+------------------------------------------------------------------+
//|                                            shetchik_pips.mq4     |
//|                                        Copyright © 2012, FOX.RM  |
//|                                             fox.rm@mail.ru       |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, FOX.RM"
#property link      "http://www.niochem.net"

#property indicator_chart_window

int old_price, old_del, sum_pip_bay, sum_pip_sell, price, delta;
int old_sell=0, old_bay = 0;

int init() {return(0);}
int deinit() {
   Dell(); 
  return(0);
}

int start() {
  
  int counted_bars=IndicatorCounted();   
  if(counted_bars<0) return(-1);
  if(counted_bars>0) counted_bars--;
 int limit=Bars-counted_bars;
   
  if(limit>0) limit=0;
   
  for(int i=limit; i>=0; i--) {
    price = Close[i]/Point;    
    delta = price-old_price; //-- разница пунктов за тик
 
         //-- условие для ап пунктов
    if(delta>=0) { 
           if(delta>100) delta=0;
    sum_pip_bay = delta + old_bay;   
     old_bay=sum_pip_bay;
        } 
      //-- условие для даун пунктов
    if(delta<0) { 
     
    sum_pip_sell = delta+old_sell;
     old_sell=sum_pip_sell;
      }          
     //----
    old_price=price;
    }
    int sum_pip = MathAbs(sum_pip_sell) + sum_pip_bay;
     //---- размещаем счетчик на графике
 string name_1 = "shetchik_ ";
   
   SetText1(name_1+"pip_sell",DoubleToStr(MathAbs(sum_pip_sell),0),Blue,14);
   SetText2(name_1+"pip_bay",DoubleToStr(sum_pip_bay,0),Red,14);
   SetText(name_1+"pip_sum",DoubleToStr(sum_pip,0),Black,14); 
    

  return(0);
}

//+------------------------------------------------------------+
 void Dell (string name_n = "shetchik_ ") // -- удаление меток с графика
  {
   string vName;
   for(int i=ObjectsTotal()-1; i>=0;i--)
    {
     vName = ObjectName(i);
     if (StringFind(vName,name_n) !=-1) ObjectDelete(vName);
    }  
  } 
  void SetText2(string name,string text, color c, int size)
 {
  ObjectCreate(name,OBJ_LABEL,0,0,0,0,0);     
  ObjectSet(name, OBJPROP_XDISTANCE, 1100);
  ObjectSet(name, OBJPROP_YDISTANCE, 80);    
  ObjectSetText(name,text,6,"Arial Black",c);
 }
void SetText1(string name,string text, color c, int size)
 {
  ObjectCreate(name,OBJ_LABEL,0,0,0,0,0);     
  ObjectSet(name, OBJPROP_XDISTANCE, 1150);
  ObjectSet(name, OBJPROP_YDISTANCE, 80);    
  ObjectSetText(name,text,6,"Arial Black",c);
 }
 void SetText(string name,string text, color c, int size)
 {
  ObjectCreate(name,OBJ_LABEL,0,0,0,0,0);     
  ObjectSet(name, OBJPROP_XDISTANCE, 1200);
  ObjectSet(name, OBJPROP_YDISTANCE, 80);    
  ObjectSetText(name,text,6,"Arial Black",c);
 }
//---- 

