Introduction
This post explains how to connect an optional local market-context bridge to a MetaTrader 5 Expert Advisor.
The bridge is designed for advanced users who want to add an extra layer of external market context to an EA. It is not required for the EA to operate. If the bridge is not running, unavailable, or unable to collect usable data, the EA should continue working with its internal technical logic and calendar/news-risk filters.
The purpose of the bridge is not to replace the EA’s trading logic. It provides additional context that can help the EA confirm, reduce, ignore, or treat a signal more cautiously.
What the Bridge Does
The bridge is a small local Python service that runs on the same computer or VPS as MetaTrader 5.
It collects external market-context information from free public sources and converts it into a simple sentiment/context response that the EA can read.
The bridge can provide information such as:
- Symbol bias: buy, sell, or neutral
- Confidence score
- Source agreement
- Whether the data is usable
- Whether the EA should use, reduce, or ignore the external context
- A short reason explaining the result
- Provider status and freshness
The EA can then use this information as an optional validation layer.
For example:
- If the EA has a buy signal and the external context also supports buying, the EA may slightly increase confidence.
- If the EA has a sell signal but the external context is strongly against it, the EA may reduce confidence or wait.
- If the bridge has no usable data, the EA ignores the external context and continues with internal logic.
The bridge should not be used as the main trading signal.
Why Use a Local Bridge Instead of Direct Web Calls from the EA?
The local bridge keeps the EA lighter and safer.
External news and market data sources can sometimes be slow, temporarily unavailable, or return incomplete data. If the EA connects directly to external sources, it can create delays or unreliable behavior.
With a local bridge:
- The EA only calls a local address.
- The bridge refreshes external data in the background.
- The EA receives cached results quickly.
- If an external source is slow, the bridge handles it.
- If the bridge has no usable data, the EA can continue in technical-only mode.
This keeps the EA’s main trading process more stable.
How the Connection Works
External free data sources ↓ Local Python bridge ↓ http://127.0.0.1:8010/sentiment ↓ MetaTrader 5 EA ↓ Optional context validation
The EA does not need the bridge to open or manage trades. The bridge only adds optional context.
What Sources Can Be Used
The bridge can be configured to use free public data sources, such as:
- Global news-context data
- Crypto market context
- Crypto fear/greed context
- Public market tone information
The exact source list depends on the bridge version and configuration.
For example:
- EURUSD context may use euro, US dollar, central bank, inflation, and interest-rate related news.
- XAUUSD context may use gold, US dollar, safe-haven, inflation, Federal Reserve, yield, and geopolitical-risk related news.
- BTCUSD context may use Bitcoin, crypto market, fear/greed, and broader risk-context information.
The bridge converts this data into a compact response for the EA.
Example Bridge Response
A normal response may look like this:
{ "ok": true, "status": "OK", "bridge_status": "ONLINE", "sentiment_status": "OK", "provider_health": "OK", "usable_sentiment": true, "symbol": "XAUUSD", "direction_bias": "BUY", "confidence": 67.5, "source_agreement": 100, "risk_mode": "EXTERNAL_CONTEXT", "action": "CONFIRM_BUY_REDUCE_SELL", "score_adjust_buy": 2.1, "score_adjust_sell": -3.15, "reason": "External context supports XAUUSD buy conditions" }
A safe fallback response may look like this:
{ "ok": true, "status": "TECHNICAL_ONLY", "bridge_status": "ONLINE", "sentiment_status": "TECHNICAL_ONLY", "provider_health": "DEGRADED", "usable_sentiment": false, "symbol": "XAUUSD", "direction_bias": "NEUTRAL", "confidence": 0, "source_agreement": 0, "action": "TECHNICAL_ONLY", "score_adjust_buy": 0, "score_adjust_sell": 0, "reason": "No usable external context available" }
In the second example, the EA should ignore the bridge result and continue using its internal logic.
Recommended EA Behavior
The EA should treat the bridge as optional.
Recommended behavior:
- External context is disabled by default.
- The EA works normally without the bridge.
- If the bridge is offline, the EA continues with internal logic.
- If the bridge data is stale, the EA ignores it.
- If the bridge returns technical-only status, the EA ignores sentiment.
- External context should only make small score adjustments.
- Risk, spread, volatility, and calendar filters should still have final authority.
A safe logic model is:
Internal technical signal first Calendar/news-risk filter second External bridge context third Risk and execution filters final
Setup Requirements
To use the bridge, the user needs:
- MetaTrader 5
- An EA with optional external context support
- Python installed on the computer or VPS
- The bridge .py file
- A launcher .bat file
- Internet access for the bridge
- WebRequest permission enabled in MetaTrader 5
The EA must remain fully usable without the bridge.
Step 1: Start the Bridge
Place the bridge files in a folder, for example:
C:\Users\Administrator\Documents\AdaptiveRegimeTraderBridge\
Typical files:
adaptive_regime_trader_context_bridge_V2_1.py run_adaptive_regime_trader_context_bridge_V2_1_watchdog.bat
Run the launcher:
run_adaptive_regime_trader_context_bridge_V2_1_watchdog.bat
If the bridge starts correctly, the terminal should show something similar to:
Adaptive Regime Trader Context Bridge running on http://127.0.0.1:8010
The bridge uses port 8010 by default so it does not conflict with another local quant server running on port 8000.
Step 2: Check the Bridge in a Browser
Open:
http://127.0.0.1:8010/health
A healthy response should show:
{ "ok": true, "bridge_status": "ONLINE" }
Then test a symbol:
http://127.0.0.1:8010/sentiment?symbol=XAUUSD
You can also test:
http://127.0.0.1:8010/sentiment?symbol=EURUSD http://127.0.0.1:8010/sentiment?symbol=BTCUSD
If the response says TECHNICAL_ONLY, the bridge is running but has no usable external context at that moment. This is not an EA error.
Step 3: Allow WebRequest in MetaTrader 5
In MetaTrader 5, open:
Tools → Options → Expert Advisors
Enable:
Allow WebRequest for listed URL
Add:
http://127.0.0.1:8010
Only the base URL is needed. The EA will call the sentiment endpoint from this local address.
Step 4: Enable the Bridge in the EA Settings
The EA should include inputs similar to:
Use external context: true / false External bridge URL: http://127.0.0.1:8010/sentiment Trade if bridge unavailable: true Maximum context boost: small value Maximum context penalty: moderate value
Recommended safe defaults:
Use external context: false Trade if bridge unavailable: true External context can veto: false or conservative Maximum boost: low Maximum penalty: moderate
Advanced users can enable the bridge after confirming it is running correctly.
Step 5: Read the Dashboard
The EA dashboard may show a context line such as:
Context: INTERNAL
or:
Context: EXTERNAL OK
or:
Context: TECHNICAL_ONLY
or:
Context: EXTERNAL UNAVAILABLE - INTERNAL FALLBACK
Suggested interpretation:
- OK = bridge data is usable
- LKG = last-known-good data is being used
- TECHNICAL_ONLY = bridge is online but has no usable sentiment
- DEGRADED = one or more providers are weak or unavailable
- OFFLINE = EA cannot reach the bridge
The EA should continue operating safely when the bridge is not usable.
Troubleshooting
Bridge terminal is open but EA shows offline
Check:
- The bridge is running on port 8010
- The EA input uses the same port
- http://127.0.0.1:8010 is added to WebRequest permissions
- Windows firewall or security software is not blocking local requests
Browser works but EA shows technical-only
This usually means the bridge is reachable, but no usable external context was produced.
This can happen when:
- A provider is slow
- A provider returns no relevant data
- The bridge is using cached neutral data
- External sources are temporarily unavailable
The EA should ignore sentiment and continue with internal logic.
Provider shows degraded
This means the bridge is online, but one or more external sources are weak or unavailable.
This is not necessarily a problem. The bridge should use cached data or neutral fallback.
News provider is slow
Some free public data sources can be slow. The bridge should handle this in the background and return cached data to the EA. If the provider is unavailable, the EA should continue with internal technical and calendar-based logic.
Best Practices
Recommended use:
- Keep the bridge optional.
- Do not increase risk because the bridge confirms a signal.
- Use external context as validation only.
- Keep internal calendar/news-risk filters enabled.
- Test on demo before live use.
- Use one symbol per chart for simple operation.
- Use unique magic numbers for each EA instance.
- Use unique database files if multiple terminals or symbols are used.
The bridge should be treated as an additional context layer, not as a standalone trading signal.
Related Product
This optional bridge is designed for use with Adaptive Regime Trader: https://www.mql5.com/en/market/product/177932
Adaptive Regime Trader remains fully functional without the bridge. The external context mode is optional and is intended for users who want to add an additional local market-context layer.
Safety Notes
The external bridge does not guarantee better trading results. It may sometimes return neutral, delayed, or incomplete context. Market conditions, spreads, execution quality, slippage, and broker specifications can all affect trading outcomes.
Trading involves risk. The EA and bridge should be tested in a demo environment before any live use.
The EA should remain fully operational without the bridge. If the bridge is unavailable, the system should fall back to internal technical and calendar-based logic.
Summary
The local market-context bridge is an optional advanced tool for users who want additional external context in their trading system.
It can provide:
- News-context awareness
- Symbol bias
- Confidence scoring
- Provider health information
- Cached sentiment results
- Safe technical-only fallback
The recommended design is:
EA works standalone first. Calendar/news-risk logic is internal. External bridge is optional. If external context fails, the EA continues normally.
This approach keeps the trading system flexible while avoiding dependency on external services.


