First I apologize for my level of English, he is not good. My level of programming is not better either.
I have prepared a formula to rank companies taking into account their Icb classification. I have already finished the whole list.
When I pass the Explore on it, I find errors in the total of some of the codes. In the image that I am putting, you can see that the scan gives a correct result for the code "20103020 Cannabis Producer" (7 companies) but incorrect for the code "20103015 Pharmaceuticals" (he says that there is only 1 value and really I I have more than 200).
I have checked in the forum what the problem may be but I cannot find the answer. I would be very grateful if someone can guide me in finding a solution.
_SECTION_BEGIN("");
// correctly classified ICB list
listIcb = CategoryGetSymbols(categoryICB, StrToNum(IcbID(0)));
// Create the full list of stocks to be ranked
List = listIcb;
ListQty = StrCount(List, ",") + 1;
StockName = FullName();
NameSect = IcbID(2);
Filter =1;
SetSortColumns(-4);
AddTextColumn ( StockName, "Name ", 1.2);
AddTextColumn (NameSect, "Sector Icb ", 1.2);
AddColumn (ListQty, "Stocks", 1.2);
_SECTION_END();
Thanks for answering.
I have looked at your recommendation "About floating point arithmetic" but I can't find the answer.
I may not have explained the situation well.
I have classified a large number of companies by the Icb, when I put for example the explore on the Icb 65 Utilities (in that classification I have a total of 184 companies) the result is the following:
20103015 has eight digits.
Please read that KB article again and output
stn = StrToNum("20103015");
via printf. You will see 20103016.
Another thing to keep in mind is that 32-bit floating point number has only 7 significant digit
Here is one possible solution
/// get all symbols being in same ICB category as of selected symbol
/// @link https://forum.amibroker.com/t/icb-code-ranking/25969/6
EnableTextOutput(0);
iid = StrExtract(IcbID(2), 0, ' ');
stn = StrToNum(StrLeft(iid, 6));
sym_list = CategoryGetSymbols(categoryIcb, stn);
printf( "\n%s", sym_list);
for ( i = 0, list = ""; (symbol = StrExtract(sym_list, i, ',')) != ""; i++ ) {
SetForeign( symbol );
if ( InIcb(iid) ) list += symbol +",";
RestorePriceArrays();
}
list = StrTrim(list, ",");
printf( "\n%s", list);