How to catch the same point on different TFs

 

Hello! I have a point on H4 TF and want to catch that point on other TFs as well. When I write:

240 * j / Period()

where j is the order of the point on H4 TF (e.g. if it is the current bar j = 0, for the previous bar j = 1, etc.) I obtain the correct results fot D1, H4 itself, H1, M30, M15, but not for M5 and M1.

Can you help? Thanks

 

There are not always 48 M5 bars or 240 M1 bars during the span of an H4 bar. Particularly when there may be a short Sunday candle on a broker's platform.

You should use time to locate the bar that you want

 
Thanks GumRai for your answer. So I should not adjust the location by order of bars and use the Time? Did I get you point correctly?
 

Yes, get the open time of the H4 candle, that will be a datetime variable, use Time[] or iTime()

Then use iBarShift in the other time-frames to find the bar's index position.

 

Thanks. I use:

int index = iBarShift(NULL, 0, Time[j]);
but the trouble is that it returns 55 for all the TFs Im on. For For H4 this is correct since the Time[j] is calculated for H4 but when Im on H1, D1, M30, M15 it gives me 55. What should I be missing?
 
mkheidzedavid:

Thanks. I use:

but the trouble is that it returns 55 for all the TFs Im on. For For H4 this is correct since the Time[j] is calculated for H4 but when Im on H1, D1, M30, M15 it gives me 55. What should I be missing?


That will simply return whatever the value of j is, so I guess that you are looking for bar index 55 on the H4 chart.

If you are calculating the value of j on the H4 chart and then switching timeframes, the chances are that the value of j will be recalculated according to the current chart.

 

You need to do it something like this

int j = 55; //or whatever bar you are interested in th H4 tf
datetime i=iTime(NULL,PERIOD_H4,j);
int index = iBarShift(NULL, 0, i);
 
GumRai:

You need to do it something like this

Or even better/clearer . . .

int SourceBarNumber = 55; //or whatever bar you are interested in th H4 tf

int SourcePeriod = PERIOD_H4;
int TargetPeriod = PERIOD_M5;

datetime TargetTime = iTime(NULL, SourcePeriod, SourceBarNumber);
int TargetBarNum = iBarShift(NULL, TargetPeriod, TargetTime);

Print("Bar ", SourceBarNumber, " on period ", SourcePeriod, " is bar ", TargetBarNum, " on period ", TargetPeriod);
Reason: