//+------------------------------------------------------------------+
//|                                    History tab pips analysis.mq4 |
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <WinUser32.mqh>
#include <stdlib.mqh>
#define  NL    "\n"


int   TotalTrades;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----
   start();
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----
   if (TotalTrades == OrdersHistoryTotal() ) return;
   TotalTrades = OrdersHistoryTotal();
   
   int total;
   double totalprofit;
   
   string ScreenMessage;
   string gap = "                                        ";
   
   for (int cc = 0; cc <= OrdersHistoryTotal() - 1; cc++)
   {
      OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY);
      int multiplier;
      if (MarketInfo(OrderSymbol(), MODE_DIGITS) == 2) multiplier = 10;
      if (MarketInfo(OrderSymbol(), MODE_DIGITS) == 3) multiplier = 100;
      if (MarketInfo(OrderSymbol(), MODE_DIGITS) == 4) multiplier = 1000;
      if (MarketInfo(OrderSymbol(), MODE_DIGITS) == 5) multiplier = 10000;
      if (MarketInfo(OrderSymbol(), MODE_DIGITS) == 6) multiplier = 100000;
            
      ScreenMessage = StringConcatenate(ScreenMessage, gap, OrderSymbol(), "   ");
      int profit = MathAbs(OrderOpenPrice() - OrderClosePrice() ) * multiplier;      
      if (OrderProfit() < 0) profit = -profit;
      total+= profit;
      totalprofit+= OrderProfit() + OrderSwap();
      ScreenMessage = StringConcatenate(ScreenMessage, profit, "       $", DoubleToStr(OrderProfit() + OrderSwap(), 2) );
   
      ScreenMessage = StringConcatenate(ScreenMessage, NL);
   }//for (int cc = 0; cc < OrdersHistoryTotal() - 1); cc++)
   
   ScreenMessage = StringConcatenate(ScreenMessage, gap, "Total: ", total, "    $", DoubleToStr(totalprofit, 2) ,NL);
   
   double percentage = (totalprofit / AccountBalance()) *100;
   ScreenMessage = StringConcatenate(ScreenMessage, gap, "Balance: $", AccountBalance(),NL);
   string spercent = DoubleToStr(percentage,2);
   ScreenMessage = StringConcatenate(ScreenMessage, gap, "Profit percentage in history tab: ", spercent);
   
   Comment(ScreenMessage);
   
//----
   return(0);
}
//+------------------------------------------------------------------+