Download MetaTrader 5

Need Help on this?

To add comments, please log in or register
How to choose the most appropriate signal and subscribe to it in no time
Sherif Hasan
7290
Sherif Hasan 2013.12.11 05:32 

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
18001
Simon Gniadkowski 2013.12.11 08:55  
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
6316
Tjipke de Vries 2013.12.11 09:03  
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
30744
Alain Verleyen 2013.12.11 11:02  
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
7290
Sherif Hasan 2013.12.11 12:49  
   datetime Bartime; 
   if (BarTime < Time[0])
{
    // we have a new bar opened
    BarTime = Time[0]; // keep the new bar open time

}
Sherif Hasan
7290
Sherif Hasan 2013.12.11 12:52  
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
7290
Sherif Hasan 2013.12.11 12:53  
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
30744
Alain Verleyen 2013.12.11 12:59  
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
14519
whroeder1 2013.12.11 13:34  
   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
7290
Sherif Hasan 2013.12.11 16:34  
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
14519
whroeder1 2013.12.11 17:16  
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