I have code below to write EOD data to a file. Two weird results:
- Sometimes writes only to correctly named file. But other times adds a second, shorter file, with different first date.
- Correctly dated file has dates wothout leading zeros which make confuses my exel type software. Tried FormatDateTime, but that creates wrong dates. Could use a "FormatDate" only.
Thanks in advance for any help.
// General Fluff
#pragma nocache
_TRACE("!CLEAR!"); // this clears the internal log window
Filter = 1; // rely on Analysis Filter
SetBarsRequired(sbrAll);
Buy = Sell = 0;
Short = Cover = False; // long only strategy for now
SetTradeDelays(0,0,0,0); // day to make trades
dn = DateNum();
tn = TimeNum();
fileName = NumToStr(dn[0]%1000000, 1.0, False) + " - "
+ NumToStr(dn[BarCount -1]%1000000, 1.0, False) + " " + Name() + ".csv";
filedeleted = fdelete(fileName);
if(Status("stocknum") == 0){
fh = fopen(fileName,"w");
if(fh){
fputs("Symbol,Date,Open,High,Low,Close,Aux1,Volume\n", fh);
fclose(fh);
}
}
fh = fopen(fileName,"a");
if(fh){
for(i = 0; (i < BarCount); i++){
if( dn[i] <= 1210122){
Line = Name() + "," + NumToStr(dn[i]%1000000, 6.0, False) +
StrFormat(",%g,%g,%g,%g,%g,%g\n",
Open[i],
High[i],
Low[i],
Close[i],
Aux1[i],
Volume[i]);
fputs(Line, fh);
}
}
fclose(fh);
}