Incorrect number of rows and/or columns error in matrix initialization

matrix_error

I checked the type of input and it is showing "number" and the values are not more than 1000.
I wonder what this error mean and still the code is working on chart and exploration.
I checked the documentation for Matrix function there is no specification given for any specific limits. What am I missing here?

The chart symbol also have enough bars in data.

You are possibly getting negative or Null values for matrix dimensions.
Check yourself. No code posted.

as seen in interpretation window rows:87 and cols:463 still I am getting this error.

Check it via _trace function not via printf.

Also once again you have not posted reproducible code.
Follow forum rules!

Thanks for you quick responses.
This is minimum error reproducible code. I am using version Amibroker 6.49.1 x64

SetBarsRequired( sbrAll, sbrAll );
EnableTextOutput(False);
mode = ParamToggle( "Box Mode", "Auto|Manual" );
atrper = Param( "ATR Period", 14, 2, 100, 1 );
boxper = Param( "Boxsize(%ATR)", 5, 0.1, 20, 0.1 )/100;
boxsize = Param( "BoxSize(Points)", 50, 0, 1000, 0.05 );
startdate = ParamDate( "Start Date", "01-01-2024", 0 );

// calculation for auto mode

TimeFrameSet(inDaily);
ydatr = Ref(ATR(atrper), -1);
TimeFrameRestore();
ydatre = TimeFrameExpand(ydatr, inDaily, expandFirst);

if(!mode)
boxsize = LastValue(ydatre)*boxper;

// global values

spread = 0.05;
tn = TimeNum();
dn = DateNum();
bi = BarIndex();
lbar = BarCount - 1;																		// last barindex of chart
fc = dn != Ref( dn, -1 );																	// day's first bar flag
lc = Ref(fc, 1) OR (bi == lbar);															// day's last bar flag
fcbi = ValueWhen( fc, bi, 1 );																// barindex of first bar of day
lcbi = ValueWhen( lc, bi, 0 );																// barindex of last bar of day (in future)
ibar = LastValue( ValueWhen( dn >= startdate AND Ref( dn, -1 ) < startdate, bi, 1 ) );		// barindex on start date first candle
relbi = bi - fcbi;																			// relative barindex from day's first bar
boxsize = round( boxsize / spread ) * spread + 1e-20;										// boxsize roundoff and avoiding division by zero
hh = LastValue( HHV( H, lbar - ibar + 1 ) );												// highest price in given history
ll = LastValue( LLV( L, lbar - ibar + 1 ) );												// lowest price in given history
last_box_high = round( hh / boxsize ) * boxsize + boxsize/2;								// high level of top most box
first_box_low = round( ll / boxsize ) * boxsize - boxsize/2;								// low level of bottom most box
rows = int( ( last_box_high - first_box_low ) / boxsize );									// total price box for matrix definition
cols = lbar - ibar + 1;																		// total bars for matrix definition

// initializing matrices and array values
// the following loop will fill all the matrices and arrays

boxl = Matrix( rows, cols, -1 );			// matrix for box low level
boxh = Matrix( rows, cols, -1 );			// matrix for box high level
boxp = Matrix( rows, cols, 1e20 );			// matrix for box price profile set to 1 or 0
boxtpo = Matrix( rows, cols, 1e20 );		// matrix for box time price opportunity 
boxdpd = Matrix( rows, cols, 0 );			// matrix for box showing daily price distribution on first bar only
boxdpp = Matrix( rows, cols, 1e20 );		// matrix for box showing daily price profile

matrix_error1

@Rakesh, check the value of the boxsize variable.
I tested with 1-minute bars and that value when getting the error was 1e-20

In my test ydatre was 0 so the boxsize too was zero here:

if(!mode)
	boxsize = LastValue(ydatre)*boxper;

Then you use it again in this line:

boxsize = round( boxsize / spread ) * spread + 1e-20;

I already wrote before that some unknown variable (because of not posting code) would return negative or null!

Always those bandwagon jumpers.

You have two problems.

Incorrect number of rows/columns and too large size of Matrix.

So for rows to remove Error of incorrect number you may write

rows = Min(100, Max(1, Nz(rows)));

Why min 100?
Why would you need 1000 boxes?
Also because Matrix size can not be larger than 500 million Elements.

1000 boxes multiplied by 500000 bars is reaching that.
But even 100 is too large. Can you see 100 boxes per bar on Chart?
I dont know what you want to do.

But anyway... to remove size Error.

cols = Min(1e6/rows, cols);

If rows would be 100 (boxes) then columns would be max 10000 (bars). And size of Matrix being one million elements.

Thanks @beppe and @fxshrat,
You are right. The boxsize variable is the root cause, somehow it managed to get to near zero value, which might be making number of rows to millions. so now I replaced previous filter with a filter which is logically right, I don't want boxsize to be smaller than ticksize(spread). And make all error disappear.

spread = 0.05;
boxsize = Max(boxsize, spread);

Thanks you, you both gave right solution.