How to get ea results with python mt5?

 

Hi

Since I'm new here - I would like to get some help in annoying situation:

I'm developing in Python a trading robot and would like to check if a trade is profitable or not.

In the attached file, in the history section there are done trades - profitable and lose trades.

I already know how to connect to my EA and get the open trades with mt5.positions_get but

I couldn't find how to get the data of the closed trades including the profit of them.


Thanks for any help


Uri

Files:
 
Uri Flexer :


This is probably:

history_deals_total

Get the number of deals in trading history within the specified interval

history_deals_get

Get deals from trading history with the ability to filter by ticket or position

Documentation on MQL5: Integration / MetaTrader for Python / history_orders_total
Documentation on MQL5: Integration / MetaTrader for Python / history_orders_total
  • www.mql5.com
[in]  Date the orders are requested from. Set by the 'datetime' object or as a number of seconds elapsed since 1970.01.01. Required unnamed parameter. [in]  Date, up to which the...
 

Looks like  history_deals_get is what I need

Thanks a lot !!!

 
Uri Flexer:

Looks like  history_deals_get is what I need

Thanks a lot !!!

Hi Uri,

import MetaTrader5 as Mt5
from datetime import datetime, timedelta

Mt5.history_deals_get((datetime.today() - timedelta(days=1)), datetime.now())[-1].profit

You can get the last deals in this way.


Also, if you have an interest, I have a library that helps integrate MQL5 to Python.


You can found it here:

https://github.com/Joaopeuko/Mql5-Python-Integration

 
Joao Paulo Euko :

Hi Uri,

You can get the last deals in this way.


Also, if you have an interest, I have a library that helps integrate MQL5 to Python.


You can found it here:

https://github.com/Joaopeuko/Mql5-Python-Integration

Thank you João.


I'm starting now, could you tell me how to plot a simple average in Metatrader, by python,

just for example. (I don't know exactly how to "plot" I mean show the average on the graph)

Thank you.

 
Mateus Lopes:

Thank you João.


I'm starting now, could you tell me how to plot a simple average in Metatrader, by python,

just for example. (I don't know exactly how to "plot" I mean show the average on the graph)

Thank you.

Hi Mateus Lopes, how are you?


The main objective for the python code is to return only the numbers that you requested for. It is intended to be used in trading automation, where there is no need for visual information like a graph, the expert advisor/"robot" only need numbers. However, if you want to plot a graph using python, we can talk about it. I will send you a personal message.


But, if the idea is just visualization, you can use the graph directly through the Metatrader5. 


I will send you a message.

Reason: