Skip to content

closeByLotSize: Close a given number of lots of one position

View as Markdown

Close a given number of lots of one position.

  • Action: closeByLotSize (case-sensitive)

  • Group: Close positions

  • From the dashboard: yes, on the Send Command page

  • Finds the position by: positionID (the comment you gave it when you opened it) or ticket

  • HTTP 200 means queued, not executed. See how delivery works and find where an alert stopped.

Field Type Required Unit Description
license string Yes text Your license key. In examples it is written YOUR_LICENSE_KEY.
action string Yes text Always closeByLotSize. Case-sensitive.
positionID string Yes, or ticket text The position’s MT5 comment (the positionID you sent when opening it). If the value is all digits and no comment matches, it is matched against the position ticket.
ticket integer No MT5 ticket MT5 ticket of the position. Used only when positionID is empty. Allowed: greater than 0. Needs EA v1.9.1 or later.
volume number Yes lots Lots to close, rounded to the symbol’s lot step. A value equal to or larger than the position’s volume closes it in full. Allowed: greater than 0.

The webhook rejects unknown fields, missing required fields and wrong types with HTTP 422 before anything is queued. Field names are case-sensitive.

Replace YOUR_LICENSE_KEY with your key. Send the body as the alert message in TradingView, or with any HTTP client.

{
"license": "YOUR_LICENSE_KEY",
"action": "closeByLotSize",
"positionID": "eurusd_breakout_1",
"volume": 0.05
}

After a successful run the MT5 Experts log shows:

✓ closeByLotSize: partially closed <lots> of <lots> lots on position <positionID> (ticket=<ticket>)
✓ closeByLotSize: fully closed position <positionID> (ticket=<ticket>, volume=<lots>)

In the dashboard, the command appears in Command History on the License Details page. What each status means.

Where you see it Message or code Cause Fix
MT5 Experts log ❌ handleCommand: closeByLotSize needs positionID and volume>0 The position reference is missing or the volume is 0 or less. Send positionID (or ticket) and a volume greater than 0.
MT5 Experts log ❌ closeByLotSize: position with ID <positionID> not found. No open position in the EA’s trade scope matches. Check the position’s comment or ticket in MT5.
Broker, MT5 return code 10014 Invalid volume in the request The volume to close is not allowed for this symbol. Use a multiple of the symbol’s lot step.
  • Only the first matching position is used.
  • Only positions in the EA’s trade scope are considered (by default, trades opened by this EA).

Verified for EA v1.9 · dashboard 2026-10-05 · reviewed by Claude Code (owner review pending)

Report a problem with this page

Trading involves substantial risk of loss. ZB Connector is software only; it does not provide investment advice, signals or brokerage services.