Connecting darwintIQ to MetaTrader
This guide shows how to connect MetaTrader 4 or MetaTrader 5 to the darwintIQ API and use the provided example Expert Advisors as a starting point.
What This Integration Is For
This integration is useful when you want to:
- fetch darwintIQ data directly inside MetaTrader
- display model, support/resistance, or trend data on the chart
- verify API access from the trading terminal
- use the examples as a base for your own execution or analysis workflows
Platform Requirement
The example EAs use MetaTrader's built-in WebRequest() function to call the darwintIQ API. MetaTrader blocks external HTTP requests by default, so you must explicitly allow the API domain before the examples will work.
Enable WebRequest
In both MT4 and MT5:
- Open
Tools -> Options -> Expert Advisors. - Enable
Allow WebRequest for listed URL:. - Add
https://api.darwintiq.com. - Click
OK. - Remove and reattach the EA, or reload the chart.
If this step is skipped, the EA will fail with a WebRequest error and no API data will be returned.
Minimum Setup
- Open the example EA in MetaEditor.
- Replace the placeholder API token with your real token.
- Compile the EA.
- Allow
https://api.darwintiq.comin MetaTrader. - Attach the EA to a chart.
- Check the
Expertstab for request or parsing errors.
How the Integration Works
At a high level, the MetaTrader integration follows this pattern:
- The EA calls a darwintIQ endpoint such as
/v1/models,/v1/supres, or/v1/trendmatrix. - The API response is parsed inside the EA.
- The parsed values are displayed on the chart or used as input for your own trading logic.
- The request is repeated on a timer or on new bars, depending on the EA configuration.
Scope of the Examples
The included examples are primarily integration and visualization examples. They are not meant to hide or compensate for backend model quality issues with extra discretionary logic inside MetaTrader.
They do not implement production-ready order handling, execution controls, or robust risk management by default.
Included Example EAs
The repository includes minimal examples for both MT4 and MT5:
-
darwintIQ_Model_Api_DemoCalls the models API, parses the first returned model, and shows a compact summary in a chart label. -
darwintIQ_SupRes_EAFetches the latest support and resistance snapshot and draws levels, regression channel lines, and swing structure directly on the chart. -
darwintIQ_TrendMatrix_EAFetches the latest trend matrix snapshot and renders a compact multi-timeframe direction and strength panel.
The MT5 files are direct ports of the MT4 examples so both platforms stay aligned.
Troubleshooting
If the examples do not work as expected, check the following first:
-
WebRequest failedThe API domain is usually not allowlisted inTools -> Options -> Expert Advisors. -
HTTP
401or authorization errors Your API token is missing, expired, or invalid. -
Parse failures or empty results The response shape may have changed, the selected endpoint may return no data, or the symbol may not match available data.
-
No useful output on the chart Your broker's symbol naming may differ from the API symbol, for example
EURUSD.ainstead ofEURUSD. -
Frequent repeated requests Check the EA timer and polling settings to make sure the refresh interval matches your intended usage.
Production Guidance
Before using this approach in live trading, harden the examples:
- replace naive string parsing with a proper JSON parser for MQL
- add risk management such as lot sizing, stop-loss, take-profit, max spread, and slippage limits
- implement duplicate-entry protection so the EA does not repeatedly open the same position
- add trading session filters and failure handling
- keep the local EA logic aligned with backend entry logic instead of compensating weak backend models with ad hoc overrides
- test thoroughly in the MetaTrader Strategy Tester before using a live account
The current examples are best treated as reference implementations for connectivity and visualization.
Example Request
GET https://api.darwintiq.com/v1/models?symbol=EURUSD&sort=fitness
Related Endpoints
Useful starting points include:
/v1/models/v1/supres/v1/trendmatrix
Repository
Public example code is available here:
https://github.com/darwintIQ/API