What you say is incorrect.
There is no problem (error message) when "original" array becomes empty (NULL);
If mySignalLast
is Null then Matrix is Null (spcond
becomes zero -> spc and spi become Null).

Same applies if there is no signal (zero array) then spcond
returns zero array too.
And spc and spi become Null array and Nullcount becoming length Barcount.

Adding Min(NullCount(spc), col)
as in 2nd post prevents error! Also NullCount does not become negative. Range of NullCount is from zero to BarCount.
So there is zero problem and nothing complicated.
Task was... creating custom array avoiding loop.
More simplified (adding spcond is not required):
bi = BarIndex();
qfdb = Status("quickaflfirstdatabar");
function MxValuesAtSignal(sig) {
/// @link https://forum.amibroker.com/t/loop-i-would-like-to-avoid/16828/8
/// by fxshrat
local col, mat, spc, spi;
spc = SparseCompress(sig, C);
spi = SparseCompress(sig, /*qfdb +*/ bi);
mat = Matrix(2, BarCount, Null);
col = MxGetSize(mat, 1)-1;
mat = MxSetBlock(mat, 0, 0, 0, col, spc);
mat = MxSetBlock(mat, 1, 1, 0, col, spi);
mat = MxGetBlock(mat, 0, 1, Min(NullCount(spc), col), col);
return mat;
}
mySignalLast = Cross(C, MA(C, 200));//Null;//
mat = MxValuesAtSignal(mySignalLast);
MxToString(mat);
if ( mat ) printf( "#Signals: %g", MxGetSize(mat, 1) );
Plot( C, "Price", colorDefault, styleBar );
PlotShapes( mySignalLast * shapeUpArrow, colorGreen, layer = 0, L, -12 );