close_percentage: Close a percentage of one position
Close a percentage of one position.
At a glance
Section titled “At a glance”-
Action:
close_percentage(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) orticket -
HTTP 200 means queued, not executed. See how delivery works and find where an alert stopped.
Fields
Section titled “Fields”| 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 close_percentage. 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. |
percentage |
number | Yes | percent | Share of the position’s current volume to close, greater than 0 and up to 100. The resulting volume is rounded to the symbol’s lot step. Allowed: greater than 0, 100 or less. |
The webhook rejects unknown fields, missing required fields and wrong types with HTTP 422 before anything is queued. Field names are case-sensitive.
Examples
Section titled “Examples”Replace YOUR_LICENSE_KEY with your key. Send the body as the alert message in TradingView, or with any HTTP client.
Close half of a position
Section titled “Close half of a position”{ "license": "YOUR_LICENSE_KEY", "action": "close_percentage", "positionID": "eurusd_breakout_1", "percentage": 50}curl -X POST "https://dev.api.zb-connector.com/webhook/" \ -H "Content-Type: application/json" \ -d '{"license":"YOUR_LICENSE_KEY","action":"close_percentage","positionID":"eurusd_breakout_1","percentage":50}'import requests
payload = """{ "license": "YOUR_LICENSE_KEY", "action": "close_percentage", "positionID": "eurusd_breakout_1", "percentage": 50}"""
response = requests.post( "https://dev.api.zb-connector.com/webhook/", data=payload, headers={"Content-Type": "application/json"}, timeout=10,)print(response.status_code, response.text)const response = await fetch("https://dev.api.zb-connector.com/webhook/", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ "license": "YOUR_LICENSE_KEY", "action": "close_percentage", "positionID": "eurusd_breakout_1", "percentage": 50 }),});console.log(response.status, await response.text());What you see
Section titled “What you see”After a successful run the MT5 Experts log shows:
Partial close succeeded: closed <lots> from ticket <ticket>✅ Closed <percentage>% of position <positionID>In the dashboard, the command appears in Command History on the License Details page. What each status means.
Errors and fixes
Section titled “Errors and fixes”| Where you see it | Message or code | Cause | Fix |
|---|---|---|---|
| MT5 Experts log | ❌ handleCommand: close_percentage needs positionID and 0<percentage≤100 |
The position reference is missing or the percentage is out of range. | Send positionID (or ticket) and a percentage greater than 0 and at most 100. |
| MT5 Experts log | 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. |
| MT5 Experts log | ❌ Failed to close <percentage>% of position <positionID> |
The broker rejected the partial close, or the rounded volume was invalid. | Check the Experts log for the broker reason and the symbol’s lot step. |
- If the rounded volume is equal to or larger than the position, the whole position is closed.
- Only the first matching position is used.
- Only positions in the EA’s trade scope are considered (by default, trades opened by this EA).
Related
Section titled “Related”- Commands overview and the cheat sheet
- closeAll: close every open position (long and short), on all symbols
- closeByID: close the position (or positions) with a given positionID
- closeByLotSize: close a given number of lots of one position
- closeLong: close every open buy (long) position, on all symbols
Verified for EA v1.9 · dashboard 2026-10-05 · reviewed by Claude Code (owner review pending)
Trading involves substantial risk of loss. ZB Connector is software only; it does not provide investment advice, signals or brokerage services.