How to check daily_profit with mq4

To add comments, please log in or register
Cromo
259
Cromo  

Hi, I use below code to check daily profit. I will stop EA when daily profit reached to the target.

But when I first time attach the EA on the chart and check the daily profit value, it shows account equity.

I wonder why...

It should be zero when I attach the EA for the first time.

double daily_profit()
{
 double prof=0;
 int trade;
 int trades=OrdersHistoryTotal();
 
for(trade=0;trade<trades;trade++) {
  OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY);  
  if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) {   
   if(OrderCloseTime() >= iTime(Symbol(),1440,0)) prof += OrderProfit() + OrderSwap() + OrderCommission(); }}
 
for(trade=0;trade<OrdersTotal();trade++) {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);  
  if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) {   
   if(OrderOpenTime() >= iTime(Symbol(),1440,0)) prof += OrderProfit() + OrderSwap() + OrderCommission(); }}
 return(prof);
}
Keith Watford
Moderator
20585
Keith Watford  
Cromo:

Hi, I use below code to check daily profit. I will stop EA when daily profit reached to the target.

But when I first time attach the EA on the chart and check the daily profit value, it shows account equity.

I wonder why...

It should be zero when I attach the EA for the first time.

Where do you print the value?

Cromo
259
Cromo  
Keith Watford:

Where do you print the value?

HI, I just print as comment.

Comment ("daily_profit="+daily_profit())


But why it shows equity?

Keith Watford
Moderator
20585
Keith Watford  
Cromo:

HI, I just print as comment.


But why it shows equity?

I don't see how it can show the equity.

Search in your code for another Comment() that may be overwriting it.

Cromo
259
Cromo  
Keith Watford:

I don't see how it can show the equity.

Search in your code for another Comment() that may be overwriting it.

Thank you.

I still don't know why it is.

Maybe I will deeply check to see if there is another code affecting it.

Fabio Cavalloni
4211
Fabio Cavalloni  
Why you cycle two times orders?
The second cycle is wrong, daily profits are generated from order that has OrderCloseTime >= today, not the open time.
You are counting two times profits of order opened today and one time orders opened before today.

Be sure of history period selected in your MT4 platoform, ordershistorytotal loads orders from it.
To add comments, please log in or register