ShellExecute - how to pause new batch before previous batch finish

I've got pretty often problem with batch that starts and exports exploration.

I need to run exploration every 30 seconds. The work flow of batch is as follows:

  1. Update Watchlist from csv
  2. Open Project
  3. Explore
  4. Save results to file
    I run above mentioned batch from file/project (ShellExecute( "runbatch"...) and it is run automatically every 30 seconds (AutoRepeat interval 30 seconds).
    Everything works fine when the whole procedure is closed within 30 seconds. Exploration, as AFL execution, takes less than 1 second. However, when I update the Watchlist (it is updated a few times a day with even 100 different stocks for Exploration), the Exploration has to backfill the data of newly added stocks. The backfill sometimes takes long time.
    If the backfill takes too long, then new batch tries to start and error apears ("There is other batch currently running or paused...") and everything stops or even Amibroker crashes.
    Is there any possibility to run new batch every 30 seconds, but only when previous cycle ended? The function Execute and Wait doesn't work because it concerns external applications. Any suggestions, please?
1 Like

Combine two batches into one. That's all.

I didn't mention that there are 2 batches. There is only 1 batch with only one project (one formula) to explore. Due to delay in backfill sometimes the batch is not able to finish in 30 second when new run of batch starts (batch is run through project/formula that executes batch every 30 seconds).
Maybe there is some possibility to check through AFL if there is still other batch running and if yes, then do nothing (or just wait another 30 seconds) ?

  1. You wrote "new batch tries to start" - this implicts that there are more than one
  2. Backfill, if needed, should be done once BEFORE anything else (NOT as part of backtest).
  3. You should use built-in AmiBroker Batch SCHEDULER - it runs batches without overlap.
  4. AFL is not meant as "director" for batches. It is the other way round. Scheduler should be used for any periodic batch runs. ShellExecute("runbatch") is kind of a hack and it is meant to be triggered only by manual action (such as ParamTrigger).

"new batch tries to start" meant the same batch run every 30 seconds. I launch batch by ShellExecute("runbatch") which is included in AFL file / project which is run every 30 seconds. It starts batch which includes: (1) Update of watchlist -> (2) openning the project with strategy -> (3) exploaration that also waits for backfill due to new stocks included in watchlist -> (4) export the results to file
I can't backfill data before anything else, because stocks are added during the trading session a few times. Sometimes there are only 5 new stocks at once, sometimes there are 80 new stocks added to watchlist. The number of new stocks depends on the filters in TradeIdeas from which I export (automatically) the file with selected stocks. I can't predict the numer of updates - sometimes it is done 3 times a day, sometimes 10 times a day. That is why I have to check for update of watchlist during every run of exploration (in batch included).
Batch Scheduler is rather... uncomfortable to set it to run batch every 30 seconds, but if it is the only way without failures, I'll try.

1 Like

As I wrote, you should use Scheduler.

ShellExecute("runbatch") is NOT meant to be used as "scheduler replacement" and AFLs are NOT meant as batch directors.


If you want to orchestrate things like that you can use OLE automation that is meant to do the automation AmiBroker Object Model and allows to check if Analysis is in running state or not.