{"id":13623282,"url":"https://github.com/bennycode/trading-signals","last_synced_at":"2025-05-14T11:09:28.691Z","repository":{"id":38180690,"uuid":"267563398","full_name":"bennycode/trading-signals","owner":"bennycode","description":"Technical indicators to run technical analysis with JavaScript \u0026 TypeScript. 📈","archived":false,"fork":false,"pushed_at":"2025-04-01T01:33:04.000Z","size":5532,"stargazers_count":693,"open_issues_count":5,"forks_count":101,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-04T11:40:03.885Z","etag":null,"topics":["analysis","cryptotrading","dema","dma","ema","financial","financial-analysis","hacktoberfest","indicator","macd","roc","rsi","signals","sma","smma","technical-analysis","technical-indicators","trading","trading-signals","typescript"],"latest_commit_sha":null,"homepage":"https://bennycode.com/trading-signals","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bennycode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bennycode","ko_fi":"bennycode"}},"created_at":"2020-05-28T10:44:05.000Z","updated_at":"2025-04-01T23:16:26.000Z","dependencies_parsed_at":"2023-02-04T02:02:38.026Z","dependency_job_id":"f6616e18-c852-45aa-8a86-f1fd420ff1ab","html_url":"https://github.com/bennycode/trading-signals","commit_stats":{"total_commits":655,"total_committers":8,"mean_commits":81.875,"dds":0.6870229007633588,"last_synced_commit":"dd1413aebc0b306fc2b95e404d49ba5044d5ce7d"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":"bennycode/ts-node-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennycode%2Ftrading-signals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennycode%2Ftrading-signals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennycode%2Ftrading-signals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennycode%2Ftrading-signals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bennycode","download_url":"https://codeload.github.com/bennycode/trading-signals/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248448375,"owners_count":21105286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analysis","cryptotrading","dema","dma","ema","financial","financial-analysis","hacktoberfest","indicator","macd","roc","rsi","signals","sma","smma","technical-analysis","technical-indicators","trading","trading-signals","typescript"],"created_at":"2024-08-01T21:01:29.888Z","updated_at":"2025-05-14T11:09:28.679Z","avatar_url":"https://github.com/bennycode.png","language":"TypeScript","readme":"# Trading Signals\n\n![Language Details](https://img.shields.io/github/languages/top/bennycode/trading-signals) ![Code Coverage](https://img.shields.io/codecov/c/github/bennycode/trading-signals/main) ![License](https://img.shields.io/npm/l/trading-signals.svg) ![Package Version](https://img.shields.io/npm/v/trading-signals.svg)\n\nTechnical indicators and overlays to run technical analysis with JavaScript / TypeScript.\n\n## Motivation\n\nThe \"trading-signals\" library provides a TypeScript implementation for common technical indicators with arbitrary-precision decimal arithmetic.\n\nThe main focus of this library is on the accuracy of calculations, but using the provided [faster implementations][2] you can also use it where performance is important.\n\nAll indicators can be updated over time by streaming data (prices or [candles](https://en.wikipedia.org/wiki/Candlestick_chart)) to the `add` method. Some indicators also provide `static` batch methods for further performance improvements when providing data up-front during a backtest or historical data import. You can try it out streaming input data by running the provided [demo script](./src/start/demo.ts) with `npm start`, which uses a keyboard input stream.\n\n## Installation\n\n```bash\nnpm install trading-signals\n```\n\n## Usage\n\n**CommonJS:**\n\n```ts\nconst {Big, SMA} = require('trading-signals');\n```\n\n**ESM:**\n\n```ts\nimport {Big, SMA} from 'trading-signals';\n```\n\n**Example:**\n\n```typescript\nimport {Big, SMA} from 'trading-signals';\n\nconst sma = new SMA(3);\n\n// You can add values individually:\nsma.add(40);\nsma.add(30);\nsma.add(20);\n\n// You can add multiple values at once:\nsma.updates([20, 40, 80]);\n\n// You can add stringified values:\nsma.add('10');\n\n// You can replace a previous value (useful for live charting):\nsma.replace('40');\n\n// You can add arbitrary-precision decimals:\nsma.add(new Big(30.0009));\n\n// You can check if an indicator is stable:\nconsole.log(sma.isStable); // true\n\n// If an indicator is stable, you can get its result:\nconsole.log(sma.getResult()?.toFixed()); // \"50.0003\"\n\n// You can also get the result without optional chaining:\nconsole.log(sma.getResultOrThrow().toFixed()); // \"50.0003\"\n\n// Various precisions are available too:\nconsole.log(sma.getResultOrThrow().toFixed(2)); // \"50.00\"\nconsole.log(sma.getResultOrThrow().toFixed(4)); // \"50.0003\"\n\n// Each indicator also includes convenient features such as \"lowest\" and \"highest\" lifetime values:\nconsole.log(sma.lowest?.toFixed(2)); // \"23.33\"\nconsole.log(sma.highest?.toFixed(2)); // \"53.33\"\n```\n\n### When to use `add(...)`?\n\nTo input data, you need to call the indicator's `add` method. Depending on whether the minimum required input data for the interval has been reached, the `add` method may or may not return a result from the indicator.\n\n### When to use `getResultOrThrow()`?\n\nYou can call `getResultOrThrow()` at any point in time, but it throws errors unless an indicator has received the minimum amount of data. If you call `getResultOrThrow()`, before an indicator has received the required amount of input values, a `NotEnoughDataError` will be thrown.\n\n**Example:**\n\n```ts\nimport {SMA} from 'trading-signals';\n\n// Our interval is 3, so we need 3 input values\nconst sma = new SMA(3);\n\n// We supply 2 input values\nsma.update(10);\nsma.update(40);\n\ntry {\n  // We will get an error, because the minimum amount of inputs is 3\n  sma.getResultOrThrow();\n} catch (error) {\n  console.log(error.constructor.name); // \"NotEnoughDataError\"\n}\n\n// We will supply the 3rd input value\nsma.update(70);\n\n// Now, we will receive a proper result\nconsole.log(sma.getResultOrThrow().valueOf()); // \"40\"\n```\n\nMost of the time, the minimum amount of data depends on the interval / time period used.\n\n## Technical Indicator Types\n\n- Trend indicators: Measure the direction of a trend (uptrend, downtrend or sideways trend)\n- Volume indicators: Measure the strength of a trend (based on volume)\n- Volatility indicators: Measure how much disagreement there is in the market based on price (statistical measure of its dispersion)\n- Momentum indicators: Measure the strength of a trend (based on price / speed of price movement)\n\n## Supported Technical Indicators\n\n1. [Acceleration Bands](./src/ABANDS/AccelerationBands.ts) (ABANDS)\n1. [Accelerator Oscillator](./src/AC/AC.ts) (AC)\n1. [Average Directional Index](./src/ADX/ADX.ts) (ADX)\n1. [Average True Range](./src/ATR/ATR.ts) (ATR)\n1. [Awesome Oscillator](./src/AO/AO.ts) (AO)\n1. [Bollinger Bands](./src/BBANDS/BollingerBands.ts) (BBANDS)\n1. [Bollinger Bands Width](./src/BBW/BollingerBandsWidth.ts) (BBW)\n1. [Center of Gravity](./src/CG/CG.ts) (CG)\n1. [Commodity Channel Index](./src/CCI/CCI.ts) (CCI)\n1. [Directional Movement Index](./src/DX/DX.ts) (DMI / DX)\n1. [Double Exponential Moving Average](./src/DEMA/DEMA.ts) (DEMA)\n1. [Dual Moving Average](./src/DMA/DMA.ts) (DMA)\n1. [Exponential Moving Average](./src/EMA/EMA.ts) (EMA)\n1. [Interquartile Range](./src/IQR/IQR.ts) (IQR)\n1. [Linear Regression](./src/LINREG/LinearRegression.ts) (LINREG)\n1. [Mean Absolute Deviation](./src/MAD/MAD.ts) (MAD)\n1. [Momentum](./src/MOM/MOM.ts) (MOM / MTM)\n1. [Moving Average Convergence Divergence](./src/MACD/MACD.ts) (MACD)\n1. [On-Balance Volume](./src/OBV/OBV.ts) (OBV)\n1. [Parabolic SAR](./src/PSAR/PSAR.ts) (PSAR)\n1. [Rate-of-Change](./src/ROC/ROC.ts) (ROC)\n1. [Relative Moving Average](./src/RMA/RMA.ts) (RMA)\n1. [Relative Strength Index](./src/RSI/RSI.ts) (RSI)\n1. [Simple Moving Average](./src/SMA/SMA.ts) (SMA)\n1. [Stochastic Oscillator](./src/STOCH/StochasticOscillator.ts) (STOCH)\n1. [Stochastic RSI](./src/STOCH/StochasticRSI.ts) (STOCHRSI)\n1. [Tom Demark's Sequential Indicator](./src/TDS/TDS.ts) (TDS)\n1. [True Range](./src/TR/TR.ts) (TR)\n1. [Weighted Moving Average](./src/WMA/WMA.ts) (WMA)\n1. [Wilder's Smoothed Moving Average](./src/WSMA/WSMA.ts) (WSMA / WWS / SMMA / MEMA)\n\nUtility Methods:\n\n1. [Average / Mean](./src/util/getAverage.ts)\n1. [Median](./src/util/getMedian.ts)\n1. [Quartile](./src/util/getQuartile.ts)\n1. [Standard Deviation](./src/util/getStandardDeviation.ts)\n1. [Streaks](./src/util/getStreaks.ts)\n\n## Performance\n\n### Arbitrary-precision decimal arithmetic\n\nJavaScript is very bad with numbers. When calculating `0.1 + 0.2` it shows you `0.30000000000000004`, but the truth is `0.3`.\n\n![JavaScript arithmetic](https://raw.githubusercontent.com/bennycode/trading-signals/HEAD/js-arithmetic.png)\n\nAs specified by the ECMAScript standard, all arithmetic in JavaScript uses [double-precision floating-point arithmetic](https://en.wikipedia.org/wiki/Double-precision_floating-point_format), which is only accurate until certain extent. To increase the accuracy and avoid miscalculations, the [trading-signals](https://github.com/bennycode/trading-signals) library uses [big.js][1] which offers arbitrary-precision decimal arithmetic. However, this arbitrary accuracy comes with a downside: Calculations with it are not as performant as with the primitive data type `number`.\n\n### Faster implementations\n\nTo get the best of both worlds (high accuracy \u0026 high performance), you will find two implementations of each indicator (e.g. `SMA` \u0026 `FasterSMA`). The standard implementation uses [big.js][1] and the `Faster`-prefixed version uses common `number` types. Use the standard one when you need high accuracy and use the `Faster`-one when you need high performance:\n\n```ts\nimport {FasterSMA} from './SMA/SMA';\n\nconst fasterSMA = new FasterSMA(5);\nconsole.log(fasterSMA.updates([1, 2, 3, 4, 5]));\n```\n\n```ts\nimport {FasterStochasticRSI, FasterSMA} from 'trading-signals';\n\nconst fasterStochRSI = new FasterStochasticRSI(3, FasterSMA);\nfasterStochRSI.update(1);\nfasterStochRSI.update(2);\nfasterStochRSI.update(3);\nfasterStochRSI.update(4);\nfasterStochRSI.update(5);\nfasterStochRSI.update(6);\n\nconsole.log(fasterStochRSI.getResultOrThrow());\n```\n\n### Benchmarks\n\nYou can run `npm run start:benchmark` to see the runtime performance of each technical indicator on your machine. This will give you an understanding of which indicators can be calculated faster than others.\n\n## Disclaimer\n\nThe information and publications of [trading-signals](https://github.com/bennycode/trading-signals) do not constitute financial advice, investment advice, trading advice or any other form of advice. All results from [trading-signals](https://github.com/bennycode/trading-signals) are intended for information purposes only.\n\nIt is very important to do your own analysis before making any investment based on your own personal circumstances. If you need financial advice or further advice in general, it is recommended that you identify a relevantly qualified individual in your jurisdiction who can advise you accordingly.\n\n## Alternatives\n\n- [Cloud9Trader Indicators (JavaScript)](https://github.com/Cloud9Trader/TechnicalIndicators)\n- [Crypto Trading Hub Indicators (TypeScript)](https://github.com/anandanand84/technicalindicators)\n- [Indicator TS](https://github.com/cinar/indicatorts)\n- [Jesse Trading Bot Indicators (Python)](https://docs.jesse.trade/docs/indicators/reference.html)\n- [LEAN Indicators](https://github.com/QuantConnect/Lean/tree/master/Indicators)\n- [libindicators (C#)](https://github.com/mgfx/libindicators)\n- [Pandas TA (Python)](https://github.com/twopirllc/pandas-ta)\n- [ta4j (Java)](https://github.com/ta4j/ta4j)\n- [Technical Analysis for Rust (Rust)](https://github.com/greyblake/ta-rs)\n- [Technical Analysis Library using Pandas and Numpy (Python)](https://github.com/bukosabino/ta)\n- [Tulip Indicators (ANSI C)](https://github.com/TulipCharts/tulipindicators)\n\n## Maintainers\n\n[![Benny Neugebauer on Stack Exchange][stack_exchange_bennycode_badge]][stack_exchange_bennycode_url]\n\n## ⭐️ Become a TypeScript rockstar! ⭐️\n\nThis package was built by Benny Code. Checkout my [**TypeScript course**](https://typescript.tv/) to become a coding rockstar!\n\n[\u003cimg src=\"https://raw.githubusercontent.com/bennycode/trading-signals/main/tstv.png\"\u003e](https://typescript.tv/)\n\n[1]: http://mikemcl.github.io/big.js/\n[2]: #faster-implementations\n[stack_exchange_bennycode_badge]: https://stackexchange.com/users/flair/203782.png?theme=default\n[stack_exchange_bennycode_url]: https://stackexchange.com/users/203782/benny-neugebauer?tab=accounts\n\n## License\n\nThis project is [MIT](./LICENSE) licensed.\n","funding_links":["https://github.com/sponsors/bennycode","https://ko-fi.com/bennycode"],"categories":["TypeScript","Packages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbennycode%2Ftrading-signals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbennycode%2Ftrading-signals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbennycode%2Ftrading-signals/lists"}