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

Re: [amibroker] New Notepad



PureBytes Links

Trading Reference Links

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 --------------------~--> 
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/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/