How to operate ARRAY?

Hi, big guys

Amibroker Version 6.40.4

Question 1:

There a formula (Xi - X_bar)

How to use ARRAY to express instead of LOOP? (it’s not efficient with loop.)

Sample code :

Period = 5; // Start Index

CloseAverage = MA(Close, Period);

IndexValue = 0;

for (i = Period; i < BarCount; i++)
{
	for (j = 0; j > 5; j++)
	{
		IndexValue[i] = Close[i-j] - CloseAverage[i];
	}
}

Question 2:

There’s a series with both positive and negative numbers (see picture for example), if i want to select down 5 positive numbers from X starting value (date) to calculate it, like examples 1~3 below. How can i use ARRAY to express instead of use LOOP?

Q

thanks.

@hengyiuchang - for your first question, can you clarify what precisely you are trying to do ( in plain English)

For your second question, your 'array' is backwards - the dates should be increasing in value from left to right.

Hi, @vmonkey

First question has been resolved.

Second question, I reversed the dates

Tomasz has helped me here.

1 Like

great @hengyiuchang! you will probably find lots of uses for sparse compress/expand - very useful functions

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.