« GeniusTrader/MoneyManagement/FixedSum.pm
↑ Summary
GeniusTrader/Graphics/DataSource/SingleIndicator.pm »
| 1 | package Finance::GeniusTrader::Signals::Generic::NewTimeFrame; | ||
| 2 | |||
| 3 | # Copyright 2004 Oliver Bossert | ||
| 4 | # This file is distributed under the terms of the General Public License | ||
| 5 | # version 2 or (at your option) any later version. | ||
| 6 | |||
| 7 | # Standards-Version: 1.0 | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 11 | |||
| 12 | use Finance::GeniusTrader::Signals; | ||
| 13 | use Finance::GeniusTrader::Eval; | ||
| 14 | use Finance::GeniusTrader::DateTime; | ||
| 15 | use Finance::GeniusTrader::Prices; | ||
| 16 | use Finance::GeniusTrader::Tools qw(:generic); | ||
| 17 | |||
| 18 | @ISA = qw(Finance::GeniusTrader::Signals); | ||
| 19 | @NAMES = ("NewTimeFrame[#*]"); | ||
| 20 | @DEFAULT_ARGS = ("month"); | ||
| 21 | |||
| 22 | =head1 NewTimeFrame Generic Signal | ||
| 23 | |||
| 24 | =head2 Overview | ||
| 25 | |||
| 26 | This signal will tell you when you entered a new timeframe | ||
| 27 | (e.g. the next month/week/year). | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub initialize { | ||
| 32 | my ($self) = @_; | ||
| 33 | $self->add_prices_dependency( 1 ); | ||
| 34 | $self->{'special_tf'} = Finance::GeniusTrader::DateTime::name_to_timeframe($self->{'args'}->get_arg_constant(1)); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub detect { | ||
| 38 | my ($self, $calc, $i) = @_; | ||
| 39 | |||
| 40 | return if (! $self->check_dependencies($calc, $i)); | ||
| 41 | return if ($calc->signals->is_available($self->get_name, $i)); | ||
| 42 | |||
| 43 | my $today = $calc->prices->at($i)->[$DATE]; | ||
| 44 | my $yesterday = $calc->prices->at($i-1)->[$DATE]; | ||
| 45 | |||
| 46 | my $time = Finance::GeniusTrader::DateTime::map_date_to_time($calc->prices->timeframe(), $today); | ||
| 47 | $today = Finance::GeniusTrader::DateTime::map_time_to_date($self->{'special_tf'}, $time); | ||
| 48 | |||
| 49 | $time = Finance::GeniusTrader::DateTime::map_date_to_time($calc->prices->timeframe(), $yesterday); | ||
| 50 | $yesterday = Finance::GeniusTrader::DateTime::map_time_to_date($self->{'special_tf'}, $time); | ||
| 51 | |||
| 52 | if ( $today ne $yesterday ) { | ||
| 53 | $calc->signals->set($self->get_name, $i, 1); | ||
| 54 | } else { | ||
| 55 | $calc->signals->set($self->get_name, $i, 0); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; |