Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: WLBuildProcess
Author/Uploader: Fred Tonetti -
Date/Time added: 2006-09-16 05:30:39
Origin:
Keywords: WatchList AddToComposite
Level: basic
Flags: exploration,function

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

Builds a user designated working watchlist using the tickers from an external file, processes the users formula and adds to a composite which is stored in the final watchlist. Any number of files can be processed

Formula:

//
// Builds Composites From External Lists of Symbols
//
// This should be run as an Exploration on the current symbol only
// 
// User Supplied Info:
//
//     WatchLists 
//         62 - Work
//         63 - Final
//
//     The requirements of input files are that they all must
//         - Be in the same directory
//         - Have the same Prefix   ( In this case ETF  ) 
//         - Have the same FileType ( In this case .tls )
//         - Contain a sequential number as part of the name beginning with 1
i.e. ETF1, ETF2 etc ...
//
//     FNMax = Number of Files to be Processed 
//     FNLoc = File Location (Path)
//     FNPre = FileName Prefix
//     FNTyp = FileType
//
// FNNum = FileName Number ( Suffix ) ... Automatically generated from 1 to
FNMax
//
// The resulting composites will be named ~FNPreFNNum and will be in the Final
WatchList
//

WLWrk = 62;
WLFin = 63;
FNMax =  2;
FNLoc = "C:/Work/";
FNPre = "ETF";
FNTyp = ".tls";

// Clear Final WatchList

IPList = GetCategorySymbols(categoryWatchlist, WLFin);

_TRACE("Removing Tickers from W/L " + NumToStr(WLFin, 1.0));
for (i = 0; i < 999999; i++)
{
    Ticker = StrExtract(IPList, i);
    if (Ticker == "")
        i = 999999;
    else
    {
        CategoryRemoveSymbol(Ticker, categoryWatchlist, WLFin);
        _TRACE("   " + Ticker);
    }
}

Filter = BarIndex() == LastValue(BarIndex());

// Loop to process all files

for (FNNum = 1; FNNum <= FNMax; FNNum++)
{
    // Clear Work WatchList

    IPList = GetCategorySymbols(categoryWatchlist, WLWrk);

    _TRACE("Removing Tickers from W/L " + NumToStr(WLWrk, 1.0));
    for (i = 0; i < 999999; i++)
    {
        Ticker = StrExtract(IPList, i);
        if (Ticker == "")
            i = 999999;
        else
        {
            CategoryRemoveSymbol(Ticker, categoryWatchlist, WLWrk);
            _TRACE("   " + Ticker);
        }
    }

    // Load WatchList

    IPFileName = FNLoc + FNPre + NumToStr(FNNum, 1.0) + FNTyp;

    fh = fopen(IPFileName, "r");  
    if(fh)  
    {
        _TRACE("Loading Tickers from " + IPFileName);
        while(! feof(fh))  
        { 
            Ticker = fgets(fh); 
            Ticker = StrReplace(Ticker, "\n", "");  
            Ticker = StrReplace(Ticker, "\r", "");
            if (Ticker != "")
            {
                CategoryAddSymbol(Ticker, categoryWatchlist, WLWrk);
                _TRACE("   " + Ticker);
            }
        } 
        fclose(fh);  
    }  
    else  
    {  
        printf("ERROR: " + IPFileName + " does NOT exist");  
    }  

    // Process WatchList 

    IPList = GetCategorySymbols(categoryWatchlist, WLWrk); 
    CompNM = "~" + FNPre + NumToStr(FNNum, 1.0);

    _TRACE("Processing Tickers & Adding to Composite " + CompNM);
    for (i = 0; i < 999999; i++) 
    { 
        Ticker = StrExtract(IPList, i); 
        if (Ticker == "") 
            i = 999999; 
        else
        {
            _TRACE("   " + Ticker);

            SetForeign(Ticker);

            // Whatever processing for each Ticker - In this case we're just
grabbing Close

            AddToComposite(C, CompNM, "X", atcFlagCompositeGroup +
atcFlagEnableInExplore);

            CategoryAddSymbol(CompNm, categoryWatchlist, WLFin);

            CategoryRemoveSymbol(CompNm, categoryGroup, 253);

        }
    }
    AddTextColumn(CompNm, "Completed");
}

Comments:

Mark H.

2006-09-17 18:58:23
Here is a simplified version which has more flexibility. Only list folder (directory) is needed and the list files doesn't have to be ETF#.tls.
Have fun!
=================================================
//
// Builds Composites From External Lists of Symbols
//
// This should be run as an Exploration on the current symbol only
// (it is recommended to use DJ30 composite as your current symbol)
//
// User Supplied Info:
//
// The requirements of input files are that they all must
// - Be in the same directory
// - Have the same FileType ( In this case .tls )
//
// WLFIN = Watchlist ID to save Final results
// FNLoc = File Location (Path)
// FNTyp = FileType
//
//
// The resulting composites will be named ~Comp~FN and will be in the Final WatchList
//
// Code created by Fred T., modified by Mark H.

WLFin = 63;
FNLoc = "C:\\Program Files\\AmiBroker\\MyLists\\";
FNTyp = ".tls";

Filter = BarIndex() == LastValue(BarIndex());

EnableScript("JScript");
FNLIST = "";
<%
fs = new ActiveXObject("Scripting.FileSystemObject");
f = fs.GetFolder(AFL("FNLoc"));
for (fc = new Enumerator(f.files); !fc.atEnd(); fc.moveNext())
{
fullname = fc.item(); name = fc.item().name;
i = name.indexOf(AFL("FNTyp"))
if(i != -1)
{
listname = name.substring(0,i);
AFL("FNLIST") = AFL("FNLIST") + listname + ",";
}
}
%>
_TRACE("To Process Lists: " + FNLIST);
// Loop to process all files
for( i = 0; ( FN = StrExtract( FNLIST, i ) ) != ""; i++ )
{
IPFileName = FNLoc + FN + FNTyp;
CompNM = "~Comp~" + FN;
_TRACE("Processing Tickers & Adding to Composite " + CompNM);
fh = fopen(IPFileName, "r");
if(fh)
{
_TRACE("Loading Tickers from " + IPFileName);
while(! feof(fh))
{
Ticker = fgets(fh);
Ticker = StrReplace(Ticker, "\n", "");
Ticker = StrReplace(Ticker, "\r", "");
if (Ticker != "")
{
_TRACE(" " + Ticker);
SetForeign(Ticker);

// Whatever processing for each Ticker - In this case we're just grabbing Close

AddToComposite(C, CompNM, "X", atcFlagCompositeGroup + atcFlagEnableInExplore);
}
}
fclose(fh);
CategoryAddSymbol(CompNm, categoryWatchlist, WLFin);
CategoryRemoveSymbol(CompNm, categoryGroup, 253);
}
else
{
printf("ERROR: " + IPFileName + " does NOT exist");
}
AddTextColumn(CompNm, "Completed");
}


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM