<?php
/**
* Finasystem version 0.4 Lin Hai - Technical Analysis Library in PHP
*Release: 14/10/2006
*Copyright (C) 2006 Rudy Zuck
*mailto:rudy[-at-]zuck.fr
*web:http://sourceforge.net/projects/finasystem
*
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Stochastic Class (stoch)
*
*<p>The Stochastic Oscillator measures where the close is in relation to the recent
*trading range. The values range from zero to 100. %D values over 75 indicate an
*overbought condition; values under 25 indicate an oversold condition. When the Fast
*%D crosses above the Slow %D, it is a buy signal; when it crosses below, it is a
*sell signal. The Raw %K is generally considered too erratic to use for crossover signals.</p>
*
*<p>The Stochastic Indicator was developed by George C. Lane.</p>
*
*
*<p>Formula:</p>
*
* - %K fast = 100 * ( (close - LL) / (HH - LL) )
*
* @author Rudy Zuck <rudy[-at-]zuck.fr>
* @copyright Copyright, 2006, Rudy Zuck
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 0.4
* @package fs_ta
*/
class stoch{
/**
* @var double[]
*/
private $Kfast;
/**
* @var double[]
*/
private $Dfast;
/**
* @var double[]
*/
private $Kslow;
/**
* @var double[]
*/
private $Dslow;
/**
* @param double[] $high
* @param double[] $low
* @param double[] $close
* @param int $range
* @return double[]
*/
function get_Kfast($high,$low,$close,$range){
$size_data = count($close);
for($i=0; $i<$size_data-$range+1; $i++){
$my_hh = new hh();
$my_hh->set($high,$i,$range);
$hh = $my_hh->get_value();
$my_ll = new ll();
$my_ll->set($low,$i,$range);
$ll = $my_ll->get_value();
$this->Kfast[$range+$i-1] = 100 * ( ($close[$range+$i-1] - $ll) / ($hh - $ll) );
}
return $this->Kfast;
}
function get_Dfast($high,$low,$close,$range,$ma){
$my_sma = new sma();
$my_Kfast = $this->get_Kfast($high,$low,$close,$range);
$this->Dfast = $my_sma->get($my_Kfast,$ma);
return $this->Dfast;
}
function get_Kslow($high,$low,$close,$range,$smooth){
$my_sma = new sma();
$my_Kfast = $this->get_Kfast($high,$low,$close,$range);
$this->Kslow = $my_sma->get($my_Kfast,$smooth);
return $this->Kslow;
}
function get_Dslow($high,$low,$close,$range,$smooth,$ma){
$my_sma = new sma();
$my_Kslow = $this->get_Kslow($high,$low,$close,$range,$smooth);
$this->Dslow = $my_sma->get($my_Kslow,$ma);
return $this->Dslow;
}
}
?>