Discussing the article: "How to Implement Metaprompting for Trading Signals in an MQL5 Expert Advisor"

Check out the new article: How to Implement Metaprompting for Trading Signals in an MQL5 Expert Advisor.

Metaprompting is an approach in which the LLM itself optimizes trading instructions based on actual P&L and signal quality metrics. The article demonstrates a practical implementation in Python and MQL5: a prompt version registry, an execution agent, an evaluator for directional accuracy and profit factor, and a meta-LLM that generates improvements in a loop. The solution is integrated into the Expert Advisor without interrupting trading.

Key idea: A prompt is a text-based program that controls the model's behavior. If we formalize the prompt quality metric (for example, the percentage of profitable trades, the Sharpe ratio, or directional accuracy), the optimization problem becomes well-defined. The LLM optimizer receives the current prompt, a quality metric based on historical data, and the instruction “make the prompt better.” A new prompt is tested, and the result is returned to the optimizer. The cycle repeats.

This is fundamentally different from simply brute-forcing variants. The LLM optimizer doesn't operate randomly — it understands the semantics of the prompt, analyzes why a particular phrasing might have produced a poor result, and suggests meaningful improvements. Essentially, this is a gradient descent process in the space of natural language, where the “gradient” is computed by a language model based on feedback from trading results.

In a trading context, meta-prompting accomplishes three tasks at once. The first is adaptation to the market regime: the optimizer determines which formulations work better in a trend and which work better in a sideways market. The second is specialization for the instrument: the prompt for oil and the prompt for the Japanese yen should emphasize different factors. The third is temporal adaptation: a prompt that was optimal three months ago may degrade as the market microstructure changes.


Author: Yevgeniy Koshtenko