What it means
The compiler met a name it doesn't know at that point of the code. Nothing called Ask (or whatever is quoted) has been declared where the line can see it, so MetaEditor stops with error 256 and doesn't build the program. Older builds print the same error as 'Ask' - undeclared identifier.
Usual causes
- MQL4 names. MetaTrader 4's built-in variables and constants don't exist in MQL5:
Ask,Bid,Close[],Time[],OP_BUY,MODE_TRADES. Code converted from MT4 is the most common source of this error. - A typo or different capitalisation.
InpStopPointinstead ofInpStopPoints; MQL5 names are case-sensitive. - Declared out of reach. A variable declared inside an
if, a loop or another function, or further down than the line that uses it. - A missing #include. Classes like
CTradecome from#include <Trade/Trade.mqh>. Without it, MetaEditor reports'CTrade' - unexpected token, probably type is missing?rather than an undeclared identifier.
How to detect it
- MetaEditor's Errors tab, after you compile (F7), shows
undeclared identifier 'Name'with the file, the line and the column. Double-click the message to jump to it. - Fix the first error first: one missing name can cause several follow-up errors.
Broken code
MetaEditor reports two errors on line 5: undeclared identifier 'Ask' (an MQL4 variable) and undeclared identifier 'InpStopPoint' (a typo).
input int InpStopPoints = 200; // Stop distance, points
void OnStart()
{
double sl = Ask - InpStopPoint * _Point;
Print("Stop-loss would be ", DoubleToString(sl, _Digits));
}Fixed code
The same program, corrected. It compiles in MetaEditor with 0 errors and 0 warnings.
input int InpStopPoints = 200; // Stop distance, points
void OnStart()
{
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double sl = ask - InpStopPoints * _Point;
Print("Stop-loss would be ", DoubleToString(sl, _Digits));
}Why the fix works
MQL5 has no Ask variable: the current price comes from SymbolInfoDouble(_Symbol, SYMBOL_ASK) (or SymbolInfoTick(), which returns the Bid and the Ask together). The input's name now matches its declaration exactly. Both names exist where line 5 uses them, so the script compiles.
MQL4 names and their MQL5 replacements
| MQL4 | MQL5 |
|---|---|
Ask, Bid | SymbolInfoDouble(_Symbol, SYMBOL_ASK), SYMBOL_BID, or SymbolInfoTick() |
Point, Digits | _Point, _Digits (or Point(), Digits()) |
Close[i], Open[i], Time[i] | iClose(_Symbol, PERIOD_CURRENT, i), iOpen(), iTime(), or CopyRates() |
OP_BUY, OP_SELL | ORDER_TYPE_BUY, ORDER_TYPE_SELL |
OrderSend() with 11 arguments | CTrade's Buy() and Sell(): see wrong parameters count |
Without parentheses, Point and Digits give a different error in MQL5, "open parenthesis expected", because they're functions there. The rest of a port is in how to convert MQL4 to MQL5.
Questions
Why is 'Ask' an undeclared identifier in MQL5?
Because Ask and Bid were built-in variables in MQL4 only. In MQL5, read prices with SymbolInfoDouble(_Symbol, SYMBOL_ASK) and SYMBOL_BID, or get both with SymbolInfoTick().
Why is OP_BUY undeclared in MQL5?
OP_BUY and OP_SELL are MQL4 constants. MQL5 uses ORDER_TYPE_BUY and ORDER_TYPE_SELL, and the CTrade class's Buy() and Sell() methods for market orders.
Can I fix undeclared identifiers by defining the MQL4 names myself?
You can, with #define or helper functions, but it usually hides the real differences between MQL4 and MQL5, such as order handling and indicator handles. Converting the code properly is safer.
The programs on this page are minimal examples written to show the error and its fix, not trading systems. Some of them send orders when they run: try them on a demo account. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.