Scan becomes an endless loop

Hello !
I'm trying to use
to create txt file with 1sec quotes. Code is like this -

	fmkdir( "D:\\DataExport\\" );
		fh = fopen( "D:\\DataExport\\VXX.txt", "w" );
		if ( fh )
			dt = DateTime();
			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


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

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 !