'How do i get the result of a trade in MT5 with python using the ticket number?

I have a python script that places trades, wait a certain amount of time and then closes the trade, however, I'm having issues trying to get the result. According to the mt5 documentation the function is:

mt5.history_deals_get(parameters)

and the parameters can be a ticket id, position id or date_from/date_end, however, even copying and pasting the code given in the documentation sometimes I get the information and sometimes I don't and mt5.last_error() just returns a (1, "Success").

So, how can i get the profit or loss from a trade with the ticket id?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source