//+------------------------------------------------------------------+ //| AcountBalanceMail.mq4 | //| Dr.EA Keiji | //| https://www.dr-ea.com/meta-blog/ | //+------------------------------------------------------------------+ #property copyright "Dr.EA Keiji" #property link "https://www.dr-ea.com/meta-blog/" #property version "1.00" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 1 extern int Mail_Hour = 9; extern int Mail_Minute = 30; string mail_time_str; string short_name; double last_balance; string last_mail_date; //+------------------------------------------------------------------+ int OnInit() { mail_time_str = IntegerToString(Mail_Hour, 2, '0') + ":" + IntegerToString(Mail_Minute, 2, '0'); short_name = "Account Balance Info, SendMail at " + mail_time_str; IndicatorShortName(short_name); last_balance = AccountBalance(); last_mail_date = TimeToStr(TimeCurrent(), TIME_DATE); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { double balance = AccountBalance(); double profit = balance - last_balance; // object string obj_name, text; int x, y; x = 5; y = 15; obj_name = "sub_1"; text = "Now Balance"; FuncLabelSet(obj_name, text, x, y); obj_name = "val_1"; text = (string)balance; FuncLabelSet(obj_name, text, x+100, y); y += 15; obj_name = "sub_2"; text = "Last Balance"; FuncLabelSet(obj_name, text, x, y); obj_name = "val_2"; text = (string)last_balance; FuncLabelSet(obj_name, text, x+100, y); y += 15; obj_name = "sub_3"; text = "Profit"; FuncLabelSet(obj_name, text, x, y); obj_name = "val_3"; text = string(balance - last_balance); FuncLabelSet(obj_name, text, x+100, y); // mail string today_str = TimeToStr(TimeCurrent(), TIME_DATE); datetime today_mail_time = StrToTime(today_str + " " + mail_time_str); if(last_mail_date != today_str && today_mail_time <= TimeCurrent()) { FuncSendMail(); last_mail_date = today_str; last_balance = balance; } return(rates_total); } void FuncLabelSet(string objname, string text, int x, int y) { if(ObjectFind(objname)< 0) ObjectCreate(objname, OBJ_LABEL, WindowFind(short_name), 0, 0); ObjectSetText(objname, text, 10, "Arial", clrWhite); ObjectSet(objname, OBJPROP_XDISTANCE, x); ObjectSet(objname, OBJPROP_YDISTANCE, y); } void FuncSendMail() { double profit = AccountBalance() - last_balance; string profit_str = (string)profit; if (profit > 0) profit_str = "+" + profit_str; string subject = AccountCompany() + ", " + (string)AccountNumber(); string body = AccountCompany() + ", " + (string)AccountNumber() + "\n\n"; body += "Now Balance: " + (string)AccountBalance() + "\n"; body += "Last Balance: " + (string)last_balance + "\n"; body += "Profit: " + profit_str; SendMail(subject, body); }