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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, SBGuy, TipmyPip, ozgur), 923 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 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,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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