Help with sorting data array

Posted By: degenerate_762

Help with sorting data array - 05/18/22 10:23

Hi,
I am trying to sort a data array using the sort functions available in the manual. However, i cannot get it to sort and just returns zero on the plot. Could someone please bump me in the right direction?


Code
function run() 
{
	set(LOGFILE);
	BarPeriod = 15;
	StartDate = 2020;
	EndDate = 2021;
	LookBack = 1440;

	asset("EUR/USD");

	var* Data = series(price());
	var* Ranks;
	int Length = 50;

	int A2V = sortRank(var* Ranks, var* Data, int Length);
	int A3V = sortIdx(var* Data, int Length);
	int A4V = sortData(var* Data, int Length);
	
}


Thanks,
Posted By: degenerate_762

Re: Help with sorting data array - 05/18/22 11:13

The plots are as follows. sortData returns an error so i commented it out. Just trying to sort a series of prices in ascending or descending order.
Posted By: degenerate_762

Re: Help with sorting data array - 05/18/22 11:22

sortData error is "cannot convert void to long". commenting out the left hand side eliminates the error. Is there a way to return the sortData into an array? sortRank and sortIdx return 0 on the plots.
Posted By: Petra

Re: Help with sorting data array - 05/18/22 11:24

Plot is for vars. You cannot plot ints. Plotting an index makes no sense anyway since you will likely get a flat line.
Posted By: Grant

Re: Help with sorting data array - 05/18/22 11:26

You already declared Data, Ranks & Length, so why would you declare them again in the sort functions?
Posted By: degenerate_762

Re: Help with sorting data array - 05/18/22 11:30

Only findIdx returns a value other than 0. "Returns the index of the highest Data element below or equal to Value, or -1 when no such element was found. ". Ok!.

please bump me! for i have sinned and i know nothing.



Attached picture FS8_RTJWAAA6yp_.jpg
Posted By: degenerate_762

Re: Help with sorting data array - 05/18/22 11:51

@Petra, I see that sortIdx, sortRank , and findIdx return int* / int. Makes sense for plot to return a constant. Ok. what does sortData return? int, var, vars ? i get the error cannot convert void to long. also if they return integers, how would i get the sorted array? it returns an integer while the sorted array of size length is of interest.
Posted By: degenerate_762

Re: Help with sorting data array - 05/18/22 11:53

@Grant, thanks.
Posted By: degenerate_762

Re: Help with sorting data array - 05/18/22 12:03

@Petra, it returns int. plot the xxx as that it a vars. thanks
Posted By: Petra

Re: Help with sorting data array - 05/18/22 12:14

sortData returns nothing. It sorts the data. The other functions return the index array pointer.

When you look up a function in the manual, you can see if and what it returns after the function parameters. *int means it returns an int array.
Posted By: degenerate_762

Re: Help with sorting data array - 05/18/22 12:24

@Petra, lord forgive me for i have sinned.
© 2024 lite-C Forums