Stuck on my first EA

 

Hello Everybody.  I am messing around with my first EA but I do not have the knowledge to do what I am trying to do.

 I am trying to add a section to my EA that will do the following action:

 Look at all open trades (All trades are long, no short positions in the EA)

If the trades are showing a negative profit

~Add all entry positions and divide by the number of open trades

 

For example if I have open positions at

1.3500 and 1.3300

and the curent market is at 1.3200

This section of the EA would do the following:

1.3500 + 1.3300 = 2.6800

2.6800 / 2 (open positions) = 1.3400

So it makes 1.3400 the new take profit of both (or all) open positions.

 

Is this even possible?

Thank you for all your help. 

 
mtandkids:

Hello Everybody.  I am messing around with my first EA but I do not have the knowledge to do what I am trying to do.

Is this even possible?

Thank you for all your help. 

It's not clear if your question is related to MT4 or MT5... However, in case it's related to MT5, please take a look at function PositionGetDouble, specifically the option POSITION_PRICE_OPEN.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: