Loading…

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

SettingDefaultWhat it does
Fast ma period20Period or timeframe used by the calculation
Slow ma period50Period or timeframe used by the calculation
Atr period14Period or timeframe used by the calculation
Asian start hour0Server time, hour asian session begins
Asian end hour8Hour when trading stops (server time)
London start hour7Hour when trading starts (server time)
London end hour16Hour when trading stops (server time)
New york start hour12Hour when trading starts (server time)
New york end hour21Hour when trading stops (server time)
Magic filter00 = all magic numbers, otherwise only this one
Poll seconds5
Log file nameTradeContextRecorder.csvFile written under MQL4\Files\

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Moving Average · Trading Sessions · Alerts · ATR · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria