Custom arrays with individual length

Arrays in amibroker (for instance the price arrays) seems to have the length of barcount.
So with

for (i = 1; i < BarCount; i++) { if (C[i] > O[i]) { // Close is greater than Open ... }; } it is possible to iterate through the whole array.

So, for instance, in the programming language JAVA it is possible to create arrays:

		int myArray[] = new int[3];
		myArray[0] = 6;
		myArray[1] = 3;
		myArray[2] = myArray[0] + myArray[1];

But it is possible to create and use arrays with self defined length in amibroker?

You may use Matrix functionality of AmiBroker

rows = 3;
cols = 1;
mat = Matrix( rows, cols );
mat[0][0] = 6;
mat[1][0] = 3;
mat[2][0] = mat[0][0] + mat[1][0];

Matrix dimensions can exceed symbol’s length of array.

Thank you for the tip.
Is it possible to dynamic extend the length of the matrix?

I'm not sure what is your specific use case but for example you could easily make custom matrix functions such as "MxCombine" or "MxStack" (those two ones are sample names) to change size of a previously defined Matrix A. See difference below (those functions are similar to MatLab functions). (And no, I will not post copy&paste ready code as I'm not doing mental work for others all the time.).

It's easy!

Custom "MxCombine" examples
Dim = 1

Dim = 0

On the other hand custom "MxStack" function example(s) -> Matrix B gets appended to Matrix A

or just stacking a Null matrix B ( here B = Matrix( 5, 3, Null); ) to Matrix A (NULLs of rows 5 to 9 of new result matrix A could be replaced by some other values later on)

1 Like

I think I more or less know now what you are looking for or want to know if it is possible...
Let's say you have some array condition and you want to output a custom array based on that very same condition. The size would be the number of "TRUE" occurrences of that array condition. If that's what you are looking for then yes, you can do that too.

You would need following functions for creating your user-defined matrix function (let's call it MxDynamixArray()):
SparseCompress(...), NullCount(...), Matrix(...), MxSetBlock(...), Ref(...)
The entire user defined function would have 4 lines of code.

Example conditions and output (watch how row number of the result matrix dynamically changes if changing the array condition):

First, row number is 153 if using array condition " condition = MACD() > 0;" and output is "Close" array of condition being true.

Now, if you change the condition i.e. to " condition = Close > Open;" then row number dynamically changes to 205 rows.

So yes, things like that are doable.