How to specify the download site for Amiquote in Batch processor

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:
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();
}
2 Likes

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

3 Likes

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

@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

@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

12 Likes

Hi @beppe,
What a the comprehensive reference.

Deeply appreciated and thanks,

jimmy

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 {
   //...run Beppe's; https://forum.amibroker.com/t/how-to-specify-the-download-site-for-amiquote-in-batch-processor/1877/12?u=swingtrademonkey

  AfterBarNum = LastValue(Barindex()); 
}

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

AB = CreateObject( "Broker.Application" );
AB.RefreshAll();

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.

@SwingTradeMonkey,
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
http://www.amibroker.com/kb/2008/07/03/quickafl/
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).

BarIndex may not change after import because BarIndex refers to AFL array, not to the database. As long as zoom level is kept constant you will just get the same number of bars displayed on chart and they will just be more recent. BarIndex() in that case will not change as QuickAFL uses only needed bars, not all. What you should be looking at is a TIMESTAMP of last bar

DateTimeToStr( LastValue( DateTime() ) );

@Tomasz After Amiquote import finishes, my chart's last displayed bar date changes from 7/17/2018 to 1/31/2019 (as expected) when the chart refreshes. However, the before import and after import result values for DateTimeToStr( LastValue( DateTime() ) ); remain identical while in the script that executed the import.

So, within the same executing script, and after Amiquote finishes it's import, is there any way to obtain the updated value from the Datetime() array?

Additional Information:
If the last date value imported is not current*, then I am adding the ticker to an exclusion list to prevent re-attempting the update, because it is likely the ticker is no longer valid.

*By current, I mean the last trading date available, excluding holidays and weekends.

@fxshrat - I execute this script to import a single quote within a chart, along with some added support code. I receive same before import and after import value for LastValue(BarIndex) after effectively disabling Quickfill by adding this to the top of my script:

SetBarsRequired( sbrAll, sbrAll );

It occurs to me that while executing, the AFL arrays (datetime() or BarIndex do NOT dynamically update.
Also, please see my reply to tomas' comment regarding the datetime() array.

Is there an alternate SetBarsRequired setting I should use?

Wrong! I don't know what exactly you are doing on your end. BUT it is definitely not the same last barindex received after import (if QuickAFL is disabled).

Watch below few seconds long video carefully from start to finish! (The barindex will change at second 7 of video.)

lastbi


Also last date time with QuickAFL enabled does update! (of course it will also update if QuickAFL is disabled)

Watch! (it will change at around second 7 again)

last%20dt

You are apparently not using the actual script on chart.
Right click chart pane and choose "Edit Formula" and check your script.

(And BTW it is not called Quickfill but QuickAFL.)

This is the code I was using

/// https://forum.amibroker.com/t/how-to-specify-the-download-site-for-amiquote-in-batch-processor/1877/12
if( ParamTrigger( "Download", "Now" ) )
{
    /// @link file:///C:/Program%20Files/AmiBroker/AmiQuote/ReadMe2.html
    AQ = CreateObject( "AmiQuote.Document" );
    AQ.AddSymbols( Name() );
    // AQ.Source = 0; // change as needed
    AQ.From = "2019-01-30 00:00:00";
    AQ.To = Now();
    AQ.AutoImport = True;
    AQ.Download();

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

//SetBarsRequired(sbrAll);// disables QuickAFL

//last_bi = LastValue(BarIndex());
//printf( "last barindex: %g\n", last_bi );

printf( "QuickAFL enabled!\n");
printf( "last datetime: %s", DateTimeToStr( LastValue( DateTime() ) ) );

Bottom line. Listen to what advanced people say instead of questioning it. I am not posting here for making pranks!


BTW, OLE works on first instance only! So make sure that you actually import to first AB instance!