I suspect I’m asking a simple question, but would appreciate some assistance. I’m trying to create a matrix with rows equal to the number of tickers in a watchlist, retaining a selectedvalue of an indicator in the matrix.
I can create a matrix for a single ticker with barcount number of rows or columns with code similar to “code 1”.
Also, I can create a matrix with a watchlist count of rows with “code 2”, but am unable to accumulate the desired value in the matrix.
Any help would be greatly appreciated.
//Code 1
function F1Value(level)
{
X1=MA(C,10);
return x1;
}
function F2Value(level)
{
X2=MA(C,50);
return x2;
}
function getvalues( level )
{
F1num=F1value(C);
F2num=F2value(C);
mat = Matrix(BarCount, 2);
mat = MxSetBlock(mat, 0, BarCount-1, 0,0, F1num);
mat = MxSetBlock(mat, 0, BarCount-1, 1,1, F2num);
return mat;
}
mat = getvalues( C );
MxToString(Mat);
//code 2
wlnumber = GetOption( "FilterIncludeWatchlist" ); // choose WL in Analysis window
symlist = CategoryGetSymbols( categoryWatchlist, wlnumber );
SYMCOUNT=0;
for( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
{
num = StrCount( symlist, "," ) + 1 ;
if ( Status( "stocknum" ) == 0 )
{
StaticVarRemove("*");
}
StaticVarSet("symcount", num);
}
//**************************************************************************************
function F1Value(level)
{
X1=MA(C,10);
return x1;
}
function F2Value(level)
{
X2=MA(C,50);
return x2;
}
//**************************************************************************************
//Create matrix
SYMCOUNT=StaticVarGet("SYMCOUNT",num);
MXCOORD=Matrix(SYMCOUNT,4,Null);
for( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
{
SetForeign(sym);
F1num=F1value(C);
F2num=F2value(C);
MxSetBlock(MXCOORD, 0, 0, 1,1, f1num);
MxSetBlock(MXCOORD, 0, 0, 2,2, f2num);
MxSetBlock(MXCOORD, 0, 0, 3,3, i);
RestorePriceArrays();
StaticVarSetText("name " + NumToStr(i,1.0),sym);
AddColumn(f1num,SYM + " /X1",2.2);
AddColumn(f2num,SYM + " /X2",2.2);
}
MxToString( MXCOORD);
Filter=1;
AddColumn(StaticVarGet("symcount"),"count",2.0);
type or paste code here