#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

### New Ranking and Percentile Composite Functions

Updated on 2010-10-19

While I was working on a new trading strategy that makes extensive use of ranking and composites, I stumbled upon something that at first sight seemed to be very difficult to implement. After few minutes I found a solution but it was too complicated. Besides, the previous step was to be repeated several times and I didn't want to use the same complicated solution each time. So I discarded this idea and thought about a way to add a feature in QS trading software in order to solve the problem in one single line. This is how I come up with two more calculation methods for the composite trading indicator.

These functions are named "rank!" and "percentile!" and they look pretty much like the "rank" and "percentile" functions (Trading Indicators using the Rank and Percentile functions) but there is a subtle difference. This difference lies in how "rank!" and "percentile!" treat symbols with the same values. In this case symbols will be given the same rank or percentile value, while using "rank" and "percentile", these symbols will be treated as if they have different values.
Here is an example:
On a particular date, we have 5 symbols with the following values:
Stock1 – 25
Stock2 – 22
Stock3 – 22
Stock4 – 29
Stock5 - 21

We will now apply the "rank" and "rank!" composite functions and see how the result is different.
Using the "rank" function we get the following result:
Stock4 – 1
Stock1 – 2
Stock2 – 3
Stock3 – 4
Stock5 - 5

Notice how stock4 gets a rank value of one because it has the highest value and more importantly how stock2 and stock3 get different ranks even if they exactly the same value.

And now let's perform the same calculation using the "rank!" function:
Stock4 – 1
Stock1 – 2
Stock2 – 3
Stock3 – 3
Stock5 - 4

The last rank value is now equal to four and stock2 and stock3 have the same rank value.

Concrete example using the new rank function

I am sure the above example was very helpful in understanding the difference between these rank functions and this is why I am going to use another example to explain a very important usage of the "rank!" function.
Let us implement the following trading strategy: Buy oversold stocks that belong to the top 3 industries based on the performance of the last month.

This isn't a very simple strategy but it is I think a great example to explain our new function. The problem here concerns ranking industries. We will not get the expected results if we use the classic "rank" function, because industry rank for each stock will be different (Two stocks with the same industry will get different industry ranks).
The problem can be easily solved by using "rank!" calculation method instead of "rank".

Strategy Formula:
os = rsi(14) < 30; // Oversold stocks
indperf = comp(perf(close, 25), "avg", industry()); // Calculate the average performance per industry
rankind = comp(indperf, "rank!"); // Calculate industry rank for each stock
buy = os AND rankind <= 2;

 Search Posts Recent Posts Chart Layouts Explained - With Custom Scripts Posted 1194 days ago Create Graphs using the Grid Tool Posted 1374 days ago Profile Graphs Posted 1479 days ago More about QuantShare Programming Language Posted 1558 days ago Backtest Trading Strategies Programmatically and on Schedule Posted 1704 days ago QuantShare Trading Software: New Features in the 3.7.0 Version Posted 1734 days ago Compare Multiple Securities in a Single Chart Posted 1794 days ago Previous Posts New Ranking and Percentile Composite Functions Posted 5072 days ago QS Trading Software: Database Optimization Posted 5079 days ago Stock Market Prediction with QuantShare Posted 5086 days ago Stock Market Prediction Posted 5093 days ago Trading Indicators using the Rank and Percentile functions Posted 5100 days ago How to Create Custom Metrics for Your Trading Positions Posted 5107 days ago How to search for a trading item Posted 5114 days ago How to create market indicators using the composite function - Part 3 Posted 5121 days ago How to create market indicators using the composite function - Part 2 Posted 5128 days ago Create a Pivot Table that displays the Relative Strength Index - RSI Posted 5142 days ago 6 Stock Trading Items Related to the New York Stock Exchange - NYSE Posted 5149 days ago Pivot Tables in QuantShare Trading Software Posted 5162 days ago How to create market indicators using the composite function - Part 1 Posted 5170 days ago

Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.