Basic example:
Code: Select all
import MetaTrader5 as mt5
import pandas as pd
mt5.initialize()
rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M5, 0, 5000)
df = pd.DataFrame(rates)
df['time'] = pd.to_datetime(df['time'], unit='s')
ticks = mt5.copy_ticks_range("EURUSD", start, end, mt5.COPY_TICKS_ALL)
mt5.shutdown()- Times are in server time, returned as UTC seconds.
- The terminal must be running and logged in.
- Windows only, unless using workarounds.
- Tick history depends on what the broker provides.
A practical tip: store the downloaded data locally after the first pull. Repeated requests for long histories are slow and may hit limits in the terminal, while local files make analysis much faster.
Do you use the MT5 Python package, and what for?