Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Strange error messages in for-loops #487333
03/20/23 11:05
03/20/23 11:05
Joined: Mar 2023
Posts: 14
Freiburg
Y
YesNotes Offline OP
Newbie
YesNotes  Offline OP
Newbie
Y

Joined: Mar 2023
Posts: 14
Freiburg
My scripts always have the same "syntax errors" whilst I can not find any actual syntax errors.
Here I created a small one as an example and would appreciate if anyone could point me to why there always are such errors in the for loops, like: " for(int i = 0; i < period; i++) "

The small sample-script is:
function run()
{
int period = 10; // Set the period for the SMA calculation
var sum = 0;
// Loop through the historical data and calculate the sum of closing prices
for(int i = 0; i < period; i++) // <- IN ALL SCRIPTS I ALWAYS GET AN ERROR IN THE FOR LOOPS HERE
{
sum += priceClose(i);
}
// Calculate the SMA by dividing the sum by the period
var sma = sum / period;
printf("SMA: %.2f", sma);
}

I apprecciate any help or pointers you can give me,
thank you.

Re: Strange error messages in for-loops [Re: YesNotes] #487335
03/20/23 13:29
03/20/23 13:29
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Lite-C does not allow you to declare int i where you did (initialization). Declare int i in a previous line.

Re: Strange error messages in for-loops [Re: AndrewAMD] #487336
03/20/23 15:24
03/20/23 15:24
Joined: Mar 2023
Posts: 14
Freiburg
Y
YesNotes Offline OP
Newbie
YesNotes  Offline OP
Newbie
Y

Joined: Mar 2023
Posts: 14
Freiburg
Thanks a lot, Andrew !
So do I get this right, that I should write:

int i = 0;
and then simply
for( i < period; i++)
?

PS:
And is there a way to get notify of the replies here by mail?
I nearly missed yours.

Re: Strange error messages in for-loops [Re: YesNotes] #487338
03/20/23 16:21
03/20/23 16:21
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Originally Posted by YesNotes
Thanks a lot, Andrew !
So do I get this right, that I should write:

int i = 0;
and then simply
for( i < period; i++)
?
Yes.
Originally Posted by YesNotes
And is there a way to get notify of the replies here by mail?
I nearly missed yours.
I don't know. I just lurk here a lot.

Re: Strange error messages in for-loops [Re: YesNotes] #487340
03/21/23 01:56
03/21/23 01:56
Joined: Mar 2023
Posts: 14
Freiburg
Y
YesNotes Offline OP
Newbie
YesNotes  Offline OP
Newbie
Y

Joined: Mar 2023
Posts: 14
Freiburg
Thank you for your help, Andrew.
Now I have this strange error I won't get rid of.
I isolated it into a one-line-script to eliminate potential other issues,
but this line ALWAYs throws an error, regardless how I call it:
Here just 4 samples of my attempts:
1.) datetime tradeTime = (datetime) iTime(NULL, 0);
2.) datetime tradeTime = Now;
3.) datetime tradeTime;
4.) datetime tradeTime = D'1970.01.01 00:00:00';

What's going on here in my system ?
(And remember - those 4 are only 1-liners, they are NOT together in a script.

Re: Strange error messages in for-loops [Re: YesNotes] #487341
03/21/23 12:54
03/21/23 12:54
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Those are MT4/MT5 functions and values. This is Zorro, not MT4/MT5. You need to read the Zorro manual to see what functions, and variables are available.

Read these:
https://zorro-project.com/manual/en/month.htm
https://zorro-project.com/manual/en/date.htm (check out the Now variable, which is an input, not an output)

Also, when Zorro outputs errors, you should read the errors, comprehend the errors, and revise your code based on what the errors say. If you must share your problems here, disclose the errors and your code for best results.
https://zorro-project.com/manual/en/trouble.htm

Re: Strange error messages in for-loops [Re: YesNotes] #487347
03/21/23 20:24
03/21/23 20:24
Joined: Mar 2023
Posts: 14
Freiburg
Y
YesNotes Offline OP
Newbie
YesNotes  Offline OP
Newbie
Y

Joined: Mar 2023
Posts: 14
Freiburg
Thank you Andrew, you are exceptionally helpful!
the thing is that I did not dare to push my script onto anyone<
so I only gave you the line the error code did mention.

But since you asked;
here is my script, and the syntax error in line 15 mentioned is:
for (int year = StartDate; year <= EndDate; year++)

Note that the error is actually not in that line but the opening bracket is supposed to be line 15
I don't see any syntax error.
Can you point me to my error?

Code
function run()
{
	StartDate = 2015;
	EndDate = 2022;
	BarPeriod = 1;
	LookBack = 1440;
	PlotScale = 15;	
	Commission = 0.6;
	Spread = 0.3*PIP;
	
	int start_time = 90009;
	int end_time = 100110;
	
	for (int year = StartDate; year <= EndDate; year++) 
	{ // <-- THIS IS ERROR LINE 15 !
		for (int week = 1; week <= 52; week++)
		{
			var time = 0;
			for (int day = 1; day <= 7; day++)
			{
				time = weekday(timeFromWeeks(year, week, day));
				if (time == MONDAY)
				{
					for (int hour = 9; hour <= 10; hour++)
					{
						for (int minute = 0; minute <= 1; minute++)
						{
							for (int second = 9; second <= 10; second++)
							{
								var bar_time = timeHour(time) * 10000 + timeMinute(time) * 100 + timeSecond(time);
								if (bar_time >= start_time && bar_time <= end_time)
								{
									// Do comparison here
									// Example: var close = priceClose(0);
									// var open = priceOpen(0);
									// if (close > open) { /* do something */ }
								}
								time = (time + 60); // Advance to next minute
							}
						}
					}
				}
			}
		}
	}
}


If you wonder what this script is about: It simply is a test whether I can compare two trading cycles from different times.

Last edited by YesNotes; 03/21/23 20:30. Reason: I tried to keep the script format
Re: Strange error messages in for-loops [Re: YesNotes] #487348
03/21/23 21:03
03/21/23 21:03
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Declare int before the for loop. You made the declaration error at least six times at six for loop statements.

Re: Strange error messages in for-loops [Re: AndrewAMD] #487370
03/24/23 12:20
03/24/23 12:20
Joined: Mar 2023
Posts: 14
Freiburg
Y
YesNotes Offline OP
Newbie
YesNotes  Offline OP
Newbie
Y

Joined: Mar 2023
Posts: 14
Freiburg
Thank you, Andrew.
I tried for days now to declare the variables right and always seem to have made it wrong, so I wrote the most simple script possible to figure out first only how to declare variables.
It simply shows the date and time.

Code
// Declare variables
int year = 2022;
int month = 3;
int day = 23;
int hour = 15;
int minute = 30;
int second = 0;

// Create datetime object
datetime myDateTime = date(year, month, day) + time(hour, minute, second);

// Print datetime object
printf("My date and time: %s", strdate(myDateTime));


Zorro 2.53.9 does throw, however following error:
Error in 'line 11:
syntax error
< datetime myDateTime = date(myYear, myMonth, myDay) + time((int)myHour, (int)myMinute, (int)mySecond); >.

Can you tell me what I am doing wrong?

Last edited by YesNotes; 03/24/23 12:20.

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