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

[amibroker] Did I screw up this loop?



PureBytes Links

Trading Reference Links

I am relatively new to looping and I am trying to create composites 
for small, mid, and large cap composites with their underlying 
sectors.  For example, take utilities, I am trying to create small, 
mid, and large cap composites for the utility sector.  When I run 
this code I get two composites for each style, i.e. 2 for small cap, 
2 for mid cap, and 2 for large cap and I have no idea why - I am 
trying to get one of each not 2.  I was hoping someone could shed 
some light on why this may be happening.  The code is as follows:


MarketCap = round(Close[BarCount -1] * GetExtraData("shares")/1000);
small = Marketcap < 3000;
mid = Marketcap >=3000 AND Marketcap < 9000;
Large = Marketcap >=9000;

function MarketCapGet()

    {

      CurDatabase = GetDatabaseName(); 

      

      if(CurDatabase == "QP3")

            {

            MarketCap = round(Close[BarCount -1] * GetExtraData
("shares")/1000);

            }

     else

            {

            MarketCap = 666;  //indicating N/A

            }

      return MarketCap ;

      }

 

function MarketCapCategoryGet(MarketCap)

    {

  CurDatabase = GetDatabaseName(); 

      

      if(CurDatabase == "QP3")

          {

        if (MarketCap < 3000)

            MarketCapCategory= "Small";

      else

                  {

                  if (MarketCap >= 3000 AND MarketCap < 9000)

                        MarketCapCategory= "Mid";

                  else

                        MarketCapCategory= "Large";

                  }

            }

     else

            {

            MarketCapCategory=      "N/A";      //indicating N/A

            }

      return MarketCapCategory;

      }


mktcaplarge = "~" + "LC_" + SectorID(1) + Large;
mktcapSC = "~" + "SC_"+ SectorID(1) + small;
mktcapmid = "~" + "MC_" + SectorID(1) + mid;