Yes, as usual in GT, when you try to get the value of an indicator
before the dependencies are satisfied, it will complain. This indicator
is available only from 1993-1-29 on for EMA(20).
I put an additional test in that causes the indicator to abort in these
cases. Thus data will only be returned if the dependencies are
satisfied.
That raises the interesting question: How should one handle requests for
data where dependencies are not satisfied.
In GT in general the series is aborted (if calculate_interval is used)
or the data is skipped until legal data is found (if calculate is used).
Of course, often one could make calculate_interval be more forgiving, as
in this case, but we should decide on a consistent pattern.
Subject: Re: [GT] New EMA
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.