Cant seem to figure out why I am not getting a good response from the mt5.

 
Cant seem to figure out why I am not getting a good response from the mt5.

2024-10-11 08:42:42,641 INFO worker.py:1786 -- Started a local Ray instance.
Initialized MetaTrader 5
(downloadasset pid=16728) Fetching data for ticker: GBPJPY
(downloadasset pid=16728) No data available for GBPJPY. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=16728) Fetching data for ticker: USDCHF
(downloadasset pid=16728) No data available for USDCHF. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=16728) Fetching data for ticker: USDJPY
(downloadasset pid=16728) No data available for USDJPY. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=31596) Fetching data for ticker: USDCAD
(downloadasset pid=31596) No data available for USDCAD. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=12328) Fetching data for ticker: EURUSD
(downloadasset pid=12328) No data available for EURUSD. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=33492) Fetching data for ticker: NZDUSD
(downloadasset pid=33492) No data available for NZDUSD. Error: (-10004, 'No IPC connection')Skipping...

Below attached is  a simple code. Can you tell me its wrong? Looks straightforward to me.

I know its been a while but I would appreciate the help, thanks alot in advance for the time and consideration.
import ray
import MetaTrader5 as mt5
import pandas as pd
import datetime

# Initialize Ray
ray.init()

# Initialize MetaTrader 5
mt5.initialize(
    path="C:/Program Files/MetaTrader 5 IC Markets (SC)/terminal64.exe",
    login=51931148,
    server="ICMarketsSC-Demo",
    password="utC9KLVn!2vFDN"
)
if not mt5.initialize():
    print("Failed to initialize MetaTrader 5")
    mt5.shutdown()
else:
    print("Initialized MetaTrader 5")
@ray.remote
def downloadasset(asset_name):
    print(f"Fetching data for ticker: {asset_name}")
   
    # Fetch historical data for the asset
    raw_data = mt5.copy_rates_from_pos(asset_name, mt5.TIMEFRAME_M15, 0, 256)
    start_date = datetime.datetime(2024, 7, 9)
    end_date = datetime.datetime(2024, 7, 16)

    # Convert to timestamps
    start_date = int(start_date.timestamp())
    end_date = int(end_date.timestamp())

    if raw_data is None or len(raw_data) == 0:
        print(f"No data available for {asset_name}. Error: {mt5.last_error()}Skipping...")

        return None
    
    # Convert raw data to DataFrame
    charts = pd.DataFrame(raw_data, columns=['time', 'open', 'high', 'low', 'close', 'tick_volume'])
    charts = charts.rename(columns={'time': 'Date', 'open': 'Open', 'high': 'High', 'low': 'Low', 'close': 'Close', 'tick_volume': 'Volume'})
    charts['Date'] = pd.to_datetime(charts['Date'], unit='s')
    charts = charts.set_index(charts['Date'])
    charts = charts.drop(columns=['Date'])
    asset_data = charts[['Open', 'High', 'Low', 'Close', 'Volume']]
    
    # Use MultiIndex to differentiate between assets
    asset_data.columns = pd.MultiIndex.from_product([[asset_name], asset_data.columns])
    
    return asset_data

# Define the list of tickers
cfdtickers = ['AUDUSD', 'EURCHF', 'EURJPY', 'EURUSD', 'GBPJPY', 'GBPUSD', 'NZDUSD', 'USDCAD', 'USDCHF', 'USDJPY']

# Download data for all tickers in parallel
futures = [downloadasset.remote(ticker) for ticker in cfdtickers]

# Get the results (data for each ticker)
results = ray.get(futures)

# Combine the data for all tickers into a single DataFrame
combined_data = pd.concat([res for res in results if res is not None], axis=1)

# Print or save the combined data
print(combined_data)

# Shutdown Ray and MT5 after usage
mt5.shutdown()
ray.shutdown()

 
Juergen Aaron Jared Israel Jesse Jean Marie:
Cant seem to figure out why I am not getting a good response from the mt5.

2024-10-11 08:42:42,641 INFO worker.py:1786 -- Started a local Ray instance.
Initialized MetaTrader 5
(downloadasset pid=16728) Fetching data for ticker: GBPJPY
(downloadasset pid=16728) No data available for GBPJPY. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=16728) Fetching data for ticker: USDCHF
(downloadasset pid=16728) No data available for USDCHF. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=16728) Fetching data for ticker: USDJPY
(downloadasset pid=16728) No data available for USDJPY. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=31596) Fetching data for ticker: USDCAD
(downloadasset pid=31596) No data available for USDCAD. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=12328) Fetching data for ticker: EURUSD
(downloadasset pid=12328) No data available for EURUSD. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=33492) Fetching data for ticker: NZDUSD
(downloadasset pid=33492) No data available for NZDUSD. Error: (-10004, 'No IPC connection')Skipping...

Below attached is  a simple code. Can you tell me its wrong? Looks straightforward to me.

I know its been a while but I would appreciate the help, thanks alot in advance for the time and consideration.

try and load the rates in mt5 first 

this is for testing ? or live ?

 
Juergen Aaron Jared Israel Jesse Jean Marie:
Cant seem to figure out why I am not getting a good response from the mt5.

2024-10-11 08:42:42,641 INFO worker.py:1786 -- Started a local Ray instance.
Initialized MetaTrader 5
(downloadasset pid=16728) Fetching data for ticker: GBPJPY
(downloadasset pid=16728) No data available for GBPJPY. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=16728) Fetching data for ticker: USDCHF
(downloadasset pid=16728) No data available for USDCHF. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=16728) Fetching data for ticker: USDJPY
(downloadasset pid=16728) No data available for USDJPY. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=31596) Fetching data for ticker: USDCAD
(downloadasset pid=31596) No data available for USDCAD. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=12328) Fetching data for ticker: EURUSD
(downloadasset pid=12328) No data available for EURUSD. Error: (-10004, 'No IPC connection')Skipping...
(downloadasset pid=33492) Fetching data for ticker: NZDUSD
(downloadasset pid=33492) No data available for NZDUSD. Error: (-10004, 'No IPC connection')Skipping...

Below attached is  a simple code. Can you tell me its wrong? Looks straightforward to me.

I know its been a while but I would appreciate the help, thanks alot in advance for the time and consideration.

I didn't check your script in depth, but before getting data from a symbol, you need to select it, check the documentation please. 

https://www.mql5.com/en/docs/python_metatrader5/mt5symbolselect_py

Documentation on MQL5: Python Integration / symbol_select
Documentation on MQL5: Python Integration / symbol_select
  • www.mql5.com
Select a symbol in the MarketWatch window or remove a symbol from the window. symbol [in]  Financial instrument name. Required unnamed...
 
Lorentzos Roussos #:

try and load the rates in mt5 first 

this is for testing ? or live ?

It works usually with asyncio. Trying a new library Ray.