Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, juanex, Grant), 1,018 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
NumBars == 0 in INITRUN. Intended? #445987
10/01/14 14:35
10/01/14 14:35
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
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] = ...
  }
}


Re: NumBars == 0 in INITRUN. Intended? [Re: GPEngine] #445989
10/01/14 15:00
10/01/14 15:00
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
Yes. As you can not initialize a variable before knowing its content, your code is the best and correct way for allocating the array.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1