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

[amibroker] Re: Index trend coding



PureBytes Links

Trading Reference Links

Hello,

Anything is possible with AB.  

The following might be of interest to you:

//Sector Analysis composite creation by Jayson Casavant
Buy=0;
newhigh=H>Ref(HHV(H,10),-1); //stocks making new high
newlow=L<Ref(LLV(L,10),-1); //Stocks making new low
up=C>Ref(C,-1);
dn=C<Ref(C,-1);
upvol=IIf(up,V/C,0);
dnvol=IIf(dn,V/C,0);
x=SectorID(0);
sym="~"+SectorID(1);
isym="~i"+SectorID(1);
Ad="~AD"+SectorID(1);
AddToComposite(C,sym ,"C"); //adds Close data to sector
AddToComposite(V/1000,sym,"V"); // adj vol overflow
AddToComposite(1,sym,"O"); //counts stocks
AddToComposite(IIf(newhigh,1,0),sym,"H");//counts new highs
AddToComposite(IIf(newlow,1,0),sym,"L");//Counts new Lows
//creates a master index of stocks under study
AddToComposite(C,"~Universe" ,"c"); 
AddToComposite(V/1000,"~Universe" ,"v"); 
AddToComposite(1,"~Universe" ,"O"); 
AddToComposite(newhigh,"~Universe","H");
AddToComposite(Newlow,"~Universe","L");
//creates master index of OHLC data 
AddToComposite(C,"~Index","C");
AddToComposite(O,"~Index","O");
AddToComposite(H,"~Index","H");
AddToComposite(L,"~Index","l");
AddToComposite(1,"~index","V");//counts stocks in index
//creates index by sector
AddToComposite(C,isym,"C");
AddToComposite(O,isym,"O");
AddToComposite(H,isym,"H");
AddToComposite(L,isym,"L");
AddToComposite(1,isym,"V"); 
//creates advance /decline by sector composite
AddToComposite(up,Ad,"C");
AddToComposite(dn,Ad,"O");
AddToComposite(upvol,Ad,"H");
AddToComposite(dnvol,Ad,"L");
 

//Sector Relative Strength Comparative by Jayson Casavant
Filter=C>0;
x=RelStrength("~index");
RSC=LinRegSlope(x,7);
AddColumn(IIf(rsc>0,BarsSince(rsc<=0),BarsSince
(rsc>=0)),"Cross",1.0);
AddColumn(RSC,"Today RSC",1.2,colorDefault,IIf(RSC==0,colorBlue,IIf
(rsc>Ref(rsc,-1),colorGreen,colorRed)));
AddColumn(Ref(RSC,-1),"Yesterday RSC",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-1)>=Ref(rsc,-
2),colorGreen,colorRed)));
AddColumn(Ref(RSC,-2),"2 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-2)>=Ref(rsc,-
3),colorGreen,colorRed)));
AddColumn(Ref(rsc,-3),"3 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-3)>=Ref(rsc,-
4),colorGreen,colorRed)));
AddColumn(Ref(rsc,-4),"4 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-4)>=Ref(rsc,-
5),colorGreen,colorRed)));
AddColumn(Ref(rsc,-5),"5 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-5)>=Ref(rsc,-
6),colorGreen,colorRed)));
AddColumn(Ref(rsc,-6),"6 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-6)>=Ref(rsc,-
7),colorGreen,colorRed)));
AddColumn(Ref(rsc,-7),"7 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-7)>=Ref(rsc,-
8),colorGreen,colorRed)));
AddColumn(Ref(rsc,-8),"8 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-8)>=Ref(rsc,-
9),colorGreen,colorRed)));
AddColumn(Ref(rsc,-9),"9 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-9)>=Ref(rsc,-
10),colorGreen,colorRed)));
AddColumn(Ref(rsc,-10),"10 days",1.2,colorDefault,IIf
(RSC==0,colorBlue,IIf(Ref(rsc,-10)>=Ref(rsc,-
11),colorGreen,colorRed))); 

//Sector AD Jayson Casavant
GraphXSpace=15;
pds=Param("Smoothing Periods",11,1,20,1);
Ad="~AD"+SectorID(1);
ADissues=Foreign(Ad,"C");
Dissues=Foreign(Ad,"O");
Advol=Foreign(Ad,"h");// High vol
Dvol=Foreign(Ad,"l");//low vol
addecvol=EMA(Sum(advol,pds),pds)-EMA(Sum(dvol,pds),pds);
Plot(addecvol,"AD VOL",IIf(addecvol>0,5,4),2);
Plot(EMA(adissues,pds)-EMA(dissues,pds),"A/d",1,1|styleOwnScale);
PlotGrid(0,colorWhite);


Title=SectorID(1)+ " Sector Advance/Decline"+"\n Advancing Issues "
+WriteVal(EMA(Adissues,pds),1.0)+" Declining Issues
"+WriteVal(EMA(dissues,pds),1.0);

symbol="~i"+SectorID(1);
sy=Wilders(RSIa((Foreign(symbol,"C")/Foreign(symbol,"V")),14),2);

Plot(sy,"",ParamColor("Sector Color",5),1);
pds=Param("RSI Periods",14,5,20);
Plot(RSI(pds),"",8);
stock=LinRegSlope(RSI(pds),pds);
istock=LinRegSlope(sy,pds);

GraphXSpace=10;
Plot(Trix(9)-MA(Trix(9),9),"Trix",IIf(Trix(9)-MA(Trix(9),9)
>0,colorLightGrey
,colorRed),2|styleOwnScale);

Title=WriteIf(stock>0 AND istock<0,"Stock and Index Divergence (Stock
Rising)","")+ WriteIf(istock>0 AND stock<0,"Stock AND Index 
Divergence
(Index Rising)","")+ "\n RSI of "+ symbol+ " Sector"+ EncodeColor(5)
+ "\n
Sector" +WriteVal(sy)+EncodeColor(8)+"\n Stock RSI"
+WriteVal(RSI(pds))+EncodeColor(colorWhite)+" Rel strength Comp "+
WriteVal( LinRegSlope(RelStrength(symbol),10));

I would appreciate if you could throw some sample code you have come 
up with and we could all expand on it.  Just a thought...

rgds, Pal

--- In amibroker@xxxxxxxxxxxxxxx, "Brian" <brian@xxxx> wrote:
> Hello everyone,
> 
> Is it possible to build a single exploration that will scan stocks 
> for buy/sell signals AND ALSO at the same time scan an index 
> [using "SetForeign("$SPX")" for example] for other buy/sell 
signals 
> as well?
> 
> How about if I want the index buy/sell signals to look across 
> multiple timeframes of an indicator (for example, the daily AND 
the 
> hourly stochastic for the SPX are both below 20 at the same time)?
> 
> What if I want to do all of the above, but with multiple indexes 
> (for example, the SPX and VIX, at the same time)?
> 
> It would be great if someone could throw some sample code for 
doing 
> this at me. I've tried doing this a few times, and was about to 
take 
> another stab at it, but thought I would ask you folks first. I've 
> been writing code all week, and finally need some help.
> 
> Thanks,
> 
> Bman



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/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/