TradeMemory Protocol

AI trading memory layer for MT5/forex with 15 MCP tools — store/recall trades, pattern discovery, strategy evolution, and Outcome-Weighted Memory.

TradeMemory Protocol

What if your trading bot could learn from every mistake — and invent better strategies by itself?

200+ trading MCP servers execute trades. None of them remember what happened.

TradeMemory is the memory layer that changes that.

PyPI Tests MCP Tools License: MIT Smithery


Before and After TradeMemory

Why TradeMemory?

"Why does my bot keep making the same mistakes?"

Persistent memory records every trade with full context — entry reasoning, market regime, confidence level, outcome. Pattern discovery finds what you can't see manually.

"My strategy worked for months, then suddenly stopped."

Outcome-weighted recall auto-downweights patterns from old regimes. Your bot adapts without you rewriting a single rule.

"How do I know it's not just overfitting?"

Every pattern carries Bayesian confidence + sample size. Built-in out-of-sample validation. Suspicious patterns get flagged, not blindly followed.

"I just want it to figure out what works."

Evolution Engine: feed raw price data. No indicators, no hand-written rules. It discovers, backtests, eliminates, and evolves — autonomously.

22 months of BTC data. Sharpe 3.84. 477 trades. 91% positive months. Zero human strategy input.


Quick Start

pip install tradememory-protocol

Add to your Claude Desktop config (claude_desktop_config.json):

{
  "mcpServers": {
    "tradememory": {
      "command": "uvx",
      "args": ["tradememory-protocol"]
    }
  }
}

Then say to Claude:

"Record my BTCUSDT long at 71,000 — momentum breakout, high confidence."

Claude Code / Cursor / Other MCP clients

Claude Code:

claude mcp add tradememory -- uvx tradememory-protocol

Cursor / Windsurf / any MCP client — add to your MCP config:

{
  "mcpServers": {
    "tradememory": {
      "command": "uvx",
      "args": ["tradememory-protocol"]
    }
  }
}
From source / Docker
git clone https://github.com/mnemox-ai/tradememory-protocol.git
cd tradememory-protocol
pip install -e .
python -m tradememory
# Server runs on http://localhost:8000
docker compose up -d
Claude Plugin (commands + skills + domain knowledge)
git clone https://github.com/mnemox-ai/tradememory-plugin.git
claude --plugin-dir ./tradememory-plugin

Adds 5 slash commands (/record-trade, /recall, /performance, /evolve, /daily-review) and 3 domain knowledge skills. See tradememory-plugin for details.


Use Cases

Crypto — Feed BTC/ETH trades from Binance. The Evolution Engine discovers timing patterns you'd never find manually. Auto-adapts when market regime shifts.

Forex + MT5 — Auto-sync every closed trade from MetaTrader 5. Persistent memory across sessions means your EA remembers that Asian session breakouts have a 10% win rate — and stops taking them.

Developers — Build memory-aware trading agents with 15 MCP tools + 30 REST endpoints. Your agent starts each session knowing its confidence level, active plans, and which strategies are working.


Architecture

OWM Architecture

Every memory is scored by five factors when recalled:

FactorWhat It Does
Q — QualityMaps trade outcomes to (0,1). A +3R winner scores 0.98. A -3R loser scores 0.02 — but never zero, because losing memories are recalled as warnings.
Sim — SimilarityHow similar is the current market context to when the memory was formed? Irrelevant memories get suppressed.
Rec — RecencyPower-law decay. 30-day memory retains 71% strength. 1-year memory retains 28%. Gentler than exponential — regime-relevant old memories stay retrievable.
Conf — ConfidenceMemories formed in high-confidence states score higher. Floor of 0.5 prevents early memories from being ignored.
Aff — AffectDuring drawdowns, cautionary memories surface. During winning streaks, overconfidence checks activate.

Based on ACT-R (Anderson 2007), Kelly criterion (1956), Tulving's memory taxonomy (1972), and Damasio's somatic markers (1994). Full spec: OWM_FRAMEWORK.md


Evolution Engine — the hidden ace

The Evolution Engine discovers trading strategies from raw price data. No indicators. No human rules. Pure LLM-driven hypothesis generation + vectorized backtesting + Darwinian selection.

How it works

  1. Discover — LLM analyzes price data, proposes candidate strategies
  2. Backtest — Vectorized engine tests each candidate (ATR-based SL/TP, long/short, time-based exit)
  3. Select — In-sample rank → out-of-sample validation (Sharpe > 1.0, trades > 30, max DD < 20%)
  4. Evolve — Survivors get mutated. Next generation. Repeat.

Results: BTC/USDT 1H, 22 months (2024-06 to 2026-03)

SystemTradesWin RateRRProfit FactorSharpeReturnMax DD
Strategy C (SHORT)15742.7%1.571.170.70+0.37%0.45%
Strategy E (LONG)32049.4%1.951.914.10+3.65%0.27%
C+E Combined47747.2%1.841.643.84+4.04%0.22%
  • 91% positive months (20 of 22)
  • Max drawdown 0.22% — lower than either strategy alone
  • Zero human strategy input. The LLM discovered these from raw candles.

Data from RESEARCH_LOG.md. 11 experiments, full methodology, model comparison (Haiku vs Sonnet vs Opus).


MCP Tools

Core Memory (4 tools)

ToolDescription
store_trade_memoryStore a trade with full context
recall_similar_tradesFind past trades with similar market context (auto-upgrades to OWM when available)
get_strategy_performanceAggregate stats per strategy
get_trade_reflectionDeep-dive into a trade's reasoning and lessons

OWM Cognitive Memory (6 tools)

ToolDescription
remember_tradeStore into all five memory layers simultaneously
recall_memoriesOutcome-weighted recall with full score breakdown
get_behavioral_analysisHold times, disposition ratio, Kelly comparison
get_agent_stateCurrent confidence, risk appetite, drawdown, streaks
create_trading_planConditional plans in prospective memory
check_active_plansMatch plans against current context

Evolution Engine (5 tools)

ToolDescription
evolution_runRun a full discover → backtest → select cycle
evolution_statusCheck progress of running evolution
evolution_resultsGet graduated strategies with full metrics
evolution_compareCompare generations side by side
evolution_configView/update evolution parameters
REST API (30+ endpoints)

Trade recording, outcome logging, history queries, daily/weekly/monthly reflections, risk constraints, MT5 sync, OWM CRUD, evolution orchestration, and more.

Full reference: docs/API.md


Star History

Star History Chart

Contributing

See CONTRIBUTING.md for guidelines.

  • Star the repo to follow progress
  • Report bugs via GitHub Issues
  • Submit PRs for bug fixes or new features

Documentation

DocDescription
OWM FrameworkFull theoretical foundation (1,875 lines)
Tutorial (EN)Step-by-step from install to using memory
Tutorial (中文)完整教學指南
API ReferenceAll REST endpoints
MT5 SetupMetaTrader 5 integration
Research Log11 evolution experiments with full data

License

MIT — see LICENSE.

Disclaimer: This software is for educational and research purposes only. It does not constitute financial advice. Trading involves substantial risk of loss.


Built by Mnemox

Serveurs connexes