無料でロボットをダウンロードする方法を見る
Telegram上で私たちを見つけてください。
私たちのファンページに参加してください
私たちのファンページに参加してください
記事を気に入りましたか?MetaTrader 5ターミナルの中でそれを試してみてください。
- ビュー:
- 1809
- 評価:
- パブリッシュ済み:
- 2016.11.02 09:47
- アップデート済み:
- 2016.11.22 07:34
-
このコードに基づいたロボットまたはインジケーターが必要なら、フリーランスでご注文ください フリーランスに移動
このライブラリはメールメッセージの送信のために設計されています。
この機能セットは従来のSendMail可能性を広げます。テキスト形式とHTML形式の両方でメッセージを送信することができます。メッセージは、複数のアドレスに送信することができます。メールには1つまたは複数のファイルを添付することができます。SSLがサポートされています。
DLLソースコードは Delphi XE4 でIndyライブラリを使って書かれています。
プロジェクトファイルに加えて OpenSSLライブラリのインストールが必要です。
ライブラリ関数の表は下記の通りです。
関数 | 説明 |
---|---|
MailConnect | メールサーバーに接続します。 |
MailSendText | テキストを送信します。 |
MailSendHtml | HTMLメッセージを送信します。 |
MailSendInlineTextFile | 挿入されたテキストファイルの内容でメッセージを送信します。 |
MailSendInlineHtmlFile | 挿入されたHTMLファイルの内容でメッセージを送信します。 |
MailErrorDescription | エラーの説明を持って帰ります。 |
MailClose | メールサーバーとの接続を閉じます。 |
エラーメッセージは下記の通りです。
定数 | 値 | 説明 |
---|---|---|
MAIL_NO_CONNECTION | -2 | 接続がありません。 |
MAIL_NO_INITIALIZATION | -1 | SMTPサーバーのためのオブジェクトがありません。 |
MAIL_NO_ERROR | 0 | エラーはありません。 |
MAIL_TIMEOUT | 1 | 接続がタイムアウトによって閉じられました。 |
MAIL_WRONG_LOGIN | 2 | 間違ったログイン/パスワード。 |
MAIL_WRONG_HOST_NAME | 3 | 不正なホスト名。 |
MAIL_HOST_NOT_FOUND | 60 | ホストが見つかりません。 |
下記はスクリプトの例です。
//+------------------------------------------------------------------+ //| MailSend.mq5 | //| avoitenko | //| https://www.mql5.com/en/users/avoitenko | //+------------------------------------------------------------------+ #property copyright "avoitenko" #property link "https://www.mql5.com/en/users/avoitenko" #property version "1.00" #property script_show_inputs #include <Trade\Trade.mqh> #include <Arrays\ArrayString.mqh> #include <SmtpMailLibrary.mqh> //+------------------------------------------------------------------+ //| ENUM_MESSAGE | //+------------------------------------------------------------------+ enum ENUM_MESSAGE { MESSAGE_TEXT, // テキスト MESSAGE_HTML, // html MESSAGE_INLINE_TEXT, // インラインテキスト MESSAGE_INLINE_HTML // インラインhtml }; //+------------------------------------------------------------------+ //| 入力パラメータ | //+------------------------------------------------------------------+ input string mail_options="=== Mail Options ==="; // メールオプション input string InpMailHost="smtp.gmail.com"; // ホスト input int InpMailPort=465; // ポート input string InpMailUser="user@gmail.com"; // ユーザー input string InpMailPassword="password"; // パスワード input string InpMailFrom=""; // 送信者(テキスト) input string InpMailSubject="Smtp Mail Library"; // 件名(テキスト) input string InpMailTo="user@ukr.net"; // 送信先 input uint InpMailConnectionTimeout=5000; // 接続タイムアウト(ミリ秒) input string msg_options="=== Message Options ==="; // メッセージオプション input ENUM_MESSAGE InpMessageType=MESSAGE_HTML; // タイプ input string InpMessageAttachmentFiles="d:\\Temp\\dollar.bmp;d:\\Temp\\euro.bmp";// 添付ファイル input string InpMessageInlineFiles="d:\\Temp\\ReportTester-20066082.html";// インラインファイル //+------------------------------------------------------------------+ //| スクリプトプログラム開始関数 | //+------------------------------------------------------------------+ void OnStart() { long smtp=0;// 初期化する //--- 接続 int err=MailConnect(smtp,InpMailHost,InpMailPort,InpMailUser,InpMailPassword,InpMailConnectionTimeout); if(err!=0) { Print("MailConnect error: ",MailErrorDescription(err)); return; } switch(InpMessageType) { //--- case MESSAGE_TEXT: { //--- プレインテキスト string text=StringFormat("Account: %d\r\nBalance: %.2f %s",AccountInfoInteger(ACCOUNT_LOGIN),AccountInfoDouble(ACCOUNT_BALANCE),AccountInfoString(ACCOUNT_CURRENCY)); //--- 自分にメールを送信する err=MailSendText(smtp,InpMailUser,InpMailFrom,InpMailSubject,text,InpMessageAttachmentFiles); if(err!=0) Print("MailSendText error: ",MailErrorDescription(err)); else PrintFormat("Program '%s' has sent mail to '%s'",MQLInfoString(MQL_PROGRAM_NAME),InpMailUser); //--- MailToにメールを送信する err=MailSendText(smtp,InpMailTo,InpMailFrom,InpMailSubject,text,InpMessageAttachmentFiles); if(err!=0) Print("MailSendText error: ",MailErrorDescription(err)); else PrintFormat("Program '%s' has sent mail to '%s'",MQLInfoString(MQL_PROGRAM_NAME),InpMailTo); } break; //--- case MESSAGE_HTML: { //--- htmlを構築する string html=BuildReport(); //--- htmlを送信する err=MailSendHtml(smtp,InpMailTo,InpMailFrom,InpMailSubject,html,""); if(err!=0) Print("MailSendText error: ",MailErrorDescription(err)); else PrintFormat("Program '%s' has sent mail to '%s'",MQLInfoString(MQL_PROGRAM_NAME),InpMailTo); } break; //--- case MESSAGE_INLINE_TEXT: { err=MailSendInlineTextFile(smtp,InpMailTo,InpMailFrom,InpMailSubject,InpMessageInlineFiles); if(err!=0) Print("MailSendText error: ",MailErrorDescription(err)); else PrintFormat("Program '%s' has sent mail to '%s'",MQLInfoString(MQL_PROGRAM_NAME),InpMailTo); } break; //--- case MESSAGE_INLINE_HTML: { err=MailSendInlineHtmlFile(smtp,InpMailTo,InpMailFrom,InpMailSubject,InpMessageInlineFiles); if(err!=0) Print("MailSendText error: ",MailErrorDescription(err)); else PrintFormat("Program '%s' has sent mail to '%s'",MQLInfoString(MQL_PROGRAM_NAME),InpMailTo); } break; } //--- 接続を閉じる MailClose(smtp); } //+------------------------------------------------------------------+ //| BuildReport | //+------------------------------------------------------------------+ string BuildReport() { CArrayString html; //--- html.Add("<html><head><title>Report</title>"); html.Add("<meta name=\"format-detection\" content=\"telephone=no\">"); html.Add("<style type=\"text/css\" media=\"screen\">"); html.Add("<!--"); html.Add("td{font: 8pt Tahoma,Arial;}"); html.Add("//-->"); html.Add("</style>"); html.Add("<style type=\"text/css\" media=\"print\">"); html.Add("<!--"); html.Add("td{font: 7pt Tahoma,Arial;}"); html.Add("//-->"); html.Add("</style>"); html.Add("</head>"); html.Add("<body topmargin=1 marginheight=1> <font face=\"tahoma,arial\" size=1>"); html.Add("<div align=center>"); html.Add(StringFormat("<div style=\"font: 18pt Times New Roman\"><b>%s</b></div>",AccountInfoString(ACCOUNT_SERVER))); html.Add("<table cellspacing=1 cellpadding=3 border=0>"); //--- html.Add("<tr>"); html.Add(StringFormat("<td colspan=2>A/C No: <b>%d</b></td>",AccountInfoInteger(ACCOUNT_LOGIN))); html.Add(StringFormat("<td colspan=6>Name: <b>%s</b></td>",AccountInfoString(ACCOUNT_NAME))); html.Add("<td colspan=2> </td>"); html.Add(StringFormat("<td colspan=2 align=right>%s</td>",TimeToString(TimeCurrent()))); html.Add("</tr>"); //--- html.Add("<tr>"); html.Add("<td colspan=13><b>Open Trades:</b></td>"); html.Add("</tr>"); //--- html.Add("<tr align=center bgcolor=\"#C0C0C0\">"); html.Add("<td>Ticket</td>"); html.Add("<td nowrap>Open Time</td>"); html.Add("<td>Type</td>"); html.Add("<td>Size</td>"); html.Add("<td>Symbol</td>"); html.Add("<td>Price</td>"); html.Add("<td>S/L</td>"); html.Add("<td>T/P</td>"); html.Add("<td>Price</td>"); html.Add("<td nowrap>Commission</td>"); html.Add("<td>Swap</td>"); html.Add("<td>Profit</td>"); html.Add("</tr>"); //--- double profit=0.0; int total=PositionsTotal(); if(total == 0) { html.Add("<tr align=right><td colspan=13 nowrap align=center>No transactions</td></tr>"); } else { CPositionInfo m_position; for(int i=0; i<total; i++) { m_position.SelectByIndex(i); //--- 色 if((i&1)==0)html.Add("<tr align=right>"); else html.Add("<tr bgcolor=#E0E0E0 align=right>"); //--- データ html.Add(StringFormat("<td>%d</td>",m_position.Identifier())); html.Add(StringFormat("<td> %s</td>",TimeToString(m_position.Time()))); if(m_position.PositionType()==POSITION_TYPE_BUY) html.Add("<td>buy</td>"); else html.Add("<td>sell</td>"); html.Add(StringFormat("<td>%.2f</td>",m_position.Volume())); html.Add(StringFormat("<td>%s</td>",m_position.Symbol())); html.Add(StringFormat("<td>%.5f</td>",m_position.PriceOpen())); html.Add(StringFormat("<td>%.5f</td>",m_position.StopLoss())); html.Add(StringFormat("<td>%.5f</td>",m_position.TakeProfit())); html.Add(StringFormat("<td>%.5f</td>",m_position.PriceCurrent())); html.Add(StringFormat("<td>%.2f</td>",m_position.Commission())); html.Add(StringFormat("<td>%.2f</td>",m_position.Swap())); html.Add(StringFormat("<td>%.2f</td>",m_position.Profit())); html.Add("</tr>"); //--- profit+=m_position.Profit(); } } //--- html.Add("<tr>"); html.Add(StringFormat("<td colspan=2><b>Balance: %.2f</b></td>",AccountInfoDouble(ACCOUNT_BALANCE))); html.Add(StringFormat("<td colspan=5><b>Equity: %.2f</b></td>",AccountInfoDouble(ACCOUNT_EQUITY))); html.Add("<td colspan=3><b>Floating P/L:</b></td>"); html.Add(StringFormat("<td colspan=4 align=right><b>%.2f</b></td>",profit)); html.Add("</tr>"); //--- html.Add("</table></div></font></body></html>"); //--- 1つの文字列に格納する string result=""; total=html.Total(); for(int i=0;i<total;i++) result+=html.At(i); //--- 完了 return(result); } //+------------------------------------------------------------------+
結果:
MetaQuotes Ltdによってロシア語から翻訳されました。
元のコード: https://www.mql5.com/ru/code/11466

このエキスパートはすべての銘柄と時間枠上で動作し、2本の線形移動平均線の交差をシグナル、1本の指数移動平均線をトレーリングストップとして使用します。

デルタジグザグに基づいてポジションを追跡するためのMQL5ウィザードモジュール。