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

Re: [amibroker] Re: Built-in DEMA questions



PureBytes Links

Trading Reference Links

Dimitris,


> > 
> > Not really. By definition DEMA and all exponential moving averages 
> because of their recursive formula,
> > require only 2 (EMA) or 3 bars (DEMA/TEMA) to calculate first value.
> > But it just the convention that first 2 * len periods are being 
> considered as "not accurate".
> 
> Tomasz,
> OK for the first 2*len periods. Is it accurate for the next 2*len 
> periods?
> Is it accurate for the next 4*len periods ?
> What is accurate for you ? 10% divergence, 1% divergence, 0.01% 
> divergence ?
> If the final amibroker use is to trade, a cross(X,20) is *very 
> different* from a cross(X,21) in a [15, 40] scale.

Please see the reply I have just sent to your other post.
Because of the fact that EMA and DEMA are INITIALIZED differently
it needs 2 * len bars for DEMA re-implemented using EMA
to converge with built-in DEMA.
After this initial stage they are the same.

As Fred wisely pointed out AMA-reimplemented DEMA is the same
from the start because it is initialized the same way as DEMA.
(Initial value is the first value of input array).

As you probably know all exponential-smoothers are recursive.
It means that they take one (or more) previous value(s) of itself
to calculate todays value.
EMA is simply

factor = 2 / ( periods + 1 );

EMA( today ) = ARRAY( today ) * factor + (1 - factor ) * EMA( yesterday ).

This EMA( yesterday) is just previous value of EMA.
So we have go recurrency here.
The problem is that at BAR ZERO you don't have any PREVIOUS value.
You have to initialize somehow.

One approach is to use ARRAY( 0 ) as initial value of EMA

EMA( 0 ) = ARRAY( 0 )

This approach is used by DEMA, TEMA, AMA, AMA2

Second approach is to initialize EMA( periods ) by simple moving average
and start calculations from periods + 1:

for all bar < periods EMA( bar ) = NULL

EMA( periods ) = MA( periods )

for all bars > periods
EMA( bar ) = ARRAY( bar ) * factor + (1 - factor ) * EMA( bar - 1 ).

In English: at bar = periods we initialize EMA with simple moving average value because
it is not recurrent. Then we continue usual EMA recursive calculation.

This method is used by EMA to match Metastock  way of calculation of EMA
(requested by numerous users)

Best regards,
Tomasz Janeczko
amibroker.com




------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading!
Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/cjB9SD/od7FAA/AG3JAA/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/