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 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); } } }
} else { if (isset($_GET['history_id'])) { $holdingId = intval($_GET['history_id']); holdings::ADMIN_MarkAbandoned($holdingId); header('Location: admin.editallholdings.php'); } else { header('Location: admin.editallholdings.php'); } } } } // load holding data $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
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 endOfDayEmail() { $email = new email(email::ADDRESSES_ALL_ACTIVE); $allText = array(BREAKOUT_TRADE => '', LONG_TRADE => '', PULLBACK_TRADE => '', SHORT_TRADE => '', BACKDRAFT_TRADE => '', BREAKDOWN_TRADE => ''); $transHistory = new transactions(); while ($transHistory->loadNext(' DATE(`transaction_date`) = DATE(NOW()) ')) { $hId = $transHistory->get_variable('transaction_holdings_id'); $holdings = new holdings(); $holdings->set_variable("holdings_id", $hId); if (!$holdings->load()) { continue; } $tId = $holdings->get_variable("holdings_ticker_id"); $ticker = new ticker(); $ticker->set_variable('ticker_id', $tId); if ($ticker->load()) { $symbol = $ticker->get_variable('ticker_symbol'); //echo "Adding to EOD EMAIL " . $symbol . "\n\n"; $tranDate = $transHistory->get_variable('transaction_date'); $tz = new DateTimeZone('America/New_York'); $date = new DateTime($tranDate); $date->setTimeZone($tz); $dateStr = $date->format("h:i A"); $tradeType = $transHistory->get_variable('transaction_tradetype'); $action = intval($transHistory->get_variable('transaction_action')); $actionPrice = floatval($transHistory->get_variable('transaction_price')); $actionInfo = email::GetEmailText($tradeType, $action, $symbol, $actionPrice, "", false); if (strlen($actionInfo["body"]) > 0) { $allText[$tradeType] .= "<div style=\"\" >" . $dateStr . " - " . $actionInfo["body"] . "</div>"; } } } $bodyText = ''; foreach ($allText as $key => $value) { if (strlen($value) > 0) { $bodyText .= "<div style=\"font-size:13pt;font-family:Helvetica;text-decoration:underline;text-align:center;padding-bottom:7px;padding-top:20px;font-weight:bold\">" . GetTradeTypeConstantName($key) . "</div>" . $value; } } if (strlen($bodyText) == 0) { echo "NO TRANSACTIONS TODAY " . $transHistory->debug(); $email->endOfDay("There were no BioBounce events today."); } else { echo "SENDING EOD EMAIL\n\n"; $email->endOfDay($bodyText); } }
$login = new login(true); if (isset($_GET['tt'])) { $tradeType = intval($_GET['tt']); } else { $tradeType = BREAKOUT_TRADE; } $counter = 1; while (true) { if (!isset($_POST[$counter])) { break; } $holdId = $_POST[$counter]; $holding = new holdings(); $holding->set_variable('holdings_id', $holdId); if ($holding->load()) { $oldAbandon = floatval($holding->get_variable('holdings_stop_price')); $oldHard = floatval($holding->get_variable('holdings_top_price')); $isEdited = false; if (isset($_POST['abandon_' . $holdId])) { $abandon = floatval($_POST['abandon_' . $holdId]); 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);
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(); } }