Giter Site home page Giter Site logo

anandanand84 / technicalindicators Goto Github PK

View Code? Open in Web Editor NEW
2.1K 95.0 550.0 22.28 MB

A javascript technical indicators written in typescript with pattern recognition right in the browser

License: MIT License

JavaScript 64.88% HTML 1.33% TypeScript 33.62% Shell 0.14% Dockerfile 0.03%
cryptocurrency stock-market stock-trading technical-indicators technical-analysis candle-stick candlestick-patterns-detection stock-data head-and-shoulders

technicalindicators's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

technicalindicators's Issues

Separate candles with bearish and bullish

Some candle patterns such as Marubozu and Harami grouped bearish and bullish into one pattern. I think separating them into two should provide better usage for them.

Use it with react

Hello
I can't use this module with react, the SMA value is undefined when i launch the exemple

Can you help me ? Have you solution to use it with react js ?

Thanks

This is flipping awesome =]

Hello mate! Apologies as this is not an issue but more of a this project is awesome! I love the Typescript support. I'm a newb at stock analysis but I'd love to share my experiences with you.

Right now I'm pulling quotes from Robinhood's API Quote.md. I'm able to obtain updates from all securities tradable on Robinhood (~7,000) every 10 seconds. What I'm aiming to do is try and find anomalies and make a move on them. I don't even know where to start, there's so many options. My first thoughts would be to find anomalies in bid/ask volume and act on that.

I would love to share my experiences and hear yours. I'm in a state of information overload! lol

[Q] Period unit

Hi, first off, thanks for this lib!

I'm not really familiar with TA, so pardon if it sounds like dumb questions.
Could you tell me what the unit the period integer refers to? Even after looking at the code and examples I can't really grasp it. Also, the values are the different close values for said period right?

Thanks!

Some indicators change based on # of values even above `period`

For example:, calling RSI with period 14. These are the outputs based on the inputs:

[ 0.08581, 0.08486146, 0.085, 0.08350007, 0.0839, 0.085, 0.08486001, 0.084873, 0.08573899, 0.0866, 0.08919999, 0.08690268, 0.08749999, 0.08689999, 0.0889, 0.08650001, 0.08523572, 0.0852799631
--> [ 0, 60.99, 51.52, 47.35, 47.51 ]
[ 0.08454304, 0.08581, 0.08486146, 0.085, 0.08350007, 0.0839, 0.085, 0.08486001, 0.084873, 0.08573899, 0.0866, 0.08919999, 0.08690268, 0.08749999, 0.08689999, 0.0889, 0.08650001, 0.08523572, 0.0852799631
--> [ 0, 58.84, 64.57, 54.73, 50.37, 50.52 ]

As you can see, the 2nd call has one more value at the beginning. As I understand it, in both cases the input has enough values to satisfy the period (14). Is RSI special in that it's relative or sth and it changes based on more values than period? If so, How can you ensure it matches consistently with things like TradingView, how many more values do I need to provide?

Same thing happens with PSAR.

Number accuracy

Using simple numbers in JS can lead to rounding errors. Have you thought about using BigNumber js?

RSI calculation returns no value

With RSI period of 14, the calculating RSI for the following values return nothing
[ 294435, 294435, 294435, 294500, 294500, 294500, 294520, 294539, 294539, 294600, 294600, 294600, 294600, 294600, 294700 ]

but when I change some value to be
[ 294435, 294435, 294435, 294500, 294500, 294400, 294520, 294539, 294539, 294600, 294600, 294600, 294600, 294600, 294700 ]
RSI returns -> 78.49

I'm not sure in which condition RSI return nothing,
should this problem be handled by input pre-validation or output post-correction.
(or if this a bug?)

Standardize return types

Some indicators return Number arrays and others return object arrays. This lib would be even easier to use if all indicators returned data of the same type.

Would you support a PR which does this?

For example SMA returns a Number array like

[ 123, 123, 123, 123]

I am proposing it return an object array like

[{ SMA: 123 }, { SMA: 123 }, { SMA: 123 }]

Chart pattern

Any chance that we can add the like of Double bottom, Rising wedge, Double top, Head and shoulder, ... ?

error with export

i am getting this error
(function (exports, require, module, __filename, __dirname) { export { sma, SMA } from './moving_averages/SMA';
^^^^^^
SyntaxError: Unexpected token export
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:511:25)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object. (/Users/albert/Downloads/poloniex-trade-bot-master/indicators/emasma.js:4:16)
at Module._compile (module.js:541:32)

i tested on several versions of node and OS systems!

Nesting indicators into window object is incompatible with previous versions.

package.json

"dependencies":  {
   "technicalindicators": "^1.0.3"
}

code example based on my usage from a previous version of this (super cool) library.

import * as Indicators from 'technicalindicators';

console.log(Indicators['SMA'])
// undefined 

console.log(Indicatos)
// window { ... }

console.log(Indicatos.window['SMA'])
// function...

I think this is due to versioning semantics. It seems version 1.0.21 is getting installed but version 1.0.3 is the last compatible version with the code example.

$ npm view technicalindicators
     '1.0.0': '2017-05-12T17:23:34.006Z',
     '1.0.1': '2017-05-16T18:53:57.903Z',
     '1.0.3': '2017-06-19T12:18:40.570Z',
     '1.0.4': '2017-06-21T14:50:55.925Z',
     '1.0.5': '2017-07-02T01:20:31.064Z',
     '1.0.6': '2017-07-25T14:23:36.998Z',
     '1.0.7': '2017-07-25T21:10:11.446Z',
     '1.0.8': '2017-07-26T15:23:42.035Z',
     '1.0.9': '2017-07-26T17:48:50.302Z',
     '1.0.10': '2017-07-26T20:01:53.177Z',
     '1.0.11': '2017-07-26T21:20:13.597Z',
     '1.0.13': '2017-07-26T23:35:32.591Z',
     '1.0.15': '2017-07-27T17:10:53.504Z',
     '1.0.16': '2017-07-30T14:22:25.010Z',
     '1.0.17': '2017-08-02T13:01:56.306Z',
     '1.0.18': '2017-08-09T13:58:04.658Z',
     '1.0.19': '2017-08-23T20:48:53.346Z',
     '1.0.20': '2017-08-25T17:07:07.540Z',
     '1.0.21': '2017-11-08T15:15:02.114Z'

Renko Chart

I'm quite a fan of Renko Charts and been looking for a library that does them. I've found that react-stockcharts does renko as well as many others.

What is the feasibility of adding support for Renko and other chart types to this library?

[FYI] Node.js and indicators

Hi,

thank you for this module! It saves quite a lot of time and coding. While implementing it inside an Node.js app I've noticed that this const SMA = require('technicalindicators').SMA isn't working. Upon calling SMA it throws "undefined". I looked a bit into the code and it works if I do this:
const SMA = require('technicalindicators').window.SMA

Not sure if you want/need to update your docs, but I've figured somebody might find this useful when searching issues.

Feel free to close this issue right away or let me know if I am doing something wrong.

PlusDM MinusDM

How can I add the plusDM and minusDM points added to my adx points?

Thanks,

Ramon

MACD strange behavior

Hello,

I calculate two MACD with the following settings. The first time I just remove the 5 oldest data. Why this affect the most recent MACD ? There is a small difference:
MACD: 7.10857, signal: 7.10857 vs MACD: 7.10239, signal: 7.10239
Thanks !

var macdInput = {
  values            : [ length: 200 ],
  fastPeriod        : 4,
  slowPeriod        : 6,
  signalPeriod      : 2,
  SimpleMAOscillator: false,
  SimpleMASignal    : false
}
var macdInput = {
  values            : [length: 205],
  fastPeriod        : 4,
  slowPeriod        : 6,
  signalPeriod      : 2,
  SimpleMAOscillator: false,
  SimpleMASignal    : false
}

Typescript errors

I'm coming across the following:

node_modules/technicalindicators/declarations/chart_types/HeikinAshi.d.ts(14,22): error TS2415: Class 'HeikinAshi' incorrectly extends base class 'Indicator'.
Types of property 'result' are incompatible.
Type 'CandleList' is not assignable to type 'any[]'.
Property 'length' is missing in type 'CandleList'.

"reversedInput" parameter modified input value

Example code:

const technicalindicators = require('technicalindicators');

const values = [0.001, 0.003, 0.001, 0.003, 0.004, 0.002, 0.003, 0.003, 0.002];
console.log("before: " + values);
const smaValues = technicalindicators.SMA.calculate({ reversedInput: true, period: 4, values: values });
console.log("after: " + values);

Expected output:

before: 0.001,0.003,0.001,0.003,0.004,0.002,0.003,0.003,0.002
after: 0.001,0.003,0.001,0.003,0.004,0.002,0.003,0.003,0.002

Actual output:

before: 0.001,0.003,0.001,0.003,0.004,0.002,0.003,0.003,0.002
after: 0.002,0.003,0.003,0.002,0.004,0.003,0.001,0.003,0.001

For calculate function for indicators with reversedInput: true, input value array is reversed. As JS array use pass by reference approach, slice(0) should be used, or reverse() the array again to keep the original value of input parameter.

Dojis seem too loosely defined

Hello, this is an amazing repo, just something I've noticed.

The following candlestick is coming back as a doji.
screen shot 2017-08-22 at 12 49 17 am

I think this is simply because of the approximateEqual function. I haven't yet worked on a more accurate version, but in this case...

approximateEqual(1.36171, 1.36079) = true

Using the latest data instead the first of the array

In the logic of the Candlestickfinders you are using the first element of the data, instead the latest, example;
https://github.com/anandanand84/technicalindicators/blob/master/src/candlestick/MorningStar.ts#L10

I think i shoul look something like;


logic (data:StockData) {
    const firstDay = data.length - 3;
    const secondDay = data.length - 2;
    const thirdDay = data.length - 1;

    let firstdaysOpen   = data.open[firstDay];
    let firstdaysClose  = data.close[firstDay];
    let firstdaysHigh   = data.high[firstDay];
    let firstdaysLow    = data.low[firstDay]
    let seconddaysOpen  = data.open[secondDay];
    let seconddaysClose = data.close[secondDay];
    let seconddaysHigh  = data.high[secondDay];
    let seconddaysLow   = data.low[secondDay]
    let thirddaysOpen   = data.open[thirdDay];
    let thirddaysClose  = data.close[thirdDay];
    let thirddaysHigh   = data.high[thirdDay];
    let thirddaysLow    = data.low[thirdDay];
     

Bullish vs Bearish indicators not checking Open vs Close

For instance, bearishspinningtop returns true for the following data

low: [205],
high: [207.95],
open: [206.16],
close: [207.9],
volume: [5231.61]

I noticed a couple things in the following code:

let bodyLength           = Math.abs(daysClose-daysOpen); // this is good
let upperShadowLength    = Math.abs(daysHigh-daysOpen); // this should be daysHigh - Math.max(daysOpen, daysClose)
let lowerShadowLength    = Math.abs(daysHigh-daysLow); // this should be Math.min(daysOpen,days.close) - daysLow
let isBearishSpinningTop = bodyLength < upperShadowLength &&
  bodyLength < lowerShadowLength; // this should include check for daysClose < daysOpen
  1. it wasn't explicitly checking if open < close (definition of bearish in this case)
  2. the shadow calculations were off (comments in code above)

Would you like me to start a PR to go through and fix these? I'm very interested in getting all these working for my project and would prefer to contribute to your lib rather than fork to correct.

ADL division by zero

In ADL.ts there is a possible division by zero if tick.high and tick.low are the same. That results in every result value afterwards being NaN.

let moneyFlowMultiplier = ((tick.close - tick.low) - (tick.high - tick.close)) /(tick.high - tick.low);

Bullish and Bearish

For Bullish and Bearish, they check against different indicators, some accept two candles, some accept three candles, if the user provided three candles to utilize all the indicators, for indicators that utilize two candles only they should use the last two candles not the first two

Trouble using CCI

Hi, thanks for this awesome library. You rock!

Having trouble getting CCI working in the latest release 10.0.16
const CCI = require('technicalindicators').CCI;
TypeError: Cannot read property 'calculate' of undefined

const CCI = require('technicalindicators/lib/oscillators/CCI').CCI;
(function (exports, require, module, __filename, __dirname) { import { Indicator, IndicatorInput } from '../indicator/indicator';
^^^^^^
SyntaxError: Unexpected token import

Thanks in advance!!

indentation rules

seems there is some inconsistent indentation going on - javascript files in test are at 2 space indentation, whereas typescript files in src are at 4 space indentation

src/chart_types/Renko.ts also has mixed indentation

I'd suggest the following .editorconfig file to resolve this:

# editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
indent_style = space
indent_size = 4

[*.mk]
indent_style = tab

[*.md]
indent_style = space
indent_size = 4

[{*.json,*.yml,*.bowerrc,*.babelrc}]
indent_style = space
indent_size = 2

VSCode plugin for EditorConfig: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

Cannot load some indicators in newer versions

I am seeing issues with a number of the candlestick patterns in newer versions with error

Cannot read property 'hasPattern' of undefined

For example:

let doji = require('technicalindicators').Doji
let values = ...
doji.hasPattern(values)

The above will throw the error and I am seeing this across a number of patterns, not just Doji. The last version available on npm that seems stable is 0.2.17.

Reversing Inputs

Love the library! Thanks for all the hard work! I am trying to understand if I should be reversing my Inputs or not, and was hoping to get some clarification on what I should be understanding! Thanks again!

Stochastic

export function stochastic(input:StochasticInput):StochasticOutput[] {
    Indicator.reverseInputs(input); //First Reverse Input Check
    var result = new Stochastic(input).result;
    if(input.reversedInput) { //Reversed Input Boolean 
        result.reverse();  //Reversed Result
    }
    Indicator.reverseInputs(input); //Second Reverse Input Check After Input is Reversed
    return result;
};

And in the Indicator Class

 static reverseInputs(input:any):void {
    if(input.reversedInput) { //Same Reversed Input Boolean Check
        input.values ? input.values.reverse() : undefined;
        input.open ? input.open.reverse() : undefined;
        input.high ? input.high.reverse() : undefined;
        input.low ? input.low.reverse() : undefined;
        input.close ? input.close.reverse() : undefined;
        input.volume ? input.volume.reverse() : undefined;
        input.timestamp ? input.timestamp.reverse() : undefined;
    }
}

As far as I can tell unless the reverseInput = truenothing happens. So when reverseInputs = true is the input being reversed twice? and the output reversed once? Is the input being reversed after the result is reversed and does that matter or just redundant? Sorry if I am missing something. Cheers!

variable "strategy" is not defined in CandlestickFinder.js

Here is the stack trace:

ReferenceError: strategy is not defined
    at AbandonedBaby._getLastDataForCandleStick (...\node_modules\technicalindicators\lib\candlestick\CandlestickFinder.js:51:75)
    at AbandonedBaby.hasPattern (...\node_modules\technicalindicators\lib\candlestick\CandlestickFinder.js:45:43)
...
...

Need to help in setup

Hi, I want to setup the project. I have downloaded the project. Extracted the zip to the folder 'technicalindicators-master'. I ran the 'npm install --save technicalindicators'. It installed the node_modules folder in the root directory. After this I have written the below simple script to check the Bearish Engulfing Pattern.

var BearishEngulfingPattern = require('technicalindicators').BearishEngulfingPattern;
var twoDayBearishInput = {
  open: [21.44,27.89],
  high: [25.10,30.87],
  close: [23.25,15.36],
  low: [20.82,14.93],
}
var result      = BearishEngulfingPattern.hasPattern(twoDayBearishInput);
console.log( 'Is BearishEngulfingPattern? :' +result); 

But I am getting below error.

TypeError: Cannot read property 'hasPattern' of undefined
    at Object.<anonymous> (/home/lk/Downloads/technicalindicators-master/node_c975eebf38a1f.tmp:8:42)
    at Module._compile (module.js:570:32)

I am very new to the nodejs world. Could you please someone help me how to resolve this? I debug and found that the require('technicalindicators').BearishEngulfingPattern is returning unidentified.

regeneratorRuntime is not defined

Hi, I used technicalindicators for a while, and it's quite good somehow.
However, I just upgrade to 1.0.4 today and found the issue which is not obvious to me.
Can you please check, thanks!

==============Install=============
$ npm install technicalindicators
[email protected] E:\data\test
-- [email protected] -- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

==============Run=============
$ node
var macd = require('technicalindicators').macd
ReferenceError: regeneratorRuntime is not defined
at E:\data\test\node_modules\technicalindicators\dist\browser.js:1:16646
at e.window (E:\data\test\node_modules\technicalindicators\dist\browser.js:1:17293)
at Object. (E:\data\test\node_modules\technicalindicators\dist\browser.js:2:14270)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)

TypeError: Cannot read property 'toFixed' of undefined

When using the MACD function getting this error here is the stack trace

TypeError: Cannot read property 'toFixed' of undefined at format (node_modules/technicalindicators/lib/Utils/NumberFormatter.js:4:24) at node_modules/technicalindicators/lib/moving_averages/MACD.js:52:27 at next (native) at MACD.input.values.forEach (node_modules/technicalindicators/lib/moving_averages/MACD.js:62:41) at Array.forEach (native) at MACD (node_modules/technicalindicators/lib/moving_averages/MACD.js:61:22) at Function.macd [as calculate] (node_modules/technicalindicators/lib/moving_averages/MACD.js:78:18)

portions of the file path were removed, verified the data is coming in in the right format

Stochastic RSI

Anyone have any success doing this with RSI and Stochastic calculations of this library?

generator function not supported by IOS or Opera etc

Hi,

The generator function may not be supported by some of the web and mobile browsers as per below link. Is this correct?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable

Is yes, was wondering if we could replace the generator function with something more generic which can be supported by almost all common browsers. It would far outweight the convenience of using the generator function.

Let me know your thoughts

Regards

[Webpack v2] Module not found: Error: Recursion in resolving

Hello mate,

Today I've been migrating my playground/sandbox over to webpack 2.0 and I can't get technicalindicators to resolve properly =[

It yells at me:

ERROR in ./~/technicalindicators/lib/moving_averages/SMA.js
Module not found: Error: Recursion in resolving

Here's a gist
https://gist.github.com/roblav96/e36937c29384db5530164e7373b2a1e5
of the full log and the webpack.config.js. (I hate when people leave absurdly long console.logs in the OP)

Any idea what could be the issue? I'm gonna keep looking into this and I'll let you know if I can resolve it.

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.