Machine learning in trading: theory, models, practice and algo-trading - page 3452

 
Maxim Dmitrievsky #:

in one fellswoop, if the quotes are loaded in the terminal

I'd rather have a figure, however approximate.

 
mytarmailS #:

I'd rather have a figure, however approximate.

I don't have a computer at hand

 
Aleksey Vyazmikin #:

Advisor is unnecessary. All queries from python, including trade queries.

Here, you can read the documentation on the language.

Would you be so kind as to answer my question? I am not interested in your opinion about the necessity of an advisor.

 
СанСаныч Фоменко #:

Would you be so kind as to answer my question exactly? I am not interested in your opinion on the need for a counsellor.

Please read the documentation at the link, and formulate questions after reading - substantively.

 
mytarmailS #:

Well, one week, for example, on 20 instruments, all TFs.

How much +-? Half a second, a minute?

After starting the terminal, 21 seconds.

2024.04.01 20:38:36.471 Python  script Get_Data (USDRUB,H1) started successfully
2024.04.01 20:38:57.126 Python  script Get_Data (USDRUB,H1) removed

Repeated request for data 13 seconds.

2024.04.01 20:39:11.397 Python  script Get_Data (USDRUB,H1) started successfully
2024.04.01 20:39:24.074 Python  script Get_Data (USDRUB,H1) removed

And again - here it's almost instantaneous 0.5 seconds.

2024.04.01 20:42:07.150 Python  script Get_Data (USDRUB,H1) started successfully
2024.04.01 20:42:07.641 Python  script Get_Data (USDRUB,H1) removed

In general, experiment - the code from the terminal will work.

# Copyright 2023, MetaQuotes Ltd.
# https://www.mql5.com

from datetime import datetime
import MetaTrader5 as mt5
import time

Start_Data = datetime(2024, 2, 5)
Stop_Data = datetime(2024, 2, 9)

def retrieve_data(get_Symbol, timeframe, retries_limit=300):
    attempt = 0
    raw_data = None
    timeframes = {
        'M1': mt5.TIMEFRAME_M1,
        'M2': mt5.TIMEFRAME_M2,
        'M3': mt5.TIMEFRAME_M3,
        'M4': mt5.TIMEFRAME_M4,
        'M5': mt5.TIMEFRAME_M5,
        'M6': mt5.TIMEFRAME_M6,
        'M10': mt5.TIMEFRAME_M10,
        'M12': mt5.TIMEFRAME_M12,
        'M15': mt5.TIMEFRAME_M15,
        'M20': mt5.TIMEFRAME_M20,
        'M30': mt5.TIMEFRAME_M30,
        'H1': mt5.TIMEFRAME_H1,
        'H2': mt5.TIMEFRAME_H2,
        'H3': mt5.TIMEFRAME_H3,
        'H4': mt5.TIMEFRAME_H4,
        'H6': mt5.TIMEFRAME_H6,
        'H8': mt5.TIMEFRAME_H8,
        'H12': mt5.TIMEFRAME_H12,
        'D1': mt5.TIMEFRAME_D1,
        'W1': mt5.TIMEFRAME_W1,
        'MN1': mt5.TIMEFRAME_MN1
    }

    TF = timeframes.get(timeframe)
    if TF is None:
        print("Invalid timeframe")
        return None
    while attempt < retries_limit:
        instrument_count = mt5.symbols_total()
        if instrument_count > 0:
            print(f"Number of instruments in the terminal: {instrument_count}")
        else:
            print("No instruments in the terminal")
        rates = mt5.copy_rates_range(get_Symbol, TF, Start_Data, Stop_Data)
        if rates is None or len(rates) == 0:
            print(f"Data for {get_Symbol} not available (attempt {attempt+1})")
            attempt += 1
            time.sleep(1)
        else:
            print(f"Котировки с {Start_Data} по {Stop_Data} на {timeframe} для {get_Symbol} получены")
            break
    return rates

# установим подключение к терминалу MetaTrader 5 
if not mt5.initialize(): 
    print("initialize() failed, error code =",mt5.last_error()) 
    quit() 
  
# получим все символы 
symbols=mt5.symbols_get() 
print('Symbols: ', len(symbols)) 
count=0 
# выведем 5 первых 
for s in symbols: 
    count+=1 
    print("{}. {}".format(count,s.name)) 
    if count==5: break 
print() 

timeframes = ['M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M10', 'M12', 'M15', 'M20', 'M30',
              'H1', 'H2', 'H3', 'H4', 'H6', 'H8', 'H12', 'D1']
              
W_data = []
count=0 

for s in symbols:
   sym=s.name
   # попробуем включить показ символа в MarketWatch 
   print(f"попробуем включить показ символа {sym} в MarketWatch")
   selected=mt5.symbol_select(sym,True) 
   if not selected: 
       print(f"Failed to select {sym}, error code =",mt5.last_error())   
   for timeframe in timeframes:
      rates = retrieve_data(sym, timeframe)   
      if rates is not None and len(rates) > 0:
          W_data.append(rates)
   count+=1       
   if count >= 20:
      break
      
# завершим подключение к терминалу MetaTrader 5 
mt5.shutdown()       
 
СанСаныч Фоменко #:

Would you be so kind as to answer my question exactly? I am not interested in your opinion on the necessity of a counsellor.

Integration with Python is made in such a way that it can only see and interact with the terminal. To interact with MQL you need R or many other less successful solutions IMHO
 
Vladimir Perervenko #:
Integration with Python is made in such a way that it can only see and interact with the terminal. To interact with MQL you need R or many other less successful IMHO solutions

How does R interact with MQL? I don't understand the difference in what globally.

 
Aleksey Vyazmikin #:

How does R interact with MQL? I don't understand the difference in what globally.

Using the long-standing proven mt-R library. Globally, it makes it possible to use MQL/R/Python together both in combat application and in testing, with a small change. When testing quotes and commands through MQL and when working through Python.
 
Vladimir Perervenko #:
Using the mt-R library, which has been tested for many years. Globally, this makes it possible to use MQL/R/Python together both in combat and testing, with a small change. When testing quotes and commands through MQL and when working through Python.

As I understand it, the difference is that you can run code from MQL for execution in R.

 
Aleksey Vyazmikin #:

After starting the terminal, 21 seconds

Repeated data request 13 seconds

And again - almost instantaneous 0.5 seconds.

In general, experiment - the code from the terminal will work

like

Reason: