//+------------------------------------------------------------------+
//|                                             Profit_Loss_Info.mq4 |
//|                                                    Goldexcalibur |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Goldexcalibur"
#property link      ""

#property indicator_chart_window
extern int Corner=3;
 int Font=9;
int x = NULL;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   int    idx;

   if(x != NULL) {
      for(idx = 0; idx<x; idx++) {
         ObjectDelete("O"+idx);
         ObjectDelete("PL"+idx);
      }
            
      ObjectDelete("h");      
      ObjectDelete("Total1");
      ObjectDelete("Total2");
   }

//----
   return(0);
  }
  
void DisplayText(string objname, string text, int fontsize, color clr, double C, double X, double Y, string font)
{
   ObjectDelete(objname);
   ObjectCreate(objname, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(objname, text, fontsize, font, clr);
   ObjectSet(objname, OBJPROP_CORNER, Corner);
   ObjectSet(objname, OBJPROP_XDISTANCE, X);
   ObjectSet(objname, OBJPROP_YDISTANCE, Y);
}


  
//+------------------------------------------------------------------+
//| Custom indicator literation function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int    j;
   int    idx;
   string text;
   double PL;
   double total;
//----
         if(x != NULL) {
            for(idx = 0; idx<x; idx++) {
               ObjectDelete("O"+idx);
               ObjectDelete("PL"+idx);
            }
            
            ObjectDelete("Total1");
            ObjectDelete("Total2");
         }
            
         text = "";
         j=0;
         total = 0;
         
         
                  
   
         DisplayText("h", "Profit/Loss Info ", Font, Gold, 0, 5, 15 , "Arial Bold"); 
   
         for (int i = OrdersTotal()-1 ; i >= 0; i--) 
         { 
            if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
            { 
               
               if(OrderType() == OP_BUY)  {
                  DisplayText("O"+j, OrderSymbol() + " (" + OrderTicket() + ")" + "   ", Font, Lime, 0, 5, Font+35 + j * 18, "Arial Bold"); 
                  
                  PL = (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);
                  total = total + PL;
                  if(PL<0) DisplayText("PL"+j, DoubleToStr(PL, 0), Font, Red, 0, 140, Font+35 + j * 18, "Arial Bold"); 
                  else if(PL>0) DisplayText("PL"+j, "+"+DoubleToStr(PL, 0), Font, Lime, 0, 140, Font+35 + j * 18, "Arial Bold"); 
                  else DisplayText("PL"+j, DoubleToStr(PL, 0), Font, White, 0, 140, Font+35 + j * 18, "Arial Bold"); 
               }
               else if(OrderType() == OP_SELL)  {
                  DisplayText("O"+j, OrderSymbol() + " (" + OrderTicket() + ")" + "   ", Font, Red, 0, 5, Font+35 + j * 18, "Arial Bold"); 
                  
                  PL = (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT);
                  total = total + PL;
                  if(PL<0) DisplayText("PL"+j, DoubleToStr(PL, 0) , Font, Red, 0, 140, Font+35 + j * 18, "Arial Bold"); 
                  else if(PL>0) DisplayText("PL"+j,"+"+DoubleToStr(PL, 0) , Font, Lime, 0, 140, Font+35 + j * 18, "Arial Bold"); 
                  else DisplayText("PL"+j,DoubleToStr(PL, 0) , Font, White, 0, 140, Font+35 + j * 18, "Arial Bold"); 
               }
               j=j+1;
            } 
         } 
   
         DisplayText("Total1","Total Profit/Loss  ", Font, Gold, 0, 5, Font+35 + j * 18, "Arial Bold");
   
         if(total<0) DisplayText("Total2", DoubleToStr(total, 0) , Font, Red, 0, 140, Font+35 + j * 18, "Arial Bold");
         else if (total>0) DisplayText("Total2","+" + DoubleToStr(total, 0) , Font, Lime, 0, 140, Font+35 + j * 18, "Arial Bold");
         else DisplayText("Total2", DoubleToStr(total, 0) , Font, White, 0, 140, Font+35 + j * 18, "Arial Bold");
         
         x=j;
   
//----
   return(0);
  }
//+------------------------------------------------------------------+