mt5.copy_ticks_range

 

Hello guys,

Does anyone know what's wrong here, I just copied the codes from the MQL5 help document to my first python script and tried to run it. But I keep got this error message:

from datetime import datetime
import MetaTrader5 as mt5 
# 显示有关MetaTrader 5程序包的数据 
print("MetaTrader5 package author: ",mt5.__author__) 
print("MetaTrader5 package version: ",mt5.__version__) 
  
# import the 'pandas' module for displaying data obtained in the tabular form
import pandas as pd
pd.set_option('display.max_columns', 500) # number of columns to be displayed
pd.set_option('display.width', 1500)      # max table width to display
# import pytz module for working with time zone
import pytz 
 
# establish connection to MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error()) 
    quit()
 
# set time zone to UTC
timezone = pytz.timezone("Etc/UTC")
# create 'datetime' objects in UTC time zone to avoid the implementation of a local time zone offset
utc_from = datetime(2020, 1, 10, tzinfo=timezone) 
utc_to = datetime(2020, 1, 11, tzinfo=timezone)
# request AUDUSD ticks within 11.01.2020 - 11.01.2020
ticks = mt5.copy_ticks_range("AUDUSD", utc_from, utc_to, mt5.COPY_TICKS_ALL)
print("Ticks received:",len(ticks))
 
# shut down connection to the MetaTrader 5 terminal
mt5.shutdown() 
 
# display data on each tick on a new line
print("Display obtained ticks 'as is'")
count = 0
for tick in ticks: 
    count+=1
    print(tick)
    if count >= 10:
        break
 
# create DataFrame out of the obtained data
ticks_frame = pd.DataFrame(ticks)
# convert time in seconds into the datetime format
ticks_frame['time']=pd.to_datetime(ticks_frame['time'], unit='s') 
 
# display data
print("\nDisplay dataframe with ticks")
print(ticks_frame.head(10))