
MT4・MT5 コンパイルエラー・警告 警告(コンパイルは通る)
implicit conversion from 'number' to 'string'
- エラー番号
warning 181- 意味
- 数値と文字列が暗黙に変換されている
「implicit conversion from 'number' to 'string'」とは
文字列と数値を + でつないだり、比較したりしたときに出る警告です(MT4 は警告番号181/180、MT5 は94/93)。動作はしますが、意図しない変換を防ぐため明示的に変換するのがおすすめです。
MetaEditor での表示例
| MT4 | warning 181: implicit conversion from 'number' to 'string' |
|---|---|
| MT5 | warning 181: implicit conversion from 'int' to 'string' |
実際のログでは先頭に「ファイル名(行,列) :」が付きます。ログの行をダブルクリックすると、エラーの場所にカーソルが移動します。表示は 2026年9月の MetaEditor で確認したもので、ビルドによって細部が変わることがあります。
「implicit conversion from 'number' to 'string'」の主な原因
- "価格:" + 1.2345 のように文字列と数値を + でつないだ
- 文字列の変数と数値を == で比較した
- int を返す関数で文字列を return した(string → number の変換)
「implicit conversion from 'number' to 'string'」の対処法
- 数値は IntegerToString()・DoubleToString(値, 桁数) で文字列にしてからつなぐ
- 文字列を数値にするなら StringToInteger()・StringToDouble() を使う
- ログ出力は Print("価格:", 値) のようにカンマで区切れば変換は不要
コード例(MQL5)
// 型変換を明示する(possible loss of data / implicit conversion 対策)
void Example()
{
double d = 12.7;
// NG: int a = d; ← 警告(小数点以下が切り捨てられる)
int a = (int)d; // 切り捨てでよいなら明示的にキャスト
int b = (int)MathRound(d); // 四捨五入したいなら MathRound
// NG: string s = "lots=" + 0.1; ← implicit conversion の警告
string s = "lots=" + DoubleToString(0.1, 2);
Print(a, " ", b, " ", s);
}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












