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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, 7th_zorro, Ayumi), 926 guests, and 2 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
Extract init variables from main program #487443
04/25/23 14:06
04/25/23 14:06
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Hello,

I am making a research paper and looking for a way to easily change the input conditions to demonstrate the constancy of the investigated effect with massive input variations. To achieve this, I wanted to make a single file with the different versions that could store all the variables and changing parts of the code. It's not that simple, like changing just the main program, because the software is more complex, and I also extracted some functions that varies.

So I would make one single file that stores everything that varies, including variables and functions.
Like this:
#include <varies/v1.cpp>
and I can change it anytime for <varies/v2.cpp> or <varies/v152.cpp>

My problem is that there are some system variables that can only be defined in the main program before anything I call, for example, StartDate.
I would like to do something like this:

Code
DLLFUNC void run() {

	if (is(INITRUN)) {
		initRunSetup();
		...
	}
	....
}


The initRunSetup() is defined in the <varies/v1.cpp> like this:

Code
void initRunSetup(){
	StartDate = 20200101;
	EndDate = 20210101;
	...
}

...and also other vars and functions that varies and used by the main software...


But it doesn't work. If I don't set up StartDate in the main program's main block, then nothing happens; it just uses the default values.
How can I achieve this?

Thank you!

Re: Extract init variables from main program [Re: NorbertSz] #487444
04/25/23 15:10
04/25/23 15:10
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
Just put all of the variables in a struct, then save the struct as a file. File size is the size of that struct. Then load the file to the struct as neeeded.

Re: Extract init variables from main program [Re: AndrewAMD] #487462
04/30/23 09:06
04/30/23 09:06
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Thank you for the tip; that would work. Finally, I separated the variable parts into multiple files, and this way I can mix them more easily to produce the test cases. Like this:

Code
...
#include "var_tradingrules/8.cpp"
...
DLLFUNC void run() {
	
	//
	//	INIT RUN
	//

	#include "var_period/12.cpp"
	#include "var_asset/3.cpp"
	...
}

Last edited by NorbertSz; 04/30/23 09:10.
Re: Extract init variables from main program [Re: AndrewAMD] #487681
07/21/23 14:41
07/21/23 14:41
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Actually, you were right. It's much better to use your method, because that way we don't need to recompile the code every time a variable changes, and therefore we can automate the whole testing process by combining all the inputs with a PowerShell or a Batch script. I take this note for further readers who need the detailed solution.

First make a struct to store the settings:
Code
struct settings_data {
	int startDate;
	int endDate;
	std::string asset;
	int barPeriod;
	...
};
settings_data settings;


Then, in the main() function, you can load all the data into that struct.
For example if you are using file input like that:

Code
2018
2020
EURUSD
5
...


You can read it line by line like this:

Code
#include <string>
#include <fstream>
...
DLLFUNC void main() {
	std::string line;
	ifstream file("C:/zinput/input.txt");

	getline(file, line);
	settings.startDate = atoi(line.c_str()) * 10000 + 101;		//2018 => 20180101
	getline(file, line);
	settings.endDate = atoi(line.c_str()) * 10000 + 1231;		//2020 => 20201231
	getline(file, line);
	settings.asset = line;
	...
}


Or if you have Zorro S you can also use the command line arguments.
Now you can easily reach the settings it the run() function.
Code
DLLFUNC void run() {
	StartDate = settings.startDate;
	EndDate = settings.endDate;
	asset(settings.asset.c_str());
	BarPeriod = settings.barPeriod;
	...
}


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1