MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
The Largest Collection of Forex Robots is on Display in MQL 5 Code Base

Number of bars from the last Fractal Up

Back to topics list To post a new topic, please log in or register
avatar
232
Alberto_jazz 2009.10.15 18: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.

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

}

 
FOMC Minutes sends USDJPY to 118
FOMC Minutes sends USDJPY to 118
ForexTime | 20 November 2014, 13:06 | Views: 70
The Dollar/Yen recorded a new seven-year high of 118.058 following the release of the FOMC Minutes which suggested the Federal Reserve will look to begin raising interest rates from the middle of 2015 onwards. The Minutes also indicated FOMC members are discussing whether to remove the “considerable time” phrase from future releases.
avatar
199
Jacques366 2009.10.15 19: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.

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!

 
avatar
232
Alberto_jazz 2009.10.16 00: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);

}

 
avatar
199
Jacques366 2009.10.16 08: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' ?

 
avatar
232
avatar
199
Jacques366 2009.10.16 13: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 http://docs.mql4.com/constants/timeframes

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


 
avatar
232
Alberto_jazz 2009.10.16 14: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);

}

 
avatar
199
Jacques366 2009.10.16 15: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);
  }

 
avatar
11
fdeguzman 2010.02.02 02: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.

 
avatar
5
xman1363 2010.03.18 21: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.

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

Attached files:
  magid_fractal_control_1.mq4  (2.29 KB)
 
avatar
105
pontuso 2012.10.23 09: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

?? 

Back to topics list  

To add comments, please log in or register