Gamestudio Links
Zorro Links
Newest Posts
How to select between IB accounts by script?
by Jack_Zodiac. 06/12/26 23:17
Zorro tutorial ideas?
by pr0logic. 06/12/26 13:36
Max Number of Strategies in /Strategy folder
by Martin_HH. 06/12/26 08:50
Stooq now requires an API key
by AndrewAMD. 06/11/26 17:55
Z9 getting Error 058
by k_ivan. 06/10/26 14:38
ZorroGPT
by TipmyPip. 06/10/26 13:07
Z12 live performance
by alx. 06/09/26 20:42
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (Quad, TipmyPip, pr0logic), 2,041 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Student_64151, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Variables persisting between run() calls? #467976
09/12/17 01:13
09/12/17 01:13
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
I imagine I could write a list of variable values to a file at the end of each run(). Then I could read them back in at the beginning of the next run(), and so have persisting variable values.

Is there a better, more convenient way to achieve that in Zorro?

Re: Variables persisting between run() calls? [Re: Hredot] #467978
09/12/17 04:18
09/12/17 04:18
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
If you define your variables as static, their values will persist between runs.
So instead of
Code:
int test = 0;


you define it as
Code:
static int test = 0;



This is explained a bit more on this page in the manual:
http://www.zorro-trader.com/manual/en/aarray.htm

Re: Variables persisting between run() calls? [Re: Dalla] #467979
09/12/17 04:26
09/12/17 04:26
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Thank you for the answer!

I'm a bit confused. Aren't static variables... well... static? Which means they cannot change? In which case we do not have to worry about passing the value between the run() calls, since the hard coded value never changes anyways.
Perhaps I am getting this wrong though.
In any case, I would like to have dynamic variables that change over time persist between run() calls. Is there a nice way of doing that?

Last edited by Hredot; 09/12/17 04:27.
Re: Variables persisting between run() calls? [Re: Hredot] #467980
09/12/17 04:31
09/12/17 04:31
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
No, not in that sense. (which I know is a bit confusing)
Try it out, it think you will find it does exactly what you describe :-)

Re: Variables persisting between run() calls? [Re: Dalla] #467981
09/12/17 04:44
09/12/17 04:44
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Wow, yes, the link you referred to also points out global variables.
I think that is exactly what I need, thank you for pointing it out.
(Somehow I was under the impression that Zorro only allows the user to write stuff in the run() function but not outside. Having access to global variables solves the issue, of course! :] )


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1