PureBytes Links
Trading Reference Links
|
Suppose a "stock" C1 goes from 100 to 110, remains there for a
period PER and then falls back to 105.
Let us see how various moving averages follow this
change.
1. EMA and DEMA
A green EMA(C1,PER/2) will asymptotically reach the new
price by the end of the period.
The first days are quite far from the real prices. For
PER=18, it takes more than 5 days to cover the half of this gap up.
A blue DEMA(C1,PER/2) will reach the new level in 5 days but
will go higher [up to 112] and will not catch the new level within the period
PER.
We need a yellow DEMA(C1,PER/3) to reach the new level in 3
days, exceed it up to 111 and catch it again within the period.
The IB code
per=18;
L1=LastValue(Cum(1));C1=IIf(Cum(1)>L1-2*per AND
Cum(1)<=L1-per,110,IIf(Cum(1)<=L1-2*PER,100,105));Plot(C1,"TEST",1,8);Plot(DEMA(C1,PER/2),"DEMA
PER:2",colorBlue,8);Plot(DEMA(C1,PER/3),"DEMA
PER:3",colorYellow,8);Plot(EMA(C1,PER/2),"EMA
PER:2",colorBrightGreen,8);
will describe this behavior.
2. An intermediate
approach
Let us select the dot-yellow DEMA(C1,PER/3) and the dot-green
EMA(C1,PER/2) and search for better intermediate lines.
The IIR2 filter gives this solution.
// DEMA, EMA and IIR2 comparison
per=18;L1=LastValue(Cum(1));C1=IIf(Cum(1)>L1-2*per AND
Cum(1)<=L1-per,110,IIf(Cum(1)<=L1-2*PER,100,105));Plot(C1,"TEST",1,8);//Plot(DEMA(C1,PER/2),"DEMA
PER:2",colorBlue,8);Plot(DEMA(C1,PER/3),"DEMA
PER:3",colorYellow,8);Plot(EMA(C1,PER/2),"EMA
PER:2",colorBrightGreen,8); function IIR2( input, f0, f1, f2
){ result[ 0 ] = input[ 0 ];result[ 1 ] = input[ 1 ];
for( i = 2; i < BarCount; i++ ) { result[ i ]
= f0 * input[ i ] + f1 * result[ i - 1 ] + f2 * result[ i - 2 ];
} return result;}CountER=0;
// the
D-parameterfor(D=PER/100;D<PER/50;D=D+PER/500){RD=IIR2( C1, D, 1,
-D);CountER=CountER+1;Plot(RD,"\n["+WriteVal(D,1.2)+"]",CountER,1);}GraphXSpace=2;
D values from 0.20 to 0.40 give smoothing lines
between the EMA and DEMA lines.
The D=0.30 is perhaps the optimal, it catches the new level in
5 days but it does not exceed this level significantly <FONT
size=2>.
This crash test has an initial period PER=18 days and matches
to medium speed trading systems.
A similar approach may be modified to match faster or slower
systems.
The quantity
<FONT
size=2>AveragePeriod=MA(ValueWhen(Ref(Buy,1),BarsSince(Buy)),50);
graph may give an indication for the proper PER you should
begin this modification.
For example, this year ^NDX, from the convexity point of
view, has an AveragePeriod of 12-14 days
and needs a D=0.3 . This value will place an IIR2 line between
a 6-day EMA and a 4-day DEMA.
The interesting for IIR2 is that this <FONT
size=2>D=0.3 would give good solutions for AveragePeriod from 10 to
40
and this may cover longer time periods without changing
EMA/DEMA parameters all the time.
IIR2 gives better response and longer time
stability.
See also the introductory <A
href="">http://www.amibroker.com/library/detail.php?id=116
Dimitris Tsokakis
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.
Attachment:
EMA-DEMA-IIR2.gif
Attachment:
Description: "Description: GIF image"
|