MQL4 error diagnosis

MQL4 EA not opening trades: trace every gate

When an MQL4 EA is not opening trades, trace the path from OnTick to the entry signal, session filter, history check, spread rule, duplicate-order guard, trading permission, and OrderSend result. A compile with zero errors proves only that the source was accepted, not that these runtime gates pass.

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

EaEntryTrace.mq4.mq4
#property strict

datetime LastBarTime = 0;

void OnTick()
  {
   if(Bars < 100)
     {
      Print("Entry skipped: insufficient bars. Bars=", Bars);
      return;
     }

   if(Time[0] == LastBarTime)
      return;
   LastBarTime = Time[0];

   bool signal = Close[1] > Open[1];
   Print("Entry trace. signal=", signal,
         " connected=", IsConnected(),
         " trade_allowed=", IsTradeAllowed(),
         " spread=", MarketInfo(Symbol(), MODE_SPREAD));

   if(!signal || !IsConnected() || !IsTradeAllowed())
      return;

   // Send the validated order from one controlled function.
  }
  • Confirm OnTick is running
  • Log each entry gate separately
  • Check terminal and account permission
  • Capture the OrderSend result

Prove that the event and signal path runs

Attach the EA to the intended chart and confirm OnInit and OnTick messages appear in the Experts log. Then print the raw values behind the signal on a controlled cadence. A condition that never becomes true is not an OrderSend failure.

New-bar filters, closed-bar indexing, trading-hour comparisons, and minimum-history guards commonly stop the entry path before any trade function runs.

Name every gate between signal and order

Log each gate with a reason instead of one final “no trade” message. Include spread, current server time, existing-order count, cooldown, account state, and permission.

GateEvidence to log
EventOnInit result, last OnTick time, chart symbol and timeframe
SignalSource values, bar shift, boolean result
RiskLots, free margin, stop distance, duplicate exposure
ExecutionOrderSend ticket, GetLastError, Bid, Ask, spread

Separate no request from a rejected request

If OrderSend is never called, fix the preceding logic. If it returns -1, use the error code page for that request. If it returns a ticket, inspect order selection and later management rather than continuing to debug entry.

Review the complete example

The EA emits one trace per new bar with the signal, connection, trade permission, spread, and history state. It leaves the final order call out so the diagnostic can run without creating exposure.

The example does not place an order. When you add execution, keep volume, stop, duplicate-order, and account-wide exposure controls explicit.

EaEntryTrace.mq4.mq4
#property strict

datetime LastBarTime = 0;

void OnTick()
  {
   if(Bars < 100)
     {
      Print("Entry skipped: insufficient bars. Bars=", Bars);
      return;
     }

   if(Time[0] == LastBarTime)
      return;
   LastBarTime = Time[0];

   bool signal = Close[1] > Open[1];
   Print("Entry trace. signal=", signal,
         " connected=", IsConnected(),
         " trade_allowed=", IsTradeAllowed(),
         " spread=", MarketInfo(Symbol(), MODE_SPREAD));

   if(!signal || !IsConnected() || !IsTradeAllowed())
      return;

   // Send the validated order from one controlled function.
  }
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

    Confirm event execution

    Log OnInit and a throttled OnTick heartbeat on the intended chart.

  2. 2

    Trace the signal

    Record source values, bar shifts, and each boolean gate.

  3. 3

    Trace risk and permission

    Log spread, margin, volume, existing exposure, connection, and trade permission.

  4. 4

    Inspect OrderSend

    Record the ticket or immediate GetLastError and follow the code-specific fix.

Frequently asked questions

Why does my MQL4 EA compile but not trade?

Compilation does not run OnTick, satisfy the signal, enable trading, validate margin, or submit an order. Trace those runtime states separately.

Where should I look when an EA does nothing?

Start in the Experts and Journal logs. Add a throttled heartbeat and explicit reason for every early return.

Can an entry filter silently block all trades?

Yes. Session, spread, history, new-bar, duplicate-order, and cooldown filters can each keep the order path unreachable.

Does IsTradeAllowed guarantee OrderSend will work?

No. It checks local permission and trade-context availability, but the server can still reject price, volume, stops, margin, or account state.

Can Pineify find the blocked gate?

Pineify can revise one .mq4 file to add trace logging and make the gates explicit. You still need runtime logs from the target terminal and broker.

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