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 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);
 }
					</tr>
				</thead>
<?php 
$tablestate = "row_odd";
$prevMonth = "";
$allMonths = array();
$first = true;
foreach ($abandon as $holding) {
    $hid = $holding['holdings_id'];
    $hitT3 = $holding['holdings_t3_marked'];
    $t3 = floatval($holding['holdings_t3']);
    $abandon = $holding['holdings_stop_price'];
    $start = $holding['holdings_orig_price'];
    $symbol = $holding['holdings_ticker_symbol'];
    $tradeType = $holding['holdings_tradetype'];
    $return_percent = holdings::GetReturnPercent($tradeType, 0, $start, 0, 0, $t3, false, false, $hitT3, $abandon);
    // process months into array for select
    $abandonMonth = date("F Y", strtotime($holding['holdings_abandon_date']));
    if ($abandonMonth != $prevMonth) {
        $prevMonth = $abandonMonth;
        $allMonths[] = $abandonMonth;
        if (!$first) {
            echo "</tbody>";
            $first = false;
        }
        echo "<tbody id=\"month_" . str_replace(" ", "", $abandonMonth) . "\" class=\"monthTable\">";
    }
    echo '<tr class="table_row ' . $tablestate . ' ">';
    echo '<td class="lowpriority">' . date("Y-m-d", strtotime($holding['holdings_orig_date'])) . '</td>';
    echo '<td class="lowpriority">' . date("Y-m-d", strtotime($holding['holdings_abandon_date'])) . '</td>';
    $symbol = strtoupper($holding['holdings_ticker_symbol']);
     if ($tt == BACKDRAFT_TRADE && $action != ABANDON) {
         continue;
     }
     if ($action == ABANDON_HARD_STOP) {
         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>";
         }
 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);
     }
 }
Beispiel #6
0
$first = true;
foreach ($abandon as $holding) {
    $hid = $holding['holdings_id'];
    $tradeType = $holding['holdings_tradetype'];
    if ($tradeType == REVERSAL_TRADE) {
        continue;
    }
    $hitT1 = $holding['holdings_t1_marked'];
    $hitT2 = $holding['holdings_t2_marked'];
    $hitT3 = $holding['holdings_t3_marked'];
    $t1 = floatval($holding['holdings_t1']);
    $t2 = floatval($holding['holdings_t2']);
    $t3 = floatval($holding['holdings_t3']);
    $start = $holding['holdings_orig_price'];
    $abandon = $holding['holdings_stop_price'];
    $return_percent = holdings::GetReturnPercent($tradeType, 0, $start, $t1, $t2, $t3, $hitT1, $hitT2, $hitT3, $abandon);
    $tradeClass = strtolower(GetTradeTypeConstantNameSingular($tradeType));
    $tradeString = GetTradeTypeConstantNameSingular($tradeType);
    $ti = GetTradeIndex($tradeType);
    $valuation = 5000 * $return_percent / 100;
    // process months into array for select
    $abandonMonth = date("F Y", strtotime($holding['holdings_abandon_date']));
    if ($abandonMonth != $prevMonth) {
        $prevMonth = $abandonMonth;
        $allMonths[] = $abandonMonth;
        if (!$first) {
            //echo "</tbody>";
            $first = false;
        }
        //echo "<tbody id=\"month_".str_replace(" ", "", $abandonMonth) ."\" class=\"monthTable\">";
    }
    } else {
        if (isset($_POST['holding_id'])) {
            $holdingId = intval($_POST['holding_id']);
        } 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);
 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;
 }
Beispiel #9
0
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();
}
 $holdCounter++;
 $holdId = $holding['holdings_id'];
 $tId = $holding['ticker_id'];
 $lastActionStr = GetLastActionString($index, $holding['holdings_last_action']);
 $last = $holding['last'];
 $hitT1 = $holding['holdings_t1_marked'];
 $hitT2 = $holding['holdings_t2_marked'];
 $hitT3 = $holding['holdings_t3_marked'];
 $t1 = floatval($holding['holdings_t1']);
 $t2 = floatval($holding['holdings_t2']);
 $t3 = floatval($holding['holdings_t3']);
 $start = $holding['holdings_top_price'];
 if ($index == BREAKDOWN_TRADE || $index == BREAKOUT_TRADE) {
     $start = $holding['holdings_orig_price'];
 }
 $return_percent = holdings::GetReturnPercent($index, $last, $start, $t1, $t2, $t3, $hitT1, $hitT2, $hitT3);
 $t1Class = $hitT1 ? "owned" : "";
 $t2Class = $hitT2 ? "owned" : "";
 $t3Class = $hitT3 ? "owned" : "";
 echo '<tr class="table_row ' . $tablestate . ' ">';
 echo '<td>' . date("Y-m-d", strtotime($holding['holdings_orig_date'])) . '</td>';
 echo '<td><a class="stocklink" target="_blank" href="https://www.google.com/finance?q=' . strtoupper($holding['ticker_symbol']) . '" >' . strtoupper($holding['ticker_symbol']) . '</a></td>';
 echo '<td>' . number_format($holding['last'], 2) . '</td>';
 if ($index == BREAKOUT_TRADE || $index == BREAKDOWN_TRADE) {
     echo '<td class="' . $t3Class . '">' . number_format($holding['holdings_t3'], 2) . '</td>';
 } else {
     if ($index == BACKDRAFT_TRADE || $index == PULLBACK_TRADE) {
         echo '<td class="' . $t1Class . '">' . number_format($holding['holdings_t1'], 2) . '</td>';
     } else {
         echo '<td class="' . $t1Class . '">' . number_format($holding['holdings_t1'], 2) . '</td>';
         echo '<td class="' . $t2Class . '">' . number_format($holding['holdings_t2'], 2) . '</td>';
Beispiel #11
0
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);
    }
}
//Include the PS_Pagination class
require_once 'php/db_interface/autoload.php';
$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]);
 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();
     }
 }
$prevMonth = "";
$allMonths = array();
$first = true;
foreach ($abandons as $holding) {
    $hid = $holding['holdings_id'];
    $hitT1 = $holding['holdings_t1_marked'];
    $hitT2 = $holding['holdings_t2_marked'];
    $hitT3 = $holding['holdings_t3_marked'];
    $t1 = floatval($holding['holdings_t1']);
    $t2 = floatval($holding['holdings_t2']);
    $t3 = floatval($holding['holdings_t3']);
    $start = $holding['holdings_top_price'];
    $orig = $holding['holdings_orig_price'];
    $abandonPrice = $holding['holdings_stop_price'];
    $tradeType = $holding['holdings_tradetype'];
    $return_percent = holdings::GetReturnPercent($tradeType, 0, $orig, $t1, $t2, $t3, $hitT1, $hitT2, $hitT3, $abandonPrice);
    // process months into array for select
    $abandonMonth = date("F Y", strtotime($holding['holdings_abandon_date']));
    if ($abandonMonth != $prevMonth) {
        $prevMonth = $abandonMonth;
        $allMonths[] = $abandonMonth;
        if (!$first) {
            echo "</tbody>";
            $first = false;
        }
        echo "<tbody id=\"month_" . str_replace(" ", "", $abandonMonth) . "\" class=\"monthTable\">";
    }
    echo '<tr class="table_row ' . $tablestate . ' ">';
    echo '<td class="lowpriority">' . date("Y-m-d", strtotime($holding['holdings_orig_date'])) . '</td>';
    echo '<td class="lowpriority">' . date("Y-m-d", strtotime($holding['holdings_abandon_date'])) . '</td>';
    $symbol = strtoupper($holding['holdings_ticker_symbol']);
Beispiel #15
0
						<th></th>
					</tr>
				</thead>
				<tbody>
<?php 
$holdings = ticker_group_info::retrieveHoldingsArray(LONG_TRADE, true);
$tablestate = "row_odd";
$borderTop = "borderTop";
foreach ($holdings as $holding) {
    $tt = intval($holding['holdings_tradetype']);
    //if ($tt == BREAKDOWN_TRADE) continue;
    $last = $holding['last'];
    $ttStr = GetTradeTypeConstantNameSingular($tt);
    $tablerowtype = strtolower($ttStr);
    $start = $holding['holdings_orig_price'];
    $return_percent = holdings::GetReturnPercent($tt, $last, $start, 0, 0, 0, 0, 0, 0);
    echo '<tr class="table_row2 ' . $tablestate . ' ' . $tablerowtype . '">';
    echo '<td class="left borderLeft ' . $borderTop . '">' . strtoupper($holding['ticker_symbol']) . '</td>';
    echo '<td class="center ' . $borderTop . '">' . $ttStr . '</td>';
    echo '<td class="center ' . $borderTop . '">' . number_format($holding['last'], 2) . '</td>';
    echo '<td class="center ' . $borderTop . '">' . number_format($start, 2) . '</td>';
    echo '<td class="center ' . $borderTop . '">' . date("m-d-Y", strtotime($holding['holdings_orig_date'])) . '</td>';
    echo '<td class="center borderRight ' . $borderTop . '">' . number_format($return_percent, 2) . '%</td>';
    echo '</tr>';
    $borderTop = "";
}
?>
					
				</tbody>
			</table>
		</div> <!-- tablegroup -->