| 1 | package Finance::GeniusTrader::Indicators::IFISH; | ||
| 2 | |||
| 3 | # Copyright 2008 Karsten Wippler | ||
| 4 | # Based on and for GeniusTrader (C) 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 5 | # This file is distributed under the terms of the General Public License | ||
| 6 | # version 2 or (at your option) any later version. | ||
| 7 | |||
| 8 | # $Id: IFISH.pm,v 1.2 2008/03/09 18:06:15 ras Exp ras $ | ||
| 9 | |||
| 10 | # Standards-Version: 1.0 | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 14 | |||
| 15 | use Finance::GeniusTrader::ArgsTree; | ||
| 16 | use Finance::GeniusTrader::Indicators; | ||
| 17 | use Finance::GeniusTrader::Indicators::EMA; | ||
| 18 | use Finance::GeniusTrader::Prices; | ||
| 19 | |||
| 20 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 21 | @NAMES = ("IFISH[#1]"); | ||
| 22 | @DEFAULT_ARGS = (9 , 0.1, 50,"{I:RSI 5}" ); | ||
| 23 | |||
| 24 | =head1 Finance::GeniusTrader::Indicators::IFISH | ||
| 25 | |||
| 26 | =head2 Overview | ||
| 27 | Remember The Fisher Transform | ||
| 28 | |||
| 29 | 1 + x | ||
| 30 | fisher = 0.5 log ------------ | ||
| 31 | 1 - x | ||
| 32 | Its inverse is | ||
| 33 | |||
| 34 | exp(2*fisher)-1 | ||
| 35 | ifisher = ---------------- | ||
| 36 | exp(2*fisher)+1 | ||
| 37 | |||
| 38 | The input values should lie in the Interval [-5,5] | ||
| 39 | so they have to be adjusted to this interval. | ||
| 40 | So an Oscillator is moved,scaled,smoothed and then inverted. | ||
| 41 | Ehlers ist using a WMA for the smoothing | ||
| 42 | I will use an EMA. | ||
| 43 | |||
| 44 | =head2 Paramters | ||
| 45 | |||
| 46 | The User has to input valid scaling parameters. | ||
| 47 | for the RSI they are 0.1 and 50 so | ||
| 48 | 0.1(RSI-50) varies between -5 and 5. | ||
| 49 | 1. smoothing period | ||
| 50 | 2. scaling value | ||
| 51 | 3. midpoint adjustment | ||
| 52 | |||
| 53 | |||
| 54 | =head2 Links | ||
| 55 | http://mesasoftware.com/technicalpapers.htm | ||
| 56 | |||
| 57 | =head2 Creation | ||
| 58 | |||
| 59 | Finance::GeniusTrader::Indicators::IFISH->new() | ||
| 60 | |||
| 61 | |||
| 62 | =cut | ||
| 63 | sub initialize { | ||
| 64 | |||
| 65 | my ($self) = @_; | ||
| 66 | my $scale = "{I:G:Eval ". $self->{'args'}->get_arg_names(2) ." * (". | ||
| 67 | $self->{'args'}->get_arg_names(4) ." - " . $self->{'args'}->get_arg_names(3) . ")}"; | ||
| 68 | $self->{'ema1'} = Finance::GeniusTrader::Indicators::EMA->new([ $self->{'args'}->get_arg_names(1) , $scale ]); | ||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | # Smoothing functions are args 2 and 3 | ||
| 73 | my $nb_days = $self->{'args'}->get_arg_names(1) + $self->{'args'}->get_arg_names(2); | ||
| 74 | |||
| 75 | $self->add_indicator_dependency($self->{'ema1'},$self->{'args'}->get_arg_names(2)); | ||
| 76 | $self->add_arg_dependency(5, $nb_days); | ||
| 77 | |||
| 78 | |||
| 79 | } | ||
| 80 | |||
| 81 | =pod | ||
| 82 | |||
| 83 | =head2 Finance::GeniusTrader::Indicators::SMI::calculate($calc, $day) | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | sub calculate { | ||
| 88 | my ($self, $calc, $i) = @_; | ||
| 89 | my $indic = $calc->indicators; | ||
| 90 | my $prices = $calc->prices; | ||
| 91 | my $ema1_name = $self->{'ema1'}->get_name; | ||
| 92 | my $name = $self->get_name(0); | ||
| 93 | |||
| 94 | return if ($indic->is_available($name, $i)); | ||
| 95 | return if (! $self->check_dependencies($calc, $i)); | ||
| 96 | |||
| 97 | # Return the results | ||
| 98 | my $input=$self->{'ema1'}->calculate($calc, $i); | ||
| 99 | my $ifish=(exp(2*$input)-1)/(exp(2*$input)+1); | ||
| 100 | $indic->set($name, $i, $ifish); | ||
| 101 | |||
| 102 | } | ||
| 103 | 1; |