Hi, If you are only allowed to have 3 open positions, then set max number of positions to 3 in the AA window settings and simply write your code to set PositionScore to the % change. AmiBroker will do the rest.
If, however, you are allowed to hold many positions, but only want to take on a max of 3 *new* postions each day, then Message #114739 may be helpful. http://finance.groups.yahoo.com/group/amibroker/message/114739? threaded=1&l=1 - Store the % change as the PositionScore then follow the rest of the code provided. - If you do not have a fixed number of open positions that you are allowed to carry, then replace in the custom backtester logic the line: posScores = IIF(minPos, Foreign("~Position" + minPos, "X", 0), 9999); // Highest possible score! with: posScores = Foreign(~Position3, "X", 0); // Top 3 scores You can read the rest of the thread to see how Tomasz solved the same issue by changing the strategy logic and avoiding having to save the sorted position scores in composites. The code I first posted is generic and does not require changing any strategy logic, but it is much less efficient than Tomasz's. Note, the code will take on more than 3 positions if there are ties. To restrict it to only 3 (even if multiple signals are tied for 1st, 2nd, or 3rd place), then add a counter in the signal loop, incrementing whenever you accept a signal, and stop taking positions (i.e. set sig.PosSize = 0) once your counter gets to 3. Mike --- In amibroker@yahoogroups.com, "tradinghumble" <[EMAIL PROTECTED]> wrote: > > I have simple system that generate some signals and I believe I can > code it in AB, but then I'd like to choose only the top 3 stocks with > the largest % increase in a certain group of stocks (which had the > signal).... something like > > 1st Step: > Select stocks from a list (example: SP500) that have have for example > MACD+ > > 2nd Step: > From the list of stocks that have the signal on step #1, I'd like to > select the top 3 stocks with the biggest % change in the day... > > Again, I can code step two but not sure how to go about step # 2? > > Can anyone help by pointing to an example or giving some ideas? Thank > you so much. >