Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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