I found many examples that can access data stream from metatrader as follows:
# request 1000 ticks from EURAUD
euraud_ticks = mt5.copy_ticks_from("EURAUD", datetime(2020,1,28,13), 1000, mt5.COPY_TICKS_ALL)
# request ticks from AUDUSD within 2019.04.01 13:00 - 2019.04.02 13:00
audusd_ticks = mt5.copy_ticks_range("AUDUSD", datetime(2020,1,27,13), datetime(2020,1,28,13), mt5.COPY_TICKS_ALL)
However they are not for accessing current values but only histories. In datetime() function the examples do not provide seconds but only hours.
I searched for examples obtaining current data but no luck.
I tried by myself as follows (adding current minute and second) but the function throws 10 hours earlier data.
audusd_ticks = mt5.copy_ticks_from("AUDUSD", datetime(2020,1,28,13,30,01), 1, mt5.COPY_TICKS_ALL)
How to access current values of bid and ask etc.. from metatrader 5?
Add this in void OnTick()
//---We Calculate the Ask Price
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
//---We Calculate the Bid Price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
Unfortunately the OP failed to explain his problem properly and that he is working in Python instead of MQL5, so your solution will not help him much!
Unfortunately the OP failed to explain his problem properly and that he is working in Python instead of MQL5, so your solution will not help him much!
Yes i am working on python but the link (https://www.mql5.com/en/docs/integration/python_metatrader5 or MQL5 Reference->Integration->MetaTrader for Python) says the source belongs to MQL5.
In addition, my problem is that i am totally new to mql5 and metatrader 5, and i am trying to get current values of pairs (bid and ask) from metatrader 5 using " MetaTrader for Python" source.
However, i cannot find any example for accessing current values from metatrader 5 while there are many examples that access only history data.
Moreover, following code returns 10 hours earlier data even if i set current time.
audusd_ticks = mt5.copy_ticks_from("AUDUSD", datetime(2020,1,28,13,30,01), 1, mt5.COPY_TICKS_ALL)
Please correct me if i failed to explain my problem again.
- www.mql5.com
Add this in void OnTick()
//---We Calculate the Ask Price
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
//---We Calculate the Bid Price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
Thanks to your reply. I am using python by MQL5 (source https://www.mql5.com/en/docs/integration/python_metatrader5).
Do you have any suggestion?
- www.mql5.com
As far as I know, there are very few users using Python integration with MetaTrader 5. Most of us here, including myself, work exclusively with MQL on MetaTrader.
So you will have to be very patient and wait until someone answers. In the mean time continue with your own research while reading the documentation to see if you can resolve the problem yourself.
As far as I know, there are very few users using Python integration with MetaTrader 5. Most of us here, including myself, work exclusively with MQL on MetaTrader.
So you will have to be very patient and wait until someone answers. In the mean time continue with your own research while reading the documentation to see if you can resolve the problem yourself.
Hello, I built a library to reduce the boilerplate code and perhaps make your life easier:
The whole library can be found here:
https://github.com/Joaopeuko/Mql5-Python-Integration
If you want just the most near to the last price for bid and ask you can use:
tick.bid
tick.ask
Here is a simple example:
In the example, I use tick.last
However, if you want the whole book, you can call the Book function.
- github.com
Hello, I built a library to reduce the boilerplate code and perhaps make your life easier:
The whole library can be found here:
https://github.com/Joaopeuko/Mql5-Python-Integration
If you want just the most near to the last price for bid and ask you can use:
tick.bid
tick.ask
Here is a simple example:
In the example, I use tick.last
However, if you want the whole book, you can call the Book function.
Dear Mr
Thanks for your reply
From your source code i found my answer. "Mt5.symbol_info_tick("AUDJPY")" this function returns the current information.
BTW can you explain me what is the meaning of the following two lines in example.py?
buy = (tick.last > rates.open)
sell = (tick.last < rates.open)
And your library is a great work. Thank you very much.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I found many examples that can access data stream from metatrader as follows:
# request 1000 ticks from EURAUD
euraud_ticks = mt5.copy_ticks_from("EURAUD", datetime(2020,1,28,13), 1000, mt5.COPY_TICKS_ALL)
# request ticks from AUDUSD within 2019.04.01 13:00 - 2019.04.02 13:00
audusd_ticks = mt5.copy_ticks_range("AUDUSD", datetime(2020,1,27,13), datetime(2020,1,28,13), mt5.COPY_TICKS_ALL)
However they are not for accessing current values but only histories. In datetime() function the examples do not provide seconds but only hours.
I searched for examples obtaining current data but no luck.
I tried by myself as follows (adding current minute and second) but the function throws 10 hours earlier data.
audusd_ticks = mt5.copy_ticks_from("AUDUSD", datetime(2020,1,28,13,30,01), 1, mt5.COPY_TICKS_ALL)
How to access current values of bid and ask etc.. from metatrader 5?