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

Re: [amibroker] Re: Help with formula- again...



PureBytes Links

Trading Reference Links




For those who are trying to convert MS code to AB 
code and have PREV somewhere within the MS code, TJ provided clues on how to 
proceed.
I get individual emails so I don't know the 
message number to this:
 
This is not recursion but ITERATION.PREV in 
metastock is not the value of some funciton butjust previous value of array 
(like in EMA formulation).What is more: even if some algorithm is 
recursive it can bealways 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 repeatingcode everywhere and not using 
variables at all (that's probablydue 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 andATR(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 
Janeczkoamibroker.com
-CS
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  <A title=gillesdeprez@xxxxxxxxx 
  href="">gillesdeprez 
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Saturday, September 06, 2003 1:36 
  AM
  Subject: [amibroker] Re: Help with 
  formula- again...
  Ok, but then what do I write instead of PREV? That's my 
  main problem, I have no idear what PREV refers 
  to...--- In <A 
  href="">amibroker@xxxxxxxxxxxxxxx, 
  "mrdavis9" <mrdavis9@x...> 
  wrote:> Should you have iif in the fifth line instead of if??  Ron 
  D>   ----- Original Message ----- >   From: 
  gillesdeprez >   To: <A 
  href="">amibroker@xxxxxxxxxxxxxxx 
  >   Sent: Saturday, September 06, 2003 12:42 
  AM>   Subject: [amibroker] Help with formula- 
  again...> > >   Hello,>   
  After fighting for hours, I give up after the fifth line, before I 
  >   jump trhu the window, screaming! I know I jump often- I 
  live on the >   ground level.>   If one 
  of you knows MS and is kind enough to give me a hand...>   
  "Recursive moving trend average">   Lb:=Input("Look-Back 
  Period?",3,100,21);>   Ty:=Input("1=C 2=H 3=L 4= Median 
  Price",1,4,1);>   
  Tv:=If(Ty=1,C,If(Ty=2,H,If(Ty=3,L,MP())));>   
  Alpha:=2/(LB+1);>   
  Bot:=(1-Alpha)*(If(Cum(1)<Lb,Tv,PREV))+Tv;>   
  RMTA:=(1-Alpha)*(If(Cum(1)<Lb,Tv,PREV))+>   
  (Alpha*(Tv+Bot-Ref(Bot,-1)));>   RMTA> 
  >   TIA!>   Gilles> > > 
  >   Send BUG REPORTS to bugs@xxxx>   Send 
  SUGGESTIONS to suggest@xxxx>   
  ----------------------------------------->   Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
  >   (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)>   
  -------------------------------------------->   Check group 
  FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  > >   Your use of Yahoo! Groups is subject to <A 
  href="">http://docs.yahoo.com/info/terms/Send 
  BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 







Yahoo! Groups Sponsor


  ADVERTISEMENT 









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 the Yahoo! Terms of Service.