Backtest - Differences between run by scheduler and manual

I wrote a strategy that goes in and out in the same bar. It opens Long at Open and closes Long at Close. By concept, only one daily bar is ever inside.
If I open the APX file and run the BackTest it produces all the trades with duration 1 bar.

I then created an .abb (batch) file.
As shown in the image, inside it I open the APX file and then launch the BackTest
If i click on "Run" button, everything it's ok

All trade are of 1 bars

If instead I compile a date and time in the scheduler for the opening of the .abb file and the consequent execution of the backtest, the strategy (which I haven't touched / changed either in the AFL file or in the APX file), it changes behaviour.

As you can see the trades change


Case A I launch by clicking on Un
Case B the scheduler takes care of opening the APX, run the backtest
Case C I also tried creating an external.js file that launches with the command

	AB = new ActiveXObject("Broker.Application" ); // creates AmiBroker object
	try	{
		NewA = AB.AnalysisDocs.Open( "N:\\APX - 093 - bis.apx");
		if( NewA )	{
			NewA.Run( 2 ); 		// Portfolio Backtest
			NewA.Close(); 		// Methods-Sub 		: close new Analysis
	catch(err) {
		WScript.echo( "Exception: " + err.message ); 	// display error that may occur

before trying to overcome the obstacle with some complex macro, does anyone have a suggestion for me?
Thank you

My version is
and run in Windows x64

With "scheduler" you mean Windows Task Scheduler or AB scheduler, in other words how exactly you run that batch? Most likely this is caused by different padding, verify if you are running that with "Pad and align" set to true (I guess so) and what is the reference symbol.

Keep in mind that if you run program from Javascript Windows Scripting Host it will use current working directory of WScript/CScript, not proper current working directory set by the icon ("Start in" property). Having correct working directory is crucial as many files are accessed using relative paths.

I apologize for explaining myself partially

By scheduler I mean the internal one of Amibroker

about the PadAlign


and I think that the set of this option is saved in the APX file, consequently, regardless of who opens the file, or the scheduler, or manually a man with the mouse, that data does not change, if configured as in the image

Thank you

Can you kindly point me to this tip, check to do,
where can i read the directions?

First I would run the code given here

And verify data checksum when run from hand and from scheduler.

Second thing is to try running without padding.

This is to find out what is the true reason for differencies

Thank you for the important guidance you have provided me.
Even if it's not a check between two different PCs, actually, it's an important check to do. I did not detect any differences when launching the strategy from the mouse, or from the internal Amibroker scheduler

I tried but it doesn't solve

One thing that I have observed thanks to the tests that you have induced me to do, has been decisive
In the scheduler, in the .abb file

Although I don't need to launch an explorer first, it solved my problem
In my opinion it is inexplicable but solving, I give up understanding the motivation

If you look at test 22276, made with the scheduler, it produced different results, equal APX file and equal AFL compared to the results I obtained using the mouse to launch the backtest

By introducing the line that invokes the explorer before the back test, the results no longer change
Now I can use the .JS file or the internal scheduler, and the results are always the same

// ### SECTION Explore
if (Status( "ActionEx" ) == actionExplore )	{
	Filter = Status("lastbarinrange");
	AddColumn( Cum( High + Low + Close + Open ), "Price checksum");
	AddColumn( Cum( Volume ), "Volume checksum" );
	AddColumn( BarIndex(), "Number of bars");
	AddSummaryRows( 1 ); 						// add total sum of column

At Explorer level, I left the suggestion you proposed for the checksum
I think there is no explanation for plausible.

Maybe it depends on a fixed behavior in later releases

I'll upgrade sooner or later
Thank you very much for helping

What data source are you using?

That is crucial question missing from all your posts.

If running Explore first fixes the problem, it might be that you are using 3rd party data source and/or plugin driven data source and the plugin does not deliver data on time (some plugins deliver data later - after remote server responds to request). In such case running with "Wait for backfill" would help too. If you run any action before actual backtest (like here Explore) the data will be requested before Backtest and more likely to be delivered before backtest starts.

I use EndOfDay Metastock data, which updates once a day.
And official plugin


I also restarted the pc, and consequently Amibroker
It doesn't change behavior until you come up with the approach of using an Explore before Backtesting

I can see you created database folder inside "C:\Program Files" .

It is bad idea. Why? Because Microsoft does not like folders inside that dir and virtualizes them. This can create all kind of problems unless folders is being given access rights in non-elevated mode.

Virtualized folders/files do not exist in the place you think they do. They are shadowed in other HIDDEN location (i.e. with 'hidden' attribute). This yet another not-well-thought Microsoft "invention" causes many problems.

It is strongly advised to keep data in either "database" subfolder of AmiBroker directory, or OUTSIDE of "Program files" altogether.

Learn more about Microsoft Virtual Store:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.