Location: PHPKode > projects > Finasystem > fs_ta/stochrsi.php
<?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 RSI (stochrsi)
 *
 *<p>The Stochastic RSI, as the name implies, is an Indicator of an Indicator. While the Stochastic
 *Oscillator monitors relationships between closing prices and the range, the Stochastic RSI monitors
 *the RSI values and their relationship over time.</p>
 *
 *
 *
 *<p>Formula:</p>
 *
 * - WARNING ->This algorithm has problems
 * - %stochRSI = 100 * ( (RSI - RSI(lowest))/ (RSI(highest) - RSI(lowest)) )
 *
 * @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 stochrsi{
	
	/**
	 * @var double[]
	 */
	private $stochrsi;
	/**
	 * @param double[] $close
	 * @param int $range_rsi
	 * @param int $range_stoch
	 * @return double[]
     */
	function get($close,$range_rsi,$range_stoch){
		$size_data = count($close);
		$my_rsi = new rsi();
		$rsi = $my_rsi->get($close,$range_rsi);
		
		for($i=$range_rsi-1; $i<$size_data-$range_stoch+1; $i++){
			
			$my_hh = new hh();
			$my_hh->set($rsi,$i,$range_stoch);
			$hh = $my_hh->get_value();
			
			$my_ll = new ll();
			$my_ll->set($rsi,$i,$range_stoch);
			$ll = $my_ll->get_value();
			
			if(($hh - $ll)==0){
				$this->stochrsi[$range_stoch+$i-1] = $this->stochrsi[$range_stoch+$i-1-1];	
			}
			else{
				$this->stochrsi[$range_stoch+$i-1] = 100*( ($rsi[$range_stoch+$i-1] - $ll) / ($hh - $ll) );
			}
		}
		return $this->stochrsi; 
	}
}
?>
Return current item: Finasystem