AttributeError: 'NoneType' object has no attribute 'ask'

 

Hi guys, i keep getting an AttributeError with my code, does anyone know how to fix it, it has got be stumped.

Get the last tick for the Crypto is Error but Currency cross is Ok!

My code in attachment file. Any support would be great.

 
Thao Pham :

Hi guys, i keep getting an AttributeError with my code, does anyone know how to fix it, it has got be stumped.

Get the last tick for the Crypto is Error but Currency cross is Ok!

My code in attachment file. Any support would be great.

Read and study the help documentation: symbol_info_tick

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

Read and study the help documentation: symbol_info_tick

This documentation doesn't say anything about crypto, currency cross only :)

For example:  Get the last tick for the BTCUSD is error but GBPUSD is Ok.

 
Thao Pham # :
This documentation doesn't say anything about crypto, currency cross only :)

Read and study the documentation. If you do not understand - just copy one to one.

Your writing style is broken. Learn to read documentation and CORRECTLY write code.

 
Vladimir Karputov #:

Read and study the documentation. If you do not understand - just copy one to one.

Your writing style is broken. Learn to read documentation and CORRECTLY write code.

Nice! It's working.

x = mt5.symbol_info_tick('BTCUSD')._asdict()
print(x['ask'])
print(x['bid'])

Thank you very much!!!

 

I'm having basically the identical error, except intermittently. E.g. sometimes I am able to get the bid price, other times it complains of the NoneType doesn't have a bid attribute.

This makes literally no sense. It implies that sometimes it cant get the bid price basically. This is a confusion to me, I have 2 computers, the one which is running slightly slower due to the complexity of my algorithm actually almost always reliably gets the bid price, the faster more modern machine ALWAYS failed to acquire the bid price.....

I run 2 RAW MT5 Demo accounts. One on the faster newer laptop, one on an older PC which actually gets the bid price more reliably using this code.

Help would be much appreciated. 


CODE:

element = "EURGBP"

exchangerate = 1/(mt5.symbol_info_tick((f"{element}.r")).bid)
self.display(exchangerate, type="note")



self.display is a method of my own.