Buy top ranked symbols first

Hello guys, I have coded a strategy in which stocks are traded on daily basis rank. I actually take 10 maximum positions and buy shares from top 10 tank. The problem is I want to buy stock which are ranked higher than other stocks means (stock which has rank 2 must be bought before stock of rank 9),but in afl (for loop work on symbol ) . what code should I add so that on same day stock with higher rank is bought first.

Start with reading the manual, ranking is explained in great detail there http://www.amibroker.com/guide/h_portfolio.html

By the way, reading Tutorial section http://www.amibroker.com/guide/tutorial.html answers 99.99% of questions you would ever have. All the information is on the plate in the docs.

After reading the manual, you can check dozens of already existing threads covering ranking by using FORUM SEARCH