What does your post have to do with arrays?
What does your post have to do with arrays?
Here what I want to get:
the Minimum value from some external variables as in the first post, excluding the empty fields.
It could be something like this: A = 1.354; B = 3.762; C = 0.0; D = 0.0
So MinValue should return 1.354 instead of 0.0..
Any idea? I know it’s pretty basic but I need your help! Thanks in advance..
Here what I want to get:
the Minimum value from some external variables as in the first post, excluding the empty fields.
It could be something like this: A = 1.354; B = 3.762; C = 0.0; D = 0.0
So MinValue should return 1.354 instead of 0.0..
Any idea? I know it’s pretty basic but I need your help! Thanks in advance..
All the time you comapre to 0 you will have a problem so you need to iterate through the values and only do the comparison if the variable is not 0.
example attached, could be done more more efficiently if the values to be checked were stored in an array.
void OnStart() { double A = 1.123; double B = 0.0; double C = 0.001; double D = 1.1; double MinValue = 999999999.00; if(A != 0 && A < MinValue) MinValue = A; if(B != 0 && B < MinValue) MinValue = B; if(C != 0 && C < MinValue) MinValue = C; if(D != 0 && D < MinValue) MinValue = D; if(MinValue == 999999999.00) Print("No value found"); else Print("MinValue = " + MinValue); }
All the time you comapre to 0 you will have a problem so you need to iterate through the values and only do the comparison if the variable is not 0.
example attached, could be done more more efficiently if the values to be checked were stored in an array.
bool condition = true; //MaxValue;
Thanks for your help Paul, very kindly on you! The problem is that I have to calculate from the same values to be checked the “Max Value” as well!
just reuse the code I gave you and change it for Max Value
just reuse the code I gave you and change it for Max Value
I was thinking about a few lines of code less but that’s enough which make it easy to adapt for exacting application requirements. Thanks so much, I really appreciate it!!
I wouldn't worry about a few lines of code it won't slow your program down relatively
int TestArray() { int Arr[] = {1000,18,500,315,0,365}; int x = INT_MAX; for(int i = ArraySize(Arr)-1; i >= 0; --i) { if(Arr[i]>0 && Arr[i]<x) x = Arr[i]; } return x; }
should return 18
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use