[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] SVN Commit r640 - branches/exp/GT/Signals/Generic
Author: thomas
Date: 2008-06-16 07:45:05 +0200 (Mon, 16 Jun 2008)
New Revision: 640
Added:
branches/exp/GT/Signals/Generic/First.pm
branches/exp/GT/Signals/Generic/StillTrue.pm
Log:
Add two generic signals. Handy in writing complex crossover systems.
Added: branches/exp/GT/Signals/Generic/First.pm
===================================================================
--- branches/exp/GT/Signals/Generic/First.pm (rev 0)
+++ branches/exp/GT/Signals/Generic/First.pm 2008-06-16 05:45:05 UTC (rev 640)
@@ -0,0 +1,82 @@
+package GT::Signals::Generic::First;
+
+# Copyright 2008 Thomas Weigert
+# Based on and for GeniusTrader (C) 2000-2002 Rapha��Hertzog, Fabien Fulhaber
+# This file is distributed under the terms of the General Public License
+# version 2 or (at your option) any later version.
+
+# Standards-Version: 1.0
+
+use strict;
+use vars qw(@ISA @NAMES);
+
+use GT::Signals;
+use GT::Indicators::Generic::Container;
+
+
AT
ISA = qw(GT::Signals);
+
AT
NAMES = ("First[#1,#2]");
+
+=head1 NAME
+
+GT::Signals::Generic::First
+
+=head2 DESCRIPTION
+
+This generic Signal will give a positive signal when the signal passed in as
+a parameter has become positive. It will not give another signal until the
+signal passed in as second parameter has become positive.
+
+=head2 EXAMPLE
+
+Becomes true when the RSI crosses above 80 and false the next day; remains
+false until the RSI first crosses down below 50 and then crosses again
+above 80.
+
+ S:Generic:First {S:Generic:Above {I:RSI} 80} {S:Generic:CrossOverDown {I:RSI} 50}
+
+=cut
+sub initialize {
+ my ($self) = @_;
+ warn "Bad number of arguments given to S:Generic:StillTrue !" if ($self->{'args'}->get_nb_args() < 1 || $self->{'args'}->get_nb_args() > 2);
+ $self->add_arg_dependency(1, 1) unless $self->{'args'}->is_constant(1);
+ $self->add_arg_dependency(2, 1) unless $self->{'args'}->is_constant(2);
+
+ my $name = $self->get_name;
+ $self->{'current'} = GT::Indicators::Generic::Container->new(["Current($name)"]);
+}
+
+sub detect {
+ my ($self, $calc, $i) = @_;
+ my $signals = $calc->signals;
+ my $name = $self->get_name;
+ my $current = $self->{'current'}->get_name;
+
+ return if ($calc->signals->is_available($self->get_name, $i));
+ return if (! $self->check_dependencies($calc, $i));
+
+ my $yesterday = $calc->indicators->get($current, $i - 1);
+#printf "[%s]\t%s\n", $calc->prices->at($i)->[5], $yesterday;
+ if ( $yesterday ) {
+ # check if the signal is still true
+ my $value = $self->{'args'}->get_arg_values($calc, $i, 2);
+ if (! (defined($value) && $value)) {
+ $calc->indicators->set($current, $i, 1);
+ return $signals->set($name, $i, 0);
+ } else {
+ $calc->indicators->set($current, $i, 0);
+ return $signals->set($name, $i, 0);
+ }
+ } else {
+ # check whether the signal has become true
+ my $value = $self->{'args'}->get_arg_values($calc, $i, 1);
+ if (defined($value) && $value) {
+ $calc->indicators->set($current, $i, 1);
+ return $signals->set($name, $i, 1);
+ } else {
+ $calc->indicators->set($current, $i, 0);
+ return $signals->set($name, $i, 0);
+ }
+ }
+}
+
+1;
Added: branches/exp/GT/Signals/Generic/StillTrue.pm
===================================================================
--- branches/exp/GT/Signals/Generic/StillTrue.pm (rev 0)
+++ branches/exp/GT/Signals/Generic/StillTrue.pm 2008-06-16 05:45:05 UTC (rev 640)
@@ -0,0 +1,71 @@
+package GT::Signals::Generic::StillTrue;
+
+# Copyright 2008 Thomas Weigert
+# Based on and for GeniusTrader (C) 2000-2002 Rapha����Hertzog, Fabien Fulhaber
+# This file is distributed under the terms of the General Public License
+# version 2 or (at your option) any later version.
+
+# Standards-Version: 1.0
+
+use strict;
+use vars qw(@ISA @NAMES);
+
+use GT::Signals;
+
+
AT
ISA = qw(GT::Signals);
+
AT
NAMES = ("StillTrue[#1,#2]");
+
+=head1 NAME
+
+GT::Signals::Generic::StillTrue
+
+=head2 DESCRIPTION
+
+This generic Signal will give a positive signal when the signal passed in as
+a parameter has become positive. It becomes negative when the signal passed in
+as second parameter becomes positive.
+
+=head2 EXAMPLE
+
+Becomes true when the RSI crosses above 80 and remains so until the RSI
+crosses down below 50.
+
+ S:Generic:StillTrue {S:Generic:Above {I:RSI} 80} {S:Generic:CrossOverDown {I:RSI} 50}
+
+=cut
+sub initialize {
+ my ($self) = @_;
+ warn "Bad number of arguments given to S:Generic:StillTrue !" if ($self->{'args'}->get_nb_args() < 1 || $self->{'args'}->get_nb_args() > 2);
+ $self->add_arg_dependency(1, 1) unless $self->{'args'}->is_constant(1);
+ $self->add_arg_dependency(2, 1) unless $self->{'args'}->is_constant(2);
+}
+
+sub detect {
+ my ($self, $calc, $i) = @_;
+ my $signals = $calc->signals;
+ my $name = $self->get_name;
+
+ return if (! $self->check_dependencies($calc, $i));
+ return if ($calc->signals->is_available($self->get_name, $i));
+
+ my $yesterday = $signals->get($name, $i - 1);
+ if ( $yesterday ) {
+ # check if the signal is still true
+ my $value = $self->{'args'}->get_arg_values($calc, $i, 2);
+ if (! (defined($value) && $value)) {
+ return $signals->set($name, $i, 1);
+ } else {
+ return $signals->set($name, $i, 0);
+ }
+ } else {
+ # check whether the signal has become true
+ my $value = $self->{'args'}->get_arg_values($calc, $i, 1);
+ if (defined($value) && $value) {
+ return $signals->set($name, $i, 1);
+ } else {
+ return $signals->set($name, $i, 0);
+ }
+ }
+}
+
+1;