Python module (A script for extracting data from Metatrader)

 

Hello All

As a new user, I'm using MQL5 module in Python!

All things are good, But a problem i have.

I couldn't find any way to go through symbols at Market watch!

The module's methods just list all instruments in the Metatrader and therefor just going through all instruments is possible! Something about 9000 instrument! So slowly!

Is there any way to just identifying active instruments in the Market Watch and going through them?

this is my code.

from datetime import datetime,date
import MetaTrader5 as mt5
import pandas as pd
import pytz


pd.set_option('display.max_columns', 500) 
pd.set_option('display.width', 1500)    


#---------------------------------------------
# establish connection to MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()
#----------------------------------------------
final_data_frame=pd.DataFrame(columns=['time','open','high','low','close','tick_volume','spread','real_volume','Name'])
count=0   
#------------------------------------------------------------------
# get all symbols
symbols=mt5.symbols_get()
total_count=mt5.symbols_total()

for s in symbols:
    
    count+=1 
    if count>=total_count: 
        break 
    else:   
        contains_digit = False

        for character in s.name:
            if character.isdigit():
                contains_digit = True


        if not contains_digit:
            ticks = mt5.copy_ticks_from(s.name , datetime.now(), 10, mt5.COPY_TICKS_ALL)
            c = 0
            for tick in ticks:
                c+=1
            if c >= 2:
                rates = mt5.copy_rates_from_pos(s.name, mt5.TIMEFRAME_H1, 0, 4)
                rates_frame = pd.DataFrame(rates)
                rates_frame['time']=pd.to_datetime(rates_frame['time'], unit='s',errors='ignore')
                rates_frame['Name']=s.name
                final_data_frame=final_data_frame.append(rates_frame) 
#--------------------------------------------------------------------
print(final_data_frame)
mt5.shutdown()

If you can, Please help me.

Sorry for my bad english

Thanks in advanced

 

Hello ALi,

I had the same problem, but I think this solve it:

# symbols of Market watch for items in mt.symbols_get(""): if items.visible: print(items.name, "visible") I hope this help you. Best regards, Stefano

 

Sorry!

    # symbols of Market watch
    for items in mt.symbols_get(""):
        if items.visible:
            print(items.name, "visible")