Discussing the article: "Implementing an LLM Agent with SQL Memory in MetaTrader 5"

Check out the new article: Implementing an LLM Agent with SQL Memory in MetaTrader 5.

An LLM agent with SQL memory in MetaTrader 5 — an architecture that eliminates the main limitation of traditional LLM Expert Advisors (EAs): the loss of context between queries. Each agent decision is recorded in SQLite along with the market conditions at the time of the signal — RSI, MA alignment, volatility — and after the position is closed, the outcome is written to the database. When the next request comes in, the agent reviews its own history — similar past RSI conditions and the last three agent decisions — and only then analyzes the current market. The result is a system that remembers its errors between restarts and adapts its behavior based on accumulated statistics, rather than starting from scratch with each new bar.

You have already connected the language model to MetaTrader 5 and are receiving real-time trading signals. The system works — but it starts each new bar from scratch. It does not remember that yesterday the RSI on EURUSD produced a false signal at the same time of day. It does not know that the agent made three mistakes in a bearish market and none in a bullish market. It does not realize that its last five recommendations ended in losses, and it continues to act with the same confidence it had at the start.

This is not a flaw in the language model — it is an architectural limitation. By definition, an LLM does not have long-term memory between queries. Every API call is like striking up a new conversation with a stranger. An Expert Advisor (EA) can run for weeks, accumulate statistics, and make recurring pattern-based mistakes — and the model will never know.

The purpose of this article is to remove this limitation. We will add persistent SQL memory to the LLM+MetaTrader 5 architecture — a knowledge base that accumulates data across sessions, is passed into the context of each query, and allows the agent to learn from its own mistakes. Success criteria are defined from an engineering perspective: the agent knows its historical accuracy by instrument/symbol and timeframe; each query to the model includes relevant context from past decisions; the database is automatically updated when a position is closed.


Author: Yevgeniy Koshtenko