5 registered members (AndrewAMD, ozgur, Ayumi, 2 invisible),
690
guests, and 10
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);
}
|
|
|
|