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 (AndrewAMD), 552 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Multicurrency Currency Strength [Re: JJ95] #486632
09/12/22 15:18
09/12/22 15:18
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
The original code uses standard C/C++ and is compiled into the Zorro executable. In standard C/C++, it is legal to declare an int in a for loop initialization, but not in Lite-C.

Re: Multicurrency Currency Strength [Re: AndrewAMD] #486633
09/12/22 15:33
09/12/22 15:33
Joined: Sep 2022
Posts: 13
J
JJ95 Offline OP
Newbie
JJ95  Offline OP
Newbie
J

Joined: Sep 2022
Posts: 13
Hello,

Thank you so much for your earliest reply.

Just out of curiosity, in the manual (https://zorro-project.com/manual/en/tutorial_var.htm), it mentions that we can switch from Lite-C to C++.

Quote:

"Zorro gives you the choice to develop strategy scripts either in lite-C, a 'lightweight' version of the C programming language, or in 'full grown' C++"

Do you know how to switch?

Re: Multicurrency Currency Strength [Re: JJ95] #486634
09/12/22 15:43
09/12/22 15:43
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago

Re: Multicurrency Currency Strength [Re: JJ95] #486662
09/15/22 09:53
09/15/22 09:53
Joined: Sep 2022
Posts: 13
J
JJ95 Offline OP
Newbie
JJ95  Offline OP
Newbie
J

Joined: Sep 2022
Posts: 13
Hello,

I am trying to run the code below in order to better understand assigning index to a currency name:

function main()
{
#define MAXCURRENCIES 32
var CStren[MAXCURRENCIES],CStrenSum[MAXCURRENCIES];
int CNum[MAXCURRENCIES];
char CNames[128];
int NumCurrencies = 0;

int ccyIdx(char* name)
{
char Ccy[4];
memcpy(Ccy,name,4);
Ccy[3] = 0;

for(int n=0; n<MAXCURRENCIES; n++)
{
if(!CNames[n*4])
{ // not yet stored
strcpy(CNames+n*4,Ccy);
NumCurrencies++;
return n;
}
if(strstr(CNames+n*4,Ccy))
return n;
}

return 0;
}

}

I am receiving the following error:

Error in 'line 14:
'name' undeclared identifier
memcpy(Ccy,name,4);

I kindly ask for some clarification

Re: Multicurrency Currency Strength [Re: JJ95] #486672
09/16/22 13:56
09/16/22 13:56
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Step 1 is to learn the C language. You cannot declare functions inside another function.

Re: Multicurrency Currency Strength [Re: JJ95] #486677
09/16/22 16:06
09/16/22 16:06
Joined: Sep 2022
Posts: 13
J
JJ95 Offline OP
Newbie
JJ95  Offline OP
Newbie
J

Joined: Sep 2022
Posts: 13
Hello,

Understood. I am trying to better understand C through learning the indicators source codes and applying them in my scripts. I grabbed a little of tips as I progress.

Regarding the assigning an index to a currency name. I can almost see the loop and the logic, yet it remains slightly unclear.

Code:
Code

#define MAXCURRENCIES	32
var CStren[MAXCURRENCIES],CStrenSum[MAXCURRENCIES];
int CNum[MAXCURRENCIES];
char CNames[MAXCURRENCIES*4];
int NumCurrencies = 0;

// assign an index to a currency name
int ccyIdx(char* name)
{
	char Ccy[4];
	memcpy(Ccy,name,4);
	Ccy[3] = 0; 
	for(int n=0; n<MAXCURRENCIES; n++) {
		if(!CNames[n*4]) { // not yet stored
			strcpy(CNames+n*4,Ccy);
			NumCurrencies++;
			return n;
		}
		if(strstr(CNames+n*4,Ccy))
			return n;
	}
	return 0;
}


I do not understand the !CNames[n*4] part.
The ! stands for not. I cannot see or understand the logic. How do we know if it is stored or not.

The way I am reading it at first is, if (CNames[0] is not, then copy the string from Ccy to CNames with a 0 etc)
But what is the logic and where is it written.
If the first element in the CName array is not what exactly?

Thank you so much for the help

Re: Multicurrency Currency Strength [Re: JJ95] #486678
09/16/22 17:47
09/16/22 17:47
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
It’s checking for null terminators at the beginning of each string.

Re: Multicurrency Currency Strength [Re: JJ95] #486692
09/18/22 17:08
09/18/22 17:08
Joined: Aug 2022
Posts: 65
alun Offline
Junior Member
alun  Offline
Junior Member

Joined: Aug 2022
Posts: 65
Think of this value in memory (0 is literal zero not the character for 0)

CNames = "EUR0USD0GBP00000"

n = 3
i = 3*4 = 12

CNames[12] == 0 <- true
!CNames[12] is !0 which is true as well


Last edited by alun; 09/18/22 17:10.
Re: Multicurrency Currency Strength [Re: JJ95] #486708
09/20/22 12:42
09/20/22 12:42
Joined: Sep 2022
Posts: 13
J
JJ95 Offline OP
Newbie
JJ95  Offline OP
Newbie
J

Joined: Sep 2022
Posts: 13
Greetings,

I would like to thank everyone who has replied to me (especially AndrewAMD).

I just wanted to ask a small question. In the earlier post it was mentioned that you cannot declare a function inside a function. I am assuming this referred to int ccyIdx(char* name) inside function main(). So how do we run the function ccyIdx(char* name) without function main()?

Re: Multicurrency Currency Strength [Re: JJ95] #486709
09/20/22 20:23
09/20/22 20:23
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Declare and define the functions outside of main and prior to main. Inside main, invoke the functions you defined.

Page 2 of 3 1 2 3

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