//+------------------------------------------------------------------+
//|                                                 Info_History.mq4 |
//|                                                     Vorchunozavr |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Vorchunozavr"
#property link      "http://forum.tradelikeapro.ru"
#property version   "1.00"
#property strict
#include <WinUser32.mqh>
#property script_show_inputs

input int magic = 0;

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{  
   int count = 0, oll;
   double lots = 0, com = 0, sum = 0, profit_plus = 0, profit_minus = 0, razn = 0, swap = 0;
   string str, pp, pm, ll,cm, rz, sw;
   oll = OrdersHistoryTotal();
   for(int i=oll-1; i>=0; i--)
   {
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      {
         if(OrderMagicNumber() != magic && magic != 0) continue;
         lots = lots + OrderLots();
         com = com + OrderCommission();
         swap = swap + OrderSwap();
         sum = OrderProfit() + OrderSwap() + OrderCommission();
         if(sum >= 0 && OrderType() < 2)
         {
            profit_plus = profit_plus + sum;
         }
         else if(sum < 0 && OrderType() < 2)
         {
            profit_minus = profit_minus + sum;
         }
         if(OrderType() < 2) count++;   
      }
      
   }
   
   ll = DoubleToString(lots, 2);
   cm = DoubleToString(com, 2);
   sw = DoubleToString(swap, 2);
   pp = DoubleToString(profit_plus, 2);
   pm = DoubleToString(profit_minus, 2);
   razn = NormalizeDouble(profit_plus + profit_minus, 2);
   rz = DoubleToString(razn, 2);
   str = StringConcatenate(str,"Ордеров\t\t", count, " (", oll,")","\t шт.\n\n");
   str = StringConcatenate(str,"Объём\t\t",ll,"\t lots\n\n");
   if(com != 0)
   {
      str = StringConcatenate(str,"Комиссия\t\t",cm,"\t USD\n\n");
   }
   if(swap != 0)
   {
      str = StringConcatenate(str,"Своп\t\t",sw,"\t USD\n\n");
   }
   str = StringConcatenate(str,"Плюс\t\t",pp,"\t USD\n\n");
   str = StringConcatenate(str,"Минус\t\t",pm,"\t USD\n\n");
   str = StringConcatenate(str,"Разница\t\t",rz,"\t USD\n\n");
   
   MessageBox(str,"История "+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS),MB_OK|MB_ICONINFORMATION);
}
//+------------------------------------------------------------------+
