Loading…

Trade Intent Recorder

A ticket's comment and magic number tell you which strategy opened it. They tell you nothing about WHY it was opened - what the RSI read, how far price sat from the moving average, what the spread was, whether a filter was active - at the exact instant the decision was made. Reconstructing that later from raw tick history is often impossible once the feature depends on internal indicator state that was never itself logged; the only reliable way to keep it is to write it down once, at decision time, before the order is even sent. This header does exactly that. STradeIntent holds the trade's intended price, stop, target and size, a strategy tag, a free-text reason, and up to 8 named numeric feature slots (SetIntentFeature assigns a label and a value to each - "rsi_m15" -> 34.2, "distance_to_ema20_pips" -> 3.1, whatever the strategy's own decision actually depended on). RecordTradeIntent appends it as one row to a CSV journal, writing a header row automatically the first time the file is created, and appending - not overwriting - on every later call. BuildIntentTag produces a short, deterministic tag from the intent's own time, symbol and direction (a truncated non-cryptographic hash, not a random ID) - the same intent always produces the same tag, which is what makes it usable as a correlation key: embed it in the real OrderSend's comment field, and a later pass over trade history can match a filled ticket back to its journal row by that tag alone, with no shared counter or external database needed between the decision-time write and the after-the-fact read. The feature slots are a fixed-size array (INTENT_MAX_FEATURES, currently 8), not a dynamic one - a struct holding a dynamic array has no safe default copy/assignment in MQL4, and STradeIntent needs to behave like an ordinary value everywhere it is built, passed and recorded. Notes and limitations - The feature set is capped at 8 named numeric slots (INTENT_MAX_FEATURES). A strategy with a richer feature vector needs to pick its 8 most useful readings, or call RecordTradeIntent more than once under different tags. - BuildIntentTag's hash is for correlation, not security - it is short (10 hex characters) and collisions are possible in principle across a very large number of intents. It is not a unique-ID guarantee, only "unlikely enough to collide for one EA's own journal". - This header never sends an order itself - RecordTradeIntent only writes the journal row. The caller is responsible for sending the real order and embedding the tag in its comment. - A comma inside strategyTag or reasonText misaligns that CSV row, the same constraint the plain CSV format imposes everywhere else in this catalogue.

Script · MT5 · v1.0 · Free

About Trade Intent Recorder

Trade Intent Recorder is a script for MetaTrader 5. It has 1 setting, such as Journal file name. MQL source code included.

Files in the download: TradeIntentRecorder.mq5.mqh, TradeIntentRecorder.txt, TradeIntentRecorderDemo.ex5, TradeIntentRecorderDemo.mq5.

Settings

SettingDefaultWhat it does
Journal file nameTradeIntentJournalDemo.csvJournal file, written into MQL5\Files\

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: RSI · Moving Average · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria