Download MetaTrader 5
To add comments, please log in or register
Publish your article and thousands of people all over the world will read it!
Mimi
499
Mimi 2016.06.02 10:09 

Hi,

How to check number of trades taken on current hour for OP_BUY & OP_SELL.

Including Closed order & open orders?

I got this function code which checks orders are opened under certain time or not. But it doesn't counts how many. 

int FoundRecentOpenedOrder(int TF) {
   int last_order_idx = (OrdersHistoryTotal() - 1);
   if(OrderSelect(last_order_idx,SELECT_BY_POS,MODE_HISTORY))
   {
   if (OrderOpenTime() >= iTime(Symbol(), TF, 1)&& OrderType() == OP_BUY && OrderType()== OP_SELL) {
      return(TRUE);
      }}
      return(FALSE);
      
    }

 Regards

Keith Watford
Moderator
7918
Keith Watford 2016.06.02 10:25  
OrderType() == OP_BUY && OrderType()== OP_SELL

will never be true

Using 1 as the index in the iTime call will include all orders opened in the previous and current bar


int FoundRecentOpenedOrder(int TF) 
  {
   int count=0;
   int last_order_idx=(OrdersHistoryTotal()-1);
   for(;last_order_idx>=0;last_order_idx--)
      if(OrderSelect(last_order_idx,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderOpenTime()>=iTime(Symbol(),TF,1) && (OrderType()==OP_BUY || OrderType()==OP_SELL)) 
           {
            count++;
           }
        }
   return(count);

  }
Keith Watford
Moderator
7918
Keith Watford 2016.06.02 10:27  

You will also have to count the open orders

Mimi
499
Mimi 2016.06.03 04:09  
GumRai:

You will also have to count the open orders


How can I count the open orders then is there any example code structure?
Fernando Carreiro
1479
Fernando Carreiro 2016.06.03 05:03  
cashcube:
How can I count the open orders then is there any example code structure?

"GumRai" has already answered that and even gave you the example code for it!

However, I do have a question for you - do you have any coding experience at all? A "loop" and "counting" is one of the most basic things one has to learn for coding.

If you have no experience in coding or even just a little, then I suggest you first learn some basic skills in common languages like "C", "C++" or even "Java" before you attempt to even code an EA which is highly complex. There are plenty of resources on the Internet to help you out, including many tutorials and videos.

Mimi
499
Mimi 2016.06.03 11:21  
FMIC:

"GumRai" has already answered that and even gave you the example code for it!

However, I do have a question for you - do you have any coding experience at all? A "loop" and "counting" is one of the most basic things one has to learn for coding.

If you have no experience in coding or even just a little, then I suggest you first learn some basic skills in common languages like "C", "C++" or even "Java" before you attempt to even code an EA which is highly complex. There are plenty of resources on the Internet to help you out, including many tutorials and videos.

Pardon please,

I missed the coding post. That's why this misunderstanding.

Thank you both of you. Its working now. 

PS: I posted the base code. I know C, C++, but yes loop advise excepted.

/
To add comments, please log in or register