First, I want to thank you for all the help here in this great forum. And thanks to Tomasz for great resources.
Below is what was described in the Amibroker manual for interacting with TWS:
As for "automatic backfill on first data access" - when it is checked AmiBroker attempts to backfill symbol when you display a chart for given symbol (or perform backtest or scan). Please note that TWS API currently allows only one backfill at a time so when there is a backfill already running in the background, automatic backfill request for next symbol will be ignored, until previous backfill is complete.
How I get around this (sometimes) was when I needed to refresh all my symbols with live data feed in TWS, I purposely do a 1 minute backtest run. Given that the 1 minute backtest run will take the most time, hence this should theoretically allowed IB sufficient time to do it's backfill on a symbol by symbol basis. But this don't work all the time.
What I would like to do is to come up with some sort of an AFL wait ( ) function and put this line of wait ( ) code at the end of my AFL file to cause my AFL script to "wait ()", say 20 seconds after each run. If I can do that, it would potentially solve the IB API automatic backfill dilemma, hopefully. I realize some people have done this before using OLE, but I want to keep things simple and do it in AFL. So does anyone have some sort of an AFL wait( ) function code to share, thanks again.
This won't work. First you should not busy wait in formula, second you don't know how much time it requires for TWS to backfill (the time CHANGES a lot). Instead of re-inventing the wheel, use BUILT-IN backfill procedure for IB that is described in manual.
I wrote dozens of times, IB backfill is special, UNLIKE normal RT sources like IQFeed and eSignal and the procedure for IB is to BACKFILL symbols via RT Quote window PRIOR to do any scanning.