How to specify the download site for Amiquote in Batch processor


#1

Hi forum experts,
I update most of my databases from the yahoo site using amiquote manually. As i have a few databases with many symbols the process take considerable time.

The Batch processor is the best solution to automate the job. https://www.amibroker.com/guide/h_batch.html2

To setup the Batch job i need to define which database to load and which site to Download load from before loading amiquote. Load database seems an option one can pick as a task but i cannot figure out how to specify the Download site as ineed to switch between yahoo and Finam etc.

Appreciate advices from experience users.

Many thanks,


How to Interactively Update a single Ticker From AFL
Automate Yahoo historical updates?
Batch Processing (Basic Schedule)
#2

Last used site is used automatically. So whatever you choose will be used in subsequent downloads. The only way to switch the source programmatically is using AmiQuote’s OLE interface as documented in the ReadMe2.html file (in AmiQuote folder)

Verbatim copy from read me (this is Windows Scripting Host code, NOT AFL):

AQ = new ActiveXObject("AmiQuote.Document");
AQ.Open("C:\\mysymbols.tls");

FromDate = new Date(1995, 5, 1, 0, 0, 0);
/* year, month-1, day, hour, min, sec (required by JScript date constructor) */

 ToDate = new Date; // current time

 /* getVarDate is required to convert from JScript Date to OLE-automation date */
 AQ.From = FromDate.getVarDate(); 
 AQ.To = ToDate.getVarDate(); 

 AQ.AutoImport = true; // import automatically
 AQ.Source = 0; // Yahoo Historical

AQ.Download(); // starts download

// wait until download and import is finished
while( AQ.DownloadInProgress || AQ.ImportInProgress )
 {
     WScript.sleep(5000); // wait 5 seconds before querying status again
 }

#3

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 AQ.open statement? As AQ normally do so by default.

Thank you for answering,


How to select the data source for batch processing?
#4
  1. You can run run JScript using cscript.exe command
    http://www.amibroker.com/kb/2015/01/12/ole-automation-scripts-with-32-and-64-bit/
    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.


#5

Hi,

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.


#6

@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;

How to Interactively Update a single Ticker From AFL
#7

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.


#8

@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?


#9

Just open AmiQuote and add symbol then click download, as in the video:
http://www.amibroker.com/video/amiquote2.html

or if you really need to do that from AFL

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

#10

@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


#11

@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.


#12

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;
    AQ.Download();

    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.


#13

@Beppe Thank you! Solution works! Much appreciated!


#14

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


#15

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


#16

@beppe,

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

Thank you very much,
jimmy


#17

@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!

Books:
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:
http://daviddeley.com/autohotkey/parameters/parameters.htm#WSH


#18

Hi @beppe,
What a the comprehensive reference.

Deeply appreciated and thanks,

jimmy