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

RE: [GT] New EMA



ras,

the latest EMA I sent out does not abort when out of range data is
requested.

Th.

> -----Original Message-----
> From: Robert A. Schmied [mailto:ras
AT
acm.org]
> Sent: Thursday, February 28, 2008 9:14 PM
> To: devel
AT
geniustrader.org
> Subject: Re: [GT] New EMA
> 
> Weigert, Thomas wrote:
> > With all these problems with EMA I decided to rewrite this
indicator. I
> > first tried to understand what the original authors were doing, but
as
> > coded it seems to do things differently from the definition of EMA
and
> > from what I see in other tools. In particular, it makes the data it
> > depends on dynamically dependent on the series it works on. Then
there
> > are many more calculations that are not in the definition of the
EMA, as
> > far as I can tell.
> >
> > I took the straightforward approach and followed the text books.
> >
> > The EMA is computed in the following manner:
> >
> > alpha = 2 / ( N + 1 )
> > EMA[n] = EMA[n-1] + alpha * ( INPUT - EMA[n-1] )
> >
> > Where EMA[n] refers to the EMA at period n, and INPUT is the value
of
> > the input series at period n.
> >
> > The starting point is usually computed as the SMA(n) over the period
> > from start - n to start. (One could also start with the actual value
of
> > the series, in which case there would be no dependency on past data.
> > Maybe I make that an option.
> 
> when operating at the start of data it complained:
> ras [ 5148 ] %    ./display_indicator.pl --start 1993-01-04 --end
1993-07-
> 01 I:EMA 13000
> Indicator I:EMA has 1 value ... all values selected
>         I:EMA/1  <=> EMA[20,{I:Prices CLOSE}]
> 
>         timeframe day, time periods 0 .. 123
> Calculating indicator ...
> Use of uninitialized value in subtraction (-) at
../GT/Indicators/EMA.pm
> line 126.
> Use of uninitialized value in addition (+) at ../GT/Indicators/EMA.pm
line
> 126.
> EMA[20,{I:Prices CLOSE}][1993-01-05 00:00:00] = 1.9978
> EMA[20,{I:Prices CLOSE}][1993-01-06 00:00:00] = 3.7676
> EMA[20,{I:Prices CLOSE}][1993-01-07 00:00:00] = 5.3456
> 
> so i hacked around and came up with
> 
>     my $ema;
>     for (my $i = $first+1; $i <= $last; $i++) {
>         my $oldema = $indic->get($name, $i - 1);
>         ( defined($oldema) )
>           ? $ema = $alpha * ($self->{'args'}->get_arg_values($calc,
$i, 2)
> - $oldema) + $oldema
>           : $ema = $alpha * ($self->{'args'}->get_arg_values($calc,
$i,
> 2));
>         $indic->set($name, $i, $ema);
>     }
> 
> you may have a better option, but it solves the issue noted above and
i
> think
> the answers remain the same.
> 
> but it falls on its face when attempting the emaema:
> ras [ 5172 ] %    ./display_indicator.pl --start 1993-01-04 --end
1993-07-
> 01 I:EMA 13000 20 '{I:EMA 20 {I:Prices CLOSE}'
> Indicator I:EMA has 1 value ... all values selected
>         I:EMA/1  <=> EMA[20,{I:EMA 20 {I:Prices CLOSE}}]
> 
>         timeframe day, time periods 0 .. 123
> Calculating indicator ...
> Use of uninitialized value in multiplication (*)
> at ../GT/Indicators/EMA.pm line 127.
> Use of uninitialized value in multiplication (*)
> at ../GT/Indicators/EMA.pm line 127.
> Use of uninitialized value in subtraction (-) at
../GT/Indicators/EMA.pm
> line 127.
> Use of uninitialized value in multiplication (*)
> at ../GT/Indicators/EMA.pm line 127.
> Use of uninitialized value in subtraction (-) at
../GT/Indicators/EMA.pm
> line 127.
> Use of uninitialized value in multiplication (*)
> at ../GT/Indicators/EMA.pm line 127.
> 
> to fix the warning, one could cheat and put
> no warnings "uninitialized";
> inside that for statement, or block the trinary statement and put the
> pragma in the block
>         {
>         no warnings "uninitialized";
>         ( defined($oldema) )
>           ? $ema = $alpha * ($self->{'args'}->get_arg_values($calc,
$i, 2)
> - $oldema) + $oldema
>           : $ema = $alpha * ($self->{'args'}->get_arg_values($calc,
$i,
> 2));
>         }
> 
> 
> this is excellent work
> i think major progress has been made, little thanks to me
> 
> aloha
> 
> ras
> 
> ps -- i added the 1; at end of file, have yet to know why -- but all
cpan
> modules have it. -- ras
> 
> pps -- ema is used in a slue (bunch) of indicators:
> ../GT/Indicators/AT3.pm:18
> ../GT/Indicators/CHAIKIN.pm:4
> ../GT/Indicators/DSS.pm:8
> ../GT/Indicators/ENV.pm:6
> ../GT/Indicators/ElderRay.pm:2
> ../GT/Indicators/KirshenbaumBands.pm:5
> ../GT/Indicators/MACD.pm:10
> ../GT/Indicators/MASS.pm:4
> ../GT/Indicators/PFE.pm:5
> ../GT/Indicators/PGO.pm:5
> ../GT/Indicators/REMA.pm:17
> ../GT/Indicators/RMI.pm:1
> ../GT/Indicators/SMI.pm:4
> ../GT/Indicators/T3.pm:18
> ../GT/Indicators/TRIX.pm:8
> ../GT/Indicators/TRIXkw.pm:8
> ../GT/Indicators/WWMA.pm:1
> -- sure wish there was a good way to validate them -- ras
> 
> 
> >
> > Please find this indicator attached. I compared it with the output
from
> > TA_lib and metastock. I also ran my tests. It depends only on the
past n
> > data points (if we use the SMA start computation). It is not
affected
> > whether called directly or in another indicator.
> >
> > Please do your own testing. But I think it works better and faster
than
> > the existing EMA.
> >
> > Cheers, Th.