Download MetaTrader 5
To add comments, please log in or register
Added support for the Spanish language. Come and check it out!
dolar
22
dolar 2013.12.15 23:09 
Hi Guys,

Do you have any idea how to check profit for all closed EURUSD positions from current day?

The code below returns only last closed order profit.

OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS,MODE_HISTORY);
    
Print(OrderProfit());

I make deals on EURUSD and EURJPY, but need only calculate profit for one instrument (EURUSD).

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.12.15 23:16  
dolar:
Hi Guys,

Do you have any idea how to check profit for all closed EURUSD positions from current day?

The code below returns only last closed order profit.

I make deals on EURUSD and EURJPY, but need only calculate profit for one instrument (EURUSD).

Loop through all the closed positions, OrderSelect() them one by one, check their OrderSymbol() if it matches EURUSD and their OrderOpenTime() is from today keep a running total of OrderProfit(), DONE.
dolar
22
dolar 2013.12.15 23:37  

something like this?

for(int i=(OrdersHistoryTotal()-1);i>=0;i--)
 {
OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
   if(OrderSymbol()==Symbol() && (TimeToStr(OrderCloseTime(),TIME_DATE))==(TimeToStr(TimeCurrent(),TIME_DATE)))
    {      
    
    Print(OrderProfit());      
    
           break; 
    }
 }
whroeder1
13610
whroeder1 2013.12.16 01:37  
  1. OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
    What are Function return values ? How do I use them ? - MQL4 forum
  2. (TimeToStr(OrderCloseTime(),TIME_DATE))==(TimeToStr(TimeCurrent(),TIME_DATE)
    Do you really think you must convert datetimes to strings in order to compare them? Do you really think that the last order will always have the same hour:minute was current time? What if the order closed 12:01:59 and now is 12:02:00?
/
To add comments, please log in or register