# closeSymbol: Close the open positions on one symbol, long, short or both

> Close the open positions on one symbol, long, short or both. Parameters, units, copy-ready examples, log lines and errors for the closeSymbol command.

Source: https://zb-connector.com/docs/commands/closesymbol/

Close the open positions on one symbol, long, short or both.

> **Use a demo account first.** Run every step on a MetaTrader 5 demo account. Switch to a live account only after the go-live checklist is done.

## At a glance

-   **Action:** `closeSymbol` (case-sensitive)
    
-   **Also accepted:** `close_symbol`
    
-   **Group:** Close positions
    
-   **From the dashboard:** yes, on the **Send Command** page
    
-   **HTTP 200 means queued, not executed.** See [how delivery works](https://zb-connector.com/docs/reliability/how-delivery-works/) and [find where an alert stopped](https://zb-connector.com/docs/troubleshooting/find-where-it-stopped/).
    

## 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 `closeSymbol` (also accepted: `close_symbol`). Case-sensitive. |
| `symbol` | string | Yes | text | Symbol as your broker names it in MT5. The EA adds the Symbol prefix / Symbol suffix inputs if you set them. |
| `direction` | string | No | text | Which side to close. Lower case. Allowed: one of `long`, `short`, `both`. Default: `both`. |

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

## Examples

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

### Close all long positions on EURUSD

**JSON**

```json
{
  "license": "YOUR_LICENSE_KEY",
  "action": "closeSymbol",
  "symbol": "EURUSD",
  "direction": "long"
}
```

**curl**

```bash
curl -X POST "https://dev.api.zb-connector.com/webhook/" \
  -H "Content-Type: application/json" \
  -d '{"license":"YOUR_LICENSE_KEY","action":"closeSymbol","symbol":"EURUSD","direction":"long"}'
```

**Python**

```python
import requests

payload = """
{
  "license": "YOUR_LICENSE_KEY",
  "action": "closeSymbol",
  "symbol": "EURUSD",
  "direction": "long"
}
"""

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)
```

**Node.js**

```js
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": "closeSymbol",
    "symbol": "EURUSD",
    "direction": "long"
  }),
});
console.log(response.status, await response.text());
```

### Close every position on GBPUSD (direction defaults to both)

**JSON**

```json
{
  "license": "YOUR_LICENSE_KEY",
  "action": "closeSymbol",
  "symbol": "GBPUSD"
}
```

**curl**

```bash
curl -X POST "https://dev.api.zb-connector.com/webhook/" \
  -H "Content-Type: application/json" \
  -d '{"license":"YOUR_LICENSE_KEY","action":"closeSymbol","symbol":"GBPUSD"}'
```

**Python**

```python
import requests

payload = """
{
  "license": "YOUR_LICENSE_KEY",
  "action": "closeSymbol",
  "symbol": "GBPUSD"
}
"""

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)
```

**Node.js**

```js
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": "closeSymbol",
    "symbol": "GBPUSD"
  }),
});
console.log(response.status, await response.text());
```

### Same command with the snake\_case alias

**JSON**

```json
{
  "license": "YOUR_LICENSE_KEY",
  "action": "close_symbol",
  "symbol": "USDJPY",
  "direction": "short"
}
```

**curl**

```bash
curl -X POST "https://dev.api.zb-connector.com/webhook/" \
  -H "Content-Type: application/json" \
  -d '{"license":"YOUR_LICENSE_KEY","action":"close_symbol","symbol":"USDJPY","direction":"short"}'
```

**Python**

```python
import requests

payload = """
{
  "license": "YOUR_LICENSE_KEY",
  "action": "close_symbol",
  "symbol": "USDJPY",
  "direction": "short"
}
"""

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)
```

**Node.js**

```js
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_symbol",
    "symbol": "USDJPY",
    "direction": "short"
  }),
});
console.log(response.status, await response.text());
```

## What you see

After a successful run the MT5 **Experts** log shows:

```text
✓ Closed <LONG|SHORT> position on <symbol> (ticket: <ticket>, volume: <lots>)
Summary for <symbol> <direction>: Closed <n>, Failed <n>
```

In the dashboard, the command appears in **Command History** on the License Details page. [What each status means](https://zb-connector.com/docs/troubleshooting/find-where-it-stopped/#where-to-look).

## Errors and fixes

| Where you see it | Message or code | Cause | Fix |
| --- | --- | --- | --- |
| MT5 Experts log | `closeSymbol requires symbol and direction` | No symbol reached the EA. | Send `symbol`. |
| MT5 Experts log | `Invalid direction: <direction>. Use 'long', 'short', or 'both'` | The direction is not one of the three accepted values. | Use `long`, `short` or `both`, in lower case. |
| Broker, MT5 return code | [10018 Market is closed](https://zb-connector.com/docs/troubleshooting/errors/10018/) | The market for this symbol is closed. | Send the command again when the market is open. |

## Notes

-   The symbol must match exactly after the prefix/suffix is added; positions on other symbols are not touched.
-   From the dashboard Send command page, closeSymbol always closes both directions.
-   Only positions in the EA’s trade scope are closed (by default, trades opened by this EA).

## Related

-   [Commands overview](https://zb-connector.com/docs/commands/overview/) and the [cheat sheet](https://zb-connector.com/docs/commands/cheatsheet/)
-   [close\_percentage](https://zb-connector.com/docs/commands/close_percentage/): close a percentage of one position
-   [closeAll](https://zb-connector.com/docs/commands/closeall/): close every open position (long and short), on all symbols
-   [closeByID](https://zb-connector.com/docs/commands/closebyid/): close the position (or positions) with a given positionID
-   [closeByLotSize](https://zb-connector.com/docs/commands/closebylotsize/): close a given number of lots of one position
