Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 552 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Reseting a static variable - the next day #475673
01/03/19 02:46
01/03/19 02:46
Joined: Jan 2019
Posts: 12
F
First Offline OP
Newbie
First  Offline OP
Newbie
F

Joined: Jan 2019
Posts: 12
I have a script that is set to begin in 2005 ending in 2017.
It obviously will run every day and on each day run it's run() function based on a BarPeriod = 30.

In the run() function, I'm setting a static variable to a price to be set the 1st run of the script on each day.
This static variable is then used in comparisons for each barPeriod of 30 bars.

In the run() function (code is purposely vague):

static var StaticPrice1 = 0;
var Price2 = 0;

If someTime is sometime {
StaticPrice1 = xxxx(); // setting the static Price for use in subesquent runs on this day.
}


Price2 = xxxxx();

if(Price2 > StaticPrice1) {
do something
}


I want the static variable to retain it value (after being set by a return value of a a function) so as to be used for subsequent runs of the run() function for the day but then be reset to the price of the next days 1st run of the script.

How do I do that?

Last edited by First; 01/03/19 05:10.
Re: Reseting a static variable - the next day [Re: First] #475708
01/04/19 14:52
01/04/19 14:52
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
There is a status flag, NEWDAY, that you can use for this.
So basically just do
Code:
if (is(NEWDAY)) {

}



This returns true if "The current bar is the first bar of the current day."

Last edited by Dalla; 01/04/19 14:52.
Re: Reseting a static variable - the next day [Re: Dalla] #476026
01/19/19 18:48
01/19/19 18:48
Joined: Aug 2018
Posts: 98
O
OptimusPrime Offline
Junior Member
OptimusPrime  Offline
Junior Member
O

Joined: Aug 2018
Posts: 98
Thanks Dalla!


Thanks so much,

OptimusPrime


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1