PureBytes Links
Trading Reference Links
|
Hello
Stephane,
<FONT face=Arial color=#0000ff
size=2>
I
think your code needs to sort the tickers according to Rank...Here is a
snip of my code, since it is a cut/adjusted to your needs pleae verify the
result. Since the results are on the screen that should be easy. Note
that as-is the text displays the top stocks at the cursor
position!
<FONT face=Arial color=#0000ff
size=2>
<FONT face=Arial color=#0000ff
size=2>herman
function GetScore(
) { return CCIa(C,14); // Substitute your
function }
function padString( InString, Length
) { SpaceFill =
" "; SL =
StrLen(InString); NS=StrLeft(SpaceFill, Length-SL); return
NS+Instring; }
procedure getPositionScores(
WatchList, BarNum, NumTickers ) { TickerList=
GetCategorySymbols( categoryWatchlist, WatchList); CurrentTicker =
Name(); TickerScoreList = "";
// Create Scores
array for( n=0; (Ticker=StrExtract( TickerList, n)) != "";
n++) { SetForeign(Ticker); TickerScores[n] =
LastValue(ValueWhen(BarIndex() == BarNum, SelectedValue(GetScore())));
TickerIndex[n] = n; }
TickerCount= n;
// Sort Tickers by
rank for(i = n; i>=0; i--) { for (j = 1; j <=
i; j++) { if (TickerScores[j-1] >
TickerScores[j]) { temp =
TickerScores[j-1]; TickerScores[j-1] = TickerScores[j]; TickerScores[j] =
temp; temp = TickerIndex[j-1]; TickerIndex[j-1] =
TickerIndex[j]; TickerIndex[j] = temp; }
} }
TopTickerList =
TopTickerNum = TopTickerScore = ""; i=0; P=10; TopComposite =
0; if( NumTickers > TickerCount ) NumTickers =
TickerCount;
// Format Top numTickers and
create composite for(n=TickerCount; n>=TickerCount-NumTickers;
n--) { T5[i++] = TickerIndex[n]; TopTickerList =
TopTickerList + PadString(StrExtract(Tickerlist,T5[i-1]),P)+",";
TopTickerScore = TopTickerScore +
PadString(NumToStr(TickerScores[n],1.3),P)+","; TopTickerNum =
TopTickerNum + PadString(NumToStr(TickerIndex[n],1.0),P)+",";
TopComposite = TopComposite + getScore(); }
<FONT face=Arial color=#0000ff
size=2> VarSet("TopComposite",TopComposite/numtickers); StaticVarSetText("TopTickerList",TopTickerList); StaticVarSetText("TopTickerScore
",TopTickerScore ); StaticVarSetText("TopTickerNum ",TopTickerNum
); }
WatchList =
Param("WatchList",0,0,1,1);BarNum = SelectedValue(BarIndex());NthScore =
Param("Nth TickerDown",5,0,100,1);getPositionScores( WatchList, BarNum,
NthScore );TopTickerScore =StaticVarGet("TopTickerScore
");TopTickerList=StaticVarGet("TopTickerList");TopTickerNum
=StaticVarGet("TopTickerNum ");Plot(VarGet("TopComposite")
,"",4,1);
Title =TopTickerList +
"\n"+TopTickerScore + "\n"+TopTickerNum + "\n"+"Number
"+NumToStr(NthScore+1,1.0)+" from the Top: "+StrExtract(TopTickerList
,NthScore);
<FONT face=Tahoma
size=2>-----Original Message-----From: Stephane Carrasset
[mailto:s.carrasset@xxxxxxxxxxx]Sent: Sunday, August 01, 2004 5:33
AMTo: amibroker@xxxxxxxxxxxxxxxSubject: [amibroker]
average of top ranked tickers in a given watchlist
Hello,
I would like to know if the code below is correct .
the purpose is to create the average of top ranked tickers in
a given watchlist
Stephane
listNum=0
;//enter watchlist number <FONT
size=1>
list = GetCategorySymbols<FONT
size=1>( categoryWatchlist, listnum );
Rank=0;
MyInd=CCIa<FONT
size=1>(C,14<FONT
size=1>);
for( i = <FONT color=#ff00ff
size=1>0; ( sym = <FONT color=#0000ff
size=1>StrExtract( list, i ) ) != <FONT
color=#ff00ff size=1>""; i++ )
{
Rank =<FONT
face="Courier New" size=1> <FONT
size=1>Rank + IIf<FONT
size=1>(MyInd<=CCIa<FONT
size=1>(Foreign( sym,
"C", False ) ,
14),<FONT
color=#ff00ff size=1>1,<FONT color=#ff00ff
size=1>0);<FONT face="Courier New"
color=#0000ff size=1>
VarSet(<FONT
face="Courier New" color=#ff00ff size=1>"Ranked"<FONT
face="Courier New" size=1>+i,Rank);
}
average=0<FONT
face="Courier New" size=1>;
Top=5<FONT
face="Courier New" size=1>;
for( <FONT face="Courier New"
size=1>j = 0<FONT
size=1>; ( sym = StrExtract<FONT
size=1>( list, j )
) != ""; <FONT
face="Courier New" size=1>j++ )
{
average=<FONT face="Courier New" color=#0000ff
size=1>IIf(<FONT
face="Courier New" color=#0000ff size=1>VarGet<FONT face="Courier New"
size=1>(<FONT face="Courier New" color=#ff00ff
size=1>"Ranked"+j)< Top
,<FONT color=#0000ff
size=1>CCIa(<FONT color=#0000ff
size=1>Foreign( sym, <FONT color=#ff00ff
size=1>"C", False ) , <FONT color=#ff00ff
size=1>14),0<FONT
size=1>) + average<FONT
size=1>;
}
Plot(<FONT face="Courier New"
size=1>average,<FONT color=#ff00ff
size=1>"",6<FONT
size=1>,1);
GraphXSpace=10<FONT
size=1>;Check AmiBroker web page at:<A
href="">http://www.amibroker.com/Check
group FAQ at: <A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Sponsor
ADVERTISEMENT
Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
|