I am trying to generate ranks on daily data, but evaluate a strategy on hourly data (which is its native periodicity)
I am grabbing the symbols from a watchlist.
When I switch the chart back and forth from daily to hourly the ranking should be the same for that particular day, but it is not. The rank should switch only once a day, so when on an hourly chart, the plot line should "stair-step" from one day to the next.
Here is my attempt. Can someone see why it is not working properly?
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
///////////////////// First Rank on Daily bars //////////////////////////////////////////////////////////////////////////////////////////
TimeFrameSet( inDaily ); // switch to daily time frame
SymbolCount = 0;
mySymList = "";
EnableTextOutput(0);
mySymList = CategoryGetSymbols( categoryWatchlist, 64, 0 );
EnableTextOutput(1);
for( i = 0; ( sym = StrExtract( mySymList, i ) ) != ""; i++ )
{
SymbolCount ++;
//printf( "Symbol is " + sym + " " );
}
printf("Symbol SymbolCount: " + NumToStr(SymbolCount,0) + "\n" );
FirstSymbol = IIf( Status("stocknum") == 0 , FirstSymbol = 1, FirstSymbol = 0);
if( FirstSymbol )
{
PPOShort = Param( "PPO Short Period", 12, 1, 150, 1 );
PPOLong = Param( "PPO Long Period", 26, 1, 150, 1 );
PPOsignal = Param( "PPOsignal", 9, 1, 150, 1 );
// delete static variables
StaticVarRemove( "ItemScore*" );
// fill input static arrays
for ( i = 0; ( sym = StrExtract( mySymList, i ) ) != ""; i++ )
{
SetForeign( sym );
myROC = ROC(Close, 14);
RestorePriceArrays();
// write ranked values to a static variable
StaticVarSet( "ItemScore" + sym, myROC );
}
// perform ranking
StaticVarGenerateRanks( "Rank", "ItemScore", 0, 1224 ); // normal rank mode
}
else
{
// Not first symbol
}
myScoreSymbol = "AAPL";
ThisScore = StaticVarGet("ItemScore" + myScoreSymbol );
//Plot( ThisScore, myScoreSymbol + "_score", colorYellow );
printf( "ThisScore: " + NumToStr( ThisScore ) + "\n" );
// read ranking
ThisRank = StaticVarGet("RankItemScore" + myScoreSymbol );
DailyRankPct = ((SymbolCount-ThisRank)/SymbolCount)*100;
//Plot( DailyRank , myScoreSymbol + "_rank", colorAqua );
printf( "RankItemScore: " + NumToStr( StaticVarGet( "RankItemScore" + "AAPL" ), 0 ) + "\n" );
for ( i = 0; ( sym = StrExtract( mySymList, i ) ) != ""; i++ )
{
//Plot( StaticVarGet( "RankItemScore" + sym ), sym, colorCustom10 + i );
}
///////////////////// STRATEGY on 60min //////////////////////////////////////////////////////////////////////////////////////////
TimeFrameRestore();
ExpandedRankPct = TimeFrameExpand( DailyRankPct, inDaily);
Plot( ExpandedRankPct , myScoreSymbol + "_rank", colorAqua );