='$lastentry' AND `entry`<='$numberofentries' ORDER BY `entry` DESC")
or die(mysql_error());
//Define limits for 200 day moving average
$lowerlimit= $numberofentries - 200 + 1;
$upperlimit= $numberofentries;
//Define limits for 50 day moving average
$lowerlimit50= $numberofentries - 50 + 1;
$upperlimit= $numberofentries;
//check if records will be returned
if (mysql_num_rows($result2) >0)
{
//print analysis
//echo '
';
echo '';
echo 'Entry | Date | Open | High | Low | Close | MA200 | MA50 | Delta | %Strength | Recommendation |
';
while ($row2= mysql_fetch_row($result2))
{
$result3 = mysql_query("SELECT avg(close) from `sp500` WHERE `entry`>='$lowerlimit' AND `entry`<='$upperlimit'")
or die(mysql_error());
// store the record of the "example" table into $row
$row3 = mysql_fetch_array($result3)
or die("Invalid query: " . mysql_error());
// Print out the contents of the entry
$ma200 = $row3['avg(close)'];
$result4 = mysql_query("SELECT avg(close) from `sp500` WHERE `entry`>='$lowerlimit50' AND `entry`<='$upperlimit'")
or die(mysql_error());
// store the record of the "example" table into $row
$row4 = mysql_fetch_array($result4)
or die("Invalid query: " . mysql_error());
// Print out the contents of the entry
$ma50 = $row4['avg(close)'];
$w=round($ma200,2);
$x=round($ma50,2);
$y=round(($ma50-$ma200),2);
$z=round(((($ma50-$ma200)/$ma200)*100),3);
if ($z >= 8.51) {
$recommendation = 'above SATURATED BULL TREND( VERY HIGH RISK BUYING)';
}
elseif ( $z >=5.1 && $z <=8.5) {
$recommendation = 'CONFIRMED BULL TREND (HIGH RISK BUYING)';
}
elseif ( $z >=2 && $z <=5) {
$recommendation = 'CONFIRMED BULL TREND (LOW RISK BUYING)';
}
elseif ( $z >=0 && $z <=1.99) {
$recommendation = 'UNCONFIRMED BULL TREND';
}
elseif ( $z <=0 && $z >=-4.99) {
$recommendation = 'UNCONFIRMED BEAR TREND';
}
elseif ( $z <=-5 && $z >=-8) {
$recommendation = 'CONFIRMED BEAR TREND (LOW RISK SHORT)';
}
elseif ( $z <=-8.1 ) {
$recommendation = 'SATURATED BEAR TREND( VERY HIGH RISK SHORT)';
}
$upperlimit--;
$lowerlimit50--;
$lowerlimit--;
echo '';
echo ''.$row2[0].' | ';
echo ''.$row2[1].' | ';
echo ''.$row2[2].' | ';
echo ''.$row2[3].' | ';
echo ''.$row2[4].' | ';
echo ''.$row2[5].' | ';
echo ''.$w.' | ';
echo ''.$x.' | ';
echo ''.$y.' | ';
echo ''.$z.' | ';
echo ''.$recommendation.' | ';
echo '
';
}
echo '
';
echo '
';
echo '
This tool is developed by: PHP Developer. Org
';
}
else
{
echo '
No rows found.
';
}
mysql_free_result($result1);
mysql_free_result($result2);
mysql_free_result($result3);
mysql_free_result($result4);
mysql_close($dbhandle);
?>