Forex data in Python delayed by 2 hours

 

I integrated Python perfectly with Metatrader 5.

At my Brazilian broker everything works fine, without delay.

I tested it at Forex brokerages ICMarkets, Activ and XM and it doesn't work well. All have a delay of 2 hours (120 minutes). I've done several tests and researches and I can't solve it.

I contacted the ICMarkets chat and they don't support it. I asked if this is on purpose and they said no.

Someone knows how to solve this problem. Because I run out of data for the past 2 hours.


DELAY




I took the images on a Sunday, in the first hour of EURUSD's opening, as you can see the data obtained by Python is from last Friday. But as a rule the delay is 2 hours.


Follow the code below for testing:


from datetime import datetime

import MetaTrader5 as mt5

# estabelecemos a conexão ao MetaTrader 5

if not mt5.initialize():

    print("initialize() failed, error code =",mt5.last_error())

    quit()

data = mt5.copy_rates_from('EURUSD', mt5.TIMEFRAME_M1, datetime.today(), 10)

mt5.shutdown()

# a partir dos dados recebidos criamos o DataFrame

rates_frame = pd.DataFrame(data)

# convertemos o tempo em segundos no formato datetime

rates_frame['time']=pd.to_datetime(rates_frame['time'], unit='s')

rates_frame

 

Hi Junior,

check your timezone on your computer vs the timezone on the MT5. Are you sure you are getting the date you want on datetime.today() python call?

Cheers

 
Blessing Dumbura #:

Hi Junior,

check your timezone on your computer vs the timezone on the MT5. Are you sure you are getting the date you want on datetime.today() python call?

Cheers

same problem facing. what is the solution??
 
demo_111 #: same problem facing. what is the solution??
Already answered. You must use the broker time to trade and the broker's time-zone is often different to your own. But that does not mean that it is delayed. It is just a different time-zone.
 
I tried to change my local timezone but that did not seem to work. What eventually worked for me was using the copy_rates_from_pos(). With 0 as start_pos you can get current data that seems correct!
Documentation on MQL5: Python Integration / copy_rates_from_pos
Documentation on MQL5: Python Integration / copy_rates_from_pos
  • www.mql5.com
Get bars from the MetaTrader 5 terminal starting from the specified index. Parameters symbol [in]  Financial instrument name, for example...