public function AddNewTickerAndWatch($tickerName, $lowOrEntry, $highOrRange) { $tt = $this->GetTradeType(); // ADD THE TICKER FIRST $ticker = new ticker(); $ticker->set_variable('ticker_symbol', $tickerName); if (!$ticker->load()) { $tickerId = $ticker->createNew(); $ticker->load(); $ticker->updateFromYahoo(); } else { $tickerId = $ticker->get_variable('ticker_id'); } // ADD TO THE WATCHLIST NOW $watchlist = new watchlist(); $watchlist->set_variable('watchlist_ticker_id', $tickerId); // call pure virtual to get fields based on trade type $this->CalculateTargets($lowOrEntry, $highOrRange); $watchlist->set_variable('watchlist_low', $lowOrEntry); $watchlist->set_variable('watchlist_high', $highOrRange); $watchlist->set_variable('watchlist_top', $this->topPrice); $watchlist->set_variable('watchlist_bottom', $this->bottomPrice); $watchlist->set_variable('watchlist_target0', $this->t0); $watchlist->set_variable('watchlist_target1', $this->t1); $watchlist->set_variable('watchlist_target2', $this->t2); $watchlist->set_variable('watchlist_target3', $this->t3); $watchlist->set_variable('watchlist_tradetype', $tt); $watchId = $watchlist->createNew(); holdings::updateTickerSellPrices($tickerId, $this->bottomPrice, $tt, false); highlights::watchlistHighlight($watchId, W_ROW, 0, highlights::EVENT_START_DAY); }
if ($watchlistItem->load()) { $lowOrEntry = $watchlistItem->get_variable('watchlist_low'); $highOrRange = $watchlistItem->get_variable('watchlist_high'); $top = $watchlistItem->get_variable('watchlist_top'); $bottom = $watchlistItem->get_variable('watchlist_bottom'); $t0 = $watchlistItem->get_variable('watchlist_target0'); $t1 = $watchlistItem->get_variable('watchlist_target1'); $t2 = $watchlistItem->get_variable('watchlist_target2'); $t3 = $watchlistItem->get_variable('watchlist_target3'); $tickerId = $watchlistItem->get_variable('watchlist_ticker_id'); $tip = $watchlistItem->get_variable('watchlist_tooltip'); $isZoned = $watchlistItem->get_variable('watchlist_is_zoned'); $ticker = new ticker(); $ticker->set_variable('ticker_id', $tickerId); $tradeTypeName = GetTradeTypeConstantName($tradeType); if ($ticker->load()) { $tickerSymbol = $ticker->get_variable('ticker_symbol'); } else { $tickerSymbol = "ERROR"; } } else { //header( 'Location: admin.editall.php' ) ; } $lowTitleName = $tradeType == BREAKOUT_TRADE || $tradeType == BREAKDOWN_TRADE ? "Entry" : "Low"; $highTitleName = $tradeType == BREAKOUT_TRADE || $tradeType == BREAKDOWN_TRADE ? "Range" : "High"; $topTitleName = $tradeType == BREAKOUT_TRADE || $tradeType == BREAKDOWN_TRADE ? "Hard Stop" : "Top"; $targetTitleName1 = $tradeType == PULLBACK_TRADE || $tradeType == BACKDRAFT_TRADE ? "Target" : "T1"; $targetTitleName3 = $tradeType == BREAKOUT_TRADE || $tradeType == BREAKDOWN_TRADE ? "Target" : "T3"; $t0ClassName = $tradeType == BREAKOUT_TRADE || $tradeType == BREAKDOWN_TRADE ? "" : "none"; $bottomClassName = $tradeType == BREAKOUT_TRADE || $tradeType == BREAKDOWN_TRADE ? "none" : ""; $zoneStr = $isZoned ? " <div class='note2'>(zoned)</div>" : "";
public function updateHistoryAndBorders($useGoogle) { echo "\n\nUpdating History and highs and lows\n\n"; if ($useGoogle) { $results = finance_google::retrieveHighsLowsPrice($this->tickerSymbols); } $results2 = finance::retrieveCurrentPrice($this->tickerSymbols, "gh"); $date = date('Y-m-d H:i:s'); $ticker = new ticker(); foreach ($results2 as $key => $value) { $ticker->reset_query(); $ticker->set_variable('ticker_symbol', $key); if ($ticker->load()) { $tickerClose = $ticker->get_variable('last_close'); $tickerId = $ticker->get_variable('ticker_id'); $last = $ticker->get_variable('last'); $yahooArr = explode(",", $value); if ($yahooArr[0] == 0) { $yahooArr[0] = $last; } if ($yahooArr[1] == 0) { $yahooArr[1] = $last; } $lasthigh = floatval($ticker->get_variable('today_high')); // Yahoo is broken //$currenthigh = max($lasthigh, floatval ($yahooArr[1])); // TEST CODE echo "\nYAHOO HIGH: " . ($yahoohigh = max($lasthigh, floatval($yahooArr[1]))); $currenthigh = $yahoohigh; // END TEST CODE $googleHigh = $last; if ($useGoogle) { $googleHigh = floatval($results[$key]['high']); if ($googleHigh > 0) { echo "\n Updating Last High " . $key . " " . $googleHigh; $ticker->set_variable('last_high', $googleHigh); $ticker->update(); $currenthigh = max($currenthigh, $googleHigh); } } $lastlow = $ticker->get_variable('today_low'); // Yahoo is broken //$currentlow = min($lastlow, floatval ($yahooArr[0])); // TEST CODE $yahoolow = min($lastlow, floatval($yahooArr[0])); $yahoolow = $yahoolow == 0 ? $lastlow : $yahoolow; $currentlow = $yahoolow; // END TEST CODE $googleLow = $last; if ($useGoogle) { $googleLow = floatval($results[$key]['low']); if ($googleLow < 10000) { if ($currentlow <= 0) { $currentlow = $googleLow; $ticker->set_variable('today_low', $currentlow); } $currentlow = min($googleLow, $currentlow); $ticker->set_variable('last_low', $googleLow); $ticker->update(); echo "\n Updating Last Low " . $key . " " . $googleLow . " And today low " . $currentlow; } } $lastupdate = date('Y-m-d', strtotime($ticker->get_variable('last_highlow_update'))); $today = date('Y-m-d'); echo "\n\nTESTING HIGH and LOW of " . $key . " as " . $currenthigh . " : " . $currentlow . "\n"; $doUpdate = false; if ($currenthigh != 0 && ($today != $lastupdate || $currenthigh > $lasthigh)) { echo "\nset high " . $currenthigh; $ticker->set_variable('yahoo_high', round($yahoohigh, 2)); $ticker->set_variable('today_high', round($currenthigh, 2)); $doUpdate = true; } if ($currentlow != 0 && ($today != $lastupdate || $currentlow < $lastlow)) { echo "\nset low " . $currentlow; $ticker->set_variable('yahoo_low', round($yahoolow, 2)); $ticker->set_variable('today_low', round($currentlow, 2)); $doUpdate = true; } if ($doUpdate) { if ($today != $lastupdate) { echo "\nset last "; $ticker->set_variable('last_highlow_update', $today); } $ticker->update(); } // add ticker history /* $tickerHistory = new ticker_history(); $tickerHistory->set_variable('history_price', $last); $tickerHistory->set_variable('history_date', $date); $tickerHistory->set_variable('history_ticker_id', $tickerId); if ($googleHigh > 0) $tickerHistory->set_variable('history_lasthigh', $googleHigh); else $tickerHistory->set_variable('history_lasthigh', $last); if ($googleLow < 10000) $tickerHistory->set_variable('history_lastlow', $googleLow); else $tickerHistory->set_variable('history_lastlow', $last); $tickerHistory->addStochInfoAndCreate($last); * */ //ticker_history::addStochInfoAndCreate($key, $tickerId); // remove oldest history $tickerHistory = new ticker_history(); $tickerHistory->set_variable('history_ticker_id', $tickerId); $numHistory = $tickerHistory->countAll('', '', 'history_id'); $tickerHistory->reset_query(); $limit = NUM_HISTORY_TO_KEEP; if ($numHistory > $limit) { $limit = $numHistory - $limit; $tickerHistory->delete(" WHERE history_ticker_id='" . $tickerId . "' ORDER BY history_date ASC LIMIT " . $limit); } } } }
public function markZoned($tradeType = LONG_TRADE, $sendUpdate = true, $logTransaction = true) { $notesStr = ""; $zoned = $this->get_variable('watchlist_is_zoned'); if ($zoned == 0) { $tid = $this->get_variable('watchlist_ticker_id'); $ticker = new ticker(); $ticker->set_variable('ticker_id', $tid); if ($ticker->load()) { $tickerSymbol = $ticker->get_variable('ticker_symbol'); $last = $ticker->get_variable('last'); $today_low = $ticker->get_variable('today_low'); $today_high = $ticker->get_variable('today_high'); $date = date('Y-m-d H:i:s'); $bottom = $this->get_variable('watchlist_bottom'); $top = $this->get_variable('watchlist_top'); $today_low = max($bottom, min($last, $today_low)); $today_high = min($top, max($last, $today_high)); if ($today_low == 0 || $today_high == 0) { return "ERROR IN DATA PROVIDED::HIGH=" . $today_high . "::LOW=" . $today_low; } $holdings = new holdings(); $holdings->set_variable('holdings_ticker_id', $tid); $holdings->set_variable('holdings_orig_date', $date); $lowOrEntry = round(floatval($this->get_variable('watchlist_low')), 2); $t0 = round(floatval($this->get_variable('watchlist_target0')), 2); $t1 = round(floatval($this->get_variable('watchlist_target1')), 2); $t2 = round(floatval($this->get_variable('watchlist_target2')), 2); $t3 = round(floatval($this->get_variable('watchlist_target3')), 2); $holdings->set_variable('holdings_t0', $t0); $holdings->set_variable('holdings_t1', $t1); $holdings->set_variable('holdings_t2', $t2); $holdings->set_variable('holdings_t3', $t3); $holdings->set_variable('holdings_tradetype', $tradeType); $holdings->set_variable('holdings_stop_type', 'EOD'); $holdings->set_variable('holdings_last_action', BUY); switch ($tradeType) { case SHORT_TRADE: case BACKDRAFT_TRADE: $actionPrice = $bottom; $holdings->set_variable('holdings_orig_price', $bottom); $holdings->set_variable('holdings_stop_price', $top); $holdings->set_variable('holdings_top_price', $bottom); $notesStr .= "\n<br/>\nIN ZONE ticker:" . $tickerSymbol . " \$" . $last . " (ORIG_PRICE = " . $today_high . ")"; break; case LONG_TRADE: case PULLBACK_TRADE: $actionPrice = $top; $holdings->set_variable('holdings_orig_price', $top); $holdings->set_variable('holdings_stop_price', $bottom); $holdings->set_variable('holdings_top_price', $top); $notesStr .= "\n<br/>\nIN ZONE ticker:" . $tickerSymbol . " \$" . $last . " (ORIG_PRICE = " . $today_low . ")"; break; case REVERSAL_TRADE: $actionPrice = $top; $holdings->set_variable('holdings_orig_price', $top); $holdings->set_variable('holdings_stop_price', $top); $holdings->set_variable('holdings_top_price', $top); $notesStr .= "\n<br/>\nIN ZONE ticker:" . $tickerSymbol . " \$" . $last . " (ORIG_PRICE = " . $today_low . ")"; break; case BREAKOUT_TRADE: $actionPrice = $lowOrEntry; $holdings->set_variable('holdings_orig_price', $lowOrEntry); $holdings->set_variable('holdings_stop_price', $top); $holdings->set_variable('holdings_top_price', $top); // Hard Stop Price $notesStr .= "\n<br/>\nIN ZONE ticker:" . $tickerSymbol . " \$" . $last . " (ORIG_PRICE = " . $today_low . ")"; break; case BREAKDOWN_TRADE: $actionPrice = $lowOrEntry; $holdings->set_variable('holdings_orig_price', $lowOrEntry); $holdings->set_variable('holdings_stop_price', $top); $holdings->set_variable('holdings_top_price', $top); $notesStr .= "\n<br/>\nIN ZONE ticker:" . $tickerSymbol . " \$" . $last . " (ORIG_PRICE = " . $today_low . ")"; break; } $tweet = new tweet(); $updateEmail = new email(email::ADDRESSES_ALL_CHOSEN, $tradeType); $action = BUY; $tweet->newTweet($tradeType, $action, $tickerSymbol, $actionPrice); $updateEmail->newEmail($tradeType, $action, $tickerSymbol, $actionPrice); $tooltip = $this->get_variable("watchlist_tooltip"); $holdings->set_variable("holdings_tooltip", $tooltip); $holdingsId = $holdings->createNew(); if ($logTransaction) { // Add a transaction to the transaction table $transactions = new transactions(); $transactions->set_variable('transaction_holdings_id', $holdingsId); $transactions->set_variable('transaction_price', $actionPrice); $transactions->set_variable('transaction_date', date('Y-m-d H:i:s')); $transactions->set_variable('transaction_action', BUY); $transactions->set_variable('transaction_tradetype', $tradeType); $transactions->createNew(); } // add to the holdings table with the current information $this->set_variable('watchlist_is_zoned', 1); $this->update(); } } return $notesStr; }
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); } }
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(); } }
function processPullbacks() { $watches = new watchlist(); $watches->set_variable("watchlist_tradetype", PULLBACK_TRADE); while ($watches->loadNext()) { $tId = $watches->get_variable("watchlist_ticker_id"); $wId = $watches->get_variable("watchlist_id"); $calcHigh = $watches->get_variable("watchlist_high"); $calcLow = $watches->get_variable("watchlist_low"); $ticker = new ticker(); $ticker->set_variable("ticker_id", $tId); if ($ticker->load()) { $dayHigh = $ticker->get_variable("today_high"); $symbol = strtoupper($ticker->get_variable("ticker_symbol")); echo "Testing " . $symbol . " PrevHigh=" . $calcHigh . " DayHigh=" . $dayHigh . "<br>\n"; if ($dayHigh > $calcHigh) { echo " RECALC AND HIGHLIGHTING\n<br>"; $className = adminControlWatchlist::GetWatchClassName(PULLBACK_TRADE); $watchlistAdmin = new $className($wId); $watchlistAdmin->Edit($calcLow, $dayHigh); // highlight the abandon price highlights::watchlistHighlight($wId, W_ENTRY_ZONE, 0, highlights::EVENT_START_DAY); } } } }