Hi everyone,
I am currently experimenting with placing limit orders with the following rules:
(1) C > 200MA
(2) RSI(2) < 50
(3) Top 5 ROC(100) values
(4) Place limit order at 1% below previous close.
Below is part of the backtesting code that I have which I used for exploration as well.
//Watchlist Lookup
Listname = "MRTSelect"; //Watchlist Name
category = categoryWatchlist;
Listnum = CategoryFind( Listname, category );
List = CategoryGetSymbols( category, Listnum);
//Parameters
Rule1 = C > MA(C, 200); // Close above 200MA
Rule2 = RSI(2) < 50; // 2-day RSI below 50
BuyRule = Rule1 AND Rule2;
//Ranking by ROC
if ( Status("stocknum") == 0 )
{
StaticVarRemove( "values*" );
for ( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{
SetForeign ( symbol );
// value used for scoring
values = ROC(C, 100);
RestorePriceArrays();
StaticVarSet ( "values" + symbol, values );
_TRACE( symbol );
}
StaticVarGenerateRanks( "rank", "values", 0, 1224 );
}
symbol = Name();
score = StaticVarGet ( "values" + symbol );
finalrank = StaticVarGet ( "rankvalues" + symbol );
AddColumn (score, "score");
AddColumn (finalrank, "finalrank");
Filter = BuyRule;
As the rules often give rise to multiple signals, itt is not possible to key in limit orders for all counters.
I tried to overcome the problem by generating a ranking based on ROC(100) and inserted a buy rule of finalrank <= 5 for the backtester.
I also did an exploration of this portion of the code and found the following ranking scores.
I notice that the ranking was not in cardinal order as I believe the ranking was done on all counters in the universe instead of the ones that fulfilled the buy rule.
As such, for example on 14/2/2022, I would have placed limit orders for 5 counters, DLTR, COP, XOM, CVS and F but due to the buy rule of finalrank <=5, the backtester would place only for DLTR, COP, XOM and CVS.
Would it be possible to "rank the finalrank" so that the buy rule can operate as above?
Thank you experts for your help in advance.
Cheers!