Run tests and coverage reports
masterUse the following commands to execute the test suite and generate code coverage reports.
npm test
npm run coverrepository·master·Indexed 25 days ago
https://github.com/anandanand84/technicalindicatorsA TypeScript-based JavaScript library for financial data analysis, providing a wide range of technical analysis indicators (such as SMA, RSI, MACD), candlestick pattern detection, and chart types like Heikin-Ashi and Renko. It supports both static computation via the calculate method and real-time streaming data via the nextValue method. Version 3.1.0.
Use the following commands to execute the test suite and generate code coverage reports.
npm test
npm run coverTo use the library in a Node.js environment (version 10 or higher), install it using npm:
npm install --save technicalindicatorsNote for Node.js versions < 10: You must use version 1.x of the library.
To prevent max call stack reached errors when working with this project, it is recommended to use TypeScript version 2.0.0.
npm install -g typescript@2.0.0To set up a local development environment, clone the repository, navigate to the directory, and start the project.
git clone git@github.com:anandanand84/technicalindicators.git
cd technicalindicators
npm run startTo check the status of the documentation, run the documentation test script and open the generated HTML file in your browser.
node testdocs.js
open "http://localhost:5444/testdocs.html"Follow these steps to implement and integrate a new technical indicator:
index.js and src/index.ts.npm run build-lib && npm run generateDts && npm run startREADME.md with a link to a Runkit URL containing a usage sample.keywords section in package.json and bower.json.TechnicalIndicators depends on the canvas package. To avoid installation errors (such as pkg-config: command not found or node-gyp rebuild failures), you must install the system dependencies required by node-canvas on your operating system.
Refer to the node-canvas installation guide for your specific platform to ensure all required libraries are present before running npm install.
Install via npm and include the ES6 distribution file:
npm install --save technicalindicators<script src="node_modules/technicalindicators/dist/browser.es6.js"></script>For ES5 support, you must include babel-polyfill and the standard browser.js file:
npm install --save technicalindicators
npm install --save babel-polyfill<script src="node_modules/babel-polyfill/browser.js"></script>
<script src="node_modules/technicalindicators/dist/browser.js"></script>Once loaded, all indicators are available on the window object. You can call them directly or via their class names:
// Direct function call
sma({period : 5, values : [1,2,3,4,5,6,7,8,9], reversedInput : true});
// Or via the class
SMA.calculate({period : 5, values : [1,2,3,4,5,6,7,8,9]});The library uses standard JavaScript numbers, which can lead to negligible rounding errors in technical indicators. You can set a global precision level using setConfig.
const technicalIndicators = require('technicalindicators');
technicalIndicators.setConfig('precision', 10);If you are using Webpack, ensure your configuration includes the following resolve setting to correctly handle module fields:
module.exports = {
resolve: {
mainFields: ["module", "main"]
}
}You can detect if a set of candlestick data matches bullish or bearish patterns using the bullish or bearish properties of the library. The input should be an object containing arrays for open, high, close, and low values.
var twoDayBullishInput = {
open: [23.25,15.36],
high: [25.10,30.87],
close: [21.44,27.89],
low: [20.82,14.93],
}
var bullish = require('technicalindicators').bullish;
bullish(twoDayBullishInput) // returns true if pattern is bullishWarning: Pattern detection was removed from version 3.0. If you require pattern detection, you must use version 2.0.
var twoDayBullishInput = {
open: [23.25,15.36],
high: [25.10,30.87],
close: [21.44,27.89],
low: [20.82,14.93],
}
var bullish = require('technicalindicators').bullish;
bullish(twoDayBullishInput) //trueThe getResult method is a combination of calculate and nextValue. It is typically used in a three-step workflow:
getResult() to get the results for those initial values.nextValue() to process subsequent incoming ticks.Note: Calling nextValue() does not update the value returned by a previous getResult() call.
var sma = new SMA({period : period, values : prices});
sma.getResult(); // [5.5, 6.6, 7.7, 8.9]
sma.nextValue(16); // 10.1