コード例 #1
0
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";
        }
    }
}
コード例 #2
0
 public function updateFromYahoo()
 {
     $date = date('Y-m-d H:i:s');
     $stocks = array();
     $symbol = strtoupper($this->get_variable('ticker_symbol'));
     $stocks[] = $symbol;
     $results = finance::retrieveCurrentPrice($stocks, "l1hgp2");
     foreach ($results as $key => $value) {
         if (strtoupper($key) != $symbol) {
             continue;
         }
         $stockUpdates = explode(",", $value);
         $this->set_variable('last', $stockUpdates[0]);
         $this->set_variable('today_high', $stockUpdates[1]);
         $this->set_variable('today_low', $stockUpdates[2]);
         $change = str_replace('"', "", $stockUpdates[3]);
         $change = str_replace('%', "", $change);
         $change = str_replace('+', "", $change);
         $this->set_variable('change_today_percent', $change);
         $this->set_variable('last_update', $date);
         $this->update();
     }
 }
コード例 #3
0
     }
     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>";
コード例 #4
0
 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);
             }
         }
     }
 }