Calculate equity-Get equity on specified date PY

 
Hello guys!
I was looking at the python API for MT5, is there any way to get the history of the equity?
I don't need the full PY method, I was just wondering if someone could give me a hint/point me to a direction to implement a way to calculate/get the equity in a specified date.

Thanks in advance
 
Francesco Bosso :
Hello guys!
I was looking at the python API for MT5, is there any way to get the history of the equity?
I don't need the full PY method, I was just wondering if someone could give me a hint/point me to a direction to implement a way to calculate/get the equity in a specified date.

Thanks in advance

Python documentation is collected in the MetaTrader for Python section.

You need to work with trading history:

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
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:

Python documentation is collected in the MetaTrader for Python section.

You need to work with trading history:

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

Thank you! I figured it out!

If possible, could I ask you another question without opening a new thread?

I read here that by setting in the request the action key to " TRADE_ACTION_MODIFY " you can modify the parameters of the previously placed trading order, so can you also modify the volume of an open position?
I tried doing it by setting in the dictionary the action to that const, specifying the position ticket, magic, type, (new) volume (that's the parameter I wanted to update), type filling, price and type time
but got the error code: 10013, that has as comment "Invalid request".

I was wondering, what did I do wrong? Obviously I would have to toss all the dictionary to have an answer, but specifically: what are the parameters I have to input to change an open position? Is it possible to do it by the python API?
I tried doing it via the Software MT5 FX PRO and it worked, but is there a thing to interact with this type of request?

Could you by any chance show a snippet of code or at least specify what are the requested parameters to make this type of request? (I tried searching in the docs but didn't find any).
Thank you in advance!.
Documentation on MQL5: Integration / MetaTrader for Python / order_check
Documentation on MQL5: Integration / MetaTrader for Python / order_check
  • www.mql5.com
order_check - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

The position size cannot be changed. You can: either close the position completely or close part of the position. In the MQL5 language, an example for the trading class CTrade:

PositionClosePartial

Partially closes a position on a specified symbol or having a specified ticket

Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionClosePartial
Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionClosePartial
  • www.mql5.com
PositionClosePartial(const string,const double,ulong) - CTrade - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:

The position size cannot be changed. You can: either close the position completely or close part of the position. In the MQL5 language, an example for the trading class CTrade:

PositionClosePartial

Partially closes a position on a specified symbol or having a specified ticket

So the only way to to change the volume of an open position would be to close the previous one and open a new one with a new volume? Right?

Thank you for the response anyway!
 
Francesco Bosso # :
So the only way to to change the volume of an open position would be to close the previous one and open a new one with a new volume? Right?

Thank you for the response anyway!

No, not really. There are two ways:

  1. Completely close a position and then open a new position
  2. Perform a partial closing operation (essentially this is item 1. - but it is performed automatically using the MQL5 language).

Links to the CTrade trading class:

Operations with positions

 

PositionClose

Closes a position for the specified symbol

PositionClosePartial

Partially closes a position on a specified symbol or having a specified ticket

Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionOpen
Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionOpen
  • www.mql5.com
PositionOpen(const string,ENUM_ORDER_TYPE,double,double,double,double,const string) - CTrade - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

For Python you will use

order_send

Send a request to perform a trading operation.

The main thing is to correctly fill out the trade request

Documentation on MQL5: Integration / MetaTrader for Python / order_send
Documentation on MQL5: Integration / MetaTrader for Python / order_send
  • www.mql5.com
order_send - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:

No, not really. There are two ways:

  1. Completely close a position and then open a new position
  2. Perform a partial closing operation (essentially this is item 1. - but it is performed automatically using the MQL5 language).

Links to the CTrade trading class:

Operations with positions

 

PositionClose

Closes a position for the specified symbol

PositionClosePartial

Partially closes a position on a specified symbol or having a specified ticket

Yep, I already had a look at them, in fact I already have built the methods for it.

Thank you for the answers! Have a nice day!
Reason: