# Assistance requested: Determining the biggest range in previous 50 bars in 5 minute chart

49

Hi, im having a small problem with developing a code to determine the ‘x’ value which is the index of the bar on the 5 minute chart with a range of 50 pips or more  between bar 1 and bar 8640. The Code keeps on returning a value of 1 even when the range of the bar with an index of 1 is less than 50 pips and even worse, the index of bar is supposed to be greater than 50. Please assist with any advice.

```bool IdentifyBigBar()

//  Code for preventing High volatility
{
int  x;
for( x=1;x<=8640; x++)
{
if ( (iHigh(NULL, PERIOD_M5, x) - iLow(NULL, PERIOD_M5, x) > 50*PipValue*Point)&&(x>50) )
break;
Print("Index of the bar is",x);
return(true);

}
}
```
272

N22:

Hi, im having a small problem with developing a code to determine the ‘x’ value which is the index of the bar on the 5 minute chart with a range of 50 pips or more  between bar 1 and bar 8640. The Code keeps on returning a value of 1 even when the range of the bar with an index of 1 is less than 50 pips and even worse, the index of bar is supposed to be greater than 50. Please assist with any advice.

have a think about what   &&(x>50)  is doing

49

Hi rod178, '&&(x>50)'  is ensuring or supposed to ensure that my x value is greater than 50. I went on and tested what happens when I only have if (x>=50)  the code still returns a value of x=1 which doesn't make sense.
```bool IdentifyBigBar()

//  Code for preventing High volatility
{
int  x;
for( x=1;x<=8640; x++)
{
if ( (iHigh(NULL, PERIOD_M5, x) - iLow(NULL, PERIOD_M5, x) > 50*PipValue*Point)&&(x>=50) )
break;
Print("Index of the bar is",x);
return(true);

}
}```
157

What do you expect. You get exactly what you coded. x will never exeed 1.

Maybe you have to use "continue" and not "break" ?

16076

Maybe you should break out the loop and then print the result.
272

N22:
Hi rod178, '&&(x>50)'  is ensuring or supposed to ensure that my x value is greater than 50. I went on and tested what happens when I only have if (x>=50)  the code still returns a value of x=1 which doesn't make sense.

x is a bar count, not a pip value, hence the result, as eddie stated above, and the reason I gave u the 'tip' to look at x.

Additionally, you should start using meaningful variable names .