MT4 / MT5 API Integration Guide

← Back to Trading
Connect your MetaTrader 4 or MetaTrader 5 Expert Advisor directly to TradeZone using our secure REST API. All requests are authenticated with HMAC-SHA256 — the same standard used by major exchanges.

Quick Start

1Generate an API key — go to My API Keys, create a key and enable the forex permission.

2Download the EA — click a link below to get the pre-built Expert Advisor template.

3Install in MT4/MT5 — copy the .mq4 / .mq5 file into your MetaEditor Experts folder and compile.

4Allow WebRequest — in MT4/MT5 go to Tools → Options → Expert Advisors and add tradezone.forex to the allowed URLs list.

5Configure inputs — set ServerURL, ApiKey, and ApiSecret in the EA input panel.

⬇ Download TradeZone_MT4.mq4 ⬇ Download TradeZone_MT5.mq5

Base URL & Authentication

All API endpoints are under:

https://tradezone.forex/index.php/api/Forex/

Every authenticated request must include these HTTP headers (or equivalent GET/POST parameters):

HeaderValue
X-API-KEYYour API key string
X-TIMESTAMPCurrent Unix timestamp (UTC, seconds)
X-SIGNATUREHMAC-SHA256 of timestamp + METHOD + path + body using your API secret

Signature Example (pseudo-code)

timestamp = unix_time_utc()
message   = timestamp + "POST" + "/index.php/api/Forex/open" + request_body
signature = HMAC_SHA256(api_secret, message)   // lowercase hex

The EA template handles all signing automatically. If you are building your own client, use the pattern above.

Endpoints

GET/ping — Server health check (no auth required)
{"status":1,"data":"ok","ts":1744200000}
GET/price?symbol=EURUSD — Live bid/ask for a symbol

Symbol format: MT4/MT5 style (EURUSD) or OANDA style (EUR_USD). Both accepted.

{"status":1,"data":{"bid":1.08432,"ask":1.08451,"mid":1.08442,"spread":1.9,"spread_pips":1.9,"tradeable":true,"source":"oanda"}}
GET/account — Account equity and margin summary auth
{"status":1,"data":{"balance":10000.00,"equity":10234.50,"used_margin":500.00,"free_margin":9734.50,"margin_level":2046.9,"open_pnl":234.50}}
GET/positions — Open positions auth
{"status":1,"data":[{"id":42,"symbol":"EUR_USD","direction":"buy","units":10000,"entry_price":1.08400,"profit":34.50,...}]}
POST/open — Open a position or place a pending order auth
ParameterTypeDescription
symbolstringreqe.g. EURUSD or EUR_USD
directionstringreqbuy or sell
unitsintegerreqNumber of units (1,000 = 0.01 lot for EUR/USD)
leverageintegerreqe.g. 100 (capped to pair maximum)
sl_pricefloatoptStop-loss price (0 = none)
tp_pricefloatoptTake-profit price (0 = none)
order_typestringoptlimit or stop for pending orders
trigger_pricefloatoptRequired when order_type is set
POST/close — Close an open position (fully or partially) auth
ParameterTypeDescription
position_idintegerreqID from /positions
unitsfloatoptUnits to close (omit for full close)
POST/modify — Update SL/TP on an open position auth
ParameterTypeDescription
position_idintegerreqOpen position ID
sl_pricefloatoptNew stop-loss price (0 = remove)
tp_pricefloatoptNew take-profit price (0 = remove)

Symbol Reference

The API accepts both MT4/MT5 format (EURUSD) and OANDA format (EUR_USD).

MT4/MT5TradeZone APICategory
EURUSDEUR_USDForex
GBPUSDGBP_USDForex
USDJPYUSD_JPYForex
AUDUSDAUD_USDForex
USDCHFUSD_CHFForex
USDCADUSD_CADForex
NZDUSDNZD_USDForex
EURGBPEUR_GBPForex
EURJPYEUR_JPYForex
GBPJPYGBP_JPYForex
XAUUSDXAU_USDMetals (Gold)
XAGUSDXAG_USDMetals (Silver)
US30US30_USDIndices (Dow Jones)
SPX500SPX500_USDIndices (S&P 500)
NAS100NAS100_USDIndices (NASDAQ)

Response Format

All responses are JSON. status: 1 = success, status: 0 = error.

{
  "status": 0,
  "info":   "Insufficient free margin. Required: $500.00, Available: $120.30"
}

Security Notes

Need help? Contact support@tradezone.forex or open the live chat on the bottom right.