MetaEditor diagnostics

Fix common MQL4 compile errors

Fix the first compiler error before later ones: a missing declaration, delimiter, or wrong event signature can create many secondary messages. Treat warnings as review items, especially possible data loss, missing indicator buffers, and unchecked return values.

Open the Coding Agent, then choose MQL4 from the language menu.

ValidCloseLine.mq4.mq4
#property strict
#property indicator_chart_window
#property indicator_buffers 1

double CloseBuffer[];

int OnInit()
  {
   SetIndexBuffer(0, CloseBuffer);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1, clrBlue);
   SetIndexLabel(0, "Close");
   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int start = (prev_calculated > 0) ? prev_calculated - 1 : 0;
   for(int i = start; i < rates_total; i++)
      CloseBuffer[i] = close[i];

   return(rates_total);
  }
  • Repair the first error first
  • Match event signatures exactly
  • Declare indicator buffers and styles
  • Review narrowing conversions

Undeclared identifier usually means scope or spelling

MetaEditor cannot resolve a name when it was never declared, is misspelled, belongs to another function scope, or comes from an API that is not MQL4. Copying MQL5 position classes or Pine Script namespaces into an .mq4 file creates valid-looking but unavailable identifiers.

Find the intended owner of the name. A local variable must be declared before use, an input belongs at global scope, and an MQL5-only API needs an MQL4 design rather than a rename.

  • Check capitalization and spelling at the first reported use
  • Check whether the declaration is inside another block or function
  • Confirm the function exists in the MQL4 reference
  • Do not silence the message with an unrelated dummy declaration

Indicator properties and handlers are structural

A custom indicator needs enough declared buffers for the mapped output series. Its OnCalculate return type and parameter list must match a documented signature. A handler with the wrong type may compile with a warning but will not be called as intended.

The keyword indicator_plots often appears in code written for MQL5. In an MQL4 target, verify supported properties and use MQL4 buffer mapping and drawing functions instead of copying a property across languages.

Diagnostic areaQuestion to askTypical repair
IdentifierWhere is this name declared?Correct scope, spelling, or API target
Event handlerDoes the signature match the program type?Use the documented return and parameters
Indicator bufferAre enough buffers declared and mapped?Align indicator_buffers and SetIndexBuffer calls
Type conversionCan the destination represent the value?Use the correct type or an explicit checked conversion

A warning can still identify a real defect

Compiler warning 43 identifies possible data loss during type casting. An explicit cast documents intent but does not make truncation correct. Check the permitted value range and rounding rule before converting a double or long to int.

Other warnings flag unused variables, missing return values, unchecked function results, and indicator configuration gaps. Resolve or justify each one before treating a build as ready for runtime testing.

Review the complete example

The example declares one indicator buffer, maps it in OnInit, uses the complete OnCalculate signature, returns rates_total, and keeps each identifier in scope. It is a useful baseline when repairing an indicator whose declarations have drifted.

A zero-error compile proves that the compiler accepted the source. It does not prove indicator values, order behavior, history quality, or broker compatibility.

ValidCloseLine.mq4.mq4
#property strict
#property indicator_chart_window
#property indicator_buffers 1

double CloseBuffer[];

int OnInit()
  {
   SetIndexBuffer(0, CloseBuffer);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1, clrBlue);
   SetIndexLabel(0, "Close");
   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int start = (prev_calculated > 0) ? prev_calculated - 1 : 0;
   for(int i = start; i < rates_total; i++)
      CloseBuffer[i] = close[i];

   return(rates_total);
  }
Where Pineify fits

Move from the rule to editable MQL4 source

Pineify can generate or revise one self-contained .mq4 file with MQL4-specific reference context. Its independent static checker returns MetaEditor diagnostics so you can repair source issues before testing in your own MT4 environment.

Open MQL4 Coding Agent

Static diagnostics do not prove runtime behavior, backtest results, broker compatibility, or live-trading safety.

Pineify MQL4 Coding Agent with MQL4 selected and an editable MetaTrader 4 code artifact

A practical workflow

  1. 1

    Start at the first diagnostic

    Later parser messages may disappear after the earliest missing token or declaration is fixed.

  2. 2

    Confirm the language target

    Check that the source uses MQL4 handlers, properties, trade APIs, and function signatures.

  3. 3

    Repair the smallest scope

    Change the declaration, call, or signature without rewriting unrelated trading logic.

  4. 4

    Recompile and review warnings

    Repeat until errors are gone and every remaining warning has an explicit explanation.

Frequently asked questions

How do I fix undeclared identifier in MQL4?

Verify spelling, scope, declaration order, and whether the name belongs to MQL4. An MQL5-only or Pine Script identifier needs a language-specific rewrite.

What does possible loss of data due to type conversion mean?

The destination type may not preserve the source value or precision. Check range and rounding before using an explicit cast.

Is indicator_plots an MQL4 property?

Do not assume MQL5 indicator properties apply to MQL4. For an MQL4 file, follow the MQL4 indicator buffer and drawing APIs supported by the target compiler.

Why does a handler compile but never run?

An event handler must match the documented name, return type, and parameters. A mismatched declaration can be ignored by the terminal.

Should I ignore MQL4 compiler warnings?

No. Warnings are not compile errors, but they can identify truncation, missing buffers, unchecked results, or handlers that will not behave as intended.

Last verified against the linked official references on . Compile and test the final source in the MetaTrader 4 build, broker, symbol, and account environment you plan to use.

Continue with one reviewable MQL4 file

Define the requirement, inspect the generated source, repair diagnostics, and test the behavior in your own MT4 environment.

Open Coding Agent