Trade Context Recorder
A raw trade log says what happened - entry price, exit price, profit. It says nothing about what the market was doing when the trade opened or closed, and reconstructing that after the fact from bar history means lining up a ticket's timestamp against a moving average snapshot from weeks or months ago, which is exactly the kind of manual work that stops getting done. This EA watches open positions and order history for the whole account (or one magic number, if filtered) and writes a context row the moment a trade is detected open, and another the moment it is detected closed. Each row carries a fast-MA-vs-slow-MA regime read (UPTREND, DOWNTREND or FLAT), the raw ATR value in price for volatility, and a session label built from three user-declared server-time windows that can legitimately overlap (for example London+NewYork). Volatility is recorded as a raw ATR figure rather than an invented HIGH/LOW bucket - a fixed threshold would need calibrating per symbol and would misrepresent volatility on anything the trader hasn't tuned it for. Leaving the raw number lets the trader bucket it themselves, per symbol, during their own post-hoc analysis. Notes and limitations Context is measured at the moment this EA detects the open or close, not at the exact tick the broker filled it - normally the same instant or a few seconds later, but not guaranteed identical on a slow poll or a busy terminal. The regime and ATR readings for a position are taken on that position's own symbol, so a multi-symbol account produces context rows spanning different instruments' own indicator values. Session labels can legitimately combine (e.g. "London+NewYork") when windows overlap, and read "OffSession" when none of the three declared windows are active. This EA never trades and never modifies an order - it only reads position and history data.
Expert advisor · MT4 · v1.0 · Free
About Trade Context Recorder
Trade Context Recorder is a script for MetaTrader 4 based on Moving Average and ATR. It can alert you with a pop-up, sound, email or push message. It has 12 settings, such as Fast ma period, Slow ma period and Atr period. MQL source code included.
Files in the download: TradeContextRecorder.ex4, TradeContextRecorder.mq4, TradeContextRecorder.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Fast ma period | 20 | Period or timeframe used by the calculation |
| Slow ma period | 50 | Period or timeframe used by the calculation |
| Atr period | 14 | Period or timeframe used by the calculation |
| Asian start hour | 0 | Server time, hour asian session begins |
| Asian end hour | 8 | Hour when trading stops (server time) |
| London start hour | 7 | Hour when trading starts (server time) |
| London end hour | 16 | Hour when trading stops (server time) |
| New york start hour | 12 | Hour when trading starts (server time) |
| New york end hour | 21 | Hour when trading stops (server time) |
| Magic filter | 0 | 0 = all magic numbers, otherwise only this one |
| Poll seconds | 5 | |
| Log file name | TradeContextRecorder.csv | File written under MQL4\Files\ |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Moving Average · Trading Sessions · Alerts · ATR · MT4 Expert Advisor · MQL4 Source Code