Max open positions control by exploration

How can cantrol maximum open position 4 symbol only in exploration

There are no "open positions" in an Exploration. That concept only applies to backtests. An Exploration is run against one symbol at a time.

@BARASARA, as said by @mradtke there are no "open positions" after an exploration.

Anyway, if you want to see only a few "results" (i.e., rows) from an Exploration (for instance to export them to some other applications/web pages, etc.) you can try to use the ranking functions like in this example:

// Parametrize as needed
lastRankAccepted = 4;
ROCPeriod = 5;

// Check the Pad&Align settings since this examples uses Foreign()
// TJ: "ANY kind of ranking REQUIRES data to be aligned (i.e. without holes)"

// Code adapted from: http://www.amibroker.com/kb/2016/01/

// watchlist should contain all symbols included in the test
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ;

if( Status( "stocknum" ) == 0 )
{
    // cleanup variables created in previous runs (if any)
    StaticVarRemove( "rank*" );
    StaticVarRemove( "values*" );

    for( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++ )
    {
        SetForeign( symbol );

        // write our ranking criteria to a variable
        // in this example we will use ROCperiod-bar rate-of-change
        values = Roc( Close, ROCPeriod );

        RestorePriceArrays();

        // write ranked values to a static variable
        StaticVarSet( "values_" + symbol, values );

    }

    // The "tie" mode (4th param) defines how ties are ranked. 1234 means that ties are NOT numbered with equal rank.
    StaticVarGenerateRanks( "rank", "values_", 0, 1234 );
}

// Exploration
rank = StaticVarGet( "rankvalues_" + Name() );
Filter = rank <= lastRankAccepted;
AddTextColumn( FullName(), "Description", 1, colorDefault, colorDefault, 200 );
AddColumn( Close, "Close" );
AddColumn( ROC( C, ROCPeriod ), "ROC" );
AddColumn( rank, "Rank", 1 );

if( Status( "action" ) == actionExplore )
    SetSortColumns( -2, 6 );

Sample results:
immagine

If you search the forum for "rank" you'll find many other examples.

Please, also read some caveats about the requirement to use aligned data (with no data holes) when you use the ranking and foreign functions.

4 Likes

@beppe,
Thanks for listing out this code with so many explanatory comments. It's very helpful and much appreciated.

Greg

2 Likes