
MT4・MT5 コンパイルエラー・警告 エラー(コンパイルできない)
undeclared identifier
- エラー番号
error 256- 意味
- 宣言されていない名前(変数・関数)を使っている
「undeclared identifier」とは
変数・関数・定数の名前が見つからないときのコンパイルエラーです。つづりの間違い、宣言のし忘れ、変数を使える範囲(スコープ)の外で使っている、MQL4専用の名前をMQL5で使っている、のどれかがほとんどです。
MetaEditor での表示例
| MT4 | error 256: 'bbb' - undeclared identifier |
|---|---|
| MT5 | error 256: undeclared identifier 'bbb' |
実際のログでは先頭に「ファイル名(行,列) :」が付きます。ログの行をダブルクリックすると、エラーの場所にカーソルが移動します。表示は 2026年9月の MetaEditor で確認したもので、ビルドによって細部が変わることがあります。
「undeclared identifier」の主な原因
- 変数名・関数名のつづりや大文字・小文字が違う(MQLは大文字・小文字を区別する)
- 変数を宣言していない、または宣言より前の行・別の関数の中で使っている
- { } の中で宣言した変数を、その外で使っている
- MQL4 の Ask・Bid・OP_BUY・OrderSend(7引数)・Close[] などを MQL5 で使っている(MQL5 にはない)
- #include するファイルに定義があるのに、#include を書いていない
「undeclared identifier」の対処法
- ログをダブルクリックしてエラー行に移動し、名前のつづりを確認する
- 変数は使う前に宣言し、複数の関数で使うならファイルの先頭(グローバル)で宣言する
- MQL4 のコードを MQL5 で使うときは、Ask → SymbolInfoDouble(_Symbol, SYMBOL_ASK) のように書き換える
- 標準ライブラリを使うなら #include <Trade\Trade.mqh> などを追加する
コード例(MQL5)
// MQL4 の書き方を MQL5 に直す例(undeclared identifier 対策)
// NG(MQL5 では Ask・Bid・OP_BUY・Close[] がない)
// double p = Ask;
// double c = Close[1];
// OK
double AskPrice() { return SymbolInfoDouble(_Symbol, SYMBOL_ASK); }
double BidPrice() { return SymbolInfoDouble(_Symbol, SYMBOL_BID); }
double CloseAt(int shift) { return iClose(_Symbol, _Period, shift); }MetaEditor(MT5)でコンパイルできることを確認済みです。自分のEAに組み込むときは、変数名や設定値を合わせてください。
関連するエラー
コンパイルエラー・警告の解説一覧
- undeclared identifier
- semicolon expected
- unexpected token
- unexpected token, probably type is missing?
- some operator expected
- unexpected end of program
- unbalanced parentheses
- closing quote '"' expected
- wrong parameters count
- function already defined and has body
- variable already defined
- function must have a body
- function not defined
- not all control paths return a value
- function must return a value
- expression of 'void' type is illegal
- event handling function not found
- function declared with wrong type or/and parameters
- possible loss of data due to type conversion
- truncation of constant value
- implicit conversion from 'number' to 'string'
- return value of 'OrderSend' should be checked
- declaration hides global variable
- l-value required
- constant cannot be modified
- constant expression required
- invalid index value
- array required
- arrays are passed by reference only
- parameter conversion not allowed
- illegal operation use
- illegal 'else' without matching 'if'
- 'break' must be used within some loop or switch statement
- case value already used
- ambiguous call to overloaded function
- can't open include file
- unknown property
- identifier already used
- struct member undefined
- struct or class type expected
- private member access error
- cannot instantiate abstract class
- structures or classes containing objects are not allowed
- function declarations are allowed on global, namespace or class scope only
- name expected
- division by zero in the constant expression
- expression has no effect
- expression not boolean
- sign mismatch
- possible use of uninitialized variable
- empty controlled statement found
- macro redefinition
- call resolves to … due to new rules of method hiding
- cannot be used for static allocated array












