php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75930 trader_bbands- error output
Submitted: 2018-02-07 15:22 UTC Modified: 2018-06-24 04:25 UTC
From: anton-praha at seznam dot cz Assigned:
Status: No Feedback Package: Trader (PECL)
PHP Version: 7.2.2 OS: mac os 10.3.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
42 - 37 = ?
Subscribe to this entry?

 
 [2018-02-07 15:22 UTC] anton-praha at seznam dot cz
Description:
------------
---
From manual page: http://www.php.net/function.trader-bbands
---

In some cases, this function returns the same values for low, high, middle Bollinger bands. The next example does not count BB for the last 14 periods for me.

var_dump($lastCloses);
var_dump(trader_bbands($lastCloses, count($lastCloses), 2, 2, TRADER_MA_TYPE_SMA));

Output:
array(14) {
  [0]=>
  float(0.0675)
  [1]=>
  float(0.0675)
  [2]=>
  float(0.0675)
  [3]=>
  float(0.0675)
  [4]=>
  float(0.06747)
  [5]=>
  float(0.06747)
  [6]=>
  float(0.06747)
  [7]=>
  float(0.06722)
  [8]=>
  float(0.06742)
  [9]=>
  float(0.06752)
  [10]=>
  float(0.06746)
  [11]=>
  float(0.06766)
  [12]=>
  float(0.06761)
  [13]=>
  float(0.06759)
}

array(3) {
  [0]=>
  array(1) {
    [13]=>
    float(0.06749214)
  }
  [1]=>
  array(1) {
    [13]=>
    float(0.06749214)
  }
  [2]=>
  array(1) {
    [13]=>
    float(0.06749214)
  }
}

Test script:
---------------
var_dump($lastCloses);
var_dump(trader_bbands($lastCloses, count($lastCloses), 2, 2, TRADER_MA_TYPE_SMA));


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-07 16:38 UTC] cmb@php.net
-Package: *General Issues +Package: Trader
 [2018-02-10 16:57 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2018-02-10 16:57 UTC] ab@php.net
Thanks for the report. Please supply a full example with the income data and expected/actual result.

Thanks.
 [2018-02-10 22:00 UTC] anton-praha at seznam dot cz
-Status: Feedback +Status: Open
 [2018-02-10 22:00 UTC] anton-praha at seznam dot cz
I have provided example with sample data. Which outputs me 3 same numbers for bollinger bands. This numbers are always need to be different, the first one is the biggest, the second is the middle, and the third is the lowest value. So i exept to get 3 different values in the order i'v described.

Regards
 [2018-02-11 12:23 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2018-02-11 12:23 UTC] ab@php.net
Ah, i see. Just that you did it an a bit unusual way, normally you would put a script, not its outputs, as a reproducer. Anyway, to the matter.

The STDDEV of the supplied dataset is so small, that TA-Lib decides it to be zero. That way, of course upper and lower bands will not differ, as per the formula. TA-Lib decides a value zero if it's smaller 1e-8 or negative. Given this, the behavior doesn't look like a bug in the PHP ext, but also perhaps is not a bug in the TA-Lib.

I think, with the given data set, you could still achieve some acceptable result. Possible ways to go were

- use the classic MA of 20
- try to convert values to integers before calling trader_bbands()
- experiment with the value precision and the time intervals

From the implementation perspective, it seems that the 1e-8 step for the double validation makes sense.

Thanks.
 [2018-06-24 04:25 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2019-03-27 04:58 UTC] php at solomon dot web dot za
I have the same problem.

        $vals = array();
        foreach ($trades as $row) {
                $vals[] = (float)$row->price;
        }
        ini_set('trader.real_precision', '10');
        $bbands = trader_bbands($vals, 7, 2.0, 2.0, TRADER_MA_TYPE_SMA);
        var_dump($vals);
        var_dump($bbands); exit;


output:

$vals:
array(100) {
  [0]=>
  float(1.90661E-5)
  [1]=>
  float(1.90662E-5)
  [2]=>
  float(1.90331E-5)
  [3]=>
  float(1.91533E-5)
  [4]=>
  float(1.91533E-5)
  [5]=>
  float(1.91533E-5)
  [6]=>
  float(1.91533E-5)
  [7]=>
  float(1.91533E-5)
  [8]=>
  float(1.91533E-5)
  [9]=>
  float(1.91533E-5)
  [10]=>
  float(1.91533E-5)
  [11]=>
  float(1.91533E-5)
  [12]=>
  float(1.91533E-5)
  [13]=>
  float(1.91533E-5)
  [14]=>
  float(1.91533E-5)
  [15]=>
  float(1.91533E-5)
  [16]=>
  float(1.91533E-5)
  [17]=>
  float(1.91533E-5)
  [18]=>
  float(1.91533E-5)
  [19]=>
  float(1.91533E-5)
  [20]=>
  float(1.91533E-5)
  [21]=>
  float(1.91533E-5)
  [22]=>
  float(1.91533E-5)
  [23]=>
  float(1.91533E-5)
  [24]=>
  float(1.91533E-5)
  [25]=>
  float(1.91533E-5)
  [26]=>
  float(1.91533E-5)
  [27]=>
  float(1.91533E-5)
  [28]=>
  float(1.91533E-5)
  [29]=>
  float(1.91533E-5)
  [30]=>
  float(1.91533E-5)
  [31]=>
  float(1.91533E-5)
  [32]=>
  float(1.91533E-5)
  [33]=>
  float(1.91533E-5)
  [34]=>
  float(1.91E-5)
  [35]=>
  float(1.91E-5)
  [36]=>
  float(1.91E-5)
  [37]=>
  float(1.91E-5)
  [38]=>
  float(1.91E-5)
  [39]=>
  float(1.91E-5)
  [40]=>
  float(1.91E-5)
  [41]=>
  float(1.90999E-5)
  [42]=>
  float(1.90999E-5)
  [43]=>
  float(1.90999E-5)
  [44]=>
  float(1.90999E-5)
  [45]=>
  float(1.90999E-5)
  [46]=>
  float(1.90999E-5)
  [47]=>
  float(1.90998E-5)
  [48]=>
  float(1.92487E-5)
  [49]=>
  float(1.90314E-5)
  [50]=>
  float(1.90314E-5)
  [51]=>
  float(1.9249E-5)
  [52]=>
  float(1.9249E-5)
  [53]=>
  float(1.925E-5)
  [54]=>
  float(1.92E-5)
  [55]=>
  float(1.92E-5)
  [56]=>
  float(1.92E-5)
  [57]=>
  float(1.901E-5)
  [58]=>
  float(1.901E-5)
  [59]=>
  float(1.901E-5)
  [60]=>
  float(1.901E-5)
  [61]=>
  float(1.901E-5)
  [62]=>
  float(1.901E-5)
  [63]=>
  float(1.9E-5)
  [64]=>
  float(1.9E-5)
  [65]=>
  float(1.9E-5)
  [66]=>
  float(1.9E-5)
  [67]=>
  float(1.89997E-5)
  [68]=>
  float(1.9E-5)
  [69]=>
  float(1.89996E-5)
  [70]=>
  float(1.89995E-5)
  [71]=>
  float(1.89999E-5)
  [72]=>
  float(1.9E-5)
  [73]=>
  float(1.89849E-5)
  [74]=>
  float(1.897E-5)
  [75]=>
  float(1.89297E-5)
  [76]=>
  float(1.892E-5)
  [77]=>
  float(1.885E-5)
  [78]=>
  float(1.88488E-5)
  [79]=>
  float(1.88374E-5)
  [80]=>
  float(1.88351E-5)
  [81]=>
  float(1.88E-5)
  [82]=>
  float(1.87999E-5)
  [83]=>
  float(1.87998E-5)
  [84]=>
  float(1.87E-5)
  [85]=>
  float(1.868E-5)
  [86]=>
  float(1.867E-5)
  [87]=>
  float(1.866E-5)
  [88]=>
  float(1.865E-5)
  [89]=>
  float(1.864E-5)
  [90]=>
  float(1.863E-5)
  [91]=>
  float(1.86299E-5)
  [92]=>
  float(1.862E-5)
  [93]=>
  float(1.861E-5)
  [94]=>
  float(1.86E-5)
  [95]=>
  float(1.859E-5)
  [96]=>
  float(1.85899E-5)
  [97]=>
  float(1.858E-5)
  [98]=>
  float(1.85768E-5)
  [99]=>
  float(1.857E-5)
}

$bbands:
array(3) {
  [0]=>
  array(93) {
    [0]=>
    float(1.91237E-5)
    [1]=>
    float(1.91361E-5)
    [2]=>
    float(1.91533E-5)
    [3]=>
    float(1.91533E-5)
    [4]=>
    float(1.91533E-5)
    [5]=>
    float(1.91533E-5)
    [6]=>
    float(1.91533E-5)
    [7]=>
    float(1.91533E-5)
    [8]=>
    float(1.91533E-5)
    [9]=>
    float(1.91533E-5)
    [10]=>
    float(1.91533E-5)
    [11]=>
    float(1.91533E-5)
    [12]=>
    float(1.91533E-5)
    [13]=>
    float(1.91533E-5)
    [14]=>
    float(1.91533E-5)
    [15]=>
    float(1.91533E-5)
    [16]=>
    float(1.91533E-5)
    [17]=>
    float(1.91533E-5)
    [18]=>
    float(1.91533E-5)
    [19]=>
    float(1.91533E-5)
    [20]=>
    float(1.91533E-5)
    [21]=>
    float(1.91533E-5)
    [22]=>
    float(1.91533E-5)
    [23]=>
    float(1.91533E-5)
    [24]=>
    float(1.91533E-5)
    [25]=>
    float(1.91533E-5)
    [26]=>
    float(1.91533E-5)
    [27]=>
    float(1.91457E-5)
    [28]=>
    float(1.91381E-5)
    [29]=>
    float(1.91305E-5)
    [30]=>
    float(1.91228E-5)
    [31]=>
    float(1.91152E-5)
    [32]=>
    float(1.91076E-5)
    [33]=>
    float(1.91E-5)
    [34]=>
    float(1.91E-5)
    [35]=>
    float(1.91E-5)
    [36]=>
    float(1.91E-5)
    [37]=>
    float(1.90999E-5)
    [38]=>
    float(1.90999E-5)
    [39]=>
    float(1.90999E-5)
    [40]=>
    float(1.90999E-5)
    [41]=>
    float(1.91211E-5)
    [42]=>
    float(1.91114E-5)
    [43]=>
    float(1.91016E-5)
    [44]=>
    float(1.91229E-5)
    [45]=>
    float(1.91442E-5)
    [46]=>
    float(1.91656E-5)
    [47]=>
    float(1.91799E-5)
    [48]=>
    float(1.9173E-5)
    [49]=>
    float(1.91971E-5)
    [50]=>
    float(1.9194E-5)
    [51]=>
    float(1.91599E-5)
    [52]=>
    float(1.91257E-5)
    [53]=>
    float(1.90914E-5)
    [54]=>
    float(1.90643E-5)
    [55]=>
    float(1.90371E-5)
    [56]=>
    float(1.90086E-5)
    [57]=>
    float(1.90071E-5)
    [58]=>
    float(1.90057E-5)
    [59]=>
    float(1.90043E-5)
    [60]=>
    float(1.90028E-5)
    [61]=>
    float(1.90014E-5)
    [62]=>
    float(1.89999E-5)
    [63]=>
    float(1.89998E-5)
    [64]=>
    float(1.89998E-5)
    [65]=>
    float(1.89998E-5)
    [66]=>
    float(1.89977E-5)
    [67]=>
    float(1.89934E-5)
    [68]=>
    float(1.89834E-5)
    [69]=>
    float(1.8972E-5)
    [70]=>
    float(1.89506E-5)
    [71]=>
    float(1.89291E-5)
    [72]=>
    float(1.89058E-5)
    [73]=>
    float(1.88844E-5)
    [74]=>
    float(1.88601E-5)
    [75]=>
    float(1.88416E-5)
    [76]=>
    float(1.88244E-5)
    [77]=>
    float(1.8803E-5)
    [78]=>
    float(1.87789E-5)
    [79]=>
    float(1.8755E-5)
    [80]=>
    float(1.873E-5)
    [81]=>
    float(1.87085E-5)
    [82]=>
    float(1.86857E-5)
    [83]=>
    float(1.86614E-5)
    [84]=>
    float(1.86514E-5)
    [85]=>
    float(1.86428E-5)
    [86]=>
    float(1.86343E-5)
    [87]=>
    float(1.86257E-5)
    [88]=>
    float(1.86171E-5)
    [89]=>
    float(1.861E-5)
    [90]=>
    float(1.86028E-5)
    [91]=>
    float(1.85952E-5)
    [92]=>
    float(1.85881E-5)
  }
  [1]=>
  array(93) {
    [0]=>
    float(1.91237E-5)
    [1]=>
    float(1.91361E-5)
    [2]=>
    float(1.91533E-5)
    [3]=>
    float(1.91533E-5)
    [4]=>
    float(1.91533E-5)
    [5]=>
    float(1.91533E-5)
    [6]=>
    float(1.91533E-5)
    [7]=>
    float(1.91533E-5)
    [8]=>
    float(1.91533E-5)
    [9]=>
    float(1.91533E-5)
    [10]=>
    float(1.91533E-5)
    [11]=>
    float(1.91533E-5)
    [12]=>
    float(1.91533E-5)
    [13]=>
    float(1.91533E-5)
    [14]=>
    float(1.91533E-5)
    [15]=>
    float(1.91533E-5)
    [16]=>
    float(1.91533E-5)
    [17]=>
    float(1.91533E-5)
    [18]=>
    float(1.91533E-5)
    [19]=>
    float(1.91533E-5)
    [20]=>
    float(1.91533E-5)
    [21]=>
    float(1.91533E-5)
    [22]=>
    float(1.91533E-5)
    [23]=>
    float(1.91533E-5)
    [24]=>
    float(1.91533E-5)
    [25]=>
    float(1.91533E-5)
    [26]=>
    float(1.91533E-5)
    [27]=>
    float(1.91457E-5)
    [28]=>
    float(1.91381E-5)
    [29]=>
    float(1.91305E-5)
    [30]=>
    float(1.91228E-5)
    [31]=>
    float(1.91152E-5)
    [32]=>
    float(1.91076E-5)
    [33]=>
    float(1.91E-5)
    [34]=>
    float(1.91E-5)
    [35]=>
    float(1.91E-5)
    [36]=>
    float(1.91E-5)
    [37]=>
    float(1.90999E-5)
    [38]=>
    float(1.90999E-5)
    [39]=>
    float(1.90999E-5)
    [40]=>
    float(1.90999E-5)
    [41]=>
    float(1.91211E-5)
    [42]=>
    float(1.91114E-5)
    [43]=>
    float(1.91016E-5)
    [44]=>
    float(1.91229E-5)
    [45]=>
    float(1.91442E-5)
    [46]=>
    float(1.91656E-5)
    [47]=>
    float(1.91799E-5)
    [48]=>
    float(1.9173E-5)
    [49]=>
    float(1.91971E-5)
    [50]=>
    float(1.9194E-5)
    [51]=>
    float(1.91599E-5)
    [52]=>
    float(1.91257E-5)
    [53]=>
    float(1.90914E-5)
    [54]=>
    float(1.90643E-5)
    [55]=>
    float(1.90371E-5)
    [56]=>
    float(1.90086E-5)
    [57]=>
    float(1.90071E-5)
    [58]=>
    float(1.90057E-5)
    [59]=>
    float(1.90043E-5)
    [60]=>
    float(1.90028E-5)
    [61]=>
    float(1.90014E-5)
    [62]=>
    float(1.89999E-5)
    [63]=>
    float(1.89998E-5)
    [64]=>
    float(1.89998E-5)
    [65]=>
    float(1.89998E-5)
    [66]=>
    float(1.89977E-5)
    [67]=>
    float(1.89934E-5)
    [68]=>
    float(1.89834E-5)
    [69]=>
    float(1.8972E-5)
    [70]=>
    float(1.89506E-5)
    [71]=>
    float(1.89291E-5)
    [72]=>
    float(1.89058E-5)
    [73]=>
    float(1.88844E-5)
    [74]=>
    float(1.88601E-5)
    [75]=>
    float(1.88416E-5)
    [76]=>
    float(1.88244E-5)
    [77]=>
    float(1.8803E-5)
    [78]=>
    float(1.87789E-5)
    [79]=>
    float(1.8755E-5)
    [80]=>
    float(1.873E-5)
    [81]=>
    float(1.87085E-5)
    [82]=>
    float(1.86857E-5)
    [83]=>
    float(1.86614E-5)
    [84]=>
    float(1.86514E-5)
    [85]=>
    float(1.86428E-5)
    [86]=>
    float(1.86343E-5)
    [87]=>
    float(1.86257E-5)
    [88]=>
    float(1.86171E-5)
    [89]=>
    float(1.861E-5)
    [90]=>
    float(1.86028E-5)
    [91]=>
    float(1.85952E-5)
    [92]=>
    float(1.85881E-5)
  }
  [2]=>
  array(93) {
    [0]=>
    float(1.91237E-5)
    [1]=>
    float(1.91361E-5)
    [2]=>
    float(1.91533E-5)
    [3]=>
    float(1.91533E-5)
    [4]=>
    float(1.91533E-5)
    [5]=>
    float(1.91533E-5)
    [6]=>
    float(1.91533E-5)
    [7]=>
    float(1.91533E-5)
    [8]=>
    float(1.91533E-5)
    [9]=>
    float(1.91533E-5)
    [10]=>
    float(1.91533E-5)
    [11]=>
    float(1.91533E-5)
    [12]=>
    float(1.91533E-5)
    [13]=>
    float(1.91533E-5)
    [14]=>
    float(1.91533E-5)
    [15]=>
    float(1.91533E-5)
    [16]=>
    float(1.91533E-5)
    [17]=>
    float(1.91533E-5)
    [18]=>
    float(1.91533E-5)
    [19]=>
    float(1.91533E-5)
    [20]=>
    float(1.91533E-5)
    [21]=>
    float(1.91533E-5)
    [22]=>
    float(1.91533E-5)
    [23]=>
    float(1.91533E-5)
    [24]=>
    float(1.91533E-5)
    [25]=>
    float(1.91533E-5)
    [26]=>
    float(1.91533E-5)
    [27]=>
    float(1.91457E-5)
    [28]=>
    float(1.91381E-5)
    [29]=>
    float(1.91305E-5)
    [30]=>
    float(1.91228E-5)
    [31]=>
    float(1.91152E-5)
    [32]=>
    float(1.91076E-5)
    [33]=>
    float(1.91E-5)
    [34]=>
    float(1.91E-5)
    [35]=>
    float(1.91E-5)
    [36]=>
    float(1.91E-5)
    [37]=>
    float(1.90999E-5)
    [38]=>
    float(1.90999E-5)
    [39]=>
    float(1.90999E-5)
    [40]=>
    float(1.90999E-5)
    [41]=>
    float(1.91211E-5)
    [42]=>
    float(1.91114E-5)
    [43]=>
    float(1.91016E-5)
    [44]=>
    float(1.91229E-5)
    [45]=>
    float(1.91442E-5)
    [46]=>
    float(1.91656E-5)
    [47]=>
    float(1.91799E-5)
    [48]=>
    float(1.9173E-5)
    [49]=>
    float(1.91971E-5)
    [50]=>
    float(1.9194E-5)
    [51]=>
    float(1.91599E-5)
    [52]=>
    float(1.91257E-5)
    [53]=>
    float(1.90914E-5)
    [54]=>
    float(1.90643E-5)
    [55]=>
    float(1.90371E-5)
    [56]=>
    float(1.90086E-5)
    [57]=>
    float(1.90071E-5)
    [58]=>
    float(1.90057E-5)
    [59]=>
    float(1.90043E-5)
    [60]=>
    float(1.90028E-5)
    [61]=>
    float(1.90014E-5)
    [62]=>
    float(1.89999E-5)
    [63]=>
    float(1.89998E-5)
    [64]=>
    float(1.89998E-5)
    [65]=>
    float(1.89998E-5)
    [66]=>
    float(1.89977E-5)
    [67]=>
    float(1.89934E-5)
    [68]=>
    float(1.89834E-5)
    [69]=>
    float(1.8972E-5)
    [70]=>
    float(1.89506E-5)
    [71]=>
    float(1.89291E-5)
    [72]=>
    float(1.89058E-5)
    [73]=>
    float(1.88844E-5)
    [74]=>
    float(1.88601E-5)
    [75]=>
    float(1.88416E-5)
    [76]=>
    float(1.88244E-5)
    [77]=>
    float(1.8803E-5)
    [78]=>
    float(1.87789E-5)
    [79]=>
    float(1.8755E-5)
    [80]=>
    float(1.873E-5)
    [81]=>
    float(1.87085E-5)
    [82]=>
    float(1.86857E-5)
    [83]=>
    float(1.86614E-5)
    [84]=>
    float(1.86514E-5)
    [85]=>
    float(1.86428E-5)
    [86]=>
    float(1.86343E-5)
    [87]=>
    float(1.86257E-5)
    [88]=>
    float(1.86171E-5)
    [89]=>
    float(1.861E-5)
    [90]=>
    float(1.86028E-5)
    [91]=>
    float(1.85952E-5)
    [92]=>
    float(1.85881E-5)
  }
}

Is this a bug or a problem with the dataset?
 [2019-03-27 05:03 UTC] php at solomon dot web dot za
Also worth adding:

$vals = array(400,500,600,700,800,900,1000,900,750,900,736,852,999);

results in expected values:
Array
(
    [0] => Array
        (
            [0] => 1104.6258225626
            [1] => 1060.2863592381
            [2] => 1042.7248223319
            [3] => 1032.9241949757
            [4] => 1034.7734930782
            [5] => 1073.4090144859
        )

    [1] => Array
        (
            [0] => 771.4285714286
            [1] => 807.1428571429
            [2] => 850
            [3] => 855.1428571429
            [4] => 862.5714285714
            [5] => 876.7142857143
        )

    [2] => Array
        (
            [0] => 438.2313202946
            [1] => 553.9993550476
            [2] => 657.2751776681
            [3] => 677.36151931
            [4] => 690.3693640646
            [5] => 680.0195569427
        )

)

and dividing the dataset by 100000000:
$vals = array(0.00000400,0.00000500,0.00000600,0.00000700,0.00000800,0.00000900,0.000001000,0.00000900,0.00000750,0.00000900,0.00000736,0.00000852,0.00000999);

results in the same bug:
Array
(
    [0] => Array
        (
            [0] => 6.4286E-6
            [1] => 6.7857E-6
            [2] => 7.2143E-6
            [3] => 7.2657E-6
            [4] => 7.34E-6
            [5] => 7.4814E-6
        )

    [1] => Array
        (
            [0] => 6.4286E-6
            [1] => 6.7857E-6
            [2] => 7.2143E-6
            [3] => 7.2657E-6
            [4] => 7.34E-6
            [5] => 7.4814E-6
        )

    [2] => Array
        (
            [0] => 6.4286E-6
            [1] => 6.7857E-6
            [2] => 7.2143E-6
            [3] => 7.2657E-6
            [4] => 7.34E-6
            [5] => 7.4814E-6
        )

)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Oct 18 10:01:27 2019 UTC