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

RE: [amibroker] AFL help



PureBytes Links

Trading Reference Links

Pankaj,

 

As Jason and others have said, you need to use AddToComposite.  There are actually two parts.  First is the AddToComposite Exploration to create the ATC symbol.  Second is the Chart plotting AFL to plot the ATC symbol. 

 

As a quick exercise, I created both (below). 

 

Notes:

 

  • I used the “H” and “L” values to save the GT and LT counts.  
  • I use an Exploration so that I can audit the values produced.  A bit slower, but more accurate.
  • The procedure allows you to package the code and more easily reuse if you want to create more symbols.  I.e., you could change the name of the symbol and then add additional symbols by calculating different RSI values and simply calling CompositeLoad multiple times:
    • CompositeLoad("~RSI_9_40Counts"…
    • CompositeLoad("~RSI_9_50Counts"…
    • CompositeLoad("~RSI_14_40Counts"…

 

ATC is a very nice AB feature.  Currently, I’m creating about 4,000 ATC symbols. 

 

Regards,

 

Dan.

 

 

Chart Plot:

//Save to file name like, “PlotRSICounts.afl” and then add as a pane.

if(Name() == "~RSICounts")

   {

   RSIGreaterThanTargetCount  = H;  

   RSILessThanTargetCount     = L;

  

   Plot(RSIGreaterThanTargetCount , "RSI >= 40", colorGreen, styleLine | styleThick);

   Plot(RSILessThanTargetCount       , "RSI < 40"  ,  colorRed, styleLine | styleThick);

   }

 

ATC Exploration:

//Save this to a file named like, “RSICountsComposite.afl.

 

//Open file in AA. Use a filter to define the source Watchlist, group, etc.

//Click “Parameters” and set your target RSI Value (like “40”), the

//number of RSI Periods (like “9”) and the target Watchlist number (like “61”)

//where you want to resulting symbol to be saved.

 

// Instantiate Broker.Application

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);

   }

  

//Parameters

RSIPeriods              = Param( "Number of RSI Periods", 9, 1, 100, 1 );

RSITargetValue          = Param( "RSI Target Value", 40, 1, 100, 1 );

 

//Set Watchlist to save target symbol

TargetWatchListNbr      = Param( "Target Watchlist Number", 61, 1, 63, 1 );

 

//Get RSI Value

RSIValue             = RSI(RSIPeriods);

 

//Set the counts

RSIGreaterThanTargetCount  =  IIf(RSIValue >= RSITargetValue, 1, 0);

RSILessThanTargetCount     =  IIf(RSIValue < RSITargetValue, 1, 0);

      

//AddToCompositeFlags

atcCurrentFlags =  atcFlagResetValues + atcFlagCompositeGroup + atcFlagEnableInExplore;

 

//Load composite symbols and add to watchlist

//CompositeLoad(Sym        , SymName                  , CloseVal             , OpenVal, HighVal, LowVal, VolVal, OpenIntVal, ATCFlags, TargetWLNbr)

CompositeLoad("~RSICounts", "~RSI Counts GT and LT 40", 0, 0, RSIGreaterThanTargetCount, RSILessThanTargetCount, 0, 0, atcCurrentFlags, TargetWatchListNbr);

 

//Filter for exploration - get all symbols

Filter = Buy = 1;

 

//Exploration columns

SetOption("NoDefaultColumns"   , True );

AddTextColumn(Name()       , "Symbol");

AddTextColumn(FullName()      , "Company");

AddColumn(RSIValue                , "RSIValue");

AddColumn(RSIGreaterThanTargetCount   , "RSIGreaterThanTargetCount"  , format = 1.0);

AddColumn(RSILessThanTargetCount      , "RSILessThanTargetCount"     , format = 1.0);

 

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Pankaj Chawla
Sent: Tuesday, October 25, 2005 4:36 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] AFL help

 

Given below is what am lookin for

I want to plot the NUMBER of issues(scrips) with rsi
below 40 and also plot the NUMBER of issues with rsi
above 40.

say if out of 100 issues.. there are 30 scrips
matching rsi (10)<40, and 70 matching rsi(10) > 40.

how would i get those figures n how do i plot them as
a indicator. I want to plot two lines one for each

match on a daily basis.

Hope am clear on what i want.

Thanks

Pankaj
 




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Real estate investment software Investment property software
Software support Real estate investment analysis software Investment software


YAHOO! GROUPS LINKS