MetaTrader 5 Python User Group - how to use Python in Metatrader - page 21

 

https://www.mql5.com/ru/docs/integration/python_metatrader5/mt5copyratesrange_py

The example uses a different function, a mistake:

# obtain bars with USDJPY M5 from 01.04.2019 in UTC timezone
rates=MT5CopyRatesFrom("USDJPY",MT5_TIMEFRAME_M5,utc_from, utc_to)

expected: MT5CopyRatesRange()

Документация по MQL5: Интеграция / MetaTrader для Python / MT5CopyRatesRange
Документация по MQL5: Интеграция / MetaTrader для Python / MT5CopyRatesRange
  • www.mql5.com
# создадим объекты datetime в таймзоне UTC, чтобы не применялось смещение локальной таймзоны                             MT5Rate(time=datetime.datetime(2019, 4, 1, 0, 0),  open=110.994, low=110.994, high=110.966, close=110.966, tick_volume=12, spread=22, real_volume=0...
 

To convert the datetime to a specific timezone, the help suggests using datetime UTC

However, this does not affect anything. When setting any timezone, the terminal time is taken (in my case it is GMT+2)

 
 
Rashid Umarov:
What is the build number?

pip install --upgrade MetaTrader5

Requirement already up-to-date: MetaTrader5 in c:\works\mt_websocket_server\.env\lib\site-packages (5.0.8)



 
can we move everything to one place?
MetaTrader 5 Python User Group - как использовать Python в Метатрейдере
MetaTrader 5 Python User Group - как использовать Python в Метатрейдере
  • 2019.11.25
  • www.mql5.com
Мы готовим модуль MetaTrader 5 для Python, аналогичную R...
 
Maxim Dmitrievsky:
Can we move it all to one place?

Which is it? The whole discussion thread?

 
Дмитрий Прокопьев:

Which is it? The whole discussion thread?

Yeah, to get the whole python thing in one place.

The moderators will move it.

 
Maxim Dmitrievsky:

Yeah, to have everything about python in one place.

Moderators will move it.

Okay, if they can move it, let them move it. Re-create, not really ...
 

Forum on trading, automated trading systems and trading strategy testing

MetaTrader5 python lib and MT5CopyRatesFrom - weirdness or bug?

Dmitry Prokopyev, 2019.11.30 10:59

Hi all.

Came across this weirdness in data returned by MT5CopyRatesRange and other functions.

from datetime import datetime
from MetaTrader5 import *
import pandas as pd
import json

from pytz import timezone
utc_tz = timezone('Etc/UTC')
 
MT5Initialize()
MT5WaitForTerminal()

# rates = MT5CopyRatesRange("EURUSD", MT5_TIMEFRAME_H1, datetime(2018,4,3), datetime(2018,4,4))
rates = MT5CopyRatesFrom("EURUSD", MT5_TIMEFRAME_H1, datetime(2018,4,3,17, tzinfo=utc_tz), 5)

MT5Shutdown()
rates_frame = pd.DataFrame(rates, columns=['time', 'open', 'low', 'high', 'close', 'tick_volume', 'spread', 'real_volume'])
print(rates_frame)
print(rates)

Everything is trivial, but the output we have:

                 time     open      low     high    close  tick_volume  spread  real_volume
0 2018-04-03 13:00:00  1.23073  1.23154  1.22861  1.22882         5090       1            0
1 2018-04-03 14:00:00  1.22882  1.23057  1.22863  1.23018         6112       1            0
2 2018-04-03 15:00:00  1.23018  1.23149  1.22919  1.22957         6691       1            0
3 2018-04-03 16:00:00  1.22957  1.22989  1.22557  1.22580        11956       1            0
4 2018-04-03 17:00:00  1.22580  1.22746  1.22536  1.22730        10275       1            0
(MT5Rate(time=datetime.datetime(2018, 4, 3, 13, 0), open=1.2307299999999999, low=1.23154, high=1.22861, close=1.22882, tick_volume=5090, spread=1, real_volume=0), 
MT5Rate(time=datetime.datetime(2018, 4, 3, 14, 0), open=1.22882, low=1.23057, high=1.2286299999999999, close=1.23018, tick_volume=6112, spread=1, real_volume=0), 
MT5Rate(time=datetime.datetime(2018, 4, 3, 15, 0), open=1.23018, low=1.23149, high=1.22919, close=1.22957, tick_volume=6691, spread=1, real_volume=0), 
MT5Rate(time=datetime.datetime(2018,4, 3, 16, 0), open=1.22957, low=1.22989, high=1.22557, close=1.2258, tick_volume=11956, spread=1, real_volume=0), 
MT5Rate(time=datetime.datetime(2018, 4, 3, 17, 0), open=1.2258, low=1.22746, high=1.22536, close=1.2273, tick_volume=10275, spread=1, real_volume=0))

I want to draw your attention to:

MT5Rate(time=datetime.datetime(2018,4, 3, 16, 0), open=1.22957, low=1.22989, high=1.22557, close=1.2258, tick_volume=11956, spread=1, real_volume=0)

go to the terminal, see low/hight for this frame:

We see thatlow=1.22557,high=1.22989

Question is this a bug or are keys for the MT5Rate somehow configurable?


MetaTrader 5 Python User Group - как использовать Python в Метатрейдере
MetaTrader 5 Python User Group - как использовать Python в Метатрейдере
  • 2019.11.25
  • www.mql5.com
Мы готовим модуль MetaTrader 5 для Python, аналогичную R...
 
Moved now to this thread.
Reason: