Download MetaTrader 5

Is this use of if correct?

To add comments, please log in or register
Neal_Van
355
Neal_Van  
if(Buffer[2-5]>=var1){Print("buffers greater than var1");}
because for some reason it compiles but doesn't yield a print.

*i'm trying to compare the values of 3 bars back through 6 bars back.
Carl Schreiber
Moderator
7962
Carl Schreiber  
No!

This:
Buffer[2-5]
will end up in

Buffer[-3]
and cause a crash of what ever it is (EA, indi., script).

You have to check the array item by item:

for(int i=2;i<=5;i++){ ... } // not tested!
whroeder1
17116
whroeder1  
Buffer[0] is the current candle, Buffer[1] is one back. Buffer[-3] is the future, and trying to access the future results in a singularity, reality destroyed, end of life, etc. Pray that all you get is your code crashes.
To add comments, please log in or register