Skip to content
All library documents

Logging Entry and Exit Indicators for Closed Trades in MQL5

Article MQL5 code base

Summary

This document describes an MQL5 Expert Advisor that records closed positions to a CSV alongside market indicators sampled at both entry and exit. The recorded context includes RSI, Stochastic, price distance from two exponential moving averages, Bollinger %B, ATR, and ADX on two timeframes. The logger is read-only and is intended to support retrospective analysis of a strategy’s rules from trade and market data.

It explains several history-processing pitfalls: position identifiers do not follow close order, timestamps have only one-second resolution, and changing the selected history during iteration can disrupt a scan. The proposed design collects position identifiers first and deduplicates using identifiers rebuilt from the CSV. It also accounts for close-by transactions and reads the magic number from the opening deal. The author cautions that the M1 bar spread is only a summary, not the spread at execution, and should not be treated as an execution-cost measure. These implementation details improve data collection, but they do not establish that any trading strategy is profitable.

Key ideas

  • The logger records closed positions with indicator values from entry and exit on two timeframes.
  • It uses a set of logged position identifiers to avoid ordering and timestamp collisions during deduplication.
  • The history scan collects identifiers before looking up individual positions to preserve the full scan.
  • Close-by transactions and opening-deal magic numbers must be handled to avoid missing or misclassifying trades.
  • The M1 bar spread is not an execution-time quote and should not be used as the trade’s execution cost.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.