Esempio n. 1
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);
     }
 }