How can I put the result of an Explorer on the graph?

Hello,

How can I put the result of an Explorer on the graph?
Thanks for your help.

Best regards,
Carlos


// Inicializamos Variables
Ind = "SPX-IDX"; // Index Sp500 
SP_500 = Foreign("SPX-IDX", "C"); // ͍ndice

ListIndSecSP500 = "SPNY,SPLRCM,SPLRCI,SPLRCD,SPLRCS,SPXHC,SPSY-IDX,SPLRCT,SPLRCL,SPLRCU,SPLRCREC"; // Índices Sectores SP 500
ListQty = StrCount(ListIndSecSP500, ",") + 1; 

// Run ranking functions
if( Status( "stocknum" ) == 0 ) {
	// Clear static vars from previous run
	StaticVarRemove("RSCM*");
	StaticVarRemove("Rank*"); 

	// Generate raw scores
	for (n = 0; (Symbol = StrExtract(ListIndSecSP500, n)) != "";  n++) { 

			RelS = (Foreign(Symbol,"C") / SP_500) * 1000; // Calculate Relative Strengh on saved Index Close price
			RSCM = 10*((RelS/MA(RelS,250))-1);// Calculate RSCMansfield --> 252 Daily - 52 Weekly
		RestorePriceArrays();

		StaticVarSet("RSCM" + Symbol, RSCM);
	} 

	// Generate raw rankings
	StaticVarGenerateRanks("RankRSCM", "RSCM" + Symbol, 0, 1224); 

}

symbol = Name();

values = StaticVarGet( "RSCM" + symbol );
rank = StaticVarGet( "RankRSCM" + "RSCM" + symbol );

Filter = 1;

AddColumn( values, "RSC M",1.4,colorBlack,IIf(values>=0,colorGreen,colorRed));

AddColumn( rank, "Rank",1.0,colorDefault,colorDefault);

TotalComp = ListQty;
Percentil = 100-((100*rank)/TotalComp);
AddColumn(Percentil,"Percentil",1.2);

// Sectores SP500 en Pantalla
XLP_01 = Foreign("SPLRCS", "C"); // Consumo Básico (XLP) Consumer Staples
XLY_02 = Foreign("SPLRCD", "C"); // Consumo Cíclico (XLY) Consumer Discretionary
XLE_03 = Foreign("SPNY", "C"); // Energia (XLE) Energy
XLF_04 = Foreign("SPSY-IDX", "C"); // Financiero (XLF) Financials
XLV_05 = Foreign("SPXHC", "C"); // Cuidados de Salud (XLV) Health Care
XLI_06 = Foreign("SPLRCI", "C"); // Industria (XLI) Industrials
XLB_07 = Foreign("SPLRCM", "C"); // Materiales Básicos (XLB) Materials
XLRE_08 = Foreign("SPLRCREC", "C"); // Inmobiliaria // (XLRE) Real State
XLK_09 = Foreign("SPLRCT", "C"); // Tecnología (XLK) Information Technology
XLU_10 = Foreign("SPLRCU", "C"); // Utilidades (XLU) Utilities
XLC_11 = Foreign("SPLRCL", "C"); // Telecomubnicaciones (XLC) Comunication Services

// AddColumn (Ref(ROC(C,1),1),"% Today",1.2, IIf(Ref(ROC(C,1),1)>=0 ,colorBlack, colorRed));

PercentChg01 = ( ( XLP_01 - Ref( XLP_01, -1 ) ) / Ref( XLP_01, -1 ) ) * 100;
PercentChg02 = ( ( XLY_02 - Ref( XLY_02, -1 ) ) / Ref( XLY_02, -1 ) ) * 100;
PercentChg03 = ( ( XLE_03 - Ref( XLE_03, -1 ) ) / Ref( XLE_03, -1 ) ) * 100;
PercentChg04 = ( ( XLF_04 - Ref( XLF_04, -1 ) ) / Ref( XLF_04, -1 ) ) * 100;
PercentChg05 = ( ( XLV_05 - Ref( XLV_05, -1 ) ) / Ref( XLV_05, -1 ) ) * 100;
PercentChg06 = ( ( XLI_06 - Ref( XLI_06, -1 ) ) / Ref( XLI_06, -1 ) ) * 100;
PercentChg07 = ( ( XLB_07 - Ref( XLB_07, -1 ) ) / Ref( XLB_07, -1 ) ) * 100;
PercentChg08 = ( ( XLRE_08 - Ref( XLRE_08, -1 ) ) / Ref( XLRE_08, -1 ) ) * 100;
PercentChg09 = ( ( XLK_09 - Ref( XLK_09, -1 ) ) / Ref( XLK_09, -1 ) ) * 100;
PercentChg10 = ( ( XLU_10 - Ref( XLU_10, -1 ) ) / Ref( XLU_10, -1 ) ) * 100;
PercentChg11 = ( ( XLC_11 - Ref( XLC_11, -1 ) ) / Ref( XLC_11, -1 ) ) * 100;

Title = EncodeColor(colorWhite)+ "     SECTORES   S&P 500                                                                                         RSC M     Rank   Percentil\n" +
        EncodeColor(colorWhite)+ "SPLRCL        = " + NumToStr(PercentChg11,1.2) + " %" + " Telecomubnicaciones - Comunication Services" + " \n" +
        EncodeColor(colorOrange)+ "SPLRCD       = " + NumToStr(PercentChg02,1.2) + " %" + " Consumo Cíclico - Consumer Discretionary" + " \n" +
        EncodeColor(colorTurquoise)+ "SPLRCS       = " + NumToStr(PercentChg01,1.2) + " %" + " Consumo Básico - Consumer Staples" + " \n" +
        EncodeColor(colorViolet)+ "SPNY             = " + NumToStr(PercentChg03,1.2) + " %" + " Energia - Energy" + " \n" +
        EncodeColor(colorGreen)+ "SPSY             = " + NumToStr(PercentChg04,1.2) + " %" + " Financiero - Financials" + " \n" +
        EncodeColor(colorRed)+ "SPXHC          = " + NumToStr(PercentChg05,1.2) + " %" + " Cuidados de Salud - Health Care" + " \n" +
        EncodeColor(colorYellow)+ "SPLRCI         = " + NumToStr(PercentChg06,1.2) + " %" + " Industria - Industrials" + " \n" +
        EncodeColor(colorBrown)+ "SPLRCT       = " + NumToStr(PercentChg09,1.2) + " %" + " Tecnología - Information Technology" + " \n" +
        EncodeColor(colorCustom10)+ "SPLRCM       = " + NumToStr(PercentChg07,1.2) + " %" + " Materiales Básicos - Materials" + " \n" +
        EncodeColor(colorCustom16)+ "SPLRCREC = " + NumToStr(PercentChg08,1.2) + " %" + " Inmobiliaria - Real State" + " \n" +
        EncodeColor(colorWhite)+ "SPLRCU       = " + NumToStr(PercentChg10,1.2) + " %" + " Utilidades - Utilities" + " \n" ;

It is unknown whether you just want to display results in title of chart or whether you want to plot a chart (e.g. scatter or whatever) using your values.

Why don't you just keep Explorer if you just want to output values?
FYI, you can add name of Ticker to Explorer too by just adding additional column.

Filter = Status("LastBarInRange");
SetOption("NoDefaultColumns", 1);
AddTextColumn(Name(), "Sector", 1, colorDefault, colorDefault);
AddTextColumn(FullName(), "FullName", 1, colorDefault, colorDefault);
AddColumn(DateTIme(), "DateTime", formatDateTime, colorDefault, colorDefault);
//etc.

Also you can color cells in same way as to be seen in your chart.
Explorer already has nice table view.
So don't quite understand additional work.

If you want to graph values then you can use XYChart* feature of Explorer



etc.

Also see
http://www.amibroker.com/guide/h_exploration.html


BTW,
This one

PercentChg01 = ( ( XLP_01 - Ref( XLP_01, -1 ) ) / Ref( XLP_01, -1 ) ) * 100;

is just this one

PercentChg01 = Roc(XLP_01, 1);

etc.


Also remove RestorePriceArrays(); inside loop. It is not needed as you use Foreign.


Anyway...
But if you really want to get the values in chart then simply call static var you created

E.g.

values1 = StaticVarGet( "RSCM" + "SPLRCS");
rank1 = StaticVarGet( "RankRSCM" + "RSCM" + "SPLRCS" );

Another hint:
Your code can be much more simplified by iteration and better formatting.
It really looks not good (the second part).

2 Likes

Thanks for your comments @fxshrat.
I have already changed the code with your ideas.
I just need to see the results of the 3 columns in the chart title.