JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 248
  • Score
    100M100P100Q119538F
  • License MIT

Package Exports

  • ohlc

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ohlc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ohlc

npm version npm Build Status

Major update for version 2

install

node.js

npm install ohlc
var ohlc = require('ohlc')

Browser

<script src="dist/ohlc.js"></script>

CDN

<script src="https://cdn.jsdelivr.net/npm/ohlc"></script>

<script src="https://cdn.jsdelivr.net/gh/mick-whats/ohlc-node@2.0.1/dist/ohlc.js"></script>

sumple data

arrayData = [
  ["2017-01-04",348,350,346,350,68700],
  ["2017-01-05",350,353,349,352,59200],
  ["2017-01-06",350,358,350,356,168900]
]

toDaily()

output to daily data

ohlc(arrayData).toDaily();
/// result 
[
  ...
  {
    "Date": '2017-04-03',
    Open: 352,
    High: 352,
    Low: 348,
    Close: 348,
    Volume: 108200
  }
  ...
]

toWeekly()

output to weekly data

ohlc(arrayData).toWeekly();
/// result 
[
  ...
  {
    "Date": '2017-04-02',
    Open: 352,
    High: 352,
    Low: 338,
    Close: 339,
    Volume: 379400
  }
  ...
]

toMonthly

output to monthly data

ohlc(arrayData).toMonthly();
/// result 
[
  ...
  {
    "Date": '2017-04-01',
    Open: 352,
    High: 370,
    Low: 330,
    Close: 357,
    Volume: 1514900
  }
  ...
]

value(period)

output data

// daily
ohlc(arrayData).value()
// equal toDaily
ohlc(arrayData).toDaily()

// weekly
ohlc(arrayData).value('weekly')
// equal toWeekly
ohlc(arrayData).toWeekly()

// monthly
ohlc(arrayData).value('monthly')
// equal toMonthly
ohlc(arrayData).toMonthly()

toChartData(period)

It complies with high charts

Candlestick | Highcharts
https://www.highcharts.com/samples/data/aapl-ohlc.json

var chartData = ohlc(arrayData).sma(5, 25).toChartData();

Object.keys(chartData)
//=> ['candle', 'volume', 'sma5', 'sma25']

chartData.candle[90]
//=> [1494979200000, 370, 372, 365, 369]
chartData.volume[90]
//=> [1494979200000, 32300]
chartData.sma5[90]
//=> [1494979200000, 372]
chartData.sma25[90]
//=> [1494979200000, 359]
moment.utc(1494979200000).format('YYYY-MM-DD')
//=> '2017-05-17'

start() and end()

Set the output period

prices = ohlc(arrayData).toDaily();
/// prices.length is 101

prices = ohlc(arrayData).start('2017-04-03').toDaily();
/// prices.length is 40

prices = ohlc(arrayData).end('2017-04-10').toDaily();
/// prices.length is 67

prices = ohlc(arrayData).start('2017-04-03').end('2017-04-10').toDaily();
/// prices.length is 6

sma

This will add sma(simple MA)

ohlc(arrayData).sma(5, 25, 75).toDaily();
/// result
[
  ...
  {
    Date: '2017-05-31',
    Open: 372,
    High: 372,
    Low: 362,
    Close: 364,
    Volume: 46500,
    sma5: 373,
    sma25: 373,
    sma75: 360
  }
  ...
]