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"; } } }
public function ZoneSymbol($list, $symbol, $target) { $ticker = new ticker(); $ticker->set_variable('ticker_symbol', $symbol); if ($ticker->loadNext()) { $tId = $ticker->get_variable('ticker_id'); $last = floatval($ticker->get_variable('last')); $holdings = new holdings(); $holdings->set_variable('holdings_ticker_id', $tId); if ($holdings->loadNext()) { $t1 = floatval($holdings->get_variable('holdings_t1')); $t2 = floatval($holdings->get_variable('holdings_t2')); $t3 = floatval($holdings->get_variable('holdings_t3')); $origPrice = $holdings->get_variable('holdings_orig_price'); $hId = $holdings->get_variable('holdings_id'); $tradeType = $holdings->get_variable('holdings_tradetype'); $newHolding = new holdings(); if ($list == "L") { $action = ""; if ($target == "T1") { $action = SELL1; $newHolding->set_variable('holdings_t1_marked', 1); $newHolding->set_variable('holdings_stop_price', $origPrice); watchlist::removeTickerHitT1($tId); holdings::updateTickerSellPrices($tId, $origPrice); highlights::holdingsHighlight($hId, H_T1, 0, highlights::EVENT_START_DAY); } else { if ($target == "T2") { $action = SELL2; $newHolding->set_variable('holdings_t2_marked', 1); holdings::updateTickerSellPrices($tId, $t1); highlights::holdingsHighlight($hId, H_T2, 0, highlights::EVENT_START_DAY); } else { if ($target == "T3") { $action = SELL3; $newHolding->set_variable('holdings_t3_marked', 1); holdings::updateTickerSellPrices($tId, $t2); highlights::holdingsHighlight($hId, H_T3, 0, highlights::EVENT_START_DAY); } } } if ($action != "") { $newHolding->set_variable('holdings_id', $hId); $newHolding->set_variable('holdings_last_action', $action); $newHolding->update(); // Add a transaction to the transaction table $transactions = new transactions(); $transactions->set_variable('transaction_holdings_id', $hId); $transactions->set_variable('transaction_price', $last); $transactions->set_variable('transaction_date', date('Y-m-d H:i:s')); $transactions->set_variable('transaction_action', $action); $transactions->set_variable('transaction_tradetype', $tradeType); $transactions->createNew(); } } } } }
function abandonNowStocks() { $holding = new holdings(); $holding->set_variable("holdings_last_action", ABANDON_AT_CLOSE); $holding->set_variable("holdings_abandon_marked", 0); $symbols = array(); $hids = array(); $hasAbandon = false; while ($holding->loadNext()) { $symbol = $holding->get_variable('holdings_ticker_symbol'); $tid = $holding->get_variable('holdings_ticker_id'); $hid = $holding->get_variable('holdings_id'); if (strlen($symbol) <= 0) { $ticker = new ticker(); $ticker->set_variable("ticker_id", $tid); if ($ticker->load()) { $symbol = $ticker->get_variable("ticker_symbol"); } } array_push($symbols, strtoupper($symbol)); array_push($hids, $hid); $hasAbandon = true; } if ($hasAbandon) { print_r($symbols); print_r($hids); $results = finance_google::retrieveCurrentPrice($symbols); $updateHolding = new holdings(); foreach ($results as $key => $value) { if ($key == "filesize") { continue; } $updateHolding->reset_query(); $ticker = $key; $price = floatval($value); if ($price > 0) { echo "\nTICKER:" . $ticker . " PRICE=" . $price . "\n"; $index = array_search($ticker, $symbols); $hid = $hids[$index]; $updateHolding->set_variable("holdings_id", $hid); if (!$updateHolding->load()) { echo "WRONG::" . $ticker . " NOT RECOGNIZED IN DB\n\n"; continue; } $updateHolding->set_variable("holdings_stop_price", $price); echo "\nChanging Stop Price for " . $ticker . " to " . $price . ". Opening Price at end of day.\n"; $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", $ticker); $updateHolding->update(); } } } }
$holidays[] = strtotime("2015-04-03"); $holidays[] = strtotime("2014-04-18"); $holidays[] = strtotime("2014-05-26"); $holidays[] = strtotime("2014-07-04"); $holidays[] = strtotime("2014-09-01"); $holidays[] = strtotime("2014-11-27"); $holidays[] = strtotime("2014-12-25"); $holidays[] = strtotime("2015-01-01"); $today = strtotime(date("Y-m-d")); if (!in_array($today, $holidays)) { //Include the PS_Pagination class $holding = new holdings(); $holding->set_variable("holdings_abandon_hide", 1); $symbols = array(); $hids = array(); while ($holding->loadNext("holdings_abandon_date LIKE '" . date("Y-m-d") . "%'")) { $symbol = $holding->get_variable('holdings_ticker_symbol'); $tid = $holding->get_variable('holdings_ticker_id'); $hid = $holding->get_variable('holdings_id'); if (strlen($symbol) <= 0) { $ticker = new ticker(); $ticker->set_variable("ticker_id", $tid); if ($ticker->load()) { $symbol = $ticker->get_variable("ticker_symbol"); $holding->set_variable('holdings_ticker_symbol', strtoupper($symbol)); $holding->update(); echo "\nUpdating Ticker Symbol for " . $symbol; } } $tt = $holding->get_variable('holdings_tradetype'); $action = $holding->get_variable('holdings_last_action');
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(); }
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(); } }