All methods of MetaTrader5 returns None for all of my symbols

 

I use this code from gitub of Udemy course to order my trades. After login successfully, all methods of mt5 like symbol_info(), symbol_info_tick(), etc returns 'None' for some of symbols. In some symbols like 'AUDJPY', it returns correct values but in some cases like 'GBPCAD' it returns None. What should I do?

Thanks in advanced.

 
 
Check out the documentation:  MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

I have checked that. The most strange part is when I use mt5.symbols_get(), I can find ' GBPCAD'. However, it cannot founded via mt5.symbol_info_tick('GBPCAD').

I write the code even without the mentioned class here:

import MetaTrader5 as mt5

path="C:/Program Files/Alpari MT5/terminal64.exe"
account = 5555555
server="demo.ecn.mt5"
password="a1a1a1a1a1"
mt5.initialize(path=path, account=account, server=server, password=password)

symbol = "GBPCAD"
print(mt5.symbol_info(symbol))

output:

None


What should I do?

 

Run the symbol_info example

Documentation on MQL5: Integration / MetaTrader for Python / symbol_info
Documentation on MQL5: Integration / MetaTrader for Python / symbol_info
  • www.mql5.com
symbol_info - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

I opened MetaTrader manually and added one by one all the symbols I needed into the watchlist and check their ticks. After that I rerun the code and interestingly, it works!

I do not have any explanation for this, but it seems first we should add the required symbols into the related account in MetaTrader5 and then open the account using python.

Do you have any idea about this situation?

 
TrexTrader # :

I opened MetaTrader manually and added one by one all the symbols I needed into the watchlist and check  their ticks. After that I rerun the code and interestingly, it works!

I do not have any explanation for this, but it seems first we should add the required symbols into the related account in MetaTrader5 and then open the account using python.

Do you have any idea about this situation?

Please read the main documentation - the documentation on the MQL5 language, and only then try to work with python.

An example of getting data by symbol: checking if there is a symbol in the Market Watch. If the symbol is in this window, you can get information on this symbol.

Highly recommend

 
Vladimir Karputov #:

Please read the main documentation - the documentation on the MQL5 language, and only then try to work with python.

An example of getting data by symbol: checking if there is a symbol in the Market Watch. If the symbol is in this window, you can get information on this symbol.

Highly recommend


Thank you very much. I would do this.
 
TrexTrader # :
Thank you very much. I would do this.

I slightly modified the help example - instead of the 'EURJPY' symbol, I requested the 'asdfer' symbol.

The code:

import MetaTrader5 as mt5 
# display data on the MetaTrader 5 package 
print("MetaTrader5 package author: ",mt5.__author__) 
print("MetaTrader5 package version: ",mt5.__version__) 
  
# establish connection to the MetaTrader 5 terminal 
if not mt5.initialize(): 
    print("initialize() failed, error code =",mt5.last_error()) 
    quit() 
  
# attempt to enable the display of the asdfer symbol in MarketWatch 
selected=mt5.symbol_select("asdfer",True) 
if not selected: 
    print("Failed to select asdfer") 
    mt5.shutdown() 
    quit() 
  
# display asdfer symbol properties 
symbol_info=mt5.symbol_info("EURJPY_") 
if symbol_info!=None: 
    # display the terminal data 'as is'     
    print(symbol_info) 
    print("asdfer: spread =",symbol_info.spread,"  digits =",symbol_info.digits) 
    # display symbol properties as a list 
    print("Show symbol_info(\"asdfer\")._asdict():") 
    symbol_info_dict = mt5.symbol_info("asdfer")._asdict() 
    for prop in symbol_info_dict: 
        print("  {}={}".format(prop, symbol_info_dict[prop]))
else: 
   print("Failed to symbol info asdfer") 
  
# shut down connection to the MetaTrader 5 terminal 
mt5.shutdown() 

Result:

Failed to select asdfer
Files:
 
Vladimir Karputov #:

I slightly modified the help example - instead of the 'EURJPY' symbol, I requested the 'asdfer' symbol.

The code:

Result:

Thank you for your consideration. It is very clear and helpful.