private function updateHoldings() { $holdings = new holdings(); $now = date('Y-m-d H:i:s'); while ($holdings->loadNextAll()) { $last_action = $holdings->get_variable('holdings_last_action'); $action = $last_action; $last = floatval($holdings->get_variable('last')); $high = floatval($holdings->get_variable('last_high')); $low = floatval($holdings->get_variable('last_low')); // check to make sure we didn't just zone for testing the ticker information $origDate = $holdings->get_variable('holdings_orig_date'); $diff = (strtotime($now) - (strtotime($origDate) + 60 * updater::HIGH_MINUTE_WINDOW)) / 60; if ($diff < 0) { $high = $last; } if ($high <= 0) { $high = $last; } if ($low <= 0) { $low = $last; } $symbol = $holdings->get_variable('ticker_symbol'); $tId = $holdings->get_variable('ticker_id'); //$t0 = floatval($holdings->get_variable('holdings_t0')); $t1 = floatval($holdings->get_variable('holdings_t1')); $t2 = floatval($holdings->get_variable('holdings_t2')); $t3 = floatval($holdings->get_variable('holdings_t3')); $t1Marked = $holdings->get_variable('holdings_t1_marked'); $t2Marked = $holdings->get_variable('holdings_t2_marked'); $t3Marked = $holdings->get_variable('holdings_t3_marked'); $stopType = $holdings->get_variable('holdings_stop_type'); $stopPrice = $holdings->get_variable('holdings_stop_price'); $topPrice = $holdings->get_variable('holdings_top_price'); $origPrice = $holdings->get_variable('holdings_orig_price'); $hId = $holdings->get_variable('holdings_id'); $tradeType = $holdings->get_variable('holdings_tradetype'); $newHolding = new holdings(); if ($tradeType == SHORT_TRADE) { if (!$t1Marked && ($last <= $t1 || $low <= $t1)) { //"SELL #1"; echo "\n\n\nSHORT BUY 1 and send tweet!"; $action = SELL1; $actionPrice = $t1; $newHolding->set_variable('holdings_t1_marked', 1); // update sell price of all holdings with this ticker_id watchlist::removeTickerHitT1($tId); //holdings::updateTickerSellPrices($tId, $origPrice); highlights::holdingsHighlight($hId, H_T1, 0, highlights::EVENT_START_DAY); } else { if (!$t2Marked && ($last <= $t2 || $low <= $t2)) { //"SELL #2"; echo "\n\n\nSHORT BUY2 and send tweet!"; $action = SELL2; $actionPrice = $t2; $newHolding->set_variable('holdings_t2_marked', 1); holdings::updateTickerSellPrices($tId, $t1); highlights::holdingsHighlight($hId, H_T2, 0, highlights::EVENT_START_DAY); } else { if (!$t3Marked && ($last <= $t3 || $low <= $t3)) { //"SELL #3"; echo "\n\n\nSELL 3 and send tweet!"; $actionPrice = $t3; $action = SELL3; $newHolding->set_variable('holdings_t3_marked', 1); holdings::updateTickerSellPrices($tId, $t3); highlights::holdingsHighlight($hId, H_T3, 0, highlights::EVENT_START_DAY); } else { if (!$t3Marked && $last >= $stopPrice) { if ($last_action != WARNING && !IsAbandoned($last_action)) { //"WARNING"; echo "\n\n\nWARNING and send tweet!"; $action = WARNING; $actionPrice = $stopPrice; } } } } } if ($action != $last_action) { $newHolding->set_variable('holdings_id', $hId); $newHolding->set_variable('holdings_last_action', $action); $newHolding->update(); // Add a transaction to the transaction table holdings::CreateNewTransaction($hId, $tradeType, $actionPrice, $action); } } else { if ($tradeType == LONG_TRADE) { if (!$t1Marked && ($last >= $t1 || $high >= $t1)) { //"SELL #1"; echo "\n\n\nSELL 1 and send tweet!"; $action = SELL1; $actionPrice = $t1; $newHolding->set_variable('holdings_t1_marked', 1); $newHolding->set_variable('holdings_stop_price', $origPrice); // update sell price of all holdings with this ticker_id watchlist::removeTickerHitT1($tId); //holdings::updateTickerSellPrices($tId, $origPrice); highlights::holdingsHighlight($hId, H_T1, 0, highlights::EVENT_START_DAY); } else { if (!$t2Marked && ($last >= $t2 || $high >= $t2)) { //"SELL #2"; echo "\n\n\nSELL 2 and send tweet!"; $action = SELL2; $actionPrice = $t2; $newHolding->set_variable('holdings_t2_marked', 1); holdings::updateTickerSellPrices($tId, $t1); highlights::holdingsHighlight($hId, H_T2, 0, highlights::EVENT_START_DAY); } else { if (!$t3Marked && ($last >= $t3 || $high >= $t3)) { //"SELL #3"; echo "\n\n\nSELL 3 and send tweet!"; $action = SELL3; $actionPrice = $t3; $newHolding->set_variable('holdings_t3_marked', 1); holdings::updateTickerSellPrices($tId, $t2); highlights::holdingsHighlight($hId, H_T3, 0, highlights::EVENT_START_DAY); } else { if ($last <= $stopPrice) { if ($last_action != WARNING && !IsAbandoned($last_action)) { //"WARNING"; echo "\n\n\nWARNING and send tweet!"; $action = WARNING; $actionPrice = $stopPrice; } } } } } if ($action != $last_action) { $newHolding->set_variable('holdings_id', $hId); $newHolding->set_variable('holdings_last_action', $action); $newHolding->update(); // Add a transaction to the transaction table holdings::CreateNewTransaction($hId, $tradeType, $actionPrice, $action); } } else { if ($tradeType == REVERSAL_TRADE) { } else { $abandonPrice = $stopPrice; $hardStopPrice = $topPrice; switch ($tradeType) { case BREAKOUT_TRADE: if (!$t3Marked && ($last >= $t3 || $high >= $t3)) { $holdings->markTarget(3, $symbol, $last, true, $t3); } else { if ($last <= $hardStopPrice) { holdings::abandonHardStop($hId, ""); } else { if ($last <= $abandonPrice) { holdings::abandonPriceMet($hId, $abandonPrice); // if ($last_action != WARNING && !IsAbandoned($last_action)) { // //"WARNING"; // echo "\n\n\nWARNING and send tweet!"; // $action = WARNING; // $actionPrice = $abandonPrice; // $newHolding -> set_variable('holdings_id', $hId); // $newHolding -> set_variable('holdings_last_action', $action); // $newHolding -> update(); // // holdings::CreateNewTransaction($hId, $tradeType, $abandonPrice, $action); // } } } } break; case PULLBACK_TRADE: if (!$t1Marked && ($last >= $t1 || $high >= $t1)) { $holdings->markTarget(1, $symbol, $last, true, $t1); } else { if (!$t1Marked && $last <= $abandonPrice) { holdings::abandonPriceMet($hId, $abandonPrice); // if ($last_action != WARNING && !IsAbandoned($last_action)) { // //"WARNING"; // echo "\n\n\nWARNING and send tweet!"; // $action = WARNING; // $actionPrice = $abandonPrice; // $newHolding -> set_variable('holdings_id', $hId); // $newHolding -> set_variable('holdings_last_action', $action); // $newHolding -> update(); // // holdings::CreateNewTransaction($hId, $tradeType, $abandonPrice, $action); // } } } break; case BACKDRAFT_TRADE: if (!$t1Marked && ($last <= $t1 || $low <= $t1)) { $holdings->markTarget(1, $symbol, $last, true, $t1); } else { if (!$t1Marked && $last >= $abandonPrice) { holdings::abandonPriceMet($hId, $abandonPrice); // if ($last_action != WARNING && !IsAbandoned($last_action)) { // //"WARNING"; // echo "\n\n\nWARNING and send tweet!"; // $action = WARNING; // $actionPrice = $abandonPrice; // $newHolding -> set_variable('holdings_id', $hId); // $newHolding -> set_variable('holdings_last_action', $action); // $newHolding -> update(); // // holdings::CreateNewTransaction($hId, $tradeType, $abandonPrice, $action); // } } } break; case BREAKDOWN_TRADE: if (!$t3Marked && ($last <= $t3 || $high <= $t3)) { $holdings->markTarget(3, $symbol, $last, true, $t3); } else { if ($last >= $hardStopPrice) { holdings::abandonHardStop($hId, ""); } else { if ($last >= $abandonPrice) { holdings::abandonPriceMet($hId, $abandonPrice); // if ($last_action != WARNING && !IsAbandoned($last_action)) { // //"WARNING"; // echo "\n\n\nWARNING and send tweet!"; // $action = WARNING; // $actionPrice = $abandonPrice; // $newHolding -> set_variable('holdings_id', $hId); // $newHolding -> set_variable('holdings_last_action', $action); // $newHolding -> update(); // // holdings::CreateNewTransaction($hId, $tradeType, $abandonPrice, $action); // } } } } break; } } } } // OBSOLETE WITH THE NEW METHODS if ($action != $last_action) { $tweet = new tweet(); $updateEmail = new email(email::ADDRESSES_ALL_CHOSEN, $tradeType, $hId); $tweet->newTweet($tradeType, $action, $symbol, $actionPrice); $updateEmail->newEmail($tradeType, $action, $symbol, $actionPrice); } } }
$holdingItem = new holdings(); $holdingItem->set_variable('holdings_id', $holdingId); if ($holdingItem->load()) { $abandonDate = strtotime($holdingItem->get_variable('holdings_abandon_date')); $tickerId = $holdingItem->get_variable('holdings_ticker_id'); $ticker = new ticker(); $ticker->set_variable('ticker_id', $tickerId); if ($ticker->load()) { $tickerSymbol = $ticker->get_variable('ticker_symbol'); $last = $ticker->get_variable('last'); } else { $tickerSymbol = "ERROR"; } // Mark Targets if (isset($_GET['markTarget'])) { $holdingItem->markTarget($_GET['markTarget'], $tickerSymbol, $last); $holdingItem->load(); } // update with the post variables if (isset($_POST['origPrice'])) { if (isset($_POST['t0'])) { $holdingItem->set_variable('holdings_t0', floatval($_POST['t0'])); } if (isset($_POST['t1'])) { $holdingItem->set_variable('holdings_t1', floatval($_POST['t1'])); } if (isset($_POST['t2'])) { $holdingItem->set_variable('holdings_t2', floatval($_POST['t2'])); } if (isset($_POST['t3'])) { $holdingItem->set_variable('holdings_t3', floatval($_POST['t3']));