MetaTrader 5 Python User Group - Come usare Python in Metatrader - pagina 65

 
Документация по MQL5: Интеграция / MetaTrader для Python / order_send
Документация по MQL5: Интеграция / MetaTrader для Python / order_send
  • www.mql5.com
[in]  Структура типа MqlTradeRequest, которая описывает требуемое торговое действие. Обязательный неименованный параметр. Пример заполнения запроса и состав перечислений смотрите ниже. Идентификатор эксперта. Позволяет организовать аналитическую обработку торговых ордеров. Каждый эксперт может выставлять свой собственный уникальный...
 
AxxelTrader:

Aggiornato alla versione 2432.
Ma l'errore è ancora lì...
Provato su diversi broker anche...

r = mt5.Buy(...)
if r is None:
    print(mt5.last_error())
else:
    if r.retcode ...
 

copy_rates_from non fornisce abbastanza dati sul timeframe M1.


È la giusta linea d'azione?

from datetime import datetime 
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
import pytz

register_matplotlib_converters()
import MetaTrader5 as mt5


 if not mt5.initialize():
    print("initialize() failed")
    mt5.shutdown()


print(mt5.terminal_info())
print(mt5. version ())

timezone = pytz.timezone("Etc/UTC")
utc_from = datetime ( 2020 , 1 , 10 , tzinfo=timezone)


eurusd_rates_m1 = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_M1, utc_from, 1000 )
print('M1 eurusd_rates(', len(eurusd_rates_m1), ')')
eurusd_rates_m5 = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_M5, utc_from, 1000 )
print('M5 eurusd_rates(', len(eurusd_rates_m5), ')')
eurusd_rates_m10 = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_M10, utc_from, 1000 )
print('M10 eurusd_rates(', len(eurusd_rates_m10), ')')
eurusd_rates_m15 = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_M15, utc_from, 1000 )
print('M15 eurusd_rates(', len(eurusd_rates_m15), ')')
eurusd_rates_m30 = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_M30, utc_from, 1000 )
print('M30 eurusd_rates(', len(eurusd_rates_m30), ')')


mt5.shutdown()
M1 eurusd_rates( 1 )      ???
M5 eurusd_rates( 1000 )
M10 eurusd_rates( 1000 )
M15 eurusd_rates( 1000 )
M30 eurusd_rates( 1000 )
 
So che questo argomento diventerà rapidamente molto lungo. Metaquotes deve aggiungere un nuovo sottoforum (Python) per ogni lingua.
 
Christian:

copy_rates_range non fornisce abbastanza dati sul timeframe M1.


È la giusta linea d'azione?

Prestare attenzione alla nota sulla gamma di tassi di copia

Nota

Vedere la funzione CopyRates() per maggiori informazioni.

Il terminale MetaTrader 5 fornisce barre solo all'interno di una storia disponibile per un utente sui grafici. Il numero di barre disponibili per gli utenti è impostato nel parametro "Max. bars in chart".

Quando si crea l'oggetto 'datetime', Python usa il fuso orario locale, mentre MetaTrader 5 memorizza il tempo di apertura di tick e barre nel fuso orario UTC (senza lo spostamento). Pertanto, 'datetime' dovrebbe essere creato nel tempo UTC per l'esecuzione di funzioni che utilizzano il tempo. I dati ricevuti dal terminale MetaTrader 5 hanno l'ora UTC.


Documentation on MQL5: Integration / MetaTrader for Python / copy_rates_range
Documentation on MQL5: Integration / MetaTrader for Python / copy_rates_range
  • www.mql5.com
# create 'datetime' objects in UTC time zone to avoid the implementation of a local time zone offset # get bars from USDJPY M5 within the interval of 2020.01.10 00:00 - 2020.01.11 13:00 in UTC time zone                  time     open     high      low    close  tick_volume  spread  real_volume...
 
Rashid Umarov:

Prestare attenzione a Nota sulla gamma dei tassi di copia

C'è un bug nei tassi di copia. L'ho postato diverse volte ma nessuno l'ha riconosciuto.

import MetaTrader5 as mt5

mt5.initialize()
maxbars = mt5.terminal_info().maxbars
for count in range(maxbars):
    rates = mt5.copy_rates_from_pos('EURUSD', mt5.TIMEFRAME_M1, 0, count)
    errno, strerror = mt5.last_error()
    if errno != mt5.RES_S_OK:
        print(f"Failed on count={count} with strerror={strerror}")
        break
mt5.shutdown()

##
# Failed on count=7844 with strerror=IPC recv failed
##
 
È un peccato, ma la mia comprensione è che c'è un problema con l'inizializzazione delle strutture in MT.
 
A proposito, devo presentare mia nipote a Python e non lo conosco... Arrivederci.
 

Ho uno script che ha funzionato per qualche ora. ma poi comincio a ricevere questi errori, Invalid_Stops, e poi non apre più i trade.

1.BUY order send (): by EURUSD 0.01 lots at 1.0949 

2. order_send failed, retcode = 10016 
   retcode = 10016 
   deal = 0 
   order = 0 
   volume = 0.0 
   price = 0.0 
   bid = 0.0 
   ask = 0.0 
   comment = Invalid stops 
   request_id = 0 
   retcode_external = 0 

   request = TradeRequest (action = 1, magic = 234000, order = 0, symbol = 'EURUSD', volume = 0.01, price = 1.0949, stoplimit = 0.0, sl = 1.0939, tp = 1.0979, 
   deviation = 0, type = 0, type_filling = 0, type_time = 0, expiration = 0, commen 

t = 'EURUSD Buy.', Position = 0, position_by = 0) 

Qualcuno può aiutare a dirigere dove iniziare a cercare questo problema?

Grazie

 
fbrand:

Ho uno script che ha funzionato per alcune ore. ma poi comincio a ricevere questi errori, Invalid_Stops, e poi non apre più i trade.

Qualcuno può aiutare a dirigere dove iniziare a cercare questo problema?

Grazie

Qual era il prezzo corrente (Bid e Ask)? Qual era il livello di congelamento (SYMBOL_TRADE_FREEZE_LEVEL)?

Motivazione: