Daily Profit

 

I have code to send a message to telegram for the following


- New Order

- Closed Order

- Order modified 


But wondering how I can send a message based on a specific time and to send the profit made that day.


Any help would be appreciated!

 
Its Fewster: Any help would be appreciated!

Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
          No free help (2017)

 
William Roeder #:

Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
          No free help (2017)

My bad here is the code I have tried to piece together

I believe the top part is figuring out what the profit is so need to know if that is the case then need to figure out the if statment to send it at a specific time. 


//---
   DailyProfit();
  }
//+------------------------------------------------------------------+
double DailyProfit()
{
double profit = 0;
int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==TRUE)
       {
         if(TimeToStr(TimeLocal(),TIME_DATE) == TimeToStr(OrderCloseTime(),TIME_DATE))
         {
            profit += OrderProfit() + OrderSwap() + OrderCommission();
         }
       }
    }
    Alert(profit);
   return(profit);
}


 if(Daily_Profit) {
      

string msg = " Daily Profit: " + profit () +  " \n";
           msg += clock_emoji_for_text + TimeToString(TimeCurrent()+3600,TIME_MINUTES|TIME_MINUTES)+"\n";   // Time modification of 1 hour          
               SendAlert(msg);
                          }
 
 if(TimeToStr(TimeLocal(),TIME_DATE) == TimeToStr(OrderCloseTime(),TIME_DATE))
All chart times (order times) are broker's time. Why are you using your PC's time?
 
Its Fewster #:

My bad here is the code I have tried to piece together

I believe the top part is figuring out what the profit is so need to know if that is the case then need to figure out the if statment to send it at a specific time. 


What William said , also , you can store the TimeDay() of the last update that was sent and poll it at intervals so if the TimeDay() currently changes you fire the notification.

here is TimeDay for MT5 

int TimeDay(datetime time)      {MqlDateTime mt;bool turn=TimeToStruct(time,mt);return(mt.day);}

You can use the magic number to indentify your system , i.e. your filename for saving the report can be 352_rd.txt , 352 is the magic number

On init you load the last report send time 

On intervals you check send_report , if true you send it 

Upon sending the report you call save 

Issues : If theres been a weekend in between , or any days between the last send and the new load , then a report will be sent out at the time of load instead at the change of a day and then at the change of a day too 

bool send_report(datetime last_report,
                 datetime now){
if(last_report!=0&&TimeDay(now)!=TimeDay(last_report)){
return(true);
}else if(last_report==0){
last_report=now;
}
return(false);
}

void save_last_report_time(string folder,string filename,datetime _last_report){
string location=folder+"\\"+filename;
if(FileIsExist(location)){FileDelete(location);}
int f=FileOpen(location,FILE_WRITE|FILE_BIN);
if(f!=INVALID_HANDLE){
FileWriteLong(f,((long)_last_report));
FileClose(f);
}
}

void load_last_report(string folder,string filename,datetime &_load_here){
_load_here=0;
string location=folder+"\\"+filename;
if(FileIsExist){
int f=FileOpen(location,FILE_READ|FILE_BIN);
if(f!=INVALID_HANDLE){
_load_here=(datetime)FileReadLong(f);
FileClose(f);
}}}