   //+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window

#import  "shell32.dll"                    
int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import "user32.dll"
int MessageBoxA(int hWnd,string lpText,string lpCaption,int uType);
#import

extern string  _ModeProf="Profit 1-floating.,2-upper";
extern int     ModeProf=2;
extern string  _orders="Show deals on chart:";
extern string  _Type= "0 all-1 Sell,1 Buy";
extern int     Type = 0;
extern bool    CurOrders=true;
extern int     lblSize=1;
extern bool    HistOrders=false;
extern bool    ShowProfits=true;
extern int     ShiftProfits=0;
extern bool    lShowTargets=true;
string    _donate1="";
string    _donate2="";
extern int     distance_SL;

double prev_profit=0,cur_prof5=0,prev_prof5=0;
int wh=0;

int coef=1;

string pre="VO_";
string name="";
string name_p="";
int _OrdersTotal=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   if(lblSize<1) lblSize=1;
   if(lblSize>4) lblSize=4;

   ReInit();
   _OrdersTotal=OrdersTotal();
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   DeleteAll(pre);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Trunc(double v=0)
  {
   return(StrToDouble(DoubleToStr(v,0)));
  }

double TakeProfit=0,StopLoss=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   if(OrdersTotal()!=_OrdersTotal)
     {
      ReInit();
     }
   double TickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
   int spread=MarketInfo(Symbol(),MODE_SPREAD);
   name=pre+"curtime";
   ObjectSetText(name,TimeToStr(TimeCurrent(),TIME_SECONDS)+" Leverage:"+DoubleToStr(AccountLeverage(),0)+" Spread:"+DoubleToStr(spread,0),12,"Arial",Black);
   int i;
   double sell_profit=0,buy_profit=0,tot_profit=0,
   sell_points=0, buy_points=0, tot_points=0, prev_points=0,
   plus_profit=0, minus_profit=0;
   double lot = 0.0;
   for(i=0;i<OrdersTotal();i++)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol())
        {
         double profit=OrderProfit()+OrderCommission()+OrderSwap();
         lot += OrderLots();
         if(OrderType()==OP_SELL) { sell_profit+=profit; sell_points+=Ask-OrderOpenPrice();}
         if(OrderType()==OP_BUY) { buy_profit+=profit; buy_points+=Bid-OrderOpenPrice();}
         if(OrderProfit()>0)
            plus_profit+=profit;
         else
            minus_profit+=profit;
        }
   tot_profit=sell_profit+buy_profit;
   tot_points=buy_points-sell_points;
   cur_prof5=Trunc(tot_points/5)*5;
   prev_prof5=Trunc(prev_points/5)*5;
   name=pre+"Account";
   ObjectSetText(name,DoubleToStr(AccountEquity(),2),12,"Arial",Black);
   string lot_text = "$. Lot: "+DoubleToStr(lot,2);
   if(tot_profit>0) ObjectSetText(name_p,DoubleToStr(plus_profit,2)+"+"+DoubleToStr(minus_profit,2)+"=+"+DoubleToStr(tot_profit,2)+lot_text,14,"Arial",LightSkyBlue);
   else if(tot_profit<0) ObjectSetText(name_p,DoubleToStr(plus_profit,2)+""+DoubleToStr(minus_profit,2)+"="+DoubleToStr(tot_profit,2)+lot_text,14,"Arial",LightGray);
   else if(tot_profit==0) ObjectSetText(name_p,"0"+lot_text,14,"Arial",Black);

   if(ModeProf==1)
     {
      ObjectSet(name_p,OBJPROP_TIME1,Time[0]+Period()*60*2);
      ObjectSet(name,OBJPROP_TIME1,Time[0]+Period()*60*2);
      double hh=High[iHighest(NULL,0,MODE_HIGH,5,0)],ll=Low[iLowest(NULL,0,MODE_LOW,3,0)];
      ObjectSet(name_p,OBJPROP_PRICE1,hh+Point*9);
      ObjectSet(name,OBJPROP_PRICE1,hh+Point*6);
     }

   prev_profit=tot_profit;
   prev_points=tot_points;


   if(HistOrders==true) ShowOrders(MODE_HISTORY);
   if(CurOrders==true) ShowOrders(MODE_TRADES);

   if(lShowTargets) fShowTargets();

   WindowRedraw();
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ShowOrders(int mode=MODE_TRADES)
  {
   int i=0; string tmp=""; color clr2=0,clr1=Blue; string prefix=pre+"time_order_trades_"; int total=0;
   double CT,CP;

   if(mode==MODE_TRADES) {prefix=pre+"time_order_trades_";total=OrdersTotal();}
   if(mode==MODE_HISTORY) {prefix=pre+"time_order_hist_";total=OrdersHistoryTotal();}

   for(i=0;i<total+15;i++)
     {
      tmp=prefix+DoubleToStr(i,0);
      ObjectDelete(tmp);
      ObjectDelete(tmp+"O");
      ObjectDelete(tmp+"C");
      ObjectDelete(tmp+"OA");
      ObjectDelete(tmp+"CA");
      ObjectDelete(tmp+"Cprof1");
      ObjectDelete(tmp+"Cprof2");
     }

   for(i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,mode)==true && OrderSymbol()==Symbol())
        {
         int ot=OrderType();
         if(OrderSymbol()==Symbol() && ((Type==0 && (ot==OP_BUY || ot==OP_SELL)) || (Type==1 && ot==OP_BUY) || (Type==-1 && ot==OP_SELL)))
           {
            tmp=prefix+DoubleToStr(i,0);
            clr2=White; if(OrderProfit()>=0) clr2=LightSkyBlue; else clr2=LightGray;
            if(OrderType()==OP_BUY) {CP=Bid;clr1=LightSkyBlue;}
            if(OrderType()==OP_SELL) {CP=Ask;clr1=LightGray;}
            if(mode==MODE_TRADES)  {CT=Time[0];}
            if(mode==MODE_HISTORY) {CT=OrderCloseTime();CP=OrderClosePrice();}

            ObjectCreate(tmp,OBJ_TREND,0,OrderOpenTime(),OrderOpenPrice(),CT,CP);
            ObjectSet(tmp,OBJPROP_COLOR,clr2);
            ObjectSet(tmp,OBJPROP_RAY,0);
            ObjectSet(tmp,OBJPROP_WIDTH,1);
            ObjectSet(tmp,OBJPROP_STYLE,STYLE_DASHDOTDOT);

            ObjectCreate(tmp+"OA",OBJ_ARROW,0,OrderOpenTime()/*-Period()*60*/,OrderOpenPrice());
            ObjectSet(tmp+"OA",OBJPROP_COLOR,clr1);
            ObjectSet(tmp+"OA",OBJPROP_ARROWCODE,1);

            if(mode==MODE_HISTORY && ShowProfits)
              {
               int j=0,sh=iBarShift(Symbol(),0,CT,true);
               double pr=0;

               if(ShiftProfits>=0) for(j=4;j>=0;j--) pr=MathMax(pr,iHigh(Symbol(),0,sh+j));
               if(ShiftProfits<0) for(j=4;j>=0;j--) pr=MathMax(pr,iLow(Symbol(),0,sh+j));

               if(ShiftProfits!=0)
                  ObjectCreate(tmp+"Cprof2",OBJ_TEXT,0,CT,pr+ShiftProfits*Point);

               if(ShiftProfits==0)
                  ObjectCreate(tmp+"Cprof2",OBJ_TEXT,0,CT,pr+(WindowPriceMax()-WindowPriceMin())/10);

               string sss=""; color clrProf=LightSkyBlue;
               if(OrderProfit()>0) { sss="+"; clrProf=LightSkyBlue;}
               if(OrderProfit()<0) { sss="-"; clrProf=LightGray;}

               ObjectSetText(tmp+"Cprof2",sss+DoubleToStr(MathAbs(OrderClosePrice()-OrderOpenPrice())/Point,0)+"("+DoubleToStr(MathAbs(OrderProfit()),0)+"$)",14,"Arial",clrProf);
               ObjectSet(tmp+"Cprof2",OBJPROP_ANGLE,90);
              }
            ObjectCreate(tmp+"CA",OBJ_ARROW,0,CT/*+Period()*60*/,CP);
            ObjectSet(tmp+"CA",OBJPROP_COLOR,clr2);
            ObjectSet(tmp+"CA",OBJPROP_ARROWCODE,3);

           }
        }
     }

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void fShowTargets()
  {
   int      i=0,prof_pts=0,ticket=0;
   double   dist_stop_pts,dist_stop;
   double   dist_take_pts,dist_take;
   double   pr=(Ask+Bid)/2, prof=0;
   datetime CT=Time[0]+Period()*60*(WindowBarsPerChart()/20+2); // time shift
   double   CP=5*Point; // price shift
   int      FS=14; // font size
   color    prof_clr=Blue;
   string   txt="";
   string name_open = pre+"O_";
   string name_take = pre+"T_";
   string name_stop = pre+"S_";
//-------------------------------------------------------------
   DeleteAll(name_open);
   DeleteAll(name_take);
   DeleteAll(name_stop);
   for(i=0;i<OrdersTotal();i++)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==_Symbol)
        {
         RefreshRates();
         prof=OrderProfit();
         if(OrderType()==OP_BUY || OrderType()==3 || OrderType()==4)
           {
            pr=Bid;
            prof_pts=pr/Point-OrderOpenPrice()/Point;
           }
         if(OrderType()==OP_SELL || OrderType()==2 || OrderType()==5)
           {
            pr=Ask;
            prof_pts=OrderOpenPrice()/Point-pr/Point;
           }
         prof_clr=Blue;
         if(prof_pts<0) prof_clr=LightGray;
         if(prof_pts>0) prof_clr=LightSkyBlue;
         txt="";
         if(OrderType()==0 || OrderType()==1) txt=" ("+DoubleToStr(MathAbs(prof),2)+"$)";
         name=name_open+IntegerToString(OrderTicket());
         ObjectCreate(name,OBJ_TEXT,0,CT,OrderOpenPrice()+CP);
         ObjectSetText(name,DoubleToStr(MathAbs(prof_pts),0)+txt,FS,"Arial",prof_clr);

         dist_take_pts=0;dist_take=0;
         if(OrderTakeProfit()!=0)
           {
            dist_take_pts=MathAbs(pr/Point-OrderTakeProfit()/Point);
            txt=DoubleToStr(dist_take_pts,0);
            dist_take_pts=MathAbs(OrderOpenPrice()/Point-OrderTakeProfit()/Point);
            txt=txt+"("+DoubleToStr(dist_take_pts,0)+"/"+DoubleToStr(dist_take_pts*OrderLots()*1,0)+"$)";
            name=name_take+IntegerToString(OrderTicket());
            ObjectCreate(name,OBJ_TEXT,0,CT,OrderTakeProfit()+CP);
            ObjectSetText(name,txt,FS,"Arial",LightSkyBlue);
           }

         dist_stop_pts=0;dist_stop=0;
         if(OrderStopLoss()!=0)
           {
            dist_stop_pts=MathAbs(pr/Point-OrderStopLoss()/Point);
            txt=DoubleToStr(dist_stop_pts,0);
            dist_stop_pts=MathAbs(OrderOpenPrice()/Point-OrderStopLoss()/Point);
            txt=txt+"("+DoubleToStr(dist_stop_pts,0)+"/"+DoubleToStr(dist_stop_pts*OrderLots()*1,0)+"$)";
            name=name_stop+IntegerToString(OrderTicket());
            ObjectCreate(name,OBJ_TEXT,0,CT,OrderStopLoss()+CP+distance_SL*coef*Point*Period());
            ObjectSetText(name,txt,FS,"Arial",LightGray);
           }

        }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Удаление объектов                                                |
//+------------------------------------------------------------------+
void DeleteAll(string str)
  {
   int s_len=StringLen(str);
//---
   for(int i=ObjectsTotal(); i>=0; i--)
     {
      if(StringSubstr(ObjectName(i),0,s_len)==str)
        {
         ObjectDelete(ObjectName(i));
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ReInit()
  {
   DeleteAll(pre);

   name=pre+"curtime";
   ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSet(name,OBJPROP_CORNER,0);
   ObjectSet(name,OBJPROP_XDISTANCE,150);
   ObjectSet(name,OBJPROP_YDISTANCE,150);
   name_p=pre+"profit2";
   name=pre+"Account";
   if(ModeProf==1)
     {
      ObjectCreate(name_p,OBJ_TEXT,0,0,0);
      ObjectCreate(name,OBJ_TEXT,0,0,0);
     }
   else if(ModeProf==2)
     {
      ObjectCreate(name,OBJ_LABEL,0,0,0);
      ObjectSet(name,OBJPROP_CORNER,0);
      ObjectSet(name,OBJPROP_XDISTANCE,150);
      ObjectSet(name,OBJPROP_YDISTANCE,180);

      ObjectCreate(name_p,OBJ_LABEL,0,0,0);
      ObjectSet(name_p,OBJPROP_CORNER,0);
      ObjectSet(name_p,OBJPROP_XDISTANCE,150);
      ObjectSet(name_p,OBJPROP_YDISTANCE,210);
     }
  }
//+------------------------------------------------------------------+