How can I keep track of the maximum unrealized profit reached on each order placed.

 

Hi Mt4 gurus,

Now this is my question. I am running several comercial EAs on a real account, and I see trades going up to lets say $210 and keep fluctuating, after a while goes down an profit taken: $50 or negative.

I wonder how I can keep track of the max unrealized profit if I am not looking at the chart. So that I could see that for that particular trade unrealized profit went up to $370, without having to look the chart for each trade.

Best regards,

 
For buy:
OrderSelect(...)
int     duration        = iBarShift(NULL, 0, OrderOpenTime()) + 1;
double  HH              = High[Highest(NULL, 0, MODE_HIGH, duration, 0)];
double  perLotPerPoint  = PointValuePerLot();
double  maxProfit       = perLotPerPoint * OrderLots() * (HH-OrderOpenPrice());
////////////////
double  PointValuePerLot() { // Value in account currency of a Point of Symbol.
    /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
     * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
     * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
     * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
     *                                  $1.00/point or $10.00/pip.
     *
     * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the
     * same value as MODE_POINT (or Point for the current symbol), however, an
     * example of where to use MODE_TICKSIZE would be as part of a ratio with
     * MODE_TICKVALUE when performing money management calculations which need
     * to take account of the pair and the account currency. The reason I use
     * this ratio is that although TV and TS may constantly be returned as
     * something like 7.00 and 0.00001 respectively, I've seen this
     * (intermittently) change to 14.00 and 0.00002 respectively (just example
     * tick values to illustrate). */
    return(  MarketInfo(Symbol(), MODE_TICKVALUE)
           / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
}
 
When I grow up to be a real Forex programmer, I want to be WHRoeder.
 

Thank you for answering Mr. WHRoeder.

I'll have to digest the answer. Too technical for me at this stage. This code is a script, a variable, ... ?

Regards,

 
xmander:

Thank you for answering Mr. WHRoeder.

I'll have to digest the answer. Too technical for me at this stage. This code is a script, a variable, ... ?

Regards,

It's a function, you call it. It looks at the highest price has gone from the time the order was placed until it closed . . and then works out what you were asking for . . . very nice.