1. Thanks very much for answer!
2. I tried asking my broker's hotline about what are the supported fillings, but they had no idea. Is there a technical way to find out?
3. My code for the order corresponds practically 100% to the example in the instructions (https://www.mql5.com/de/docs/integration/python_metatrader5/mt5ordersend_py):
# Vorbereitung der Struktur request für einen Kauf symbol = "USDJPY" symbol_info = mt5.symbol_info(symbol) if symbol_info is None: print(symbol, "not found, can not call order_check()") mt5.shutdown() quit() # Wenn das Symbol im MarketWatch nicht verfügbar ist, wird es hinzugefügt if not symbol_info.visible: print(symbol, "is not visible, trying to switch on") if not mt5.symbol_select(symbol,True): print("symbol_select({}}) failed, exit",symbol) mt5.shutdown() quit() lot = 0.1 point = mt5.symbol_info(symbol).point price = mt5.symbol_info_tick(symbol).ask deviation = 20 # Maximal akzeptierte Abweichung vom gewünschten Preis, angegeben in Punkten request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": mt5.ORDER_TYPE_BUY, "price": price, "sl": price - 100 * point, #Ein Preis, zu dem eine Stop-Loss-Order aktiviert wird, wenn sich der Preis in eine ungünstige Richtung bewegt. "tp": price + 100 * point, #Ein Preis, zu dem ein Take-Profit-Auftrag aktiviert wird, wenn sich der Preis in eine günstige Richtung bewegt. "deviation": deviation, #Maximal akzeptierte Abweichung vom gewünschten Preis, angegeben in Punkten "magic": 234000, # EA-ID. Ermöglicht das Erkennen von Handelsaufträgen für eine anlytische Behandlung. Jeder EA kann beim Senden einer Handelsanfrage eine eindeutige ID festlegen. "comment": "python script open", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_RETURN, } # Senden eines Handelsauftrags result = mt5.order_send(request) # Prüfen des Ausführungsergebnisses print("1. order_send(): by {} {} lots at {} with deviation={} points".format(symbol,lot,price,deviation)); if result.retcode != mt5.TRADE_RETCODE_DONE: print("2. order_send failed, retcode={}".format(result.retcode)) # Abrufen des Ergebnisses als Liste und Darstellung Element für Element result_dict=result._asdict() for field in result_dict.keys(): print(" {}={}".format(field,result_dict[field])) # Wenn es die Struktur eines Handelsauftrags ist, werden die Elemente auch einzeln angezeigt if field=="request": traderequest_dict=result_dict[field]._asdict() for tradereq_filed in traderequest_dict: print(" traderequest: {}={}".format(tradereq_filed,traderequest_dict[tradereq_filed])) print("shutdown() and quit") mt5.shutdown() #quit() print("2. order_send done, ", result) print(" opened position with POSITION_TICKET={}".format(result.order))
- www.mql5.com
1. Thanks very much for answer!
2. I tried asking my broker's hotline about what are the supported fillings, but they had no idea. Is there a technical way to find out?
3. My code for the order corresponds practically 100% to the example in the instructions (https://www.mql5.com/de/docs/integration/python_metatrader5/mt5ordersend_py):
What did the print out give you?
Did you try another broker, maybe? (demo account)
Print out the request structure to console before sending it to the function call:
# Senden eines Handelsauftrags # Bitte die request-struct auf der Konsole ausgeben, die Werte gegenprüfen. result = mt5.order_send(request)
What did the print out give you?
Did you try another broker, maybe? (demo account)
Print out the request structure to console before sending it to the function call:
So I got it working now :-)
The platform only accepts: "type_filling": mt5.ORDER_FILLING_IOC.
The mistake was also that you have to enter an explizit login for an order:
account=12345 authorized=mt5.login(account, password="XXXX") if authorized: # Anzeige der Daten des Handelskontos 'as is' print("") print("account_info:\n", mt5.account_info()) # Anzeige der Daten des Handelskontos als Liste print("") print("Show account_info()._asdict():") account_info_dict = mt5.account_info()._asdict() for prop in account_info_dict: print(" {}={}".format(prop, account_info_dict[prop])) else: print("failed to connect at account #{}, error code: {}".format(account, mt5.last_error()))
If you do it that way, you also get the individual specifics of the access back as an additional benefit, especially important for me that the ordering option is activated.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The full error message: