Forum

How to properly close an opened order with python? (can't pass a ticket number to “position” when sending an order)

I want to open an order, no problem with that, but if I want to close this order, I need the ticket number, ticket that I can't write manually, it will be given after the order is opened. From the documentation , I've got this: but I can't pass anything else than 0 to "position": 0 (line 20)

How to close an mt5 order/position with python?

I want to create a function to open an order and one to close the pending order or the position. No problem with opening the position/order, but the issue is with the closing function. import time import MetaTrader5 as mt5 # establish connection to the MetaTrader 5 terminal if not mt5.initialize()