Output of string counting function and matrix dimensions

I am trying to get a string containing tickers from the parameter window, count the number of tickers D in the string and form a DxD matrix as follows:

TickersList = ParamStr("Tickers List","MSFT,AMZN,NFLX" );
NoTickers = 1 + StrCount( TickersList, "," );
DMatrix = Matrix(NoTickers, NoTickers, 999 );
rows = MxGetSize( DMatrix, 0 );
columns = MxGetSize( DMatrix, 1 );
printf(NumToStr(rows));
printf(NumToStr(columns));
A=DMatrix[2][2];
printf(NumToStr(A));

Although the number of rows and columns in printf comes out correct, equal to 3, when I am trying to print the [2][2] element, I get:

Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range

_TRACE shows that DMatrix is indeed a matrix.

On the other hand, if I give the list myself (not getting it from parameters window), everything works ok. The code below correctly returns 999 as the value of DMatrix[2][2].

TickersList = "MSFT,AMZN,NFLX";
NoTickers = 1 + StrCount( TickersList, "," );
DMatrix = Matrix(NoTickers, NoTickers, 999 );
rows = MxGetSize( DMatrix, 0 );
columns = MxGetSize( DMatrix, 1 );
printf(NumToStr(rows));
printf(NumToStr(columns));
A=DMatrix[2][2];
printf(NumToStr(A));

Any suggestions how to get the tickers from the parameter window and still get the code to work? Thank you.

Please note that Parameters window is separate for chart and separate for Analysis window and Param() would give different answers if used in chart and in Analysis (separate parameters, remember).

You might be using some other parameter set than you think you are using.

Use the debugger and/or _TRACE

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.