LoginSignup
6
7

More than 3 years have passed since last update.

【超簡単】MetaTrade4からLINE@へメッセージを送る

Last updated at Posted at 2019-01-10

MetaTrede4からLINE@へメッセージを送る方法を調べたところ、直接送信する記事がなかったので書いてみようと思いました。
LINE Messaging APIを使ってMT4からLINE@へメッセージ通知を行います。

事前準備

・LINE developersでユーザーIDとチャネルトークンを取得する
(ここでは取得方法は書かないので、他で確認してください。)

ソース

code
```LINE_Send.mq4
string url = "https://api.line.me/v2/bot/message/push";
string UserID = "<ユーザーID>";
string ChannelToken = "<チャネルトークン>";

message = "{\x0022to\x0022 : \x0022" + UserID + "\x0022, \x0022messages\x0022:[{\x0022type\x0022:\x0022text\x0022,\x0022text\x0022:\x0022ラインテスト\x0022},{\x0022type\x0022:\x0022text\x0022, \x0022text\x0022:\x0022Hello, world2\x0022}]}";

headers="Content-Type: application/json\r\n";
headers+="Authorization: Bearer "+ChannelToken;

string data = ArrayResize(post,StringToCharArray(message,post,0,WHOLE_ARRAY,CP_UTF8)-1);
œœ
int rest=WebRequest("POST",url,headers,5000,post,result,headers);
```
Qiitaのソース表示がうまくいってないですが、ソース自体は簡単ですね。
ポイントはダブルクオーテーションを「\x0022」で書くことですね。

追加で注意

スクリーンショット 2019-01-10 21.22.25.png
MT4のツール>オプションを選択し、エキスパートアドバイザタブを開きます。
そこで、WebRequestを許可するURLリストにチェックし、下記URLを追加しましょう!
https://api.line.me/v2/bot/message/push
インジケーターではWebRequestを使用できないので、EA化するかDLLを使用して対応する必要があります。

6
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7