1 registered members (AndrewAMD),
816
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
file_append, file_appendfront
#476155
01/30/19 09:34
01/30/19 09:34
|
Joined: Feb 2015
Posts: 652 Milano, Italy
MatPed
OP
User
|
OP
User
Joined: Feb 2015
Posts: 652
Milano, Italy
|
Goodmorning community, I am struggling using zorro's file_append and file_appendfront functions. I have prepared a script to test the 2 functions:
void storeTrade();
/* Stores all the trades closed this bar
Use after the algo/Asset loop. Not in the loop */
void printTrade(int counter);
int createReRArray(var* ReRarray, int Counter);
#define _storedRER "Data\storedRER.txt"
#define _storedTradeSize 50000 //1.000 trades (1.000 char [50])
#define _sTradeSize 50
char sRow[_storedTradeSize];
void storeTrade(){
char sTrade[_sTradeSize];
string ls, bo = "{", bc = "}";
for(closed_trades){ // Check only phantom trades closed this Bar
if ((int) TradeBarClose == Bar) {
if (TradeIsPhantom && TradeIsClosed){
if(TradeIsShort) ls = "S"; else ls = "L";
sprintf(sTrade, "n{%s:%s:%s%i}:%.2f", TradeAsset, TradeAlgo, ls, TradeID, TradeProfit );
// file_appendfront(_storedRER, sTrade, strlen(sTrade)+1 ); //<<--------- 1
// file_appendfront(_storedRER, sTrade, strlen(sTrade) ); //<<--------- 2
// file_appendfront(_storedRER, sTrade, 0); //<<--------- 3
// file_append(_storedRER, sTrade, 0); //<<--------- 4
// file_append(_storedRER, sTrade, strlen(sTrade) ); //<<--------- 5
// file_append(_storedRER, sTrade, strlen(sTrade) ); //<<--------- 6
printf("%s", sTrade);
// printf("Bar:%i - %s", Bar, sTrade);
}
//
}
else break_trades;
}
}
void run()
{
// set(LOGFILE);
MaxLong = 5;
MaxShort = 5;
StartDate = 20180101;
EndDate = 20180102;
BarPeriod =1;
Hedge = 5;
algo("TREND");
LifeTime = (int) random(10);
if (random(6) > 3) enterLong(); else enterShort();
enterLong(); enterShort();
storeTrade();
}
The idea behind the script is to print the same windows output in a file in normal and reverse order. I have tried all the 6 version listed uncommenting one of the numbered row at the time (remember to delete the file before each run). My finding is that file_append works, but does not write the EOL so instead of a file of strings a long sequence of char is written. file_appendfront does not work at all. I have involved the support and they confirmed that file_appendfront() with length=0 does not work as expected. Does anybody got some experience using this functions? Any idea? Ciao
|
|
|
Re: file_append, file_appendfront
[Re: jcl]
#476232
02/06/19 13:49
02/06/19 13:49
|
Joined: Feb 2015
Posts: 652 Milano, Italy
MatPed
OP
User
|
OP
User
Joined: Feb 2015
Posts: 652
Milano, Italy
|
The file_appenfront in 2.016 now works as a charme. Thank you Now I need to read all the strings written in the file and extract the info stored. Shold I use the standard C file functions or there is smarter way using Zorro, predefined functions? In C I was looking for something like:
main(){
char buf[80];
FILE *fp;fp=fopen("testo.txt", "r");
while (fscanf(fp,"%s",buf)>0)
printf("%s", buf);
fclose(fp);
}
|
|
|
Re: file_append, file_appendfront
[Re: MatPed]
#476279
02/10/19 09:59
02/10/19 09:59
|
Joined: Feb 2015
Posts: 652 Milano, Italy
MatPed
OP
User
|
OP
User
Joined: Feb 2015
Posts: 652
Milano, Italy
|
Trying to parse a simple csv: 1371,EUR/USD,TRD,79701,-0.055 1371,EUR/USD,TRD,79703,-0.055 1371,EUR/USD,TRD,82601,-0.102 1371,EUR/USD,TRD,86602,1.117 1371,EUR/USD,TRD,86802,1.373 The format I use: string sFormat = "0,i,sss,sss,i,f"; this is the testing code:
#define _storedRER "Data\storedRER.csv"
#define _storedTradeSize 50000 //1.000 trades (1.000 char [50])
#define _sTradeSize 50
void storeTrade(){
int iCounter = 0;
char sTrade[_sTradeSize];
string sDel=",", ls;
string sFormat = "%i%s%s%s%s%s%i%s%.3f";
for(closed_trades){
if (TradeIsPhantom && TradeIsClosed && TradeBarClose == Bar){
if(TradeIsShort) ls = "S"; else ls = "L";
sprintf(sTrade, sFormat, TradeBarClose, sDel, TradeAsset, sDel, TradeAlgo, sDel, TradeID, sDel, TradeProfit );
strcat (sTrade, "rn");
file_appendfront(_storedRER, sTrade, 0);
// printf("n");
// print(TO_WINDOW ,"n%s", sTrade);
}
}
}
void readTrade(){
// string sFormat = "%i%s%s%s%s%s%i%s%.3f";
string sFormat = "0,i,sss,sss,i,f";
int iHandle, iCounter;
iCounter = dataParse(iHandle, sFormat, _storedRER); //, sFilter
printf("n%i", iCounter);
dataNew(iHandle,0,0);
}
void main() {
set(LOGFILE);
Verbose = 7|DIAG;
readTrade();
}
No info is generated in the log file. The output is always 0. 2 questions: - Why no data are parsed? - If I want to filter the data set only EUR/USD is the filter string ",EUR/USD,,," correct? Thank you
|
|
|
Re: file_append, file_appendfront
[Re: MatPed]
#476300
02/15/19 09:43
02/15/19 09:43
|
Joined: Jul 2000
Posts: 27,986 Frankfurt
jcl
Chief Engineer
|
Chief Engineer
Joined: Jul 2000
Posts: 27,986
Frankfurt
|
For debugging your parsing, you can find instructions and advices under "remarks" on the dataParse manual page. Your filter string makes no sense. You can only filter strings that really appear in your csv, like "EUR/USD", but not ",EUR/USD,,,".
|
|
|
|