Counting closed trades in a day

 

hello members,

i am trying to count closed trades in a day but it is not working  and all the values i am printing in the for loop does not get printed. Any help would be much appreciated thank you.

#include <Trade/Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>  




CTrade m_trade;
CPositionInfo m_position;
CSymbolInfo m_symbol;



  
  
  

void OnTick()
  {
//---

   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid1 = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);


    if(PositionsTotal() < 1 )
     m_trade.Buy(0.01,NULL,m_symbol.Ask(),(Ask - 100 * _Point));
    //m_trade.Sell(0.01,NULL,/*m_symbol.Bid()*/ (Bid1 - 100 * _Point),(Bid1 + 100 * _Point));
   
   

int ClosedOdersCount = 0;
datetime now_time = TimeCurrent();  // Get the current time
datetime today_time = MathRound(MathFloor(now_time / 86400) * 86400);  // Get the datetime value for the start of today

  if(HistoryDealsTotal() > 0){
    for(int i=0; i<HistoryDealsTotal(); i++){
      
       ulong ticket = HistoryDealGetTicket(i);
       if ( HistoryDealSelect(ticket) ){
         Print("ticket: ", ticket); 

        datetime CloseOdersTime = HistoryDealGetInteger(ticket, DEAL_TIME);
        Print("i = ", i, ", ticket = ", ticket, ", CloseOdersTime = ", CloseOdersTime, ", today_time = ", today_time);
        if(CloseOdersTime >= today_time){
          ClosedOdersCount ++;
        //  Print("CloseOdersTime: ", CloseOdersTime);        
          Print("CloseOdersTime: ", CloseOdersTime);
          Print("today_time: ", today_time);
        
          }
              
         }
        }
       }

       Print("Today's closed trades count: ", ClosedOdersCount);  
   }
 
Courage Adjetey:

hello members,

i am trying to count closed trades in a day but it is not working  and all the values i am printing in the for loop does not get printed. Any help would be much appreciated thank you.

HistoryDealGetTicket

Prior to calling HistoryDealGetTicket(), first it is necessary to receive the history of deals and orders using the HistorySelect() or HistorySelectByPosition() function.

HistorySelect(from_date,to_date); 
 
thanks chioma for the response i called it like this 
HistorySelect(today_time,now_time);
but it didn't work. any other solutions?
 
Courage Adjetey # but it didn't work. any other solutions?

“Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
     How To Ask Questions The Smart Way. (2004)
          When asking about code
          Be precise and informative about your problem

 
William Roeder #:

Hi William,

I don't know if you know this, but the external links have not been working for some time now, and even if I copy link and go to it in another tab, I get this:

The connection is not private

It is possible that the attackers are trying to steal your information from www.catb.org (e.g. passwords, messages or credit cards). 

NET::ERR_CERT_COMMON_COMMON_NAME_INVALID

I would appreciate it (myself and I think other moderators) to avoid including external links in all your posts. I doubt anyone will read more than two lines of what you say.

Thank you.

 
@Miguel Angel Vico Alba #I don't know if you know this, but the external links have not been working for some time now, and even if I copy link and go to it in another tab, I get this:

Have external links now been permanently disabled by MetaQuotes or is this a temporary website bug?

Currently, clicking on any external link simply redirects to the main website URL — https://www.mql5.com/

 
Fernando Carreiro #:

Have external links now been permanently disabled by MetaQuotes or is this a temporary website bug?

Currently, clicking on any external link simply redirects to the main website URL — https://www.mql5.com/

Not all external links have been deactivated. There seems to be a kind of blacklist and for example links to Wikipedia are working. They also seem to take SSL certificates into consideration.

 
@Miguel Angel Vico Alba #: Not all external links have been deactivated. There seems to be a kind of blacklist and for example links to Wikipedia are working. They also seem to take SSL certificates into consideration.
I tested an external link I recently provided and it worked correctly. So, it seems that this website is probably validating certificates before redirecting.
 
Fernando Carreiro #:
I tested an external link I recently provided and it worked correctly. So, it seems that this website is probably validating certificates before redirecting.

I'm not sure, but I seem to remember seeing some external links in the product descriptions that did have the SSL certificate and still redirected to this site (mql5.com).

Which makes me think that in addition to the SSL there must also be some sort of "whitelist".

I say this with total ignorance, since there is nothing official about this.

 
William Roeder #:

“Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
     How To Ask Questions The Smart Way. (2004)
          When asking about code
          Be precise and informative about your problem

what i meant to say is that, after calling the HistorySelect() prior to the HistoryDealGetTicket() suggested earlier, i still wasn't able to get the 

ClosedOdersCount

to increase instead it continue to print  0

 
Chioma Obunadike #:
HistoryDealGetTicket

Prior to calling HistoryDealGetTicket(), first it is necessary to receive the history of deals and orders using the HistorySelect() or HistorySelectByPosition() function.

Thanks Chioma, i have now called it prior to the iterator and it is now counting as i expected  

Reason: