Skip to content

Runtime error

4109 ERR_CHART_WRONG_PROPERTY

A wrong chart property (MQL5), trade not allowed (MQL4)

What it means

In MQL5, 4109 is a chart error: a chart function was asked for a property ID it does not know. In MQL4, 4109 is ERR_TRADE_NOT_ALLOWED ("Trade is not allowed. Enable checkbox "Allow live trading" in the Expert Advisor properties"); in MQL5 the same situation is error 4752 and retcode 10027.

Common causes

  • MQL5: a property passed to the chart function of the wrong type, for example a double property to ChartGetInteger(), or a numeric ID copied from old code.
  • MQL4: the EA's "Allow live trading" box unticked, or the terminal's automated trading switched off.
  • MQL4 to MQL5 ports that still test for 4109 after a failed trade and never see it, because MQL5 reports trade permissions with other codes.

A real scenario

A trader ports an MQL4 EA whose error handler says "Enable live trading" when it sees 4109. In MQL5 the handler never fires: with Algo Trading off, the journal shows 4752 and retcode 10027 instead, and the EA silently stops trading. The port now checks the three MQL5 permissions in OnTick() and shows on the chart which one is off.

How to fix it

  1. MQL5 chart code: use the function that matches the property type (ChartGetInteger, ChartGetDouble, ChartGetString) and the named CHART_* constants.
  2. MQL4 meaning: in MQL5, check TERMINAL_TRADE_ALLOWED, MQL_TRADE_ALLOWED and ACCOUNT_TRADE_EXPERT before trading.
  3. Replace MQL4 error numbers in ported handlers with the MQL5 codes (4752, 10027).

Fixed MQL5 code

MQL5
// MQL5 meaning: ask for a chart property with the function of its type.
long ChartScaleOrMinusOne()
{
   long scale = -1;
   ResetLastError();
   if(!ChartGetInteger(0, CHART_SCALE, 0, scale))     // CHART_SCALE is an integer property
      PrintFormat("ChartGetInteger failed, error %d", GetLastError());
   return scale;
}

// MQL4 meaning ("Trade is not allowed"): the MQL5 checks to run before trading.
bool MayTrade()
{
   if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) { Comment("Algo Trading is off in the terminal"); return false; }
   if(!MQLInfoInteger(MQL_TRADE_ALLOWED))           { Comment("Allow Algo Trading in the EA's properties"); return false; }
   if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))    { Comment("The broker does not allow EAs on this account"); return false; }
   Comment("");
   return true;
}

A focused example for MetaTrader 5: adapt names, magic number and limits to your EA, and test it on a demo account first.

EA Doctor rules that catch it

  • HighMQL4 functions in an MQL5 fileThe file uses MQL4's order functions and variables (OP_BUY, OrderSelect by position, Bid, Ask, Close[]), which MQL5 does not have.

Sources

Get your EA fixed

Still failing with 4109? Send us the EA and the journal lines: we find the cause in the code and fix it. Or check it yourself first with the EA Doctor.