Natural Language Processing NLP
- Библиотеки
- Версия: 1.3
Overview
AlgoNLP.mqh is a standalone MQL5 library designed to convert natural-language trading instructions into structured trade intents that can be processed by Expert Advisors (EAs) and custom indicators.
It provides a lightweight text-parsing interface for developers who want to integrate plain-language command processing into their MetaTrader 5 applications.
Example input:
Buy gold at 2370 with TP 0.3% and SL 1%
Parsed output:
Side: BUY | Type: LIMIT | Symbol: XAUUSD | Entry: 2370 | TP: 0.3% | SL: 1% | Lot: 0.00
The resulting intent contains structured information about the requested trading operation. Developers can inspect the parsed fields and decide how their applications should process them.
The library can be integrated into text-driven trading applications, custom command processors and systems that receive trading instructions from external message sources.
Trade safety: Always validate parsed instructions before using them in a live trading environment. Check the symbol, order direction, entry price, volume, stop-loss, take-profit and applicable risk limits. Incomplete or ambiguous instructions should not be executed without additional verification.
System Requirements
| Requirement | Details |
|---|---|
| Platform | MetaTrader 5, Build 2750 or later |
| Programming language | MQL5 |
| Compilation | Strict mode |
| Text encoding | Unicode-compatible |
| Dependencies | None |
| Execution time | Approximately 0.2 ms for an average test sentence |
| Memory footprint | Approximately 20–30 KB per instance |
| Execution model | Single-threaded MQL5 event processing |
Performance measurements are based on the specified test environment. Actual results may vary depending on hardware, terminal build and input complexity.
Library Architecture
The library is organized into several components, each responsible for a specific part of the parsing process.
| Component | Type | Description |
|---|---|---|
| CNLP | Main manager | Coordinates parsing, context management and listener dispatch. |
| CIntentDetector | Core engine | Performs numerical extraction and trade-intent mapping. |
| CKeywordExtractor | Utility | Extracts relevant keywords and filters stopwords. |
| CLexicon | Utility | Maintains semantic word sets for trade directions and order types. |
| CContext | Helper | Manages known trading symbols and the last-used instrument. |
| INLPListener | Interface | Provides callback methods for event-driven intent handling. |
| NLPUtil | Namespace | Contains text-processing and timing utilities. |
Core Data Types
SNLPIntent — Parsed Trade Object
SNLPIntent represents the structured result produced by the parsing engine.
| Field | Type | Description |
|---|---|---|
| valid | bool | Indicates whether parsing was successful. |
| side | ENLPOrderSide | BUY, SELL or UNKNOWN. |
| type | ENLPOrderType | MARKET, LIMIT or STOP. |
| symbol | string | Resolved trading instrument. |
| price | double | Entry price, when specified. |
| tp, sl | double | Take-profit and stop-loss values. |
| tp_is_percent, sl_is_percent | bool | Identifies percentage-based values. |
| tp_is_pips, sl_is_pips | bool | Identifies pip- or point-based values. |
| qty_lots | double | Detected trading volume. |
| when | SNLPWhen | Represents time-based or breakout conditions. |
| raw | string | Original input message. |
| reason | string | Parsing information and diagnostic details. |
How It Works
The parsing process consists of several stages:
-
Normalization: Converts text into a consistent format, removes unnecessary characters and replaces recognized synonyms, such as "take profit" with "tp".
-
Tokenization: Splits the input into individual words and filters predefined stopwords.
-
Lexical Matching: Identifies trade directions and order-related keywords using fuzzy Levenshtein matching with a configurable distance threshold.
-
Number Context Extraction: Interprets numerical values as entry prices, take-profit, stop-loss or lot sizes using contextual and unit-based rules.
-
Timing Logic: Recognizes supported time expressions, such as "at 09:15", "in 15 min" and breakout conditions.
-
Symbol Resolution: Resolves recognized instrument references, such as "gold" to XAUUSD, using the available symbol context.
-
Intent Construction: Builds the SNLPIntent structure and dispatches the result through registered listener callbacks.
Parsing limitations: AlgoNLP.mqh uses deterministic text-processing algorithms and context-based heuristics. It does not use artificial intelligence, external APIs or machine-learning models. Interpretation depends on recognized keywords, numerical context and supported input patterns. Ambiguous or incomplete sentences may produce incomplete or incorrect results. Always validate the resulting intent before using it for trade execution.
Performance Metrics
The following measurements represent the observed results for the tested input cases.
| Test Case | Tokens | Parse Time | Observed Result |
|---|---|---|---|
| Short command: "Buy BTC market" | 5 | 0.09 ms | 100% |
| Full sentence: "Buy gold at 2370 with TP 0.3% and SL 1%" | 15 | 0.22 ms | 100% |
| Noisy query: "Hey bot short nasdaq please 0.5 lot" | 18 | 0.26 ms | Above 95% |
Benchmark environment: Intel Core i7-9700, MetaTrader 5 Build 3820.
The reported results apply to the tested input samples and are not a guarantee of accuracy for arbitrary trading instructions. Execution times may vary between systems.
Summary
AlgoNLP.mqh provides a native MQL5 solution for converting plain-language trading instructions into structured trade intent data.
Its keyword extraction, contextual number interpretation, symbol resolution and event-driven listener interface provide developers with the building blocks for creating text-driven trading applications directly within MetaTrader 5.
The library is self-contained, requires no external NLP services and can be integrated into custom Expert Advisors and indicators.
It is intended as a text-parsing component. Final trade validation, risk management and order execution remain the responsibility of the integrating application.

Пользователь не оставил комментарий к оценке