Time





//
//  Time.mq4 
//  Dmitry Yakovlev 
//  dmitry_yakovlev@rambler.ru
//  Íà ïèâî WebMoney R865705290089
//------------------------------------------------------------------
#property copyright "Dmitry Yakovlev, Russia,Omsk, WM R865705290089"
#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  _Color="Öâåò òåêñòà:";
extern color   nColor=MediumBlue;
extern string  _ModeInfo1="Îáðàòíûé îòñ÷åò:";
extern int     lCountdown=1;
extern string  _ModeInfo2="Èíôîðìàöèÿ:";
extern int     lInfo=1;
extern string  _donate1="Äëÿ \"Ñïàñèáî\"";
extern string  _donate2="R865705290089";
extern string  _advert="Íàïèøó íà çàêàç,ïåðåäåëàþ.";

int init()
{
   CheckDonate();

   ObjectDelete("Time_Timer");
   ObjectDelete("Time_Info");
   ObjectDelete("Time_Info2");
} 
int deinit()
{
   ObjectDelete("Time_Timer");
   ObjectDelete("Time_Info");
   ObjectDelete("Time_Info2");
}

int start()
{
   int i,sign=0;
   double TickValue=MarketInfo(Symbol(), MODE_TICKVALUE);
   int spread=MarketInfo(Symbol(), MODE_SPREAD);
   
   ObjectDelete("Time_Info");
   ObjectDelete("Time_Info2");
   if(lInfo==1)
   {
      // <---- ñ÷èòàåì ñòîïû ----
      double sum_stop=0, sum_profits=0;
      for(i=0;i<OrdersTotal();i++)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL ) )
      {
         sign=0;
         if(OrderStopLoss()!=0)
         {
            if(OrderType()==OP_SELL) sign=-1; else sign=+1;
            sum_stop=sum_stop+OrderLots()*TickValue*sign*(OrderOpenPrice()-OrderStopLoss())/Point;
         }
      
         if(OrderTakeProfit()!=0)
         {
            if(OrderType()==OP_BUY) sign=-1; else sign=+1;
            sum_profits=sum_profits+OrderLots()*TickValue*sign*(OrderOpenPrice()-OrderTakeProfit())/Point;
         }
      }
      // ---- ñ÷èòàåì ñòîïû --- >
      string cInfo;
      ObjectCreate("Time_Info", OBJ_LABEL,0,0,0);
      ObjectSet("Time_Info", OBJPROP_CORNER,0);
      ObjectSet("Time_Info", OBJPROP_XDISTANCE,270);
      ObjectSet("Time_Info", OBJPROP_YDISTANCE,0);
      cInfo="Ñïðýä:"+DoubleToStr(spread,0)+
            "  1ï="+DoubleToStr(TickValue,2)+"$";//+
            //"  áàë:"+DoubleToStr(AccountBalance(),2)+
            //"  ïð:"+DoubleToStr(AccountBalance()+sum_profits,2)+"("+DoubleToStr(sum_profits,2)+")"+
            //"  ñò:"+DoubleToStr(AccountBalance()-sum_stop,2)+"("+DoubleToStr(-sum_stop,2)+")";
      ObjectSetText("Time_Info", cInfo, 10, "Arial", nColor);
      
      ObjectCreate("Time_Info2", OBJ_LABEL,0,0,0);
      ObjectSet("Time_Info2", OBJPROP_CORNER,0);
      ObjectSet("Time_Info2", OBJPROP_XDISTANCE,200);
      ObjectSet("Time_Info2", OBJPROP_YDISTANCE,20);
      ObjectSetText("Time_Info2","áàë:"+DoubleToStr(AccountBalance(),2)+"   ïð: "+DoubleToStr(AccountBalance()+sum_profits,2)+"("+DoubleToStr(sum_profits,2)+")   ñò: "+DoubleToStr(AccountBalance()-sum_stop,2)+"("+DoubleToStr(-sum_stop,2)+")", 9, "Arial", nColor);
   }
   
   // <-timer
   ObjectDelete("Time_Timer");
   if(lCountdown==1)
   {
      int tmp1=Period()*60-TimeCurrent()+Time[0];
      int tmpm=MathFloor(tmp1/60),tmps=tmp1-tmpm*60;
      string strm=DoubleToStr(tmpm,0);
      string strs=DoubleToStr(tmps,0);
      if(StringLen(strs)==1) strs="0"+strs;

      int tmp2=TimeCurrent()-Time[0];
      int tmpm2=MathFloor(tmp2/60),tmps2=tmp2-tmpm2*60;
      string strm2=DoubleToStr(tmpm2,0);
      string strs2=DoubleToStr(tmps2,0);
      if(StringLen(strs2)==1) strs2="0"+strs2;
   
      ObjectCreate("Time_Timer", OBJ_LABEL,0,0,0);
      ObjectSet("Time_Timer", OBJPROP_CORNER,1); //0
      ObjectSet("Time_Timer", OBJPROP_XDISTANCE,50); //550
      ObjectSet("Time_Timer", OBJPROP_YDISTANCE,0);
      ObjectSetText("Time_Timer",strm2+":"+strs2+"..."+strm+":"+strs, 12, "Arial", MediumBlue);
   }
   // -timer>
}


void CheckDonate()
{
   int fd=0; string pay="0"; datetime dt=0;
   string fn="Time.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(pay=="0" && (TimeCurrent()-dt)>10*24*60*60) // 5 äíåé
   {
      if(MessageBoxA(0,"Åñëè Âàì ïîíðàâèëñÿ èíäèêàòîð Time,\n õîòèòå ïîìî÷ü àâòîðó ìàòåðèàëüíî?","Âîïðîñ",4)==6)
      {
         ShellExecuteA(0,"Open","iexplore.exe","wmk:payto?Purse=R865705290089&Amount=30&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);
}





Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:
shell32
user32

Order Management characteristics:
Checks for the total of open orders


Other Features:

Uses files from the file system
It reads information from a file
It writes information to file