How to specify the download site for Amiquote in Batch processor

Dear Tomasz,

Thank you very much indeed for the solution and the excellent professional help/support I did not paid for. Amibroker at its price is probably the best value for money investment I made for many years. I will definitely buy the upgrade when it becomes available. The lessons I learn here is money cannot buy. Amibroker is nothing but a steal indeed.

For low proficiency users like me, to make sure I understand the concept properly, I appreciate clarification on the detailed questions below:

  1. To include the above as a step in the batch job, may I just add <script…/script> at top and bottom of the code and save it as an apx file.
  2. AQ.Source number for Finam is 6 I guess.
  3. If I open the forex database before calling this batch file, may I omit statement? As AQ normally do so by default.

Thank you for answering,

  1. You can run run JScript using cscript.exe command
    you could also rewrite the above code to AFL (it can be run from AFL level as well), the only practical diference is that you are not using JScript new but CreateObject() call.

  2. The number is just zero-based index to items in “Source” combo box, so first is 0, second is 1, third is 2 and so on

  3. AQ.Open is only used to load .TLS file. If you want to get tickers from currently loaded AmiBroker database you have to call GetTickersFromAmiBroker.

1 Like


I have been switching between 2 sources to download data, I have created a vbscript ‘set_to_fx.vbs’ to change the source site as below, it works ok if I were to run the script under windows explorer.

Set AQ = CreateObject(“AmiQuote.Document”)
AQ.Source = 6
AQ.interval = 2

However, when I add the following command in the batch job to call the script:

Execute and Wait: cmd.exe c:\vbscript\set_to_fx.vbs /C

it does not seems to update the amiquote and I still see it called up other data source which was previously used.

Please advise.

Thank you.

@Tomasz Can you clarify how I can get the AQ.From and AQ.Date values?
I converted the above code to AFL but I'm unable to accurately create the OLE date.

//Download one ticker
AQ = CreateObject("AmiQuote.Document");

AQ.Source = 0; // Yahoo Historical
AQ.AddSymbols("BP"); // comma separated list of symbols 
AQ.AutoImport = True; // no automatic import

//Fromdate = new Date(2018,01,12,0,0,0);
AQ.From = DateTimeConvert(1, StrToDateTime("2005-Mar-05")); //<<<<<< not working!!!
AQ.To = DateTimeConvert(1, StrToDateTime("2018-Mar-05"));

AQ.Download(); // starts download
AQ = Null;

Please don't create multiple topics on same subject. If you started something here, already don't create new topics.

As to the question, you DO NOT need to do ANYTHING. "From" and "To" just accept date as string

AQ.From = "2005-03-05";

It is is suprising that people don't try the most obvious thing.
OLE in windows does Variant coercion so if you pass one type it attempts the conversion for you, so pretty much everywhere you can just use string if you don't know what to do.

1 Like

@Tomasz makes it easy using Amiquote to download one (or more) ticker data in his post. How to download Intraday quotes from NSE

But I am seeking a shortcut method to download data for one ticker I am viewing on my chart.

Is anyone aware of or do they have an AFL formula that launches AmiQuote using the current chart's ticker?

Just open AmiQuote and add symbol then click download, as in the video:

or if you really need to do that from AFL

if( ParamTrigger("download", "Now") )
   AQ = CreateObject("AmiQuote.Document");
   AQ.AddSymbols( Name() );
   AQ.AutoImport = True;

@Tomasz Thanks. but how can I assign the AQ.From and AQ.To dates?

Note: This is a duplicate question from: How to specify the download site for amiquote in Batch processor

@SwingTradeMonkey, try this (ISO format string):

   AQ.From = "2010-01-01 00:00:00";
   AQ.To = "2017-12-31 00:00:00";

Now() also work on my system since it returns a string in the same format.

1 Like

To get the update, on my PC, (using AB 6.1 32 bit) I had to add the while loop at the bottom (like in the sample OLE js/vb scripts)

if( ParamTrigger( "Download", "Now" ) )
    AQ = CreateObject( "AmiQuote.Document" );
    AQ.AddSymbols( Name() );
    // AQ.Source = 0; // change as needed
    AQ.From = "2018-01-01 00:00:00";
    AQ.To = Now();
    AQ.AutoImport = True;

    while( AQ.DownloadInProgress() OR AQ.ImportInProgress() )
        ThreadSleep( 250 );

To use this code you need to "apply" it to a chart from the code editor. Then from the corresponding "pane" in the chart, you need to open the "Parameters" window (right-click on the pane) and then "Toggle" the "Now" to execute the code to launch AmiQuote.


@Beppe Thank you! Solution works! Much appreciated!

...and thanks to @Tomasz for making things so simple!

Instead of busy waiting in AFL (which is not good thing to do), you could just use ShellExecute to call external JScript.


Appreciate if you could recommend a book or online document for learning JScript, ideally in the context of AB/trading.

Thank you very much,

@etcjkam, for Amibroker the only suggestion is to look and study all the published JScripts starting from the simple examples at the bottom of the AmiBroker's OLE Automation Object Model.

Another useful source is the source code of the cleanup.js that is described in this AmiBrokers Tips article (paragraph 3)

Then there are some KB articles (some using external scripts, some using OLE from .afl)
How to export chart image to a file
How to browse charts in selected date range
How to delete quotes...
How to change property for multiple symbols at once.

Maybe @Tomasz and/(or others users will provide additional links and resources (probably some others useful scripts where posted in the old Yahoo group)

Read also this Running OLE automation scripts with 32- and 64-bit versions of AmiBroker

I also found an old newsletter article (not updated to the latest version of the OLE model) that, anyway, explains pretty well how to use the AB automation interface (at that time it was still almost new technology!).

To interact with Amiquote (AmiQuote's OLE Automation Object Model the best thing to do is to study the "ReadMe2.html" file that you'll find the AmiQuote installation folder (at the end there are two handy sample scripts).

In general, to interact with AB/AQ you can efficiently use JScript (a Microsoft subset of ECMAJavaScript) and/or VBScript. Both are natively included in Windows, that offers also supports for some less know variations like.WSF - an interesting one that allows to use/mix multiple scripting languages in the same source code - and the now-defunct files with the .HTA extension.

Nowadays you could also write your code in any other scripting language that could be installed in Windows (Python, Ruby, Perl, etc.). But in such a case I will not expect to get support from AmiBroker to troubleshoot any potential issues.

To learn more about the evolution of the languages, Wikipedia has some good articles on both VBScript and JScript and about the others supported scripting languages

Official documentation:
Here is the link to Microsoft JScript Language Reference (Windows Scripting - JScript)

In any case, if you want to focus on JScript or VBScript one of the most useful things is to learn how to use a debugger!

Re books, I have some old out-of-print titles (approx. the year 2000) but I I have a subscription to SafariBooksOnline and here is a list of some titles that are probably still relevant and available: (looking at the content tables I see that VBScript is a lot more documented than JScript):

  • Microsoft® PowerShell, VBScript and JScript® Bible by William R. Stanek , James O'Neill , Jeffrey Rosen - Publisher: John Wiley & Sons - Published: February 2009 (this seems to be the most comprehensive one)

  • VBScript Programmer's Reference, Third Edition by Kathie Kingsley-Hughes , Daniel Read , Adrian Kingsley-Hughes - Publisher: Wrox - Published: October 2007 (I have a previous edition, and I found it useful)

  • Microsoft® WSH and VBScript Programming for the Absolute Beginner, Fourth Edition - by Jerry Lee Ford Jr.
    Publisher: Course Technology PTR -Release Date: April 2014 - ISBN: 9781305260320

  • "Windows 7 and Vista Guide to Scripting, Automation, and Command Line Tools" by Brian Knittel - Publisher: Que - Release Date: December 2010 - ISBN: 9780789737281

  • Microsoft® Windows® 2000 Scripting Guide - Publisher: Microsoft Press - Release Date: December 2002 - ISBN: 9780735618671

Keep in mind that in many cases these books go over some topics/objects/methods that you'll probably never use with AB (accessing some essential Windows components, like the file system, printers, network, etc.).
For this kind of stuff nowadays is a lot better to learn and use PowerShell (a very powerful scripting language that unfortunatelly is difficult to use for AB/AQ interaction).

Finally, I found this online resource very useful to correctly understand command line argument passing:


Hi @beppe,
What a the comprehensive reference.

Deeply appreciated and thanks,


While running the beppe script, I notice that Lastvalue(BarIndex()) value does not change even after importing additional quotes. (The new Barindex() value is available during a subsequent run of the script). Any idea how to force an update to the BarIndex() array with current values while still running code within the same afl script?

BeforeBarNum = LastValue(Barindex());
NowSerialNo	 = Lookup(DaySerialNums,_DT(Now(1)), mode = 0);
StaleQuote       = IsNull(NowSerialNo);    
IF StateQuote {
   // Beppe's;

  AfterBarNum = LastValue(Barindex()); 

@SwingTradeMonkey, try adding (after the wait loop - but still inside the "trigger" conditional):

AB = CreateObject( "Broker.Application" );

Same result. In fact, even the Barcount variable does not change, although, from the refreshed chart display, the update is clearly working. Maybe @Tomasz can shed some light on why the internal amibroker arrays are not growing, as expected, while an afl script that runs Amiquote to add new quotes is executing.

You do not mention anything about where you run your code but I suppose you run from chart pane. Also you just posted code snippet only.

But you should read following Knowledge Base article to understand what QuickAFL means
Everything is there.

Just print LastValue BI

last_bi = LastValue(BarIndex());
printf( "%g", last_bi );

It doesn't matter whether you import additional quotes -> the original bar range (of chart) with QuickAFL enabled remains the same one as before import. Since chart's bar range remains the same as before barindex remains the same too.

Think about it... will previous chart range change just because of import. No, it won't (if not zoomed out completely). Import does not cause auto zoom out to include previous first visible bar of before import. So why should Barindex change (with QuickAFL enabled) if chart range remains the same one as before?

LastValue(BarIndex) will change after import if you disable QuickAFL via SetBarsRequired (also mentioned in upper article) or if you scroll to the very left of the chart (since LastValue() calls last index of array).