Ref(Foreign("Futures","Close" ),1)

In my exploration, I'd like to read the Ref(C,1) value of a foreign instrument (S&P futures) that has 1 day more EOD data than all other instruments.
Ref(Foreign("Futures","Close" ),1) does not work since all the other instrument doesn't have n+1 data. As per its documentation.
Doing the other way around, i.e. making all other symbols foreign is not possible since it is a lengthy code.
I wonder if there is any workaround solution, for example I could read that particular future close value and store it's value in a txt file and read it with fgets from the file to the afl.

Or is there any better idea?

Read the User's Guide on Foreign function http://www.amibroker.com/f?foreign especially the COMMENT about synchronization. For any meaningful use data must be synchronized and that is what Foreign function does. Also referring to future data (positive offsets in ref()) is bad. Future leak leads to unrealistic results in backtest. You should be doing things the other way round. Instead of referencing future, reference past for other symbols. Use negative references for OTHER symbols instead of positive for this one symbol.

1 Like