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

[amibroker] Re: Questions re: AFL



PureBytes Links

Trading Reference Links

Ron,

Tomasz answered your Prev question some time ago. Don't have the 
number, just the info:


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.

Regards,

John

--- In amibroker@xxxxxxxxxxxxxxx, "Graham" <gkavanagh@xxxx> wrote:
> Rck
> The help screens are up to date per the last official release, plus 
there is
> a htm file for the Beta changes with each Beta release.
> Help files can also be downloaded separately, and there is an online
> function reference
> 
> Prev - there has been a lot of discussion over time on this , check 
the
> history of these emails in the yahoo group. 
> 
> Cheers,
> Graham
> http://groups.msn.com/asxsharetrading
> http://groups.msn.com/fmsaustralia 
> 
> -----Original Message-----
> From: rck1135 [mailto:rkrebs@x...] 
> Sent: Saturday, 6 December 2003 8:33 AM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Questions re: AFL
> 
> 
> I am using the evaluation version of AB and have a couple of 
> questions regarding the programming language:
> 1.  Is there a an up to date manual available covering all of the 
AFL 
> commands and functions?
> 
> 2.  I have been using MS and wonder if AB has a function similar to 
> the MS 'PREV' function?
> 
> Have been lurking in this forum for several days and as another 
> fellow wrote; this is a very helpful and friendly group!
> Many Thanks,
> Ron - Mission Viejo, CA
> 
> 
> 
> 
> ------------------------ 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/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
> --------------------------------------------------------------------
-~->
> 
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> 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 ---------------------~-->
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/mOAaAA/3exGAA/qnsNAA/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/