Class: StudyCalculator

StudyCalculator


new StudyCalculator(ciq [, params])

The Study Calculator is a node.js module which can be included in your JS application.

  • It requires a specially locked version the ChartIQ library to run.
  • It will not work with your browser based locked package.
  • Available in the modules directory if you have purchased this feature.

The purpose of this module is to calculate the results of one or more studies/indicators applied to market data provided to the module.
The results can then be retrieved by your application and used.

Included in the modules directory is a detailedExample.js file which is a detailed example of how to interface with the study-calculator module.
You can modify this file or incorporate into your own code as you wish.
The study-calculator.js module itself should not be modified, although its functions are documented and you are encouraged to read the documentation.

See the example section for more details.

Parameters:
Name Type Argument Description
ciq object

ChartIQ namespace

params object <optional>

Parameters

Properties
Name Type Argument Default Description
marketFactory function <optional>

Some studies require a market factory. If omitted will use CIQ.Market.Symbology.factory

symbolObject object <optional>

Some studies require a symbol to be set. This object should look like this: {symbol:xxx}

periodicity number <optional>

Some studies require an periodicity (e.g. 1) to be set.

interval string <optional>

Some studies require an interval (e.g. "day") to be set.

timeUnit string <optional>

Some studies require a timeUnit (e.g. "seconds") to be set.

maxRecords number <optional>
1000

Maximum number of records to keep in the calculator. If additional records are pushed in, the oldest records will be dropped. Set to 0 to remove the limitation.

Since:
  • 7.1.0
Examples

Here is a very simple example of how to use the Study Calculator module to compute the results of a 5 period moving average. It is included as simpleExample.js:

const ciq = require('chartiq').CIQ;
const StudyCalculator = require('./study-calculator');

const sampledata = [
	{"DT":new Date("2015-04-16 16:00"),"Close":152.11},	{"DT":new Date("2015-04-17 09:30"),"Close":151.79},
	{"DT":new Date("2015-04-17 09:35"),"Close":151.75},	{"DT":new Date("2015-04-17 09:40"),"Close":151.84},
	{"DT":new Date("2015-04-17 09:45"),"Close":151.95},	{"DT":new Date("2015-04-17 09:50"),"Close":152.07},
	{"DT":new Date("2015-04-17 09:55"),"Close":151.91},	{"DT":new Date("2015-04-17 10:00"),"Close":151.95},
	{"DT":new Date("2015-04-17 10:05"),"Close":151.98},	{"DT":new Date("2015-04-17 10:10"),"Close":151.73},
	{"DT":new Date("2015-04-17 10:15"),"Close":151.82},	{"DT":new Date("2015-04-17 10:20"),"Close":151.75},
	{"DT":new Date("2015-04-17 10:25"),"Close":151.73},	{"DT":new Date("2015-04-17 10:30"),"Close":151.82},
	{"DT":new Date("2015-04-17 10:35"),"Close":151.84},	{"DT":new Date("2015-04-17 10:40"),"Close":151.95},
	{"DT":new Date("2015-04-17 10:45"),"Close":152.03},	{"DT":new Date("2015-04-17 10:50"),"Close":152.03}
];

const studyCalculator=new StudyCalculator(ciq, {interval:5, symbolObject:{symbol:"IBM"}});
const maHandle=studyCalculator.addStudy("ma", {Period:5});

studyCalculator.addData(sampledata);
studyCalculator.calculate();

for(let record=0;record<sampledata.length;record++){
	const results=studyCalculator.getResults(record, maHandle);
	for(let f in results) console.log(sampledata[record].DT.toISOString()+"   "+f+":  "+results[f]);
}

To run the above, execute the following command:

$ NODE_PATH=[path/to/license/js] node simpleExample.js

Methods


addData(data)

Add input data to the calculator.

Parameters:
Name Type Description
data object

data to compute studies upon.

Since:
  • 7.1.0

addStudy(type [, inputs])

Add a study to the calculator.

Parameters:
Name Type Argument Description
type string

study type to add

inputs object <optional>

input parameters for study, if different from default

Since:
  • 7.1.0
Returns:

a handle to the study just added

Type
String

calculate()

Calculate all added studies using given data.

Since:
  • 7.1.0
Example
// Declare a StudyCalculator
var studyCalculator = new StudyCalculator(ciq);
studyCalculator.addData(sampleData);
var sd=studyCalculator.addStudy("rsi");
studyCalculator.calculate();
var results=[];
for(var i=0;i<sampleData.length;i++) 
	results.push(studyCalculator.getResults(i,sd));

clearData()

Clear calculator input data.

Since:
  • 7.1.0