Skip to content

Trading mechanics

How Forex Trading Works: Orders, Lots, Margin and Costs in MT5

Forex trading works by using a broker’s quotes to request and manage currency positions. Buys generally fill at the ask and sells at the bid. In MetaTrader 5 (MT5), an order is a request, not a confirmed fill. The broker checks its volume, stops, margin and filling type. Orders can wait, execute, be rejected or be cancelled. Executed deals can open, change or close positions, with costs determined by the broker’s terms.

This hub maps PineConnector's trading mechanics library: the parts of a trade that stay the same whatever strategy sends it. CFDs on indices, metals and other assets follow the same chain, with contract sizes, margin rules and sessions set in each symbol's specification. When a TradingView alert starts the chain, PineConnector and its EA pass the request on, and the broker still accepts or rejects it.[1]

Illustrative cover for how forex trading works: a request passing four broker checks before becoming a position, with the official PineConnector logo.
The trading mechanics library: from quote and order to margin and costs.

Which trading mechanics guide answers your question?

The library groups its guides by the stage of a trade where each question comes up. Start with the stage you are stuck on. The diagram in the next section shows how the stages connect.

Quotes and prices

Orders and execution

Size, leverage and margin

Positions and accounts

Costs

Time, sessions and gaps

How does a forex order become a position?

MetaQuotes describes MT5 trading with three linked records: an order, a deal and a position.[2] The diagram adds the alert that starts an automated request, and the costs.

Illustrative flow diagram of how forex trading works in MT5: a TradingView alert, a PineConnector EA order request, four broker checks (volume, stops level, free margin, filling), a deal and a position, with spread, commission, swap and slippage as costs.
Illustrative diagram. MetaQuotes documents each check but not a public processing order. Acceptance, the deal and the resulting position are separate records.
  1. Quote. Market Watch shows each symbol's bid and ask; the spread is the difference.[3] A security is generally bought at the ask and sold at the bid.[2] A TradingView chart can use another feed, from ICE composite symbols to individual brokers.[4]
  2. Signal. In an automated setup, a TradingView alert triggers and its webhook sends an HTTP POST with the alert message as the body.[5] A PineConnector message holds a License ID, a command, the broker's exact symbol and parameters.[6] The receiving EA applies its settings, and the broker accepts or rejects the resulting request.[1]
  3. Order. An order is an instruction to a broker to buy or sell. MT5 offers market orders and six pending types: buy limit, buy stop, sell limit, sell stop, buy stop limit and sell stop limit.[2][7] Each order records its volume, stop loss, take profit and filling type.[8]
  4. Checks. The trade server checks the order's correctness, including prices and available funds, and can reject it.[2] The next section lists the checks.
  5. Deal. A deal is the actual buy or sell, and one order can produce several deals.[2] The broker sets each symbol's execution mode. In Market Execution, sending an order means agreeing in advance to the broker's price. In Instant Execution, a broker that does not accept the requested price sends a requote.[2]
  6. Position. A deal can open, add to, reduce, close or reverse a netting position. A hedging account can hold separate positions, including opposite ones.[2] Check actual SL/TP on the receiving position. The forex examples use Bid for a long’s trigger and Ask for a short’s. Exchange Stocks, Exchange Futures and Futures Forts follow exchange trigger rules, usually Last.[2][7]
  7. Margin. While the position is open, MT5 shows its margin, the free margin (equity minus margin) and the margin level (equity divided by margin, times 100).[7] Margin call and stop-out levels are properties of the account, set in percent or in the deposit currency.[9] In MT5's normal mode, a stop-out closes the position with the largest loss first.[7]
  8. Costs and close. The spread is paid through the ask-to-bid round trip. Commission follows the broker's terms, and swap follows the specification's swap settings at each rollover.[7][3] A netting position closes with an opposite deal of the same volume; a hedging position closes with Close Position.[2]

Each stage leaves its own evidence. TradingView's alert log has a Webhook status column for delivery.[5] PineConnector's docs treat receipt of a message and the broker outcome as separate checks.[10] In MT5, the Trade tab lists the open position, and the History tab lists the order and each deal it produced.[7]

What does the broker check before it accepts an order?

MetaQuotes documents each check below in the symbol specification or the account state. The MetaQuotes pages cited here do not give the order in which the server applies them, so treat them as a set. Each failure has its own MQL5 trade server return code.[11]

Scroll horizontally to read every column.

Check What the request must satisfy Return code if it fails
Volume Lots between the symbol's minimal and maximal volume, in whole volume steps.[3][12] 10014, invalid volume
Stop distance Stop loss, take profit and pending prices outside the Stops level channel, counted in points from the current price.[3] 10016, invalid stops
Margin Enough free margin to cover the margin the new order needs.[2][7] 10019, not enough money
Filling A filling type the symbol allows under its execution mode.[8][2] 10030, invalid filling type
Trade mode and session A symbol open to this direction at this time. Some symbols are long only, short only or close only.[3] 10017, trade disabled; 10018, market closed

A rejected request produces no deal and no position. PineConnector's error guide lists unsupported filling mode, invalid volume and invalid stops among the messages that can appear beside MT5 error 4756. The guide adds that 4756 alone does not select one fix.[13] For the fixes, see how to fix MT5 error 4756 and common MetaTrader errors in automated trading.

One illustrative EURUSD order, check by check

Illustrative example, not a recommendation. A USD account has a balance of 10,000.00 USD, no open positions and leverage of 1:30. The EURUSD specification is invented for the arithmetic: contract size 100,000, five digits (Point 0.00001), Stops level 20 points, volume from 0.01 to 100 in steps of 0.01, Forex margin calculation and a margin rate of 1. The quote is bid 1.10000, ask 1.10010.

The TradingView alert's Message field holds this illustrative PineConnector message, with your License ID in place of LicenseID:

LicenseID,buy,EURUSD,vol_lots=0.30,sl_pips=20

Forex margin = lots × contract size ÷ leverage (in the base currency), converted to the deposit currency, × margin rate

  1. Volume: 0.30 lot sits inside 0.01 to 100 and is exactly 30 steps of 0.01, so it passes.
  2. Stop distance: one PineConnector pip is 10 points,[14] so 20 pips is 200 points, or 0.00200. The minimum distance is Stops level × Point = 20 × 0.00001 = 0.00020,[15] so the stop passes.
  3. Margin: 0.30 × 100,000 ÷ 30 = 1,000.00 EUR. For a buy, MT5 converts at the current ask: 1,000.00 × 1.10010 = 1,100.10 USD.[16] Free margin of 10,000.00 USD covers it, so it passes.
  4. Filling: the request must use a filling type listed in the symbol's Filling field.[3] The example assumes it does.
  5. Deal and position: assume the order fills at the 1.10010 ask. Closing a long means selling at the bid, so the position opens one spread behind: (1.10000 − 1.10010) × 30,000 units = −3.00 USD.
  6. Account state: ignoring when commission is charged, equity is 10,000.00 − 3.00 = 9,997.00 USD. Free margin is 9,997.00 − 1,100.10 = 8,896.90 USD. Margin level is 9,997.00 ÷ 1,100.10 × 100, about 908.7%.[7]

At 0.30 lot, one pip is worth 0.30 × 0.0001 × 100,000 = 3.00 USD. The 1.0-pip spread therefore costs 3.00 USD. An illustrative commission of 7 USD per lot for the round turn adds 2.10 USD, for 5.10 USD, or 1.7 pips, before swap and slippage. Each 0.1 pip of slippage on either fill adds 0.30 USD. Holding through rollover adds the specification's swap.

The 20-pip stop plans a loss of 20 × 3.00 = 60.00 USD before costs, so the known costs equal 5.10 ÷ 60.00 = 0.085 R. The planned loss is not a maximum: costs, fills and gaps can make the actual loss differ.[17] In this example, leverage changes only the margin figures. At 1:100, the margin would be 300.00 EUR, or 330.03 USD, and one pip would still be worth 3.00 USD.

Where do you read each number in MT5?

Open Market Watch, right-click the exact broker symbol and choose Specification.[3][15] Use the receiving account's specification, as it stands on the day you check. PineConnector's docs list the same fields to record. On PineConnector Edge, the Symbols tab (Portal → Edge → Symbols) lists every symbol the broker offers, with its specification, including digits, contract size, minimal volume, volume step and stops level, and lets you copy the exact symbol name into the alert instead of retyping it (Edge Symbols guide). For a field the tab does not show, the docs say to request the specification through the broker or support.[15]

Number Where in MT5 What it decides
Bid, ask, spread Market Watch The fill side and the spread cost
Contract size, Digits, Tick size, Tick value Specification Pip value and profit per price step
Minimal volume, Maximal volume, Volume step Specification Whether a lot size is valid
Stops level (points) Specification The minimum distance for stops, targets and pending orders
Execution, Filling Specification Which filling types a request can use
Calculation, Margin currency Specification The margin formula and its conversion
Swap type, Swap long, Swap short, Swap rates Specification The holding cost at each rollover
Balance, Equity, Margin, Free margin, Margin level, each position's Swap Toolbox, Trade tab Room for another order, and swap charged so far
Orders, deals, each deal's Commission Toolbox, History tab What happened, and what it cost

Field names follow MetaQuotes' help as of 25 September 2026.[3][7] On the TradingView side, note which data provider the chart uses. Volume data and trading hours can vary by provider,[4] and your broker quotes its own bid and ask. Read why TradingView prices differ from your broker's before relying on exact price levels in an alert.

How should you use this library?

Every number in these guides is illustrative. Your broker's specification, your account type and your regulator decide the real values.

What does this map leave out?

  • Broker variation. The broker sets each symbol's execution mode and each account's netting or hedging system.[2] Commission terms are the broker's too.[7] Each account carries its own margin call and stop-out levels.[9]
  • Volume rounding. PineConnector's FAQ says the EA checks the broker's minimum, maximum and step before sending a size.[19] Its syntax reference says to compare the requested and accepted volume rather than assume a rounding direction.[17]
  • Acceptance is not the final state. An accepted request, a deal and the resulting position are separate facts. On a netting account, a new deal can reduce or reverse a position instead of opening one.[2] Only a stop loss that reached the broker is held on its server;[7] a level that exists only in a chart script is not.
  • Regulation. Retail leverage limits and margin close-out rules are set by regulators, so check the rules that apply to your account. ASIC's order for retail CFD clients in Australia, for example, sets leverage limits from 30:1 to 2:1 and runs to 23 May 2027.[20]
  • Automation. PineConnector executes the instruction in the message. It does not choose the symbol, the size, the stop or whether to trade.

Frequently asked questions

What are the basics of forex trading?

Forex trading basics come down to five parts: a bid and ask quote, an order sized in lots, the margin held while a position is open, trading costs, and the broker's rules in each symbol's specification. The costs are spread, commission, swap and slippage. A buy generally fills at the ask and closes at the bid, so each position starts one spread behind.

How do CFD trading mechanics differ from spot forex?

ASIC describes a CFD as a leveraged derivative contract that lets a client speculate on the change in value of an underlying asset, such as an exchange rate, index or commodity. In MT5, a CFD uses the same order, deal and position chain as a forex pair. Contract size, margin calculation, sessions and swap come from each CFD's specification, and retail leverage limits depend on the regulator.

How do orders work in MT5?

An MT5 order requests a trade; acceptance is not a confirmed fill. Check the order state and any deals, which can open, change or close positions. Market orders request execution at available prices, subject to the execution mode and broker processing. Pending orders wait for their conditions. Match the order and deal records in History, then verify the resulting position.

Why does MT5 reject an order?

MT5 rejects an order when the broker's trade server finds it invalid or cannot fund it. Common MQL5 return codes are 10014 (invalid volume), 10016 (invalid stops), 10019 (not enough money) and 10030 (invalid filling type). Each points to a field in the symbol specification or to the account's free margin. A request sent through PineConnector faces the same broker checks after the EA builds it.

Does leverage change how much you lose per pip?

No. For a given lot size, pip value depends on pip size, contract size and lots, converted to the account currency. On EURUSD with a 100,000 contract, 1.00 lot moves 10 USD per pip at any leverage. Leverage changes the margin the broker holds for the position, and with it how much free margin remains before the account's margin call and stop-out levels apply.

Reviewed 25 September 2026. Facts were checked against the linked sources on that date. Nothing in this article was tested on a trading account.

Related reading

Sources

  1. PineConnector – EA settings reference: what shapes the trade request, accessed 25 September 2026.
  2. MetaQuotes – MetaTrader 5 Help: Basic Principles, accessed 25 September 2026.
  3. MetaQuotes – MetaTrader 5 Help: Market Watch and symbol specification, accessed 25 September 2026.
  4. TradingView – What is the difference between ICE and other forex providers?, accessed 25 September 2026.
  5. TradingView – How to configure webhook alerts, accessed 25 September 2026.
  6. PineConnector – Syntax: message structure, accessed 25 September 2026.
  7. MetaQuotes – MetaTrader 5 Help: Executing Trades, accessed 25 September 2026.
  8. MetaQuotes – MQL5 Reference: Order Properties, accessed 25 September 2026.
  9. MetaQuotes – MQL5 Reference: Account Properties, accessed 25 September 2026.
  10. PineConnector – Syntax: check the result, accessed 25 September 2026.
  11. MetaQuotes – MQL5 Reference: Trade Server Return Codes, accessed 25 September 2026.
  12. MetaQuotes – MQL5 Reference: Symbol Properties, accessed 25 September 2026.
  13. PineConnector – EA errors: match the message beside 4756, accessed 25 September 2026.
  14. PineConnector – Syntax: the PineConnector pip, accessed 25 September 2026.
  15. PineConnector – Syntax: look up broker values, accessed 25 September 2026.
  16. MetaQuotes – MetaTrader 5 Help: Margin Calculation: Retail Forex, Futures, accessed 25 September 2026.
  17. PineConnector – Syntax: loss-based sizing, accessed 25 September 2026.
  18. PineConnector – Match your broker's symbols: add a broker prefix and suffix, accessed 25 September 2026.
  19. PineConnector – Frequently asked questions: volume handling, accessed 25 September 2026.
  20. ASIC – 22-082MR ASIC's CFD product intervention order extended for five years, accessed 25 September 2026.

PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.


Leave a comment

Back To PiCo Blog

Ready when your strategy is

You bring the strategy.We bring the infrastructure.

Connect TradingView to MetaTrader, choose where MT5 runs and put the full PineConnector workflow through its paces from your first month.

Strategy and trading decisions remain yours. The MT5 environment can be ours.

PineConnector Edge

Run the full PineConnector workflow.

$59/mo at launch

Core plan · 1 connection · 1 hosted MT5 environment

Try Core for $7

7 days of Core for $7, then $59/month at the launch price unless you cancel.