PureBytes Links
Trading Reference Links
|
I've been using AddToComposite to create various reference indices
and industry indices lately and I'm wondering what this statement
from the AB help file really means?
atcFlagResetValues = 1 - reset values at the beginning of scan
(recommended)
I occassionaly get corrupted values of zero in the middle of the
price arrays even though I try to correct for this. Usually it goes
away if I completely delete the data in my composite index and rerun
the composite calculation routine. I would really like to not have
to do this as its a manual process. I;d like it to be completely
automatic.
-ace
Here's my code. Maybe I'm doing something wrong. Feel free to use
it. It seems to work quite well.
//-------------------------------------------------------------
// INDUSTRY COMPOSITE CALCULATOR
//-------------------------------------------------------------
// AFL Script Version date 12/7/03
//-------------------------------------------------------------
// NOTES: Prior to running place your settings to this arrangement
// 1. Set the 'Apply to' filter to a watchlist containing one
// stock from each industry group and click 'use filter'
// 2. Set the 'Range' to 'n last quotations' where n=1
// 3. Run a 'Scan'
//-------------------------------------------------------------
function CreateIndustryAverage( listnum, price )
{
// retrieve comma-separated list of symbols in watch list
list = GetCategorySymbols( categoryIndustry, listnum );
Average = 0; // just in case there are no watch list members
m=0;
for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
{
Val = Nz(Foreign( sym, "Close" ));
n=Nz(IIf(Val!=0,1,0));
m=m+n;
f = Nz(Foreign( sym, price ));
if( i == 0 ) Average = Average;
else Average = Average + f;
}
// 'm' is the running total of the number of stocks in the
// group vs. time. This account for differing lengths of
// historical data by stock
return Average / m;
}
//-------------------------------------------------------------
// Create the industry averages and store the values in temporary
// price arrays
//-------------------------------------------------------------
indticker="~"+IndustryID(1);
IO=CreateIndustryAverage( IndustryID(0), "O" )*10;
IH=CreateIndustryAverage( IndustryID(0), "H" )*10;
IL=CreateIndustryAverage( IndustryID(0), "L" )*10;
IC=CreateIndustryAverage( IndustryID(0), "C" )*10;
IV=CreateIndustryAverage( IndustryID(0), "V" );
list = GetCategorySymbols( categoryIndustry, IndustryID(0) );
//-------------------------------------------------------------
// Get Running total for number of stocks in the group vs. time
//-------------------------------------------------------------
m=0;
for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
{
Val = Nz(Foreign( sym, "Close" ));
n=Nz(IIf(Val!=0,1,0));
m=m+n;
}
sf=1;
//-------------------------------------------------------------
// Create scale factors to correct for step changes in the
// number of stocks in the group
//-------------------------------------------------------------
for( i = 1; i<LastValue(Cum(IIf(m!=0,1,0))); i++ )
{
if(m[i]>m[i-1]) sf[i]=sf[i-1]*IC[i-1]/IO[i];
else sf[i]=sf[i-1];
}
IO1=sf*IO;
IH1=sf*IH;
IL1=sf*IL;
IC1=sf*IC;
IO=IIf(IO1==0,Ref(IO1,-1),IO1);
IH=IIf(IH1==0,Ref(IH1,-1),IH1);
IL=IIf(IL1==0,Ref(IL1,-1),IL1);
IC=IIf(IC1==0,Ref(IC1,-1),IC1);
IV=IIf(IV==0,Ref(IV,-1),IV);
//-------------------------------------------------------------
// Now correct for any zero values
for( i = 1; i<BarCount; i++ )
{
if(IO[i]==0) IO[i]=IO[i-1];
if(IH[i]==0) IH[i]=IH[i-1];
if(IL[i]==0) IL[i]=IL[i-1];
if(IC[i]==0) IC[i]=IC[i-1];
if(IV[i]==0) IV[i]=IV[i-1];
}
AddToComposite(IO,indticker,"O", 3);
AddToComposite(IH,indticker,"H", 3);
AddToComposite(IL,indticker,"L", 3);
AddToComposite(IC,indticker,"C", 3);
AddToComposite(IV,indticker,"V", 3);
Buy=0;
Sell=0;
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
|