Download MetaTrader 5

How to get last closed order gained pip?

To add comments, please log in or register
Install apps from the library right in MetaTrader. It is easy!
Sherif Hasan
7289
Sherif Hasan 2014.12.01 06:27 

How to get last closed order gained pip?

Is there any function available to find last closed order pip value?

Carl Schreiber
6580
Carl Schreiber 2014.12.01 07:41  

I would do

1) loop though all closed orders,

2) check the OrderCloseTime() whether the most recent so far

3) if 2) save ( OrderClosePrice() - OrderOpenPrice() )/pip; // for a buy order!

Sherif Hasan
7289
Sherif Hasan 2014.12.01 11:36  

Thanks gooly, got success by your idea.

int last_trade=HistoryTotal();
if(last_trade>0)
  {
   if(OrderSelect(last_trade-1,SELECT_BY_POS,MODE_HISTORY)==true)
     {
      BuyProfitPip=OrderClosePrice()-OrderOpenPrice();
      SellProfitPip=OrderOpenPrice()-OrderClosePrice();
     }
  }
Carl Schreiber
6580
Carl Schreiber 2014.12.01 11:45  
sheriffonline:

Thanks gooly, got success by your idea.

But now you get only the trade with the highest pos no. - not the last trade in a temporal sequence!

To be save you have to loop through the history!

To add comments, please log in or register