コード例 #1
0
 public static function addStochInfoAndCreate($ticker, $tid)
 {
     $parts = finance_google::retrieveSlowDAndParts($ticker);
     echo "\nUpdating history for " . $ticker . " TID:" . $tid;
     $tickerHistory = new ticker_history();
     $tickerHistory->set_variable('history_price', $parts['last']);
     $date = date("Y-m-d h:i:s", $parts['date']);
     $tickerHistory->set_variable('history_date', $date);
     $tickerHistory->set_variable('history_ticker_id', $tid);
     $tickerHistory->set_variable('history_lasthigh', $parts['high']);
     $tickerHistory->set_variable('history_lastlow', $parts['low']);
     $tickerHistory->set_variable('history_r1', $parts['r1']);
     $tickerHistory->set_variable('history_r2', $parts['r2']);
     $tickerHistory->set_variable('history_fastk', $parts['fastK']);
     $tickerHistory->set_variable('history_slowk', $parts['slowK']);
     $tickerHistory->set_variable('history_slowd', $parts['slowD']);
     $tickerHistory->createNew();
 }
コード例 #2
0
 private function updateStochStateMachine($hId, $tId, $symbol, $last, $stoch_action, $action)
 {
     $new_stoch_action = $stoch_action;
     $func = "";
     if ($stoch_action != STOCH_STATE_SELL3) {
         echo "\nTESTING STOCH MACHINE " . $symbol;
         $tickerHistory = new ticker_history();
         $tickerHistory->set_variable('history_ticker_id', $tId);
         if ($tickerHistory->loadLatest()) {
             $slowk = $tickerHistory->get_variable('history_slowk');
             $slowd = $tickerHistory->get_variable('history_slowd');
             switch ($stoch_action) {
                 case STOCH_PENDING:
                     if ($action == BUY && $slowk <= 20) {
                         // TEST 1 - set when slow K is below 20
                         $new_stoch_action = STOCH_STATE_BUY_WAIT;
                         $func = stoch_state_buy_wait;
                     }
                     break;
                 case STOCH_STATE_BUY_WAIT:
                     if ($slowk >= 20) {
                         // BUY NOW
                         $new_stoch_action = STOCH_STATE_BUY;
                         $func = stoch_state_buy;
                     }
                     break;
                 case STOCH_STATE_BUY:
                     if ($slowk >= 80 && $action == SELL1) {
                         $new_stoch_action = STOCH_STATE_SELL1_WAIT;
                         $func = stoch_state_sell_wait;
                     }
                     break;
                 case STOCH_STATE_SELL1:
                     if ($slowk >= 80 && $action == SELL2) {
                         $new_stoch_action = STOCH_STATE_SELL2_WAIT;
                         $func = stoch_state_sell_wait;
                     }
                     break;
                 case STOCH_STATE_SELL2:
                     if ($slowk >= 80 && $action == SELL3) {
                         $new_stoch_action = STOCH_STATE_SELL3_WAIT;
                         $func = stoch_state_sell_wait;
                     }
                     break;
                 case STOCH_STATE_SELL1_WAIT:
                 case STOCH_STATE_SELL2_WAIT:
                 case STOCH_STATE_SELL3_WAIT:
                     if ($slowk >= 80) {
                         if ($stoch_action == STOCH_STATE_SELL1_WAIT && $action == SELL2) {
                             $new_stoch_action = STOCH_STATE_SELL2_WAIT;
                             $func = stoch_state_sell_wait;
                         }
                         if ($stoch_action == STOCH_STATE_SELL2_WAIT && $action == SELL3) {
                             $new_stoch_action = STOCH_STATE_SELL3_WAIT;
                             $func = stoch_state_sell_wait;
                         }
                     } else {
                         if ($slowk <= 80) {
                             if ($stoch_action == STOCH_STATE_SELL1_WAIT) {
                                 $new_stoch_action = STOCH_STATE_SELL1;
                                 $func = stoch_state_sell;
                             } else {
                                 if ($stoch_action == STOCH_STATE_SELL2_WAIT) {
                                     $new_stoch_action = STOCH_STATE_SELL2;
                                     $func = stoch_state_sell;
                                 } else {
                                     if ($stoch_action == STOCH_STATE_SELL3_WAIT) {
                                         $new_stoch_action = STOCH_STATE_SELL3;
                                         $func = stoch_state_sell;
                                     }
                                 }
                             }
                         }
                     }
                     break;
             }
         }
     }
     if ($new_stoch_action != $stoch_action) {
         echo "\n" . $symbol . " UPDATING STOCH STATE MACHINE FROM " . $stoch_action . " TO " . $new_stoch_action;
         $newHolding = new holdings();
         $newHolding->set_variable('holdings_id', $hId);
         $newHolding->set_variable('holdings_stoch_action', $new_stoch_action);
         $newHolding->update();
         $tweetprivate = new tweetprivate();
         $tweetprivate->{$func}($symbol, $last, $new_stoch_action);
     }
 }