Amibroker - how to use for loops (?) - Aussie Stock Forums

# Thread: Amibroker - how to use for loops (?)

1. ## Amibroker - how to use for loops (?)

Hi all ! I'm new here and I'm new in Amibroker. I'm looking help for write a code for back test for rules:
1. buy when MACD cross Signal , and....
2. the same conditions like in 1. but occured max 10 days before 1.

I'm thinking the best way is to use for loop but how to write it in AFL ...?

thanks

2. ## Re: Amibroker - how to use for loops (?)

Hi Cor --

AmiBroker's fundamental data structure is an array of prices -- OHLCVI. Many of the operations that manipulate the data and produce Buy and Sell signals operate on arrays and return arrays. Everything you have described can be done with native operations without the use of loops. The MACD function is an array function, the Signal function is an array function, the Cross function identifies when two arrays cross, and the Ref function provides access to prior values.

I recommend reading some of the introductory and tutorial material on the AmiBroker website, and in the AmiBroker Library.

Best wishes,
Howard

3. ## Re: Amibroker - how to use for loops (?)

Howard, thanks for your replay !
I know possibolity of Ref, but in this case I'd like to use for loop (also for my education and experience).
could you help ???

4. ## Re: Amibroker - how to use for loops (?)

Originally Posted by Cor
I'd like to use for loop (also for my education and experience).
There's no need for a loop to code the statements in your first post but if you want to learn looping then the thread link below has an excellent tutorial/document on looping.

5. ## Re: Amibroker - how to use for loops (?)

thanks Captain,
I know that it is not needed but I want to do this loop !
help ...

6. ## Re: Amibroker - how to use for loops (?)

Hi All,
I 've created two codes:

// j1 = condition of cross

1.
for (i=1; i < 4; i++)
{
factor = Ref( j1, -i );
}
buy = j1 and factor >0;

2.
for( i = 1; i < 4; i++ )
{
VarSet( "ab"+i, Ref( j1, -i ) );
}
con1 = ab1+ab2+ab3;
con2 = con1>0;

...
1. is not working good, because buy only for j1 and Ref(j1,-3).
2. is working good but is not smooth.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Aussie Stock Forums