Close[1] - How to make that applicable to different time frame?

 

Hey All :)

New quicker question this time! How can I tell "Close[1]" to be focusing on the 4 hour time frame, irrespective of the time frame I am currently looking at?

Close[1] > Hour4_60 // EMA -//- I want that Close[1] to be the close of a 4 hour bar?

Many thanks as usual!

 

Use iClose().

double H4_close_price = 0;
H4_close_price = iClose(NULL, PERIOD_H4, 1);
 
So like this?
double H4_close_price = 0;
H4_close_price = iClose(NULL, PERIOD_H4, 1);
if(Close[H4_close_price] > Hour4_60);
 
DomGilberto:
So like this?
if(Close[H4_close_price] > Hour4_60);
no, ......... H4_close_price can't used this way it is not integer
 

I assume Hour4_60 represents a price, correct?

If so, your code would look like:

double H4_close_price = 0;
H4_close_price = iClose(NULL, PERIOD_H4, 1);  // <---this gives you the close price of the previous 4-hour bar
if (H4_close_price > Hour4_60) {              // <---this is true when H4_close_price is greater than Hour4_60
   // do something
}
 
double H4_close_price = 0;
H4_close_price = iClose(NULL, PERIOD_H4, 1);
Whats the purpose of "double H4_Close_Price = 0"?

Why could I not just do "double H4_close_price = iClose(NULL, PERIOD_H4, 1);" ?
 
DomGilberto:
Whats the purpose of "double H4_Close_Price = 0"?

Why could I not just do "double H4_close_price = iClose(NULL, PERIOD_H4, 1);" ?
Some people ( like me ) prefer to declare their variables in one place at the start of the function and in some cases explicitly set the initial value. It's mostly, but not completely, personal preference.
 
Ok thanks for your help again guys :)