PureBytes Links
Trading Reference Links
|
<FONT face=Arial color=#0000ff
size=2>Stephane, the earlier code was written before i knew how to run loops
within the QuickAFL bounds. Please turn off QuickAFL to verify the code and then
modify the loops to work under QuickAFL. Attached a simpler version, scored by
Close for testing. It appears to list the stocks according to the stocks C
pricem you can modify this code. You can coompare with a simple explore.
h<SPAN
class=734414600-04082004>erman<SPAN
class=734414600-04082004>
// Explore<SPAN
class=734414600-04082004><FONT
size=2>Buy=Sell=Short=Cover=<FONT
color=#ff00ff>0;Filter = <FONT
color=#ff00ff>1;AddColumn(C,<FONT
color=#ff00ff>"C",1.2);
<FONT face=Arial color=#0000ff
size=2>
global
Top5TickerList, Tickercount ;function GetScore( Ticker, Barnum
) { return C; // substitute your own scoring
formula. }
<FONT face=Arial color=#0000ff
size=2>function getPositionScores( WatchList, BarNum, NumTickers
) { TickerList= GetCategorySymbols( categoryWatchlist,
WatchList); CurrentTicker = Name(); TickerScoreList =
""; global Top5Index, Top5Scores; for( n=0;
(Ticker=StrExtract( TickerList, n)) != "";
n++) { SetForeign(Ticker); TickerScores[n]
= LastValue(ValueWhen(BarIndex() == BarNum, GetScore( Ticker, BarNum
))); TickerIndex[n] = n; }
<FONT face=Arial color=#0000ff
size=2> TickerCount= n;
<FONT face=Arial color=#0000ff
size=2> 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; } } }
<FONT face=Arial color=#0000ff
size=2> Top5TickerList =
""; i=0; for(m=TickerCount; m>TickerCount-NumTickers;
m--) { Top5Index[(BarCount--)-6] =
TickerIndex[m]; T5[i++] =
TickerIndex[m]; Top5TickerList = Top5TickerList +
StrExtract(Tickerlist,T5[i-1])+","; }
<FONT face=Arial color=#0000ff
size=2> SetForeign( "QQQ" ); return T5
; }
<FONT face=Arial color=#0000ff
size=2>getPositionScores( 1, BarCount-1, 5 );Title =
Top5TickerList+" "+NumToStr(TickerCount,1.0);
<FONT face=Tahoma
size=2>-----Original Message-----From: Stephane Carrasset
[mailto:s.carrasset@xxxxxxxxxxx]Sent: Tuesday, August 03, 2004 7:29
PMTo: amibroker@xxxxxxxxxxxxxxxSubject: Re: [amibroker]
average of top ranked tickers in a given
watchlistHerman ,Ok i'll try it and come back
on this subject in few days. it that represents for me one of the
key of a EOD winning trading system.I send the attachment comparing osake
hermann and manual.Thanks for your help.>
Stephane,>> The simplest way to debug any code is to insert
_TRACE() statements inside> the loops and use DebugView. That way you
will get a complete report > of each> step through the code and
each step through each loop.>>
herman>>>> -----Original
Message-----> From: Stephane Carrasset
[mailto:s.carrasset@xxxxxxxxxxx]> Sent: Tuesday, August 03,
2004 2:38 PM> To:
amibroker@xxxxxxxxxxxxxxx> Subject: Re: [amibroker] average
of top ranked tickers in a given>
watchlist>>> Hermann &
All,>> I have tried two differents codes to built an
average of top n tickers> of a watchlist ( looks like
a real time composite)> unfortunately the two codes return
wrong results.>> I have tried your code and a
Tomasz code written with osaka plugin (> the formulas are
below )> I have reduced The watchlist zero to 5
tickers and want the average> for an idicator of the
3 first tickers for each bar.> I have choosen the RSI ( a
positive indicator)> So i can check manually the
result>> for example the image attached speak
itself for the last bar .>> I hope the next
pastis.dll will save us... ^_^ ( thanks dingo for
all> these
information)>>>>>
FORMULAS>>
//////////OSAKA////////////> /*> As for
hints: you would do the following:> 1. iterate through
watch list and store scores (in case of osaka plugin>
osTabSetNumber)> 2. find top ranked symbols (this can be
done even entriely in AFL as> Dimitris has
shown,> or using Osaka plugin sort capability - osTabSort
function)> 3. create average from top ranked
symbols.> Below is the code that uses Osaka plugin
1.4.>> */>>
osInitialize();> List =
GetCategorySymbols(categoryWatchlist, 0 ); // <-- change
wl> number here>
table=osTabCreate();> // setup columns>
osTabAddColumn( "Ticker", 2, table, 25 );> for( j = 0; j
< BarCount; j++ )> {> osTabAddColumn(
"Score"+j, 1, table );> osTabAddColumn( "Close"+j, 1, table
);> }> // CALCULATING SCORES and saving
them to the table> for(i=0; ( ticker = StrExtract( List, i
) ) != ""; i++)> {>
SetForeign(ticker);> osTabSetString( ticker, i, 0, table
);> score = RSIa(C,14); // YOUR SCORE CALCULATION
HERE> for( j = 0; j < BarCount; j++)>
{> osTabSetNumber( abs( Nz( score[ j ] ) ), i, 2 * j + 1,
table );> osTabSetNumber( Close[ j ], i, 2 * j + 2, table
); // for calculation of> average>
}> }> // you can export for
debugging> // osTabExport( "test.csv", ",", table
);> // SORTING SCORES AND finding top
ranks:> average = 0; // init avarage>
for( j = 0; j < BarCount; j++)> {>
osTabSort( table, 2 * j + 1, False );> average[ j ] =
0;> topnum = 3; // TOPNUM> for( k = 0; k
< topnum ; k++ ) //> {> fc =
osTabGet( k, 2 * j + 2, table );> average[ j ] = average[ j
] + fc;> }> average[ j ] = average[ j
]/topnum; // calculate average from top N> symbols at given
bar> }> osTabDelete( table
);> Filter=1;> AddColumn(average, "AVG
top10 (each bar different)" );> Plot( average, "AVG top10
(each bar different)", colorRed );>> ///////////END
OSAKA //////////////////////////>>>
///////////////HERMAN/////////////////> function GetScore(
)> {> return RSIa(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",3,0,100,1);> // TOPNUM>
getPositionScores( WatchList, BarNum, NthScore );>
TopTickerScore =StaticVarGet("TopTickerScore ");>
TopTickerList=StaticVarGet("TopTickerList");> TopTickerNum
=StaticVarGet("TopTickerNum ");>
Plot(VarGet("TopComposite") ,"",2,1);>> Title
=> TopTickerList + "\n"+> TopTickerScore
+ "\n"+> TopTickerNum + "\n"+> "Number
"+NumToStr(NthScore+1,1.0)+" from the Top:>
"+StrExtract(TopTickerList ,NthScore);>
//////////////////END
HERMAN/////////////////////////////>>>>>
Check AmiBroker web page at:> <A
href="">http://www.amibroker.com/>>
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.
|