oh really? thanks will test it
i already used append but didn't know it will automatically find the correct data to append. My full code was this (see below). So if it found the file it would use append. But it can be done easier, will check it out, thanks
_SECTION_BEGIN( "Export 1Min Data" );
ExportOHCL = ParamTrigger( "Export Data", "EXPORT" );
TF = interval();
str = strold = "";
val = 0;
function findLastLineInFile()
{
Say( "Find last line in file" );
str = strold = "";
fh = fopen( "D:\\AmibrokerData\\" + Name() + ".txt", "r" );
if( fh )
{
while( !feof( fh ) )
{
strold = str;
str = fgets( fh );
}
str = StrExtract( strold, 1 );
val = StrToDateTime( str );
}
else
{
printf( "ERROR: file can not be found (does not exist)" );
val = 0;
str = "";
}
fclose( fh );
}
if( ExportOHCL AND TF == in1Minute )
{
findLastLineInFile();
// new file, file does not yet exist
if( val == 0 AND str = "" )
{
_TRACE( "export 1 " );
Say( "start export One" );
fmkdir( "C:\\AmibrokerData\\" );
// open file for writing
// file name depends on currently processed ticker
fh = fopen( "D:\\AmibrokerData\\" + Name() + ".txt", "w" );
// proceed if file handle is correct
if( fh )
{
dt = DateTime();
// write header line
fputs( "Ticker,Date/Time,Open,High,Low,Close,Volume,BuyVolume,SellVolume\n", fh );
// iterate through all the bars
for( i = 0; i < BarCount; i++ )
{
// write ticker name
fputs( Name() + "," , fh );
// write date/time information
fputs( DateTimeToStr( dt[i] ) + ",", fh );
//write quotations and go to the next line
qs = StrFormat( "%g,%g,%g,%g,%g.%g,%g\n", O[i], H[i], L[i], C[i], V[i], BuyVolume[i], SellVolume[i] );
fputs( qs, fh );
}
// close file handle
fclose( fh );
Say( "finished export one" );
}
}
else
// the export file already exists just append from last saved data
if( val != 0 AND str != "" )
{
_TRACE( "export 2 " );
Say( "start export Two" );
// open file for appending
// file name depends on currently processed ticker
fh = fopen( "D:\\AmibrokerData\\" + Name() + ".txt", "a" );
// proceed if file handle is correct
if( fh )
{
dt = DateTime();
//fputs( "sep\n", fh ); // test separator
// iterate through all the bars
for( i = 0; i < BarCount; i++ )
{
if( dt[i] > val )
{
// write ticker name
fputs( Name() + "," , fh );
// write date/time information
fputs( DateTimeToStr( dt[i] ) + ",", fh );
//write quotations and go to the next line
qs = StrFormat( "%g,%g,%g,%g,%g.%g,%g\n", O[i], H[i], L[i], C[i], V[i], BuyVolume[i], SellVolume[i] );
fputs( qs, fh );
}
}
// close file handle
fclose( fh );
Say( "finished export two" );
}
}
}
_SECTION_END();