Orders Report EA

 

hello guys hope you're doing good , i'm new to mql4 , i'm trying to do a simple expert expert advisor that counts the number of trades each expert advisor did historically using the matching number,

int OnInit()
  {

   return(INIT_SUCCEEDED);
  }



void OnTick()
   {
   
   
  
  int i;
  int exe;
  for ( i=OrdersHistoryTotal();i>0;i--);
  {
  OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
  if(OrderMagicNumber()==3421){
  exe++;

  }
   Comment("Ask =  ",exe);
   
    }
  
  return;
   
 
  }

but it is always returning result 0 ,(new to mql4 , training).

 
nidalzd:

hello guys hope you're doing good , i'm new to mql4 , i'm trying to do a simple expert expert advisor that counts the number of trades each expert advisor did historically using the matching number,

but it is always returning result 0 ,(new to mql4 , training).

Do not double post!

I have deleted your duplicated topic.

 int exe;

You should always assign an initial value to variables like this.

 int exe=0;
  for ( i=OrdersHistoryTotal();i>0;i--);

Should be

  for ( i=OrdersHistoryTotal()-1;i>=0;i--);

Are there any closed orders with that magic number?

 
nidalzd:

hello guys hope you're doing good , i'm new to mql4 , i'm trying to do a simple expert expert advisor that counts the number of trades each expert advisor did historically using the matching number,

but it is always returning result 0 ,(new to mql4 , training).

Instead of counting the orders, try printing a list of orders with their magic numbers, so initially you can see if there are any matching orders.

It's a good idea to work out how you can debug code, not just in this example but any future issues, too?

 
  int exe;
  for ( i=OrdersHistoryTotal();i>0;i--);
  {
  OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

If there are n history orders, their position index is [n-1 … 0]

  1. Your first OrderSelect failed, but you don't check.
  2. Your last OrderSelect is skipped.
  3. MT4:

    1. Do not assume history has only closed orders.
                OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017)

    2. Do not assume history is ordered by date, it's not.
                Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012)
                Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020)

    3. Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
                "balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017)

      Broker History
      FXCM
      Commission - <TICKET>
      Rollover - <TICKET>

      >R/O - 1,000 EUR/USD @0.52

      #<ticket>  N/A
      OANDA
      Balance update
      Financing (Swap: One entry for all open orders.)

 
Keith Watford #:

Do not double post!

I have deleted your duplicated topic.

You should always assign an initial value to variables like this.

Should be

Are there any closed orders with that magic number?

Hello , thanks for the reply , yes there's open and closed orders

 
nidalzd #:

You have been told not to double post and yet you have opened a new topic that is related to this code. I have deleted that topic.

Continue your questions here, don't open a new topic every time that you have a related question.

Also Topics concerning MT4 and MQL4 have their own section. I have already moved this topic.

In future please post in the correct section.

 
Keith Watford #:

You have been told not to double post and yet you have opened a new topic that is related to this code. I have deleted that topic.

Continue your questions here, don't open a new topic every time that you have a related question.

Also Topics concerning MT4 and MQL4 have their own section. I have already moved this topic.

In future please post in the correct section.

I have just deleted yet another topic, again posted in the wrong section.

I will ban you for 1 day, next time you can expect longer.

 

I have just deleted yet another topic of yours that is related to dealing with historic orders.

Again it was posted in the wrong section!