Hi, After rereading your original question, I may have sent you on a wild goose chase. You don't really need to persist all the PositionScores as is being done in the referenced thread. That was to handle the placing of a subset of *conditional* orders (i.e. limit orders) that may not have resulted in fills (i.e. backtester Signals).
The referenced thread would probably still work for you, but it's a sledgehammer for a thumbtack and would be unnecessarily slow. Since you will be placing a subset of orders which are not conditional (i.e. absolutely buy at open the top 2 symbols from previous night's scan, right?), you could probably just write custom backtester code to iterate through the actual Signals at each bar to identify the top 2 PosScore values. Then, iterate through again, and blank out (set to 0) the PosSize of the Signals that have a PosScore less than the ones identified. You would need to have a count to make sure that you didn't inadvertantly take too many Signals, in the case where multiple signals tied for first or second place. Similarly, you would have to ensure that you didn't take 2 tied second place finishers rather than the first place finisher and one of the second place finishers. I'd offer a code sample, but I don't have AmiBroker on this computer and will not be in front of one that does for at least a day. If you don't figure it out, let me know and I'll have a crack at it. Mike --- In amibroker@yahoogroups.com, "tradinghumble" <[EMAIL PROTECTED]> wrote: > > --- In amibroker@yahoogroups.com, "Mike" <sfclimbers@> wrote: > > > > 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" <sharp2be@> > > 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. > > > > > > > Wow, that's a lot to digest for a simple coder like me :-) -- thanks > Mike .. one other thing, I'd like my system to take only two positions > per day (as it's an EOD system), any way to limit it as well? > > Thanks again. >