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

Re: [amibroker] Re: If(C<PREV,StLong,Max(StLong,PREV));



PureBytes Links

Trading Reference Links

Hello,

PREV in MS is needed because MS does NOT have looping.

In AB, there are loop constructs so there is no need for PREV
because loops give faster and more general way of solving coding problems.

Since loops are more general they allow easy translation of every
case where MS needs PREV.

Statment like this:
Z =(A*B)+(C*PREV);

Using loop looks as follows:

z = 0; // initialize
for( i = 1; i < BarCount; i++ )
{
  prev = Z[ i - 1 ]; // PREV is previous value of Z.
  Z[ i ] = A[ i ] * B[ i ] + C[ i ] * prev;
}

As you can see the statement is identical with the exception that 
AFL looping code uses [ ]  operator to access individual array elements.

Good thing is that AFL looping code is BarCount-times faster than MS code.
Since 5 years of EOD data is 1300 bars, AFL looping code is 1300 times faster than MS in that case.

It is also possible to use AMA/AMA2 instead of PREV:

Z = AMA2( A, B, C );

which is shorter but AMA is less general than looping code.

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "Thomas Ludwig" <Thomas.Ludwig@xxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Monday, April 04, 2005 2:45 PM
Subject: [amibroker] Re: If(C<PREV,StLong,Max(StLong,PREV));


> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Herman van den Bergen" 
> <psytek@xxxx> wrote:
>> This comes up a million times and is a constant frustration for ex-
> MS users;
>> the collective number of hours lost on this by new-comers must be 
> in the
>> thousands.
>> 
>> Can somebody write an MS-type Prev() in afl and add it to the afl 
> library?
> 
> Herman,
> 
> I don't think that's possible. According to the Metastock Formula 
> Primer "PREV is a special value that refers to the current formulas' 
> value for the previous period". The AFL translation below covers only 
> the AMA-type case. IMHO there are other cases where this translation 
> doesn't fit.
> 
> Greetings, Thomas
> 
>> 
>> // PREV
>> Z =(A*B)+(C*PREV);
>> 
>> can be written in AFL as:
>> 
>> Z = AMA2( A(array), B, C );
>> 
>> also:
>> 
>> xx = FactorA * Close + (FactorB * PREV(xx)); // metastock
>> 
>> translates to:
>> 
>> xx = AMA2( Close, FactorA, FactorB );
>> 
>> best regards,
>> herman.
>> 
>>   -----Original Message-----
>>   From: gunovanengel [mailto:gunovanengel@x...]
>>   Sent: Monday, April 04, 2005 3:11 AM
>>   To: amibroker@xxxxxxxxxxxxxxx
>>   Subject: [amibroker] If(C<PREV,StLong,Max(StLong,PREV));
>> 
>> 
>> 
>>   How do I change this to AmiBroker code
>> 
>>   Thanks
>>   Guno
>> 
>>   If(C<PREV,StLong,Max(StLong,PREV));
>> 
>> 
>> 
>> 
>> 
>>   Please note that this group is for discussion between users only.
>> 
>>   To get support from AmiBroker please send an e-mail directly to
>>   SUPPORT {at} amibroker.com
>> 
>>   For other support material please check also:
>>   http://www.amibroker.com/support.html
>> 
>> 
>> 
>> 
>> 
>> --------------------------------------------------------------------
> --------
>> --
>>   Yahoo! Groups Links
>> 
>>     a.. To visit your group on the web, go to:
>>     http://groups.yahoo.com/group/amibroker/
>> 
>>     b.. To unsubscribe from this group, send an email to:
>>     amibroker-unsubscribe@xxxxxxxxxxxxxxx
>> 
>>     c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of 
> Service.
> 
> 
> 
> 
> 
> 
> Please note that this group is for discussion between users only.
> 
> To get support from AmiBroker please send an e-mail directly to 
> SUPPORT {at} amibroker.com
> 
> For other support material please check also:
> http://www.amibroker.com/support.html
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
>


------------------------ Yahoo! Groups Sponsor --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

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