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

[amibroker] Ping Dan Clark - CompositeLoad Procedure



PureBytes Links

Trading Reference Links

Dan:  As I delve deeper into Sector and Industry analysis, I find a lot of
help in most of your past messages on this subject. Your code snippits you
have shared have been very helpful in seeing good, efficient coding
practice.
 
I thought I understood the statements and approach you shared in your
CompositeLoad procedure, and it is so flexible and compact, I rewrote some
of my clumsy code to use this.  However, it did not work.  It did not issue
an error, it just produced one composite instead of the several I was
thinking it would.
 
Can you look at this code and tell me what I did wrong or if what I am
trying cannot be done with this approach.
 
Here is the code:
//  Z_LoopCode_ATCS3.afl  KSC   8/13/2006
//  Credit to Dan Clark for code and concepts
 

AB = CreateStaticObject("Broker.Application");
 
//Procedure to add to Composite values
 
procedure CompositeLoad(Sym, SymName, CloseVal, OpenVal, HighVal, LowVal,
VolVal, 
 OpenIntVal, ATCFlags, TargetWLNbr)
   {
   //Add To Composite
   AddToComposite(CloseVal,   Sym, "C", ATCFlags);
   AddToComposite(OpenVal,    Sym, "O", ATCFlags);
   AddToComposite(HighVal,    Sym, "H", ATCFlags);
   AddToComposite(LowVal,     Sym, "L", ATCFlags);
   AddToComposite(VolVal,     Sym, "V", ATCFlags); 
   AddToComposite(OpenIntVal, Sym, "I", ATCFlags); 
   
   //Modify Names
   cs        = AB.Stocks(Sym) ;                      
   cs.FullName = SymName          ;                 
 
   // Add to Watchlists
   if (TargetWLNbr != 0)
       CategoryAddSymbol(Sym, categoryWatchlist, TargetWLNbr); 
   }
   
//AddToCompositeFlags
atcCurrentFlags =  atcFlagResetValues + atcFlagCompositeGroup +
atcFlagEnableInExplore;
//Load composite symbols and add to watchlist
 
NumOfIndustry = 5; // or the actual number (max 256)
for(w=1;w<NumOfIndustry;w++) // note that the loop starts from 0, not 1
 {
  if(IndustryID() == w) 
  {
   Sym = "~Z"+w;
   SymName = CategoryGetName(categoryIndustry,w);
   //CompositeLoad(Sym, SymName, CloseVal, OpenVal, HighVal, LowVal, 
   //VolVal, OpenIntVal, ATCFlags, TargetWLNbr)
   CompositeLoad("~Sym", "SymName", C, O,H,L,V, 1, atcCurrentFlags, 8);
 
   //  Get Adv and Decliners
   Up = IIf(C>Ref(C,-1),1,0);
   Dn = IIf(C<Ref(C,-1),1,0);
   Sym = "~U_D"+w;
   SymName = "Advances_Decliners U_D"+w;
   CompositeLoad("~Sym", "SymName", 0,0,Up,Dn,0, 1, atcCurrentFlags, 9);
 
  }
 }
 
Buy=1;
 
Since I only set 5 Industry groups, I expected five composites in two
different watchlists (one for Price/Vol info the other for Adv/Dec info).
Instead, in each designated watchlist, there was one symbol listed and it
was called "Sym" rather than the name of the symbol.  I can say that I
really do not understand these two lines and exactly what they do and why
they are needed.  But I copied them in.
 //Modify Names
   cs        = AB.Stocks(Sym) ;                      
   cs.FullName = SymName         
 
What did I do wrong and what can make this work?
 
I really appreciate any direstion you can offer.
 
Thanks, Ken