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

Back to topics list To post a new topic, please log in or register
avatar
15
N22 2016.07.22 08: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);


  }
}
avatar
164
rod178 2016.07.22 11: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

 

 

avatar
15
N22 2016.07.22 17: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);
 
    
  }
}
avatar
108
eddie 2016.07.22 20: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" ?


avatar
13006
WHRoeder 2016.07.22 22:39 #
 
Maybe you should break out the loop and then print the result.
avatar
164
rod178 2016.07.23 04: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 .

Back to topics list  

To add comments, please log in or register