Australian (ASX) Stock Market Forum

Amibroker - how to use for loops (?)

Cor

Joined
28 June 2011
Posts
8
Reactions
0
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 ...?

please, help ....
thanks
 
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
 
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 ???
 
thanks Captain,
I know that it is not needed but I want to do this loop ! :)
help ... :)
 
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;
buy = j1 and con2;

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

Could you correct please ????
 
Top