Number of bars from the last Fractal Up

Have you developed an application? Publish it in Code Base!
481
2009.10.15 16:41

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.

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

}

299
2009.10.15 17:14
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.

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!

481
2009.10.15 22:15

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

}

299
2009.10.16 06:39
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' ?

481
2009.10.16 08:08
If I copy this code in an expert file, Print function return 0.
299
2009.10.16 11:33
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.

481
2009.10.16 12:54

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

}

299
2009.10.16 13:26
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);
}```
35
2010.02.02 01:04

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.

10
2010.03.18 20:36
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.

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

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

Files:
376
2012.10.23 07:44
```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

??

/