0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【mt4/mql4】口座情報(証拠金、残高、ほか)を表示する

Last updated at Posted at 2021-11-01

はじめに

システムトレードプログラマのmt4/mql4のメモノートです。
初心者向けの簡単なトピックから公開していきます。
.noteでEAそのものも公開していますので良ければそちらも見てください。

目次

  1. 処理内容
  2. mql4ソースコード

処理内容

証拠金額や残高など、様々な口座情報を表示させる方法です。
実際には、有効証拠金や残高などを使ってロット単位のロジックを組むケースが多いと思いますが
まずはざっと関連情報を表示させ、ログにも残すことで
その後の挙動解析などをやりやすくすることが必要かと思ってます。

ちなみに、稼働させるとMT4のコンソールにはこんな感じで表示されます。
56万くらい入れてるテスト用口座です。ちなみにoandaでポジション無し時

test.PNG

mql4ソースコード

こちらがソースコードです。
int OnInit()の中でなくてももちろん動きますが、EA設定時の最初に出力しておいたほうが使いやすいと思います。(ログの追跡などにも)

test.mq4

int OnInit()
  {
//---口座情報出力
   printf("口座残高/ACCOUNT_BALANCE: %G",AccountInfoDouble(ACCOUNT_BALANCE));
   printf("クレジット/ACCOUNT_CREDIT: %G",AccountInfoDouble(ACCOUNT_CREDIT));
   printf("評価損益/ACCOUNT_CREDIT: %G",AccountInfoDouble(ACCOUNT_PROFIT));
   printf("有効証拠金/ACCOUNT_EQUITY: %G",AccountInfoDouble(ACCOUNT_EQUITY));
   printf("必要証拠金/ACCOUNT_MARGIN: %G",AccountInfoDouble(ACCOUNT_MARGIN));
   printf("余剰証拠金/ACCOUNT_FREEMARGIN: %G",AccountInfoDouble(ACCOUNT_FREEMARGIN));
   printf("証拠金維持率(%%)/ACCOUNT_MARGIN_LEVEL: %G",AccountInfoDouble(ACCOUNT_MARGIN_LEVEL));
   printf("マージンコールレベル/ACCOUNT_MARGIN_SO_CALL: %G",AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL));
   printf("マージンストップレベル/ACCOUNT_MARGIN_SO_SO: %G",AccountInfoDouble(ACCOUNT_MARGIN_SO_SO));
   printf("ログインID/ACCOUNT_LOGIN: %d",AccountInfoInteger(ACCOUNT_LOGIN));
   printf("トレードモード/ACCOUNT_TRADE_MODE: %d",AccountInfoInteger(ACCOUNT_TRADE_MODE));
   printf("レバレッジ/ACCOUNT_LEVERAGE: %d",AccountInfoInteger(ACCOUNT_LEVERAGE));
   printf("注文上限/ACCOUNT_LIMIT_ORDERS: %d",AccountInfoInteger(ACCOUNT_LIMIT_ORDERS));
   printf("アカウントマージンモード/ACCOUNT_MARGIN_SO_MODE: %d",AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE));
   printf("アカウントの取引許可/ACCOUNT_TRADE_ALLOWED: %d",AccountInfoInteger(ACCOUNT_TRADE_ALLOWED));
   printf("EA取引許可/ACCOUNT_TRADE_EXPERT: %d",AccountInfoInteger(ACCOUNT_TRADE_EXPERT));
   printf("アカウント名/ACCOUNT_NAME: %s",AccountInfoString(ACCOUNT_NAME));
   printf("アカウントサーバー名/ACCOUNT_SERVER: %s",AccountInfoString(ACCOUNT_SERVER));
   printf("口座標準通貨/ACCOUNT_CURRENCY: %s",AccountInfoString(ACCOUNT_CURRENCY));
   printf("口座開設会社/ACCOUNT_COMPANY: %s",AccountInfoString(ACCOUNT_COMPANY));
   
//---
  }

皆様の手助けになりますように。
間違いなどあればご指摘いただけると助かります。
以上です

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?