Simple BOOLEAN FUNCTION HELP - page 2

 

@William Roeder

Actually I was referring to this bit:

   for(int i=Bars-1;i>=1;i=10)
Not this:
High[i] > (iBands(NULL,0,21,2,0,PRICE_CLOSE,MODE_UPPER,i)))
 
Yes, but William is referring to Bars, because it's something different in MT4 compared to MT5.

In MT4 it's a system provided variable. In MT5 it's a function, but no variable is available.

And the usage of iBands is from MT4, therefore referring MT4-code.
 
Dominik Christian Egert #:
Yes, but William is referring to Bars, because it's something different in MT4 compared to MT5.

In MT4 it's a system provided variable. In MT5 it's a function, but no variable is available.

And the usage of iBands is from MT4, therefore referring MT4-code.

I see, so it must be this I guess...

https://docs.mql4.com/predefined/bars

Ok I have nothing to add to this beyond the "return false" statement in my first comment

Bars - Predefined Variables - MQL4 Reference
Bars - Predefined Variables - MQL4 Reference
  • docs.mql4.com
Bars - Predefined Variables - MQL4 Reference
 

As already mentioned by others your "for" cycle is wrong. You need something like this:

for ( int i = Bars - 1; i > 1; i-- )
        ;               //do something
 

After you fixed that for loop you need logical OR:

bool flag=false;

for(...)
{
flag ||= (conditions);
}

That way if the conditions are true for minimum one bar, flag becomes true.

 
VikMorroHun #:

As already mentioned by others your "for" cycle is wrong. You need something like this:

Hi thanks for the reply. Is the loop not counting back across the bars i.e. starting at i and counting through i-- which is every bar on that chart. my thinking was i-- replaced with i=10 would count back until the 10th bar. but I guess its not that simple? then the logic is if the if statement is true across any on those bars then it would return true. if not false?

Thanks anyway it didn't help I posted it in the wrong thread at first it has just confused me further>

 

Loops will work the same way in MQL4 and MQL5.

 
Tobias Johannes Zimmer #:

Loops will work the same way in MQL4 and MQL5.

... when using compiler directive "strict".
else it will declare a variable with scope beyond the for loop.

 
Dominik Christian Egert #:
... when using compiler directive "strict".
else it will declare a variable with scope beyond the for loop.

Oh. What I was trying to say was "Take a look at the reference"
 
Tobias Johannes Zimmer #:
Oh. What I was trying to say was "Take a look at the reference"
The documentation does not state the fact that in expr1 of a for-loop declaration, any declared variable will continue to exist in the enclosing scope where the for-loop itself is declared.

So, I added this as an additional info. MQL4 states syntax be like c/c++, but I don't remember C ever having such behaviour.

So that's, as far as my concerns go, a significant detail why you should be using "strict" in MQL4.



Reason: