Esempio n. 1
0
function getBollingerBands3($company, $from = "1900-01-01 00:00:00", $to = null, $dataorg = "json", $enSignals = false, $host, $db, $user, $pass)
{
    $studyPeriod = 20;
    $offsetPeriod = $studyPeriod * 1;
    //from date has to be adjusted for the bollinger bands
    $date = date_create($from);
    date_add($date, date_interval_create_from_date_string("-{$offsetPeriod} days"));
    $fromAdjusted = date_format($date, "Y-m-d");
    //echo "fromAdjusted: $fromAdjusted<Br>";
    $dataOhlc = [];
    //OHLC data format [timestamp,open,high,low,close,volume]
    if ($dataorg == "highchart") {
        $dataOhlc = getOHLC($company, $fromAdjusted, $to, "array2", $host, $db, $user, $pass);
    } else {
        $dataOhlc = getOHLC($company, $fromAdjusted, $to, "array", $host, $db, $user, $pass);
    }
    //Return if $dataOhlc is null
    if ($dataOhlc == [] || $dataOhlc == 0) {
        return 0;
    }
    //Input for bollinger bands should be [timestamp,open,high,low,close]
    $ctr = 0;
    foreach ((array) $dataOhlc as $ohlc) {
        $dbreturn[$ctr][0] = $ohlc[0];
        //timestamp
        $dbreturn[$ctr][1] = $ohlc[1];
        //high
        $dbreturn[$ctr][2] = $ohlc[2];
        //low
        $dbreturn[$ctr][3] = $ohlc[3];
        //low
        $dbreturn[$ctr++][4] = $ohlc[4];
        //close
    }
    if ($dataorg == "json") {
        $bbohlc = codesword_bollinger_bands3($dbreturn, $studyPeriod);
        if (count($bbohlc) <= 1) {
            //No Data
            return 0;
        }
        $returnBB = $bbohlc;
    } elseif ($dataorg == "highchart") {
        $returnBB = codesword_bollinger_bands3($dbreturn, $studyPeriod);
        if ($returnBB == 0) {
            //No Data
            return 0;
        }
    } elseif ($dataorg == "array") {
        //TODO: create code for organizing an array data output
    } else {
        //json
        $returnBB = codesword_bollinger_bands3($dbreturn, $studyPeriod);
        if ($returnBB == 0) {
            //No Data
            return 0;
        }
    }
    $allData = [];
    if (strcasecmp($enSignals, "latest") == 0) {
        //return only the latest signal
        // [timestamp,trade signal,... other info...]
        $lastSignal = codesword_bbTrendDetectorLatests($returnBB);
        return $lastSignal;
    } elseif ($enSignals) {
        $allData[0] = $returnBB;
        $allData[1] = codesword_bbTrendDetector($returnBB);
        echo json_encode($allData);
    } else {
        $allData = $returnBB;
        echo json_encode($allData);
    }
}
Esempio n. 2
0
function codesword_bbTrendDetectorLatests($input)
{
    $bb3 = codesword_bbTrendDetector($input);
    if ($bb3 == 0 || $bb3 == [] || $bb3 == null) {
        //No Signals
        return 0;
    }
    $latest = $bb3[count($bb3) - 1];
    //return $bb3 latest;
    return $latest;
}