//-------------------------------------------------------------------- // #MTF_Mail_Utility.mq4 // // Copyright(C) 2010, FTLabo // http://www.ftlabo.com/index.php // order@ftlabo.com // Rev.001 //-------------------------------------------------------------------- #property copyright "Copyright(C) 2010, FTLabo." #property link "http://www.ftlabo.com/index.php" //-------------------------------------------------------------------- // パラメーター //-------------------------------------------------------------------- extern string Copyright = "Copyright(C)2009, ForexTradingLaboratory"; extern string URL = "http://www.ftlabo.com/index.php"; extern string EMail = "info@ftlabo.com"; extern string explanationMaPeriod = "メール送信間隔(単位:分)"; extern int SendInterval = 15; extern string explanationML = "E-Mail通知(true:通知あり false:通知なし)"; extern bool EmailFL = true; extern string explanationET = "EmailTitleへメールタイトルを指定します。"; extern string EmailTitle = "EA Message"; extern string exSendTimeSpecify = "メール送信時間帯指定(true:指定あり、false:指定なし)"; extern bool SendTimeSpecify = false; extern string exSendTimeFrom = "メールを送信する時間帯(From 0〜24 ※24の場合は23時59分59秒までとする)"; extern int SendTimeFrom = 0; extern string exSendTimeTo = "メールを送信する時間帯(To 0〜24 ※24の場合は23時59分59秒までとする)"; extern int SendTimeTo = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- //グローバル変数へ起動時の日付時間を設定する。 double GblYear = GlobalVariableSet("year",Year()); double GblMonth = GlobalVariableSet("month",Month()); double GblDay = GlobalVariableSet("day",Day()); double GblHour = GlobalVariableSet("hour",Hour()); double GblMinute = GlobalVariableSet("minute",Minute()); return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //メール送信フラグOFF if(EmailFL==false){ //メール送信不要 return (0); } //メールを送信する時間帯? if(specifyTime()==false){ //送信時間外 return (0); } //次回送信時間を取得する。 datetime alertDateTime = getStringGlobalDate(); //メール送信時間を過ぎているか? if(alertDateTime <= TimeCurrent()){ //通信遮断 if(6 == GetLastError()){ SendMail(EmailTitle, "Communication interception generation"); } //メールを送信する。 sendmailRtn(); //次回送信時間を取得及び設定する。 setStringGlobalDate(getStringGlobalDateNextTime()); } return(0); } //+------------------------------------------------------------------+ //送信日時を取得する。 //+------------------------------------------------------------------+ datetime getStringGlobalDate(){ //グローバル変数へ起動時の日付時間を設定する。 string year = DoubleToStr(GlobalVariableGet("year"),0); string month = DoubleToStr(GlobalVariableGet("month"),0); string day = DoubleToStr(GlobalVariableGet("day"),0); string hour = DoubleToStr(GlobalVariableGet("hour"),0); string minute = DoubleToStr(GlobalVariableGet("minute"),0); string yyyymmdd = year + "." + month + "." + day; string hhmm = hour + ":" + minute ; return (StrToTime(yyyymmdd + " " + hhmm)); } //+------------------------------------------------------------------+ //送信日時を設定する。 //+------------------------------------------------------------------+ void setStringGlobalDate(datetime paraDate){ //グローバル変数へ起動時の日付時間を設定する。 double GblYear = GlobalVariableSet("year",TimeYear(paraDate)); double GblMonth = GlobalVariableSet("month",TimeMonth(paraDate)); double GblDay = GlobalVariableSet("day",TimeDay(paraDate)); double GblHour = GlobalVariableSet("hour",TimeHour(paraDate)); double GblMinute = GlobalVariableSet("minute",TimeMinute(paraDate)); } //+------------------------------------------------------------------+ //次回送信時間を取得する。 //+------------------------------------------------------------------+ datetime getStringGlobalDateNextTime(){ datetime nowtime = getStringGlobalDate(); datetime nexttime = nowtime + (SendInterval * 60); return (nexttime); } //+------------------------------------------------------------------+ //メール送信処理 //+------------------------------------------------------------------+ void sendmailRtn(){ //メール通知ありの場合メール送信する SendMail(EmailTitle, "Mail was transmitted." + TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) + "\r\n" + "Currency[" + Symbol() + "]" + "\r\n" + "Bid[" + DoubleToStr(localAsk(),3) + "]" + "\r\n" + "Ask[" + DoubleToStr(localBid(),3) + "]" + "\r\n" + "AccountBalance[" + AccountBalance() + "]" + "\r\n" + "OrdersTotal[" + OrdersTotal() + "]" + "\r\n" + "AccountProfit[" + AccountProfit( ) + "]" ); } //+------------------------------------------------------------------+ //メール送信時間か判定する。 //+------------------------------------------------------------------+ bool specifyTime(){ bool MailSendFlag = false; if(!SendTimeSpecify){ //メール送信時間帯指定なしの場合、メール送信フラグをたてる MailSendFlag = true; } else { if(0 > SendTimeFrom || SendTimeFrom > 24 || 0 > SendTimeTo || SendTimeTo > 24){ MailSendFlag = false; Print("Time zone specification error"); } else { int NowHour = Hour(); if(SendTimeFrom == SendTimeTo){ //1時間のみ指定 if(NowHour == SendTimeFrom){ MailSendFlag = true; } } else if(SendTimeFrom < SendTimeTo){ //日をまたがない場合 if(SendTimeFrom <= NowHour && SendTimeTo >= NowHour){ MailSendFlag = true; } } else { //日をまたぐ場合 if(SendTimeFrom <= NowHour && 24 >= NowHour){ MailSendFlag = true; } if(0 <= NowHour && SendTimeTo >= NowHour){ MailSendFlag = true; } } } } return (MailSendFlag); } double localAsk(){ double returnValue = Ask; if(returnValue > 10){ double tempDouble = returnValue * 100; int tempInt = tempDouble; tempDouble = tempInt; returnValue = tempDouble / 100; } return (returnValue); } double localBid(){ double returnValue = Bid; if(returnValue > 10){ double tempDouble = returnValue * 100; int tempInt = tempDouble; tempDouble = tempInt; returnValue = tempDouble / 100; } return (returnValue); } //+------------------------------------------------------------------+