For each order, find the symbol in your array of symbols. If you don't find it, it's a new symbol, add it to the array.
After the loop, the answer is the size of the array.
Thus
#define INDEX uint// 0 based#define COUNT uint// 1 based/** Linear search an _array_ for a specific _value_. @returns INDEX
* of the first element found with _value_ or _end_ if not found. */template<typename Ti1, typename Ti2>
INDEX find(const Ti1& inp[], INDEX iBeg, INDEX iEnd,
const Ti2& value){
while(iBeg != iEnd && !(inp[iBeg] == value) ) ++iBeg;
return iBeg;
}
COUNT count_open_symbols(void){
string symbols[]; COUNT n=0;
for(int iPos=OrdersTotal()-1; iPos >= 0; --iPos)
if(OrderSelect(iPos, SELECT_BY_POS)
&& find(symbols, 0, n) == n){
ArrayResize(symbols, n+1);
symbols[n] = OrderSymbol();
++n;
} }
return n;
}
For each order, find the symbol in your array of symbols. If you don't find it, it's a new symbol, add it to the array.
After the loop, the answer is the size of the array.
Thus
Hello Mr Whroeder,
Thanks for all you do, and thank you for sharing your code snippet. Unfortunately I'm not able to compile your example (4 errors). Also, I do have some questions for which I hoped you could provide some clarity. First, would you mind explaining the difference between your method and the one that nicholishen proposed? It seems easier to me to use CArrayString in this context. Is there a material difference in your code?
I'm very confused with some patterns in your example. Would you mind sharing your explanation?
#define INDEX uint// 0 based#define COUNT uint// 1 based/** Linear search an _array_ for a specific _value_. @returns INDEX
* of the first element found with _value_ or _end_ if not found. */template <typename Ti1, typename Ti2>
INDEX find(const Ti1 &inp[], INDEX iBeg, INDEX iEnd, const Ti2 &value)
{
while (iBeg != iEnd && !(inp[iBeg] == value))
++iBeg;
return iBeg;
}
COUNT count_open_symbols(void)
{
string symbols[];
COUNT n = 0;
for (int iPos = OrdersTotal() - 1; iPos >= 0; --iPos)
{
if (OrderSelect(iPos, SELECT_BY_POS) && find(symbols, 0, n) == n)
{
ArrayResize(symbols, n + 1);
symbols[n] = OrderSymbol();
++n;
}
}
return n;
}
What is the purpose for this code? It's very confusing because it looks like the MQL convention used for enum return type.
#define INDEX uint// 0 based#define COUNT uint// 1 based
2. Why use a separated funtion instead of a nested for loop?
negligible
My example is wrong.
My example is wrong.
ArraySort return false for string[].
ArraySort return false for string[].
Yup... just use the Set collection.. it's easy and fast.
Forum on trading, automated trading systems and testing trading strategies
How to count how many currency pair(s) running with active order(s)
nicholishen, 2018.02.05 21:46
Alternative (not for string[])
Alternative (not for string[])
Alternative(any data-type)
There is no such positions total in MT4.
Simplify your condition: i <= n-1 is the same as i < n.
Sorry,i thought i was in mt5 session.
The easiest way is to use a set collection....
Thank you very much. its works nicely!
The Easy and fast was what I stated in #1
The Easy and fast was what I stated in #1
Hello Mr Whroeder,
Thanks for all you do, and thank you for sharing your code snippet. Unfortunately I'm not able to compile your example (4 errors). Also, I do have some questions for which I hoped you could provide some clarity. First, would you mind explaining the difference between your method and the one that nicholishen proposed? It seems easier to me to use CArrayString in this context. Is there a material difference in your code?
This is my adaptation of nicholishen's example~
I'm very confused with some patterns in your example. Would you mind sharing your explanation?
2. Why use a separated funtion instead of a nested for loop?
Best regards,
SB