//+------------------------------------------------------------------+
//|                                             Profit_Loss_Info.mq4 |
//|                                                    Goldexcalibur |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Goldexcalibur"
#property link      ""

#property indicator_chart_window
extern int Corner=0;
extern color Warna_Text       = Gold;
extern color Warna_Order_Sell = Tomato;
extern color Warna_Order_Buy  = LimeGreen;
extern color Warna_Rugi       = LightSalmon;
extern color Warna_Laba       = LightGreen;
extern bool  Show_Money       = false;
extern bool  Show_Account     = false;
extern string NamaFont        = "Verdana Bold";
extern int    UkuranFont      = 10;
extern double posX            =  5;
extern double posY            = 15;

int Font=9;
int x = NULL;
double Bal, Equ, mrg, fmrg;

//+------------------------------------------------------------------+
//| 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");
   }
   
   ObjectsDeleteAll(0,OBJ_HLINE);
   ObjectsDeleteAll(0,OBJ_TEXT);
   ObjectsDeleteAll(0,OBJ_LABEL); 

//----
   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 iteration 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, Warna_Text, 0, 10, 15 , NamaFont); 
   
         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, Warna_Order_Buy, 0, 5, Font+35 + j * 18, "Arial Bold"); 
                  
                  DisplayText("O"+j, "Buy "+OrderSymbol() + "          = ", Font, Warna_Order_Buy, 0, 10, Font+30 + j * 18, "Arial Bold"); 
                  PL = ( (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT) )/10;
                  total = total + PL;
                  if(PL<0) DisplayText("PL"+j, DoubleToStr(PL, 1)+" pips", Font, Warna_Rugi, 0, 120, Font+30 + j * 18, "Arial Bold"); 
                  else if(PL>0) DisplayText("PL"+j, "+"+DoubleToStr(PL, 1)+" pips", Font, Warna_Laba, 0, 120, Font+30 + j * 18, "Arial Bold"); 
                  else DisplayText("PL"+j, DoubleToStr(PL, 1)+" pips", Font, Warna_Text, 0, 120, Font+30 + j * 18, "Arial Bold"); 
               }
               else if(OrderType() == OP_SELL)  {
                  //DisplayText("O"+j, OrderSymbol() + " (" + OrderTicket() + ")" + "   ", Font, Warna_Order_Sell, 0, 5, Font+35 + j * 18, "Arial Bold"); 
                  DisplayText("O"+j, "Sell "+OrderSymbol() + "         = ", Font, Warna_Order_Sell, 0, 10, Font+30 + j * 18, "Arial Bold"); 
                  PL = ( (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT) ) /10;
                  total = total + PL;
                  if(PL<0) DisplayText("PL"+j, DoubleToStr(PL, 1)+" pips" , Font, Warna_Rugi, 0, 120, Font+30 + j * 18, "Arial Bold"); 
                  else if(PL>0) DisplayText("PL"+j,"+"+DoubleToStr(PL, 1)+" pips" , Font, Warna_Laba, 0, 120, Font+30 + j * 18, "Arial Bold"); 
                  else DisplayText("PL"+j,DoubleToStr(PL, 1)+" pips" , Font, Warna_Text, 0, 120, Font+30 + j * 18, "Arial Bold"); 
               }
               j=j+1;
            } 
         } 
   
         DisplayText("Total1","Total Profit/Loss  = ", Font, Warna_Text, 0, 10, Font+30 + j * 18, "Arial Bold");
   
         if(total<0) DisplayText("Total2", DoubleToStr(total, 1)+" pips" , Font, Warna_Rugi, 0, 118, Font+30 + j * 18, "Arial Bold");
         else if (total>0) DisplayText("Total2","+" + DoubleToStr(total, 1)+" pips" , Font, Warna_Laba, 0, 118, Font+30 + j * 18, "Arial Bold");
         else DisplayText("Total2", DoubleToStr(total, 1)+" pips" , Font, White, 0, 118, Font+30 + j * 18, "Arial Bold");
         
         if (Show_Money)
            {
             double PLuang=AccountEquity()-AccountBalance();
             if (PLuang>0)
                   DisplayText("PLU", "= $ "+DoubleToStr(PLuang, 2), Font, Warna_Laba, 0, 180, Font+30 + j * 18, "Arial Bold");
                
             else if (PLuang<0)
                   DisplayText("PLU", "= $ "+DoubleToStr(PLuang, 2), Font, Warna_Rugi, 0, 180, Font+30 + j * 18, "Arial Bold");
             else DisplayText("PLU", "= $ "+DoubleToStr(PLuang, 2), Font, Warna_Text, 0, 180, Font+30 + j * 18, "Arial Bold");
            }
            
         x=j;
         
         if (Show_Account)
            {
             Bal  = AccountBalance();
             Equ  = AccountEquity();
             mrg  = AccountMargin();
             fmrg = AccountFreeMargin();
             DisplayText("MyBal",  "Balance = $" + DoubleToStr(Bal, 2), Font, DimGray, 0, 10, Font+50 + j * 18, "Arial Bold");
             DisplayText("MyEqu",  "Equity     = $" + DoubleToStr(Equ, 2), Font, DimGray, 0, 10, Font+65 + j * 18, "Arial Bold");
             DisplayText("MyMrg",  "Margin   = $" + DoubleToStr(mrg, 2), Font, DimGray, 0, 10, Font+80 + j * 18, "Arial Bold");
             DisplayText("MyFmrg", "Free Margin = $" + DoubleToStr(fmrg, 2), Font, DimGray, 0, 10, Font+95 + j * 18, "Arial Bold");
             DisplayText("MyLvl",  "Margin Level = " + DoubleToStr(((fmrg/mrg)*100)+100, 2)+ " %", Font, DimGray, 0, 10, Font+110 + j * 18, "Arial Bold");
            }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+