# need help with an atr variable

235

I know that if I am looking at a daily or weekly or whichever time frame and I want the ATR of the 1HR chart, I can use:

`double ATR_V2= iATR(NULL,PERIOD_H1,period,shift);`

But what if I want the ATR of whichever time period I am looking at from 2 periods earlier?  i.e. if I am viewing the Daily chart, it will give me a 1HR ATR.  But if I am viewing a weekly chart, I will be looking at the 4HR ATR?

154803

rajakesar:

I know that if I am looking at a daily or weekly or whichever time frame and I want the ATR of the 1HR chart, I can use:

But what if I want the ATR of whichever time period I am looking at from 2 periods earlier?  i.e. if I am viewing the Daily chart, it will give me a 1HR ATR.  But if I am viewing a weekly chart, I will be looking at the 4HR ATR?

You should use a period converter function to implement this in ATR

```int PeriodConvert (ENUM_TIMEFRAMES etf)
{
int tconvert;
switch (etf)
{
case 1:   tconvert  = 1;   break;
case 5:   tconvert  = 1;   break;
case 15:   tconvert  = 1;   break;
case 30:   tconvert  = 5;   break;
case 60:   tconvert  = 15;   break;
case 240:   tconvert  = 30;   break;
case 1440:   tconvert  = 60;   break;
case 10080:   tconvert  = 240;   break;
case 43200:   tconvert  = 1440;   break;
}
return(tconvert);
}```