How to Fix Off-Quotes Error in MT4 and MT5 Expert Advisors

How to Resolve Off-Quotes Errors in MetaTrader

An off-quotes error stops your Expert Advisor cold — the order fires, the broker cannot match the requested price, and the trade is rejected before it ever reaches the market. According to the MQL4 Documentation, Error 136 specifically denotes "off quotes," meaning price has moved beyond your slippage tolerance faster than the broker can fill the request. Applying a reliable off quotes MT4 error fix requires changes at the code level, not just the platform settings. This MetaTrader execution troubleshooting process walks you through six targeted steps.

  1. Open MetaEditor and locate the OrderSend() call (MT4) or trade.Buy() / trade.Sell() call (MT5) inside your EA’s source file — this is the exact function producing Error 136.
  2. Insert RefreshRates() immediately before that trade execution call in MT4 to pull a fresh bid/ask snapshot and reduce the gap between your requested price and the live quote.
  3. Increase the slippage parameter inside OrderSend() from the common default of 3 pips to at least 10 pips, giving the broker a wider acceptable fill range during volatile conditions.
  4. Implement a for loop that retries the order three to five times whenever GetLastError() returns 136, so a single transient price spike does not permanently block execution.
  5. Add Sleep(200) inside the retry loop to pause execution for 200 milliseconds between attempts, allowing price to stabilize and preventing a “Trade Context Busy” condition from compounding the error.
  6. Compile the updated code and run the EA on a demo account during a high-impact news release — this stress-tests the retry logic under the real volatility that most commonly triggers off-quotes rejections.

With these changes in place, your EA handles transient price gaps gracefully rather than failing silently. The next step examines exactly how to structure that retry logic — including the critical difference between MT4's RefreshRates() approach and MT5's MqlTradeRequest struct requirements.

Step 1: Implement Code-Level Error Handling and Retry Logic

A single failed order attempt tells you very little. Transient volatility — a brief liquidity gap, a rapid spread spike — often causes one request to fail while a second, sent milliseconds later, would succeed without issue. Building retry logic directly into your EA is the foundation of any reliable off quotes MT5 Expert Advisor solution, and it applies equally to MetaTrader 4.

Accomplish this by wrapping your order function in a controlled loop that checks the specific error code before retrying:

  1. Call GetLastError() immediately after a failed order and check whether the returned value is ERR_OFF_QUOTES (error 136). Only retry on that specific code; other errors such as 130 or 138 require different fixes entirely.
  2. Insert a Sleep() call between retry attempts — [200ms to 500ms is the standard range](https://www.ea-coder.com/troubleshooting-mt4-expert-advisors/) recommended in developer best practices. Skipping this pause risks triggering a “Trade Context Busy” state, which compounds the original rejection.
  3. In MQL4, call RefreshRates() inside the loop before each retry so the EA operates on a fresh bid/ask rather than the stale price that triggered error 136.
  4. In MQL5, repopulate your MqlTradeRequest struct with updated symbol prices before resubmitting via OrderSend(). MT5 does not have RefreshRates(); current prices must be fetched explicitly using SymbolInfoDouble().
  5. Cap the loop at three to five attempts then log a meaningful failure message. An uncapped retry loop can overwhelm the broker connection during genuine market halts.
int maxRetries = 5;
int ticket     = -1;

for (int i = 0; i < maxRetries; i++) {
    RefreshRates(); // MQL4 only
    ticket = OrderSend(Symbol(), OP_BUY, lotSize, Ask, slippage, sl, tp);
    if (ticket > 0) break; // success
    int err = GetLastError();
    if (err != ERR_OFF_QUOTES) break; // non-retryable error
    Sleep(300); // pause 300ms before next attempt
}

One important caveat: retry logic handles execution failures — it does not address the underlying reason prices are unavailable. Once your retries are solid, the next layer to examine is how your EA handles market execution mode and slippage buffers, which often interact directly with error 136 in live ECN environments.

Step 2: Adjust for Market Execution and Slippage Buffers

With retry logic in place, the next common source of off-quotes rejections is a mismatch between how your EA submits orders and how your broker actually executes them. Knowing how to fix off quotes in MT4 often comes down to one critical distinction: Instant Execution versus Market Execution.

On ECN accounts, brokers typically use Market Execution. According to various broker execution guides, brokers operating under this model frequently reject orders that include SL/TP values embedded in the initial request, returning an Off-Quotes or Invalid Price error. The correct approach is to send 0 for both SL and TP in the opening order, then apply those levels in a follow-up call.

Follow this adjustment sequence in your EA code:

  1. Identify your account’s execution model by checking the broker’s account specifications or the symbol’s “Execution” field in MetaTrader’s Market Watch properties panel.
  2. Set SL and TP to 0 in your initial OrderSend() call when operating on a Market Execution account.
  3. Call OrderModify() immediately after a successful open to attach your intended stop-loss and take-profit levels as a second, separate step.
  4. Increase the Slippage parameter (MT4) or Deviation value (MT5) in your order parameters to tolerate fast price movement during volatile sessions — a value between 10 and 30 points is a practical starting range for most instruments.
  5. Cap slippage relative to lot size. On large positions, excessive slippage tolerance can cause meaningful price degradation between your intended entry and the filled price. Treat slippage as a ceiling, not a default allowance.
  6. Validate the change in a demo environment using forward testing before deploying to a live account, confirming that orders open and modify without rejection.

These adjustments address the execution-model mismatch directly in code. However, even a correctly structured order can be rejected if the price data reaching your EA is already stale — a problem rooted in infrastructure rather than logic. That is where connection latency becomes the next variable to control.

Step 3: Optimize Infrastructure and Connection Latency

Even with solid retry logic and accurate slippage buffers in place, your EA can still generate off-quotes errors if the underlying connection between your trading terminal and your broker's server is slow. Latency above 100ms significantly increases the probability of price requotes and off-quotes rejections in fast-moving markets — by the time your order reaches the broker, the price it references is already stale.

Applying this mt4 error 136 fix at the infrastructure level is often the highest-leverage change you can make. Follow these steps to identify and resolve latency-driven rejections:

  1. Move your EA to a VPS in a major trading hub. Hosting your Expert Advisor on a dedicated virtual private server located near LD4 (London) or NY4 (New York) — the primary data centers for most retail forex brokers — dramatically reduces round-trip order time and minimizes the window for price staleness.
  2. Check the Journal tab in MetaTrader. Open the Terminal window and navigate to the Journal tab. Connection drops, broker-side rejections, and network timeouts appear here separately from code-level errors, helping you distinguish an infrastructure problem from a logic bug in your EA.
  3. Monitor your EA’s request frequency. Review how many order requests your EA is sending per second. Brokers impose rate limits, and an EA firing too rapidly can trigger automatic rejections that surface as off-quotes errors rather than explicit throttle messages.
  4. Test ping latency to your broker’s server. Run a continuous ping from your VPS to your broker’s trade server address, visible under Tools → Options → Server in MT4. Consistent latency above 50ms warrants switching to a closer hosting region.
  5. Disable unnecessary background processes on your VPS. Antivirus scans, system updates, and competing applications consume bandwidth and CPU cycles, introducing unpredictable spikes in execution latency precisely when market volatility is highest.

Bold callout: VPS location is not optional for latency-sensitive EAs — a server even 500 miles closer to your broker's data center can reduce execution latency by 30–50ms, meaningfully cutting off-quotes exposure during volatile sessions.

Addressing infrastructure is the final layer of a complete execution strategy. Once you have code-level retry logic, accurate slippage handling, and low-latency connectivity working together, the remaining challenge is making all of that execution behavior visible and measurable — which the next section brings together in the key takeaways.

Key Takeaways for Reliable EA Execution

Fixing the off-quotes error is not a single-step task — it is a layered process that addresses price data freshness, slippage tolerance, broker execution mode, and infrastructure quality together. Apply these steps in sequence to build a genuinely resilient Expert Advisor:

  1. Call RefreshRates() before every OrderSend() in MT4 to ensure the EA is pricing orders against current market data, not stale tick values that the broker will reject outright.
  2. Implement expert advisor retry logic with three to five attempts and a short Sleep() delay between each. This single pattern resolves the majority of transient off-quotes rejections caused by momentary [volatility spikes](https://www.defcofx.com/off-quotes-mean-in-mt4/).
  3. Match your SL/TP submission method to your broker’s execution mode. Instant Execution brokers often require orders to be placed first, then modified — submitting SL/TP inline triggers an immediate off-quotes rejection.
  4. Set a realistic slippage buffer calibrated to the instrument’s average spread rather than a fixed placeholder. A buffer that is too tight is functionally identical to zero tolerance during fast markets.
  5. Host your EA on a dedicated trading VPS located close to your broker’s execution server. Latency above roughly 10–20 ms measurably increases the probability that quotes expire before your order arrives.
  6. Transition to professional visual systems to gain clear visibility into execution performance over time. As MQL UI Studio emphasizes, the goal is to build systems that help traders “see, validate, and automate how they trade” — making execution behavior measurable, not invisible.

Reliable EA execution comes from understanding each failure mode and addressing it deliberately. And when your trading workflow is optimized — through better dashboards, structured retry handling, and properly configured infrastructure — the off-quotes error becomes a manageable trading challenge rather than an unpredictable obstacle. Build toward that clarity with MQL UI Studio.