The Signal Analyzer is responsible for parsing trading signals from Telegram messages using advanced regex patterns and text processing. It extracts key trading information including direction, symbol, prices, and risk management levels.
The analyzer processes raw text messages and converts them into structured trading data that can be executed by the MetaTrader integration. It supports multiple message formats and languages (English and Persian/Farsi).
BUY EURUSD @ 1.0850
SL: 1.0800
TP: 1.0900, 1.0950
SELL XAUUSD @ 1950.50
Stop Loss: 1945.00
Take Profit: 1960.00, 1970.00
BUY GBPUSD
Entry: 1.2650
SL: 1.2600
TP1: 1.2700
TP2: 1.2750
خرید یورو @ ۱.۰۸۵۰
حد ضرر: ۱.۰۸۰۰
تی پی: ۱.۰۹۰۰، ۱.۰۹۵۰
- Normalizes Unicode characters (bold, italic formatting)
- Removes emojis and special symbols
- Standardizes whitespace
- Converts Persian numbers to English
Detects buy/sell signals using keyword matching:
Buy keywords: buy, خرید, بخر, بای Sell keywords: sell, فروش, بفروش, selling
Recognizes trading symbols through pattern matching:
- Direct symbols: EURUSD, XAUUSD, GBPUSD
- Special mappings:
- Gold: طلا, GOLD, XAUUSD, اونس, گلد
- EURUSD: یورو, EURUSD
- US30/DJI: US30, داوجونز
- NASDAQ: NASDAQ
- OIL: OIL
- Primary pattern:
@ 1.0850 - Fallback patterns:
entry:,open:,price: - Supports decimal numbers and Persian numerals
- Patterns:
1.0850 - 1.0860,1.0850///1.0860 - Used when
HighRisk: truein configuration
Multiple patterns supported:
TP: 1.0900, 1.0950TP1: 1.0900, TP2: 1.0950Take Profit: 1.0900- Persian:
تی پی: ۱.۰۹۰۰
Common patterns:
SL: 1.0800Stop Loss: 1.0800حد ضرر: ۱.۰۸۰۰(Persian)استاپ: ۱.۰۸۰۰(Persian)
For certain symbols (XAUUSD, DJIUSD), prices are validated and adjusted to match broker's tick size and formatting requirements.
The analyzer checks for existing positions with identical parameters to prevent duplicate trades.
Supports various message layouts:
- Single line:
BUY EURUSD @ 1.0850 SL 1.0800 TP 1.0900 - Multi-line with labels
- Mixed English/Persian text
- Different separator formats (comma, space, newline)
Custom symbol mappings in settings.json affect how symbols are resolved:
"SymbolMappings": {
"XAUUSD": "XAUUSDm",
"EURUSD": "EURUSD!"
}When enabled, supports dual entry points for position averaging.
The analyzer gracefully handles:
- Malformed messages (returns null)
- Missing required fields
- Invalid price formats
- Unsupported symbols
All parsing errors are logged for debugging purposes.
Unit tests for the analyzer are available in tests/AnalayzerTest.py. Run with:
python -m unittest tests/AnalayzerTest.pyTo add support for new signal formats:
- Add regex patterns to the respective functions in
app/Analayzer/Analayzer.py - Update keyword lists for action types and symbols
- Add unit tests for new patterns
- Test with real message examples