Download MetaTrader 5

Help on finding the bigest of last 10 bars

To add comments, please log in or register
gbenga Ayodele
222
gbenga Ayodele  
Please I need help on mql4 code for finding the biggest of 10 last bars just like iHighest() fuction
Marco vd Heijden
Moderator
4957
Marco vd Heijden  
int highest_bar;

if(High[9]>High[10]){highest_bar=9;)
if(High[8]>High[9]) {highest_bar=8;)
if(High[7]>High[8]) {highest_bar=7;)
if(High[6]>High[7]) {highest_bar=6;)
if(High[5]>High[6]) {highest_bar=5;)
if(High[4]>High[5]) {highest_bar=4;)
if(High[3]>High[4]) {highest_bar=3;)
if(High[2]>High[3]) {highest_bar=2;)
if(High[1]>High[2]) {highest_bar=1;)
if(High[0]>High[1]) {highest_bar=0;)

Print(" Highest Bar: ",highest_bar);
gbenga Ayodele
222
gbenga Ayodele  

I want the biggest bar among the 10 not the highest bar.

ForexTrader17
1041
ForexTrader17  
Use support and resistance levels. Like if high of last bar is > highest high of last 10 bars and low of last bar is < lowest low of last 10 bars.
Stuart Browne
6037
Stuart Browne  
gbenga Ayodele:

I want the biggest bar among the 10 not the highest bar.

If you want the bar with the biggest range, regardless if it's up or down candle, try this:

 

int iLargestBar=fnLargestBar();

int fnLargestBar()
{
   double dBiggestRange=0.0, dThisBarRange=0.0;
   int iMyLargestBar=-1;
   
   for(int i=0;i<10;i++)
   {
      dThisBarRange=MathAbs(High[i]-Low[i]);
      if ( dThisBarRange > dBiggestRange )
      {
         dBiggestRange=dThisBarRange;
         iMyLargestBar=i;
      }
   }
   return(iMyLargestBar);
}

This assumes you want the current [0] bar and the last 9 bars. If you want the 10 bars prior to the current bar, change the for loop to this:

 

for(int i=1;i<=10;i++)
Marco vd Heijden
Moderator
4957
Marco vd Heijden  
gbenga Ayodele:

I want the biggest bar among the 10 not the highest bar.

Obviously then it will be High-Low.
To add comments, please log in or register