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

Re: [amibroker] Need Sort Function to sort TickerList by Ticker-Value



PureBytes Links

Trading Reference Links

BlankHerman.

I use something like this.  It's been awhile since I looked at it, but I know it does work.

I think the two loops, together, sort a list of tickers (listtouse) by whatever value is specified in the variable sorttouse

Maybe this'll help?

chuck

///PROCEDURE TO SORT THE TICKERS BY TODAY CHANGE
procedure SORTWATCHLIST(ListToUse)
{

 // Create zero-based Scores array in wrt to current data
 for( j=0; (CurrentTicker=StrExtract( ListtoUse, j)) != ""; j++)
 {
   SortToUse = SelectedValue((GetTClose(CurrentTicker) - GetYClose(CurrentTicker)) / GetYClose(CurrentTicker) *100);
 TickerScore[j]  = SortToUse;
 TickerIndex[j]  = j;  //Index number of the Ticker
 }

TickerCount= j;

// Sort Tickers by index
for(i = TickerCount-1; i>=0; i--)
 {
 for (j = 1; j <= i; j++)
  {
  if (TickerScore[j-1] > TickerScore[j])
   {
   temp = TickerScore[j-1]; TickerScore[j-1] = TickerScore[j];
   TickerScore[j] = temp;
   temp = TickerIndex[j-1]; TickerIndex[j-1] = TickerIndex[j];
   TickerIndex[j] = temp;
   }
  }
 }

} //procedure



Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.7/618 - Release Date: 1/6/2007 7:47 PM