rohitb Posted October 17, 2012 Share Posted October 17, 2012 <?php session_start();?> <html> <body> <center> <h2> Gann Levels Calculator! </h2> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <b>Enter Current Market Price<input type="text" value="<?php echo $_POST['num1'] ?>" name="num1" /> <T><br><input type="submit" value="Calculate Gann Levels ->>" /> </form> <?php $num1 = $_POST["num1"]; $square_root=ceil(sqrt($num1)); $one_num_below=$square_root-1; $two_num_below=$square_root-2; $one_num_above=$square_root+1; $two_num_above=$square_root+2; $center_value=$two_num_below*$two_num_below; $value = $two_num_below; $names = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty','twentyone','twentytwo','twentythree','twentyfour'); // up to twentyfour //alternatively use pear/Number_Words //$nw = new Number_Words; echo "<table cellpadding='5' cellspacing='2' border='0'>"; for ($i = 1; $i <= 24; $i++) { $value += 0.125; //$word = str_replace('-', '', $nw->toWord($i)); ${'value_' . $names[$i - 1]} = $value; ${'value_' . $names[$i - 1] . '_fin'} = round($value * $value, 2); $res=${'value_' . $names[$i - 1] . '_fin'}; //${'value_' . $word} = $value; //${'value_' . $word . '_fin'} = round($value * $value, 2); } echo "<table cellpadding='5' cellspacing='2' border='0'>"; //depending on your own parameters of course, but the values must be in single quotes echo "<tr><td bgcolor=#FF0099><font size=1 face=verdana>$value_eighteen_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#CC0066><font size=1 face=verdana>$value_nineteen_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_twenty_fin</td></tr>"; echo "<tr><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_ten_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#CC0066><font size=1 face=verdana>$value_eleven_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_twelve_fin</td><td bgcolor=#990033><font size=1 face=verdana></td></tr>"; echo "<tr><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_two_fin</td><td bgcolor=#CC0066><font size=1 face=verdana>$value_three_fin</td><td bgcolor=#FF0099><font size=1 face=verdana>$value_four_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td></tr>"; echo "<tr><td bgcolor=#CC0066><font size=1 face=verdana>$value_seventeen_fin</td><td bgcolor=#CC0066><font size=1 face=verdana>$value_nine_fin</td><td bgcolor=#CC0066><font size=1 face=verdana>$value_one_fin</td><td bgcolor=#FF3399><font size=1 face=verdana>$center_value</td><td bgcolor=#CC0066><font size=1 face=verdana>$value_five_fin</td><td bgcolor=#CC0066><font size=1 face=verdana>$value_thirteen_fin</td><td bgcolor=#CC0066><font size=1 face=verdana>$value_twentyone_fin</td></tr>"; echo "<tr><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_eight_fin</td><td bgcolor=#CC0066><font size=1 face=verdana>$value_seven_fin</td><td bgcolor=#FF0099><font size=1 face=verdana>$value_six_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td></tr>"; echo "<tr><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_sixteen_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#CC0066><font size=1 face=verdana>$value_fifteen_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_fourteen_fin</td><td bgcolor=#990033><font size=1 face=verdana></td></tr>"; echo "<tr><td bgcolor=#FF0099><font size=1 face=verdana>$value_twentyfour_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#CC0066><font size=1 face=verdana>$value_twentythree_fin</td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#990033><font size=1 face=verdana></td><td bgcolor=#FF0099><font size=1 face=verdana>$value_twentytwo_fin</td></tr>"; echo "</table>"; //this ends your table echo "<br><br>"; echo "<table cellpadding='5' cellspacing='2' border='0'>"; //depending on your own parameters of course, but the values must be in single quotes echo "<tr><td bgcolor=#FF6633><font size=1 face=verdana>R1</td><td bgcolor=#FF6633><font size=1 face=verdana>R2</td><td bgcolor=#FF6633><font size=1 face=verdana>R3</td><td bgcolor=#FF6633><font size=1 face=verdana>R4</td><td bgcolor=#FF6633><font size=1 face=verdana>R5</td></tr>"; echo "<tr><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td></tr>"; echo "<tr><td bgcolor=#FF6633><font size=1 face=verdana>S1</td><td bgcolor=#FF6633><font size=1 face=verdana>S2</td><td bgcolor=#FF6633><font size=1 face=verdana>S3</td><td bgcolor=#FF6633><font size=1 face=verdana>S4</td><td bgcolor=#FF6633><font size=1 face=verdana>S5</td></tr>"; echo "<tr><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td><td bgcolor=#FF6633><font size=1 face=verdana></td></tr>"; echo "</table>"; echo "<br><br>"; function findClosest($sortedArray,$value) { $numberOfElements = count($sortedArray); $middle = floor($numberOfElements/2); if($sortedArray[$middle] == $value || $numberOfElements == 1) return $sortedArray[$middle]; elseif($sortedArray[$middle] < $value) { #upperhalf $half = array_slice($sortedArray,$middle); } else { #lowerhalf $half = array_slice($sortedArray,0,$middle); } $closestHalf = findClosest($half,$value); return (abs($value - $sortedArray[$middle]) < abs($value - $closestHalf)) ? $sortedArray[$middle] : $closestHalf; } $sortedArray = array($value_one_fin,$value_two_fin,$value_three_fin,$value_four_fin,$value_five_fin,$value_six_fin,$value_seven_fin,$value_eight_fin,$value_nine_fin,$value_ten_fin,$value_eleven_fin,$value_twelve_fin,$value_thirteen_fin,$value_fourteen_fin,$value_fifteen_fin,$value_sixteen_fin,$value_seventeen_fin,$value_eighteen_fin,$value_nineteen_fin,$value_twenty_fin,$value_twentyone_fin,$value_twentytwo_fin,$value_twentythree_fin,$value_twentyfour_fin); $result=findClosest($sortedArray,$num1); echo $result ; echo "<table cellpadding='5' cellspacing='2' border='0'>"; echo "<tr><td bgcolor=#FF6633><font size=1 face=verdana>Recomendations</td></tr>"; echo "<tr><td bgcolor=#FF6633><font size=1 face=verdana>Buy At/Above ";if ($num1>$result) {echo "$result ";}if ($num1=$result) {echo "$result ";}if ($num1<$result) {echo "$result ";}echo "for Targets"; if ($result<$value_one_fin){echo " $value_one_fin,";} if ($result<$value_two_fin){echo " $value_two_fin,";} if ($result<$value_three_fin){echo " $value_three_fin,";} if ($result<$value_four_fin){echo " $value_four_fin,";} if ($result<$value_five_fin){echo " $value_five_fin,";} if ($result<$value_six_fin){echo " $value_six_fin,";} if ($result<$value_seven_fin){echo " $value_seven_fin,";} if ($result<$value_eight_fin){echo " $value_eight_fin,";} if ($result<$value_nine_fin){echo " $value_nine_fin,";} if ($result<$value_ten_fin){echo " $value_ten_fin,";} if ($result<$value_eleven_fin){echo " $value_eleven_fin,";} if ($result<$value_twelve_fin){echo " $value_twelve_fin,";} if ($result<$value_thirteen_fin){echo " $value_thirteen_fin,";} if ($result<$value_fourteen_fin){echo " $value_fourteen_fin,";} if ($result<$value_fifteen_fin){echo " $value_fifteen_fin,";} if ($result<$value_sixteen_fin){echo " $value_sixteen_fin,";} if ($result<$value_seventeen_fin){echo " $value_seventeen_fin,";} if ($result<$value_eighteen_fin){echo " $value_eighteen_fin,";} if ($result<$value_nineteen_fin){echo " $value_nineteen_fin,";} if ($result<$value_twenty_fin){echo " $value_twenty_fin,";} if ($result<$value_twentyone_fin){echo " $value_twentyone_fin,";} if ($result<$value_twentytwo_fin){echo " $value_twentytwo_fin,";} if ($result<$value_twentythree_fin){echo " $value_twentythree_fin,";} if ($result<$value_twentyfour_fin){echo " $value_twentyfour_fin";} echo "</td></tr>"; echo "<tr><td bgcolor=#FF6633><font size=1 face=verdana>Sell At/Below ";if ($num1<$result) {echo "$result ";}if ($num1=$result) {echo "$result ";}if ($num1>$result) {echo "$result ";}echo "for Targets"; if ($result>$value_twentyfour_fin){echo " $value_twentyfour_fin";} if ($result>$value_twentythree_fin){echo " $value_twentythree_fin,";} if ($result>$value_twentytwo_fin){echo " $value_twentytwo_fin,";} if ($result>$value_twentyone_fin){echo " $value_twentyone_fin,";} if ($result>$value_twenty_fin){echo " $value_twenty_fin,";} if ($result>$value_nineteen_fin){echo " $value_nineteen_fin,";} if ($result>$value_eighteen_fin){echo " $value_eighteen_fin,";} if ($result>$value_seventeen_fin){echo " $value_seventeen_fin,";} if ($result>$value_sixteen_fin){echo " $value_sixteen_fin,";} if ($result>$value_fifteen_fin){echo " $value_fifteen_fin,";} if ($result>$value_fourteen_fin){echo " $value_fourteen_fin,";} if ($result>$value_thirteen_fin){echo " $value_thirteen_fin,";} if ($result>$value_twelve_fin){echo " $value_twelve_fin,";} if ($result>$value_eleven_fin){echo " $value_eleven_fin,";} if ($result>$value_ten_fin){echo " $value_ten_fin,";} if ($result>$value_nine_fin){echo " $value_nine_fin,";} if ($result>$value_eight_fin){echo " $value_eight_fin,";} if ($result>$value_seven_fin){echo " $value_seven_fin,";} if ($result>$value_six_fin){echo " $value_six_fin,";} if ($result>$value_five_fin){echo " $value_five_fin,";} if ($result>$value_four_fin){echo " $value_four_fin,";} if ($result>$value_three_fin){echo " $value_three_fin,";} if ($result>$value_two_fin){echo " $value_two_fin,";} if ($result>$value_one_fin){echo " $value_one_fin";} echo "</td></tr>"; echo "</table>"; ?> </center> </body> </html> this code is for gann squre of nine when i enter say 50 it should give me Recommendation: Buy at / above: 50.76 Targets: 52.53 - 54.36 - 56.22 - 58.11 Stoploss : 49 Sell at / below: 49 Targets: 47.28 - 45.58 - 43.91 - 42.27 Stoploss : 50.76 but im getting Recomendations Buy At/Above 50.77 for Targets 52.56, 54.39, 56.25, 58.14, 60.06, 62.02, 64, 66.02, 68.06, 70.14, 72.25, 74.39, 76.56, 78.77, 81 Sell At/Below 50.77 for Targets 49, 47.27, 45.56, 43.89, 42.25, 40.64, 39.06, 37.52 if i enter 100 i should get Recommendation: Buy at / above: 102.51 Targets: 105 - 107.58 - 110.19 - 112.83 Stoploss : 100 Sell at / below: 100 Targets: 97.56 - 95.11 - 92.68 - 90.29 Stoploss : 102.51 but i get Recomendations Buy At/Above 100 for Targets 102.52, 105.06, 107.64, 110.25, 112.89, 115.56, 118.27, 121 Sell At/Below 100 for Targets 97.52, 95.06, 92.64, 90.25, 87.89, 85.56, 83.27, 81, 78.77, 76.56, 74.39, 72.25, 70.14, 68.06, 66.02 forget the accuracy of the decimals but i want to display the result in this manner Recommendation: Buy at / above: 102.51 Targets: 105 - 107.58 - 110.19 - 112.83 Stoploss : 100 Sell at / below: 100 Targets: 97.56 - 95.11 - 92.68 - 90.29 Stoploss : 102.51 can some one help me Quote Link to comment https://forums.phpfreaks.com/topic/269593-desperate-help-needed-with-this-code/ Share on other sites More sharing options...
ignace Posted October 17, 2012 Share Posted October 17, 2012 Please keep it to one topic: http://forums.phpfreaks.com/topic/265698-gann-square-of-nine/ Quote Link to comment https://forums.phpfreaks.com/topic/269593-desperate-help-needed-with-this-code/#findComment-1385849 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.