Exemplo n.º 1
0
function get_most_hit_sp($symbol, $current_date)
{
    $begin_date = getPrevious60Days($current_date);
    $swingArray = array();
    $min_spl_row = array();
    $min_spl = 100000000000;
    $swingArray = generate_swing_points($symbol, $begin_date, $current_date);
    $arrayLen = count($swingArray);
    for ($x = 0; $x < $arrayLen; $x++) {
        if ($swingArray[$x]['type'] == "SPH") {
            $sphUpperBound = $swingArray[$x]['price'] + $swingArray[$x]['ATR'];
            $sphLowerBound = $swingArray[$x]['price'] - $swingArray[$x]['ATR'];
            for ($i = 0; $i < $arrayLen; $i++) {
                if ($swingArray[$i]['type'] == "SPH") {
                    if ($swingArray[$i]['price'] > $sphLowerBound && $sphUpperBound > $swingArray[$i]['price']) {
                        $swingArray[$i]['count'] = $swingArray[$i]['count'] + 1;
                    }
                }
            }
        } else {
            if ($swingArray[$x]['type'] == "SPL") {
                $splUpperBound = $swingArray[$x]['price'] + $swingArray[$x]['ATR'];
                $splLowerBound = $swingArray[$x]['price'] - $swingArray[$x]['ATR'];
                for ($i = 0; $i < $arrayLen; $i++) {
                    if ($swingArray[$i]['type'] == "SPL") {
                        if ($swingArray[$i]['price'] > $splLowerBound && $splUpperBound > $swingArray[$i]['price']) {
                            $swingArray[$i]['count'] = $swingArray[$i]['count'] + 1;
                        }
                    }
                }
            }
        }
    }
    $max_hit_sph = array();
    $max_hit_sph['count'] = 0;
    for ($y = 0; $y < $arrayLen; $y++) {
        if ($swingArray[$y]['type'] == "SPH") {
            if ($swingArray[$y]['count'] > $max_hit_sph['count']) {
                $max_hit_sph = $swingArray[$y];
            } else {
                if ($swingArray[$y]['count'] == $max_hit_sph['count'] && $swingArray[$y]['price'] > $max_hit_sph['price']) {
                    $max_hit_sph = $swingArray[$y];
                }
            }
        }
        if ($swingArray[$y]['type'] == "SPL") {
            if ($swingArray[$y]['count'] > $max_hit_spl['count']) {
                $max_hit_spl = $swingArray[$y];
            } else {
                if ($swingArray[$y]['count'] == $max_hit_spl['count'] && $swingArray[$y]['price'] < $max_hit_spl['price']) {
                    $max_hit_spl = $swingArray[$y];
                }
            }
        }
    }
    print " MAX SPH: ";
    print $max_hit_sph['price'];
    print " Type: ";
    print $max_hit_sph['type'];
    print " count: ";
    print $max_hit_sph['count'];
    print " MAX SPL: ";
    print $max_hit_spl['price'];
    print " Type: ";
    print $max_hit_spl['type'];
    print " count: ";
    print $max_hit_spl['count'];
    return $swingArray;
}
Exemplo n.º 2
0
function populate_swing_points($symbol, $end_date, $start_date, $time_frame)
{
    $swing_point_table = "sw_swing_points";
    $query = "";
    $dateString = "";
    $spArray = array();
    if (!$start_date) {
        $start_date = getPrevious60Days($end_date);
    }
    //print "symbol: $symbol start date: $start_date end date: $end_date time frame: $time_frame \n";
    $spArray = generate_swing_points($symbol, $start_date, $end_date, $time_frame);
    $arrayLen = count($spArray);
    for ($x = 0; $x < $arrayLen; $x++) {
        $query = "insert into " . $swing_point_table . " (symbol, trade_date, type, price, ATR, time_frame) ";
        $query .= "values ('" . $symbol . "', '" . $spArray[$x]['date_string'] . "', '" . $spArray[$x]['type'] . "', " . $spArray[$x]['price'] . ", " . $spArray[$x]['ATR'] . ", '" . $time_frame . "') ";
        $query .= "ON DUPLICATE KEY UPDATE symbol = '" . $symbol . "', trade_date='" . $spArray[$x]['date_string'] . "', type='" . $spArray[$x]['type'] . "', price=" . $spArray[$x]['price'] . ", ATR=" . $spArray[$x]['ATR'] . ", time_frame='" . $time_frame . "'";
        $query = stripslashes($query);
        $result = queryMysql($query);
    }
}
Exemplo n.º 3
0
     $arrayLen = count($swingArray);
     echo json_encode($swingArray);
 } else {
     if ($_GET['action'] == 'test_generate_swing_points') {
         $symbol = $_GET['symbol'];
         $start_date = $_GET['start_date'];
         $end_date = $_GET['end_date'];
         $pid = $_GET['portfolio_id'];
         if (!$end_date) {
             $end_date = date("Y-m-d");
         }
         if (!$pid) {
             $pid = 1;
         }
         $swingArray = array();
         $swingArray = generate_swing_points($symbol, $start_date, $end_date, $pid);
         $arrayLen = count($swingArray);
         echo json_encode($swingArray);
     } else {
         if ($_GET['action'] == 'test_generate_swing_points_and_trends') {
             $symbol = $_GET['symbol'];
             $start_date = $_GET['start_date'];
             $end_date = $_GET['end_date'];
             $pid = $_GET['portfolio_id'];
             if (!$end_date) {
                 $end_date = date("Y-m-d");
             }
             if (!$pid) {
                 $pid = 1;
             }
             $swingArray = array();