NumBars == 0 in INITRUN. Intended?

Posted By: GPEngine

NumBars == 0 in INITRUN. Intended? - 10/01/14 14:35

http://zorro-trader.com/manual/en/mode.htm
INITRUN
First run of the script, before the price data is loaded. Can be used to initialize global and static variables.

NumBars
Total number of bars in the simulation, determined from StartDate and EndDate and from the available data in the price history files.
http://zorro-trader.com/manual/en/numbars.htm

I want NumBars to be initialized in INITRUN.
so I can malloc arrays that are based on the size of the test period.

As I work-around, I need to wait for the second bar (SECONDRUN ?) before NumBars has a useful value.
Code:
function run() {
  static var* final_report_data = NULL;
  if (is(INITRUN)) {
  } else {
    if (final_report_data == NULL) {
      final_report_data = malloc(NumBars * sizeof(var));
      memset(final_report_data, 0, NumBars * sizeof(var));
    }
  }
  ...
  if (final_report_data != NULL) {
     final_report_data[x] = ...
  }
}

Posted By: jcl

Re: NumBars == 0 in INITRUN. Intended? - 10/01/14 15:00

Yes. As you can not initialize a variable before knowing its content, your code is the best and correct way for allocating the array.
© 2024 lite-C Forums