Australian (ASX) Stock Market Forum

Reply to thread

Following on from discussions about Rotational trading I have pieced together some code that ranks stocks in your selected watchlist.


I am thinking that you could run in at the end of the month and review your portfolios positions against their current rank as defined by your criteria to get a feel for your stock selections.


Obviously you could incorporate this into your system but pretty easy just to run at end of the month (2nd last day of month)


- Exploration is run against selected watchlist


[ATTACH=full]104616[/ATTACH]


- Ranks each stock based on ROC(Close, 60) - which can be changed to your preference


[ATTACH=full]104617[/ATTACH]


- Only displays positive valves of ROC for long only system


- Only displays results if 2nd last day of month as you might want to trade on the last day

Filter = TradeDay;



[CODE]// Ranking of stocks in current watchlist


if ( GetOption( "ApplyTo" )== 2 )

{

    wlnum = GetOption( "FilterIncludeWatchlist" );

    List = CategoryGetSymbols( categoryWatchlist,wlnum ) ;

}

else

if ( GetOption( "ApplyTo" )== 0 )

{

    List = CategoryGetSymbols( categoryAll, 0 );

}

else

{

     Error( "Theformula works fine if your ApplyTo setting is 'Filter' or 'All' " );

}



if ( Status("stocknum")== 0 ) //GENERATE RANKING WHEN WE ARE ON VERY FIRST SYMBOL

{

    StaticVarRemove( "values*" );


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

    {

        SetForeign (symbol );

        values = ROC(Close, 60); // ROC Indicator used to create set of values for Ranking

        RestorePriceArrays();

        StaticVarSet (  "values"  +  symbol,values );

        _TRACE(symbol );

    }


    StaticVarGenerateRanks( "rank", "values", 0, 1224 );

}


symbol = Name();


LastDayOfMonth = IIf( (Month() == Ref( Month(), 1) AND (Month() != Ref( Month(), 2)) ), 1, 0);

TradeDay = LastDayOfMonth ;


values = StaticVarGet ( "values" +  symbol);

rank = IIf (TradeDay, StaticVarGet ( "rankvalues" +  symbol), Null);


PositionScore = IIf(values < 0, 0, values ); // Long only


SetSortColumns( 4 );

Filter = TradeDay;

  

AddColumn ( PositionScore, "ROC Values" );

AddColumn ( rank, "rank",1); [/CODE]


Enjoy !


Top