# Separate ranks for categories that can be used in backtesting

https://www.amibroker.com/kb/2016/01/30/separate-ranks-for-categories-that-can-be-used-in-backtesting/

Can you help to modify this code so that the ranking is done for multiple weighted values?

In the example above ranking is done for just one values : ROC
And the top ROC stocks (that are in all the different sectors) receive the highest value in positionscore.

I want to add a second and third criterion by which the rank is done.
For example 33% criterion1 + 33% criterion2 + 33% criterion3

Thank you

All you have to do is change the assignment of the `values` variable in the example. Something like this should work:

``````wt1 = 0.33;
wt2 = 0.33;
wt3 = 0.33;
crit1 = ROC(C,10);
crit2 = ROC(C,20);
crit3 = ROC(C,50)
values = (wt1 * crit1) + (wt2 * crit2) + (wt3 * crit3);
``````

If you actually want to rank the three criteria independently and then weight the resulting ranks, then the solution would be a little more complicated.

2 Likes

Correct if i am wrong. If the criterions are homogeneus (like different variant of ROC) the method above could be a solution. But if we would weight different criterions (ROC, RSI, etc., with different order of magnitude) i thnk that the second method you proposed is the right solution. Honestly i was thinking to this second method and searching for an example of this one.

What you are referring to is called Multiple-Criteria Decision Analysis (MCDA) and need to research on Decision matrix.

To take the second approach, you would need two loops that iterate through all the symbols. in the first loop, you would generate the three different criteria and save each one to a static variable.

After that loop, you would call StaticVarGenerateRanks() three times, once for each criteria.

In the second loop, you would retrieve the three ranking values, combine them into a new weighted value, and save that value to a fourth static variable.

After the second loop, call StaticVarGenerateRanks() once more to get the final ranking.

3 Likes