Number of bars from the last Fractal Up

 

Hi, I need an help in writing this indicator, it doesn't work.

I must find the last bar that formed a Fractal Up.

The indicator will return the shift from the present bar, to reach the Fractal bar. For instance, if the Fractal Up is formed 3 bars ago, the indicator will return 3.

Thank you for your help!

int i ;
int j ;
int limit ;


int start()
{
int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(i=limit; i>0; i--)
if (iFractals(NULL,NULL,MODE_UPPER,i)>0)
{
j=i ;
Return(j);
}

}

 
Alberto_jazz:

Hi, I need an help in writing this indicator, it doesn't work.

I must find the last bar that formed a Fractal Up.

The indicator will return the shift from the present bar, to reach the Fractal bar. For instance, if the Fractal Up is formed 3 bars ago, the indicator will return 3.

Thank you for your help!

int i ;
int j ;
int limit ;


int start()
{
int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(i=limit; i>0; i--)
if (iFractals(NULL,NULL,MODE_UPPER,i)>0)
{
j=i ;
Return(j);
}

}

The shift parameter of the Fractal() function is the shift from the current bar, you should start your search from 1 and not from counted_bars!

 

I tried this way but it doesn't work yet...


int start()
{

int i,j ;

for (i=1;i==200;i++)
if (iFractals(NULL,NULL,MODE_UPPER,i)>0)
{
j=i ;
break ;
}

Print(j);

}

 
Alberto_jazz:

I tried this way but it doesn't work yet...


int start()
{

int i,j ;

for (i=1;i==200;i++)
if (iFractals(NULL,NULL,MODE_UPPER,i)>0)
{
j=i ;
break ;
}

Print(j);

}

I think this code should give you the result you're looking for. What do you mean by 'it doesn't work yet' ?

 
If I copy this code in an expert file, Print function return 0.
 
Alberto_jazz:
If I copy this code in an expert file, Print function return 0.

Certainly because your time frame parameter is wrong: null is not allowed : see https://docs.mql4.com/constants/timeframes

You should put 0 if you do not want to specify one.

 

I'm trying the following code, but the expert print 0.

I would expect that the result is the shift to reach the last upper fractal, but it doesn't work...

int start()
{

int i,j ;

for (i=1;i==200;i++)
if (iFractals(NULL,0,MODE_UPPER,i)>0)
{
j=i ;
break ;
}

Print(j);

}

 
Alberto_jazz:

I'm trying the following code, but the expert print 0.

I would expect that the result is the shift to reach the last upper fractal, but it doesn't work...

int start()
{

int i,j ;

for (i=1;i==200;i++)
if (iFractals(NULL,0,MODE_UPPER,i)>0)
{
j=i ;
break ;
}

Print(j);

}

COME ON WAKE UP!

int start()
{

int i,j ;

for (i=1;i==200;i++)

{
if (iFractals(NULL,0,MODE_UPPER,i)>0)
{
j=i ;
break ;
}

}

Print(j);

}

Write properly and this should not occur! 8-b

I mean you can also code that way:

int start() 
  {for (int i=1; i<=200; i++)
       {if (iFractals(NULL,0,MODE_UPPER,i) > 0)
           {break ; 
           }
       }
   Print(i);
  }
 

If my chart is set at M15 timeframe and it has been running for 5 days and I issue this for loop for H4 timeframe:

int start() 
  {for (int i=1; i<=200; i++)
       {if (iFractals(NULL,240,MODE_UPPER,i) > 0)
           {break ; 
           }
       }
   Print(i);
  }

Is the above statement going to give me the latest information.

I am worried that the iFractals do not exist for a timeframe that I haven't brought up on the screen.

The data may still be 5 days old.

Is MetaTrader continously forming the bars for other timeframes even though I do not have them on the screen?

Thank you very much for your response.

 
Alberto_jazz wrote >>

Hi, I need an help in writing this indicator, it doesn't work.

I must find the last bar that formed a Fractal Up.

The indicator will return the shift from the present bar, to reach the Fractal bar. For instance, if the Fractal Up is formed 3 bars ago, the indicator will return 3.

Thank you for your help!

int i ;
int j ;
int limit ;


int start()
{
int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(i=limit; i>0; i--)
if (iFractals(NULL,NULL,MODE_UPPER,i)>0)
{
j=i ;
Return(j);
}

}



int counted_bars= IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
{

f1=iFractals(NULL,0, MODE_HIGH,i)+iFractals(NULL,0,MODE_LOW,i);

//Alert(f1);
msg1=iFractals(NULL,0, MODE_HIGH,i);
msg2=iFractals(NULL,0,MODE_LOW,i);
// you can use program magid_fractal_control.mq4

 
int start() 
  {for (int i=1; i<=200; i++)
       {if (iFractals(NULL,0,MODE_UPPER,i) > 0)
           {break ; 
           }
       }
   Print(i);
  }

  {for (int k=1; k<=200; k++)
       {if (iFractals(NULL,0,MODE_UPPER,k) > 1)
           {break ; 
           }
       }
   Print(k);
  }


  {for (int L=1; L<=200; L++)
       {if (iFractals(NULL,0,MODE_LOWER,L) > 0)
           {break ; 
           }
       }
   Print(L);
  }

  {for (int M=1; M<=200; M++)
       {if (iFractals(NULL,0,MODE_LOWER,M) > 1)
           {break ; 
           }
       }
   Print(M);
  }

Is it possible to write like this if i want the:

-last and the second last fractal up i,k

-last and the second last fractal down L,M

?? 

Reason: