----- Original Message -----
Sent: Sunday, March 26, 2006 9:18
AM
Subject: [amibroker] Simple code
problem
Hi,
This is my first
attempt at using the built in language to program. I wrote the code
below, a simple moving average, which looks correct but only works correctly
when “Periods” has a value of 3. Any other value and the resulting line
has a much greater value than the closing prices. I know there are
functions to do this, but I’m just trying to make an example to teach
myself.
Periods = Param("Periods", 10, 2, 200, 1, 1 );
n = 0;
for ( i
= 0; i < BarCount; i++
){
if( i > Periods ){
for ( j = i -
(Periods-1); j <= Periods; j++ ){
n =
n + Ref(Close,-j);
}
}
}
n = n /
Periods;
Plot( n, "MA", ParamColor( "Color", colorCycle ), ParamStyle("Style"));
However, it seems more sense to me to code it the following way,
which slows the software down and also ends up with the wrong
values. Am I missing something with the way
the flow of the code works in
AmiBroker.
Periods = Param("Periods", 10, 2, 200, 1, 1 );
for ( i
= 0; i < BarCount; i++
){
if( i > Periods ){
n = 0;
for ( j = Periods; j >= 0; j-- ){
n = n + Ref(Close,-j);
}
n = n / Periods;
Plot( n, "MA", ParamColor( "Color", colorCycle ), ParamStyle("Style"));
}
}
Thanks