# MT5 event notifier: Expert Advisor → API → Telegram

> Software that turns MetaTrader 5 trade events into Telegram messages and scheduled reports. We build the software; we do not trade or give investment advice.

- Service: Trading software (development only)
- Stack: MQL5, Python, FastAPI, PostgreSQL, Jinja2
- Canonical: https://jamm-automation.com/cases/mt5-notifier/
- Updated: 2026-11-29

## Manual

Without a notifier, trade events stay inside the MetaTrader terminal.

- **Events:** opens, closes, stop changes and partial closes.
- **Visibility:** seen only by someone who logs in and looks.

## System

An MQL5 Expert Advisor reports events to a FastAPI backend; we build the software, not trading decisions.

- **Expert Advisor:** listens to trade transactions (`OnTradeTransaction`) and keeps a position cache to detect SL and TP changes and partial closes.
- **Transport:** JSON over HTTPS with a Bearer token and an `X-Timestamp` header.
- **Backend:** FastAPI checks auth and a 300 s replay window.
- **Storage:** 11 event types classified and stored in PostgreSQL without duplicates (`ON CONFLICT` on the event key).

## Autopilot

Events are routed and reported on schedule.

- **Routing:** rules send each event to the right chat or topic through Jinja2 templates.
- **Threads:** a close is posted as a reply to its open.
- **Reports:** daily, weekly and monthly, run by APScheduler.
- **Scope:** the software reports events; it makes no trading decisions and gives no advice.
