Hello,
I want to pass the result of the screener to an array.
Thanks for your help
ListWL = CategoryGetSymbols( categoryWatchlist, 8 ); // Sotcks SP500
numtickers = 1 + StrCount( ListWL, "," );
// Define the Matrix. Always 5x3
rows = 5;
cols = 3;
myMatrix = Matrix( rows, cols, 0 );
MCap = Close * GetFnData( "SharesOut" );
Filter = MCap > 800000000000;
SetOption("NoDefaultColumns", True );
AddTextColumn(Name(),"Ticker");
AddTextColumn(FullName(),"Name");
AddColumn ( MCap, "MarketCap", 1.0 );
SetSortColumns( -3 );
//How can I pass the result to myMatrix?
for( i = 0; i < rows; i++ )
{
// assign matrix element
myMatrix[ i ][ 0 ] = " " ; // Error 8 --> Cannot assign a string
myMatrix[ i ][ 1 ] = " " ; // Error 8
myMatrix[ i ][ 2 ] = 1234546 ;
}

Matrix is numeric array only.
You can not store string to matrix.
You can store symbol's index in watchlist to matrix and then to call sym you can use StrExtract(yourWL, idx). Or simply use row index. So that way matrix size becomes smaller (e.g. just column vector (rx1
) where MCap is stored to).
ListWL = CategoryGetSymbols( categoryWatchlist, 8 ); // Stocks SP500
numtickers = 1 + StrCount( ListWL, "," );
// Define the Matrix. E.g. 5x2
rows = numtickers;
cols = 2;
myMatrix = Matrix( rows, cols, 0 );
rownum = MxGetSize(MyMatrix, 0);
MCap = Close * GetFnData( "SharesOut" );
Filter = MCap > 8e10 AND Status("lastbarinrange");
SetOption("NoDefaultColumns", True );
AddTextColumn(Name(),"Ticker");
AddTextColumn(FullName(),"Name");
AddColumn ( MCap, "MarketCap", 1.0 );
SetSortColumns( -3 );
// Matrix is numeric array. You can NOT store string to matrix.
for( i = 0; i < rownum; i++ )
{
sym = StrExtract(ListWl, i);
MCap = SelectedValue(Foreign(sym, "C")) * GetFnDataForeign( "SharesOut", sym );
// assign matrix element
myMatrix[ i ][ 0 ] = i; // symbol's index in WL
myMatrix[ i ][ 1 ] = MCap;
// just to double_check
_TRACEF("Sym: %s, value: %g", StrExtract(ListWl, myMatrix[ i ][ 0 ] ), myMatrix[ i ][ 1 ] );
}
_TRACE(MxToString(myMatrix));
4 Likes
Thanks @fxshrat for your quick response as always.
I have tried it and it works ok.