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

Re: [amibroker] Re: Translation into AFL



PureBytes Links

Trading Reference Links

Stephane,

This is not recursion but ITERATION.
PREV in metastock is not the value of some funciton but
just previous value of array (like in EMA formulation).

What is more: even if some algorithm is recursive it can be
always rewriten to iterational form (there is a proof for this in computer science)

As for the question below, of course it can be written using loops
(as any other algorithm).

BTW: Metastock people have very interesting habit of repeating
code everywhere and not using variables at all (that's probably
due to the 20 variable limit that metastock has)

We would need to 'unwind' this bad coding practice:

Original:
If(LinearReg(C,13)>PREV,If(LinearReg(C,13)-(ATR(13)*2.5)>
PREV,LinearReg(C,13)-(ATR(13)*2.5),PREV),LinearReg(C,13));

So, we have LinearReg(C,13) in this formula mentioned 4 times and
ATR(13) mentioned 2 times.

So let us replace this with variables :

myLR = LinearReg( C, 13 );
myATR = ATR( 13 );

result =
   If(  myLR > PREV,
        If( myLR - 2.5 * myATR > PREV,
             myLR - 2.5 * myATR,
             PREV ),
      myLR );

Now let's rewrite to AFL native loops:

myLR = LinearReg( C, 13 );
myATR = ATR( 13 );

result[ 0 ] = myLR[ 0 ];
for( i = 1 ; i < BarCount; i++ )
{
   if( myLR[ i ] > result[ i - 1 ] )
   {
       temp = myLR[ i ] - 2.5 * myATR[ i ];

      if( temp > result[ i - 1 ] )    result[ i ] = temp;
      else                                    result[ i ] = result[ i - 1 ];
   }
   else
       result[ i ] = myLR[ i ];
}

Graph0=result;

Graph1=Close;

This shows "DIRECT" rewriting of the formula. Resulting AFL code is 100+ times faster than Metastock code.


Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "Stephane Carrasset" <nenapacwanfr@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Tuesday, July 29, 2003 3:16 PM
Subject: [amibroker] Re: Translation into AFL


> Hello,
> I ask to me if recursion is not supported ( a function call itself
> from within itself) is it possible to get this formula below ( with
> PREV) in pure AFL with loops?
>
> stephane
>
> In amibroker@xxxxxxxxxxxxxxx, "Anthony Faragasso" <ajf1111@xxxx>
> wrote:
> > If(LinearReg(C,13)>PREV,If(LinearReg(C,13)-(ATR(13)*2.5)>
> > PREV,LinearReg(C,13)-(ATR(13)*2.5),PREV),LinearReg(C,13));
> >
> >
> > x=IIf(LinearReg(C,13) > Ref(LinearReg(C,13),-1),
> > IIf(LinearReg(C,13)-(ATR(13)*2.5)>Ref(LinearReg(C,13)-(ATR(13)
> *2.5),-1),Line
> > arReg(C,13)-(ATR(13)*2.5),Ref(LinearReg(C,13)-(ATR(13)*2.5),-
> 1)),LinearReg(C
> > ,13));
> >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.504 / Virus Database: 302 - Release Date: 7/24/2003
>
>
>
> Send BUG REPORTS to bugs@xxxxxxxxxxxxx
> Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
> -----------------------------------------
> Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
> (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> --------------------------------------------
> Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Free shipping on all inkjet cartridge & refill kit orders to US & Canada. Low prices up to 80% off. We have your brand: HP, Epson, Lexmark & more.
http://www.c1tracking.com/l.asp?cid=5510
http://us.click.yahoo.com/GHXcIA/n.WGAA/ySSFAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

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