Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Expert Advisor | TradeHistoryLogger | Source Code Included

Explore the latest free tools from the MQL5 community. Here's a new indicator, expert advisor, or script for MetaTrader.

Image for TradeHistoryLogger

This Expert Advisor writes every closed position to a CSV file together with RSI, Stochastic, distance from the EMA20 and EMA50, Bollinger %B, ATR and ADX — on two timeframes, at entryand

It isstrictly read-only. It never opens, closes or modifies a position.

Unique stair-step trend trading with the Stairsteps Expert Advisor. Innovative approach for consistent results. Learn more.

Three traps this handles, and why they are in the code with their history

Deduplication went through three designs before it worked, and each failed version is documented in the source, because the failures are more useful to the reader than the final answer.

  • A position_id watermark
  • A close_time watermarkdatetime
  • A set of logged position ids

And one that is easy to get wrong in a different way.

Two more details that silently lose data if you miss them

  • A position is closed byDEAL_ENTRY_OUTorDEAL_ENTRY_OUT_BY. "Close by" — closing a position against an opposite one on a hedging account — emits the second. Code that matches only the first never marks those positions closed.
  • The magic number must be read from the position'sopening

Inputs

Input Meaning
InpSymbol Symbol to track. Empty = the chart's own symbol.
InpCsvFileName Output file, written to this terminal's MQL5\Files.
InpCheckIntervalSec How often the history is scanned, in seconds.
InpMagicFilter If non-zero, log ONLY this magic number.
InpExcludeMagics Magic numbers to skip, comma separated. Empty = log everything.
InpBackfillHours Backfill hours, NEW file only. 0 = start from now.

On InpExcludeMagics, because exclusion is deliberate.your own

On InpBackfillHours.

One honest note about one column.m1bar_spread_ptsnot

Build better strategies with RobotFX professional tools – check them out.

76950

Best MetaTrader Indicators + Profitable Expert Advisors