Download MetaTrader 5

Need Help on this?

To add comments, please log in or register
Sherif Hasan
7310
Sherif Hasan  

Hi!

I have written EA using 2 strategy. first strategy i use 30 minutes and 2nd strategy i use 4hrs and for JPY pairs.

I run EA with 30min tf. for second strategy i used BB indicator at 4hr timeframe and once per bar.

I validate the below conditions once per bar. problom is EA check every 30 minute candle, bcoz i run ea by 30m timeframe. how to make this ea to run second strategy with 4hr timeframe. please give me support.

  if (Close[2] > iBands(NULL, PERIOD_H4,20,2.0,0,PRICE_CLOSE,MODE_UPPER,2))
Simon Gniadkowski
Moderator
18018
Simon Gniadkowski  
sheriffonline:

Hi!

I have written EA using 2 strategy. first strategy i use 30 minutes and 2nd strategy i use 4hrs and for JPY pairs.

I run EA with 30min tf. for second strategy i used BB indicator at 4hr timeframe and once per bar.

I validate the below conditions once per bar. problom is EA check every 30 minute candle, bcoz i run ea by 30m timeframe. how to make this ea to run second strategy with 4hr timeframe. please give me support.

How do you do this ? do the same but for the H4 timeframe . . .
Tjipke de Vries
6339
Tjipke de Vries  
sheriffonline:

Hi!

I have written EA using 2 strategy. first strategy i use 30 minutes and 2nd strategy i use 4hrs and for JPY pairs.

I run EA with 30min tf. for second strategy i used BB indicator at 4hr timeframe and once per bar.

I validate the below conditions once per bar. problom is EA check every 30 minute candle, bcoz i run ea by 30m timeframe. how to make this ea to run second strategy with 4hr timeframe. please give me support.

  if (Close[2] > iBands(NULL, PERIOD_H4,20,2.0,0,PRICE_CLOSE,MODE_UPPER,2)) 

Close[2] is a value from your 30M chart

do you want that value or is it you needed a value from bar2 H4 chart to compare ??

if you check first the time candle 0 H4 and you check newbar according to that candletime ....

Alain Verleyen
Moderator
31599
Alain Verleyen  
sheriffonline:

Hi!

I have written EA using 2 strategy. first strategy i use 30 minutes and 2nd strategy i use 4hrs and for JPY pairs.

I run EA with 30min tf. for second strategy i used BB indicator at 4hr timeframe and once per bar.

I validate the below conditions once per bar. problom is EA check every 30 minute candle, bcoz i run ea by 30m timeframe. how to make this ea to run second strategy with 4hr timeframe. please give me support.

How do you check "once per bar" ?
Sherif Hasan
7310
Sherif Hasan  
   datetime Bartime; 
   if (BarTime < Time[0])
{
    // we have a new bar opened
    BarTime = Time[0]; // keep the new bar open time

}
Sherif Hasan
7310
Sherif Hasan  
deVries:

Close[2] is a value from your 30M chart

do you want that value or is it you needed a value from bar2 H4 chart to compare ??

if you check first the time candle 0 H4 and you check newbar according to that candletime ....

Yes.currently it takes value value of Close[2] at 30m tf. but i need to take value Close[2] for 4hr tf applying 30m chart.
Sherif Hasan
7310
Sherif Hasan  
RaptorUK:
How do you do this ? do the same but for the H4 timeframe . . .


   datetime Bartime; 
   if (BarTime < Time[0])
{
    // we have a new bar opened
    BarTime = Time[0]; // keep the new bar open time

}
Alain Verleyen
Moderator
31599
Alain Verleyen  
sheriffonline:

So if you want your condition about H4 to be run only once per H4 bar, you have to use anothor method. What you post here only detect a new bar on current chart. Use iTime() instead of Time[].

whroeder1
15051
whroeder1  
   datetime Bartime; 
   if (BarTime < Time[0]){ BarTime = Time[0]; // keep the new bar open time
     :
   }
Won't work. as Bartime will ALWAYS be zero. Code runs every tick. Search once per bar and learn the difference.
Sherif Hasan
7310
Sherif Hasan  
angevoyageur:

So if you want your condition about H4 to be run only once per H4 bar, you have to use anothor method. What you post here only detect a new bar on current chart. Use iTime() instead of Time[].


Changed code changing iTime(). works fine now.

Thanks for your support angevoyageur,RaptorUK,WHRoeder



datetime Bartime;
if (BarTime < iTime(NULL,PERIOD_H4,0))
{
    // we have a new bar opened
    BarTime = iTime(NULL,PERIOD_H4,0); // keep the new bar open time
    
}


if (iClose(NULL,PERID_H4,2) > iBands(NULL, PERIOD_H4,20,2.0,0,PRICE_CLOSE,MODE_UPPER,2))
whroeder1
15051
whroeder1  
Are you hard of reading? Won't work as Bartime will ALWAYS be zero. Code runs every tick. Search once per bar and learn the difference.
12
To add comments, please log in or register