foreach ($row as $key => $value) { //$rowRet[] = $value; $ret[$i][$key] = $value; } //$ret[i] = $rowRet; $i++; } $ret2["dataset"] = $ret; echo json_encode($ret2); //exit; } elseif ($_GET['action'] == 'getCurrentTurtlePortfolio') { $query = $_GET['txtInputQuery']; $query = stripslashes($query); $result = queryMysql($query); $sightings = array(); $sightings = mysql_resultTo2DAssocArray_JGrid($result); echo json_encode($sightings); exit; } elseif ($_GET['action'] == 'calculateEndBalance') { $transactionList = array(); $beginBalance = 1000000; // get unique symbol from transaction table that has sell $query = "select symbol, trade_type, trade_date, shares, price from turtle_portfolio_transaction where portfolio_id = 1 order by trade_date asc "; $result = queryMysql($query); while ($data = mysql_fetch_row($result)) { if ($data[1] == 'BUY') { $beginBalance -= $data[3] * $data[4]; } else { $beginBalance += $data[3] * $data[4]; } }
$my_sql = "insert into turtle_s2_system (symbol, trade_date, trade_type, num_shares, "; $my_sql .= "price_paid, current_N, stop_loss, next_buy_point, stop_loss_type, cash_balance, buy_type) "; $my_sql .= "values ('" . $symbol . "', '" . $ph[$x]['trade_date'] . "', 'Sell', {$current_pos}, " . $stop_loss . ", "; $my_sql .= "{$current_N}, 0, 0, '{$stop_loss_type}', {$cash_balance}, '{$buy_signal}') "; $result = queryMysql($my_sql); $current_pos = 0; $pyramid_mode = 0; } } } $query = "select * from turtle_s2_system where symbol = '" . $symbol . "'"; $query .= " and stop_loss_type = '{$stop_loss_type}' and buy_type = '{$buy_signal}'"; $query = stripslashes($query); $result = queryMysql($query); $json_result = array(); $json_result = mysql_resultTo2DAssocArray_JGrid($result); echo json_encode($json_result); exit; } } function get_stop_loss($type, $current_stop, $close_price, $day_high, $day_low, $high_55, $high_20, $low_20, $ma_50, $ma_200, $ATR) { $stop = 0; if ($type == "ATR_1N") { $stop = $high_55 - $ATR; } else { if ($type == "ATR_2N") { $stop = $high_55 - 2 * $ATR; } else { if ($type == "8PCT") { $stop = $high_55 * 0.92;