Home arrow PHP arrow Page 4 - Building an E-mini Trading System Using PHP and Advanced MySQL Queries

Implementation, steps 14 and 15 - PHP

This article shows illustrative examples of how PHP and some advanced MySQL queries can be used to build an online trading system. For simplicity, we will be featuring one of the most common stock indexes: the S&P 500 index.

TABLE OF CONTENTS:
  1. Building an E-mini Trading System Using PHP and Advanced MySQL Queries
  2. Implementation, steps 1 through 5
  3. Implementation, steps 6 through 13
  4. Implementation, steps 14 and 15
By: Codex-M
Rating: starstarstarstarstar / 4
November 10, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Step 14: Combine all queries above and computations. Then print to an HTML table using a WHILE loop:

if (mysql_num_rows($result2) >0)

{

//print analysis

//echo '<table width=100% cellpadding=10 cellspacing=10 border=1>';

echo '<table width=100% border=1>';

echo '<tr><td><b>Entry</b></td><td><b>Date</b></td><td><b>Open</b>
</td><td><b>High</b></td><td><b>Low</b></td><td><b>Close</b></td>
<td><b>MA200</b></td><td><b>MA50</b></td><td><b>Delta</b></td>
<td><b>%Strength</b></td><td><b>Recommendation</b></td></tr>';

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 '<tr>';

echo '<td>'.$row2[0].'</td>';

echo '<td>'.$row2[1].'</td>';

echo '<td>'.$row2[2].'</td>';

echo '<td>'.$row2[3].'</td>';

echo '<td>'.$row2[4].'</td>';

echo '<td>'.$row2[5].'</td>';

echo '<td>'.$w.'</td>';

echo '<td>'.$x.'</td>';

echo '<td>'.$y.'</td>';

echo '<td>'.$z.'</td>';

echo '<td>'.$recommendation.'</td>';

echo '</tr>';

}

echo '</table>';

}

else

{

echo '<br />No rows found.<br />';

}

Step 15: Free the MySQL results and close the database connection.

mysql_free_result($result1);

mysql_free_result($result2);

mysql_free_result($result3);

mysql_free_result($result4);

mysql_close($dbhandle);

This is a fairly complicated application. You can see it in action here: http://www.php-developer.org/SP500historicaldataanalysis.php  

Or download the complete PHP script.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: