John,
Put a _TRACE statement at the end of your loop (ie. just before the
closing brace) for variables period[i], factor[i], and Vaexp[i], and
you will see what the problem is if you look at the output in DebugView.
_TRACE(StrFormat("period = %1.3f, factor = %1.3f, vaexp = %1.3f",
period[i], factor[i], Vaexp[i]));
Essentially it's an issue of propogating Nulls through the loop, since
ATR(50) starts off as Null and every operation involving Null gives a
Null result. Basing the value of Vaexp[i] on Vaexp[i-1] then
propogates the Null value through the whole array.
Regards,
GP
--- In [email protected], <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> i am trying to teach myself how to use teh looping statements in AFL.
> So i have used teh code example:
>
> _SECTION_BEGIN("Looptest");
>
> Period=10*ATR(50);
>
> Vaexp[ 0 ] = Close[ 0 ]; // initialise first value
>
> for( i = 1; i < BarCount; i++)
> {
> //calculate the value of the smoothing factor
> factor = 2/(period[ i ] + 1);
>
> //calculate the value of the i-th element of the array
> //using this bars close (close [ i ]) and the previous average
value ( vaexp{ i - 1])
> Vaexp[ i ] = factor * Close[ i ] + (1 - factor) * Vaexp[ i - 1 ];
> }
> _SECTION_END();
>
> ...
>
> now i want to know how i plot VAexp as an indicator on a chart (i am
getting a few strange outputs with the code i have been trying -
including using PLOT within the loop. When i use PLOT outside the loop
i get an empty chart)
>
> Think its probably a simple answer, but i cant get to it..
>
> J
>
>
>
> John Ramdenee
>