Jump to content

what is wrong with this code of mine


rohitb

Recommended Posts

what is wrong with this code of mine. i am getting warning messages

Warning: Division by zero in /home/rohitb/public_html/test/live nifty trend/trend.php on line 52

 

Warning: Division by zero in /home/rohitb/public_html/test/live nifty trend/trend.php on line 54

<Form name ="form1" Method ="POST" >
Enter Nifty Spot Price<INPUT TYPE = "TEXT" value="<?php echo $_POST['spotprice'] ?>" Name ="spotprice"/>
<INPUT TYPE = "Submit" Name = "getCallPut" VALUE = "Next->">
</form>

<?php 

if(isset($_POST['getCallPut'])) { 
callput(); 
} 

function callput() {

$spotPrice = 1.0 * $_POST['spotprice'];
if($spotPrice%100>=0 && $spotPrice%100<40){
            $callStrikePrice=floor($spotPrice/100)*100 + 100;
            $putStrikePrice=floor($spotPrice/100)*100 - 100;
            
        }else if($spotPrice%100 >=40 && $spotPrice%100<=60){
            $callStrikePrice=floor($spotPrice/100)*100 + 100;
            $putStrikePrice=floor($spotPrice/100)*100;
            
        }else{
            $callStrikePrice=floor($spotPrice/100)*100 + 200;
            $putStrikePrice=floor($spotPrice/100)*100;
            
        }
echo' <Form name ="form2" Method ="POST" >';
echo'Enter price for Nifty <input type="text" name="something" disabled="" style="border:none;width:40px;background-color:#000000;color:yellow;font-weight:bold;text-align:center" value="'.$callStrikePrice.'"/> CE <input type="text" name="callRate" size="10"><br><br>';
echo'Enter price for Nifty <input type="text" name="something1" disabled="" style="border:none;width:40px;background-color:#000000;color:yellow;font-weight:bold;text-align:center" value="'.$putStrikePrice.'"/> PE <input type="text" name="putRate" size="10">';
echo'<INPUT TYPE = "Submit" Name = "trend" VALUE = "Calculate Trend->">';
echo'</form>';  
                 }
 ?>

<?php

if(isset($_POST['trend'])) { 
trend(); 
} 

function trend(){
$callRate = 1.0 * $_POST['callRate'];
$putRate = 1.0 * $_POST['putRate'];
$actualCallRate = ceil(100*(((($callStrikePrice-$spotPrice)-($callStrikePrice-($callStrikePrice+$putStrikePrice)/2))/($callStrikePrice - $spotPrice)) + 1) * $callRate);
$actualPutRate = ceil(100.0 * (1 - (((($callStrikePrice+$putStrikePrice)/2.0 - $putStrikePrice) - ($spotPrice - $putStrikePrice))/($spotPrice - $putStrikePrice))) * $putRate);
$buyPercent = ceil(10000.0 * $actualCallRate/($actualCallRate + $actualPutRate));
$sellPercent =  ceil(10000.0 * $actualPutRate/($actualCallRate + $actualPutRate));
 
echo'The chances of Nifty Future going up is ' .$buyPercent/100.0.  ' % and going down is ' .$sellPercent/100.0. ' %';
if($buyPercent==$sellPercent){
            echo"<br/><h1 style='color:yellow'>TREND IS NEUTRAL</h1>";
        }else if($buyPercent>$sellPercent){
            echo"<br/><h1 style='color:green'>TREND IS UP</h1>";
        }else{
            echo"<br/><h1 style='color:red'>TREND IS DOWN</h1>";
        }   
        }              
?>

pls help me ...im trying to get some thing like this http://stocknews72.blogspot.in/p/stock-tips.html... how can i achieve this with above code

Edited by rohitb
Link to comment
Share on other sites

Variables defined outside a function (including in a different function) are not available inside the function. So trend() cannot use $callStrikePrice or $spotPrice or $putStrikePrice or any of the other variables that callput() defines.

 

Your script doesn't need those two functions. Put their code inline.

Edited by requinix
Link to comment
Share on other sites

Variables defined outside a function (including in a different function) are not available inside the function. So trend() cannot use $callStrikePrice or $spotPrice or $putStrikePrice or any of the other variables that callput() defines.

 

Your script doesn't need those two functions. Put their code inline.

can u help me with that

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.