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

RE: [amibroker] Re: Translation into AFL



PureBytes Links

Trading Reference Links

To help all the MS users that ask for the PREV function,
  Would a solution be to write an AFL function (With whatever looping is 
required), Call it PREV and upload it to the 3rd party & Online AFL 
sections for anyone asking to download? They then just pop this code into 
the front of their afl and away they go.

<MSG>

At 10:49 AM 29/07/2003 -0400, you wrote:
>Tomasz,
>We routinely see MS code using PREV on this forum. You have indeed shown
>many times that  AMA, or now, native loops, can be used to emulate MS PREV
>code. Since so many (including myself) still struggle with looping Would it
>make any sense for AB to simply offer PREV as a function?
>
>Regards,
>Jayson
>
>
>-----Original Message-----
>From: Tomasz Janeczko [mailto:amibroker@xxxxxx]
>Sent: Tuesday, July 29, 2003 10:24 AM
>To: amibroker@xxxxxxxxxxxxxxx
>Subject: Re: [amibroker] Re: Translation into AFL
>
>
>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));
> > >
> > >
> > > ---



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/sO0ANB/LIdGAA/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/