โ† All tutorials
MT5 API ยท 4:14

Trading error handling.

Understand fills, pending orders and broker refusals. Read the result before sending another trade.

Step-by-step transcript

  1. 0:00

    Trading error handling.

    This tutorial shows how to understand MT5 trading results and errors. We will distinguish completed trades, partial fills, pending orders, broker refusals, and uncertain outcomes.

  2. 0:15

    Open the trading method’s guide.

    Open M T five dot M R P C dot pro. Select Order Send in the Trading Helper section. Below the code example, expand How to check whether a request succeeded. For another trading method, open that method’s own guide.

  3. 0:33

    1. Check the HTTP status code.

    First, check the HTTP status code. HTTP status code two hundred means the API received the request and returned a response. Read the JSON body next. For another status code, read the HTTP error and its response body first.

  4. 0:53

    2. Inspect error and broker details.

    If error is not null, read error code and error message. When present, also read M Q L error trade integer code and its description. A broker rejection can appear in this error structure, so use its actual code to choose the corrective action.

  5. 1:12

    Step 3. Read the broker result.

    For a trading request, HTTP status code two hundred with no API error means the request was submitted to the broker. It does not mean that the broker filled it. Read data dot returned code, returned string code, and the method-specific result.

  6. 1:31

    Market order: filled or partly filled?

    For a market Buy or Sell, ten thousand and nine, Done, means completed. Ten thousand and ten, Done Partial, means only part was filled. Read the executed volume, price, and deal. Check open positions and history to resolve any remainder.

  7. 1:50

    Pending placement is not a market fill.

    For a market order, ten thousand and eight, Placed, means accepted for execution, not yet a confirmed fill. For a pending order, Placed or Done confirms placement. Save data dot order and inspect Opened Orders. The pending order still waits for its trigger price.

  8. 2:10

    Market closed is a broker refusal.

    A broker refusal can be inside data even when error is absent. Ten thousand and eighteen means the market is closed. Wait for the symbol’s trading session. The presence of data does not make the trade successful. The code tells you what happened.

  9. 2:28

    Fix the specific trading problem.

    Insufficient funds means reduce the volume or provide sufficient free margin. Invalid stops means correct stop distances and prices. Invalid volume means use the symbol’s allowed size and step. No quote means wait for a current quote. The guide shows the code and next action together.

  10. 2:50

    A timeout needs a state check.

    A trade timeout or lost broker connection leaves an uncertain outcome. Read open orders, positions, and history before submitting again. Otherwise you could create a duplicate trade. The same broker code may appear in data dot returned code or error dot M Q L error trade integer code.

  11. 3:13

    Close and modify have their own rules.

    For Order Close, read the close result and then inspect remaining positions. A partial close leaves volume open. For Order Modify, Done means modified, while No Changes means the requested values were already set. Do not apply Order Send rules to every trading method.

  12. 3:33

    Preflight checks do not place trades.

    Order Check is different from Order Send. Read returned code and comment inside data dot M Q L trade check result. A zero code with Done means the preflight check passed. It does not place an order. Send the trade separately and inspect that execution result.

  13. 3:53

    Trading checks: one, two, three.

    For every trade, check the HTTP status code, inspect error, and read the broker result for that specific method. Keep the returned order, deal, or position identifiers as appropriate. After a timeout or lost connection, inspect account state before sending the request again.