//------------------------------------------------------------------
//  VisualOrdersMagic.mq4 
//  Dmitry Yakovlev 
//  dmitry_yakovlev@rambler.ru
//------------------------------------------------------------------
//
//  Мод от ST2050
//  Добавлены настройки цветов,
//  добавлена возможность фильтрации по магику
//------------------------------------------------------------------

#property copyright "Dmitry Yakovlev, Russia, Omsk // mod by ST2050 from tradelikeapro.ru forum"
#property link      "dmitry_yakovlev@rambler.ru"

#property indicator_chart_window

#import  "shell32.dll"           //Connect a dll (provided with Windows)             
  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="Прибыль 1-плавающ.,2-сверху";
extern int     ModeProf=2;
extern string  _orders="Показывать сделки на графике:";
extern string  _Type = "0 все,-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=false;
extern bool    ShowDeposit=false;
extern bool    ShowTimeSpread=true;
extern bool    DrawArrows = false;
extern color   ColorLinesBuy = LimeGreen;
extern color   ColorLinesSell = DarkOrange;
extern bool    FilterMagic = true;
extern int     Magic = 0;


int            ProfitTextSise = 10;
string         FontName = "Courier New";
color          ColorProfit0 = RoyalBlue;
color          ColorProfitPositive = Green;
color          ColorProfitNegative = Red;
int profit_dist_label = 110;
int profit_dist_count = 90;
int profit_dist_value = 10;

double prev_profit=0, cur_prof5=0, prev_prof5=0;
int wh=0;
int init()
{
   int i,total;
   if(lblSize<1) lblSize=1;
   if(lblSize>4) lblSize=4;
   
   //CheckDonate();

   deleteAll();
   
    if (ShowTimeSpread) {
    ObjectCreate("curtime", OBJ_LABEL,0,0,0);
    ObjectSet("curtime", OBJPROP_CORNER,1);
    ObjectSet("curtime", OBJPROP_XDISTANCE,300);
    ObjectSet("curtime", OBJPROP_YDISTANCE,2);
    }

    if(ModeProf==1)
    {
      ObjectCreate("profit_buy_label", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_sell_label", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_total_label", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_buy_count", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_sell_count", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_total_count", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_buy_value", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_sell_value", OBJ_TEXT,0,0,0);
      ObjectCreate("profit_total_value", OBJ_TEXT,0,0,0);
      if (ShowDeposit) ObjectCreate("Account", OBJ_TEXT,0,0,0);
    }
    else if(ModeProf==2 && ShowProfits)
    {
      if (ShowDeposit) {
      ObjectCreate("Account", OBJ_LABEL,0,0,0);
      ObjectSet("Account", OBJPROP_CORNER,3);
      ObjectSet("Account", OBJPROP_XDISTANCE,350);
      ObjectSet("Account", OBJPROP_YDISTANCE,5);
      }

      ObjectCreate("profit_buy_label", OBJ_LABEL,0,0,0);
      ObjectSet("profit_buy_label", OBJPROP_CORNER,3);
      ObjectSet("profit_buy_label", OBJPROP_XDISTANCE,profit_dist_label);
      ObjectSet("profit_buy_label", OBJPROP_YDISTANCE,50);
      ObjectSetText("profit_buy_label","Buys :", ProfitTextSise, FontName, ColorProfit0);

      ObjectCreate("profit_buy_count", OBJ_LABEL,0,0,0);
      ObjectSet("profit_buy_count", OBJPROP_CORNER,3);
      ObjectSet("profit_buy_count", OBJPROP_XDISTANCE,profit_dist_count);
      ObjectSet("profit_buy_count", OBJPROP_YDISTANCE,50);
      ObjectSetText("profit_buy_count","?", ProfitTextSise, FontName, ColorProfit0);

      ObjectCreate("profit_buy_value", OBJ_LABEL,0,0,0);
      ObjectSet("profit_buy_value", OBJPROP_CORNER,3);
      ObjectSet("profit_buy_value", OBJPROP_XDISTANCE,profit_dist_value);
      ObjectSet("profit_buy_value", OBJPROP_YDISTANCE,50);

      ObjectCreate("profit_sell_label", OBJ_LABEL,0,0,0);
      ObjectSet("profit_sell_label", OBJPROP_CORNER,3);
      ObjectSet("profit_sell_label", OBJPROP_XDISTANCE,profit_dist_label);
      ObjectSet("profit_sell_label", OBJPROP_YDISTANCE,30);
      ObjectSetText("profit_sell_label","Sells :", ProfitTextSise, FontName, ColorProfit0);

      ObjectCreate("profit_sell_count", OBJ_LABEL,0,0,0);
      ObjectSet("profit_sell_count", OBJPROP_CORNER,3);
      ObjectSet("profit_sell_count", OBJPROP_XDISTANCE,profit_dist_count);
      ObjectSet("profit_sell_count", OBJPROP_YDISTANCE,30);
      ObjectSetText("profit_sell_count","?", ProfitTextSise, FontName, ColorProfit0);

      ObjectCreate("profit_sell_value", OBJ_LABEL,0,0,0);
      ObjectSet("profit_sell_value", OBJPROP_CORNER,3);
      ObjectSet("profit_sell_value", OBJPROP_XDISTANCE,profit_dist_value);
      ObjectSet("profit_sell_value", OBJPROP_YDISTANCE,30);
      ObjectSetText("profit_sell_value","?", ProfitTextSise, FontName, ColorProfit0);

      ObjectCreate("profit_tot_label", OBJ_LABEL,0,0,0);
      ObjectSet("profit_tot_label", OBJPROP_CORNER,3);
      ObjectSet("profit_tot_label", OBJPROP_XDISTANCE,profit_dist_label);
      ObjectSet("profit_tot_label", OBJPROP_YDISTANCE,10);
      ObjectSetText("profit_tot_label","Total :", ProfitTextSise, FontName, ColorProfit0);

      ObjectCreate("profit_tot_count", OBJ_LABEL,0,0,0);
      ObjectSet("profit_tot_count", OBJPROP_CORNER,3);
      ObjectSet("profit_tot_count", OBJPROP_XDISTANCE,profit_dist_count);
      ObjectSet("profit_tot_count", OBJPROP_YDISTANCE,10);
      ObjectSetText("profit_tot_count","?", ProfitTextSise, FontName, ColorProfit0);

      ObjectCreate("profit_tot_value", OBJ_LABEL,0,0,0);
      ObjectSet("profit_tot_value", OBJPROP_CORNER,3);
      ObjectSet("profit_tot_value", OBJPROP_XDISTANCE,profit_dist_value);
      ObjectSet("profit_tot_value", OBJPROP_YDISTANCE,10);
      ObjectSetText("profit_tot_value","?", ProfitTextSise, FontName, ColorProfit0);

    }

   ObjectDelete("VOSignal");
   /*ObjectCreate("VOSignal", OBJ_LABEL,0,0,0);
   ObjectSet("VOSignal", OBJPROP_CORNER,1);
   ObjectSet("VOSignal", OBJPROP_XDISTANCE,10);
   ObjectSet("VOSignal", OBJPROP_YDISTANCE,10);*/
}
int deinit()
{
   deleteAll();
   for(int i=0;i<30;i++)
   {
      ObjectDelete(Symbol()+DoubleToStr(Period(),0)+"vopen"+i);
      ObjectDelete(Symbol()+DoubleToStr(Period(),0)+"vtake"+i);
      ObjectDelete(Symbol()+DoubleToStr(Period(),0)+"vstop"+i);
   }
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
double Trunc(double v=0)
{
   return(StrToDouble(DoubleToStr(v,0)));
}

double TakeProfit=0, StopLoss=0;


int start()
{
   datetime t1,t2,t3,t4;
   double TickValue=MarketInfo(Symbol(), MODE_TICKVALUE);
   int spread=MarketInfo(Symbol(), MODE_SPREAD);
   
   if (ShowTimeSpread) ObjectSetText("curtime", TimeToStr(TimeCurrent(),TIME_SECONDS)+" Плечо:"+DoubleToStr(AccountLeverage(),0)+" Спрэд:"+DoubleToStr(spread,0), 11, "Arial",ColorProfit0);
	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;
   int    sell_count=0, buy_count=0;
   for(i=0;i<OrdersTotal();i++)
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
      if ((FilterMagic) && (Magic!=OrderMagicNumber()) ) continue;
   
      if(OrderSymbol()==Symbol() && OrderType()==OP_SELL) { 
         sell_profit+=OrderProfit(); sell_points+=Ask-OrderOpenPrice();
         sell_count+=1; 
      }
      if(OrderSymbol()==Symbol() && OrderType()==OP_BUY) { 
         buy_profit+=OrderProfit(); buy_points+=Bid-OrderOpenPrice();
         buy_count+=1; 
      }
      if(OrderSymbol()==Symbol() ) 
         if(OrderProfit()>0) 
            plus_profit+=OrderProfit();
         else
            minus_profit+=OrderProfit();
   }
   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;

   if (ShowDeposit) ObjectSetText("Account", DoubleToStr(AccountEquity(),2), 20, "Arial", Gold);

   //if(tot_profit>0) ObjectSetText("profit2", DoubleToStr(plus_profit,2)+"+"+DoubleToStr(minus_profit,2)+"=+"+DoubleToStr(tot_profit,2)+" (+"+DoubleToStr(tot_points/Point,0)+")", 12, "Arial", Lime);
   //else if(tot_profit<0) ObjectSetText("profit2", DoubleToStr(plus_profit,2)+""+DoubleToStr(minus_profit,2)+"="+DoubleToStr(tot_profit,2)+" ("+DoubleToStr(tot_points/Point,0)+")", 12, "Arial", OrangeRed);
   //else if(tot_profit==0) ObjectSetText("profit2","0", 12, "Arial", Yellow);
   
//   if(tot_profit>0) ObjectSetText("profit2", DoubleToStr(plus_profit,2)+"+"+DoubleToStr(minus_profit,2)+"=+"+DoubleToStr(tot_profit,2), 15, "Arial", Green);
//   else if(tot_profit<0) ObjectSetText("profit2", DoubleToStr(plus_profit,2)+""+DoubleToStr(minus_profit,2)+"="+DoubleToStr(tot_profit,2), 15, "Arial", OrangeRed);
//   else if(tot_profit==0) ObjectSetText("profit2","0", 15, "Arial", Yellow);
   
//   if(tot_profit>0) ObjectSetText("profit2", DoubleToStr(plus_profit,2)+"+"+DoubleToStr(minus_profit,2)+"=+"+DoubleToStr(tot_profit,2), 15, "Arial", Green);
//   else if(tot_profit<0) ObjectSetText("profit2", DoubleToStr(plus_profit,2)+""+DoubleToStr(minus_profit,2)+"="+DoubleToStr(tot_profit,2), 15, "Arial", OrangeRed);
//   else if(tot_profit==0) ObjectSetText("profit2","0", 15, "Arial", Yellow);

   ObjectSetText("profit_tot_count",DoubleToStr(sell_count+buy_count,0), ProfitTextSise, FontName, ColorProfit0);
   if(tot_profit==0) ObjectSetText("profit_tot_value","0", ProfitTextSise, FontName, ColorProfit0);
   else {
     if(tot_profit>0) ObjectSetText("profit_tot_value", "$ +"+DoubleToStr(tot_profit,2), ProfitTextSise, FontName, ColorProfitPositive);
     else ObjectSetText("profit_tot_value", "$ "+DoubleToStr(tot_profit,2), ProfitTextSise, FontName, ColorProfitNegative);
   }
   
   ObjectSetText("profit_sell_count",DoubleToStr(sell_count,0), ProfitTextSise, FontName, ColorProfit0);
   if(sell_profit==0) ObjectSetText("profit_sell_value","0", ProfitTextSise, FontName, ColorProfit0);
   else {
     if(sell_profit>0) ObjectSetText("profit_sell_value", "$ +"+DoubleToStr(sell_profit,2), ProfitTextSise, FontName, ColorProfitPositive);
     else ObjectSetText("profit_sell_value", "$ "+DoubleToStr(sell_profit,2), ProfitTextSise, FontName, ColorProfitNegative);
   }

   ObjectSetText("profit_buy_count",DoubleToStr(buy_count,0), ProfitTextSise, FontName, ColorProfit0);
   if(buy_profit==0) ObjectSetText("profit_buy_value","0", ProfitTextSise, FontName, ColorProfit0);
   else {
     if(buy_profit>0) ObjectSetText("profit_buy_value", "$ +"+DoubleToStr(buy_profit,2), ProfitTextSise, FontName, ColorProfitPositive);
     else ObjectSetText("profit_buy_value", "$ "+DoubleToStr(buy_profit,2), ProfitTextSise, FontName, ColorProfitNegative);
   }   

   if(ModeProf==1)
   {
      ObjectSet("profit2", OBJPROP_TIME1, Time[0]+Period()*60*2);
      if (ShowDeposit) ObjectSet("Account", 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("profit2", OBJPROP_PRICE1, hh+Point*9);
      if (ShowDeposit) ObjectSet("Account", OBJPROP_PRICE1, hh+Point*6);
   }

   //string VOSignal="flat";
   /*ObjectSetText("VOSignal", "flat", 12, "Arial", Blue);
   if(Close[0]>High[1] && Low[0]>Low[1] && Low[1]>Low[2])
   {
      ObjectSetText("VOSignal", "buy", 12, "Arial", Lime);
   }
   if(Close[0]<Low[1] && High[0]<High[1] && High[1]<High[2])
   {
      ObjectSetText("VOSignal", "sell", 12, "Arial", Red);
   }*/
   
   prev_profit=tot_profit;
   prev_points=tot_points;
   
   // <---orders
      if(HistOrders==true) ShowOrders(MODE_HISTORY);
      if(CurOrders==true) ShowOrders(MODE_TRADES);
   // --- orders >
   
   // <---targets
   if(lShowTargets) fShowTargets();
   // ---targets>
   WindowRedraw();
}

void deleteAll()
{
   string tmp,prefix;
   int i,total;

   ObjectDelete("VOSignal");
   
   prefix="time_order_trades_";total=OrdersTotal();
   for(i=0;i<total+5;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");
   }
   prefix="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");
   }

   ObjectDelete("curtime");   
   ObjectDelete("profit_buy_label");
   ObjectDelete("profit_buy_count");
   ObjectDelete("profit_buy_value");
   ObjectDelete("profit_sell_label");
   ObjectDelete("profit_sell_count");
   ObjectDelete("profit_sell_value");
   ObjectDelete("profit_tot_label");
   ObjectDelete("profit_tot_count");
   ObjectDelete("profit_tot_value");

   ObjectDelete("Account");

   ObjectDelete("time_TP");
   ObjectDelete("time_SL");
   ObjectDelete("time_mar");
   ObjectDelete("time_per");
   ObjectDelete("time_lot");
   ObjectDelete("time_lot100");
   ObjectDelete("time_vv1");
   ObjectDelete("time_vv2");
   ObjectDelete("time_sr1");
   ObjectDelete("time_sr2");
}

void ShowOrders(int mode=MODE_TRADES)
{
   int i=0; string tmp=""; color clr2=0,clr1=Blue; string prefix="time_order_trades_"; int total=0;
   double CT, CP;
   
   if(mode==MODE_TRADES) {prefix="time_order_trades_";total=OrdersTotal();}
   if(mode==MODE_HISTORY) {prefix="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())
      {
         if ((FilterMagic) && (Magic!=OrderMagicNumber()) ) continue;
      
         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=ColorLinesBuy; else clr2=ColorLinesSell;
            if(OrderType()==OP_BUY) {CP=Bid;clr1=Lime; clr2=ColorLinesBuy;}
            if(OrderType()==OP_SELL) {CP=Ask;clr1=Red; clr2=ColorLinesSell;}
            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_DOT);
            
            if (DrawArrows)
            {
               ObjectCreate(tmp+"OA", OBJ_ARROW, 0, OrderOpenTime()/*-Period()*60*/, OrderOpenPrice());
               ObjectSet(tmp+"OA", OBJPROP_COLOR, clr1);
               ObjectSet(tmp+"OA", OBJPROP_ARROWCODE, 2);
            }
            
            /*if(mode==MODE_TRADES) 
            {
               ObjectCreate(tmp+"O", OBJ_ARROW, 0, OrderOpenTime()-Period()*60, OrderOpenPrice());
               ObjectSet(tmp+"O", OBJPROP_COLOR, clr1);
               ObjectSet(tmp+"O", OBJPROP_WIDTH, lblSize);
               ObjectSet(tmp+"O", OBJPROP_ARROWCODE, 5);
            }*/

            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=Lime;
               if(OrderProfit()>0) { sss="+"; clrProf=Lime;}
               if(OrderProfit()<0) { sss="-"; clrProf=Red;}
               
               ObjectSetText(tmp+"Cprof2", sss+DoubleToStr(MathAbs(OrderClosePrice()-OrderOpenPrice())/Point,0)+"("+DoubleToStr(MathAbs(OrderProfit()),0)+"$)",10,"Arial",clrProf);
               ObjectSet(tmp+"Cprof2", OBJPROP_ANGLE,90);
            }
            
            if (DrawArrows)
            {
            ObjectCreate(tmp+"CA", OBJ_ARROW, 0, CT/*+Period()*60*/, CP);
            ObjectSet(tmp+"CA", OBJPROP_COLOR, clr2);
            ObjectSet(tmp+"CA", OBJPROP_ARROWCODE, 3);
            }
            /*if(mode==MODE_TRADES) 
            {
               
               ObjectCreate(tmp+"C", OBJ_ARROW, 0, CT+Period()*60, CP);
               ObjectSet(tmp+"C", OBJPROP_COLOR, clr2);
               ObjectSet(tmp+"C", OBJPROP_WIDTH, lblSize);
               ObjectSet(tmp+"C", OBJPROP_ARROWCODE, 6);
            }*/
         }
      }
   }
   //---торгуемые ордера>
}


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=10; // font size
   color    prof_clr=Blue;
   string   txt="";
   //-------------------------------------------------------------
   for(i=0;i<10;i++)
   {
      ObjectDelete(Symbol()+DoubleToStr(Period(),0)+"vopen"+i);
      ObjectDelete(Symbol()+DoubleToStr(Period(),0)+"vtake"+i);
      ObjectDelete(Symbol()+DoubleToStr(Period(),0)+"vstop"+i);
   }
   for(i=0;i<OrdersTotal();i++)
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
      // <---считаем
      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=Red;
      if(prof_pts>0) prof_clr=RoyalBlue;
      txt="";
      if(OrderType()==0 || OrderType()==1) txt=" ("+DoubleToStr(MathAbs(prof),2)+"$)";
      ObjectCreate(Symbol()+DoubleToStr(Period(),0)+"vopen"+i,OBJ_TEXT,0,CT,OrderOpenPrice()+CP);
      ObjectSetText(Symbol()+DoubleToStr(Period(),0)+"vopen"+i,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()*10,0)+"$)";
         
         ObjectCreate(Symbol()+DoubleToStr(Period(),0)+"vtake"+i,OBJ_TEXT,0,CT,OrderTakeProfit()+CP);
         ObjectSetText(Symbol()+DoubleToStr(Period(),0)+"vtake"+i,txt,FS,"Arial",RoyalBlue);
      }
      
      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()*10,0)+"$)";

         ObjectCreate(Symbol()+DoubleToStr(Period(),0)+"vstop"+i,OBJ_TEXT,0,CT,OrderStopLoss()+CP);
         ObjectSetText(Symbol()+DoubleToStr(Period(),0)+"vstop"+i,txt,FS,"Arial",Red);
      }
      // рисуем--->
   }
}

//void CheckDonate()
//{
//   int fd=0; string pay="0"; datetime dt=0;
//   string fn="VisualOrders.txt";
//   fd=FileOpen(fn,FILE_READ|FILE_CSV,";");
//   if(fd>=1)
//   {
//      pay=FileReadString(fd); if(pay!="0" && pay!="1") pay="0";
//      dt=StrToTime(FileReadString(fd));
//   }
//   else
//   {
//      dt=TimeCurrent();
//      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
//      FileWrite(fd,"0",TimeToStr(dt,TIME_DATE));
//   }
//   FileClose(fd);
//   
//   if(=="0" && (TimeCurrent()-dt)>10*24*60*60) // 5 дней
//   {
//      if(MessageBoxA(0,"Если Вам понравился индикатор VisualOrders,\n хотите помочь автору материально?","Вопрос",4)==6)
//      {
//         ShellExecuteA(0,"Open","iexplore.exe","wmk:payto?Purse=R865705290089&Amount=100&Desc=Indicator&BringToFront=Y&ExecEvenKeeperIsOffline=Y","",7);
//         pay="1";
//      }
//      dt=TimeCurrent();
//      
//      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
//      FileWrite(fd,pay,TimeToStr(dt,TIME_DATE));
//      FileClose(fd);
//   }
//   FileClose(fd);
//}


