### Project Setup and Start
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Clones the project repository and starts the development server. Assumes Git is installed and accessible.
```bash
git clone git@github.com:anandanand84/technicalindicators.git # or use your fork
cd technicalindicators
npm run start
```
--------------------------------
### Build and Start Scripts
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Runs the build process for libraries, generates TypeScript definition files, and starts the application. These commands are part of adding new indicators.
```bash
npm run build-lib && npm run generateDts && npm run start
```
--------------------------------
### Monaco Editor Setup and Indicator Usage
Source: https://github.com/anandanand84/technicalindicators/blob/master/index.html
Initializes Monaco Editor with TypeScript support, loads custom type definitions for technical indicators, and sets up an editor instance with example code for financial analysis.
```javascript
var editor;
require.config({
paths: { 'vs': 'http://unpkg.com/monaco-editor@0.8.3/min/vs' }
});
require(['vs/editor/editor.main'], function() {
fetch('/declarations/generated.d.ts', {
method: 'get'
}).then(function(response) {
return response.text()
}).then(function(content) {
var technicalIndicators = content.replace(new RegExp('default ', 'g'), '').split('export').join('declare');
var disposable = monaco.languages.typescript.typescriptDefaults.addExtraLib(technicalIndicators, 'indicators.d.ts');
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES5,
noEmit: true,
allowNonTsExtensions: true
});
editor = monaco.editor.create(container, {
value: "//Try indicators and check console\nvar result = sma({period : 3 , values: [1,2,3,4,5,6,7,8,9]});\nconsole.log(result)\nvar closes = [ 0.0157284, 0.01611, 0.014443, 0.0140176, 0.0162684, 0.01613634, 0.01558049, 0.01575501, 0.0149112, 0.01480108, 0.01480001, 0.01525985, 0.01544233, 0.0144598, 0.01382822, 0.01279583, 0.01175, 0.01159958, 0.01178, 0.011123, 0.01112922, 0.0114, 0.01355, 0.01349045, 0.01959994, 0.02218001, 0.02176, 0.0198301, 0.02487826, 0.0318, 0.03004005, 0.034, 0.029, 0.02906306, 0.02996344, 0.0292, 0.0273099, 0.0275, 0.02503347, 0.0271993, 0.0266, 0.0265, 0.02726001, 0.02685, 0.0265, 0.0268, 0.0269025, 0.02852501, 0.02662222, 0.02720729, 0.0259492, 0.02567084, 0.0248122, 0.025123, 0.024644, 0.0238, 0.02408784, 0.02440999, 0.02427949, 0.024021, 0.02407001, 0.02427055, 0.02346, 0.02274575, 0.02210346, 0.0212, 0.02076246, 0.02156947, 0.0213, 0.02118064, 0.02085065, 0.02060162, 0.01941197, 0.01783183, 0.01811, 0.01816038, 0.016, 0.01687994, 0.0170935, 0.016696, 0.01663758, 0.01619777, 0.0160149, 0.01546081, 0.01501212, 0.01469499, 0.01445, 0.01416607, 0.016, 0.01524071, 0.014998, 0.01499313, 0.01497, 0.01436, 0.0145, 0.0135, 0.01263481, 0.0118519, 0.01220291, 0.01179555, 0.0117713, 0.01457129, 0.01394975, 0.01517396, 0.0169575, 0.015952, 0.01888341, 0.02120348, 0.01891419, 0.01837705, 0.01660662, 0.01534076, 0.01578865, 0.01702121, 0.01630797, 0.01697012, 0.01717741, 0.01928742, 0.0203, 0.01962058, 0.01939301, 0.01731557, 0.01740172, 0.01840138, 0.01764544, 0.01723999, 0.017402, 0.01740637, 0.01727272, 0.0177303, 0.0206, 0.022, 0.01559999, 0.01760001, 0.0177798, 0.01605, 0.01609146, 0.01701004, 0.01865633, 0.0198699, 0.01789293, 0.0168, 0.0175003, 0.01927, 0.02048543, 0.02748999, 0.02645733, 0.02509375, 0.0251825, 0.0242558, 0.02430792, 0.02225683, 0.02369875, 0.02488625, 0.02466, 0.02448999, 0.02422329, 0.02498978, 0.02559, 0.02515339, 0.0254, 0.02109999, 0.0209001 ];
var pattern = await predictPattern({ values : closes });
var hs = await hasHeadAndShoulder({ values : closes });
var ihs = await hasInverseHeadAndShoulder({ values : closes });
var db = await hasDoubleBottom({ values : closes });
var dt = await hasDoubleTop({ values : closes });
var tu = await isTrendingUp({ values : closes });
var td = await isTrendingDown({ values : closes });
console.log('Pattern ' , pattern)
console.log('hasHeadAndShoulder ', hs)
console.log('hasInverseHeadAndShoulder ', ihs)
console.log('hasDoubleBottom ' , db)
console.log('hasDoubleTop ' , dt)
console.log('isTrendingUp ' , tu)
console.log('isTrendingDown ' , td)
",
fontSize: 12,
emptySelectionClipboard: false,
formatOnType: true,
formatOnPaste: true,
parameterHints: true,
language: 'typescript'
});
window.addEventListener('resize', function() {
editor.layout();
});
})
});
```
```typescript
// Example usage within the editor:
// var result = sma({period : 3 , values: [1,2,3,4,5,6,7,8,9]});
// console.log(result)
// var closes = [ ... ];
// var pattern = await predictPattern({ values : closes });
// console.log('Pattern ' , pattern)
```
--------------------------------
### Install TechnicalIndicators via npm
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Installs the technicalindicators library for Node.js projects using npm. This command adds the package as a dependency to your project.
```bash
npm install --save technicalindicators
```
--------------------------------
### Canvas Dependency Error Example
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Illustrates a common error message encountered during the installation of the 'canvas' package if its underlying system dependencies are not met. It shows the output from 'node-gyp rebuild'.
```bash
> canvas@1.6.6 install /Users/balupton/Projects/trading/technicalindicators/node_modules/canvas
> node-gyp rebuild
./util/has_lib.sh: line 31: pkg-config: command not found
gyp: Call to './util/has_lib.sh freetype' returned exit status 0 while in binding.gyp. while trying to load binding.gyp
```
--------------------------------
### Monaco Editor Setup with Technical Indicators
Source: https://github.com/anandanand84/technicalindicators/blob/master/testdocs.html
Initializes the Monaco Editor with TypeScript support and loads custom type definitions for technical indicators. Fetches definitions from a local server and configures the editor for optimal usage.
```javascript
var editor;
require.config({
paths: { 'vs': 'node_modules/monaco-editor/min/vs' }
});
require(['vs/editor/editor.main'], function() {
fetch('http://localhost:5444/declarations/generated.d.ts', {
method: 'get'
}).then(function(response) {
return response.text()
}).then(function(content) {
var technicalIndicators = content.replace(new RegExp('default ', 'g'), '').split('export').join('declare');
var disposable = monaco.languages.typescript.typescriptDefaults.addExtraLib(
technicalIndicators,
'indicators.d.ts'
);
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES5,
noEmit : true,
// noLib : true,
allowNonTsExtensions: true
});
editor = monaco.editor.create(container, {
value: "//Try indicators and check console\nlet result = sma({period : 10 , values: [1,2,3,4,5,6,7,8,9]});\nconsole.log(result)",
fontSize : 12,
emptySelectionClipboard:false,
formatOnType : true,
formatOnPaste : true,
parameterHints : true,
language: 'typescript'
});
window.addEventListener('resize', function () {
editor.layout();
});
})
});
```
--------------------------------
### Technical Indicator Usage Example
Source: https://github.com/anandanand84/technicalindicators/blob/master/testdocs.html
An example of how to use a technical indicator function (e.g., SMA) within the Monaco Editor. This snippet demonstrates calling an indicator with specific parameters and logging the result to the console.
```typescript
//Try indicators and check console
let result = sma({period : 10 , values: [1,2,3,4,5,6,7,8,9]});
console.log(result)
```
--------------------------------
### Install Specific TypeScript Version
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Installs TypeScript version 2.0.0 globally using npm. This specific version is recommended to prevent 'max call stack reached' errors.
```bash
npm install -g typescript@2.0.0
```
--------------------------------
### Indicator Instance Methods (nextValue, getResult)
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Explains how to use indicator instances for incremental calculations. Initialize with data, get all results using `getResult()`, and then process new data points with `nextValue()`.
```javascript
var sma = new SMA({period : period, values : []});
var results = [];
prices.forEach(price => {
var result = sma.nextValue(price);
if(result)
results.push(result)
});
```
```javascript
var sma = new SMA({period : period, values : prices});
sma.getResult(); // [5.5, 6.6, 7.7, 8.9]
sma.nextValue(16); // 10.1
// Note: Calling nextValue will not update getResult() value.
```
--------------------------------
### Include TechnicalIndicators for ES5 Browsers
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Includes the technicalindicators library for ES5 compatible browsers, requiring babel-polyfill and the browser.js file. Ensure both are installed via npm.
```html
```
--------------------------------
### Include TechnicalIndicators for ES6 Browsers
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Includes the technicalindicators library for ES6 compatible browsers via a script tag, after installation with npm.
```html
```
--------------------------------
### Verify Documentation
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Executes a script to verify documentation and then opens the generated documentation HTML file in a web browser.
```bash
node testdocs.js
open "http://localhost:5444/testdocs.html"
```
--------------------------------
### Running Tests and Coverage
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Executes the project's test suite and generates a code coverage report using npm scripts.
```bash
npm test
npm run cover
```
--------------------------------
### Use SMA Indicator in Browser (Global)
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Demonstrates how to use the SMA indicator directly from the global scope in a browser environment after including the library.
```javascript
sma({period : 5, values : [1,2,3,4,5,6,7,8,9], reversedInput : true});
```
--------------------------------
### Use SMA Indicator in Browser (Class Method)
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Demonstrates how to use the SMA indicator by calling its static calculate method, available after importing or including the library.
```javascript
SMA.calculate({period : 5, values : [1,2,3,4,5,6,7,8,9]});
```
--------------------------------
### Calculate Bullish/Bearish Indicator
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Demonstrates how to use the library's bullish function to determine if a bullish pattern is present based on input price data. Requires the 'technicalindicators' module.
```javascript
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
```
--------------------------------
### Configure Webpack for TechnicalIndicators
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Configures Webpack to correctly resolve the main fields for the technicalindicators library, ensuring compatibility with module and main entry points.
```javascript
module.exports = {
resolve: {
mainFields: ["module", "main"]
}
}
```
--------------------------------
### Calculate Indicator Statically
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Shows how to use the static `calculate` method available on each indicator. This method allows calculation without instantiating an object, using either the specific indicator module or the main library.
```javascript
const sma = require('technicalindicators').sma;
var prices = [1,2,3,4,5,6,7,8,9,10,12,13,15];
var period = 10;
sma({period : period, values : prices})
```
```javascript
const SMA = require('technicalindicators').SMA;
var prices = [1,2,3,4,5,6,7,8,9,10,12,13,15];
var period = 10;
SMA.calculate({period : period, values : prices})
```
--------------------------------
### Code Execution Function
Source: https://github.com/anandanand84/technicalindicators/blob/master/index.html
A utility function to execute the code written in the Monaco editor. It uses `eval` to parse and run the editor's content as an asynchronous function.
```javascript
var executeCode = function() {
var fn = eval('(async function test() {'+editor.getValue()+'})');
console.log(fn());
}
```
--------------------------------
### Import SMA Indicator in Node.js
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Imports the Simple Moving Average (SMA) indicator from the technicalindicators library. This allows you to use the SMA calculation function in your JavaScript code.
```javascript
const SMA = require('technicalindicators').SMA;
```
--------------------------------
### Set Calculation Precision
Source: https://github.com/anandanand84/technicalindicators/blob/master/README.md
Details how to configure the precision for calculations within the library. This helps manage potential floating-point rounding errors by setting a specific number of decimal places.
```javascript
const technicalIndicators = require('technicalindicators');
technicalIndicators.setConfig('precision', 10);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.