简体   繁体   English

Metatrader5 - Python 集成 - symbol_total() 返回无

[英]Metatrader5 - Python Integration - symbol_total() returns None

I'm trying to get the number of symbols of metatrader5 and I'm getting an error我正在尝试获取metatrader5的符号数量,但出现错误

TypeError: '>' not supported between instances of 'NoneType' and 'int'

Link to the documentation: https://www.mql5.com/en/docs/integration/python_metatrader5/mt5symbolstotal_py文档链接: https://www.mql5.com/en/docs/integration/python_metatrader5/mt5symbolstotal_py

code:代码:

import MetaTrader5 as mt5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)

if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()

symbols=mt5.symbols_total()
if symbols>0:
    print("Total symbols =",symbols)
else:
    print("symbols not found") 
mt5.shutdown()

The problem is that the function is returning NoneType instead of a number.问题是 function 返回 NoneType 而不是数字。 Why it's returning a NoneType?为什么它返回一个 NoneType? How can i get the list of Symbols/Stocks?我怎样才能得到符号/股票的列表? Any clue?有什么线索吗?

I had the same problem too.我也有同样的问题。 If you are currently using a downloaded MT5 terminal from your broker, you can try using the official MT5 terminal instead.如果您目前正在使用从您的经纪商处下载的 MT5 终端,您可以尝试使用官方的 MT5 终端 That seemed to have fixed my issue.这似乎解决了我的问题。 Don't forget to specify the path to the correct MT5 terminal.exe afterwards within the initialization function initialize(path=...) .不要忘记在初始化 function initialize(path=...)之后指定正确的 MT5 terminal.exe 的路径。

As to why this was causing an issue, I'm unsure myself.至于为什么这会引起问题,我自己也不确定。 I happened across this post and it mentioned that there may have been modifications made by brokers.我偶然看到了这篇文章,它提到经纪人可能进行了修改。

Anyway, hope this works for you too!无论如何,希望这对你也有用!


To connect to your broker's server afterwards, within the MT5 terminal under Navigator->Accounts (Right Click)->Open an account->Search for your broker and enter your credentials.之后要连接到您的经纪商服务器,在 MT5 终端中的导航器->账户(右键单击)->开立账户->搜索您的经纪商并输入您的凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM