What is the purpose for this code? It's very confusing because it looks like the MQL convention used for enum return type.
Why use a separated funtion instead of a nested for loop?
Self documenting code. You asked for a count, an enum is not a count.
Self documenting code. Write general functions when possible. Write once, use many. What do you think symbols.SearchLinear(), symbols.Add(), and symbols.Total() are?
#define INDEX uint// 0 based#define COUNT uint// 1 basedtemplate<typename T>
bool resize_vector(T& vector[], ///<[in,out]The vector.
COUNT nRows) /**<[in]Row count.*/{
returnArrayResize(vector, nRows, extra) >= nRows;
}
/// Adds the given _value_ to the end of the vector.template<typename T>
bool push_back( T& vector[], ///<[in,out] The vector.const T& value, /**<[in] New elements value.*/{
INDEX iEmpty = ArraySize(vector);
bool result = resize_vector(vector, iEmpty + 1);
if(result) vector[iEmpty] = value;
return result;
}
/** 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)
{
string symbol = OrderSymbol();
if(find(symbols, 0, n, symbol) == n){
push_back(symbols, OrderSymbol() ); ++n;
} }
return n;
}
Self documenting code. You asked for a count, an enum is not a count.
Self documenting code. Write general functions when possible. Write once, use many. What do you think symbols.SearchLinear(), symbols.Add(), and symbols.Total() are?
Thank you for taking the time with your explanations. I'm still confused why you are adding extra layers of complexity by redefining the data-types. The variable name itself should be the self-documenting component, no?
int count;
versus
COUNT count;
why?
It seems both redundant and confusing... programmer has to remember that "COUNT" is really an "int". I'm still trying to understand what is benefit? It only looks like extra layers of complexity to me and no benefits. I'm sorry for my bad English. I hope that made sense.
The best way I do it is by starting with an empty array of symbols and each time I find the symbol in the array of symbols tab, I add the new one after the loop, and the answer is in the size of the array.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Thank you for taking the time with your explanations. I'm still confused why you are adding extra layers of complexity by redefining the data-types. The variable name itself should be the self-documenting component, no?
int count;versus
why?
It seems both redundant and confusing... programmer has to remember that "COUNT" is really an "int". I'm still trying to understand what is benefit? It only looks like extra layers of complexity to me and no benefits. I'm sorry for my bad English. I hope that made sense.
That won't work.
If the loop finds GBPUSD,EURUSD,GBPUSD it will count 3 instead of 2.
In this way it can works.
In this way it can works.
In this way it can works.
Just fixed a little mistake .
Thanks