What I would like to do is to run RHistoryQuery get the results from callback event OnImage and pass it to AdInterp function. Is it possible to loop the following steps for different Instrument lists (for the Rhistory) and retrieve only the results from the Adinterp?
Yes, it's possible and there's more than one way of doing it.
First of all you can retrieve multiple instruments in a single request, just like you can with RHistory worksheet function.
Then, if for whatever reason you need to retrieve your instruments one by one, you can do this by introducing a module level counter. You will need to initialize it and call the data requesting procedure for the first instrument in the list. In the OnImage event handler you can apply AdInterp function and output the result. Then you can increment the counter, check if the counter is still in range for your list of instruments, and if yes call the requesting procedure for the next instrument from the list. This process will break if there are any invalid instruments in the list. To handle it you'll also need to implement the same logic in the OnError event handler.
Finally, you can create an instance of RHistoryQuery object per instrument, and place all these objects into a collection, so they remain in memory while the data is being retrieved. In this case to manage the event handling you will need to create a custom class.
These are your options.
Thank you Alex! I need to interpolate a spread for a list of instruments, hence asking for the Rhistory loop. By the way, do you happen to have an example of the module level counter...it would definitely save me some time.
I cannot say I understand why you prefer retrieving timeseries one instrument at a time over retrieving them all at once, which will be faster. Once you've retrieved the timeseries you can apply whatever analytics you want to the data you retrieved. Whatever you rationale, attached is an example of doing both: retrieving the list of instruments in one request and retrieving the list in a loop one instrument at a time. I hope you find it useful.