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
1 registered members (Edgar_Herrera), 1,111 guests, and 1 spider.
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
Page 1 of 2 1 2
How to sort current values of multiple series #449410
03/19/15 10:53
03/19/15 10:53
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
I have several separate series that I am using to measure volatility. I'd like to sort the current values of each series in ascending order and pick out the five highest values for use in another function.

What is the best way to accomplish this in Lite-C?

I've tried passing the current value of each series to an element in an array (myarray[] = {series1[0], series2[0], ... , series12[0]} and then using the qsort function:

Code:
#include <stdio.h>
function run()
{
var myarray[] = {2, 6, 1, 9, 52, 3};
qsort(myarray, 6, 8, compare);	
}



This returns an error that seems to originate in stdio.h:

Error in 'stdio.h' line 228:
'API' undeclared identifier
< API(_fsopen,msvcrt)
>.

Can anyone suggest what I'm doing wrong, or a better approach to this problem?

Thanks in advance

Re: How to sort current values of multiple series [Re: boatman] #449414
03/19/15 14:25
03/19/15 14:25
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline
User
GPEngine  Offline
User
G

Joined: Sep 2013
Posts: 504
California
You are correct that you should not sort the series in place
however my guess is that you have not discovered http://zorro-trader.com/manual/en/sortdata.htm

Re: How to sort current values of multiple series [Re: GPEngine] #449423
03/19/15 22:19
03/19/15 22:19
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Hi GP

I had looked at the sortData function, but since its argument is a series rather than single values from multiple series, I assumed it wasn't applicable for my case. Are you implying that I should create a series out of the values I want to sort and then pass that to the sortData function? I will give that a try.

Cheers

Re: How to sort current values of multiple series [Re: boatman] #449428
03/20/15 05:58
03/20/15 05:58
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline
User
GPEngine  Offline
User
G

Joined: Sep 2013
Posts: 504
California
When including something
#include <stdio.h>
you must also always include
#include <default.c>
FIRST

default.c is only implicitly included if there are no other includes. yep.

So try
#include <default.c>
#include <stdio.h>

function run() {
...
}

Last edited by GPEngine; 03/20/15 06:09.
Re: How to sort current values of multiple series [Re: GPEngine] #449430
03/20/15 06:40
03/20/15 06:40
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
That's great, thanks for the tip. Now I just need to work out how to use the qsort function. Any ideas how to include the 'compare' argument (the code below is the sort code from stdio.h)?

void qsort(
void *base, // array to be sorted
int num, // number of elements
int width, // element size
void* compare //int (__cdecl *compare)(void* element1,void* element2)

Also, I am having a go at the sortData function you mentioned above. I'm pretty sure I can achieve what I want to achieve, but no doubt my code will be highly inefficient. I'll post it once I'm done and would really appreciate any critiques.

Cheers

Re: How to sort current values of multiple series [Re: boatman] #449437
03/20/15 14:57
03/20/15 14:57
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline
User
GPEngine  Offline
User
G

Joined: Sep 2013
Posts: 504
California
Well, if it's efficiency you're concerned about... rub hands together
Since you only need the top k values where k << N , you don't need to sort the whole list. O(N log N). You can use
  • Partial selection sort O(Nk)
  • max-heap of k elements. O(N + k log N)
As for the compare function did you try something like qsort translated to lite-c?

Re: How to sort current values of multiple series [Re: GPEngine] #449438
03/20/15 15:51
03/20/15 15:51
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline
User
GPEngine  Offline
User
G

Joined: Sep 2013
Posts: 504
California
jcl,
add lines like these to every header file in your include/.
Code:
#ifndef API
INCLUDE_DEFAULT_C_FIRST  // intentional compile failure
#endif


That way Boatman would have at least seen a clue in the cryptic compiler error
Code:
sort compiling..
Error in 'stdio.h' line 231: 
'INCLUDE_DEFAULT_C_FIRST' undeclared identifier

and maybe not needed to waste a day in the forums.

Re: How to sort current values of multiple series [Re: GPEngine] #449441
03/20/15 17:24
03/20/15 17:24
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
This error message would probably not be seen as less cryptic. But we'll include <default.c> in all headers - that should solve the problem.

Re: How to sort current values of multiple series [Re: jcl] #449463
03/21/15 05:16
03/21/15 05:16
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline
User
GPEngine  Offline
User
G

Joined: Sep 2013
Posts: 504
California
That solution is so simple I figured there must have been a technical reason for not doing it. It took more effort than that for you to write the remark about it on http://www.zorro-trader.com/manual/en/include.htm

iwyu, bro.

Re: How to sort current values of multiple series [Re: GPEngine] #465611
05/05/17 18:34
05/05/17 18:34
Joined: Dec 2014
Posts: 204
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 204
Germany
I'm trying to use sortData with no success.

What am I doing wrong?

Code:
function main()
{
	var Data[6] = {1,7,10,0,12,19};

	
	sortData (var* Data,6);      //syntax error!
	
	
	for (int i=0, i<6, i++)
	{
		printf("n%d, "Data[i]);
	}
	
	
}




I'm working on a support and resistance indicator. The array will contain price values later on. This is why I declared the array as "var".

Page 1 of 2 1 2

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