Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Different result in main() and run() #487350
03/22/23 02:05
03/22/23 02:05
Joined: Mar 2023
Posts: 11
D
DisplayName Offline OP
Newbie
DisplayName  Offline OP
Newbie
D

Joined: Mar 2023
Posts: 11
Hi,
can anyone explain why I get different output, if I call the function main() or run()?
Code
int count;
function main() //run()
{
	vars MySeriesArrayX = series(); 
	vars MySeriesArrayY = series(); 
	if (count!=1){
		int x;
		for(x=0; x<5; x++) {
			MySeriesArrayX[x] = 20220101+x;
			MySeriesArrayY[x] = x+0.1;
		}
		
		int date;
		for(x=0; x<5; x++){		
			date = MySeriesArrayX[x];
			printf("\n date: %d",date);
			printf("\n number: %f",MySeriesArrayY[x]);
			
		}
		count=1;
	}
}


If it is called main() the output is correct:

date: 20220101
number: 0.100000
date: 20220102
number: 1.100000
date: 20220103
number: 2.100000
date: 20220104
number: 3.100000
date: 20220105
number: 4.100000


If it is called run() date returns the int of number:

date: 0
number: 0.100000
date: 1
number: 1.100000
date: 2
number: 2.100000
date: 3
number: 3.100000
date: 4
number: 4.100000

I edited the code to the core problem.
If I comment out the count and the if-case, then it is wrong in the first 'run' of run() and after that it shows also correct results.

Thanks for any help.



Last edited by DisplayName; 03/22/23 12:40.
Re: Different result in main() and run() [Re: DisplayName] #487351
03/22/23 14:06
03/22/23 14:06
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
First of all, series() was designed to be used in run(), not main().

Second, during INITRUN, series() only returns a dummy buffer. So you're writing to the same buffer for both arrays.

Read the documentation for series():
https://zorro-project.com/manual/en/series.htm
Quote
Since the LookBack value is normally only known after the INITRUN, series are allocated in the FIRSTRUN. During the INITRUN they are set to a temporary pointer and filled with the initial value. This temporary content is overwritten by the series allocation in the FIRSTRUN. Series are only valid during the session and released after the EXITRUN.

An internal counter determines the pointer to be returned by a series() call. For keeping the counter in sync with the series calls, they are restricted to the run function or a function that is called from the run function, and must be always in the same order. Therefore series calls cannot be skipped by if or other conditions that change from bar to bar (see example below). If the content of a series shall depend on if conditions, set the [0] element dependent on if. These restrictions also apply to all functions that internally create series, such as some indicator or signal processing functions. Zorro detects wrong series calls and will display an error message in this case.

For accessing the same series from several functions, declare a global vars, and set it with a series call in the run function.

Re: Different result in main() and run() [Re: AndrewAMD] #487352
03/22/23 15:26
03/22/23 15:26
Joined: Mar 2023
Posts: 11
D
DisplayName Offline OP
Newbie
DisplayName  Offline OP
Newbie
D

Joined: Mar 2023
Posts: 11
Thanks for your reply!
I have already read the manual about series and also tried it with global variables.

In this case I always get Error 111: Crash in run: run()

Mybe I did not understand what exactly is meant with 'set it with a series call' and what the correct syntax should look like.
Can you show me an example?

Re: Different result in main() and run() [Re: DisplayName] #487353
03/22/23 17:01
03/22/23 17:01
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Show me the code with the error.

Re: Different result in main() and run() [Re: AndrewAMD] #487354
03/22/23 17:18
03/22/23 17:18
Joined: Mar 2023
Posts: 11
D
DisplayName Offline OP
Newbie
DisplayName  Offline OP
Newbie
D

Joined: Mar 2023
Posts: 11
Belive me I work since 4 nights on this little piece of code.
I can show you tons of not working examples. Do you want to see them all? I tried nearly everything.
Now I don't know what else I can do. So I'm looking for some help.
Is it a tremendously huge problem to say look this 3 lines of code are an example for a correct series call?
I would then adapt my code and post it, if it's not working.

Re: Different result in main() and run() [Re: DisplayName] #487355
03/22/23 17:28
03/22/23 17:28
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Post the code that confuses you the most, and I will comment.

Re: Different result in main() and run() [Re: DisplayName] #487356
03/22/23 18:09
03/22/23 18:09
Joined: Mar 2023
Posts: 11
D
DisplayName Offline OP
Newbie
DisplayName  Offline OP
Newbie
D

Joined: Mar 2023
Posts: 11
Oh, it seems to be a tremendously huge problem.
But no problem, for me all of them are looking good. Have a look on it.
Please tell me in detail for each example what 's the problem. And if you like you can also give marks.
Just tell me if you want to see more examples.

Eg1
Code
int count;
vars MyGlobalArray[1]; 

function load()
{	
	MyGlobalArray[0] = series();
	MyGlobalArray[1] = series();
	int x;	
	for(x=0; x<5; x++) {
		(MyGlobalArray[0])[x] = 20220101+x;
		(MyGlobalArray[1])[x] = x+0.1;
	}
}

function run()
{
	vars MySeriesArray[1];
	MySeriesArray[0] = series(); 	
	MySeriesArray[1] = series(); 
	if (count!=1){
		load();
		int x;
		int date;
		for(x=0; x<5; x++) {
			(MySeriesArray[0])[x] = (MyGlobalArray[0])[x];
			(MySeriesArray[1])[x] = (MyGlobalArray[1])[x];
		}

		for(x=0; x<5; x++){		
			date = (MySeriesArray[0])[x];
			printf("\n date: %d",date);
			printf("\n number: %.4f",(MySeriesArray[1])[x]);
			
		}
		count=1;
	}
}


Eg2
Code
int count;
vars MyGlobalArray[1]; 

function load()
{	
	MyGlobalArray[0] = series();
	MyGlobalArray[1] = series();
	int x;	
	for(x=0; x<5; x++) {
		(MyGlobalArray[0])[x] = 20220101+x;
		(MyGlobalArray[1])[x] = x+0.1;
	}
}

function run()
{
	vars MySeriesArray[1]; 
	if (count!=1){
		load();
		int x;
		int date;
		for(x=0; x<5; x++) {
			(MySeriesArray[0])[x] = (MyGlobalArray[0])[x];
			(MySeriesArray[1])[x] = (MyGlobalArray[1])[x];
		}

		for(x=0; x<5; x++){		
			date = (MySeriesArray[0])[x];
			printf("\n date: %d",date);
			printf("\n number: %.4f",(MySeriesArray[1])[x]);
			
		}
		count=1;
	}
}


Eg3
Code
int count;
vars MyGlobalArray[1]; 

function load()
{	
	MyGlobalArray[0] = series();
	MyGlobalArray[1] = series();
	int x;	
	for(x=0; x<5; x++) {
		(MyGlobalArray[0])[x] = 20220101+x;
		(MyGlobalArray[1])[x] = x+0.1;
	}
}

function run()
{
	vars MySeriesArray[1]; 
	vars MySeriesArray[0] = series();
	vars MySeriesArray[1] = series();
	if (count!=1){
		load();
		int x;
		int date;
		
		MySeriesArray[0] = (MyGlobalArray[0];
		MySeriesArray[1] = (MyGlobalArray[1];

		for(x=0; x<5; x++){		
			date = (MySeriesArray[0])[x];
			printf("\n date: %d",date);
			printf("\n number: %.4f",(MySeriesArray[1])[x]);
			
		}
		count=1;
	}
}


Eg4
Code
int count;
vars MyGlobalArray[1]; 

function load()
{	
	MyGlobalArray[0] = series();
	MyGlobalArray[1] = series();
	int x;	
	for(x=0; x<5; x++) {
		(MyGlobalArray[0])[x] = 20220101+x;
		(MyGlobalArray[1])[x] = x+0.1;
	}
}

function run()
{
	vars MySeriesArray[1]; 
	if (count!=1){
		load();
		int x;
		int date;
		
		MySeriesArray[0] = (MyGlobalArray[0];
		MySeriesArray[1] = (MyGlobalArray[1];

		for(x=0; x<5; x++){		
			date = (MySeriesArray[0])[x];
			printf("\n date: %d",date);
			printf("\n number: %.4f",(MySeriesArray[1])[x]);
			
		}
		count=1;
	}
}


Eg5
Code
int count;
vars MySeriesArray[1]; 

vars load()
{	
	
	MySeriesArray[0] = series();
	MySeriesArray[1] = series();
	int x;	
	for(x=0; x<5; x++) {
			(MySeriesArray[0])[x] = 20220101+x;
		}
	for(x=0; x<5; x++) {
			(MySeriesArray[1])[x] = x+0.1;
		}
	return MySeriesArray; 	
}

function run() 
{
	vars MySeriesArrayX[0] = series(); 
	vars MySeriesArrayX[1] = series(); 
	if (count!=1){
		MySeriesArrayX = load();
		int x;	
		int date;
		for(x=0; x<5; x++){		
			date = (MySeriesArrayX[0])[x];
			printf("\n date: %d",date);
			printf("\n number: %f",(MySeriesArrayX[1])[x]);
			
		}
		count=1;
	}
}

Last edited by DisplayName; 03/22/23 18:19.
Re: Different result in main() and run() [Re: DisplayName] #487357
03/22/23 19:26
03/22/23 19:26
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
OK, there are so many problems here.

1) vars is a pointer to a buffer.
2) series() returns a pointer to an array created by Zorro.
3) vars MyGlobalArray[1]; creates an array of one pointer (which defeats the purpose of it being an array).
4) the manual was hinting at using an array of var (that is, doubles), not vars (pointers to doubles). And once you do, you have absolutely no reason to call series because you supplied an array.

OK, now try this. (Not tested, I don't have time):
Code
function run(){
	if(!Test){return quit("!Click [Test] to begin");}
	assetList("AssetsFix");
	asset("EUR/USD");
	vars MySeriesArrayX = series(0,-5); 
	vars MySeriesArrayY = series(0,-5); 
	if (!Init){
		int x;
		for(x=0; x<5; x++) {
			MySeriesArrayX[x] = 20220101+x;
			MySeriesArrayY[x] = x+0.1;
		}
		
		int date;
		for(x=0; x<5; x++){		
			date = MySeriesArrayX[x];
			printf("\n date: %d",date);
			printf("\n number: %f",MySeriesArrayY[x]);
			
		}
		return quit("!Done!");
	}
}

Re: Different result in main() and run() [Re: AndrewAMD] #487358
03/23/23 01:41
03/23/23 01:41
Joined: Mar 2023
Posts: 11
D
DisplayName Offline OP
Newbie
DisplayName  Offline OP
Newbie
D

Joined: Mar 2023
Posts: 11
Thank you and if one wants to keep it simple, the short answer was: use if(!Int) instead of if(count!=1).

I nearly do not dare to ask but the reason why I do this is because I want to compare the time stamp of the time series with my created dates.

So, how can I access my array during each run?

Last edited by DisplayName; 03/23/23 01:44.
Re: Different result in main() and run() [Re: DisplayName] #487359
03/23/23 02:02
03/23/23 02:02
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
remove the line:
return quit("!Done!");

And it will print it for every line except for during INITRUN. You skip INITRUN because series() returns a dummy buffer.

You dereference item x from MySeriesArrayX when you call MySeriesArrayX[x], as shown in the code.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1