Variable scope

Posted By: First

Variable scope - 01/03/19 03:59

If I set variables in the 1st execution of the run() function, will the variables retain their 1st run values on subsequent runs of the run() function or do I need to somehow make them global so they cannot be changed between subsequent runs of the run() function?
Posted By: AndrewAMD

Re: Variable scope - 01/03/19 04:15

Use static to retain latest value, else it is lost once it goes out of scope.
Posted By: First

Re: Variable scope - 01/03/19 04:24

I am using static, however, I set the value after its initalization in the 1st run of the the run() function.

On subsquent runs of the run() function as set by the BarPeriod = 30, will Price be zero or the value from priceHigh() set in the first iteration of the run() function?

I need it to be the value from priceHigh() in the first iteration.

In the run() function:

static var Price = 0;

Price = priceHigh();

© 2024 lite-C Forums