PureBytes Links
Trading Reference Links
|
Hermann,
What a Nice code... respect !!
of course I'll check it,
But right Now time to Pastis and others pleasures.
Stephane
----- Original Message -----
From: Herman van den Bergen
To: amibroker@xxxxxxxxxxxxxxx
Sent: Sunday, August 01, 2004 1:29 PM
Subject: RE: [amibroker] average of top ranked tickers in a given watchlist
Hello Stephane,
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!
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();
}
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);
------------------------------------------------------------------------------
-----Original Message-----
From: Stephane Carrasset [mailto:s.carrasset@xxxxxxxxxxx]
Sent: Sunday, August 01, 2004 5:33 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [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
list = GetCategorySymbols( categoryWatchlist, listnum );
Rank=0;
MyInd=CCIa(C,14);
for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
{
Rank = Rank + IIf(MyInd<=CCIa(Foreign( sym, "C", False ) , 14),1,0);
VarSet("Ranked"+i,Rank);
}
average=0;
Top=5;
for( j = 0; ( sym = StrExtract( list, j ) ) != ""; j++ )
{
average=IIf(VarGet("Ranked"+j)< Top ,CCIa(Foreign( sym, "C", False ) , 14),0) + average;
}
Plot(average,"",6,1);
GraphXSpace=10;
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: 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
a.. To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
b.. To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
__________ NOD32 1.829 (20040801) Information __________
This message was checked by NOD32 antivirus system.
http://www.nod32.com
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~->
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
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:
http://docs.yahoo.com/info/terms/
|