<html>

<title>
Results: Timing the market
</title>

<body bgcolor = "#C9C299">
<script src="http://www.clocklink.com/embed.js"></script><script type="text/javascript" language="JavaScript">obj=new Object;obj.clockfile="5004-white.swf";obj.TimeZone="USA_NewYork";obj.width=240;obj.height=20;obj.Place="";obj.DateFormat="yyyy / mm / dd DDD";obj.TimeFormat="hh:mm:ss TT";obj.wmode="transparent";showClock(obj);</script></div>
<table valign = "top"border = "1" height = "30%"width = "100%"  >
		<tr>
			<td >
			 <img src = "home_logo.JPG" align = "center">

			</td>
		</tr>	

	</table>
	<a href = "home.html">Back to Home</a>
	<h1 align="center">Requested Services:</h1>

</br></br>
<?php 
include 'C:\php\jpgraph-2.3\src\jpgraph.php';
include 'C:\php\jpgraph-2.3\src\jpgraph_line.php';
include 'C:\php\jpgraph-2.3\src\jpgraph_date.php';

if(isset($_POST['graphs']))
{	
	//nothing comes here. See closeGraph.php
}

else if(isset($_POST['quotes']))
{
	$var_quote = $_POST["lsCompanyName"];
	
	//part to invoke the web service >> getQuote
	$client = new SoapClient("http://localhost/StockPredictorWS/Service.asmx?WSDL");
	$params=array('organization_name' => $var_quote);
	$objectresult = $client->__soapCall('getQuotesWS', array('parameters'=> $params));
	$simpleresult = $objectresult->getQuotesWSResult;
	echo 'The current price for'.' '.$var_quote.' '.'is'.' '.'$'.$simpleresult;	
}
else if(isset($_POST['predictions']))
{
	$var_predict = $_POST["lsCompanyName"];
	
	$client = new SoapClient("http://localhost/StockPredictorWS/Service.asmx?WSDL");
	$params=array('organization_name' => $var_predict);
	
	$objectresult = $client->__soapCall('getPredictionWS', array('parameters'=> $params));
	$simpleresult = $objectresult->getPredictionWSResult;
	$predictionarray = explode(",",$simpleresult);
	
	$r_rate = $predictionarray[2]*100;	
	
	if($predictionarray[0] == '1')
	{
		echo 'Recommendation: Buy this Stock...You are going to make some money';
		?></br>
		<?php echo 'The predicted price for this company is'.' '.'$'.$predictionarray[1];?></br></br>
		<?php echo 'Confidence Level: The Recognition Rate for this company is'.' '.$r_rate;?></br></br>
		<?php echo 'Time Horizon for the predicted price is 3 Days';?></br>
	<?php
	}	
	else if($predictionarray[0] == '0')
	{
		echo 'Recommendation: Our advice is not to buy this Stock...since Our Neural network predicts losses';
		?></br>
		<?php echo 'The predicted price for this company is'.' '.'$'.$predictionarray[1];?></br></br>
		<?php echo 'Confidence Level: The Recognition Rate for this company is'.' '.$r_rate;?></br></br>
		<?php echo 'Time Horizon for the predicted price is 3 Days';?></br>
<?php
	}	
}
else if(isset($_POST['indicators']))
{	
	$var_indicate = $_POST["lsCompanyName"];
	
	//first parameter is server name, 2nd username 'root', 3rd is password
	$rst = @mysql_connect("localhost","root","ateet");
	if (!$rst)
	{
		echo( "<p>Unable to connect to database manager.</p>");
		die('Could not connect: ' . mysql_error());
		exit();
	} 
	else 
	{
		//echo("<p>Successfully Connected to MySQL Database Manager!</p>");
	}

	//selecting database
	if (! @mysql_select_db("test_schema") )
	{
		echo( "<p>Unable to  connect database...</p>");
		exit();
	} 
	else 
	{
		//echo("<p>Successfully Connected to Database 'testschema'!</p>");
	}

	$result_id = mysql_query("select OrganizationID from organizationtable where OrganizationName = '$var_indicate'") or die(mysql_error());
	$c_id = mysql_fetch_array($result_id, MYSQL_NUM);

	$company_id = $c_id[0];
	
	$close = array();
	$high = array();
	$low = array();

	//we retrieve the close price for the selected organization
	$result_close = mysql_query("select Close from organizationhistory where OrganizationID ='$company_id' ORDER BY Date") or die(mysql_error());
	//$closearray = mysql_fetch_array($result_close, MYSQL_NUM);

	$result_high = mysql_query("select High from organizationhistory where OrganizationID ='$company_id' ORDER BY Date") or die(mysql_error());
	//$higharray = mysql_fetch_array($result_high, MYSQL_NUM);

	$result_low = mysql_query("select Low from organizationhistory where OrganizationID ='$company_id' ORDER BY Date") or die(mysql_error());
	//$lowarray = mysql_fetch_array($result_low, MYSQL_NUM);

	while($row = mysql_fetch_array($result_close, MYSQL_NUM))
	{
		array_push($close, $row[0]);
	}

	while($row = mysql_fetch_array($result_high, MYSQL_NUM))
	{
		array_push($high, $row[0]);
	}


	while($row = mysql_fetch_array($result_low, MYSQL_NUM))
	{
		array_push($low, $row[0]);
	}

	$size = sizeof($close);
	$predict = array(0,0,0,0);

	//Price momentum oscillator (PMO)
	$tc=$close[$size-1];
	$tdac=$close[$size-11];

	//echo $tdac;

	$pmo=$tc-$tdac;
	//echo $pmo;
	if($pmo>0)
		$predict[0]=1;
	else
		$predict[0]=0;

	//Relative strength Index (RSI)
	$upclose=0;
	$downclose=1;
	for($i=9; $i>0; $i--)
	{
	$tc=$close[$size-$i];
	$yc=$close[$size-$i-1];
	if($tc>$yc)
		$upclose = $upclose + $tc;
	else
		$downclose = $downclose + $tc;
	}
	$ratio = $upclose / $downclose;
	$rsi = 100 - 100/(1 + $ratio);

	//echo $rsi;

	if($rsi>50)
		$predict[1]=1;
	else
		$predict[1]=0;
		
	// Stochastic Oscillator (%K)
	$tc=$close[$size-1];
	$ln=$low[$size-1];
	$hn=$high[$size-1];
	for ($i=5; $i>1; $i--)
	{
	if($ln>$low[$size-$i])
		$ln=$low[$size-$i];
	if($hn<$high[$size-$i])
		$hn=$high[$size-$i];
	}
	$percentk = ($tc-$ln)*100/($hn-$ln);

	if($percentk>80)
		$predict[2]=1;
	elseif ($percentk<20)
		$predict[2]=0;
	else
		$predict[2]=2;

	//Moving Averages
	$tma = 0;
	$yma = 0;
	for ($i=10; $i>0; $i--)
	{
	$tma = $tma + $close[$size-$i];
	$yma = $yma + $close[$size-$i-1];
	}
	$tma = $tma/10;
	$yma = $yma/10;

	if($tma>$yma)
		$predict[3]=1;
	else
		$predict[3]=0;
		
	//Verification module
	$buy=1;
	$sell=0;
	for($i=0; $i<4; $i++)
	{
		$buy=$buy*$predict[$i];
		$sell=$sell+$predict[$i];
	}
	if($buy==1)
		echo "Tomorrow`s closing price will increase.";
	elseif($sell==0)
		echo "Today's closing price will decrease.";
	else
		echo "Hold on to your Stocks!!";
}
else if(isset($_POST['indicators2']))
{	
	$var_indicate2 = $_POST["lsCompanyName"];
	
	//first parameter is server name, 2nd username 'root', 3rd is password
	$rst = @mysql_connect("localhost","root","ateet");
	if (!$rst)
	{
			echo( "<p>Unable to connect to database manager.</p>");
			die('Could not connect: ' . mysql_error());
			exit();
	} 
	else 
	{
			//echo("<p>Successfully Connected to MySQL Database Manager!</p>");
	}

	//selecting database
	if (! @mysql_select_db("test_schema") )
	{
				echo( "<p>Unable to  connect database...</p>");
				exit();
	} 
	else 
	{
				//echo("<p>Successfully Connected to Database 'testschema'!</p>");
	}

	//we select the company ID from the name of the organization selected
	//$name = "IBM";
	$result_id = mysql_query("select OrganizationID from organizationtable where OrganizationName = '$var_indicate2'") or die(mysql_error());
	$c_id = mysql_fetch_array($result_id, MYSQL_NUM);

	$company_id = $c_id[0];
	//echo  "organization id :".$company_id;

	$close = array();
	$high = array();
	$volume = array();
	$low = array();

	//we retrieve the close price for the selected organization
	$result_close = mysql_query("select Close from organizationhistory where OrganizationID ='$company_id' ORDER BY Date") or die(mysql_error());
	//$closearray = mysql_fetch_array($result_close, MYSQL_NUM);

	$result_high = mysql_query("select High from organizationhistory where OrganizationID ='$company_id' ORDER BY Date") or die(mysql_error());
	//$higharray = mysql_fetch_array($result_high, MYSQL_NUM);

	$result_low = mysql_query("select Low from organizationhistory where OrganizationID ='$company_id' ORDER BY Date") or die(mysql_error());
	//$lowarray = mysql_fetch_array($result_low, MYSQL_NUM);

	$result_volume = mysql_query("select Volume from organizationhistory where OrganizationID ='$company_id' ORDER BY Date") or die(mysql_error());
	//$volumearray = mysql_fetch_array($result_volume, MYSQL_NUM);

	while($row = mysql_fetch_array($result_close, MYSQL_NUM))
	{
				array_push($close, $row[0]);
	}

	while($row = mysql_fetch_array($result_high, MYSQL_NUM))
	{
				array_push($high, $row[0]);
	}


	while($row = mysql_fetch_array($result_low, MYSQL_NUM))
	{
				array_push($low, $row[0]);
	}

	while($row = mysql_fetch_array($result_volume, MYSQL_NUM))
	{
				array_push($volume, $row[0]);
	}


	$size=sizeof($close);
	$count_sell=0;
	$count_buy=0;
	$count_hold=0;


	//Money Flow Index
	$tp=array();
	$mf=array();
	$pmf=0;
	$nmf=0;
	$mr=0;
	$mfi=0;

	for($i=1; $i<=15; $i++)
	{
	$k = $size-$i;
	$tp[$i-1]= ($high[$k]+$low[$k]+$close[$k])/3;
	$mf[$i-1]=  $volume[$k]*$tp[$i-1];

	//echo $tp[$i];
	//echo " ";
	}

	for($i=1; $i<=14; $i++)
	{
	if($tp[$i] > $tp[$i-1])
			    $pmf=$pmf+$mf[$i];
	else
			    $nmf=$nmf+$mf[$i];
	}
	if($nmf !=0)
	{
				$mr=($pmf/$nmf);
	}
	$mfi=100-(100/(1+$mr));
    
	//echo "mfi=";
	//echo $mfi;

	if($mfi>80)
	$count_buy = $count_buy+1;
				//echo "BUY";
	elseif($mfi<20)
	$count_sell = $count_sell+1;
			    //echo "SELL";
	else 
	$count_hold= $count_hold+1;
				//echo"HOLD";

	//DeMarker Indicator
	$Demax=array();
	$Demin=array();
	$maxsum=0;
	$minsum=0;
	for($i=1; $i<=10; $i++)
	{
	if($high[$size-$i]>$high[$size-$i-1])
			   $Demax[$i-1]= ($high[$size-$i]-$high[$size-$i-1]);
	else
			   $Demax[$i-1]=0;
			   
	if($low[$size-$i]<$low[$size-$i-1])
			   $Demin[$i-1]= ($low[$size-$i-1]-$low[$size-$i]);
	else
			   $Demin[$i-1]=0;
			   
	$maxsum=$maxsum+ $Demax[$i-1];
	$minsum=$minsum+ $Demin[$i-1];
	}

	$Demax_avg= $maxsum/10;
	$Demin_avg= $minsum/10;

	$DeMaker=($Demax_avg)/($Demax_avg+$Demin_avg);
	
	//echo "D=";
	//echo $DeMaker;

	if($DeMaker<30)
	$count_buy = $count_buy+1;
				//echo "BUY";
	elseif($DeMaker>70)
	$count_sell = $count_sell+1;
			   // echo "SELL";
	else 
	$count_hold= $count_hold+1;
	//echo"HOLD";
	
	
	//William Percent Range Indicator
	$tc=$close[$size-1];

	for($i=1; $i<15; $i++)
	{
	if($high[$size-$i]> $high[$size-$i-1])
			    $high_max = $high[$size-1];
	else
			    $high_max = $high[$size-$i-1];
	}
	for($i=1; $i<15; $i++)
	{
	if($low[$size-$i] < $high[$size-$i-1])
			    $low_min = $low[$size-$i];
	else
			    $low_min = $high[$size-$i-1];
	}
	
	if(($high_max-$low_min)!= 0)
		$WR=(($high_max-$tc)/($high_max-$low_min))*100;
	
	//echo "WR";
	//echo $WR;
	if($WR>80)
	$count_sell = $count_sell+1;
				//echo "SELL";
	elseif($WR<20)
	$count_buy = $count_buy+1;
			   // echo "BUY";
	else 
	$count_hold= $count_hold+1;
	//echo"HOLD";
	
	
	//Commodity Channel Index
	$tp_tot=array();
	$D=array();
	$sum_tp_tot=0;
	$sum_D=0;

	$tp=($high[$size-1]+$low[$size-1]+$close[$size-1])/3;

	for($i=1; $i<=10; $i++)
	{
	$tp_tot[$i-1]=($high[$size-$i]+$low[$size-$i]+$close[$size-$i])/3;

	$sum_tp_tot = $sum_tp_tot+$tp_tot[$i-1];
	}

	$sma_tp = $sum_tp_tot/10;

	for($i=1; $i<=10; $i++)
	{
	if ($tp_tot[$i-1]> $sma_tp)
	$D[$i-1]= $tp_tot[$i-1]- $sma_tp;
	else
	$D[$i-1]= $sma_tp-$tp_tot[$i-1];

	$sum_D = $sum_D+ $D[$i-1];
	}

	$sma_D = $sum_D/10;

	$M= $sum_D*0.015;

	$T= $tp-$sma_tp;

	$CCI=$T/$M;

	//echo " CCI=";
	//echo $CCI;

	if($CCI<-5)
	$count_buy = $count_buy+1;
				//echo "BUY";
	elseif($CCI>5)
	$count_sell = $count_sell+1;
			    //echo "SELL";
	else
	$count_hold= $count_hold+1; 
				//echo"HOLD";

	//Aroon Oscillator

	for($i=9; $i>=2; $i--)
	{
	if ($high[$size-$i] > $high[$size-$i+1])
	{$max=$high[$size-$i];
	$num_high = 10-$i;
	}
	}
	
	for($j=9; $j>=2; $j--)
	{
	if ($low[$size-$j] < $low[$size-$j+1])
	{
	$min=$low[$size-$j];
	$num_low= 10-$j;
	}
	}
	
	$AU=((10- $num_high)/10)*100;
	$AD=((10- $num_low)/10)*100;
	$AO= $AU-$AD;

	//echo "ao";
	//echo $AO;
	if ($AO>50)
	$count_buy = $count_buy+1;
			   //echo 'BUY';
	elseif($AO<50)
	$count_sell = $count_sell+1;
			   // echo "SELL";
	else 
	$count_hold= $count_hold+1;
			   //echo"HOLD"
			   
	//echo $count_buy;
	//echo $count_sell;
	//echo $count_hold;
	
	if($count_buy> $count_sell)
			    echo 'BUY';
	elseif($count_buy < $count_sell)
			    echo 'SELL';
	else
				echo 'HOLD';
}

?>
</br></br></br>
<a href="http://localhost/PredictionPage.php">Click here to return to previous page</a>
</body>
</html>