MetaTrader 4/5 Setup Guide
Time: 15 minutes | Difficulty: Advanced | Market: Forex Mode: Full automation | API: MQL4/MQL5 + local socket/pipe communication | Docs: mql5.com/en/docs
This guide wires a MetaTrader trading bot to MT4 or MT5 using the botwir3 runtime. Configure the bridge between botwir3 and the MetaTrader terminal, connect to any broker that supports MT4/MT5, and run automated forex strategies locally.
Before you start
Verify that automated operation is permitted under the applicable broker's terms of service before deploying. MetaTrader is a trading platform, not a broker — it is used by hundreds of brokers worldwide. The broker's terms determine what automated operation is permitted. botwir3 provides tools for building structured automation. The user is responsible for compliance with the broker's terms and all applicable regulations.
MetaQuotes Terms of Use | Last verified: May 2026
Check the specific broker's terms of service separately.
What you need
- MetaTrader 4 or MetaTrader 5 installed and connected to a broker account
- Expert Advisors (EAs) enabled in the terminal settings
- The botwir3 runtime downloaded and unzipped
- A strategy config file from the builder
- The botwir3 MetaTrader bridge EA (included in the runtime package)
Step 1: Enable Expert Advisors
- Open MetaTrader 4 or MetaTrader 5
- Navigate to Tools → Options → Expert Advisors
- Enable Allow automated trading
- Enable Allow DLL imports (required for the bridge EA to communicate with the botwir3 runtime)
- Click OK
Permissions required: Automated trading enabled, DLL imports enabled. Permissions to disable: N/A. MetaTrader EAs operate within the terminal — withdrawal requires the broker's own interface.
🔒 Security. The botwir3 bridge EA communicates with the botwir3 runtime via a local socket on the same machine. No data leaves the machine. Broker credentials are managed by the MetaTrader terminal itself, not by botwir3.
Step 2: Install the bridge EA
- Copy
botwir3_bridge.mq4(or.mq5) from the runtime package into the MetaTraderExpertsfolder:- MT4:
C:\Users\[user]\AppData\Roaming\MetaQuotes\Terminal\[instance]\MQL4\Experts\ - MT5:
C:\Users\[user]\AppData\Roaming\MetaQuotes\Terminal\[instance]\MQL5\Experts\
- MT4:
- Restart MetaTrader or click Refresh in the Navigator panel
- Drag
botwir3_bridgeonto the chart of the instrument to trade - In the EA settings dialog, set the Socket Port to match the botwir3 adapter config (default: 5555)
Step 3: Configure the adapter
Create adapter.json in the bot directory:
{
"adapter": "metatrader",
"credentials": {
"socket_port": 5555
},
"trading_pair": "EURUSD",
"environment": "live",
"rate_limit_ms": 1000
}
Common instruments: EURUSD, GBPUSD, USDJPY, XAUUSD (Gold), US30 (Dow Jones). Instrument names vary by broker — use the exact symbol name shown in the MetaTrader Market Watch panel.
API keys are not required — the bridge EA communicates with the botwir3 runtime via a local socket. Broker credentials are managed by MetaTrader. They are not transmitted to botwir3 or any third party. botwir3 never sees, stores, or has access to broker credentials.
Step 4: Test the connection
botwir3 test --adapter metatrader
Expected output:
[botwir3] Adapter: metatrader
[botwir3] Connection: OK (local socket on port 5555)
[botwir3] Terminal: MetaTrader 5 (Build 4180)
[botwir3] Broker: [broker name]
[botwir3] Instrument: EURUSD
Step 5: Start the bot
botwir3 start --config my-strategy.json
The runtime loads the strategy, computes the spec hash, connects to MetaTrader via the local socket bridge, and begins evaluating signals. The gate function compares proposed actions against the configured spec. The user is responsible for monitoring the bot and verifying execution outcomes.
Rate limits and considerations
| Component | Limit | Notes |
|---|---|---|
| Order execution | Broker-dependent | Varies by broker. Some brokers limit EA order frequency. |
| Socket communication | Local (no network limit) | Latency is sub-millisecond on the same machine. |
| Market data | Broker-dependent | Tick data frequency varies. MT5 supports more timeframes than MT4. |
ℹ MT4 vs MT5. MT4 uses MQL4 and supports forex and CFDs. MT5 uses MQL5 and supports forex, CFDs, stocks, and futures. The botwir3 bridge EA is available for both. MT5 provides deeper market data (Level 2), more timeframes, and better backtesting. Not all brokers offer both — check broker availability.
Common MetaTrader bot configurations include trend-following EAs on major pairs, scalping strategies on low-spread instruments (EURUSD, USDJPY), and multi-pair portfolio strategies. MetaTrader's built-in Strategy Tester can backtest MQL strategies — botwir3 adds the configurable discipline layer (spec, gate, ledger) on top of the execution. All actions and decisions are recorded in the local ledger.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
CONNECTION_REFUSED | Bridge EA not running or port mismatch | Verify the bridge EA is attached to a chart and the socket port matches adapter config |
EA_NOT_ENABLED | Expert Advisors disabled in MetaTrader | Enable Allow automated trading in Tools → Options → Expert Advisors |
DLL_IMPORT_DENIED | DLL imports disabled | Enable Allow DLL imports in Tools → Options → Expert Advisors |
BROKER_REJECTED | Broker rejected the order (insufficient margin, market closed, etc.) | Check broker error message in the MetaTrader Experts tab. Verify market hours and margin. |
MANDATE_INTEGRITY_VIOLATION | Config file modified while bot is running | Stop the bot, verify config, restart |
Related guides
- OANDA Setup Guide — forex, REST API, practice accounts
- FXCM Setup Guide — forex, REST + FIX protocol
- TradingView → Broker Setup Guide — route TradingView alerts to MetaTrader via webhook
One bot. $129. No subscription. No $749/mo platform. → Build for MetaTrader