PureBytes Links
Trading Reference Links
|
Dave,
the topList in my code is a comma separated string.
If you run the exploration for more than one [the last or not] bars,
the string appears the same [this is the same for any AddTextColumn
result, as you probably know].
Of course, if you select another single day [say From 2/6/2004 To
2/6/2004] you will see the topList of this 2/6/2004.
It is easier in IB, paste the
list = CategoryGetSymbols( categoryWatchlist, 61 );
g=-100;t="";topList="";i1=0;
nt=5;// calibrate here the topX
for(n=1;n<=nt;n++)
{
for( i = 0; ( sym = StrExtract( list, i ) ) != "" ; i++ )
{
SetForeign(sym);
x=StochD();//the individual metric
t=WriteIf(x>g,sym,t);i1=IIf(x>g,i,i1);
g=Max(g,x);
}
topList=topList+t+",";L0="";
for( i = 0; ( sym = StrExtract( list, i ) ) != "" ; i++ )
{
SetForeign(sym);
L0=L0+ WriteIf(i!=i1,sym+",","");
}
List=L0;g=-100;
}
Title="The top"+WriteVal(nt,1.0)+"list for "+Date()+" is "+topList;
Put your cursor on a bar and you will have the topX list for that bar.
It is a good starting point for your further study.
Dimitris Tsokakis
--- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx>
wrote:
> Thanks for replying Dimitris; I was wondering when someone would
have a
> suggestion (:-).
>
> Unfortunately, unless I'm misunderstanding your code, it's not what
I meant.
> It's creating a single watchlist to work off, containing the top 5
tickers
> by StochD, but that list is the same for every bar.
>
> I'll try again to explain: Whenever there's uncommitted capital,
buy the
> stocks ranked the highest (by StochD for example) ON THAT DAY. So
first bar,
> I'd buy the 20 stocks with the highest StochD, and hold each of
them until
> it exits by a custom AFL rule based on entry price and time.
Whenever
> there's free capital, buy as many of the top StochD stocks as
there's room
> for in the position sizing.
>
> Make sense? When you buy, you're looking for the stocks ranked
highest THAT
> DAY, which will change every bar.
>
> I don't see how to do that in native AFL. I thought I'd seen an
example of
> something similar using the Osaka plugin (for its sorting
capability), but I
> don't know where.
>
> Any ideas, AFL or Osaka?
>
> Dave
> Dave,
> The following code will select from WL61 the top5 STOCHDs, then it
> will create
> a new topList and , finally, apply the trading system.
> You only need to explore *ANY* ticker for the n=1 last quotations
>
> list = CategoryGetSymbols( categoryWatchlist, 61 );
> g=-100;//SHOULD BE LOWER THAN ANY POSSIBLE METRIC VALUE
> t="";topList="";i1=0;
> nt=5;// calibrate here the topX
> for(n=1;n<=nt;n++)
> {
> for( i = 0; ( sym = StrExtract( list, i ) ) != "" ; i++ )
> {
> SetForeign(sym);
> x=StochD();//the individual metric
> t=WriteIf(x>g,sym,t);i1=IIf(x>g,i,i1);
> g=Max(g,x);
> }
> topList=topList+t+",";L0="";
> for( i = 0; ( sym = StrExtract( list, i ) ) != "" ; i++ )
> {
> SetForeign(sym);
> L0=L0+ WriteIf(i!=i1,sym+",","");
> }
> List=L0;g=-100;
> }
> /*The top5 list is already created, apply now the trading rules*/
> for(j=0;j<nt;j++)
> {
> global Buy;global Sell;
> TICKER=StrExtract(topList,j);
> SetForeign(TICKER,True,True);
> Buy=Cross(StochD(),50);Sell=Ref(Buy,-5);//the trading rules
> AddColumn(Equity(1,0),TICKER);
> }
> Filter=1;
> AddTextColumn(topList,"top"+WriteVal(nt,1.0)+"List");
> AddTextColumn(L0,"The rest");
>
> The topList is temporarily created for the exploration needs, if
you
> want to save the topList tickers for further use,
CategoryAddSymbol -
> CategoryRemoveSymbol will do the job.
> The clue is to find first the top ticker and then "subtract" it
from
> the comma separated string of the initial list.
> Unfortunately this "string subtraction" is not supported. We may
> write "MSFT,INTC,CSCO"+",BEAS", but we can not
write "MSFT,INTC,CSCO"-
> "CSCO".
> To solve this I find the ordinal # of the top ticker and replace
it
> with "". The remaining list will have one ticker less and, at this
> stage, we may repeat the top procedure.
> Some steps may be shorter but, DAX is opening...
> Dimitris Tsokakis
> --- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx>
> wrote:
> >
> > Say I wanted to buy the top 20 stocks ranked by ROC(C, 1), for
> example,
> > and sell with a custom exit somewhat like a trailing stop, one
that
> depends
> > on knowing the entry date and price.
> >
> > This is the only thing I could come up with, which won't do
it,
> because
> > the exit function won't know when buys actually occur according
to
> > PositionScore.
> >
> > Buy = 1;
> > PostitionScore = Max(ROC(C, 1), 0);
> > ExitLine = MyExitFunction();
> > Sell = Cross(ExitLine, C);
> >
> > Am I being clear? Is there a way to do this in native AFL?
> >
> > Thanks,
> >
> > Dave
> > A few more explanations would be required to know what you
are
> after.
> >
> > In both rotational and non-rotational mode you can buy top N
> stocks
> > if you code PositionScore variable according to your metric.
> >
> > > Does anyone have a non-rotational example of buying the
top N
> stocks
> > ranked
> > > by some metric? Far as I can see, that requires the Osaka
> plug-in,
> > which I'm
> > > not familiar with.
> > >
> > > Thanks,
> > >
> > > Dave Merrill
------------------------ 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/
|