Forex

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

  1. Open MetaTrader 4 or MetaTrader 5
  2. Navigate to Tools → Options → Expert Advisors
  3. Enable Allow automated trading
  4. Enable Allow DLL imports (required for the bridge EA to communicate with the botwir3 runtime)
  5. 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

  1. Copy botwir3_bridge.mq4 (or .mq5) from the runtime package into the MetaTrader Experts folder:
    • MT4: C:\Users\[user]\AppData\Roaming\MetaQuotes\Terminal\[instance]\MQL4\Experts\
    • MT5: C:\Users\[user]\AppData\Roaming\MetaQuotes\Terminal\[instance]\MQL5\Experts\
  2. Restart MetaTrader or click Refresh in the Navigator panel
  3. Drag botwir3_bridge onto the chart of the instrument to trade
  4. 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

ComponentLimitNotes
Order executionBroker-dependentVaries by broker. Some brokers limit EA order frequency.
Socket communicationLocal (no network limit)Latency is sub-millisecond on the same machine.
Market dataBroker-dependentTick 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

ErrorCauseFix
CONNECTION_REFUSEDBridge EA not running or port mismatchVerify the bridge EA is attached to a chart and the socket port matches adapter config
EA_NOT_ENABLEDExpert Advisors disabled in MetaTraderEnable Allow automated trading in Tools → Options → Expert Advisors
DLL_IMPORT_DENIEDDLL imports disabledEnable Allow DLL imports in Tools → Options → Expert Advisors
BROKER_REJECTEDBroker rejected the order (insufficient margin, market closed, etc.)Check broker error message in the MetaTrader Experts tab. Verify market hours and margin.
MANDATE_INTEGRITY_VIOLATIONConfig file modified while bot is runningStop the bot, verify config, restart

Related guides


One bot. $129. No subscription. No $749/mo platform. → Build for MetaTrader


Build your MetaTrader 4/5 bot

Ready to build?