Connect your MetaTrader 4 Expert Advisors to MT4 Manager API with minimal code changes.
Note: This is the MT4 Connector component of the SoloDex platform. For complete setup including database, authentication, and monitoring features, see the main README.
- What is MT4 Dynamic Trailing?
- Quick Start
- EA Integration
- Telegram Bot Integration
- Troubleshooting
- Technical Reference
The MT4 Dynamic Trailing connector is a tool that enables your Expert Advisors to execute trades automatically through the MT4 Manager API using a simple file-based communication method.
- One-Click Setup: Simple installation and configuration
- Minimal EA Changes: Add just one function to your EA code
- Cross-Platform: Works on Windows, Mac, and Linux
- Automatic Order Management: Place, modify, and close trades
- Full Signal Support: Market orders, pending orders, and position management
- Telegram Integration: Control trades from your mobile device
- Double-click
scripts/START_CONNECTOR.bat
- Follow the on-screen prompts to enter your MT4 server details
- Open a terminal in the project directory
- Run
./scripts/START_CONNECTOR.sh
(you may need to make it executable withchmod +x scripts/START_CONNECTOR.sh
) - Follow the on-screen prompts
The connector will:
- Check and install required dependencies
- Create necessary directories and files
- Guide you through MT4 connection setup
- Connect to your MT4 server
- Start monitoring for trading signals
Important: The MT4 Connector does NOT need to be installed in any specific directory. It works independently of your MT4 terminal installation.
- MT4 Manager API: Connects directly to the MT4 server over the network (e.g., 195.88.127.154:45543)
- No MT4 Terminal Required: Uses manager credentials to authenticate directly with the broker's server
- File-Based Communication: Your EA writes signals to a JSON file that the connector monitors
C:\Any\Directory\You\Want\MT4Connector\
βββ mt4_api\
β βββ mtmanapi.dll (Required - MT4 Manager API)
β βββ mtmanapi64.dll (Required - 64-bit version)
βββ signals\
β βββ ea_signals.txt (EA writes signals here)
βββ src\
β βββ (connector code)
βββ START_WINDOWS.bat
- MT4 Terminal:
C:\Program Files (x86)\MetaTrader 4\
- MT4 Connector:
C:\MT4Connector\
(or any location you prefer) - EA Signal File: Update your EA to write to the connector's signals directory
The connector acts as a bridge between your EA and the MT4 server, using the Manager API for direct server communication.
The MT4 Connector includes a Telegram bot that allows you to receive trading signals and manage trades from your mobile device.
-
Create a new bot using BotFather in Telegram:
- Open Telegram and search for
@BotFather
- Send the command
/newbot
and follow the instructions - Copy the API token provided by BotFather
- Open Telegram and search for
-
Configure the bot in MT4 Connector:
- Open
src/config.py
in the MT4 Connector directory - Set your bot token:
TELEGRAM_BOT_TOKEN = "YOUR_TOKEN_HERE"
- Add your Telegram user ID:
TELEGRAM_ADMIN_IDS = [YOUR_USER_ID]
- To find your user ID, chat with
@userinfobot
in Telegram
- Open
-
Run the Telegram bot:
python src/run_with_telegram.py
- Receive Trading Signals: Get real-time notifications about new trading signals from your EAs
- Approve/Reject Trades: Make trading decisions directly from Telegram
- Modify Orders: Adjust parameters like volume, stop loss, or take profit
- Settings Management: Configure auto-approval and notification preferences
/start
- Start the bot and show welcome message/help
- Show help information/settings
- Configure your trading preferences
For more details, see the Telegram Bot README.
- Copy this function to your Expert Advisor:
void SendSignalToConnector(string type, string symbol, double volume,
double stoploss = 0, double takeprofit = 0,
string comment = "", int magic = 0, double price = 0,
int ticket = 0) {
// Create a unique ID for this signal
string signal_id = IntegerToString(TimeCurrent()) + "_" + DoubleToString(volume, 2) + "_" + symbol;
// Open the signal file - UPDATE THIS PATH to match your installation!
int file = FileOpen("C:\\MT4_Dynamic_Trailing\\signals\\ea_signals.txt", FILE_WRITE|FILE_TXT);
if(file != INVALID_HANDLE) {
// Create JSON with required fields
string json = "{\"signal_id\":\"" + signal_id + "\",\"type\":\"" + type +
"\",\"symbol\":\"" + symbol + "\",\"volume\":" + DoubleToString(volume, 2) +
",\"login\":\"" + IntegerToString(AccountNumber()) + "\"";
// Add optional fields if provided
if(stoploss > 0) json += ",\"stoploss\":" + DoubleToString(stoploss, 5);
if(takeprofit > 0) json += ",\"takeprofit\":" + DoubleToString(takeprofit, 5);
if(comment != "") json += ",\"comment\":\"" + comment + "\"";
if(magic > 0) json += ",\"magic\":" + IntegerToString(magic);
if(price > 0) json += ",\"price\":" + DoubleToString(price, 5);
if(ticket > 0) json += ",\"ticket\":" + IntegerToString(ticket);
json += "}";
// Write the JSON to the file
FileWriteString(file, json);
FileClose(file);
Print("Signal sent to connector: ", json);
} else {
Print("Error opening signal file!");
}
}
- Update the signal file path in the
FileOpen()
function to match your installation directory:- Windows:
"C:\\MT4_Dynamic_Trailing\\signals\\ea_signals.txt"
- Mac/Linux:
"Z:/path/to/MT4_Dynamic_Trailing/signals/ea_signals.txt"
- Windows:
// Buy 0.1 lot of EURUSD
SendSignalToConnector("buy", "EURUSD", 0.1);
// Sell 0.05 lots of GBPUSD with SL and TP
SendSignalToConnector("sell", "GBPUSD", 0.05, 1.3050, 1.2850);
// Buy limit 0.1 lot of EURUSD at 1.1800
SendSignalToConnector("buy_limit", "EURUSD", 0.1, 0, 0, "", 0, 1.1800);
// Sell stop 0.2 lots of USDJPY at 109.50 with comment and magic number
SendSignalToConnector("sell_stop", "USDJPY", 0.2, 110.50, 108.50, "MA Cross", 12345, 109.50);
// Close position with ticket #123456
SendSignalToConnector("close", "EURUSD", 0.0, 0, 0, "", 0, 0, 123456);
// Modify SL and TP on position #123456
SendSignalToConnector("modify", "EURUSD", 0.0, 1.1850, 1.1950, "", 0, 0, 123456);
Signal Type | Description | Required Parameters |
---|---|---|
buy |
Market buy order | symbol, volume, login |
sell |
Market sell order | symbol, volume, login |
buy_limit |
Buy limit pending order | symbol, volume, login, price |
sell_limit |
Sell limit pending order | symbol, volume, login, price |
buy_stop |
Buy stop pending order | symbol, volume, login, price |
sell_stop |
Sell stop pending order | symbol, volume, login, price |
close |
Close an open position | symbol, login, ticket |
modify |
Modify an existing order | symbol, login, ticket, (+ parameters to modify) |
- Ensure Python 3.6+ is installed and added to your PATH
- Try running the script as Administrator
- Check the logs folder for error messages
- Run the application as Administrator
- Check if your antivirus has quarantined the DLL files
- Add an exception in your antivirus for the MT4_Dynamic_Trailing folder
- Ensure you have the Microsoft Visual C++ Redistributable installed
- Double-check your MT4 server address, port, username, and password
- Ensure your MT4 server allows API access
- Check if your firewall is blocking the connection
- Verify the EA is writing to the correct signal file location
- Ensure the signal file format matches the expected JSON format
- Check logs for any parsing errors
- Update the signal file path in the EA to match your installation directory
- Use double backslashes in file paths in MQL4 code
- Ensure MT4 has permission to write to the signals directory
- Navigate to the
logs
folder in your MT4_Dynamic_Trailing directory - Look for the most recent log file
- Open it with any text editor to see detailed error messages
To test only the MT4 API connection:
- Open a command prompt in the MT4_Dynamic_Trailing directory
- Run:
python -c "from src.mt4_api import MT4API; api = MT4API(); print(api.connect('your_server', port, 'username', 'password'))"
- Python 3.6 or higher
- MetaTrader 4 with Manager API access
- Internet connection to your MT4 server
MT4Connector/
βββ README.md # This documentation file
βββ LICENSE # MIT License file
βββ CHANGELOG.md # Version history and changes
βββ package.json # Project metadata and scripts
βββ requirements.txt # Python dependencies
βββ assets/ # Project assets
β βββ logos/ # Project logos and branding
β βββ logo.png # Main project logo
βββ config/ # Configuration files
β βββ mt4-connector.rdp # Remote desktop connection file
βββ docs/ # Documentation files
β βββ WINDOWS_SETUP_GUIDE.md # Windows setup guide
βββ deploy/ # Deployment scripts and configurations
β βββ WINDOWS_SERVER_CORE_SETUP.md
β βββ deploy_to_windows_core.sh
β βββ quick_deploy.sh
β βββ quick_setup.ps1
β βββ setup_and_deploy.sh
βββ examples/ # Example MT4 EA files
β βββ SignalWriter.mq4 # Signal writer EA
β βββ pumping_mode_example.py # Pumping mode example
β βββ websocket_client_example.html # WebSocket client example
βββ logs/ # Log files directory
βββ mt4_api/ # MT4 Manager API files
β βββ MT4Manager.h # MT4 Manager API header
β βββ MT4ManagerAPI.h # MT4 Manager API header
β βββ MT4RestfulAPIWrapper.zip # REST API wrapper
β βββ MT4RestfulAPIWrapper/ # REST API wrapper source
β βββ mtmanapi.dll # MT4 Manager API DLL (32-bit)
β βββ mtmanapi64.dll # MT4 Manager API DLL (64-bit)
β βββ pumping_mode_design.md # Pumping mode design docs
β βββ logs/ # MT4 API specific logs
βββ scripts/ # Setup and execution scripts
β βββ 1) TEST_CONNECTION_WINDOWS.bat
β βββ 2) START_WINDOWS.bat
β βββ START_CONNECTOR.bat # Windows one-click starter script
β βββ START_CONNECTOR.command # macOS one-click starter script
β βββ START_CONNECTOR.sh # Linux one-click starter script
β βββ deploy_to_ubuntu.sh # Ubuntu deployment script
β βββ run.bat # Windows run script
β βββ run.sh # Linux/macOS run script
β βββ setup.bat # Windows setup script
β βββ setup.sh # Linux/macOS setup script
β βββ setup_ubuntu.sh # Ubuntu setup script
βββ signals/ # Signal files directory
β βββ ea_signals.txt # Signal file monitored by the connector
β βββ ea_signals_example.txt # Example signal file
βββ src/ # Source code
β βββ app.py # Main application
β βββ config.py # Configuration module
β βββ dx_integration.py # Trading platform integration
β βββ mt4_api.py # MT4 API wrapper
β βββ mt4_event_dispatcher.py # Event dispatcher
β βββ mt4_pumping.py # Pumping mode implementation
β βββ mt4_real_api.py # Real MT4 API implementation
β βββ mt4_websocket.py # WebSocket server
β βββ run_mt4_connector.py # MT4 connector runner
β βββ run_with_telegram.py # Telegram bot integration
β βββ signal_processor.py # Signal processing logic
β βββ logs/ # Source-specific logs
β βββ signals/ # Source-specific signal files
β βββ utils/ # Utility modules
β βββ debug_signal.py # Signal debugging utility
β βββ generate_test_signal.py # Test signal generator
βββ telegram_bot/ # Telegram bot functionality
β βββ README.md # Telegram bot documentation
β βββ bot.py # Telegram bot implementation
β βββ signal_handler.py # Signal handling for Telegram
βββ tests/ # Test suite
βββ README.md # Testing documentation
βββ run_all_tests.py # Test runner implementation
βββ test_connection.py # Connection tests
βββ test_config.py # Config module tests
βββ test_dx_integration.py # Integration tests
βββ test_error_handling.py # Error handling tests
βββ test_integration.py # Integration tests
βββ test_mt4_api.py # MT4 API tests
βββ test_mt4_real_api.py # Real MT4 API tests
βββ test_phase1_integration.py # Phase 1 integration tests
βββ test_phase2_trading.py # Phase 2 trading tests
βββ test_pumping_mode.py # Pumping mode tests
βββ test_signal_monitoring.py # Signal monitoring tests
βββ test_signal_processing.py # Signal processing tests
βββ test_signal_writer.py # Signal writer tests
βββ test_telegram_bot.py # Telegram bot tests
βββ test_trade_signals.py # Trade signal tests
The connector processes trading signals in JSON format with these required fields:
signal_id
: A unique identifier for the signaltype
: The order type (buy, sell, etc.)symbol
: The trading instrument symbolvolume
: Trading volume/lot sizelogin
: Your MT4 account number
Optional fields:
stoploss
: Stop loss price leveltakeprofit
: Take profit price levelcomment
: Order commentmagic
: Magic number for the orderprice
: Price for pending ordersticket
: Ticket number for modify/close operations
- Generate unique signal IDs to prevent duplicate execution
- Always check if the file opened successfully
- Use
Print()
to log when signals are sent - Avoid sending too many signals in a short time
- Check logs if orders aren't being executed
- Always test in a demo account first
If you encounter issues:
- Check the Troubleshooting section above
- Examine the log files in the
logs
directory - Contact support with details about your issue
This software is provided "as is" and is intended for educational and trading purposes only. Use at your own risk.