Reseting a static variable - the next day

Posted By: First

Reseting a static variable - the next day - 01/03/19 02:46

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?
Posted By: Dalla

Re: Reseting a static variable - the next day - 01/04/19 14:52

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."
Posted By: OptimusPrime

Re: Reseting a static variable - the next day - 01/19/19 18:48

Thanks Dalla!
© 2024 lite-C Forums