How would I know that? You don't show the definition of N, and the number of GetNewestSD() calls depends on the outcome of the do-while loop condition. Plus int Round is local to run() but somehow you're using it in the GetNewestSD() code? Does this even compile?

Consider also what the manual says:
Quote
Matrices are created in the INITRUN and released after the EXITRUN. Just like series, matrix() creation must happen in the same order at any bar, preferably at the begin of the run function.
This probably means the values are retained in memory between run calls. Also note the advice it gives about the location of the matrix() calls.