[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [amibroker] Re: Greybeard Topic - Sorting and Ranking Arrays



PureBytes Links

Trading Reference Links

Ken,

 

This could be generalized even more but it suffices for proof of concept with two metrics.

 

You can do the rest …

 

AB = CreateObject("Broker.Application");

AA = AB.Analysis;

WL = AA.Filter(0, "WatchList");

 

WLSyms = CategoryGetSymbols(categoryWatchlist, WL);

 

rsSymNo = rsScore = rsiSymNo = rsiScore = rocSymNo = rocScore = Cum(0);

rsScore[0] = rsiScore[0] = rocScore[0] = 1e100;

 

procedure Rank_Sym (rsSymNoX, rsScoreX)

{

    rsSymNo  = IIf(rsScoreX > rsScore, IIf(rsScoreX <= Ref(rsScore, -1), rsSymNoX,  Ref(rsSymNo, -1)), rsSymNo);

    rsScore  = IIf(rsScoreX > rsScore, IIf(rsScoreX <= Ref(rsScore, -1), rsScoreX,  Ref(rsScore, -1)), rsScore);

}

 

if (Name() == StrExtract(WLSyms, 0))

{

    WLQty = 0;

    for (i = 0; (Symbol = StrExtract(WLSyms, i)) != ""; i++)

    {

        WLQty = WLQty + 1;

        SetForeign(Symbol);

        RSIx = SelectedValue(RSI(14));

        ROCx = SelectedValue(ROC(C, 14));

        RestorePriceArrays();

 

        rsSymNo = rsiSymNo;

        rsScore = rsiScore;

        Rank_Sym (i, RSIx);

        rsiSymNo = rsSymNo;

        rsiScore = rsScore;

 

        rsSymNo = rocSymNo;

        rsScore = rocScore;

        Rank_Sym (i, ROCx);

        rocSymNo = rsSymNo;

        rocScore = rsScore;

    }

    for (i = 1; i <= WLQty; i++)

    {

        StaticVarSet("RSI_Rank_" + NumToStr(RSISymNo[i], 1.0), i);

        StaticVarSet("ROC_Rank_" + NumToStr(ROCSymNo[i], 1.0), i);

    }

}

 

for (i = 0; i <= 1000; i++)

{

    if (Name() == StrExtract(WLSyms, i))

        break;

}

 

RSI_Rank = StaticVarGet("RSI_Rank_" + NumToStr(i, 1.0));

ROC_Rank = StaticVarGet("ROC_Rank_" + NumToStr(i, 1.0));

Tot_Rank = RSI_Rank + ROC_Rank;

 

Filter = BarIndex() == SelectedValue(BarIndex());

AddColumn(RSI_Rank, "RSI", 1.0);

AddColumn(ROC_Rank, "ROC", 1.0);

AddColumn(Tot_Rank, "Tot", 1.0);

 

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Ken Close
Sent: Saturday, May 10, 2008 7:41 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Re: Greybeard Topic - Sorting and Ranking Arrays

 

Droskill: Thanks for your suggestion. I did not explain exactly what I
am trying to accomplish, so this is a little away from my objective.

As I put in another reply (to Tomasz) on this subject,

"What I need to achieve is equivalent to using the Excel Function RANK,
which allows the specification of a Range (a column for say, stochastics for
100 funds), then getting in another column the Ordinal Position of that
ticker relative to all others for the result of stochastics. Then, another
column might have an indicator, say RSI14, and another column using RANK
that shows the Ordinal Position of each RSI value for all tickers. I then
take a final column and say, sum the two ordinal values for each ticker to
get a Master Ranking column. My situation is more complex than this (more
columns and a more complex combining method) but this is the basic idea.

This can all be done in Excel, but a tremendous labor saving step is to
accomplish it all in AB. Imagine trying to do this on 1000s of stocks on a
daily or even hourly basis."

Thus, I am left with trying to manipulate the various columns, perhaps with
an ATC for each column, but the looping I envision will be necessary will
likely make this kind of an approach too slow.

Another way to get to a master ranking of ordinal positions of two or more
indicators is to take each indicator and multiply them together for each
ticker (RSI times stochastics times etc) and use the overall product as a
ranking "score". However, the Ordinal Position for each intermediate
indicator has appeal in a display that others look at, even as all issues
are sorted by this so-called MasterRanking parameter. Thus this
multiplication route, while it "might" work, loses some functionality from
the overall output.

I appreciate you making the suggestion. Any other ideas?

Ken

-----Original Message-----
From: amibroker@xxxxxxxxxps.com [mailto:amibroker@xxxxxxxxxps.com] On Behalf
Of droskill
Sent: Friday, May 09, 2008 5:19 PM
To: amibroker@xxxxxxxxxps.com
Subject: [amibroker] Re: Greybeard Topic - Sorting and Ranking Arrays

I'll take a different tact - let me assume you just want to display the
ranking on the screen rather than a backtest - so that's an Exploration.

Here's quick sample Exploration - I'm not saying there is any value to these
measurements - they are for demonstration only.

MAShort = MA (C,20);
MALong = MA (C,100);
PS = ROC(C,250);
MAps = MA(PS,50); //Do a calculation based on another number

BuySignal = MAShort > MALong;
SellSignal = MAShort < MALong;

Filter = Status("lastbarinrange"); //Filter to only show last bar AddColumn(
BuySignal,"Buy"); AddColumn( SellSignal,"Sell"); AddColumn( C, "Close");
AddColumn( MAShort,"MAShort"); AddColumn( MALong,"MALong"); AddColumn(
PS,"PositionScore"); AddColumn( MAps,"MA of PS"); SetSortColumns(-3); //this
sets the sorting column

--- In amibroker@xxxxxxxxxps.com, "Ken Close" <ken45140@xx.> wrote:
>
> It has been fun to search the yahoo archives back to 2002 and see
names of a
> lot of the original folks who got on the Amibroker bandwagon back in
> the early days, many of whom are no longer around (at least not
> posting like they used to). Boy, how the program has evolved and
> improved over these many years.
>
> I was looking back there in the archives for messages on the Osaka
Plugin
> (which is still on my hard drive since 2002 but which I have never
used).
> Maybe now......
>
> I have a need to take a watchlist and position rank several columns of
> calculations and determine the postion rank of the ticker for that
> calculation; then do the same for another column (calculation), get
> the position rank for that additional column, and then combine the
> position ranking numbers for the columns for each ticker, sort of to
> get a Master ranking parameter.
>
> My question is: what new features in AB might help accomplish this?
Surely
> the Osaka Plugin (2002 vintage) is not the only way to do what I
want. I
> have not really studied nor used Static and Dynamic variables---is
this the
> set of commands that I would use with looping to get position ranks of
> a watchlist?
>
> I did find and just tested some code from the Library which used
just these
> tools (variables and looping) and it was painfully slow and would
not really
> work for the application I have in mind. I am uncertain if the code
in that
> example can be modified to make it faster.
>
> Any suggestions about this age-old question/problem, given the many
advances
> of Amibroker since 2002??
>
> Thanks for any ideas (the more specific the better).
>
> Ken
>

------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to SUPPORT {at}
amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

No virus found in this incoming message.
Checked by AVG.
Version: 8.0.100 / Virus Database: 269.23.14/1425 - Release Date: 5/9/2008
12:38 PM

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___