I was finally able to solve it myself.

The issue was that I did not change the Handle.

Below the solution that works for me:




#define SPLIT // split into separate years


string Format = "+%d/%m/%Y,f3,f1,f2,f4,f6,f5";

int n;

function convert(string InName, string OutName)
{
int Records = dataParse(n,Format,InName);
printf("n%d lines read",Records);

#ifndef SPLIT
if(Records) dataSave(n,OutName);
#else

int i, Start = 0, Year, LastYear = 0;
for(i=0; i<Records; i++)
{
Year = atoi(strdate("%Y",dataVar(n,i,0)));
if(!LastYear) LastYear = Year;
if(i == Records-1)
{ // end of file
LastYear = Year; Year = 0;
}
if(Year != LastYear)
{
string NewName = strf("%s_%4i.t6",strxc(OutName,'.',0),LastYear);
printf("n%s",NewName);
dataSave(n,NewName,Start,i-Start);
Start = i;
LastYear = Year;
}
}
#endif
}

function main()
{
int x = assetList("History\SP500\AssetsSP500.csv");
int i;
n=1;

for(i=0; i<x; i++)
{
string down = Assets[i];
convert(down,down);
n++;
}
}