PureBytes Links
Trading Reference Links
|
Ah, I see.
PREV is a Kludge for Looping in MetaStock.
Gotchya.
KR
Michael.
At 02:43 AM 30/07/2003 +0200, you wrote:
>Michael,
>
>PREV in metastock is not a function and it can not be written as a function.
>It is a 'magic word' (or 'special variable') that causes that metastock
>instead of executing formula
>once, executes is as many times as there are bars loaded.
>This makes it that slow. It is sick workaround in MS language that does
>not support looping.
>
>Looping is hundeds times faster, better and nicer way of writing formulas
>involving interation.
>
>Best regards,
>Tomasz Janeczko
>amibroker.com
>----- Original Message -----
>From: "Michael.S.G." <OzFalcon@xxxxxxxx>
>To: <amibroker@xxxxxxxxxxxxxxx>
>Sent: Wednesday, July 30, 2003 2:27 AM
>Subject: RE: [amibroker] Re: Translation into AFL
>
>
> > 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));
> > > > >
> > > > >
> > > > > ---
> >
> >
> >
> >
> > 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/
> >
> >
> >
>
>
>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/
|