Skip to content

Commit

Permalink
Add count() mothod to OrderPoolMatcher; update README example to us…
Browse files Browse the repository at this point in the history
…e foreachorder
  • Loading branch information
dingmaotu committed Jun 22, 2018
1 parent 649f098 commit af8e050
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,12 @@ Here is a simple example:
// for simplicity, I will not use the Lang/Script class
void OnStart()
{
TradingPool pool;
LinkedList<Order*> list;
int total= pool.total();
for(int i=0; i<total; i++)
TradingPool pool;
foreachorder(pool)
{
if(Order::Select(i))
{
OrderPrint(); // to compare with Order.toString
list.push(new Order());
}
}
PrintFormat("There are %d orders. ",list.size());
Expand All @@ -574,7 +570,6 @@ void OnStart()
//--- foreachv macro: declare element varaible o in the second parameter
foreachv(Order*,o,list)
Print(o.toString());
}
//+------------------------------------------------------------------+
```
Expand Down
15 changes: 15 additions & 0 deletions Trade/OrderPool.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ private:
public:
OrderPoolMatcher(const OrderMatcher *m):m_om(m){}
virtual bool matches() const {return m_om?m_om.matches():true;}

//--- count the number of orders that satisfies the matcher condition
//--- generally you don't want to use this method unless all you want is the number of satisfying orders
//--- use foreachorder for iteration. The select(int) method does not work with count()
int count() const
{
int total=total();
int c=0;
for(int i=0; i<total; i++)
{
// we use matches here instead of m_om.matches because the matches method may be overidden by child classes
if(select(i) && matches()) c++;
}
return c;
}
};
//+------------------------------------------------------------------+
//| The pool of orders from the Terminal order history tab |
Expand Down

0 comments on commit af8e050

Please sign in to comment.