PHP code example of kenshodigital / chart

1. Go to this page and download the library: Download kenshodigital/chart library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kenshodigital / chart example snippets


 declare(strict_types=1);

use Kensho\Chart\Chart\ChartFactory;

$chart = ChartFactory::bootstrap([
    '2023-01-25' => [
        'open'   => '140.8900',
        'high'   => '142.4300',
        'low'    => '138.8100',
        'close'  => '141.8600',
        'volume' => '65799349',
    ],
    '2023-01-26' => [
        'open'   => '143.1700',
        'high'   => '144.2500',
        'low'    => '141.9000',
        'close'  => '143.9600',
        'volume' => '54105068',
    ],
    // ...
]);

$period = 7;
$result = $chart->getSMA($period);

// '2023-01-25' => null,
// '2023-01-26' => null,
// ...
// '2023-02-02' => '145.0414',
// '2023-02-03' => '146.8471',
// ...

$period = 7;
$result = $chart->getEMA($period);

// '2023-01-25' => null,
// '2023-01-26' => null,
// ...
// '2023-02-02' => '145.6779',
// '2023-02-03' => '147.8834',
// ...

$period = 7;
$result = $chart->getDI($period);

// '2023-01-25' => [
//     'DIp' => null,
//     'DIm' => null,
// ],
// '2023-01-26' => [
//     'DIp' => null,
//     'DIm' => null, 
// ],
// ...
// '2023-02-02' => [
//     'DIp' => '44.1913',
//     'DIm' =>  '3.0372',
// ],
// '2023-02-03' => [
//     'DIp' => '50.3535',
//     'DIm' =>  '2.1344',
// ],
// ...

$period = 7;
$result = $chart->getADX($period);

// '2023-01-25' => null,
// '2023-01-26' => null,
// ...
// '2023-02-10' => '85.4433',
// '2023-02-13' => '83.2376',
// ...

$SMAPeriod = 20
$EMAPeriod = 10;
$result    = $chart->getTrend($SMAPeriod, $EMAPeriod);

// '2023-01-25' => [
//     'close' => '141.8600',
//     'SMA'   => null,
//     'EMA'   => null,
//     'DIp'   => null,
//     'DIm'   => null,
//     'ADX'   => null,
// ],
// ...
// '2023-02-07' => [
//     'close' => '154.6500',
//     'SMA'   => null,
//     'EMA'   => '148.8578',
//     'DIp'   =>  '45.1810',
//     'DIm'   =>   '1.8100',
//     'ADX'   => null,
// ],
// ...
// '2023-02-22' => [
//     'close' => '148.9100',
//     'SMA'   => '149.8000',
//     'EMA'   => '151.0938',
//     'DIp'   =>  '28.7024',
//     'DIm'   =>  '18.6931',
//     'ADX'   =>  '67.8187',
// ],
// ...