[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Need an example of for loop in afl



PureBytes Links

Trading Reference Links


In the following version, we need only 16 steps [instead of 4,143] 
for the same result.

y0=0; k0=0;step=0.1;Title="";
for(z=1;z<2;z=z+step)
{
if(z^2>2)
{
z=z-step;
step=step/10;
}
if(step<0.00001)
{
y0=z;
z=2;
}
Title=Title+"\n"+WriteVal(z,1.5);
k0=k0+1;
}
Title=Title+"\nSqrt(2)="+WriteVal(y0,1.5)+" [ "+WriteVal(k0,1.0)+" 
steps]";

The trick is interesting : In the first code we search all numbers 
from 1 to 2 with an accuracy 0.0001.
The method needs [theoretically] 10,000 steps and will stop after the 
4,143th step.
The second method uses a crude approximation first [accuracy 0.1] and 
increases the accuracy when the result is near to the final solution.
As you see, a more sophisticated code may decrease the steps from 
4,143 to 16 and offer the same accuracy much faster.
Dimitris


--- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxx> 
wrote:
> 
> The following Indicator Builder code will calculate the sqrt(2) in 
> 4143 steps.
> 
> y0=0; k0=0;
> for(z=1;z<2;z=z+0.0001)
> {
> if(z^2>2)
> {
> y0=z;
> z=2;
> }
> k0=k0+1;
> }
> Title="Sqrt(2)="+WriteVal(y0,1.4)+" [ "+WriteVal(k0,1.0)+" steps]";
> 
> z is equal to 1 and has an increment of 0.0001 in every step.
> If z^2>2 then 
> a. the respective z is calculated and
> b. the loop is terminated
> If z^2<=2, then k0 [the counter] is increased by +1 for every step.
> We may have the same result with less steps [faster], but the code 
> should be more complicated. 
> Dimitris
> --- In amibroker@xxxxxxxxxxxxxxx, "kubikconcepts" 
> <kubikconcepts@xxxx> wrote:
> > 
> > Hello,
> > Can somebody post an example of how to use the for loop in AFL?   
> > 
> > Thanks.





------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/