I'm trying to make an indicator to calculate the Mansfield RSC of the GICS Sector of the shares (then I will try it for the Industrial Groups, the Industries and finally the Sub-Industries). I use the Norgate Data database (the trial version).
This is the code I have been able to do so far and it doesn't work (it doesn't draw anything):
// [...] Inicio modulo de calculo del RSC Mansfield del Sector GICS del valor
_SECTION_BEGIN("RSC Mansfield Sector GICS");
// Buscamos el Sector GICS y utilizaremos Índices para representarlo
switch (gicsID(0))
{
case"10":sector="$IXE"; break;//Sector GICS Energy
case"15":sector="$IXB"; break;//Sector GICS Materials
case"20":sector="$SPXI"; break;//Sector GICS Industrials
case"25":sector="$IXY"; break;//Sector GICS Consumer Discretionary
case"30":sector="$IXR"; break;//Sector GICS Consumer Staples
case"35":sector="$IXV"; break;//Sector GICS Health Care
case"40":sector="$SPXF"; break;//Sector GICS Financials
case"45":sector="$SPXT"; break;//Sector GICS Information Technology
case"50":sector="$IXCPR"; break;//Sector GICS Communication Services
case"55":sector="$IXU"; break;//Sector GICS Utilities
case"60":sector="$IXRE"; break;//Sector GICS Real Estate
//Cuando no haya sector GICS tomará el índice S&P500
default:sector = "$SPX";
}
SetForeign(sector);//sintonizamos el Sector GICS al que pertenece el actual valor
// RSC Mansfield del Sector GICS
period = Param("Periodo", 52, 1, 500, 1);
rsSymbol = ParamStr( "Base Index Symbol", "$SPX" );
//Comienza el calculo del RSC Mansfield del Sector GICS
Cociente = C / Foreign(rsSymbol, "C"); //Comparamos el precio Cierre del activo con respecto al precio Cierre del S&P500
CountR = Sum(Cociente,period); //Acumulamos los cocientes de las últimas 52 semanas
Baseprice = CountR/period; //Media de los cocientes
RSC = ((Cociente / Baseprice ) - 1)*10; //Comparamos el cociente actual con respecto a su media
RestorePriceArrays(); // volvemos al actual valor
// [...] Fin modulo de calculo del RSC Mansfield del Sector GICS del valor
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield de Sector GICS
//escogemos la forma de representacion y estilos
SetGradientFill(colorGreen/*top*/,colorRed/*bottom*/,0/*baseline level*/,GetChartBkColor()/*baseline color*/);
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield
Plot(RSC, "RSC Sector GICS"+ "-" + GicsID(2)+ " vs S&P500", colorBrown, styleLine | styleGradient);
_SECTION_END();
Something I've noticed so far is that the gicsID(0) gets the 8 digit code from the actions and then case "10" has two digits and since they don't match, it doesn't matter.
How can I make the gicsID(0) only take the first two digits of the GICS code of the actions?
I am very happy, every step with AmiBroker is important!
I attach the code for RSC Mansfield for Sector in case someone wants to tell me how to optimize it.
/ [...] Inicio modulo de calculo del RSC Mansfield del Sector GICS del valor
_SECTION_BEGIN("RSC Mansfield Sector GICS");
// Buscamos el Sector GICS y utilizaremos Índices para representarlo
gics = GicsID( 0 );
level1 = StrToNum( StrLeft( gics, 2 ) );
level2 = StrToNum( StrLeft( gics, 4 ) );
level3 = StrToNum( StrLeft( gics, 6 ) );
//printf("Level 1 %s\n", CategoryGetName( categoryGICS, level1 ) );
//printf("Level 2 %s\n", CategoryGetName( categoryGICS, level2 ) );
//printf("Level 3 %s\n", CategoryGetName( categoryGICS, level3 ) );
//printf("Level 4 %s\n", GicsID( 1 ) );
switch (StrLeft(gicsID(0),2))
{
case"10":sector="$IXE"; break;//Sector GICS Energy
case"15":sector="$IXB"; break;//Sector GICS Materials
case"20":sector="$SPXI"; break;//Sector GICS Industrials
case"25":sector="$IXY"; break;//Sector GICS Consumer Discretionary
case"30":sector="$IXR"; break;//Sector GICS Consumer Staples
case"35":sector="$IXV"; break;//Sector GICS Health Care
case"40":sector="$SPXF"; break;//Sector GICS Financials
case"45":sector="$SPXT"; break;//Sector GICS Information Technology
case"50":sector="$IXCPR"; break;//Sector GICS Communication Services
case"55":sector="$IXU"; break;//Sector GICS Utilities
case"60":sector="$IXRE"; break;//Sector GICS Real Estate
//Cuando no haya sector GICS tomará el índice S&P500
default:sector = "$SPX"; break;
}
SetForeign(sector);//sintonizamos el Sector GICS al que pertenece el actual valor
// RSC Mansfield del Sector GICS
period = Param("Periodo", 52, 1, 500, 1);
rsSymbol = ParamStr( "Base Index Symbol", "$SPX" );
//Comienza el calculo del RSC Mansfield del Sector GICS
Cociente = C / Foreign(rsSymbol, "C"); //Comparamos el precio Cierre del activo con respecto al precio Cierre del S&P500
CountR = Sum(Cociente,period); //Acumulamos los cocientes de las últimas 52 semanas
Baseprice = CountR/period; //Media de los cocientes
RSC = ((Cociente / Baseprice ) - 1)*10; //Comparamos el cociente actual con respecto a su media
RestorePriceArrays(); // volvemos al actual valor
// [...] Fin modulo de calculo del RSC Mansfield del Sector GICS del valor
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield de Sector GICS
//escogemos la forma de representacion y estilos
SetGradientFill(colorGreen/*top*/,colorRed/*bottom*/,0/*baseline level*/,GetChartBkColor()/*baseline color*/);
//mostramos en pantalla la variable RSC que contiene el RSC de Mansfield
Plot(RSC, "RSC Sector GICS"+ " "+"-"+" " + StrLeft(gicsID(0),2)+ " " + CategoryGetName(categoryGICS, Level1) + " vs S&P500", colorBrown, styleLine | styleGradient);
GraphLabelDecimals = 2;
_SECTION_END();
Thank you very much to those who help newbies like me.