Hi,

I am trying to convert multiple csv files into t6. I coded up a loop to run through each csv files and to convert it into t6, however all created t6 files contain the history of the first csv file only.


#define SPLIT // split into separate years

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

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

#ifndef SPLIT
if(Records) dataSave(1,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(1,NewName,Start,i-Start);
Start = i;
LastYear = Year;
}
}
#endif
}

function main()
{
int x = assetList("HistorySP500AssetsSP500.csv");
int i;
for(i=0; i<x; i++)
{
string down = Assets[i];
convert(down,down);
}
}

I have used the csvToExport File from Zorro and added a loop.

However, as mentioned it does not properly created the t6 files. All of them contain the history of the first csv.

Could someone explain what goes wrong here?

Cheers

Last edited by Ger1; 05/09/18 00:26.