Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
file_append, file_appendfront #476155
01/30/19 09:34
01/30/19 09:34
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

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:

Code:
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: MatPed] #476166
01/31/19 19:14
01/31/19 19:14
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
AFAIK we have no bug confirmed for file_appendfront, so it should work as described. It's normally used to add records in front, and zero length will most likely add nothing.

I am not sure what you mean with the EOL issue. Your string has no EOL. For this, let it end with \r\n, or 0x0a 0x0d. The function just adds what you pass as argument. It does not care about EOL or other character sequences.

Re: file_append, file_appendfront [Re: jcl] #476172
02/01/19 00:20
02/01/19 00:20
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Hi,
thank you for your reply, this is the email from support:
"Hi,

you appended data with zero length. Pass the string length to the size parameter, otherwise nothing is appended. But we'll change this in the next version so that 0 is also accepted for the length, as with file_append. "


file_append with 0 as lenght. works as stated in the manual. file_appendfront does not.


The append_front does not append any character in front of the file with any of the variants. Just run my script and you can check it. Maybe I am not using the right sintax. Can you tell me how to modify the script? I just want to print the window output in the reverse order.

I guess that n was enough as in normal printf. I will update my string accordingly with your suggestion.

Thank you in advance

Re: file_append, file_appendfront [Re: MatPed] #476177
02/02/19 11:46
02/02/19 11:46
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Yes, I see that file_appendfront was changed in the current beta version so that it also accepts strings, similar to file_append.

Re: file_append, file_appendfront [Re: jcl] #476180
02/02/19 14:12
02/02/19 14:12
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Ok,
do you have a walkaround for the previous version?
Thank You

Re: file_append, file_appendfront [Re: MatPed] #476181
02/02/19 14:26
02/02/19 14:26
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
I do not see any note in the bug list. From which version the file_appendfront have been fixed?

Thank you

Re: file_append, file_appendfront [Re: MatPed] #476182
02/02/19 14:46
02/02/19 14:46
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I have no fix in my list, only the note of string support. So I'm not sure if that fixes your issue - but just try!

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
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

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:
Code:
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] #476269
02/09/19 07:18
02/09/19 07:18
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I would simply use dataParse for reading back data from a file.

Re: file_append, file_appendfront [Re: jcl] #476278
02/09/19 22:03
02/09/19 22:03
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Interesting, never dig into that set of function seems powerfull.
Thank You

Page 1 of 2 1 2

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1