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;
 }
 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();
                 }
             }
         }
     }
 }
 public static function abandonHardStop($holding_id, $message = "")
 {
     $holding = new holdings();
     $holding->set_variable('holdings_id', $holding_id);
     if ($holding->load()) {
         $symbol = $holding->get_variable('holdings_ticker_symbol');
         $tId = $holding->get_variable('holdings_ticker_id');
         $tradeType = $holding->get_variable("holdings_tradetype");
         $stopPrice = floatval($holding->get_variable('holdings_top_price'));
         $action = $holding->get_variable("holdings_last_action");
         if (IsAbandoned($action)) {
             return;
         }
         $tweet = new tweet();
         $abandonEmail = new email(email::ADDRESSES_ALL_CHOSEN, $tradeType, $hId);
         if (strlen($symbol) <= 0) {
             $ticker = new ticker();
             $ticker->set_variable("ticker_id", $tId);
             if ($ticker->load()) {
                 $symbol = $ticker->get_variable("ticker_symbol");
                 $last = $ticker->get_variable('last');
             }
         }
         //"ABANDON";
         $action = ABANDON_HARD_STOP;
         $tweet->newTweet($tradeType, $action, $symbol, $stopPrice, $message);
         $abandonEmail->newEmail($tradeType, $action, $symbol, $stopPrice, $message);
         $holding->set_variable('holdings_last_action', $action);
         $holding->set_variable('holdings_stop_price', $stopPrice);
         $holding->update();
         highlights::holdingsHighlight($hId, H_LAST_ACTION, 0, highlights::EVENT_END_DAY);
         // Add a transaction to the transaction table
         $transactions = new transactions();
         $transactions->set_variable('transaction_holdings_id', $holding_id);
         $transactions->set_variable('transaction_price', $stopPrice);
         $transactions->set_variable('transaction_date', date('Y-m-d H:i:s'));
         $transactions->set_variable('transaction_action', ABANDON_HARD_STOP);
         $transactions->set_variable('transaction_tradetype', $tradeType);
         $transactions->createNew();
     }
 }