tghooks is a tool that bridges Telegram forex signal channels to MetaTrader 5 (MT5), automatically executing trades based on signals received from Telegram groups/channels by integrating Telethon with MT5 for automated trading.
- Real-time Telegram signal parsing and execution
- MT5 trade automation
- Configurable risk management
- Multiple symbol support
- Signal filtering and validation
- Only processes messages containing BUY/SELL keywords
- Maps symbols using your SYMBOL_MAP
- Places market orders at current/specified price
- Places pending orders at best price when different
- Sets TP (closest level) and SL automatically
- Uses channel ID as magic number and comment
- MetaTrader 5 terminal
- Telegram account and bot token
- Python 3.8+
# Clone the repository
git clone https://github.com/mamolas/tghooks.git
cd tghooks
# Install dependencies
pip install -r requirements.txt- Get API credentials from https://my.telegram.org
Replace API_ID, API_HASH, and PHONE_NUMBER in the
config.jsonwith your settings:
{
"MT5_INSTANCE": {
"main": "C:\\Program Files\\MetaTrader\\terminal64.exe"
},
"CHANNEL_IDS": [1002980294890,1001609594692, 1002080341106, 1001490446443,1001584939836,1001272542052,1002495224665],
"SYMBOL_MAP": {
"XAUUSD": "XAUUSDz",
"GOLD": "XAUUSDz"
},
"API_ID": "your_api_id",
"API_HASH": "your_api_hash",
"PHONE_NUMBER": "1234567890",
"TP_THRESHOLD": 0.0015,
"SL_THRESHOLD": 0.0015
}
TP_THRESHOLD and SL_THRESHOLD (both default 0.0015 or 0.15%) act as maximum relative distance filters from entry price. They prevent execution of signals with unrealistically distant take profit/stop loss levels, or when the signal provider didn't define a TP/SL 0.15% is very thight because the sample groups trade mostly 1min Gold scalping usually with a very small TP/SL.
- MT5 Setup:
Ensure MT5 is installed at the specified path Enable algorithmic trading in MT5
python main.pySupports common forex signal formats, it handles all the parsing automatically and executes both market and pending orders as needed.:
EURUSD BUY 1.0850 TP:1.0900 SL:1.0820
GBPUSD SELL 1.2650 | TP1:1.2600 TP2:1.2550 | SL:1.2700
"GOLD BUY 3527/ 3524" → Market buy + Buy limit at 3524
"GOLD SELL NOW PRICE: 3551 -3554" → Market sell + Sell limit at 3554
"Compro oro ahora 3538.4 - 3535" → Market buy + Buy limit at 3535
- Automatic position sizing based on account balance
- Stop loss and take profit execution
- Maximum daily loss limits
- Partial close support
# Run tests
pytest tests/
# Lint code
flake8 .
# Run with debug logging
debug=true python main.py- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- MetaTrader 5 Python API
- Telethon
- Forex trading community