Advertisement IC Markets

MT4 Error 134 (Even When "You Have Money")

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

MT4 Error 134 (Even When "You Have Money")

Post by PTScalper »

Hi traders, scalpers,

Here is an extended, pro-level engineering breakdown of MT4 OrderSend Error 134 (ERR_NOT_ENOUGH_MONEY), addressing the classic discrepancy: “Why am I getting insufficient margin when my account balance is clearly healthy?”

1. The Core Misconception: Balance vs. Free Margin

The single most frequent trap developers and algorithmic traders fall into is conflating Account Balance with Free Margin.

Balance is your realized capital (deposits minus withdrawals, plus closed trade P&L). It does not change when you open a trade.

Free Margin (AccountFreeMargin()) is what you actually have available to open new positions. It is dynamically calculated as:

Free Margin = Equity - Margin (Used)

Where Equity = Balance + Floating P&L

Even if your balance is massive, if your Equity is depleted by open losing trades, or if your Used Margin is already locking up your capital, Free Margin will hit zero, throwing Error 134.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Recommended broker for automated trading & scalping IC Markets
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: MT4 Error 134 (Even When "You Have Money")

Post by PTScalper »

2. Hidden Culprits Behind Error 134 (Even When "You Have Money")

If your balance is high, open positions are profitable or flat, and you still get Error 134, check these structural margin killers:

A. Contract Size & Leverage Mismatch (Forex vs. Indices vs. Commodities)

A lot size of 1.0 on EURUSD requires a fraction of the margin required for 1.0 lot on a stock index (e.g., US30 / DAX) or Spot Gold (XAUUSD).

The Trap: Your code or manual script uses a hardcoded lot size (e.g., Lots = 1.0) across all symbols. While 1.0 lot on EURUSD needs ~$200 to $500 in margin (depending on leverage), 1.0 lot on a gold or index contract can demand thousands.

The Fix: Always dynamically query the margin requirement per lot for the specific symbol before firing OrderSend() using MarketInfo(Symbol(), MODE_MARGINREQUIRED).
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: MT4 Error 134 (Even When "You Have Money")

Post by PTScalper »

B. Hedging vs. Netting Margins & Account Type

MT4 operates primarily on a hedging model, but certain broker entity types or regulatory jurisdictions (like FIFO rules or specific account tiers) handle margin differently.

If your broker uses hedged margin discounting (where holding a Buy and a Sell on the same pair reduces the margin requirement to zero or a nominal fee), closing a hedge leg abruptly recalculates your used margin. If your remaining free margin drops below the threshold, simultaneous or subsequent orders will trigger Error 134.

C. Pending Orders Lock Up Margin

Many traders forget that pending orders (Stop and Limit orders) can reserve margin depending on the broker's server-side configuration.

If you have multiple pending breakout or grid orders sitting on the book, the broker's risk engine may pre-allocate or reserve free margin for those potential fills. When your Expert Advisor tries to fire a market order, Error 134 hits because the pending queue has cannibalized your available free margin.

D. The Stop-Out Level Trap

If your account is drifting into a drawdown and your margin level approaches your broker's Stop-Out level (e.g., 20% or 50%), the terminal enters a restricted state where new orders are universally blocked with Error 134 before the forced liquidation cascade even executes.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: MT4 Error 134 (Even When "You Have Money")

Post by PTScalper »

3. How to Diagnose and Fix It in MQL4

Never execute an OrderSend() blind. Implement a robust pre-flight check function in your MQL4 code to verify that your free margin can comfortably absorb the trade plus a safety buffer.

Robust Pre-Flight Margin Validation Function

Code: Select all

bool CheckMarginBeforeTrade(string symbol, double lots, int cmd) {
   // 1. Get the margin required to open 1 lot of this symbol
   double marginRequired1Lot = MarketInfo(symbol, MODE_MARGINREQUIRED);
   if (marginRequired1Lot <= 0) {
      Print("Error: Could not retrieve margin required for ", symbol);
      return false;
   }

   // 2. Calculate total margin required for the intended lot size
   double totalMarginNeeded = marginRequired1Lot * lots;

   // If it's a hedged account type, check if broker discounts hedged margin
   // (Optional adjustment depending on broker specs)

   // 3. Compare against current free margin with a safety buffer (e.g., 20% cushion)
   double freeMargin = AccountFreeMargin();
   double safetyBuffer = totalMarginNeeded * 0.20; 

   if (freeMargin < (totalMarginNeeded + safetyBuffer)) {
      Print("Error 134 Prevention: Insufficient Free Margin. Needed: ", 
            totalMarginNeeded + safetyBuffer, " | Available Free Margin: ", freeMargin);
      return false;
   }

   return true;
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: MT4 Error 134 (Even When "You Have Money")

Post by PTScalper »

Usage in Your Execution Logic:

Code: Select all

void OnTick() {
   string targetSymbol = "XAUUSD";
   double lotSize = 0.5;
   
   // Run pre-flight check before sending
   if (CheckMarginBeforeTrade(targetSymbol, lotSize, OP_BUY)) {
      int ticket = OrderSend(targetSymbol, OP_BUY, lotSize, Ask, 3, 0, 0, "Pro Scalp", 12345, 0, clrGreen);
      if (ticket < 0) {
         Print("OrderSend failed with error #", GetLastError());
      }
   } else {
      Print("Trade aborted locally to prevent Error 134.");
   }
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: MT4 Error 134 (Even When "You Have Money")

Post by Shadow Trader »

The pending orders point is a good one, and it's the one most likely to confuse an EA developer, because the behaviour depends on the broker's server settings and can't be seen from the code alone.

For anyone debugging Error 134, a simple routine before each OrderSend makes the problem much easier to find:

Log AccountEquity, AccountMargin and AccountFreeMargin right before the call.
Log MarketInfo(Symbol(), MODE_MARGINREQUIRED) multiplied by the lot size you're about to send.
Use AccountFreeMarginCheck(Symbol(), cmd, lots) and log what it returns. If it comes back negative or zero, the order will fail and you know it before sending.

With those numbers in the log, the cause is usually obvious within a couple of failures: either the lot size is wrong for that symbol, or floating losses have eaten the free margin, or something else is holding margin.

It's also worth remembering that margin requirements are not always fixed. Some brokers raise them before weekends, before major news or on specific instruments, so an EA that worked all week can start throwing 134 on Friday afternoon with no code change at all.

And for multi-symbol EAs, sizing should be calculated per symbol. A hardcoded lot that's fine on EURUSD can be several times too large on gold or an index, as you point out.

Does anyone know whether MT5's OrderCheck gives more reliable answers than the MT4 checks here, especially with pending orders on the book?
Post Reply