//+------------------------------------------------------------------+
//|                                                   pipcounter.mq4 |
//|                                                  Forex-Tests.com |
//|                                        http://www.forex-tests.com|
//+------------------------------------------------------------------+
#property link      "http://www.forex-tests.com"

#property indicator_chart_window

double PCPoint = 10000;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if( Digits == 2 || Digits == 3)
     PCPoint = 100;
   else
      PCPoint = 10000;  
  return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double counter = 0, previouscounter = 0; 
   int index = 0;
   double lots = 0.0, previouslots = 0.0;
   
   for(index = 0; index < OrdersTotal();index++)   // search  in the order pool
      {
         OrderSelect(index,SELECT_BY_POS,MODE_TRADES);
            {  
                       if(OrderType() == OP_BUY)
                           {
                               counter = counter + (OrderClosePrice() - OrderOpenPrice()) * PCPoint * OrderLots() * 10;
                               lots = lots + OrderLots();
                           }
                       else if(OrderType() == OP_SELL)
                           {
                               counter = counter + (OrderOpenPrice() - OrderClosePrice()) * PCPoint * OrderLots() * 10;
                               lots = lots + OrderLots();
                           }
            }
      }

   for(index = 0; index <  OrdersHistoryTotal();index++)   // search  in history pool 
      {
         if(OrderSelect(index,SELECT_BY_POS,MODE_HISTORY))
           { 
                 datetime DayStart = StrToTime("00:00");
                 datetime PreviousDayStart = DayStart - 3600 * 24;
                 if(OrderCloseTime() > DayStart)
                     {
                       if(OrderType() == OP_BUY)
                           {
                               counter = counter + (OrderClosePrice() - OrderOpenPrice()) * PCPoint * OrderLots() * 10;
                               lots = lots + OrderLots();
                           }
                       else if(OrderType() == OP_SELL)
                           {
                               counter = counter + (OrderOpenPrice() - OrderClosePrice()) * PCPoint * OrderLots() * 10;
                               lots = lots + OrderLots();
                           }
                     }
                else if((OrderCloseTime() > PreviousDayStart) && (OrderCloseTime() < DayStart)) // Previus day pips
                     {
                          if(OrderType() == OP_BUY)
                           {
                               previouscounter = previouscounter + (OrderClosePrice() - OrderOpenPrice()) * PCPoint * OrderLots() * 10;
                               previouslots = previouslots + OrderLots();
                           }
                          else if(OrderType() == OP_SELL)
                           {
                               previouscounter = previouscounter + (OrderOpenPrice() - OrderClosePrice()) * PCPoint * OrderLots() * 10;
                               previouslots = previouslots + OrderLots();
                           }
                     }
           }
      }
   Comment("\n Today Pips: ",counter,"\n Today Lots: ",lots,"\n Yesterday Pips: ",previouscounter,"\n Yesterday Lots: ",previouslots);   
   return(0);
  }
//+------------------------------------------------------------------+

