function processBreakouts() { $holding = new holdings(); $holding->set_variable("holdings_abandon_hide", 0); $holding->set_variable("holdings_tradetype", BREAKOUT_TRADE); $symbols = array(); $hids = array(); while ($holding->loadNext()) { $hId = $holding->get_variable("holdings_id"); $tId = $holding->get_variable("holdings_ticker_id"); $abandon = $holding->get_variable("holdings_stop_price"); $ticker = new ticker(); $ticker->set_variable("ticker_id", $tId); if ($ticker->load()) { $symbol = strtoupper($ticker->get_variable("ticker_symbol")); echo "Symbol: " . $symbol . "\n"; $weeksAgo = strtotime("-32 days"); $historicalData = finance::retrieveHistorical($symbol, date("Ymd", $weeksAgo), date("Ymd"), 'daily'); $ATRCount = $ATRSum = 0; $count = sizeof($historicalData); // get the last 19 days of information for the average and add today on the end $i = min($count - 1, 19); for ($j = $i - 1; $j >= 0; $j--) { $today = $historicalData[$j]['date']; $yesterdaysClose = $historicalData[$i]['close']; $todayHigh = $historicalData[$j]['high']; $todayLow = $historicalData[$j]['low']; $todayClose = $historicalData[$j]['close']; echo "TEST - DATE=" . $today . " PrevDayClose=" . $yesterdaysClose . " DayHigh=" . $todayHigh . " DayLow=" . $todayLow; $finalATRVal = GetATR($yesterdaysClose, $todayHigh, $todayLow); $ATRSum += $finalATRVal; $ATRCount++; $i = $j; echo " FINAL=" . $finalATRVal . "\n"; } // ADD Today $yesterdaysClose = $todayClose; $todayHigh = $ticker->get_variable("today_high"); $todayLow = $ticker->get_variable("today_low"); $todayClose = $ticker->get_variable("last_close"); echo "TEST - DATE=TODAY PrevDayClose=" . $yesterdaysClose . " DayHigh=" . $todayHigh . " DayLow=" . $todayLow; $finalATRVal = GetATR($yesterdaysClose, $todayHigh, $todayLow); echo " FINAL=" . $finalATRVal . "\n"; $ATRSum += $finalATRVal; $ATRCount++; $ATRAvg = round($ATRSum / $ATRCount, 2); echo $symbol . " ATR=" . $ATRAvg . " todayClose=" . $todayClose . "\n"; $newAbandon = round($todayClose - 2 * $ATRAvg, 2); echo "Comparing Abandons: Old=" . $abandon . " New=" . $newAbandon . "\n"; if ($newAbandon > $abandon) { echo "NEW ABANDON PRICE SET TO " . $newAbandon . "\n"; $holding->set_variable("holdings_stop_price", $newAbandon); $holding->update(); // highlight the abandon price highlights::holdingsHighlight($hId, H_ABANDON, 0, highlights::EVENT_START_DAY); } echo "\n\n\n\n"; } } }
continue; } if ($action == ABANDON_AT_CLOSE) { continue; } echo "\nAdding Ticker Symbol for " . $symbol . " to price update list.\n"; array_push($symbols, strtoupper($symbol)); array_push($hids, $hid); } //$results = finance_google::retrieveCurrentPrice($symbols); $results = finance::retrieveCurrentPrice($symbols, "o"); $updateHolding = new holdings(); foreach ($hids as $updateHid) { $updateHolding->reset_query(); $updateHolding->set_variable("holdings_id", $updateHid); if ($updateHolding->load()) { $symbol = strtoupper($updateHolding->get_variable('holdings_ticker_symbol')); $tid = $holding->get_variable('holdings_ticker_id'); $price = floatval($results[$symbol]); if ($price > 0) { $updateHolding->set_variable("holdings_stop_price", $price); echo "\n<br>Changing Stop Price for " . $symbol . " to " . $price . ". Opening Price after Abandon.\n<br>"; $updateHolding->update(); } else { $str = "holdings_abandon_date LIKE '" . date("Y-m-d") . "%'"; echo "\nNOT Changing Stop Price for " . $symbol . " to " . $price . ". Opening Price after Abandon. SOMETHiNG WRONG!! " . $str . "\n<br>"; } } } echo "\ncomplete HOLDINGS abandon update"; }
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); } }
if ($origAbandon != $newAbandon) { $holdingItem->set_variable('holdings_stop_price', $newAbandon); highlights::holdingsHighlight($holdingId, H_ABANDON, 0, highlights::EVENT_START_DAY); } // Check if we have to update the abandon price and add highlight $origHardStop = $holdingItem->get_variable('holdings_top_price'); $newHardStop = floatval($_POST['hardStopPrice']); if ($origHardStop != $newHardStop) { $holdingItem->set_variable('holdings_top_price', $newHardStop); highlights::holdingsHighlight($holdingId, H_HARDSTOP, 0, highlights::EVENT_START_DAY); } $holdingItem->set_variable('holdings_orig_date', $_POST['origdate']); if ($abandonDate != null) { $holdingItem->set_variable('holdings_abandon_date', $_POST['abandondate']); } $holdingItem->update(); } $origDate = strtotime($holdingItem->get_variable('holdings_orig_date')); $action = $holdingItem->get_variable('holdings_last_action'); $t0 = $holdingItem->get_variable('holdings_t0'); $t1 = $holdingItem->get_variable('holdings_t1'); $t2 = $holdingItem->get_variable('holdings_t2'); $t3 = $holdingItem->get_variable('holdings_t3'); $hitT0 = $holdingItem->get_variable('holdings_t0_marked'); $hitT1 = $holdingItem->get_variable('holdings_t1_marked'); $hitT2 = $holdingItem->get_variable('holdings_t2_marked'); $hitT3 = $holdingItem->get_variable('holdings_t3_marked'); $tip = $holdingItem->get_variable('holdings_tooltip'); $origPrice = $holdingItem->get_variable('holdings_orig_price'); $abandonPrice = $holdingItem->get_variable('holdings_stop_price'); $hardStopPrice = $holdingItem->get_variable('holdings_top_price');
function startOfDayUpdate() { // Update the highlights with start of day trigger highlights::eventTrigger(highlights::EVENT_START_DAY); // Make sure no expired users get emails. user::resetAllExpiredEmailUpdates(); // Delete previously deleted watchlists watchlist::pruneDeletedWatchlistIds(); watchlist::deleteZonedTickers(BREAKOUT_TRADE); watchlist::deleteZonedTickers(BREAKDOWN_TRADE); watchlist::deleteZonedTickers(LONG_TRADE); watchlist::deleteZonedTickers(SHORT_TRADE); watchlist::deleteZonedTickers(PULLBACK_TRADE); watchlist::deleteZonedTickers(BACKDRAFT_TRADE); $deleteIds = array(); $deleteHoldingsIds = array(); $holdings = new holdings(); while ($holdings->loadNext()) { $hid = $holdings->get_variable("holdings_id"); $tid = $holdings->get_variable("holdings_ticker_id"); $action = $holdings->get_variable("holdings_last_action"); $hidden = $holdings->get_variable("holdings_abandon_hide"); $tradeType = $holdings->get_variable("holdings_tradetype"); if (IsAbandoned($action) && $hidden == 0) { $deleteHoldingsIds[] = $hid; echo "\nDELETING Holdings ID " . $hid . " because it was abandoned"; $watchlist = new watchlist(); $watchlist->set_variable("watchlist_ticker_id", $tid); $watchlist->set_variable("watchlist_tradetype", $tradeType); while ($watchlist->loadNext()) { $deleteIds[] = $watchlist->get_variable("watchlist_id"); } } else { if (($tradeType == REVERSAL_TRADE || $tradeType == SHORT_TRADE) && $hidden == 0) { $hitT3 = $holdings->get_variable("holdings_t3_marked"); if ($hitT3 == 1) { $deleteHoldingsIds[] = $hid; echo "\nDELETING Holdings ID " . $hid . " because topped reversal/shorts"; $watchlist = new watchlist(); $watchlist->set_variable("watchlist_ticker_id", $tid); $watchlist->set_variable("watchlist_tradetype", $tradeType); while ($watchlist->loadNext()) { $deleteIds[] = $watchlist->get_variable("watchlist_id"); } } } else { if (($tradeType == BACKDRAFT_TRADE || $tradeType == PULLBACK_TRADE) && $hidden == 0) { $hitT1 = $holdings->get_variable("holdings_t1_marked"); if ($hitT1 == 1) { $deleteHoldingsIds[] = $hid; echo "\nDELETING Holdings ID " . $hid . " because topped pullback/backdraft"; $watchlist = new watchlist(); $watchlist->set_variable("watchlist_ticker_id", $tid); $watchlist->set_variable("watchlist_tradetype", $tradeType); while ($watchlist->loadNext()) { $deleteIds[] = $watchlist->get_variable("watchlist_id"); } } } } } } foreach ($deleteIds as $wid) { echo "\n\n\nDELETING Watchlist ID " . $wid . " because it is abandoned or topped out reversal/shorts"; $watchlist = new watchlist(); $watchlist->set_variable('watchlist_id', $wid); $watchlist->delete(); } foreach ($deleteHoldingsIds as $hid) { echo "\n\n\nDELETING Holdings ID " . $hid . " because it is abandoned or topped out reversal/shorts"; $holdings = new holdings(); $holdings->set_variable('holdings_id', $hid); // instead of deleting, mark it as hidden if ($holdings->load()) { $tickerInfo = new ticker(); $tickerInfo->set_variable('ticker_id', $holdings->get_variable('holdings_ticker_id')); if ($tickerInfo->load()) { $holdings->set_variable('holdings_ticker_symbol', $tickerInfo->get_variable('ticker_symbol')); } $holdings->set_variable('holdings_abandon_hide', 1); $holdings->set_variable('holdings_abandon_date', date('Y-m-d H:i:s')); $holdings->update(); } // replace this //$holdings->delete(); } // delete the tickers that are no longer used. $ticker = new ticker(); $deleteIds = array(); while ($ticker->loadNext()) { $tid = $ticker->get_variable("ticker_id"); // reset the high and low $last = $ticker->get_variable("last"); $ticker->set_variable("today_high", $last); $ticker->set_variable("today_low", $last); $ticker->set_variable("last_high", $last); $ticker->set_variable("last_low", $last); $ticker->update(); $watchlist = new watchlist(); $watchlist->set_variable("watchlist_ticker_id", $tid); if (!$watchlist->load()) { $holding = new holdings(); $holding->set_variable("holdings_ticker_id", $tid); $holding->set_variable("holdings_abandon_hide", 0); if (!$holding->load()) { $deleteIds[] = $tid; } } } foreach ($deleteIds as $tid) { echo "\n\n\nDELETING TICKER ID " . $tid . " because it is no longer used"; $ticker = new ticker(); $ticker->set_variable('ticker_id', $tid); $ticker->delete(); } $tickerHist = new ticker_history(); while ($tickerHist->loadNextDistinctTicker()) { $ticker = new ticker(); $tid = $tickerHist->get_variable('history_ticker_id'); $ticker->set_variable('ticker_id', $tid); if (!$ticker->load()) { echo "\nTicker History Cleanup:: Removing " . $tid . "\n"; ticker_history::removeTickerHistory($tid); } } // try to reconcile any payments that are not currently known. // now doing this whenever a payment is received. //payment_info::reconcileAllPaymentUids(); }
function endOfDayUpdate() { // Update the highlights with end of day trigger highlights::eventTrigger(highlights::EVENT_END_DAY); // Abandon the stocks that were marked abandon during the day abandonNowStocks(); // update the close price of the ticker $ticker = new ticker(); while ($ticker->loadNext()) { $last = $ticker->get_variable('last'); $ticker->set_variable('last_close', $last); $ticker->update(); } /// update the holdings $holdings = new holdings(); while ($holdings->loadNextAll()) { $last_action = $holdings->get_variable('holdings_last_action'); if (IsAbandoned($last_action)) { continue; } $last = floatval($holdings->get_variable('last')); $low = floatval($holdings->get_variable('today_low')); $t3 = floatval($holdings->get_variable('holdings_t3')); $tId = $holdings->get_variable('ticker_id'); $symbol = $holdings->get_variable('ticker_symbol'); $stopType = $holdings->get_variable('holdings_stop_type'); $stopPrice = floatval($holdings->get_variable('holdings_stop_price')); $hId = $holdings->get_variable('holdings_id'); $initSellPriceSet = $holdings->get_variable('holdings_init_sell_price_set'); $isT1Marked = $holdings->get_variable('holdings_t1_marked'); $tradeType = $holdings->get_variable("holdings_tradetype"); echo "\n\n\nChecking " . $hId . " ticker " . $tId . " against \$" . $last; $action = NONE; switch ($tradeType) { case BREAKDOWN_TRADE: case SHORT_TRADE: $doAbandon = $last > $stopPrice; break; case BACKDRAFT_TRADE: $doAbandon = $last > $stopPrice && !$isT1Marked; break; case LONG_TRADE: case REVERSAL_TRADE: case BREAKOUT_TRADE: $doAbandon = $last < $stopPrice; break; case PULLBACK_TRADE: $doAbandon = $last < $stopPrice && !$isT1Marked; break; } if ($doAbandon) { $tweet = new tweet(); $abandonEmail = new email(email::ADDRESSES_SMS_ONLY, $tradeType, $hId); $action = ABANDON; $tweet->newTweet($tradeType, $action, $symbol, $stopPrice); $abandonEmail->newEmail($tradeType, $action, $symbol, $stopPrice); $newHolding = new holdings(); $newHolding->set_variable('holdings_id', $hId); $newHolding->set_variable('holdings_last_action', $action); $newHolding->set_variable('holdings_abandon_marked', 1); $newHolding->update(); // Add a transaction to the transaction table holdings::CreateNewTransaction($hId, $tradeType, $stopPrice, $action); } if ($action != ABANDON && $last_action == WARNING) { // reset WARNING list $t1Marked = $holdings->get_variable('holdings_t1_marked'); $t2Marked = $holdings->get_variable('holdings_t2_marked'); $t3Marked = $holdings->get_variable('holdings_t3_marked'); if ($t3Marked) { $next_action = SELL3; } else { if ($t2Marked) { $next_action = SELL2; } else { if ($t1Marked) { $next_action = SELL1; } else { $next_action = BUY; } } } $newHoldings = new holdings(); $newHoldings->set_variable('holdings_id', $hId); $newHoldings->set_variable('holdings_last_action', $next_action); echo "\nREPLACE WARNING WITH LAST ACTION\n"; echo $newHoldings->debug(); $newHoldings->update(); } } // end of day, check to see if we are out of zone /* $watchlist = new watchlist(); $watchlist->set_variable('watchlist_is_zoned', 1); $deleteIds = array(); while ($watchlist->loadNext()){ $tradeType = $watchlist->get_variable("watchlist_tradetype"); $ticker = new ticker(); $ticker->set_variable('ticker_id', $watchlist->get_variable('watchlist_ticker_id')); if ($ticker->load()){ if ($tradeType==SHORT_TRADE){ $high = floatval($ticker->get_variable('today_high')); $bottom = floatval($watchlist->get_variable('watchlist_bottom')); if ($high < $bottom){ $watchlistId = floatval($watchlist->get_variable('watchlist_id')); $deleteIds[] = $watchlistId; } }else if ($tradeType==LONG_TRADE){ $low = floatval($ticker->get_variable('today_low')); $top = floatval($watchlist->get_variable('watchlist_top')); if ($low > $top){ $watchlistId = floatval($watchlist->get_variable('watchlist_id')); $deleteIds[] = $watchlistId; } }else if ($tradeType==REVERSAL_TRADE){ $low = floatval($ticker->get_variable('today_low')); $top = floatval($watchlist->get_variable('watchlist_top')); if ($low > $top){ $watchlistId = floatval($watchlist->get_variable('watchlist_id')); $deleteIds[] = $watchlistId; } } } } foreach ($deleteIds as $wId){ echo "\n\n\nDELETING WATCHLIST ID ". $wId. " because it was higher than top all day"; $watchlist = new watchlist(); $watchlist->set_variable('watchlist_id', $wId); $watchlist->delete(); } * */ }
if ($abandon != $oldAbandon) { $holding->set_variable('holdings_stop_price', $abandon); highlights::holdingsHighlight($holdId, H_ABANDON, 0, highlights::EVENT_START_DAY); $isEdited = true; } } if (isset($_POST['hardstop_' . $holdId])) { $hardstop = floatval($_POST['hardstop_' . $holdId]); if ($hardstop != $oldHard) { $holding->set_variable('holdings_top_price', $hardstop); highlights::holdingsHighlight($holdId, H_HARDSTOP, 0, highlights::EVENT_START_DAY); $isEdited = true; } } if ($isEdited) { $holding->update(); } } $counter++; } $holdings = array(); $holdings = ticker_group_info::retrieveHoldingsArray($tradeType); ?> <!DOCTYPE html> <html> <head> <title>BioBounce.com</title> <meta name = "keywords" content = "biotech, stock, market, swing trading, stock trading" />
public static function ADMIN_MarkAbandoned($holding_id) { $updateHolding = new holdings(); $updateHolding->set_variable('holdings_id', $holding_id); if ($updateHolding->loadNext()) { $tId = $updateHolding->get_variable('holdings_ticker_id'); $ticker = new ticker(); $ticker->set_variable("ticker_id", $tId); if ($ticker->load()) { $symbol = $ticker->get_variable("ticker_symbol"); } $updateHolding->set_variable("holdings_abandon_marked", 1); $updateHolding->set_variable("holdings_abandon_hide", 1); $updateHolding->set_variable('holdings_abandon_date', date('Y-m-d H:i:s')); $updateHolding->set_variable("holdings_ticker_symbol", $symbol); $updateHolding->update(); } }