function populate_stock_trend($symbol, $end_date, $start_date, $time_frame) { $stock_trend_table = "sw_stock_trend"; $query = ""; $dateString = ""; $trendArray = array(); $spArray = array(); if (!$start_date) { $start_date = getPrevious60Days($end_date); } $trendArray = generate_trends($symbol, $start_date, $end_date, $time_frame); $arrayLen = count($trendArray); for ($x = 0; $x < $arrayLen; $x++) { $query = "insert into " . $stock_trend_table . " (symbol, trade_date, price, trend, trend_strength, time_frame) "; $query .= "values ('" . $symbol . "', '" . $trendArray[$x]['date_string'] . "', " . $trendArray[$x]['price'] . ", '" . $trendArray[$x]['trend'] . "', " . $trendArray[$x]['strength'] . ", '" . $time_frame . "') "; $query .= "ON DUPLICATE KEY UPDATE symbol = '" . $symbol . "', trade_date='" . $trendArray[$x]['date_string'] . "', trend='" . $trendArray[$x]['trend'] . "', price=" . $trendArray[$x]['price'] . ", trend_strength=" . $trendArray[$x]['strength'] . ", time_frame='" . $time_frame . "'"; $query = stripslashes($query); $result = queryMysql($query); } }
function get_previous_trend($symbol, $current_date) { $stockRetArray = array(); $retArray = array(); $eachRow = array(); $lastSPHfound = 0; $lastSPLfound = 0; $begin_date = getPrevious60Days($current_date); $trendArray = array(); $previous_trend_array = array(); $previous_60_days = getPrevious60Days($current_date); $trendArray = generate_trends($symbol, $begin_date, $current_date); $trendLen = count($trendArray); $previous_trend_array = $trendArray[$trendLen - 2]; return $previous_trend_array; /* $swingArray = array(); $swingArray = generate_swing_points($symbol, $begin_date, $current_date); $arrayLen = count($swingArray); $count = $arrayLen; // while loop to find out which posistion the 2nd to last SPH and SPL occurs while ((!$lastSPHfound) || (!$lastSPLfound) ) { $last_sp_type = $swingArray[$count-1]['type']; if ($last_sp_type == 'SPH') { $lastSPHfound = 1; $lastSPHpos = $count; } else { $lastSPLfound = 1; $lastSPLpos = $count; } $count --; } $secondLastSPHfound = 0; $secondLastSPHpos = -1; $secondLastSPLfound = 0; $secondLastSPLpos = -1; $secondLastMaxSPH = 0; $secondLastMinSPL = 10000; while (((!$secondLastSPHfound) || (!$secondLastSPLfound)) && ($count >= 1)) { $second_last_sp_type = $swingArray[$count-1]['type']; print "date: "; print $swingArray[$count-1]['date']; print " type: "; print $swingArray[$count-1]['type']; print " SPH: "; print $swingArray[$count-1]['price']; print " SPL: "; print $swingArray[$count-1]['price']; print "\n"; if ($second_last_sp_type == 'SPH') { $secondLastSPHfound = 1; $secondLastSPHpos = $count; if ($swingArray[$count-1]['price'] > $secondLastMaxSPH) { $secondLastMaxSPH = $swingArray[$count-1]['price']; } } else { $secondLastSPLfound = 1; $secondLastSPLpos = $count; if ($swingArray[$count-1]['price'] < $secondLastMinSPL) { $secondLastMinSPL = $swingArray[$count-1]['price']; } } $count --; } print " final count: $count "; print "second last SPH pos: $secondLastSPHpos second last SPL pos: $secondLastSPLpos \n"; print " max SPH: $secondLastMaxSPH min SPL: $secondLastMinSPL \n"; $last_y = $swingArray[$arrayLen-2]['y']; $last_x = $swingArray[$arrayLen-2]['x']; $last_title = $swingArray[$arrayLen-2]['title']; print "last y: $last_y last x: $last_x last title: $last_title "; $last_sph_array = array(); $last_spl_array = array(); $last_sph_array = get_last_sph($symbol, $current_date); $last_sph = $last_sph_array[1]; $last_spl_array = get_last_spl($symbol, $current_date); $last_spl = $last_spl_array[1]; $query = "select close from price_history where symbol = '".$symbol."' and trade_date = '".$current_date."' "; $query= stripslashes($query); $result = queryMysql($query); while ($tmp_data = mysql_fetch_row($result)) { $current_price = $tmp_data[0] * 1 / 1; } if ($current_price > $last_sph) { return "bullish"; } else if ($current_price > $last_spl) { return "sideway"; } else { return "bearish"; } */ }