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

RE: [amibroker] Ranking Symbols by Ordinal Value Then Summing and ReRanking



PureBytes Links

Trading Reference Links

Ken,

 

The code I provided summed the ordinals …

 

The output was in Explore …

 

Single and/or multiple columns can be sorted in ascending or descending sequence in AA …

 

Was there some reason you wanted to be able to do more than this programmatically ?

 

Fred

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Ken Close
Sent: Friday, May 23, 2008 3:14 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Ranking Symbols by Ordinal Value Then Summing and ReRanking

 

This is a revisit to code which FredT provided which:

Takes two indicatorss, ranks and then assigned ordinal values to each of the indicators according to their sorted value, and then sums the ordinal values together.

 

The code works fine and I have been able to extend it to numbers of indicators.

 

The last remaining task for me is to take the SUM of the ordinal values of the indicators and RANK this sum and assign an Ordinal Value to the Sum.

 

The pasted code below contains the section where I tried to do the ranking and sorting of the Sum of the Ordinal Values of the other indicators.

No errors occur and when I run this, I get ordinal values in the ComboRank column, but they are not sorted by Sum from minimum to maximum.

 

I asked about variables in combination AFL and COM objects in another message and got no reponses, probably because it is too basic a question to respond to.  SetVar is used to transfer values between COM object loops and AFL statements is what I think the answer is.  Yet rereading Tomasz message of 124022, I now think that this entire code is a COM object (Analysis Object is called in second line).  Yet how to manipulate the variables to get an extension of the logic which Fred set up.

 

Is there anyone who could offer some help on this.  This code actually could prove useful to some who wanted to do some ranking (by ordinal values).

 

Thanks,

 

Ken

 

Code by FredT with mods by me....

 

AB = CreateObject("Broker.Application");

AA = AB.Analysis;

 

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

 

WLSyms = CategoryGetSymbols(categoryWatchlist, WL);

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

rsSymNo = rsiSymNo = rocSymNo = rsScore = rsiScore = rocScore =

TOTSymNo = TOTScore =    ////These symbols added for Ranking of Sum of Ordinal Ranks

Cum(0) - 99999999;

rsScore[0] = rsiScore[0] = rocScore[0] = TOTScore[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 = SelectedValue(RSI_Rank + ROC_Rank);

 

//////////////////////////////////////////////////////////

//   Add code to rank Tot_Rank

//////////////////////////////////////////////////////////

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

      {

         WLQty = 0;

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

         {

            WLQty = WLQty + 1;

 

            rsSymNo = TOTSymNo;

            rsScore = TOTScore;

            Rank_Sym (i, Tot_Rank);//Seems like Tot_Rank is not getting sorted

            ToTSymNo = rsSymNo;

            TOTScore = rsScore;

         }

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

            {

               StaticVarSet("TOt_Rank_" + NumToStr(TOTSymNo[i], 1.0), i);

            }

      }

 

Tot_Rank_RANK  =  StaticVarGet("TOT_Rank_" + NumToStr(i, 1.0));

 

/////////////  End of Ranking Total Rank ///////////////////

 

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

RSIn = SelectedValue(RSI());

 

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

AddColumn(RSI_Rank, "RSI", 1.0);

AddColumn(ROC_Rank, "ROC", 1.0);

AddColumn(Tot_Rank, "Tot", 1.0);

AddColumn(Tot_Rank_RANK,"ComboRank", 1.0);

AddColumn(ROCn, "ROC", 1.3);

AddColumn(RSIn,"RSI()",1.3);

 

 



I am using the free version of SPAMfighter for private users.
It has removed 459 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
__._,_.___

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

__,_._,___