[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] SVN Commit r621 - in trunk/GT/Indicators: . Generic
Author: thomas
Date: 2008-04-26 17:26:51 +0200 (Sat, 26 Apr 2008)
New Revision: 621
Modified:
trunk/GT/Indicators/AT3.pm
trunk/GT/Indicators/DSS.pm
trunk/GT/Indicators/EMA.pm
trunk/GT/Indicators/ElderRay.pm
trunk/GT/Indicators/ForceIndex.pm
trunk/GT/Indicators/Generic/Divide.pm
trunk/GT/Indicators/HilbertPeriod.pm
trunk/GT/Indicators/HilbertSine.pm
trunk/GT/Indicators/InstantTrendLine.pm
trunk/GT/Indicators/Interquartil.pm
trunk/GT/Indicators/KAMA.pm
trunk/GT/Indicators/MaxDrawDown.pm
trunk/GT/Indicators/PERF.pm
trunk/GT/Indicators/STO.pm
trunk/GT/Indicators/StandardError.pm
trunk/GT/Indicators/T3.pm
trunk/GT/Indicators/TR.pm
Log:
Updated remaining indicators to new format. Corrected several indicators. Updated documentation.
Modified: trunk/GT/Indicators/AT3.pm
===================================================================
--- trunk/GT/Indicators/AT3.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/AT3.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -5,7 +5,7 @@
# version 2 or (at your option) any later version.
use strict;
-use vars qw(@ISA @NAMES);
+use vars qw(@ISA @NAMES @DEFAULT_ARGS);
use GT::Indicators;
use GT::Indicators::EMA;
@@ -14,6 +14,7 @@
@ISA = qw(GT::Indicators);
@NAMES = ("AT3[#1,#2]");
+
AT
DEFAULT_ARGS = (5, 4.1);
=pod
@@ -47,54 +48,33 @@
T3 = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3
-=head2 Parameters
-
-The default values are :
-N = 5
-
=cut
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args) = @_;
- my $self = { 'args' => defined($args) ? $args : [ 5, 4.1 ] };
-
- $args->[0] = 5 if (! defined($args->[0]));
- $args->[0] = 4.1 if (! defined($args->[0]));
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, "");
-}
-
sub initialize {
my $self = shift;
# Initialization of RSquare
- $self->{'rsquare'} = GT::Indicators::RSquare->new([ $self->{'args'}[1] ]);
+ $self->{'rsquare'} = GT::Indicators::RSquare->new([ $self->{'args'}->get_arg_names(2) ]);
# Initialize e1, e2, e3, e4, e5 and e6
- $self->{'e1'} = GT::Indicators::EMA->new([ $self->{'args'}[0] ]);
+ my $period = $self->{'args'}->get_arg_names(1);
+ $self->{'e1'} = GT::Indicators::EMA->new([ $period ]);
- $self->{'e2'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e1'}->{'args'}->get_arg_names()]}}" ]);
+ $self->{'e2'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e1'}->get_name . "}" ]);
+
+ $self->{'e3'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e2'}->get_name . "}" ]);
+
+ $self->{'e4'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e3'}->get_name . "}" ]);
+
+ $self->{'e5'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e4'}->get_name . "}" ]);
+
+ $self->{'e6'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e5'}->get_name . "}" ]);
- $self->{'e3'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e2'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->{'e4'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e3'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->{'e5'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e4'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->{'e6'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e5'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->add_indicator_dependency($self->{'e1'}, $self->{'args'}[0] * 5 - 4);
- $self->add_indicator_dependency($self->{'e2'}, $self->{'args'}[0] * 4 - 3);
- $self->add_indicator_dependency($self->{'e3'}, $self->{'args'}[0] * 3 - 2);
- $self->add_indicator_dependency($self->{'e4'}, $self->{'args'}[0] * 2 - 1);
- $self->add_indicator_dependency($self->{'e5'}, $self->{'args'}[0]);
+ $self->add_indicator_dependency($self->{'e1'}, $period * 5 - 4);
+ $self->add_indicator_dependency($self->{'e2'}, $period * 4 - 3);
+ $self->add_indicator_dependency($self->{'e3'}, $period * 3 - 2);
+ $self->add_indicator_dependency($self->{'e4'}, $period * 2 - 1);
+ $self->add_indicator_dependency($self->{'e5'}, $period);
$self->add_indicator_dependency($self->{'e6'}, 1);
$self->add_indicator_dependency($self->{'rsquare'}, 1);
}
@@ -116,7 +96,7 @@
my $e5_name = $self->{'e5'}->get_name;
my $e6_name = $self->{'e6'}->get_name;
my $t3_name = $self->get_name(0);
- my $period = $self->{'args'}[0];
+ my $period = $self->{'args'}->get_arg_constant(1);
return if ($indic->is_available($t3_name, $i));
return if (! $self->check_dependencies($calc, $i));
Modified: trunk/GT/Indicators/DSS.pm
===================================================================
--- trunk/GT/Indicators/DSS.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/DSS.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -1,6 +1,7 @@
package GT::Indicators::DSS;
# Copyright 2002 Oliver Bossert
+# Updated 2006, 2008 by Karsten Wippler, Thomas Weigert
# This file is distributed under the terms of the General Public License
# version 2 or (at your option) any later version.
@@ -12,23 +13,46 @@
use GT::ArgsTree;
use GT::Indicators;
use GT::Indicators::EMA;
-use GT::Indicators::STO;
+use GT::Indicators::Generic::MinInPeriod;
+use GT::Indicators::Generic::MaxInPeriod;
@ISA = qw(GT::Indicators);
-
AT
NAMES = ("DSS-BLAU[#*]");
-
AT
DEFAULT_ARGS = (5,7,3,"{I:Prices CLOSE}");
+
AT
NAMES = ("DSS-BLAU[#1,#2,#3]");
+
AT
DEFAULT_ARGS = (5,7,3,"{I:Prices HIGH}","{I:Prices LOW}","{I:Prices CLOSE}");
=head1 NAME
-GT::Indicators::DSS - The Double Smoothed Stochastic (William Blau)
+GT::Indicators::DSS - Double Smoothed Stochastic (William Blau).
+
=head1 DESCRIPTION
-The DSS is calculated as follows:
+From http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=128:
- DSS (p1, p2, p3) = EMA( EMA( Close - Lowest(p1), p2), p3 ) /
- EMA( EMA( Highest(p1) - Lowest(p1), p2), p3 ) /
+DSS applies 2 smoothing EMAs of different lengths to a Stochastic Oscillator.
+DSS ranges from 0 to 100, like the standard Stochastic Oscillator. The same
+rules of interpretation that you use for Stochastics can be applied to DSS,
+although DSS offers a much smoother curve than Stochastics.
+From http://www.tradesignalonline.com/Lexicon/Default.aspx?name=DSS%3a+Double+Smoothed+Stochastics+(Blau)
+
+Calculation of the DSS indicator is similar to stochastics. The numerator:
+first the difference between the current close and the period low is formed,
+and this is then exponentially smoothed twice. The denominator is formed in
+the same way, but here the difference is calculated from the period high minus
+the period low. Numerator and denominator yield the quotient, and this value
+is multiplied by 100.
+
+=head2 Calculation
+
+As can be seen from above, there is some disagreement on the calculation
+process. We follow the latter and calculate DSS-BLAU as follows:
+
+DSS-BLAU[p1,p2,p3] =
+ EMA[p3, EMA[p2, Close - LowestLow[p1]]
+ 100 * ----------------------------------------------
+ EMA[p3, EMA[p2, HighestHigh[p1]-LowestLow[p1]]
+
The handling and the calculations of signals is similar to the
Stochastic-Indictor.
@@ -38,42 +62,46 @@
=item Period 1 (default 5)
-The period of the minimum/maximum.
+The period over which to consider highest highs and lowest lows.
=item Period 2 (default 7)
-The period of the first EMA
+The period of the first smoothing
=item Period 3 (default 3)
-The period of the second EMA
+The period of the second smoothing
-=item Source
+=item High, Low, and Close of Source
-The source of which the indicators is calculated.
+The source from which the indicators is calculated.
=back
-=head2 Creation
+=cut
-=head2 Link
+sub initialize {
+ my ($self) = @_;
+ my $args = $self->{'args'};
-This link is unfortunately only in german:
+ for (my $i=1;$i<=3;$i++) {
+ die "Argument $i to ".$self->get_name." must be a constant value.\n" unless $args->is_constant($i);
+ }
-http://www.trading-konzepte.de/indikator/dss-blau.htm
-defaults taken from the recommendations of William Blau to be
-seen in "Technical Analysis of Stocks & Commodities, Jan 1991"
+ my $nb1 = $args->get_arg_names(1);
+ my $nb2 = $args->get_arg_names(2);
+ my $nb3 = $args->get_arg_names(3);
-=cut
+ my $min = "{I:Generic:Eval ".$args->get_arg_names(6)." - {I:Generic:MinInPeriod $nb1 ".$args->get_arg_names(5)."}}";
+ my $max = "{I:Generic:Eval {I:Generic:MaxInPeriod $nb1 ".$args->get_arg_names(4)."} - {I:Generic:MinInPeriod $nb1 ".$args->get_arg_names(5)."}}";
+ $self->{'num'} = GT::Indicators::EMA->new([$nb3, "{I:EMA $nb2 $min}"]);
+ $self->{'den'} = GT::Indicators::EMA->new([$nb3, "{I:EMA $nb2 $max}"]);
-sub initialize {
- my ($self) = @_;
- my $sto1 = "{I:STO/1 " . $self->{'args'}->get_arg_names(1) . " 1 1 1 " . $self->{'args'}->get_arg_names(4) . "}";
- $self->{'ema1'} = GT::Indicators::EMA->new([ $self->{'args'}->get_arg_names(2), $sto1 ]);
- $self->{'ema2'} = GT::Indicators::EMA->new([ $self->{'args'}->get_arg_names(3),
- "{I:EMA @{[$self->{'ema1'}->{'args'}->get_arg_names()]}}" ]);
+ $self->add_prices_dependency( $nb1 + $nb2 + $nb3 );
+ $self->add_indicator_dependency( $self->{'num'}, 1 );
+ $self->add_indicator_dependency( $self->{'den'}, 1 );
}
@@ -81,21 +109,28 @@
my ($self, $calc, $i) = @_;
my $indic = $calc->indicators;
my $name = $self->get_name();
- my $nb2 = $self->{'args'}->get_arg_values($calc, $i, 2);
- my $nb3 = $self->{'args'}->get_arg_values($calc, $i, 3);
- return if (!defined($nb2) || !defined($nb3) );
-
- # Calculate the depencies
- $self->remove_volatile_dependencies();
- $self->add_volatile_indicator_dependency( $self->{'ema1'}, $nb2*2-1);
- $self->add_volatile_indicator_dependency( $self->{'ema2'}, $nb3);
return if ($calc->indicators->is_available($name, $i));
return if (! $self->check_dependencies($calc, $i));
- my $dss = $indic->get($self->{'ema2'}->get_name, $i);
-
+ my $den = $indic->get($self->{'den'}->get_name, $i) || 0.0000001;
+ my $dss = 100 * $indic->get($self->{'num'}->get_name, $i) / $den;
$indic->set($name, $i, $dss);
}
+sub calculate_interval {
+ my ($self, $calc, $first, $last) = @_;
+ my $indic = $calc->indicators;
+ my $name = $self->get_name();
+
+ return if ($calc->indicators->is_available_interval($name, $first, $last));
+ return if (! $self->check_dependencies_interval($calc, $first, $last));
+
+ for(my $i = $first; $i <= $last; $i++) {
+ my $den = $indic->get($self->{'den'}->get_name, $i) || 0.0000001;
+ my $dss = 100 * $indic->get($self->{'num'}->get_name, $i) / $den;
+ $indic->set($name, $i, $dss);
+ }
+}
+
1;
Modified: trunk/GT/Indicators/EMA.pm
===================================================================
--- trunk/GT/Indicators/EMA.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/EMA.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -15,7 +15,9 @@
use GT::Indicators;
use GT::Indicators::SMA;
+use GT::Eval;
+
@ISA = qw(GT::Indicators);
@NAMES = ("EMA[#*]");
@DEFAULT_ARGS = (20, "{I:Prices CLOSE}");
@@ -43,6 +45,18 @@
stream of input data for the average instead of the close prices.
This is usually an indicator (detailed via {I:MyIndic <param>}).
+=item Start data input
+
+The third argument is optional. It can be used to specify the
+stream of input data to compute the starting point of the moving
+average. The default is computed by the SMA of the given period.
+
+If a very long period is required, it may be advisable to set this
+to {I:PRICES CLOSE} (or whatever data stream is used as the input
+for the EMA) to avoid excessive history data being required just to
+compute the starting value. Using the first value of the input series
+does not result in a large error and requires no dependencies.
+
=back
=head2 Calculation
@@ -63,7 +77,7 @@
GT::Indicators::EMA->new([20])
If you need a 30 days EMA of the opening prices you can write
-one of these lines:
+one of those lines :
GT::Indicators::EMA->new([30, "{I:Prices OPEN}"])
@@ -77,9 +91,20 @@
sub initialize {
my ($self) = @_;
- $self->{'sma'} = GT::Indicators::SMA->new([ $self->{'args'}->get_arg_names() ]);
- $self->add_indicator_dependency($self->{'sma'}, 1);
-
+ my $start = $self->{'args'}->get_arg_names(3);
+ if ($start) {
+ if ($start =~ /^\s*{(.*)}\s*$/) {
+ $start = $1;
+ }
+ if ($start =~ /^\s*(\S+)\s*(.*)\s*$/) {
+ $self->{'start'} = create_standard_object("$1", $2);
+ } else {
+ die "Inappropriate argument $start given to ".$self->get_name." .\n";
+ }
+ } else {
+ $self->{'start'} = GT::Indicators::SMA->new([ $self->{'args'}->get_arg_names() ]);
+ }
+ $self->add_indicator_dependency($self->{'start'}, 1);
}
sub calculate {
@@ -101,7 +126,7 @@
if (defined $oldema) {
$ema = $alpha * ($self->{'args'}->get_arg_values($calc, $i, 2) - $oldema) + $oldema;
} else {
- $ema = $indic->get($self->{'sma'}->get_name, $i);
+ $ema = $indic->get($self->{'start'}->get_name, $i);
$before = 0;
}
$indic->set($name, $i, $ema);
@@ -118,13 +143,13 @@
return if ($indic->is_available_interval($name, $first, $last));
# Don't need to calculate all SMA values, just the first data point.
- $self->{'sma'}->calculate($calc, $first);
+ $self->{'start'}->calculate($calc, $first);
return unless $self->dependencies_are_available($calc, $first);
my $alpha = 2 / ($nb + 1);
- $indic->set($name, $first, $indic->get($self->{'sma'}->get_name, $first));
+ $indic->set($name, $first, $indic->get($self->{'start'}->get_name, $first));
for (my $i=$first+1;$i<=$last;$i++) {
my $oldema = $indic->get($name, $i - 1);
Modified: trunk/GT/Indicators/ElderRay.pm
===================================================================
--- trunk/GT/Indicators/ElderRay.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/ElderRay.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -5,7 +5,7 @@
# version 2 or (at your option) any later version.
use strict;
-use vars qw(@ISA @NAMES);
+use vars qw(@ISA @NAMES @DEFAULT_ARGS);
use GT::Indicators;
use GT::Indicators::EMA;
@@ -13,7 +13,9 @@
@ISA = qw(GT::Indicators);
@NAMES = ("BullPower[#1]", "BearPower[#1]");
+
AT
DEFAULT_ARGS = (13);
+
=head1 GT::Indicators::ElderRay
GT::Indicators::ElderRay->new([13])
@@ -24,19 +26,10 @@
"Trading for a living" ("Vivre du trading" in french).
=cut
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args) = @_;
- my $self = { 'args' => defined($args) ? $args : [13] };
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, "");
-}
-
sub initialize {
my $self = shift;
- $self->{'mme'} = GT::Indicators::EMA->new([$self->{'args'}[0]]);
+ $self->{'mme'} = GT::Indicators::EMA->new([$self->{'args'}->get_arg_names(1)]);
$self->add_indicator_dependency($self->{'mme'}, 1);
$self->add_prices_dependency(1);
}
Modified: trunk/GT/Indicators/ForceIndex.pm
===================================================================
--- trunk/GT/Indicators/ForceIndex.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/ForceIndex.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -26,15 +26,6 @@
"Trading for a living" ("Vivre du trading" in french).
=cut
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args) = @_;
- my $self = { 'args' => [] };
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, "");
-}
-
sub initialize {
my $self = shift;
Modified: trunk/GT/Indicators/Generic/Divide.pm
===================================================================
--- trunk/GT/Indicators/Generic/Divide.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/Generic/Divide.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -38,7 +38,12 @@
sub initialize {
my ($self) = @_;
-
+ for (my $j = 1; $j <= $self->{'args'}->get_nb_args; $j++) {
+ unless ($self->{'args'}->is_constant($j)) {
+ $self->add_arg_dependency($j, 1);
+ }
+ }
+
}
sub calculate {
@@ -46,6 +51,7 @@
my $indic = $calc->indicators;
return if ($calc->indicators->is_available($self->get_name, $i));
+
return if (! $self->check_dependencies($calc, $i));
my $value = $self->{'args'}->get_arg_values($calc, $i, 1);
Modified: trunk/GT/Indicators/HilbertPeriod.pm
===================================================================
--- trunk/GT/Indicators/HilbertPeriod.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/HilbertPeriod.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -12,6 +12,7 @@
use GT::Indicators::WTCL;
use GT::Indicators::Generic::ByName;
use GT::Prices;
+use POSIX;
@ISA = qw(GT::Indicators);
@NAMES = ("HilbertPeriod", "HP:Detrender", "HP:Q1", "HP:I1", "HP:jI",
@@ -30,15 +31,6 @@
TASC November 2000 - page 108
=cut
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args) = @_;
- my $self = { 'args' => defined($args) ? $args : [] };
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, "");
-}
-
sub initialize {
my $self = shift;
Modified: trunk/GT/Indicators/HilbertSine.pm
===================================================================
--- trunk/GT/Indicators/HilbertSine.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/HilbertSine.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -30,15 +30,6 @@
TASC May 2000 - page 27
=cut
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args) = @_;
- my $self = { 'args' => defined($args) ? $args : [] };
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, "");
-}
-
sub initialize {
my $self = shift;
Modified: trunk/GT/Indicators/InstantTrendLine.pm
===================================================================
--- trunk/GT/Indicators/InstantTrendLine.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/InstantTrendLine.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -29,15 +29,6 @@
TASC May 2000 - page 22
=cut
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args) = @_;
- my $self = { 'args' => defined($args) ? $args : [] };
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, "");
-}
-
sub initialize {
my $self = shift;
Modified: trunk/GT/Indicators/Interquartil.pm
===================================================================
--- trunk/GT/Indicators/Interquartil.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/Interquartil.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -13,11 +13,11 @@
@ISA = qw(GT::Indicators);
@NAMES = ("IQ[#*]");
-
AT
DEFAULT_ARGS = (50, 80, "{I:Prices CLOSE}");
+
AT
DEFAULT_ARGS = (80, 50, "{I:Prices CLOSE}");
=head1 NAME
-GT::Indicators::Interqurtil - Interquartil-Distance
+GT::Indicators::Interquartil - Interquartil-Distance
=head1 DESCRIPTION
@@ -58,7 +58,6 @@
sub calculate {
my ($self, $calc, $i) = @_;
my $nb = $self->{'args'}->get_arg_values($calc, $i, 2);
- my $getvalue = $self->{'func'};
my $name = $self->get_name;
return if (! defined($nb));
@@ -71,7 +70,7 @@
my @values = ();
for(my $n = $i - $nb + 1; $n <= $i; $n++)
{
- my $val = &$getvalue($calc, $n);
+ my $val = $self->{'args'}->get_arg_values($calc, $n, 3);
return if (! defined($val));
push @values, $val;
}
Modified: trunk/GT/Indicators/KAMA.pm
===================================================================
--- trunk/GT/Indicators/KAMA.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/KAMA.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -13,7 +13,7 @@
@ISA = qw(GT::Indicators);
@NAMES = ("KAMA[#*]");
-
AT
DEFAULT_ARGS = (21, "{I:Prices CLOSE}");
+
AT
DEFAULT_ARGS = (21, 2, 30, "{I:Prices CLOSE}");
=head1 NAME
@@ -33,6 +33,14 @@
The first argument is the period used to calculed the average.
+=item Fastest period (default 30)
+
+The fastest period to be considered.
+
+=item Slowest period (default 2)
+
+The slowest period to be considered.
+
=back
=head2 Creation
@@ -45,20 +53,22 @@
sub initialize {
my ($self) = @_;
if ($self->{'args'}->is_constant(1) && ($self->{'args'}->get_nb_args() > 1)) {
- $self->add_arg_dependency(2, $self->{'args'}->get_arg_constant(1));
+ $self->add_arg_dependency(4, $self->{'args'}->get_arg_constant(1));
}
}
sub calculate {
my ($self, $calc, $i) = @_;
my $nb = $self->{'args'}->get_arg_values($calc, $i, 1);
+ my $fast = $self->{'args'}->get_arg_constant(2);
+ my $slow = $self->{'args'}->get_arg_constant(3);
my $name = $self->get_name;
my $kama = 0;
return if (! defined($nb));
$self->remove_volatile_dependencies();
- $self->add_volatile_arg_dependency(2, $nb);
+ $self->add_volatile_arg_dependency(4, $nb);
return if ($calc->indicators->is_available($name, $i));
return if (! $self->check_dependencies($calc, $i));
@@ -67,18 +77,18 @@
my $noise = 0;
for(my $n = $i - $nb + 1; $n <= $i; $n++)
{
- $noise += abs( $self->{'args'}->get_arg_values($calc, $n-1, 2) -
- $self->{'args'}->get_arg_values($calc, $n, 2));
+ $noise += abs( $self->{'args'}->get_arg_values($calc, $n-1, 4) -
+ $self->{'args'}->get_arg_values($calc, $n, 4));
}
- my $signal = abs( $self->{'args'}->get_arg_values($calc, $i-$nb+1, 2) -
- $self->{'args'}->get_arg_values($calc, $i, 2) );
+ my $signal = abs( $self->{'args'}->get_arg_values($calc, $i-$nb+1, 4) -
+ $self->{'args'}->get_arg_values($calc, $i, 4));
if ($noise != 0)
{
$efratio = $signal / $noise;
}
- my $fastsc = 2/(2+1);
- my $slowsc = 2/(30+1);
+ my $fastsc = 2/($fast+1);
+ my $slowsc = 2/($slow+1);
my $ssc = $efratio * ($fastsc-$slowsc) + $slowsc;
my $smooth = $ssc * $ssc;
@@ -86,10 +96,10 @@
if ($calc->indicators->is_available($name, $i-1))
{
$ama = $calc->indicators->get($name, $i-1);
- $kama = $ama + $smooth * ($self->{'args'}->get_arg_values($calc, $i, 2)-$ama);
+ $kama = $ama + $smooth * ($self->{'args'}->get_arg_values($calc, $i, 4)-$ama);
}
else {
- $kama = $self->{'args'}->get_arg_values($calc, $i-1, 2);
+ $kama = $self->{'args'}->get_arg_values($calc, $i-1, 4);
}
$calc->indicators->set($name, $i, $kama);
Modified: trunk/GT/Indicators/MaxDrawDown.pm
===================================================================
--- trunk/GT/Indicators/MaxDrawDown.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/MaxDrawDown.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -59,10 +59,4 @@
$calc->indicators()->set($name, $i, $max_draw_down);
}
-sub calculate_interval {
- my ($self, $calc, $first, $last) = @_;
-
- $self->calculate($calc, $last);
-}
-
1;
Modified: trunk/GT/Indicators/PERF.pm
===================================================================
--- trunk/GT/Indicators/PERF.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/PERF.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -5,48 +5,32 @@
# version 2 or (at your option) any later version.
use strict;
-use vars qw(@ISA @NAMES);
+use vars qw(@ISA @NAMES @DEFAULT_ARGS);
use GT::Indicators;
use GT::Prices;
@ISA = qw(GT::Indicators);
-
AT
NAMES = ("PERF[#1]");
+
AT
NAMES = ("PERF[#1,#2]");
+
AT
DEFAULT_ARGS = (0, "{I:Prices CLOSE}");
=head1 GT::Indicators::PERF
-The performance indicator display a security's price performance from a reference day as a percentage. GT::Indicators::PERF->new($reference_day);
+The performance indicator display a security's price performance from a reference day as a percentage.
+If first parameter is omitted, uses the first price as a reference day.
+(Note: In this case, uses "0" in name of indicator.)
+
Example :
GT::Indicators::PERF->new(["2001-09-22"]);
-GT::Indicators::PERF->new(["2001-09-22"], "VOLUME", $GET_VOLUME);
+GT::Indicators::PERF->new(["2001-09-22", "{I:Prices VOLUME}"]);
-=cut
-
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args, $key, $func) = @_;
- my $self = { 'args' => defined($args) ? $args : [] };
-
- # User defined function to get data or default with $GET_LAST
- if (defined($func)) {
- $self->{'_func'} = $func;
- } else {
- $self->{'_func'} = $GET_LAST;
- $key = 'LAST';
- }
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, $key);
-}
-
=head2 GT::Indicators::PERF::calculate($calc, $day)
=cut
sub calculate {
my ($self, $calc, $i) = @_;
- my $reference = $self->{'args'}[0];
- my $getvalue = $self->{'_func'};
+ my $reference = $self->{'args'}->get_arg_constant(1);
my $indic = $calc->indicators;
my $prices = $calc->prices;
my $performance_name = $self->get_name(0);
@@ -58,7 +42,7 @@
my $item = $prices->date($reference);
# Calculate the performance of a security from a reference day in percentage
- my $performance = (((&$getvalue($calc, $i) - &$getvalue($calc, $item)) / &$getvalue($calc, $item)) * 100);
+ my $performance = ((($self->{'args'}->get_arg_values($calc, $i, 2) - $self->{'args'}->get_arg_values($calc, $item, 2)) / $self->{'args'}->get_arg_values($calc, $item, 2)) * 100);
$indic->set($performance_name, $i, $performance);
}
Modified: trunk/GT/Indicators/STO.pm
===================================================================
--- trunk/GT/Indicators/STO.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/STO.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -76,10 +76,6 @@
GT::Indicators::STO->new()
GT::Indicators::STO->new([14, 3, 3, 3])
- --add=Curve(Indicators::STO/3, black) # %K Slow oscillator
- --add=Curve(Indicators::STO/4, red) # %D Slow signal line
-
-
=head2 Links
http://www.stockcharts.com/education/What/IndicatorAnalysis/indic_stochasticOscillator.html
Modified: trunk/GT/Indicators/StandardError.pm
===================================================================
--- trunk/GT/Indicators/StandardError.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/StandardError.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -51,16 +51,9 @@
my $self = shift;
# Linear regression of the CLOSE against the sequence number
- $self->{'linear_regression_line'} = GT::Indicators::LinearRegression->new([
- $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(2) ]);
-# # What are the arguments to the linear regression?
-# $self->{'linear_regression_line'} = GT::Indicators::LinearRegression->new([
-# $self->{'args'}->get_arg_names(1),
-# $self->{'args'}->get_arg_names(2),
-# $self->{'args'}->get_arg_names(2)]);
+ $self->{'linear_regression_line'} = GT::Indicators::LinearRegression->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(2) ]);
- $self->add_indicator_dependency($self->{'linear_regression_line'},
- $self->{'args'}->get_arg_constant(1));
+ $self->add_indicator_dependency($self->{'linear_regression_line'}, $self->{'args'}->get_arg_constant(1));
$self->add_prices_dependency($self->{'args'}->get_arg_constant(1));
}
@@ -87,9 +80,7 @@
my $linear_regression_line_value = $a * $n + $b;
# Calculate the distance from the linear regression line
- my $d = $self->{'args'}->get_arg_values($calc, $n, 2)
- - $linear_regression_line_value;
-# my $d = $get_arg_values($calc, $n, 2) - $linear_regression_line_value;
+ my $d = $self->{'args'}->get_arg_values($calc, $n, 2) - $linear_regression_line_value;
# Calculate the sum of the squared errors
$sum_of_the_squared_errors += ($d ** 2);
Modified: trunk/GT/Indicators/T3.pm
===================================================================
--- trunk/GT/Indicators/T3.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/T3.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -5,7 +5,7 @@
# version 2 or (at your option) any later version.
use strict;
-use vars qw(@ISA @NAMES);
+use vars qw(@ISA @NAMES @DEFAULT_ARGS);
use GT::Indicators;
use GT::Indicators::EMA;
@@ -13,6 +13,7 @@
@ISA = qw(GT::Indicators);
@NAMES = ("T3[#1,#2]");
+
AT
DEFAULT_ARGS = (5, 0.7);
=pod
@@ -44,57 +45,30 @@
T3 = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3
-=head2 Parameters
-
-The default values are :
-N = 5
-a = 0.7
-
-=head2 Examples
-
-GT::Indicators::T3->new()
-GT::Indicators::T3->new([5, 0.7])
-
=cut
-sub new {
- my $type = shift;
- my $class = ref($type) || $type;
- my ($args) = @_;
- my $self = { 'args' => defined($args) ? $args : [ 5, 0.7 ] };
-
- $args->[0] = 5 if (! defined($args->[0]));
- $args->[1] = 0.7 if (! defined($args->[1]));
-
- return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, "");
-}
-
sub initialize {
my $self = shift;
# Initialize e1, e2, e3, e4, e5 and e6
- $self->{'e1'} = GT::Indicators::EMA->new([ $self->{'args'}[0] ]);
+ my $period = $self->{'args'}->get_arg_names(1);
+ $self->{'e1'} = GT::Indicators::EMA->new([ $period ]);
- $self->{'e2'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e1'}->{'args'}->get_arg_names()]}}" ]);
+ $self->{'e2'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e1'}->get_name . "}" ]);
+
+ $self->{'e3'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e2'}->get_name . "}" ]);
+
+ $self->{'e4'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e3'}->get_name . "}" ]);
+
+ $self->{'e5'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e4'}->get_name . "}" ]);
+
+ $self->{'e6'} = GT::Indicators::EMA->new([ $period, "{I:Generic:ByName " . $self->{'e5'}->get_name . "}" ]);
- $self->{'e3'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e2'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->{'e4'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e3'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->{'e5'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e4'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->{'e6'} = GT::Indicators::EMA->new([ $self->{'args'}[0],
- "{I:EMA @{[$self->{'e5'}->{'args'}->get_arg_names()]}}" ]);
-
- $self->add_indicator_dependency($self->{'e1'}, $self->{'args'}[0] * 5 - 4);
- $self->add_indicator_dependency($self->{'e2'}, $self->{'args'}[0] * 4 - 3);
- $self->add_indicator_dependency($self->{'e3'}, $self->{'args'}[0] * 3 - 2);
- $self->add_indicator_dependency($self->{'e4'}, $self->{'args'}[0] * 2 - 1);
- $self->add_indicator_dependency($self->{'e5'}, $self->{'args'}[0]);
+ $self->add_indicator_dependency($self->{'e1'}, $period * 5 - 4);
+ $self->add_indicator_dependency($self->{'e2'}, $period * 4 - 3);
+ $self->add_indicator_dependency($self->{'e3'}, $period * 3 - 2);
+ $self->add_indicator_dependency($self->{'e4'}, $period * 2 - 1);
+ $self->add_indicator_dependency($self->{'e5'}, $period);
$self->add_indicator_dependency($self->{'e6'}, 1);
}
@@ -115,8 +89,8 @@
my $e5_name = $self->{'e5'}->get_name;
my $e6_name = $self->{'e6'}->get_name;
my $t3_name = $self->get_name(0);
- my $period = $self->{'args'}[0];
- my $a = $self->{'args'}[1];
+ my $period = $self->{'args'}->get_arg_constant(1);
+ my $a = $self->{'args'}->get_arg_constant(2);
return if ($indic->is_available($t3_name, $i));
return if (! $self->check_dependencies($calc, $i));
Modified: trunk/GT/Indicators/TR.pm
===================================================================
--- trunk/GT/Indicators/TR.pm 2008-04-23 15:30:46 UTC (rev 620)
+++ trunk/GT/Indicators/TR.pm 2008-04-26 15:26:51 UTC (rev 621)
@@ -70,10 +70,10 @@
my $a = $high - $low;
# B = Yesterday's Close - Today's High
- my $b = abs($yesterday_close - $high);
+ my $b = abs($high - $yesterday_close);
# C = Yesterday's Close - Today's Low
- my $c = abs($yesterday_close - $low);
+ my $c = abs($low - $yesterday_close);
# TR = max (A, B, C)
$tr = max($a, $b, $c);