Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,731 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
I may be stupid, but I'm not crazy! caution LONG! #429877
09/19/13 19:25
09/19/13 19:25
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
In my continuing saga of reading a files' contents into a zorro script, I have come across a problem.
To recreate this you need to:
A: open notepad and type a few lines pressing return at the end of each line and then save the file in zorro's history folder. Give it a new of atestfile.txt
B: copy the following text into a new zorro script.

#define H1 (60/BarPeriod)

function run()
{
BarPeriod = 60;
TimeFrame = H1;
Lots=1;
Margin=0;
set(LOGFILE);
StartDate=20080102;
EndDate=20080131;
var acctbal;
if(is(INITRUN)){
string buff = file_content("History\\atestfile.txt");
printf("# \n %s80 \n", buff);
}

printf("# \n ALLDONE! \n");
}

Now save as atest.c and select EURUSD for the test currency and then run the script.
Now open in notepad the file \log\atest_EURUSDtest.log
you should get something like this:


BackTest: atest EUR/USD 2008
[1: Wed 02.01. 10:00] 1.46545
ALLDONE!

[2: Wed 02.01. 11:00] 1.46624
ALLDONE!

[3: Wed 02.01. 12:00] 1.46532
ALLDONE!
etc etc etc...IE No printing of the buff string.

now go back and comment out the if(is(INITRUN))
so it looks like this:
//if(is(INITRUN)){
string buff = file_content("History\\atestfile.txt");
printf("# \n %s80 \n", buff);
//}

saveit and run it again

Now you get something that looks like this:

BackTest: atest EUR/USD 2008
[1: Wed 02.01. 10:00] 1.46545
abcdef 1234

ghijkl 1234

mnopqw 1243

ertyui 1243

asdfgh 124

zxvcbn 43280

ALLDONE!

[2: Wed 02.01. 11:00] 1.46624
abcdef 1234

ghijkl 1234

mnopqw 1243

ertyui 1243

asdfgh 124

zxvcbn 43280

ALLDONE!

etc etc etc....
NOW it prints the buff string...

So now after all of this.... I am stupid, because I use printf alot for debugging and I thought I was crazy trying to debug this and the log results would change. Turns out the printf doesn't print if you inside the if(is(INITRUN)) for somereason. Oh.. and you can change it to be a main() instead of a run() and it does the same thing. I've attached a zip file with 4 files, 2 .c and 2.log files that show the results I'm getting. Hopefully this can be repeated and fixed next release.

sorry if this is too long.

Thanks
P

Attached Files
atest.zip (1 downloads)
Re: I may be stupid, but I'm not crazy! caution LONG! [Re: Pork] #429897
09/20/13 10:07
09/20/13 10:07
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
The reason is quite simple: just like prices and assets, there is also no logfile in the INITRUN. The INITRUN is for initializing parameters. As you're setting the LOGFILE flag in the script, Zorro can only know after the first run whether to open a logfile at all or not.

This will be made more clear in the manual.

Re: I may be stupid, but I'm not crazy! caution LONG! [Re: jcl] #429915
09/20/13 13:18
09/20/13 13:18
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Thanks for that jcl. I can fix that.
But, I hate to keep pestering you, but why doesnt this work:

bool firsttime=true;
function run()
{
BarPeriod = 60;
TimeFrame = H1;
Lots=1;
Margin=0;
set(LOGFILE);
StartDate=20080102;
EndDate=20080131;
var acctbal;
string buff;

if(firsttime){
buff= file_content("History\\atestfile.txt");
firsttime=false;
printf("# \n %s \n", buff);
}
else {
printf("# \n first time is not true \n");
}
}

the results I get are :


BackTest: atest EUR/USD 2008
[1: Wed 02.01. 10:00] 1.46545
first time is not true

[2: Wed 02.01. 11:00] 1.46624
first time is not true

this doesn't make sense to me, sorry. I've tried various ways to do this and none of them work. What am I doing wrong. This shouldn't be this difficult.
P

Re: I may be stupid, but I'm not crazy! caution LONG! [Re: Pork] #429916
09/20/13 13:34
09/20/13 13:34
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Wasnt this already explained? There is no logfile in the initial run. It wont help if you call the variable "Firsttime" instead of "INITRUN".

What do you want to do with the text from your file anyway? When you explain that, I can maybe help, I have a project where I read texts from files all the time.

Re: I may be stupid, but I'm not crazy! caution LONG! [Re: Spirit] #429927
09/20/13 15:00
09/20/13 15:00
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Yes it was explained that it wouldn't work in INITRUN.
I wrongly assumed that an int or bool that I define is NOT INITRUN.
You will be pleased to know that I have figured it out.
I don't understand why it works, but it works.
Sorry if I was a pest.
The following will read the file just once at the beginning and print the readfile to the log file.
Why? Don't know why comparing a var is different than comparing an int or a bool. But it apparently is.

var firstprice=0;
function run()
{
BarPeriod = 60;
TimeFrame = H1;
Lots=1;
Margin=0;
set(LOGFILE);
StartDate=20080102;
EndDate=20080131;
var acctbal;
string buff;
if(firstprice==0){
firstprice=priceClose();
buff = file_content("History\\atestfile.txt");
printf("# \n %s \n", buff);
}

Thanks.

P

Re: I may be stupid, but I'm not crazy! caution LONG! [Re: Pork] #429932
09/20/13 15:30
09/20/13 15:30
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Now youre reading your file twice, first in the initial run, then also in the second run. This is probably still not what you want to do.

If you want to do something only in the second run when the log file is open, just count the runs. Like this:

int count = 1;
function run()
{
...
if(count == 2) {
buff = ...
...
}
count++;
}

Hope this helps...

Re: I may be stupid, but I'm not crazy! caution LONG! [Re: Spirit] #429935
09/20/13 15:53
09/20/13 15:53
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Yes, Thank you.
But I'm still confused about why this doesn't work.
int count = 1;
function run()
{
...
if(count == 1) {
buff = ...
...
}
Sorry.
P

Re: I may be stupid, but I'm not crazy! caution LONG! [Re: Pork] #429938
09/20/13 16:17
09/20/13 16:17
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi Pork,

What do you mean by "doesn't work"? buff not loaded? printf's output doesn't appear in the log? buff load not happening at the bar you want it to happen at?

As near as I can tell, buff is being loaded fine. You just can't see it when the log isn't active yet. If you take the "#" out, you should see the buff printf in the Zorro window.

If you need to have the buff printf show in the log, you'll need to hold off until the log is active, as Spirit says. Similarly if you need it at a particular bar.

I believe the reason your if(count==1) doesn't work is because it happens on the INITRUN when the log isn't active yet.

HTH.

Re: I may be stupid, but I'm not crazy! caution LONG! [Re: DdlV] #429942
09/20/13 16:55
09/20/13 16:55
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Hi Ddlv,
The way it is written. The if is NEVER executed and buff is never loaded as near as I can tell because I can never find out what buff contains by using the printf function.
Try it if you haven't.You'll see why I'm so confused.
If I change the int count=1 to var count=0 and then compare to the var the program functions as expected. I'm happy. I found a way to make it work.
I just don't know why it makes a difference on the type of variable defined.
Shouldn't the script function the same way for var count=0 and int count=1 or bool count=true? Chnage the variable declaration type and see what happens.
P

Last edited by Pork; 09/20/13 17:07.
Re: I may be stupid, but I'm not crazy! caution LONG! [Re: Pork] #429947
09/20/13 17:23
09/20/13 17:23
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
Pork: all your scripts work fine, as far as I can see from the code.

Just listen to people who now have told you three times that the log file is not open in the first run. Somehow you always manage to come up with a script that will not print anything.

If you only want to test your code, just remove the '#' from your printf statements for god's sake. Then it prints to the window, and you can at least see what your code does, and can continue with your project. For counting use an int, not a var.

Page 1 of 2 1 2

Moderated by  Petra 

Gamestudio download | 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