Skip to content
All library documents

Writing Closed Trade Data to CSV from an Expert Advisor

Article MQL5 code base

Summary

This document explains an example workflow for recording order information from a MetaTrader expert advisor in a CSV file for later analysis. The example opens trades in a selected direction and treats take-profit and stop-loss closures virtually through input settings. When the data-writing option is enabled, the file stores fields such as trade direction, gain or loss, and price. The author presents the example as a way to add CSV logging to another expert, rather than as a complete trading strategy.

It distinguishes where the output can be found during strategy-tester runs and when running an expert on a demo or live account. The directory and file name can be changed while retaining the CSV extension. No sample data, analytics procedure, or performance results are given, and the example explicitly is not ready for trading. Its value is in demonstrating a basic data collection pattern; users would need to verify what fields are recorded and how virtual closures correspond to their own execution and accounting needs.

Key ideas

  • An expert advisor can write trade records to a CSV file for later analysis.
  • The example logs details such as direction, price, and gain or loss when its data-writing option is enabled.
  • Tester output and account-run output are stored in different locations.
  • The sample is a logging demonstration and does not provide a ready-to-trade strategy or performance evidence.

Tags

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