Scan becomes an endless loop

Hello !
I'm trying to use
http://www.amibroker.com/kb/2014/11/14/how-to-export-quotes-to-separate-text-files-per-symbol/
to create txt file with 1sec quotes. Code is like this -

TimeFrameSet(1);
	fmkdir( "D:\\DataExport\\" );
	{
		fh = fopen( "D:\\DataExport\\VXX.txt", "w" );
		if ( fh )
		{
			dt = DateTime();
			startbar=16250001;
			for ( i = startbar; i < Min (startbar+1000000, BarCount); i++ )
			{
				fputs( DateTimeToStr( dt[ i ],1 ) + ",", fh );
				fputs( DateTimeToStr( dt[ i ],2 ) + ",", fh );
				qs = StrFormat( "%f,%f,%f,%f,%f,%f,%f\n", O[ i ], H[ i ], L[ i ], C[ i ],startbar,i,barcount );
				fputs( qs, fh );
			}
			fclose( fh );
		}
	}
// line required by SCAN option
Buy = 0;

So I'm trying to export 1M rows after the bar number 16250001. I have put "endless loop detection threshold" as 10M but I get "Endless loop" error all the time. When I open output file , I see that after some bar variable "i" stops to increase and there are infinite rows that are all the same and look like

5/6/2019,10:41:07,27.560499,27.560499,27.559999,27.559999,16250001.000000,16777216.000000,17511420.000000
5/6/2019,10:41:07,27.560499,27.560499,27.559999,27.559999,16250001.000000,16777216.000000,17511420.000000
5/6/2019,10:41:07,27.560499,27.560499,27.559999,27.559999,16250001.000000,16777216.000000,17511420.000000

I've checked data of symbol (VXX) and it's perfectly fine, no glithes on that particular date/time.

I just don't get why "i" variable stops increasing during the loop after some moment. Any ideas ? Thank a lot to everyone.

You are trying to increment numbers with 8 significant digits. But IEEE floating point numbers only have 7 sig digs, as explained here: http://www.amibroker.com/kb/2010/07/20/about-floating-point-arithmetic/. You may also wish to review this post: Limitations of the IEEE floating point standard and BarIndex(), iterator for loop

It would be simpler for you to simply use an Exploration like the one below.

Filter = True;
AddColumn(O,"Open",1.4);
AddColumn(H,"High",1.4);
AddColumn(L,"Low",1.4);
AddColumn(C,"Close",1.4);

If you want to skip some of the early data, then you could use a filter assignment like this:

Filter = DateNum() > 1150101;

Which would only give you data after Jan 1, 2015.

1 Like

It worked ! Thank you so much !