| 1 | package Finance::GeniusTrader::Indicators::PP; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 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::Indicators; | ||
| 13 | use Finance::GeniusTrader::Indicators::TP; | ||
| 14 | use Finance::GeniusTrader::Prices; | ||
| 15 | |||
| 16 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 17 | @NAMES = ("Pivot[#*]", "FirstSupport[#*]", "SecondSupport[#*]", "FirstResistance[#*]", "SecondResistance[#*]"); | ||
| 18 | @DEFAULT_ARGS = ("{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices CLOSE}"); | ||
| 19 | |||
| 20 | =head1 Finance::GeniusTrader::Indicators::PP | ||
| 21 | |||
| 22 | =head2 Overview | ||
| 23 | |||
| 24 | Pivot Points and Daily Support and Resistance. | ||
| 25 | |||
| 26 | =head2 Calculation | ||
| 27 | |||
| 28 | The calculation for the new day are calculated from the High (H), low (L) and close (C) of the previous day. | ||
| 29 | Pivot point = P = (H + L + C)/3 | ||
| 30 | First area of resistance = R1 = 2P - L | ||
| 31 | First area of support = S1 = 2P - H | ||
| 32 | Second area of resistance = R2 = (P -S1) + R1 | ||
| 33 | Second area of support = S2 = P - (R1 - S1) | ||
| 34 | |||
| 35 | =head2 Links | ||
| 36 | |||
| 37 | http://www.sixer.com/y/s/education/tutorial/edpage.cfm?f=pivots.cfm&OB=indicators | ||
| 38 | http://www.tradertalk.com/tutorial/Pivpt.html | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | sub initialize { | ||
| 43 | my $self = shift; | ||
| 44 | |||
| 45 | $self->{'tp'} = Finance::GeniusTrader::Indicators::TP->new( [ $self->{'args'}->get_arg_names(1), | ||
| 46 | $self->{'args'}->get_arg_names(2), | ||
| 47 | $self->{'args'}->get_arg_names(3) | ||
| 48 | ] ); | ||
| 49 | |||
| 50 | $self->add_indicator_dependency($self->{'tp'}, 2); | ||
| 51 | $self->add_prices_dependency(2); | ||
| 52 | } | ||
| 53 | |||
| 54 | =head2 Finance::GeniusTrader::Indicators::PP::calculate($calc, $day) | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | sub calculate { | ||
| 59 | my ($self, $calc, $i) = @_; | ||
| 60 | my $prices = $calc->prices; | ||
| 61 | my $indic = $calc->indicators; | ||
| 62 | my $pivot_name = $self->get_name(0); | ||
| 63 | my $first_support_name = $self->get_name(1); | ||
| 64 | my $second_support_name = $self->get_name(2); | ||
| 65 | my $first_resistance_name = $self->get_name(3); | ||
| 66 | my $second_resistance_name = $self->get_name(4); | ||
| 67 | |||
| 68 | # Return if results are already available | ||
| 69 | return if ($indic->is_available($pivot_name, $i) && | ||
| 70 | $indic->is_available($first_support_name, $i) && | ||
| 71 | $indic->is_available($second_support_name, $i) && | ||
| 72 | $indic->is_available($first_resistance_name, $i) && | ||
| 73 | $indic->is_available($second_resistance_name, $i)); | ||
| 74 | |||
| 75 | # Return if dependencies are missing | ||
| 76 | return if (! $self->check_dependencies($calc, $i)); | ||
| 77 | |||
| 78 | # Get the Pivot Point which is the Typical Price | ||
| 79 | # in the "traditional" calculation method | ||
| 80 | my $pivot = $indic->get($self->{'tp'}->get_name, $i - 1); | ||
| 81 | |||
| 82 | # Calculate supports and resistances | ||
| 83 | my $first_resistance = (2 * $pivot) - $self->{'args'}->get_arg_values($calc, $i-1, 2); | ||
| 84 | my $first_support = (2 * $pivot) - $self->{'args'}->get_arg_values($calc, $i-1, 1); | ||
| 85 | my $second_resistance = ($pivot - $first_support) + $first_resistance; | ||
| 86 | my $second_support = $pivot - ($first_resistance - $first_support); | ||
| 87 | |||
| 88 | # Then return results | ||
| 89 | $calc->indicators->set($pivot_name, $i, $pivot); | ||
| 90 | $calc->indicators->set($first_support_name, $i, $first_support); | ||
| 91 | $calc->indicators->set($second_support_name, $i, $second_support); | ||
| 92 | $calc->indicators->set($first_resistance_name, $i, $first_resistance); | ||
| 93 | $calc->indicators->set($second_resistance_name, $i, $second_resistance); | ||
| 94 | |||
| 95 | } | ||
| 96 | |||
| 97 | 1; |