ok thanks. I was actually wanting to use it in such a way that a function can return multiple arrays.

for instance I have a function that calculates peaks and troughs but at the same time (within the same loop) also 4 other arrays are calculated. What I do now is save all arrays in 6 static variable arrays and then define a separate function to get these arrays.

I though maybe I could fill up the matrix with these 6 arrays and get them all at once. But I think I will need to be able to access matrix elements for this.

But no big issue. My knowledge of C++ is too small to do it in another way although I had a look at the Osaka source code

yes this is what I had been using (gSite.Setvariable) but from later comments I understood that the correct way of working with ADK is that one needs to work with functions that (might) have parameters and return a value or array. Maybe I understood that incorrectly. I thought it also had something to do with multi-threading. In any case using a function and ask it for some return is more transparent.

I forgot about this latest addition in 6.25, will check it out

You mixed things a little bit. The advice from the other thread was not to use complex HIDDEN relationships via variables. If you PASS the variables to the function EXPLICITLY there is no “hidden” relationship. Generally best practice is to return single result from any function. But if for some reasons you need to return more, then you can use the technique presented in KB because it is EXPLICIT about which variables get modified. And no, multithreading has nothing to do with that (normal variables are thread-private)

Tomasz, I wonder what you think about adding some AFL statistical functions to support matrix data type, e.g. sum , average, stand deviation, sorting, percentile ranking, etc that are currently available to single-ticker time series. A possibly related functionality is to extend the “AddToComposite” (which computes the sum and can be used to compute average) function to the above mentioned statistical calculations for cross-sectional analysis, e.g. when build portfolio-level trading strategies.
Thank you in advance for sharing your thoughts on this subject.

@Tomasz
Thank you for clearly & simply describing how to calculate statistics for matrices.

I’ve been trying to work out how to calculate Stdev from 5000 element matrix which I mxgetblock() as array so I could use inbuilt AFL function.
Since I wanted to chart a generated distribution (for heck of it).

Converted to array but -1exx or whatever for >200 bars, then changed preference setting to 1000. Should be plenty good enough but asked myself how?
Above post answered.
FE

Technically it is just a matter of providing header file, but matrix functionality is being expanded and exposing it via API means locking it from expansion (ADK spec need to be backward compatible), so it will occur not sooner than when I am sure that we don’t need to change the API quickly.

@Tomasz I was too terse and assumed background. Old problem boss (manager not technical) used to get the red pen out.
I’ve been coding matrix with 5000 gaussian variables from mtrandom using Box-Muller transform algo I copied. Then to verify the data, I tried to use superlative PriceVolDistribution() function to display in mode=3 (x-bars, y-pixels).
Function needs array for H, L, Vol vars.
Trying several approaches reduced the samples size from matrix size to barcount size. Default 200 bars or visible bars. That’s normal, but I wanted to convert matrix[5000] to array[5000] inside the function.
I think I’ve confirmed that doesn’t happen. I used debug and _trace.
So accessing bars outside barcount range returns error, -1e31 or some NAN.
Also tried changing bars in settings(new feature) and turned off quickafl.

Now got matrix RandGauss() code (6 lines, amazing matrix functions) working. Now working to display data with gfx. It’ll be interesting to see if chart is any different.
Hope that’s clearer .
FE

Now I am trying to fill that matrix by calling MxSetBlock function
The line I am struggling with is arg2[ 0 ] = m;
I do not think that is a correct line of mine since I am not setting any type.

Thank you. I wasn't sure because if compiling and calling the DLL function from AFL editor then the AmiBroker engine reports Error 27 for DLL's MxSetBlock
"Invalid number of arguments passed to Call Function (..) from plugin DLL".

The MxSetBlock AFL function reference of AmiBroker guide documents 6 arguments https://www.amibroker.com/guide/afl/mxsetblock.html
and in my DLL function there are 6 ones also. Is there anything I am missing?

Hello @Tomsaz,
What about matrix operations like addition, subtraction, product and multiplication, Is there a way to call those functions via g.Site.CallFunction()?

Why not just use AFL for such basic operations? There is no gain in writing DLL. Just the opposite. DLLs slow things down as they use blocking critical section to prevent reentrancy problems with code written by users not being aware how to write safe reentrant code.

Hello @Tomasz,
Because I have been having problems with AFL:

Therefore I am forced to come up with workarounds :

A year ago you said that matrix functionality is being expanded and exposing it via API will lock it from expansion.
A year later, the only thing I can think of is that expanding matrix functionality has not been a priority - its OK, you decide that.
In the mean time, do you think that an intermediate ADK update to allow at least element wise matrix operations is doable?