How to get started with batch script (OLE)

After reading https://www.amibroker.com/guide/objects.html I have a few questions:

  1. What is the console command to start running a JScript?
  2. How is it possible to download multiple symbols?
  3. How do I calculate and find the buy/sell signals only on new bars?
1 Like

How to get started with batch script (OLE)

Manual of (new) Batch feature
https://www.amibroker.com/guide/h_batch.html


"1. What is the console command to start running a JScript?"

Do you want to run jscript file from AFL?
If so then you may do so via ShellExecute() function

if ( ParamTrigger("Run script", "CLICK HERE") )
	ShellExecute("Scripts\\ArconeTest.js", "", "", showcmd = False );

If you want to run batch file (see upper link) then you may do like this

// run batch
if ( ParamTrigger("Run batch file", "CLICK HERE") )
	ShellExecute("runbatch", "path_to_batch_file.abb", "" );

Source here https://www.amibroker.com/guide/afl/shellexecute.html


"2. How is it possible to download multiple symbols?"

Downloading symbol names or price data of symbols? EOD, streaming quotes?
You are too vague about what you actually want.
http://www.amibroker.com/guide/h_quotes.html
http://www.amibroker.com/guide/h_amiquote.html


"3. How do I calculate and find the buy/sell signals only on new bars?"

https://www.amibroker.com/kb/2015/11/29/how-to-execute-part-of-the-formula-only-when-new-bar-is-added/

4 Likes

Thanks for all the usefull links :+1:
One thing that aint all clear to me. Is it possible to have an all code setup?

I was of the understanding that I could start the batch script (ArconeTest.js) via cmd. And it would run as a cron job, and trigger once a day to run my strategy.afl... ?

  1. What is the console command to start running a JScript?

I have still not figured out how to start my amibroker trading system via console. Maybe its not possible?

  1. How is it possible to download multiple symbols?

I have managed this using a chart button. When the symbols are downloaded the script only run for the selected symbol and not all the other symbols downloaded. How can I on download trigger update on all symols?

idDownlaodButton = 1;
GuiButton( "Download symbols", idDownlaodButton, 10, 20, 100, 20, notifyClicked );

for ( n = 0; eventId = GuiGetEvent( n, 0 ); n++ )
{
	if(eventId == idDownlaodButton) 
	{
		AQ = CreateObject("AmiQuote.Document");
		AQ.Open("C:\\amibroker\\symbols.tls");

		AQ.From = "2017-01-01 00:00:00";
		AQ.To = Now();

		AQ.AutoImport = True;
		AQ.Source = 0; // Yahoo Historical
		AQ.Download();

		while( AQ.DownloadInProgress() OR AQ.ImportInProgress() )
		{
			ThreadSleep( 500 );
		}
	}
}
  1. How do I calculate and find the buy/sell signals only on new bars?

With the help of @fxshrat I managed it with:

varName = Name() + "_processedBarIndex";
processedBarIndex = Nz( StaticVarGet( varName ) );
lastBarIndex = BarCount;

for( i = processedBarIndex; i < lastBarIndex; i++ )
{
	printf("New bar added "+i+" \n");
   
	StaticVarSet( varName, lastBarIndex, True );
}

You may do whatever you like.

Please read the batch help of upper provided link. Internal batch processor has internal scheduler.
(As aside you can also add jscripts/vbscript/py/exe... to internal batch command).

For example you may execute jscript from batch via Execute and Wait command and adding script path to Parameter/file field:

Scripts\MyScript.js

In addition please read below link as you may need to specify wscript.exe or cscript.exe to execute jscripts
http://www.amibroker.com/kb/2015/01/12/ole-automation-scripts-with-32-and-64-bit/


Or use any other external 3rd party scheduler to run your custom jscripts or vbscripts (see windows task scheduler or whatever).

Your choice.


I did not help you on that code (and it does not make sense to me as proper one is to be found in KB article of previous post's link already). You do not need to iterate to check for new bar added to DB.

The code example provided in the link did not work as needed. The iteration is to handle any previous bars if the system have not been running for a few days.