# How to Retrieve 50,000 Historic Candlesticks from MetaTrader 5 with Python > MetaTrader 5 Python Trading Bot **Published by:** [The Crypto - AI - Cyber Disruption Continuum](https://paragraph.com/@appnologyjames/) **Published on:** 2024-08-06 **Categories:** python, metatrader 5, metatrader, metatrader 5 python trading bot, metatrader 5 python expert advisor **URL:** https://paragraph.com/@appnologyjames/how-to-retrieve-50%2C000-historic-candlesticks-from-metatrader-5-with-python ## Content MetaTrader 5 is an amazing platform for retrieving and analyzing historic candlestick data.With very little effort, you can retrieve up to 50,000 candles, and from an incredible range of timeframes. It leaves other exchanges like Binance and Coinbase in the dust.Here’s how you do it:Make sure that you’ve connected to MetaTrader 5Make sure that you’ve initalized the symbol you want to queryAdd the following 2 functions (the timeframe converter is to make it easier)# Function to convert a timeframe string in MetaTrader 5 friendly format def set_query_timeframe(timeframe): # Implement a Pseudo Switch statement. Note that Python 3.10 implements match / case but have kept it this way for # backwards integration if timeframe == "M1": return MetaTrader5.TIMEFRAME_M1 elif timeframe == "M2": return MetaTrader5.TIMEFRAME_M2 elif timeframe == "M3": return MetaTrader5.TIMEFRAME_M3 elif timeframe == "M4": return MetaTrader5.TIMEFRAME_M4 elif timeframe == "M5": return MetaTrader5.TIMEFRAME_M5 elif timeframe == "M6": return MetaTrader5.TIMEFRAME_M6 elif timeframe == "M10": return MetaTrader5.TIMEFRAME_M10 elif timeframe == "M12": return MetaTrader5.TIMEFRAME_M12 elif timeframe == "M15": return MetaTrader5.TIMEFRAME_M15 elif timeframe == "M20": return MetaTrader5.TIMEFRAME_M20 elif timeframe == "M30": return MetaTrader5.TIMEFRAME_M30 elif timeframe == "H1": return MetaTrader5.TIMEFRAME_H1 elif timeframe == "H2": return MetaTrader5.TIMEFRAME_H2 elif timeframe == "H3": return MetaTrader5.TIMEFRAME_H3 elif timeframe == "H4": return MetaTrader5.TIMEFRAME_H4 elif timeframe == "H6": return MetaTrader5.TIMEFRAME_H6 elif timeframe == "H8": return MetaTrader5.TIMEFRAME_H8 elif timeframe == "H12": return MetaTrader5.TIMEFRAME_H12 elif timeframe == "D1": return MetaTrader5.TIMEFRAME_D1 elif timeframe == "W1": return MetaTrader5.TIMEFRAME_W1 elif timeframe == "MN1": return MetaTrader5.TIMEFRAME_MN1 # Function to query previous candlestick data from MT5 def query_historic_data(symbol, timeframe, number_of_candles): # Convert the timeframe into an MT5 friendly format mt5_timeframe = set_query_timeframe(timeframe) # Retrieve data from MT5 rates = MetaTrader5.copy_rates_from_pos(symbol, mt5_timeframe, 1, number_of_candles) return ratesFrom here, you can determine the number of candles to retrieve (up to 50,000) and for which timeframe. Enjoy and don't forget to subscribe for more helpful functions.Subscribe ## Publication Information - [The Crypto - AI - Cyber Disruption Continuum](https://paragraph.com/@appnologyjames/): Publication homepage - [All Posts](https://paragraph.com/@appnologyjames/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@appnologyjames): Subscribe to updates ## Optional - [Collect as NFT](https://paragraph.com/@appnologyjames/how-to-retrieve-50%2C000-historic-candlesticks-from-metatrader-5-with-python): Support the author by collecting this post - [View Collectors](https://paragraph.com/@appnologyjames/how-to-retrieve-50%2C000-historic-candlesticks-from-metatrader-5-with-python/collectors): See who has collected this post