Deducting an average derived from anything other than the values of the watch list in question (e.g. deducting average of S&P500) would still be prone to the same problem since the elements of the watch list might all be on the high side of the average and thus still all end up positive (or conversely all be on the low side and all end up negative).
Similarly, deducting an average of the watchlist itself would only be guaranteed to correctly handle the single long/single short scenario. If the strategy were to be expanded to handle 2 or more longs or 2 or more shorts, then a single extreme value could drag the average up/down such that only that single extreme value was above/below the average and the subsequent longs/shorts would never get recognized. If you're sure that you only ever want a single long and a single short, this can easily be accomplished by first running an AFL that uses AddToComposite with which to later derive an average in the main AFL on the second pass. The more robust solution would be to calculate the *median* value and subtract that from the individual ROC(C,NumBars)/ATR(250) values giving an equal number of positive results as negative results. You could then successfully employ your original logic for taking longs when > 0 and shorts when < 0 with the assurance that there will always be an equal number of each, thereby allowing any combination of longs and shorts. e.g. PositionScore = ROC(C,NumBars)/ATR(250) - MedianValue; Buy=FirstHourUp AND PositionScore > 0; Short=FirstHourUp AND PositionScore < 0; So, the question becomes how to get the median value? For that you would need to rank and sort the ROC(C,NumBars)/ATR(250) calculation across all members of the watch list, then pull out the value appearing in the center of the ordered list (if odd number of items in watch list) or the average of the two center items (if even number of items in watch list). So, how do you rank and sort across a watch list? You can refer to the following link for a solution where there are not too many items in the list: http://finance.groups.yahoo.com/group/amibroker/message/126400 Mike --- In [email protected], "vlanschot" <[EMAIL PROTECTED]> wrote: > > One way of solving this would be to deduct an average ROC from some > aggregate index from each of your individual scores, e.g. if your > stocks belong to the S&P500, deduct its ROC from each of your > individual ROCs (you can also create one yourself). You are correct > in using the new functionality to seperate your shorts from your > longs via the MaxOpenLong and MaxOpenShort functions. > > Hope this helps. > > PS > > --- In [email protected], "claudecaruana" <claudecaruana@> > wrote: > > > > Hi, > > > > Actually the code I supplied on my original message already does > > this.. Works ok if the positionscores for each iteration contain > both > > positive and negative values. If they are all positive or all > negative > > the code below would fail. > > > > BR > > C > > --- In [email protected], "Joe" <j0etr4der@> wrote: > > > > > > Hi, > > > > > > This bit me, too. From the AFL Reference Manual, section on Using > > > Position Score, "...AmiBroker will use the absolute value of > > > PositionScore variable to decide which trades are preferred." > > > > > > Try this (untested): > > > > > > PS = ROC(C,NumBars)/ATR(250); > > > PositionScore = PS; > > > . > > > . > > > . > > > Buy=FirstHourUp AND PS > 0; > > > Short=FirstHourUp AND PS < 0; > > > > > > > > > Good luck, > > > > > > Joe > > > > > > > > > > > > --- In [email protected], "claudecaruana" <claudecaruana@> > > > wrote: > > > > > > > > hi All, > > > > > > > > I am trying to implement a very simple intraday system using > > > > PositionScore, which buys the strongest symbol at a particular > time > > > > and shorts the weakest. Exit is at some particular time later. > > > > > > > > I am using ROC to determine strength. The code below works fine > when > > > > the symbols backtested have mixed positive and negative ROC's, > but if > > > > on a particular day all ROC's are positive, the short trade is > missed > > > > and vice versa for all ROC's negative. > > > > > > > > I think I understand why this is happening, however I cannot get > > > > around solving it! > > > > > > > > Here is the code: (I am using V5.17) > > > > > > > > FirstHourUp = IIf (TimeNum() == 103000,True,False); > > > > numbars=13; > > > > > > > > SetOption("SeparateLongShortRank", True ); > > > > SetOption("MaxOpenPositions", 2); > > > > SetOption("MaxOpenLong", 1 ); > > > > SetOption("MaxOpenShort",1); > > > > > > > > PositionScore = ROC(C,NumBars)/ATR(250); > > > > > > > > Buy=FirstHourUp AND PositionScore > 0; > > > > Short=FirstHourUp AND PositionScore < 0; > > > > > > > > Sell = TimeNum() == 113000; > > > > Cover = TimeNum() == 113000; > > > > > > > > > > > > Note: If I replace the buy/sell lines with the following: > > > > > > > > Buy=FirstHourUp ; > > > > Short=FirstHourUp ; > > > > > > > > then I get no short signals at all. I am not sure why. > > > > > > > > Any ideas on what I can do to resolve the issue? > > > > > > > > Thanks for any feedback, > > > > Claude > > > > > > > > > >
