Download MetaTrader 5
To add comments, please log in or register
Improve your rating. Execute orders in Freelance service!
N22ko
49
N22ko 2016.07.22 06:35 

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.Image 1

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);


  }
}
rod178
276
rod178 2016.07.22 09:41  
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

N22ko
49
N22ko 2016.07.22 15:26  
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);
 
    
  }
}
peter.MT4Web
158
peter.MT4Web 2016.07.22 18:41  

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

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

whroeder1
13610
whroeder1 2016.07.22 20:39  
Maybe you should break out the loop and then print the result.
rod178
276
rod178 2016.07.23 02:51  
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 .

/
To add comments, please log in or register