Hourly ATR and hourly change

Hi,,,
I've tried to get hourly ATR and hourly change in price in my exploration window while the stock market is live with IQFEED intra-day data - however the following code just showed the same data as daily EOD..not sure what i am missing here - pls help:

dailyATR = ATR(14);
TimeFrameSet(inWeekly);
weeklyATR = ATR(14);
TimeFrameRestore();
TimeFrameSet(inMonthly);
monthlyATR = ATR(5);
TimeFrameRestore();
TimeFrameSet(inQuarterly);
quarterlyATR = ATR(5);
TimeFrameRestore();
TimeFrameSet(inYearly);
yearlyATR = ATR(5);
TimeFrameRestore();
TimeFrameSet(inHourly);
hourlyATR = ATR(14);
HChg = ((C - Ref(C,-1))/Ref(C,-1))*100;
TimeFrameRestore();

DChg = ((C - Ref(C,-1))/Ref(C,-1))*100;

Filter=1;
AddColumn(hourlyATR,"DailyATR",4.2);
AddColumn(dailyATR,"DailyATR",4.2);
AddColumn(weeklyATR,"weeklyATR",4.2);
AddColumn(monthlyATR,"monthlyATR",4.2);
AddColumn(quarterlyATR,"quarterlyATR",4.2);
AddColumn(yearlyATR,"yearlyATR",4.2);
AddColumn(HChg,"HourlyChg",4.2);
AddColumn(DChg,"DailyChg",4.2);

All the columns worked except hourly ATR and hourly Change - not sure why?

Thank You,
Satish

@uvdsatish,

dailyATR = ATR(14);
TimeFrameSet(inWeekly);
weeklyATR = ATR(14);
TimeFrameRestore();
TimeFrameSet(inMonthly);
monthlyATR = ATR(5);
TimeFrameRestore();
TimeFrameSet(inQuarterly);
quarterlyATR = ATR(5);
TimeFrameRestore();
TimeFrameSet(inYearly);
yearlyATR = ATR(5);
TimeFrameRestore();
TimeFrameSet(inHourly);
hourlyATR = ATR(14);
HChg = ((C - Ref(C,-1))/Ref(C,-1))*100;
TimeFrameRestore();

DChg = ((C - Ref(C,-1))/Ref(C,-1))*100;

Filter=1;
AddColumn(hourlyATR,"DailyATR",4.2);
AddColumn(dailyATR,"DailyATR",4.2);
AddColumn(weeklyATR,"weeklyATR",4.2);
AddColumn(monthlyATR,"monthlyATR",4.2);
AddColumn(quarterlyATR,"quarterlyATR",4.2);
AddColumn(yearlyATR,"yearlyATR",4.2);
AddColumn(HChg,"HourlyChg",4.2);
AddColumn(DChg,"DailyChg",4.2);

You need to use the TimeFrameExpand function on your compressed arrays (weeklyATR, monthlyATR, etc): https://www.amibroker.com/guide/afl/timeframeexpand.html

Also, your code implies that you're running with Periodicity set to Daily. If this is the case, you can't access hourly bars.

1 Like

Thank you. I think it worked when i added the following code.


wc1 = TimeFrameCompress( Close, inHourly );
wc2 = TimeFrameCompress( High, inHourly );
wc3 = TimeFrameCompress( Low, inHourly );
wc4 = TimeFrameCompress( Open, inHourly );


hourlyATR = ATR(14);
HChg = ((wc1 - Ref(wc1,-1))/Ref(wc1,-1))*100; 
AHChg = ((wc1 - Ref(wc1,-1))/Ref(hourlyATR,0));
HChg = TimeFrameExpand(HChg,inHourly);
hourlyATR = TimeFrameExpand(hourlyATR,inHourly);
AHChg = TimeFrameExpand(AHChg,inHourly);