Skip to content
All library documents

Extracting MACD Zero-Cross Signals and Saving Them to a File

Article MQL5 code base

Summary

This MQL5 example shows how to extract MACD values over a chosen date range, identify zero-line crossings, and save each signal with its timestamp in a CSV file. A crossing from below zero to zero or above is labeled as a buy signal; a crossing from above zero to zero or below is labeled as a sell signal. The symbol, timeframe, MACD parameters, applied price, and start date are configurable inputs, while the end date is set to the current time.

The workflow retrieves indicator and time data, waits for indicator calculations, checks for retrieval and file-opening errors, and writes the signal count followed by the signal records. The example explains data handling rather than testing a trading strategy. It provides no evidence that the zero-cross signals are profitable, and it does not describe trade execution, position sizing, or risk controls. Results depend on the selected instrument, timeframe, MACD settings, and the data available in the terminal.

Key ideas

  • The example retrieves MACD values and corresponding timestamps for a selected symbol and period.
  • An upward zero-line crossing is labeled a buy signal, and a downward crossing is labeled a sell signal.
  • Signal timestamps and directions are written to a CSV file in the terminal's data area.
  • The example handles indicator readiness and reports data-copying or file-opening errors.
  • It demonstrates signal extraction and storage, but provides no strategy performance evidence.

Tags

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