What sort of results do you get running that code on ASX? Or, would you share your AB code please, so we can try it?
Instead of this:
First Rank all tickers by their 200 day ROC and take the top 50 stocks from this ranked list
Rank these top 50 stocks by their 100 day ROC and take the top 25 from this 2nd ranked list
From this final list of 25 stocks, Rank them by their 50 day ROC and take the top 10 stocks
could you weight them in a single line?
eg.
rank = 2*ROC(c,200) + 10*ROC(c,100) + 20*ROC(c,50)
or whatever weighting you like. This would obviously give more weighting to recent performance.
As promised, this is my basic dual momentum rotational code, please let me know if you spot any errors.
I'm still working on a system that conducts multiple sorting runs to see if I can get it to work... debugging amibroker can be a real pain tbh...
C++:
//==================================
// Basic Dual Momentum System ===
// AFL By Willzy ===
//==================================
// Be sure to set your trade settings in the settings window because for Rotational Trading Mode, the script code will not work.
// ie BuyPrice = Open, SellPrice = Open.
// --- Include Files --- //
#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"
// --- Functions --- //
//OptimizerSetEngine("cmae");
SetBacktestMode( backtestRotational );
//--- Rotation settings
nPos = 10;//Optimize("nPos",5,3,20,1);
worstRankHeld = 10;//Optimize("worstRankHeld",15,5,20,1);
SetOption("BuyDelay",1);
SetOption("MaxOpenPositions", nPos);
SetOption("WorstRankHeld",worstRankHeld);
//--- account Settings
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 0 );
//--- All Positions Use Max Available Equity - Compounded Returns
posSize = 100/(nPos);
SetOption("InitialEquity",100000);
SetPositionSize(posSize,spsPercentOfEquity);
// Set Price Arrays for price and vol filters
CloseArray = NorgateOriginalCloseTimeSeries();
VolumeArray = NorgateOriginalVolumeTimeSeries();
priceFilter = CloseArray >= 10;
//--- Set foreign symbol for the indexFilter and Constituents
indexSymbol = "$NDX";
//--- Symbol exists within index at the time
canTrade = NorgateIndexConstituentTimeSeries(indexSymbol);
//--- index Filter
index = Foreign( "$NDX", "Close" );
indexPeriod = 200;
indexFilter = index > MA(index,indexPeriod);
//--- rankingScore
symScore = 0.4 * ROC(C,63) + 0.2*ROC(C,126) + 0.2*ROC(C,189) + 0.2*ROC(C,252);
//---symbol moving up
symbolFilter = C>MA(C,200) AND symScore > 0;
//--- Final Score Function
posScore = Max(0,
canTrade *
priceFilter *
indexFilter *
symbolFilter *
symScore
) ;
//--- rotate only at beginning of the month
Monthly = TimeFrameExpand(1, inMonthly, expandPoint);
PositionScore = IIf(monthly, Ref(posScore,-1), scoreNoRotate);
Filter = 1;
AddColumn( ROC(C,63), "ROC 50",1.4, colorBlack);
AddColumn( ROC(C,126), "ROC 100",1.4, colorBlack);
AddColumn( ROC(C,189), "ROC 250",1.4, colorBlack);
AddColumn( ROC(C,252), "ROC 500",1.4, colorBlack);
AddColumn( indexFilter, "indexFilter",1.4, colorBlack);
AddColumn( symScore, "symScore",1.4, colorBlack);
AddColumn( posScore, "posScore",1.4, colorBlack);
AddColumn( Close, "Close",1.4, colorBlack);
AddColumn( DayOfWeek(), "dayOfWeek",1.1, colorBlack);