Help in Coloring Cells of Rankings using StaticVarGenerateRanks

I am trying to color the background of cells of an exploration of rankings done using StaticVarGenerateRank. The ranking I have figured out (thanks to all who have posted on ranking examples) but I am having some difficulty trying to understand the best path or function to code the background of the cells. In the attached pics I have used the following code with the assumption that I have to calculate each ranking column separately. I am using the ColorHSB but I surmising there is a more efficient and effective way to code this. Ideally the goal would be to for example rank in green the highest ranked (1=Best) with a gradient down to red for the lowest values, but I can live with the ColorHSB if it would take too much in resources to process. Any pointers would be greatly appreciated.

rank2

Rank

Please do not post pictures of code.
Also not incomplete code.

Other than that you are using same color variable named Color for multiple ranks -> each line overwrites the other one (because of that same variable name).

Effective way?
Write loop.

Thank you for the reply Fxshrat, my apologies for not imbedding the code. That snippet posted was the only code I was using to reference color in the cells. I went back and changed the variable for "Color" to a unique for each rank but still end up with basically the same output. In regards to your suggestion of using a loop, I think that is the probably the correct path but I am not sure exactly what I am putting through the loop yet. I guess I could calculate a percentage rank then assign a color if the rank falls within that range or something similar but that is where I was hoping more knowledgeable folks could point me in the right direction.

//Exploration of Relative Strength over time  

Market=ParamList("Market","VOO|ACWI|ACWX|AGG|MUB");
//Market=GetBaseIndex();
Mkt=Foreign(Market,"C");

Per=Param("Periods",130,1,260,1);

Ratio = ((C/MKT)/(Ref(C,-Per))/Ref(Mkt, -Per));

ROCM= ROC(Mkt, Per);//Rate of change of the Market
ROCS= ROC(C, Per); //Rate of change of Security

/***********************   For ROC Year-to-Date  **********************************************/
TradeDayOfYear = BarsSince( year() > Ref( year(), -1 ) ) + 1;
RateOfChangeYTD = ( C - Ref( C, -TradeDayOfYear ) ) / ( Ref( C, -TradeDayOfYear ) ) * 100;
/**********************************************************************************************/

/*********************************************************************************************/

// in AA window run this analysis on a WL that contains the symbols you are testing
wlnum = GetOption( "FilterIncludeWatchlist" );
List  = CategoryGetSymbols( categoryWatchlist, wlnum ) ;

if( Status( "stocknum" ) == 0 )
{
    StaticVarRemove( "values*" );

    for( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++ )
    {
		
        SetForeign( symbol );
        
        Ratio=((C/MKT)/(Ref(C,-Per))/Ref(Mkt, -Per));
        Wk0= Ratio; 
		Wk1=Ref(Ratio, -5);//1Wk
		Wk2=Ref(Ratio, -10);//2Wk
		Wk3=Ref(Ratio, -15);//3Wk
		Wk4=Ref(Ratio, -20);//4Wk
		Wk5=Ref(Ratio, -25);//5Wk
		Wk6=Ref(Ratio, -30);//6Wk
		Wk7=Ref(Ratio, -35);//7Wk
		Wk8=Ref(Ratio, -40);//8Wk
		Wk9=Ref(Ratio, -45);//9Wk
		Wk10=Ref(Ratio, -50);//10Wk
		Wk11=Ref(Ratio, -55);//11Wk
		Wk12=Ref(Ratio, -60);//12Wk
		Wk13=Ref(Ratio, -65);//13Wk
        
        /*Values105 = ROC( C, 105 );
        Value20	  = ROC( C, 20 );*/
        
        RestorePriceArrays();
        
        StaticVarSet( "Wk1"  +  symbol, Wk1 );
        StaticVarSet( "Wk2"  +  symbol, Wk2 );
        StaticVarSet( "Wk3"  +  symbol, Wk3 );
        StaticVarSet( "Wk4"  +  symbol, Wk4 );
        StaticVarSet( "Wk5"  +  symbol, Wk5 );
        StaticVarSet( "Wk6"  +  symbol, Wk6 );
        StaticVarSet( "Wk7"  +  symbol, Wk7 );
        StaticVarSet( "Wk8"  +  symbol, Wk8 );
        StaticVarSet( "Wk9"  +  symbol, Wk9 );
        StaticVarSet( "Wk10"  +  symbol, Wk10 );
        StaticVarSet( "Wk11"  +  symbol, Wk11 );
        StaticVarSet( "Wk12"  +  symbol, Wk12 );
        StaticVarSet( "Wk13"  +  symbol, Wk13 );


    }

    StaticVarGenerateRanks( "rank", "Wk1", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk2", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk3", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk4", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk5", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk6", 0, 1224 ); 
    StaticVarGenerateRanks( "rank", "Wk7", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk8", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk9", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk10", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk11", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk12", 0, 1224 );
    StaticVarGenerateRanks( "rank", "Wk13", 0, 1224 );
    
    }

symbol   	= Name();
svValuesWk1 = StaticVarGet( "Wk1" +  symbol );
svValuesWk2 = StaticVarGet( "Wk2" +  symbol );
svValuesWk3 = StaticVarGet( "Wk3" +  symbol );
svValuesWk4 = StaticVarGet( "Wk4" +  symbol );
svValuesWk5 = StaticVarGet( "Wk5" +  symbol );
svValuesWk6 = StaticVarGet( "Wk6" +  symbol );
svValuesWk7 = StaticVarGet( "Wk7" +  symbol );
svValuesWk8 = StaticVarGet( "Wk8" +  symbol );
svValuesWk9 = StaticVarGet( "Wk9" +  symbol );
svValuesWk10 = StaticVarGet( "Wk10" +  symbol );
svValuesWk11 = StaticVarGet( "Wk11" +  symbol );
svValuesWk12 = StaticVarGet( "Wk12" +  symbol );
svValuesWk13 = StaticVarGet( "Wk13" +  symbol );

svRankWk1	= StaticVarGet( "rankWk1" +  symbol );
svRankWk2	= StaticVarGet( "rankWk2" +  symbol );
svRankWk3	= StaticVarGet( "rankWk3" +  symbol );
svRankWk4	= StaticVarGet( "rankWk4" +  symbol );
svRankWk5	= StaticVarGet( "rankWk5" +  symbol );
svRankWk6	= StaticVarGet( "rankWk6" +  symbol );
svRankWk7	= StaticVarGet( "rankWk7" +  symbol );
svRankWk8	= StaticVarGet( "rankWk8" +  symbol );
svRankWk9	= StaticVarGet( "rankWk9" +  symbol );
svRankWk10	= StaticVarGet( "rankWk10" +  symbol );
svRankWk11	= StaticVarGet( "rankWk11" +  symbol );
svRankWk12	= StaticVarGet( "rankWk12" +  symbol );
svRankWk13	= StaticVarGet( "rankWk13" +  symbol );

// explore the calculations //

Filter = Status("lastbarinrange");

Color1 = ColorHSB( svRankWk1,  150, 255 );
Color2 = ColorHSB( svRankWk2,  150, 255 );
Color3 = ColorHSB( svRankWk3,  150, 255 );
Color4 = ColorHSB( svRankWk4,  150, 255 );
Color5 = ColorHSB( svRankWk5,  150, 255 );
Color6 = ColorHSB( svRankWk6,  150, 255 );
Color7 = ColorHSB( svRankWk7,  150, 255 );
Color8 = ColorHSB( svRankWk8,  150, 255 );
Color9 = ColorHSB( svRankWk9,  150, 255 );
Color10 = ColorHSB( svRankWk10, 150, 255 );
Color11 = ColorHSB( svRankWk11, 150, 255 );
Color12 = ColorHSB( svRankWk12, 150, 255 );
Color13 = ColorHSB( svRankWk13, 150, 255 );

AddtextColumn(FullName(),"Fund Name",1.2,colorBlue,colorWhite,55);
AddTextColumn(SectorID(1),"Category",1.2,colorBlue,colorWhite,35);
AddColumn(RateOfChangeYTD,"YTD %",1.2,colorBlue,colorWhite,12);

//AddColumn( svValuesWk1, "svValuesWk1" );
AddColumn( svRankWk1, "Wk1", 1.0,colorDefault,color1, -1, svrankWk1);
AddColumn( svRankWk2, "Wk2", 1.0,colorDefault,color2, -1, svrankWk2);
AddColumn( svRankWk3, "Wk3", 1.0,colorDefault,color3, -1, svrankWk3);
AddColumn( svRankWk4, "Wk4", 1.0,colorDefault,color4, -1, svrankWk4);
AddColumn( svRankWk5, "Wk5", 1.0,colorDefault,color5, -1, svrankWk5);
AddColumn( svRankWk6, "Wk6", 1.0,colorDefault,color6, -1, svrankWk6);
AddColumn( svRankWk7, "Wk7", 1.0,colorDefault,color7, -1, svrankWk7);
AddColumn( svRankWk8, "Wk8", 1.0,colorDefault,color8, -1, svrankWk8);
AddColumn( svRankWk9, "Wk9", 1.0,colorDefault,color9, -1, svrankWk9);
AddColumn( svRankWk10, "Wk10", 1.0,colorDefault,color10,-1, svrankWk10);
AddColumn( svRankWk11, "Wk11", 1.0,colorDefault,color11,-1, svrankWk11);
AddColumn( svRankWk12, "Wk12", 1.0,colorDefault,color12,-1, svrankWk12);
AddColumn( svRankWk13, "Wk13", 1.0,colorDefault,color13,-1, svrankWk13);


SetSortColumns( 6,7,8,9 );


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.