Time compression of Foreign from Day to Hour

I'm using this http://www.amibroker.com/kb/2014/10/20/foreign-timeframeset/ as a template which pulls weekly into daily.

In my case though the data (and the database) is hourly with the Foreign symbol having daily bars, so daily to hourly. The foreign symbol in the db shows EOD in the EOD column in the Quote Editor. Also the db is set to allow mixed EOD/Intraday.

Running an exploration with the period set to hourly provides no data for the foreign symbol, it's MA or the index. I do get data when the period is set to daily but this is no good of course. I need to operate against hourly bars.

This is the article code modified only for the symbol name and time frame period (inDaily instead of inWeekly).

indexClose = Foreign("^CMBI10_day","C");
indexWeeklyClose2 = TimeFrameCompress( indexClose, inDaily );
indexWeeklyMA2 = MA( indexWeeklyClose2, 52 );
indexWeeklyFilter2 = indexWeeklyClose2 > indexWeeklyMA2;
//
Filter = 1;
AddColumn( Close, "Close AAPL" );
AddColumn( TimeFrameExpand( indexWeeklyClose2, inDaily ), "Weekly close ^GSPC" );
AddColumn( TimeFrameExpand( indexWeeklyMA2, inDaily ), "Weekly MA ^GSPC" );
AddColumn( TimeFrameExpand( indexWeeklyFilter2, inDaily ), "Weekly index filter", 1 );

The article seems simply enough but I'm just not getting a result.

@DingoCC , if the data you have for the foreign symbol is EOD or Daily, how do you expect to get hourly data from it? If hourly data is not their, you can not retrieve it.

You can only build UP.... i.e. from tick to minute to hour to day to week....

You can't build down, as you have no way of knowing how the smaller time happened within the larger time. If you have EOD data, you can't tell if the 3rd hour of the day was near the Open, High, Low, or close of the Day, it could cover all of them or been somewhere in between.

@snoopy.pa30 thanks for the reply.

The linked article shows weekly pulled down to daily. The weekly value, in this case, an index up/down flag is available for each day to process. The second article image clearly shows weekly pulled down to daily. Just like the article, I expect for my code that the daily value will be pulled downed to hourly. The daily value would be the same value for every hour of the day.

@DingoCC

Again, it depends on if you have the data in your database. If you have hourly data for stock A, you can access it. If you have Stock B that is Daily data only (EOD), then there is NO WAY for Amibroker to give you hourly values.

You need data in a lower time frame to build a longer time frame. You can't build Daily data from Weekly data. Similarily, you can build Daily data from Hourly, but you can't build Hourly from Daily.

@snoopy.pa30 In plain English the linked article contains the basis for this: Calculate the moving average for ^GSPC using the weekly value. If the Close is above the MA then set a filter value of 1. There is one filter value per week, either 1 or 0. The daily stocks are not using ^GSPC, they are using the filter value of 1 or 0. There is no creation of daily values from weekly values and I get that that is not possible, and it is not what I am trying to do.

Thanks for responding. I'll create a support call.

Just think about, with TimeFrameCompress above you order Amibroker to compress from hour to daily, but guess what ?
The symbol CMBI10_day does not have hourly data, so how can AB do the compression ?
What you want to do is access EOD data from hourly not TimeFrameCompress

@DingoCC I believe you are misinterpreting the article. The implication you are arriving at is that there is no available daily data for the symbol ^GSPC in the article. But that is not the my interpretation. The article is illustrating how you can use a different symbol from the same database " so we can implement strategies where rules are based on multiple symbols." In the example a long term market regime filter based upon a commonly used 52 week moving average.

You are interpreting the article to mean that there is ONLY WEEKLY data available in that users database for the symbol ^GSPC. IMHO that is where your confusion arises. The article does not state there is only weekly data, the article states "retrieve data of another symbol from the database" and they are creating a weekly moving average from their DAILY ^GSPC data.

From that article:

  1. compress data into higher interval with TimeFrameSet
  2. store the weekly values / conditions in custom variables
  3. with TimeFrameRestore() or RestorePriceArrays() functions restore the original arrays of the tested symbol (in the original time-frame)
1 Like

I see now how I misunderstood the article. Thanks for setting me straight.

With a base time of 1hr I can now return the EOD with this:

 TimeFrameSet(inDaily);
 indexClose 	= Foreign("^CMBI10_day","Close");
 indexMA 		= MA( indexClose, 10 );
 TimeFrameRestore();

However the returned value is off-set by one day. The prior days value is returned. 2021-11-16 18_05_23-Greenshot image editor

I can use Ref to fix it. AddColumn(Ref(indexClose,24),"indexClose",1.3,colorDefault,colorDefault,100);

But I'd rather know why the misalignment is occurring?

1 Like

You are doing it wrong. If you mix TimeFrame functions with Foreign you MUST OBEY specific order of calls, namely FIRST you have to call Foreign / SetForeign and THEN you can call TimeFrame functions.

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.