technicalindicators

repository·master·Indexed 25 days ago

https://github.com/anandanand84/technicalindicators

A 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.

Tokens
6.4K
Snippets
12
Records
52
Agent score
82%

What's inside technicalindicators

  1. Add a new indicator to the library

    master

    Follow these steps to implement and integrate a new technical indicator:

    1. Write Tests: Create tests for the new indicator and ensure they pass (using stockcharts excel samples is recommended).
    2. Register Indicator: Add the indicator to index.js and src/index.ts.
    3. Build: Run the build scripts to compile the library and generate type definitions: npm run build-lib && npm run generateDts && npm run start
    4. Document: Update README.md with a link to a Runkit URL containing a usage sample.
    5. Metadata: Add the indicator name to the keywords section in package.json and bower.json.
    6. Submit: Send a Pull Request.
  2. Install and use technicalindicators in the Browser

    master

    ES6 Browsers

    Install via npm and include the ES6 distribution file:

    npm install --save technicalindicators
    <script src="node_modules/technicalindicators/dist/browser.es6.js"></script>

    ES5 Browsers

    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]});
  3. Configure indicator precision

    master

    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);
  4. Detect bullish or bearish candlestick patterns

    master

    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 bullish

    Warning: 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) //true
  5. Use `getResult` to combine initial calculation and streaming

    master

    The getResult method is a combination of calculate and nextValue. It is typically used in a three-step workflow:

    1. Initialize the indicator with existing historical price values.
    2. Call getResult() to get the results for those initial values.
    3. Use 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