Hi All,
My model is
1st step : Select the top 60 stocks (from all 700 stocks in universe) using Ranking of criteria-1
2nd step : then, select the top 20 stocks (from 60 stocks in 1st step) using Ranking of criteria-2
3rd step : invest in this 20 stocks and hold for 20 days then rebalance to invest in another new 20 stocks.
Because I am so novice on coding and programming, I used to ask how to code this model here.
but The code I got is a bit too complicated for me to translate and modify.
So I write the code by myself with guideline from
https://www.amibroker.com/guide/afl/staticvargenerateranks.html
As example, I use Close price as criteria-1, ROC as criteria-2
1st step :I use staticvargenerateranks function
2nd step :I use positionscore
3rd step :I use ApplyStop :stopTypeNBar
{//Option
SetOption("InitialEquity" , 1000000);
SetOption("MaxOpenPositions", 20);
SetOption("MinShares", 100);
RoundLotSize = 100;
SetOption("CommissionMode", 1);
SetOption("CommissionAmount", 0.16);
SetTradeDelays(1, 1, 0, 0);
BuyPrice = Open;
SellPrice = Open;
}
///// Start my own coding////////////
Mainlistnum = GetOption( "FilterIncludeWatchlist" ); //ok...probably about identify and getting the number of stocks in universe
Mainlist = CategoryGetSymbols( categoryWatchlist, Mainlistnum ); //ok..probably about identify and getting list of stocks in universe
StaticVarRemove( "ValuesToSort*" );
// Fill input value (for ranking) into Static arrays
for( i = 0; ( sym = StrExtract( Mainlist, i ) ) != ""; i++ )
{
SetForeign(sym );
Value = C;
RestorePriceArrays();
StaticVarSet( "ValuesToSort" + sym, Value );
}
// Perform Ranking
StaticVarGenerateRanks("rank", "ValuesToSort", 60, 1224); // Top rank mode
buyConRank = StaticVarGet("rankValuesToSort" + sym ) < 60;
Buy = buyConRank; //buyConMK +
Sell = 0;
{//Position
SetPositionSize(5, spsPercentOfEquity);
PositionScore = ROC(C,100);
}
{//Stop
ApplyStop(stopTypeNBar, stopModeBars, 20);//20 means 20 trading day equal to 1 month holding period.
}
The backtest show no result ! or even worse, detect the error!
which should not be an error
because I copy this part from amibroker guideline itself at
https://www.amibroker.com/guide/afl/staticvargenerateranks.html
About the error message, it happen only to my amibroker on my PC. I have my friend check the code
on his computer, no error message like this shown, but still the backtest show no result.
Can anyone help me pinpoint what I do wrong with my code
or guide me which part probably need to be fixed or checked?