You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
dr.Rez:
and I did not understand this :
That code just count the number of times a value is present in the given array, which is basically the same "functionality" of the logical OR that you used. However, in your case, you don't need to count the value occurrences, but you just need to know if the value is present or not in the array. So, you can just stop as soon as the value is found, like this:
This is equivalent to do the logical OR. However, this requires to define a new array each time for every condition to be checked, which is not convenient. It may have sense to use it if you have to check that condition for many many times and the condition is very long (for example, you have to compare your value to 10 numbers), so you can create a function like this to easily perform the operation:
So the previous code will become:
Of course you can also just create a "stupid" function like:
Which does the same thing, but using the previous approach you can write a shorter and less error-prone function in case there are lots of values to be compared (imagine if you have to compare the value to 10 different numbers).
I hope it'll be useful for you.
There is count in the C++ template library but no equivalent of present.
There is count in the C++ template library but no equivalent of present.
Yes of course but, by stopping immediately, you will save some useless loop cycles since there is no need to continue if the value has been found. However, I agree that, with small arrays like those ones, this is completely negligible.
The standard C++ libray does check for presence. It has the std::find function that checks for presence in a generic container and stops immediately if it is found, returning its position (iterator). It's similar to what I did, with the difference that I've just returned true or false instead of the position, basically in C++ it'll be like this:
return (std::find(vector.begin(), vector.end(), value) != vector.end());
But for the usage described by the topic author the position was not needed, so I didn't return it.
Anyway, it's just a little different approach for doing the same thing :-)
That's probably because you are no mind reader either.
Thank you Marco
you have always helped me .
Thank you whroeder1
My English is not good and I read,write and understand it with a little difficulty.
and also I am beginner in mql.
when you told me "There is no mind readers here", I didn't understand you were talking about the way I asked my question .
by the way , thank you for your help.
You can also use a string. It's much more easy, but you'll get to worry about var conversion.