Hello,
I want to rank stocks by coppock, and then buy that stocks at the beginning of the month ordered by the ranking. The problem that I have is when I compare the "explore" stocks with the "backtest" buyed stocks are different. I am trying to figure out what is happening, but no idea...I think that I have some concept wrong...
// ################ START SETUP ######################################
PosQty = 10;
SetOption("MaxOpenPositions", PosQty);
PositionSize = 100/PosQty;
SetPositionSize( PositionSize, spsPercentOfEquity );
SetTradeDelays(1,1,1,1);
SetOption("initialequity",10000);
BuyPrice = O;
SellPrice = O;
// ################ END SETUP #########################################
// ################ START Ranking #####################################
// 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*" );
categoryList = ",";
for( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{
SetForeign( symbol );
// START CODE CRITERIA
// COPPOCK CRITERIA BASED RANKING
WMAPeriods =Param("WMA periods",10,2,200,1,0);
ROC1Periods =Param("ROC1 periods",14,2,200,1,0);
ROC2Periods =Param("ROC2 periods",11,2,200,1,0);
Coppock=WMA((ROC(C,ROC1Periods)+ROC(C,ROC2Periods)),WMAPeriods);
values = Coppock;
// END CODE CRITERIA
RestorePriceArrays();
// write ranked values to a static variable
StaticVarSet( "values_" + symbol, values );
}
// generate ranks
StaticVarGenerateRanks( "rank", "values_", 0, 1224 );
}
symbol = Name();
values = StaticVarGet( "values_" + symbol ); //Coppock criteria based ranking value
rank = StaticVarGet( "rankvalues_" + symbol ); //from 1 to end, ranking the top
// exploration code for verification
if( Status( "action" ) == actionExplore )
{
AddColumn( values, "values" );
AddColumn( rank, "rank" );
Filter = rank <= 10;
SetSortColumns(-2, 4);
}
//For the backtest. Start from the stocks that have more coppock critera based ranking
PositionScore = values;
// ################ END Ranking ########################################################
// ################ START BUY/SELL #####################################################
BuySignal = 1;//(Close > SAR(0.002,0.2));
SellSignal = (Month() != Ref(Month(), -1));
Buy = ExRem(BuySignal, SellSignal);
Sell = ExRem(SellSignal, BuySignal);
// trade on next bar open
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = SellPrice = Open;
// ################ END BUY/SELL #########################################################
Thanks for all the help!
Iaki