StaticVarGet and GfxTextOut

Hi, I am developing a system which takes into account among other criteria the strength of the price either in reference to the SP500 or to the respective market index.

To do this, for testing purposes I am calculating the static variables in the exploration for one or more markets and trying to reflect this in the chart template.

The problem occurs when I try to switch from one security to another on the chart as the chart does not update the security unless I double click on the respective tick in the exploration.

Does anyone know why this happens and what could be the solution.

Code

Filter=1;

list=CategoryGetSymbols(categoryMarket,MarketID());


ListQty=StrCount(List,",")+1;

ValorSP500=Foreign("SPX","C");


StaticVarRemove("RSC*");


for ( i = 0; ( symbol = StrExtract( List, i ) ) != ""; i++ )
		
	{
		Cociente = Close / ValorSP500;
		CountR = Sum(Cociente , 52);
		Baseprice = CountR / 52 ;
		RSCValor = ((Cociente / Baseprice ) - 1)*10;
					
		StaticVarSet( "RSCValor"+MarketID()+symbol, LastValue(RSCValor));
		V=StaticVarGet( "RSCValor" +MarketID()+symbol);
	}
		
AddColumn(V,"RSC Simbolo",1.2);

Graphic code:

GfxTextOut("RSC Mansfield :" + StaticVarGetText( "RSCValor" +MarketID()+symbol) ,50,150);

Exploration result:

@antoniomartngarca, it seems to me that there are multiple problems to deal with... (even ignoring the Warning 512!)

I think this should be:

Cociente = Foreign(symbol, "C" ) / ValorSP500;

Moreover, I wonder why do you use LastValue():

StaticVarSet( "RSCValor"+MarketID()+symbol, LastValue(RSCValor));

Since you are working with arrays, you can store your calculated "strenght" for all the bars:

StaticVarSet( "RSCValor"+MarketID()+symbol, RSCValor);

And this one is just a bad idea:

V=StaticVarGet( "RSCValor" +MarketID()+symbol);

You are assigning your calculate values to the Volume array... Use a different variable name like:

values=StaticVarGet( "RSCValor" +MarketID()+symbol);

More generally, you should avoid recalculating values ​​when changing the active symbol, if the corresponding MarketID() is not different from the previous symbol.

Fixing these problems will probably also allow you to get the desired result for displaying the data on the chart (also take a look at the SelectedValue() function)

@antoniomartngarca, looking better at the code I wonder what the loop is actually for?
For a chart you can directly calculate and visualize the value without using any static variable (here keeping your calculations):

ValorSP500 = Foreign( "$SPX", "C" );
Cociente = Close / ValorSP500;
CountR = Sum( Cociente , 52 );
Baseprice = CountR / 52 ;
RSCValor = ( ( Cociente / Baseprice ) - 1 ) * 10;
GfxTextOut( "RSC Mansfield :" + SelectedValue( RSCValor ), 50, 150 );

Filter = 1;
AddColumn(RSCValor, "RSCValor", 1.5);

and for the exploration you will should simply select a specific market in the Filter setting dialog.

image