ohlcv-indicators 1.5.4 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
var OHLCV_INDICATORS;(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};(()=>{t.r(e),t.d(e,{default:()=>Fe});var r=1e6,n="[big.js] ",i=n+"Invalid ",o=i+"decimal places",u=i+"rounding mode",s=n+"Division by zero",l={},a=void 0,c=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function f(t,e,r,n){var i=t.c;if(r===a&&(r=t.constructor.RM),0!==r&&1!==r&&2!==r&&3!==r)throw Error(u);if(e<1)n=3===r&&(n||!!i[0])||0===e&&(1===r&&i[0]>=5||2===r&&(i[0]>5||5===i[0]&&(n||i[1]!==a))),i.length=1,n?(t.e=t.e-e+1,i[0]=1):i[0]=t.e=0;else if(e<i.length){if(n=1===r&&i[e]>=5||2===r&&(i[e]>5||5===i[e]&&(n||i[e+1]!==a||1&i[e-1]))||3===r&&(n||!!i[0]),i.length=e,n)for(;++i[--e]>9;)if(i[e]=0,0===e){++t.e,i.unshift(1);break}for(e=i.length;!i[--e];)i.pop()}return t}function h(t,e,r){var n=t.e,i=t.c.join(""),o=i.length;if(e)i=i.charAt(0)+(o>1?"."+i.slice(1):"")+(n<0?"e":"e+")+n;else if(n<0){for(;++n;)i="0"+i;i="0."+i}else if(n>0)if(++n>o)for(n-=o;n--;)i+="0";else n<o&&(i=i.slice(0,n)+"."+i.slice(n));else o>1&&(i=i.charAt(0)+"."+i.slice(1));return t.s<0&&r?"-"+i:i}l.abs=function(){var t=new this.constructor(this);return t.s=1,t},l.cmp=function(t){var e,r=this,n=r.c,i=(t=new r.constructor(t)).c,o=r.s,u=t.s,s=r.e,l=t.e;if(!n[0]||!i[0])return n[0]?o:i[0]?-u:0;if(o!=u)return o;if(e=o<0,s!=l)return s>l^e?1:-1;for(u=(s=n.length)<(l=i.length)?s:l,o=-1;++o<u;)if(n[o]!=i[o])return n[o]>i[o]^e?1:-1;return s==l?0:s>l^e?1:-1},l.div=function(t){var e=this,n=e.constructor,i=e.c,u=(t=new n(t)).c,l=e.s==t.s?1:-1,c=n.DP;if(c!==~~c||c<0||c>r)throw Error(o);if(!u[0])throw Error(s);if(!i[0])return t.s=l,t.c=[t.e=0],t;var h,v,p,y,d,b=u.slice(),g=h=u.length,m=i.length,w=i.slice(0,h),O=w.length,S=t,_=S.c=[],j=0,P=c+(S.e=e.e-t.e)+1;for(S.s=l,l=P<0?0:P,b.unshift(0);O++<h;)w.push(0);do{for(p=0;p<10;p++){if(h!=(O=w.length))y=h>O?1:-1;else for(d=-1,y=0;++d<h;)if(u[d]!=w[d]){y=u[d]>w[d]?1:-1;break}if(!(y<0))break;for(v=O==h?u:b;O;){if(w[--O]<v[O]){for(d=O;d&&!w[--d];)w[d]=9;--w[d],w[O]+=10}w[O]-=v[O]}for(;!w[0];)w.shift()}_[j++]=y?p:++p,w[0]&&y?w[O]=i[g]||0:w=[i[g]]}while((g++<m||w[0]!==a)&&l--);return _[0]||1==j||(_.shift(),S.e--,P--),j>P&&f(S,P,n.RM,w[0]!==a),S},l.eq=function(t){return 0===this.cmp(t)},l.gt=function(t){return this.cmp(t)>0},l.gte=function(t){return this.cmp(t)>-1},l.lt=function(t){return this.cmp(t)<0},l.lte=function(t){return this.cmp(t)<1},l.minus=l.sub=function(t){var e,r,n,i,o=this,u=o.constructor,s=o.s,l=(t=new u(t)).s;if(s!=l)return t.s=-l,o.plus(t);var a=o.c.slice(),c=o.e,f=t.c,h=t.e;if(!a[0]||!f[0])return f[0]?t.s=-l:a[0]?t=new u(o):t.s=1,t;if(s=c-h){for((i=s<0)?(s=-s,n=a):(h=c,n=f),n.reverse(),l=s;l--;)n.push(0);n.reverse()}else for(r=((i=a.length<f.length)?a:f).length,s=l=0;l<r;l++)if(a[l]!=f[l]){i=a[l]<f[l];break}if(i&&(n=a,a=f,f=n,t.s=-t.s),(l=(r=f.length)-(e=a.length))>0)for(;l--;)a[e++]=0;for(l=e;r>s;){if(a[--r]<f[r]){for(e=r;e&&!a[--e];)a[e]=9;--a[e],a[r]+=10}a[r]-=f[r]}for(;0===a[--l];)a.pop();for(;0===a[0];)a.shift(),--h;return a[0]||(t.s=1,a=[h=0]),t.c=a,t.e=h,t},l.mod=function(t){var e,r=this,n=r.constructor,i=r.s,o=(t=new n(t)).s;if(!t.c[0])throw Error(s);return r.s=t.s=1,e=1==t.cmp(r),r.s=i,t.s=o,e?new n(r):(i=n.DP,o=n.RM,n.DP=n.RM=0,r=r.div(t),n.DP=i,n.RM=o,this.minus(r.times(t)))},l.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t},l.plus=l.add=function(t){var e,r,n,i=this,o=i.constructor;if(t=new o(t),i.s!=t.s)return t.s=-t.s,i.minus(t);var u=i.e,s=i.c,l=t.e,a=t.c;if(!s[0]||!a[0])return a[0]||(s[0]?t=new o(i):t.s=i.s),t;if(s=s.slice(),e=u-l){for(e>0?(l=u,n=a):(e=-e,n=s),n.reverse();e--;)n.push(0);n.reverse()}for(s.length-a.length<0&&(n=a,a=s,s=n),e=a.length,r=0;e;s[e]%=10)r=(s[--e]=s[e]+a[e]+r)/10|0;for(r&&(s.unshift(r),++l),e=s.length;0===s[--e];)s.pop();return t.c=s,t.e=l,t},l.pow=function(t){var e=this,r=new e.constructor("1"),n=r,o=t<0;if(t!==~~t||t<-1e6||t>1e6)throw Error(i+"exponent");for(o&&(t=-t);1&t&&(n=n.times(e)),t>>=1;)e=e.times(e);return o?r.div(n):n},l.prec=function(t,e){if(t!==~~t||t<1||t>r)throw Error(i+"precision");return f(new this.constructor(this),t,e)},l.round=function(t,e){if(t===a)t=0;else if(t!==~~t||t<-r||t>r)throw Error(o);return f(new this.constructor(this),t+this.e+1,e)},l.sqrt=function(){var t,e,r,i=this,o=i.constructor,u=i.s,s=i.e,l=new o("0.5");if(!i.c[0])return new o(i);if(u<0)throw Error(n+"No square root");0===(u=Math.sqrt(i+""))||u===1/0?((e=i.c.join("")).length+s&1||(e+="0"),s=((s+1)/2|0)-(s<0||1&s),t=new o(((u=Math.sqrt(e))==1/0?"5e":(u=u.toExponential()).slice(0,u.indexOf("e")+1))+s)):t=new o(u+""),s=t.e+(o.DP+=4);do{r=t,t=l.times(r.plus(i.div(r)))}while(r.c.slice(0,s).join("")!==t.c.slice(0,s).join(""));return f(t,(o.DP-=4)+t.e+1,o.RM)},l.times=l.mul=function(t){var e,r=this,n=r.constructor,i=r.c,o=(t=new n(t)).c,u=i.length,s=o.length,l=r.e,a=t.e;if(t.s=r.s==t.s?1:-1,!i[0]||!o[0])return t.c=[t.e=0],t;for(t.e=l+a,u<s&&(e=i,i=o,o=e,a=u,u=s,s=a),e=new Array(a=u+s);a--;)e[a]=0;for(l=s;l--;){for(s=0,a=u+l;a>l;)s=e[a]+o[l]*i[a-l-1]+s,e[a--]=s%10,s=s/10|0;e[a]=s}for(s?++t.e:e.shift(),l=e.length;!e[--l];)e.pop();return t.c=e,t},l.toExponential=function(t,e){var n=this,i=n.c[0];if(t!==a){if(t!==~~t||t<0||t>r)throw Error(o);for(n=f(new n.constructor(n),++t,e);n.c.length<t;)n.c.push(0)}return h(n,!0,!!i)},l.toFixed=function(t,e){var n=this,i=n.c[0];if(t!==a){if(t!==~~t||t<0||t>r)throw Error(o);for(t=t+(n=f(new n.constructor(n),t+n.e+1,e)).e+1;n.c.length<t;)n.c.push(0)}return h(n,!1,!!i)},l[Symbol.for("nodejs.util.inspect.custom")]=l.toJSON=l.toString=function(){var t=this,e=t.constructor;return h(t,t.e<=e.NE||t.e>=e.PE,!!t.c[0])},l.toNumber=function(){var t=Number(h(this,!0,!0));if(!0===this.constructor.strict&&!this.eq(t.toString()))throw Error(n+"Imprecise conversion");return t},l.toPrecision=function(t,e){var n=this,o=n.constructor,u=n.c[0];if(t!==a){if(t!==~~t||t<1||t>r)throw Error(i+"precision");for(n=f(new o(n),t,e);n.c.length<t;)n.c.push(0)}return h(n,t<=n.e||n.e<=o.NE||n.e>=o.PE,!!u)},l.valueOf=function(){var t=this,e=t.constructor;if(!0===e.strict)throw Error(n+"valueOf disallowed");return h(t,t.e<=e.NE||t.e>=e.PE,!0)};const v=function t(){function e(r){var n=this;if(!(n instanceof e))return r===a?t():new e(r);if(r instanceof e)n.s=r.s,n.e=r.e,n.c=r.c.slice();else{if("string"!=typeof r){if(!0===e.strict&&"bigint"!=typeof r)throw TypeError(i+"value");r=0===r&&1/r<0?"-0":String(r)}!function(t,e){var r,n,o;if(!c.test(e))throw Error(i+"number");for(t.s="-"==e.charAt(0)?(e=e.slice(1),-1):1,(r=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(r<0&&(r=n),r+=+e.slice(n+1),e=e.substring(0,n)):r<0&&(r=e.length),o=e.length,n=0;n<o&&"0"==e.charAt(n);)++n;if(n==o)t.c=[t.e=0];else{for(;o>0&&"0"==e.charAt(--o););for(t.e=r-n-1,t.c=[],r=0;n<=o;)t.c[r++]=+e.charAt(n++)}}(n,r)}n.constructor=e}return e.prototype=l,e.DP=20,e.RM=1,e.NE=-7,e.PE=21,e.strict=!1,e.roundDown=0,e.roundHalfUp=1,e.roundHalfEven=2,e.roundUp=3,e}();function p(t){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p(t)}function y(t){var e="function"==typeof Map?new Map:void 0;return y=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(d())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var i=new(t.bind.apply(t,n));return r&&b(i,r.prototype),i}(t,arguments,g(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),b(r,t)},y(t)}function d(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(d=function(){return!!t})()}function b(t,e){return b=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},b(t,e)}function g(t){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},g(t)}var m=function(t){function e(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not enough data";return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),t=function(t,e,r){return e=g(e),function(t,e){if(e&&("object"==p(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,d()?Reflect.construct(e,r||[],g(t).constructor):e.apply(t,r))}(this,e,[r]),Object.setPrototypeOf(t,(this instanceof e?this.constructor:void 0).prototype),t.name="NotEnoughDataError",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&b(t,e)}(e,t),r=e,Object.defineProperty(r,"prototype",{writable:!1}),r;var r}(y(Error));function w(t){return w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},w(t)}function O(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function S(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,P(n.key),n)}}function _(t,e,r){return e&&S(t.prototype,e),r&&S(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function j(t,e,r){return(e=P(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function P(t){var e=function(t,e){if("object"!=w(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=w(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==w(e)?e:e+""}var E=function(){return _((function t(){O(this,t),j(this,"previousHighest",void 0),j(this,"highest",void 0),j(this,"previousLowest",void 0),j(this,"lowest",void 0),j(this,"previousResult",void 0),j(this,"result",void 0)}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"setResult",value:function(t,e){return e&&(this.highest=this.previousHighest,this.lowest=this.previousLowest,this.result=this.previousResult),void 0===this.highest?this.highest=t:t.gt(this.highest)?(this.previousHighest=this.highest,this.highest=t):this.previousHighest=this.highest,void 0===this.lowest?this.lowest=t:t.lt(this.lowest)?(this.previousLowest=this.lowest,this.lowest=t):this.previousLowest=this.lowest,this.previousResult=this.result,this.result=t}},{key:"replace",value:function(t){return this.update(t,!0)}}])}(),R=function(){return _((function t(){O(this,t),j(this,"previousHighest",void 0),j(this,"highest",void 0),j(this,"previousLowest",void 0),j(this,"lowest",void 0),j(this,"previousResult",void 0),j(this,"result",void 0)}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"setResult",value:function(t,e){return e&&(this.highest=this.previousHighest,this.lowest=this.previousLowest,this.result=this.previousResult),void 0===this.highest?this.highest=t:t>this.highest?(this.previousHighest=this.highest,this.highest=t):this.previousHighest=this.highest,void 0===this.lowest?this.lowest=t:t<this.lowest?(this.previousLowest=this.lowest,this.lowest=t):this.previousLowest=this.lowest,this.previousResult=this.result,this.result=t}},{key:"replace",value:function(t){return this.update(t,!0)}}])}();function A(t){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},A(t)}function k(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function C(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,L(n.key),n)}}function T(t,e,r){return e&&C(t.prototype,e),r&&C(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function B(t,e,r){return e=I(e),function(t,e){if(e&&("object"==A(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,M()?Reflect.construct(e,r||[],I(t).constructor):e.apply(t,r))}function M(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(M=function(){return!!t})()}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function x(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&H(t,e)}function H(t,e){return H=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},H(t,e)}function F(t,e,r){return(e=L(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function L(t){var e=function(t,e){if("object"!=A(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=A(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==A(e)?e:e+""}var D=function(t){function e(t){var r;return k(this,e),F(r=B(this,e),"interval",void 0),r.interval=t,r}return x(e,t),T(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"replace",value:function(t){return this.update(t,!0)}}])}(E),N=function(t){function e(t){var r;return k(this,e),F(r=B(this,e),"interval",void 0),r.interval=t,r}return x(e,t),T(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"replace",value:function(t){return this.update(t,!0)}}])}(R);function G(t){return G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},G(t)}function q(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function z(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,X(n.key),n)}}function V(t,e,r){return e&&z(t.prototype,e),r&&z(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function U(t,e,r){return e=K(e),function(t,e){if(e&&("object"==G(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,$()?Reflect.construct(e,r||[],K(t).constructor):e.apply(t,r))}function $(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return($=function(){return!!t})()}function K(t){return K=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},K(t)}function J(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Q(t,e)}function Q(t,e){return Q=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Q(t,e)}function W(t,e,r){return(e=X(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function X(t){var e=function(t,e){if("object"!=G(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=G(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==G(e)?e:e+""}var Y=function(t){function e(){var t;q(this,e);for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];return W(t=U(this,e,[].concat(n)),"prices",[]),t}return J(e,t),V(e,[{key:"update",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.prices.length&&r?this.prices[this.prices.length-1]=t:this.prices.push(t),this.prices.length>this.interval&&this.prices.shift(),this.prices.length===this.interval)return this.setResult(e.getResultFromBatch(this.prices),r)}}],[{key:"getResultFromBatch",value:function(t){return t.reduce((function(t,e){return t.plus(e)}),new v("0")).div(t.length||1)}}])}(D),Z=function(t){function e(){var t;q(this,e);for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];return W(t=U(this,e,[].concat(n)),"prices",[]),t}return J(e,t),V(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.prices.length&&e?this.prices[this.prices.length-1]=t:this.prices.push(t),this.prices.length>this.interval&&this.prices.shift(),this.prices.length===this.interval){var r=this.prices.reduce((function(t,e){return t+e}),0);return this.setResult(r/this.prices.length,e)}}}])}(N);function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function et(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function rt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,ct(n.key),n)}}function nt(t,e,r){return e&&rt(t.prototype,e),r&&rt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function it(t,e,r){return e=ut(e),function(t,e){if(e&&("object"==tt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ot()?Reflect.construct(e,r||[],ut(t).constructor):e.apply(t,r))}function ot(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(ot=function(){return!!t})()}function ut(t){return ut=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ut(t)}function st(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&<(t,e)}function lt(t,e){return lt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},lt(t,e)}function at(t,e,r){return(e=ct(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function ct(t){var e=function(t,e){if("object"!=tt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==tt(e)?e:e+""}var ft=function(t){function e(t){var r;return et(this,e),at(r=it(this,e,[t]),"interval",void 0),at(r,"indicator",void 0),at(r,"smoothingFactor",void 0),r.interval=t,r.indicator=new Y(t),r.smoothingFactor=new v(1).div(r.interval),r}return st(e,t),nt(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=this.indicator.update(t,e);if(e&&this.previousResult){var n=new v(t).minus(this.previousResult).mul(this.smoothingFactor);return this.setResult(n.plus(this.previousResult),e)}if(!e&&this.result){var i=new v(t).minus(this.result).mul(this.smoothingFactor);return this.setResult(i.plus(this.result),e)}if(void 0===this.result&&r)return this.setResult(r,e)}}])}(D),ht=function(t){function e(t){var r;return et(this,e),at(r=it(this,e),"interval",void 0),at(r,"indicator",void 0),at(r,"smoothingFactor",void 0),r.interval=t,r.indicator=new Z(t),r.smoothingFactor=1/r.interval,r}return st(e,t),nt(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=this.indicator.update(t);if(e&&void 0!==this.previousResult){var n=(t-this.previousResult)*this.smoothingFactor;return this.setResult(n+this.previousResult,e)}if(!e&&void 0!==this.result){var i=(t-this.result)*this.smoothingFactor;return this.setResult(i+this.result,e)}if(void 0===this.result&&void 0!==r)return this.setResult(r,e)}}])}(R);function vt(t){return t.reduce((function(t,e){return t.add(e)}),new v(0)).div(t.length||1)}function pt(t){return t.length?t.reduce((function(t,e){return t+e}),0)/t.length:0}function yt(t){return yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},yt(t)}function dt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function bt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,wt(n.key),n)}}function gt(t,e,r){return e&&bt(t.prototype,e),r&&bt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function mt(t,e,r){return(e=wt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function wt(t){var e=function(t,e){if("object"!=yt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=yt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==yt(e)?e:e+""}var Ot=function(){return gt((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;dt(this,t),mt(this,"interval",void 0),mt(this,"deviationMultiplier",void 0),mt(this,"prices",[]),mt(this,"result",void 0),this.interval=e,this.deviationMultiplier=r}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"update",value:function(t){if(this.prices.push(new v(t)),this.prices.length>this.interval){this.prices.shift();var e=Y.getResultFromBatch(this.prices),r=function(t,e){var r=e||vt(t);return vt(t.map((function(t){return new v(t).sub(r).pow(2)}))).sqrt()}(this.prices,e);return this.result={lower:e.sub(r.times(this.deviationMultiplier)),middle:e,upper:e.add(r.times(this.deviationMultiplier))}}}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}}])}(),St=function(){return gt((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;dt(this,t),mt(this,"interval",void 0),mt(this,"deviationMultiplier",void 0),mt(this,"prices",[]),mt(this,"result",void 0),this.interval=e,this.deviationMultiplier=r}),[{key:"update",value:function(t){if(this.prices.push(t),this.prices.length>this.interval){this.prices.shift();var e=pt(this.prices),r=function(t,e){var r=e||pt(t),n=pt(t.map((function(t){return t-r})).map((function(t){return t*t})));return Math.sqrt(n)}(this.prices,e);return this.result={lower:e-r*this.deviationMultiplier,middle:e,upper:e+r*this.deviationMultiplier}}}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"isStable",get:function(){return void 0!==this.result}}])}();function _t(t){return _t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_t(t)}function jt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Pt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Mt(n.key),n)}}function Et(t,e,r){return e&&Pt(t.prototype,e),r&&Pt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function Rt(t,e,r){return e=kt(e),function(t,e){if(e&&("object"==_t(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,At()?Reflect.construct(e,r||[],kt(t).constructor):e.apply(t,r))}function At(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(At=function(){return!!t})()}function kt(t){return kt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},kt(t)}function Ct(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Tt(t,e)}function Tt(t,e){return Tt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Tt(t,e)}function Bt(t,e,r){return(e=Mt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Mt(t){var e=function(t,e){if("object"!=_t(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=_t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==_t(e)?e:e+""}var It=function(t){function e(t){var r;return jt(this,e),Bt(r=Rt(this,e,[t]),"interval",void 0),Bt(r,"pricesCounter",0),Bt(r,"weightFactor",void 0),r.interval=t,r.weightFactor=2/(r.interval+1),r}return Ct(e,t),Et(e,[{key:"update",value:function(t){var e,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];r?r&&0===this.pricesCounter&&this.pricesCounter++:this.pricesCounter++;var n=new v(t);return r&&this.previousResult?this.setResult(n.times(this.weightFactor).add(this.previousResult.times(1-this.weightFactor)),r):this.setResult(n.times(this.weightFactor).add((null!==(e=this.result)&&void 0!==e?e:n).times(1-this.weightFactor)),r)}},{key:"getResult",value:function(){if(this.pricesCounter<this.interval)throw new m;return this.result}},{key:"isStable",get:function(){try{return this.getResult(),!0}catch(t){return!1}}}])}(D),xt=function(t){function e(t){var r;return jt(this,e),Bt(r=Rt(this,e,[t]),"interval",void 0),Bt(r,"pricesCounter",0),Bt(r,"weightFactor",void 0),r.interval=t,r.weightFactor=2/(r.interval+1),r}return Ct(e,t),Et(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e?e&&0===this.pricesCounter&&this.pricesCounter++:this.pricesCounter++,e&&void 0!==this.previousResult?this.setResult(t*this.weightFactor+this.previousResult*(1-this.weightFactor),e):this.setResult(t*this.weightFactor+(void 0!==this.result?this.result:t)*(1-this.weightFactor),e)}},{key:"getResult",value:function(){if(this.pricesCounter<this.interval)throw new m;return this.result}},{key:"isStable",get:function(){try{return this.getResult(),!0}catch(t){return!1}}}])}(N);function Ht(t){return Ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ht(t)}function Ft(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Lt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Gt(n.key),n)}}function Dt(t,e,r){return e&&Lt(t.prototype,e),r&&Lt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function Nt(t,e,r){return(e=Gt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Gt(t){var e=function(t,e){if("object"!=Ht(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=Ht(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ht(e)?e:e+""}var qt=function(){return Dt((function t(e){Ft(this,t),Nt(this,"prices",[]),Nt(this,"long",void 0),Nt(this,"short",void 0),Nt(this,"signal",void 0),Nt(this,"result",void 0),this.long=new e.indicator(e.longInterval),this.short=new e.indicator(e.shortInterval),this.signal=new e.indicator(e.signalInterval)}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=new v(t);this.prices.length&&e?this.prices[this.prices.length-1]=r:this.prices.push(r);var n=this.short.update(r,e),i=this.long.update(r,e);if(this.prices.length>this.long.interval&&this.prices.shift(),this.prices.length===this.long.interval){var o=n.sub(i),u=this.signal.update(o);return this.result={histogram:o.sub(u),macd:o,signal:u}}}},{key:"getResult",value:function(){if(!this.isStable||void 0===this.result)throw new m;return this.result}}])}(),zt=function(){return Dt((function t(e,r,n){Ft(this,t),Nt(this,"short",void 0),Nt(this,"long",void 0),Nt(this,"signal",void 0),Nt(this,"prices",[]),Nt(this,"result",void 0),this.short=e,this.long=r,this.signal=n}),[{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"isStable",get:function(){return void 0!==this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.prices.length&&e?this.prices[this.prices.length-1]=t:this.prices.push(t);var r=this.short.update(t,e),n=this.long.update(t,e);if(this.prices.length>this.long.interval&&this.prices.shift(),this.prices.length===this.long.interval){var i=r-n,o=this.signal.update(i,e);return this.result={histogram:i-o,macd:i,signal:o}}}}])}();function Vt(t){return Vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Vt(t)}function Ut(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function $t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,te(n.key),n)}}function Kt(t,e,r){return e&&$t(t.prototype,e),r&&$t(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function Jt(t,e,r){return e=Wt(e),function(t,e){if(e&&("object"==Vt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Qt()?Reflect.construct(e,r||[],Wt(t).constructor):e.apply(t,r))}function Qt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(Qt=function(){return!!t})()}function Wt(t){return Wt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Wt(t)}function Xt(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Yt(t,e)}function Yt(t,e){return Yt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Yt(t,e)}function Zt(t,e,r){return(e=te(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function te(t){var e=function(t,e){if("object"!=Vt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=Vt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Vt(e)?e:e+""}var ee=function(t){function e(t){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ft;return Ut(this,e),Zt(r=Jt(this,e),"interval",void 0),Zt(r,"previousPrices",[]),Zt(r,"avgGain",void 0),Zt(r,"avgLoss",void 0),Zt(r,"maxValue",new v(100)),r.interval=t,r.avgGain=new n(r.interval),r.avgLoss=new n(r.interval),r}return Xt(e,t),Kt(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.previousPrices.length&&e?this.previousPrices[this.previousPrices.length-1]=t:this.previousPrices.push(t),!(this.previousPrices.length<2)){var r=new v(t),n=new v(this.previousPrices[this.previousPrices.length-2]);if(r.gt(n)?(this.avgLoss.update(new v(0),e),this.avgGain.update(r.sub(n),e)):(this.avgLoss.update(n.sub(r),e),this.avgGain.update(new v(0),e)),this.avgGain.isStable){var i=this.avgLoss.getResult();if(i.eq(0))return this.setResult(new v(100),e);var o=this.avgGain.getResult().div(i);return this.setResult(this.maxValue.minus(this.maxValue.div(o.add(1))),e)}}}}])}(E),re=function(t){function e(t){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ht;return Ut(this,e),Zt(r=Jt(this,e),"interval",void 0),Zt(r,"previousPrices",[]),Zt(r,"avgGain",void 0),Zt(r,"avgLoss",void 0),Zt(r,"maxValue",100),r.interval=t,r.avgGain=new n(r.interval),r.avgLoss=new n(r.interval),r}return Xt(e,t),Kt(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.previousPrices.length&&e?this.previousPrices[this.previousPrices.length-1]=t:this.previousPrices.push(t),!(this.previousPrices.length<2)){var r=t,n=this.previousPrices[this.previousPrices.length-2];if(r>n?(this.avgLoss.update(0,e),this.avgGain.update(t-n,e)):(this.avgLoss.update(n-r,e),this.avgGain.update(0,e)),this.avgGain.isStable){var i=this.avgLoss.getResult();if(0===i)return this.setResult(100,e);var o=this.avgGain.getResult()/i;return this.setResult(this.maxValue-this.maxValue/(o+1),e)}}}}])}(R);function ne(t){return ne="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ne(t)}var ie=function(t,e,r){if(void 0===r||void 0===t||void 0===e)throw Error("undefined param in getEMA");for(var n=t.length,i=new Array(n).fill(null),o=r?new It(e):new xt(e),u=0;u<n;u++){var s=null;if(null!==t[u]){o.update(t[u]);try{s=o.getResult()}catch(t){s=null}}i[u]=s}return i};function oe(t){return oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},oe(t)}var ue=function(t,e,r){if(void 0===r||void 0===t||void 0===e)throw Error("undefined param in getSMA");for(var n=t.length,i=new Array(n).fill(null),o=r?new Y(e):new Z(e),u=0;u<n;u++){var s=null;if(null!==t[u]){o.update(t[u]);try{s=o.getResult()}catch(t){s=null}}i[u]=s}return i};function se(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var le=function(t){var e,r,n,i=t.fast,o=t.slow,u=t.precision,s=i.length;if(s==!o.length)throw Error("fast and slow do not have the same length");u?(e=function(t,e){return t.eq(e)},r=function(t,e){return t.gt(e)},n=function(t,e){return t.lt(e)}):(e=function(t,e){return t===e},r=function(t,e){return t>e},n=function(t,e){return t<e});for(var l=new Array(s).fill(null),a=0;a<s;a++){var c=i[a],f=o[a],h=void 0;null===c||null===f?h="neutral":e(c,f)?h=r(i[a-1],o[a-1])?"up":n(i[a-1],o[a-1])?"down":"neutral":r(c,f)?h="up":n(c,f)&&(h="down"),l[a]=h}var v=ae(l),p=v.map((function(t){return t.length}));return v.map((function(t,e){var r=p[e];return t.map((function(t,e){var n=r-e;return"neutral"===t&&(n=0),"up"===t&&(n*=1),"down"===t&&(n*=-1),n})).reverse()})).flat()},ae=function(t){return 0===t.length?[]:t.reduce((function(t,e,r,n){if(0===r)t.push([e]);else{var i=n[r-1],o=t[t.length-1];e!==i?t.push([e]):o.push(e)}return t}),[])};function ce(t){return ce="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ce(t)}var fe={getSMA:ue,getEMA:ie},he=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:14,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"SMA",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:14,i=arguments.length>4?arguments[4]:void 0,o=t.length;if(o<e)return[];for(var u=new Array(o).fill(null),s=i?new ee(e):new re(e),l=0;l<o;l++){var a=null;if(null!==t[l]){s.update(t[l]);try{a=s.getResult()}catch(t){a=null}}u[l]=a}var c,f,h,v=(c={},f="rsi_".concat(e),h=u,(f=function(t){var e=function(t,e){if("object"!=ce(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=ce(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ce(e)?e:e+""}(f))in c?Object.defineProperty(c,f,{value:h,enumerable:!0,configurable:!0,writable:!0}):c[f]=h,c);if("string"==typeof r&&"number"==typeof n&&fe.hasOwnProperty("get".concat(r))){var p=fe["get".concat(r)](u,n,i);v["rsi_".concat(r,"_").concat(n)]=p,v["rsi_".concat(e,"_x_rsi_").concat(r,"_").concat(n)]=le({fast:u,slow:p,precision:i})}return v};function ve(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return pe(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?pe(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){s=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(s)throw o}}}}function pe(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var ye=[{candle_name:"isHammer",candle_score:1,isSingleCandle:!0},{candle_name:"isInvertedHammer",candle_score:1,isSingleCandle:!0},{candle_name:"isBullishHammer",candle_score:1,isSingleCandle:!0},{candle_name:"isBearishHammer",candle_score:-1,isSingleCandle:!0},{candle_name:"isBullishInvertedHammer",candle_score:1,isSingleCandle:!0},{candle_name:"isBearishInvertedHammer",candle_score:-1,isSingleCandle:!0},{candle_name:"isHangingMan",candle_score:-1,isSingleCandle:!1},{candle_name:"isShootingStar",candle_score:-1,isSingleCandle:!1},{candle_name:"isBullishEngulfing",candle_score:1,isSingleCandle:!1},{candle_name:"isBearishEngulfing",candle_score:-1,isSingleCandle:!1},{candle_name:"isBullishHarami",candle_score:1,isSingleCandle:!1},{candle_name:"isBearishHarami",candle_score:-1},{candle_name:"isBullishKicker",candle_score:1,isSingleCandle:!1},{candle_name:"isBearishKicker",candle_score:-1,isSingleCandle:!1}],de=function(t){return Math.abs(t.open-t.close)},be=function(t){return t.high-Math.max(t.open,t.close)},ge=function(t){return Math.min(t.open,t.close)-t.low},me=function(t){return t.open<=t.close?{bottom:t.open,top:t.close}:{bottom:t.close,top:t.open}},we=function(t){return t.open<t.close},Oe=function(t){return t.open>t.close},Se=function(t,e){return me(t).top<=me(e).top&&me(t).bottom>=me(e).bottom},_e=function(t,e){return me(t).top<me(e).bottom},je=function(t){return ge(t)>2*de(t)&&be(t)<de(t)},Pe=function(t){return be(t)>2*de(t)&&ge(t)<de(t)},Ee=function(t){return Oe(t)&&je(t)},Re=function(t){return Oe(t)&&Pe(t)},Ae={isHammer:je,isInvertedHammer:Pe,isBullishHammer:function(t){return we(t)&&je(t)},isBearishHammer:Ee,isBullishInvertedHammer:function(t){return we(t)&&Pe(t)},isBearishInvertedHammer:Re,isHangingMan:function(t,e){return we(t)&&Ee(e)&&_e(t,e)},isShootingStar:function(t,e){return we(t)&&Re(e)&&_e(t,e)},isBullishEngulfing:function(t,e){return Oe(t)&&we(e)&&Se(t,e)},isBearishEngulfing:function(t,e){return we(t)&&Oe(e)&&Se(t,e)},isBullishHarami:function(t,e){return Oe(t)&&we(e)&&Se(e,t)},isBearishHarami:function(t,e){return we(t)&&Oe(e)&&Se(e,t)},isBullishKicker:function(t,e){return Oe(t)&&we(e)&&_e(t,e)&&!(je(e)||Pe(e))},isBearishKicker:function(t,e){return we(t)&&Oe(e)&&function(t,e){return me(t).bottom>me(e).top}(t,e)&&!(je(e)||Pe(e))}};function ke(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Ce(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Ce(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){s=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(s)throw o}}}}function Ce(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var Te=function(t,e){return null===t||null===e?null:t>1.25*e?"large":t<.75*e?"small":"medium"};function Be(t){return Be="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Be(t)}function Me(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,u,s=[],l=!0,a=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=o.call(r)).done)&&(s.push(n.value),s.length!==e);l=!0);}catch(t){a=!0,i=t}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(a)throw i}}return s}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Ie(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Ie(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ie(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function xe(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,He(n.key),n)}}function He(t){var e=function(t,e){if("object"!=Be(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=Be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Be(e)?e:e+""}var Fe=function(){return t=function t(e){var r=this,n=e.input,i=e.precision,o=void 0!==i&&i,u=e.ticker,s=void 0===u?"undefined":u;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),!Array.isArray(n))throw Error("input ohlcv must be an array: "+s);if(0===n.length)throw Error("input ohlcv must not be empty: "+s);if(!n[0].hasOwnProperty("close"))throw Error("input ohlcv array objects require at least close property: "+s);var l=function(t){return r.precision?new v(t):t};return this.len=n.length,this.precision=o,this.big=l,this.crossPairsArr=[],this.inputOhlcv=n,this.verticalOhlcv=function(t,e,r){for(var n=["open","high","low","close","volume"],i=new Set(n),o={},u=0,s=n;u<s.length;u++)o[s[u]]=new Array(e);for(var l,a=[],c=0,f=Object.keys(t[0]);c<f.length;c++){var h=f[c];i.has(h)||(o[h]=new Array(e),a.push(h))}var v,p=0,y=0,d=(v=t)[0].hasOwnProperty("date")&&/^\d{4}-\d{2}-\d{2}/.test(v[0].date);d&&(o.session_index=new Array(e),o.session_intraday_index=new Array(e),l=t[0].date.slice(0,10));for(var b=0;b<e;b++){var g=t[b];o.open[b]=r(g.open),o.high[b]=r(g.high),o.low[b]=r(g.low),o.close[b]=r(g.close),o.volume[b]=r(g.volume);var m,w=ke(a);try{for(w.s();!(m=w.n()).done;){var O=m.value;o[O][b]=g[O]}}catch(t){w.e(t)}finally{w.f()}if(d){var S=g.date.slice(0,10);S!==l&&(l=S,p++,y=0),o.session_index[b]=p,o.session_intraday_index[b]=y,y++}}return o}(n,this.len,l),this.indicators={},this.studies={},this.isComputed=!1,this},(e=[{key:"getData",value:function(){this.computeIndicators();var t=this.verticalOhlcv,e=this.precision,r=Object.keys(t),n=r.length;return t.open.map((function(i,o){for(var u={},s=0;s<n;s++){var l=r[s],a=t[l][o];u[l]=e&&a instanceof v?a.toNumber():a}return u}))}},{key:"getLastValues",value:function(){this.computeIndicators();for(var t=this.verticalOhlcv,e=this.precision,r=this.len,n={},i=0,o=Object.entries(t);i<o.length;i++){var u=Me(o[i],2),s=u[0],l=u[1][r-1];n[s]=e&&l instanceof v?l.toNumber():l}return Object.assign(n,this.studies),n}},{key:"computeIndicators",value:function(){if(!0===this.isComputed)return!1;this.isComputed;for(var t=this.indicators,e=this.addColumn.bind(this),r=0,n=Object.entries(t);r<n.length;r++){var i=Me(n[r],2),o=i[0],u=i[1];this.verticalOhlcv.hasOwnProperty(o)?delete this.indicators[o]:e(o,u)}return!0}},{key:"addColumn",value:function(t,e){var r=this.len;if(t=t.toLowerCase(),e.length>r)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");if(e.length<r){var n=r-e.length;e=new Array(n).fill(null).concat(e)}this.verticalOhlcv[t]=e}},{key:"crossPairs",value:function(t){this.computeIndicators();var e=function(t,e){var r,n=t.verticalOhlcv,i=t.precision,o=t.big,u=t.len,s={},l={},a={},c=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return se(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?se(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){s=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(s)throw o}}}}(e);try{var f=function(){var t=r.value,e=t.fast,c=t.slow,f=t.count;if(!e||!c)return 1;"number"!=typeof c||s[c]||(s[c]=Array(u).fill(o(c)));var h="".concat(e,"_x_").concat(c),v="".concat(e,"_c_").concat(c),p=function(t){return void 0!==f?t.slice(-f).filter((function(t){return 1===t||-1===t})).length:0};if(n[h]){var y=n[h];l[h]=y,void 0!==f&&(a[v]=p(y))}else if(n[e]&&n[c]){var d=le({fast:n[e],slow:n[c],precision:i});l[h]=d,void 0!==f&&(a[v]=p(d))}else if(n[e]&&s[c]){var b=le({fast:n[e],slow:s[c],precision:i});l[h]=b,void 0!==f&&(a[v]=p(b))}else console.log("Missing ohlcv properties for ".concat(e," or ").concat(c))};for(c.s();!(r=c.n()).done;)f()}catch(t){c.e(t)}finally{c.f()}return{x:l,c:a}}(this,t),r=e.x,n=e.c;return Object.assign(this.indicators,r),Object.assign(this.studies,n),this.computeIndicators(),this}},{key:"ema",value:function(t){var e=function(t,e){var r=t.verticalOhlcv,n=t.precision,i=r.close,o=ie(i,e,n);return function(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=ne(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=ne(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ne(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}({},"ema_".concat(e),o)}(this,t);return Object.assign(this.indicators,e),this}},{key:"sma",value:function(t){var e=function(t,e){var r=t.verticalOhlcv,n=t.precision,i=r.close,o=ue(i,e,n);return function(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=oe(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==oe(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}({},"sma_".concat(e),o)}(this,t);return Object.assign(this.indicators,e),this}},{key:"macd",value:function(t,e,r){var n=function(t,e,r,n){var i=t.verticalOhlcv,o=t.precision;return function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:12,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:26,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:9,i=arguments.length>4?arguments[4]:void 0,o=t.length,u=new Array(o).fill(null),s=new Array(o).fill(null),l=new Array(o).fill(null),a=i?new qt({indicator:It,shortInterval:e,longInterval:r,signalInterval:n}):new zt(new xt(e),new xt(r),new xt(n)),c=0;c<o;c++){var f={};a.update(t[c]);try{f=a.getResult()}catch(t){f={macd:null,signal:null,histogram:null}}u[c]=f.macd,s[c]=f.signal,l[c]=f.histogram}return{macd_diff:u,macd_dea:s,macd_histogram:l,macd_diff_x_macd_dea:le({fast:u,slow:s,precision:i})}}(i.close,e,r,n,o)}(this,t,e,r);return Object.assign(this.indicators,n),this}},{key:"bollingerBands",value:function(t,e){var r=function(t,e,r){var n=t.verticalOhlcv,i=t.precision;return function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,o=arguments.length>3?arguments[3]:void 0,u=t.length,s=Array(u).fill(null),l=Array(u).fill(null),a=Array(u).fill(null),c=Array(u).fill(null),f=Array(u).fill(null),h=null,v=null;o?(r=new Ot(n,i),e=function(t,e,r){return{range:t.minus(r).div(e.minus(r)).times(100),height:e.minus(r).div(r).times(100)}}):(r=new St(n,i),e=function(t,e,r){return{range:(t-r)/(e-r)*100,height:(e-r)/r*100}});for(var p=0;p<u;p++){var y={};r.update(t[p]);var d=!1;try{y=r.getResult()}catch(t){d=!0,y={upper:null,middle:null,lower:null}}if(s[p]=y.upper,l[p]=y.middle,a[p]=y.lower,d)c[p]=null,f[p]=null;else{var b=e(t[p],y.upper,y.lower);h=b.range,v=b.height}c[p]=h,f[p]=v}return{bollinger_bands_upper:s,bollinger_bands_middle:l,bollinger_bands_lower:a,bollinger_bands_range:c,bollinger_bands_height:f}}(n.close,e,r,i)}(this,t,e);return Object.assign(this.indicators,r),this}},{key:"rsi",value:function(t,e,r){var n=function(t,e,r,n){var i=t.verticalOhlcv,o=t.precision,u=i.close;return"number"==typeof e&&void 0===n&&(n=e),he(u,e,r,n,o)}(this,t,e,r);return Object.assign(this.indicators,n),this}},{key:"candles",value:function(){var t=function(t,e){for(var r=[],n=[],i=[],o=1;o<e;o++){var u,s=t[o],l=t[o-1],a="Neutral",c="None",f=0,h=ve(ye);try{for(h.s();!(u=h.n()).done;){var v=u.value,p=v.isSingleCandle,y=v.candle_name,d=v.candle_score;if(p?Ae[y](s):Ae[y](l,s))if(0===f)a=1===d?"Bullish":"Bearish",c=y,f=d;else{if(f!==d){a="Neutral",c="None",f=0;break}c+=",".concat(y)}}}catch(t){h.e(t)}finally{h.f()}r.push(a),n.push(c),i.push(f)}return{candle_pattern:r,candle_name:n,candle_score:i}}(this.inputOhlcv,this.len);return Object.assign(this.indicators,t),this}},{key:"orb",value:function(){var t,e,r,n=(e=(t=this).inputOhlcv,r=t.len,t.precision,t.verticalOhlcv.close,function(t,e,r,n){for(var i=new Array(r).fill(0),o=new Array(r).fill(0),u=0,s=null,l=0,a=0,c=0;c<r;c++){var f=t[c];if(0===c&&!f.hasOwnProperty("date"))throw Error("input ohlcv array must have a date property available in candle datapoint");var h=f.date.split(" ")[0];h!==s&&(s=h,l=f.high,a=f.low),i[u]=l,o[u]=a,u++}return{orb_high:i,orb_low:o}}(e,0,r));return Object.assign(this.indicators,n),this}},{key:"donchianChannels",value:function(t,e){var r=function(t,e,r){var n=t.verticalOhlcv,i=t.precision,o=t.len;return function(t,e,r,n,i,o){for(var u=new Array(o).fill(null),s=new Array(o).fill(null),l=new Array(o).fill(null),a=[],c=[],f=i?function(t,e){return t.plus(e).div(2)}:function(t,e){return(t+e)/2},h=0;h<o;h++){for(;a.length&&a[0]<=h-r;)a.shift();for(;a.length&&t[a[a.length-1]]<=t[h];)a.pop();for(a.push(h);c.length&&c[0]<=h-r;)c.shift();for(;c.length&&e[c[c.length-1]]>=e[h];)c.pop();if(c.push(h),h>=r-1){var v=t[a[0]],p=e[c[0]],y=f(v,p),d=h+n;d>=0&&d<o&&(u[d]=v,s[d]=p,l[d]=y)}}return{donchian_channel_upper:u,donchian_channel_lower:s,donchian_channel_basis:l}}(n.high,n.low,e,r,i,o)}(this,t,e);return Object.assign(this.indicators,r),this}},{key:"candlesStudies",value:function(t){var e=function(t,e){return function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,r=arguments.length>2?arguments[2]:void 0,n=function(t,e){return Math.abs(t-e)},i=new Array(r).fill(null),o=new Array(r).fill(null),u=new Array(r).fill(null),s=new Array(r).fill(null),l=new Array(r).fill(null),a=new Array(r).fill(null),c=new Array(r).fill(null),f=new Array(r).fill(null),h=new Array(r).fill(null),v=new Array(r).fill(null),p=new Z(e),y=new Z(e),d=new Z(e),b=0;b<r;b++){var g=t[b],m=g.open,w=g.high,O=g.low,S=g.close,_=null,j=null,P=null,E=n(m,S),R=void 0,A=void 0,k=S>m?"up":"down";"up"===k?(R=n(w,S),A=n(m,O)):(R=n(w,m),A=n(S,O)),p.update(E),y.update(R),d.update(A);try{_=p.getResult(),j=y.getResult(),P=d.getResult()}catch(t){_=null}i[b]=k,o[b]=E,u[b]=_,s[b]=Te(E,_),a[b]=R,l[b]=j,c[b]=Te(R,j),h[b]=A,f[b]=P,v[b]=Te(A,P)}return{candle_direction:i,candle_body_size_mean:u,candle_body_size:o,candle_body_size_label:s,candle_top_size_mean:l,candle_top_size:a,candle_top_size_label:c,candle_bottom_size_mean:f,candle_bottom_size:h,candle_bottom_size_label:v}}(t.inputOhlcv,e,t.len)}(this,t);return Object.assign(this.indicators,e),this}}])&&xe(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}()})(),OHLCV_INDICATORS=e})();
|
|
1
|
+
var OHLCV_INDICATORS;(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};(()=>{t.r(e),t.d(e,{default:()=>Oe});var r=1e6,n="[big.js] ",i=n+"Invalid ",o=i+"decimal places",u=i+"rounding mode",s=n+"Division by zero",l={},c=void 0,a=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function f(t,e,r,n){var i=t.c;if(r===c&&(r=t.constructor.RM),0!==r&&1!==r&&2!==r&&3!==r)throw Error(u);if(e<1)n=3===r&&(n||!!i[0])||0===e&&(1===r&&i[0]>=5||2===r&&(i[0]>5||5===i[0]&&(n||i[1]!==c))),i.length=1,n?(t.e=t.e-e+1,i[0]=1):i[0]=t.e=0;else if(e<i.length){if(n=1===r&&i[e]>=5||2===r&&(i[e]>5||5===i[e]&&(n||i[e+1]!==c||1&i[e-1]))||3===r&&(n||!!i[0]),i.length=e,n)for(;++i[--e]>9;)if(i[e]=0,0===e){++t.e,i.unshift(1);break}for(e=i.length;!i[--e];)i.pop()}return t}function h(t,e,r){var n=t.e,i=t.c.join(""),o=i.length;if(e)i=i.charAt(0)+(o>1?"."+i.slice(1):"")+(n<0?"e":"e+")+n;else if(n<0){for(;++n;)i="0"+i;i="0."+i}else if(n>0)if(++n>o)for(n-=o;n--;)i+="0";else n<o&&(i=i.slice(0,n)+"."+i.slice(n));else o>1&&(i=i.charAt(0)+"."+i.slice(1));return t.s<0&&r?"-"+i:i}l.abs=function(){var t=new this.constructor(this);return t.s=1,t},l.cmp=function(t){var e,r=this,n=r.c,i=(t=new r.constructor(t)).c,o=r.s,u=t.s,s=r.e,l=t.e;if(!n[0]||!i[0])return n[0]?o:i[0]?-u:0;if(o!=u)return o;if(e=o<0,s!=l)return s>l^e?1:-1;for(u=(s=n.length)<(l=i.length)?s:l,o=-1;++o<u;)if(n[o]!=i[o])return n[o]>i[o]^e?1:-1;return s==l?0:s>l^e?1:-1},l.div=function(t){var e=this,n=e.constructor,i=e.c,u=(t=new n(t)).c,l=e.s==t.s?1:-1,a=n.DP;if(a!==~~a||a<0||a>r)throw Error(o);if(!u[0])throw Error(s);if(!i[0])return t.s=l,t.c=[t.e=0],t;var h,v,p,y,d,b=u.slice(),g=h=u.length,m=i.length,w=i.slice(0,h),O=w.length,j=t,S=j.c=[],P=0,_=a+(j.e=e.e-t.e)+1;for(j.s=l,l=_<0?0:_,b.unshift(0);O++<h;)w.push(0);do{for(p=0;p<10;p++){if(h!=(O=w.length))y=h>O?1:-1;else for(d=-1,y=0;++d<h;)if(u[d]!=w[d]){y=u[d]>w[d]?1:-1;break}if(!(y<0))break;for(v=O==h?u:b;O;){if(w[--O]<v[O]){for(d=O;d&&!w[--d];)w[d]=9;--w[d],w[O]+=10}w[O]-=v[O]}for(;!w[0];)w.shift()}S[P++]=y?p:++p,w[0]&&y?w[O]=i[g]||0:w=[i[g]]}while((g++<m||w[0]!==c)&&l--);return S[0]||1==P||(S.shift(),j.e--,_--),P>_&&f(j,_,n.RM,w[0]!==c),j},l.eq=function(t){return 0===this.cmp(t)},l.gt=function(t){return this.cmp(t)>0},l.gte=function(t){return this.cmp(t)>-1},l.lt=function(t){return this.cmp(t)<0},l.lte=function(t){return this.cmp(t)<1},l.minus=l.sub=function(t){var e,r,n,i,o=this,u=o.constructor,s=o.s,l=(t=new u(t)).s;if(s!=l)return t.s=-l,o.plus(t);var c=o.c.slice(),a=o.e,f=t.c,h=t.e;if(!c[0]||!f[0])return f[0]?t.s=-l:c[0]?t=new u(o):t.s=1,t;if(s=a-h){for((i=s<0)?(s=-s,n=c):(h=a,n=f),n.reverse(),l=s;l--;)n.push(0);n.reverse()}else for(r=((i=c.length<f.length)?c:f).length,s=l=0;l<r;l++)if(c[l]!=f[l]){i=c[l]<f[l];break}if(i&&(n=c,c=f,f=n,t.s=-t.s),(l=(r=f.length)-(e=c.length))>0)for(;l--;)c[e++]=0;for(l=e;r>s;){if(c[--r]<f[r]){for(e=r;e&&!c[--e];)c[e]=9;--c[e],c[r]+=10}c[r]-=f[r]}for(;0===c[--l];)c.pop();for(;0===c[0];)c.shift(),--h;return c[0]||(t.s=1,c=[h=0]),t.c=c,t.e=h,t},l.mod=function(t){var e,r=this,n=r.constructor,i=r.s,o=(t=new n(t)).s;if(!t.c[0])throw Error(s);return r.s=t.s=1,e=1==t.cmp(r),r.s=i,t.s=o,e?new n(r):(i=n.DP,o=n.RM,n.DP=n.RM=0,r=r.div(t),n.DP=i,n.RM=o,this.minus(r.times(t)))},l.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t},l.plus=l.add=function(t){var e,r,n,i=this,o=i.constructor;if(t=new o(t),i.s!=t.s)return t.s=-t.s,i.minus(t);var u=i.e,s=i.c,l=t.e,c=t.c;if(!s[0]||!c[0])return c[0]||(s[0]?t=new o(i):t.s=i.s),t;if(s=s.slice(),e=u-l){for(e>0?(l=u,n=c):(e=-e,n=s),n.reverse();e--;)n.push(0);n.reverse()}for(s.length-c.length<0&&(n=c,c=s,s=n),e=c.length,r=0;e;s[e]%=10)r=(s[--e]=s[e]+c[e]+r)/10|0;for(r&&(s.unshift(r),++l),e=s.length;0===s[--e];)s.pop();return t.c=s,t.e=l,t},l.pow=function(t){var e=this,r=new e.constructor("1"),n=r,o=t<0;if(t!==~~t||t<-1e6||t>1e6)throw Error(i+"exponent");for(o&&(t=-t);1&t&&(n=n.times(e)),t>>=1;)e=e.times(e);return o?r.div(n):n},l.prec=function(t,e){if(t!==~~t||t<1||t>r)throw Error(i+"precision");return f(new this.constructor(this),t,e)},l.round=function(t,e){if(t===c)t=0;else if(t!==~~t||t<-r||t>r)throw Error(o);return f(new this.constructor(this),t+this.e+1,e)},l.sqrt=function(){var t,e,r,i=this,o=i.constructor,u=i.s,s=i.e,l=new o("0.5");if(!i.c[0])return new o(i);if(u<0)throw Error(n+"No square root");0===(u=Math.sqrt(i+""))||u===1/0?((e=i.c.join("")).length+s&1||(e+="0"),s=((s+1)/2|0)-(s<0||1&s),t=new o(((u=Math.sqrt(e))==1/0?"5e":(u=u.toExponential()).slice(0,u.indexOf("e")+1))+s)):t=new o(u+""),s=t.e+(o.DP+=4);do{r=t,t=l.times(r.plus(i.div(r)))}while(r.c.slice(0,s).join("")!==t.c.slice(0,s).join(""));return f(t,(o.DP-=4)+t.e+1,o.RM)},l.times=l.mul=function(t){var e,r=this,n=r.constructor,i=r.c,o=(t=new n(t)).c,u=i.length,s=o.length,l=r.e,c=t.e;if(t.s=r.s==t.s?1:-1,!i[0]||!o[0])return t.c=[t.e=0],t;for(t.e=l+c,u<s&&(e=i,i=o,o=e,c=u,u=s,s=c),e=new Array(c=u+s);c--;)e[c]=0;for(l=s;l--;){for(s=0,c=u+l;c>l;)s=e[c]+o[l]*i[c-l-1]+s,e[c--]=s%10,s=s/10|0;e[c]=s}for(s?++t.e:e.shift(),l=e.length;!e[--l];)e.pop();return t.c=e,t},l.toExponential=function(t,e){var n=this,i=n.c[0];if(t!==c){if(t!==~~t||t<0||t>r)throw Error(o);for(n=f(new n.constructor(n),++t,e);n.c.length<t;)n.c.push(0)}return h(n,!0,!!i)},l.toFixed=function(t,e){var n=this,i=n.c[0];if(t!==c){if(t!==~~t||t<0||t>r)throw Error(o);for(t=t+(n=f(new n.constructor(n),t+n.e+1,e)).e+1;n.c.length<t;)n.c.push(0)}return h(n,!1,!!i)},l[Symbol.for("nodejs.util.inspect.custom")]=l.toJSON=l.toString=function(){var t=this,e=t.constructor;return h(t,t.e<=e.NE||t.e>=e.PE,!!t.c[0])},l.toNumber=function(){var t=Number(h(this,!0,!0));if(!0===this.constructor.strict&&!this.eq(t.toString()))throw Error(n+"Imprecise conversion");return t},l.toPrecision=function(t,e){var n=this,o=n.constructor,u=n.c[0];if(t!==c){if(t!==~~t||t<1||t>r)throw Error(i+"precision");for(n=f(new o(n),t,e);n.c.length<t;)n.c.push(0)}return h(n,t<=n.e||n.e<=o.NE||n.e>=o.PE,!!u)},l.valueOf=function(){var t=this,e=t.constructor;if(!0===e.strict)throw Error(n+"valueOf disallowed");return h(t,t.e<=e.NE||t.e>=e.PE,!0)};const v=function t(){function e(r){var n=this;if(!(n instanceof e))return r===c?t():new e(r);if(r instanceof e)n.s=r.s,n.e=r.e,n.c=r.c.slice();else{if("string"!=typeof r){if(!0===e.strict&&"bigint"!=typeof r)throw TypeError(i+"value");r=0===r&&1/r<0?"-0":String(r)}!function(t,e){var r,n,o;if(!a.test(e))throw Error(i+"number");for(t.s="-"==e.charAt(0)?(e=e.slice(1),-1):1,(r=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(r<0&&(r=n),r+=+e.slice(n+1),e=e.substring(0,n)):r<0&&(r=e.length),o=e.length,n=0;n<o&&"0"==e.charAt(n);)++n;if(n==o)t.c=[t.e=0];else{for(;o>0&&"0"==e.charAt(--o););for(t.e=r-n-1,t.c=[],r=0;n<=o;)t.c[r++]=+e.charAt(n++)}}(n,r)}n.constructor=e}return e.prototype=l,e.DP=20,e.RM=1,e.NE=-7,e.PE=21,e.strict=!1,e.roundDown=0,e.roundHalfUp=1,e.roundHalfEven=2,e.roundUp=3,e}();function p(t){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p(t)}function y(t){var e="function"==typeof Map?new Map:void 0;return y=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(d())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var i=new(t.bind.apply(t,n));return r&&b(i,r.prototype),i}(t,arguments,g(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),b(r,t)},y(t)}function d(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(d=function(){return!!t})()}function b(t,e){return b=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},b(t,e)}function g(t){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},g(t)}var m=function(t){function e(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not enough data";return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),t=function(t,e,r){return e=g(e),function(t,e){if(e&&("object"==p(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,d()?Reflect.construct(e,r||[],g(t).constructor):e.apply(t,r))}(this,e,[r]),Object.setPrototypeOf(t,(this instanceof e?this.constructor:void 0).prototype),t.name="NotEnoughDataError",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&b(t,e)}(e,t),r=e,Object.defineProperty(r,"prototype",{writable:!1}),r;var r}(y(Error));function w(t){return w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},w(t)}function O(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function j(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,_(n.key),n)}}function S(t,e,r){return e&&j(t.prototype,e),r&&j(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function P(t,e,r){return(e=_(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _(t){var e=function(t,e){if("object"!=w(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=w(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==w(e)?e:e+""}var E=function(){return S((function t(){O(this,t),P(this,"previousHighest",void 0),P(this,"highest",void 0),P(this,"previousLowest",void 0),P(this,"lowest",void 0),P(this,"previousResult",void 0),P(this,"result",void 0)}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"setResult",value:function(t,e){return e&&(this.highest=this.previousHighest,this.lowest=this.previousLowest,this.result=this.previousResult),void 0===this.highest?this.highest=t:t.gt(this.highest)?(this.previousHighest=this.highest,this.highest=t):this.previousHighest=this.highest,void 0===this.lowest?this.lowest=t:t.lt(this.lowest)?(this.previousLowest=this.lowest,this.lowest=t):this.previousLowest=this.lowest,this.previousResult=this.result,this.result=t}},{key:"replace",value:function(t){return this.update(t,!0)}}])}(),R=function(){return S((function t(){O(this,t),P(this,"previousHighest",void 0),P(this,"highest",void 0),P(this,"previousLowest",void 0),P(this,"lowest",void 0),P(this,"previousResult",void 0),P(this,"result",void 0)}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"setResult",value:function(t,e){return e&&(this.highest=this.previousHighest,this.lowest=this.previousLowest,this.result=this.previousResult),void 0===this.highest?this.highest=t:t>this.highest?(this.previousHighest=this.highest,this.highest=t):this.previousHighest=this.highest,void 0===this.lowest?this.lowest=t:t<this.lowest?(this.previousLowest=this.lowest,this.lowest=t):this.previousLowest=this.lowest,this.previousResult=this.result,this.result=t}},{key:"replace",value:function(t){return this.update(t,!0)}}])}();function k(t){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k(t)}function A(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function T(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,B(n.key),n)}}function C(t,e,r){return e&&T(t.prototype,e),r&&T(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function x(t,e,r){return e=I(e),function(t,e){if(e&&("object"==k(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,M()?Reflect.construct(e,r||[],I(t).constructor):e.apply(t,r))}function M(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(M=function(){return!!t})()}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function F(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&L(t,e)}function L(t,e){return L=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},L(t,e)}function D(t,e,r){return(e=B(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function B(t){var e=function(t,e){if("object"!=k(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==k(e)?e:e+""}var N=function(t){function e(t){var r;return A(this,e),D(r=x(this,e),"interval",void 0),r.interval=t,r}return F(e,t),C(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"replace",value:function(t){return this.update(t,!0)}}])}(E),H=function(t){function e(t){var r;return A(this,e),D(r=x(this,e),"interval",void 0),r.interval=t,r}return F(e,t),C(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"replace",value:function(t){return this.update(t,!0)}}])}(R);function G(t){return G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},G(t)}function q(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function V(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,X(n.key),n)}}function z(t,e,r){return e&&V(t.prototype,e),r&&V(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function U(t,e,r){return e=J(e),function(t,e){if(e&&("object"==G(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,$()?Reflect.construct(e,r||[],J(t).constructor):e.apply(t,r))}function $(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return($=function(){return!!t})()}function J(t){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},J(t)}function K(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Q(t,e)}function Q(t,e){return Q=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Q(t,e)}function W(t,e,r){return(e=X(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function X(t){var e=function(t,e){if("object"!=G(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=G(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==G(e)?e:e+""}var Y=function(t){function e(){var t;q(this,e);for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];return W(t=U(this,e,[].concat(n)),"prices",[]),t}return K(e,t),z(e,[{key:"update",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.prices.length&&r?this.prices[this.prices.length-1]=t:this.prices.push(t),this.prices.length>this.interval&&this.prices.shift(),this.prices.length===this.interval)return this.setResult(e.getResultFromBatch(this.prices),r)}}],[{key:"getResultFromBatch",value:function(t){return t.reduce((function(t,e){return t.plus(e)}),new v("0")).div(t.length||1)}}])}(N),Z=function(t){function e(){var t;q(this,e);for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];return W(t=U(this,e,[].concat(n)),"prices",[]),t}return K(e,t),z(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.prices.length&&e?this.prices[this.prices.length-1]=t:this.prices.push(t),this.prices.length>this.interval&&this.prices.shift(),this.prices.length===this.interval){var r=this.prices.reduce((function(t,e){return t+e}),0);return this.setResult(r/this.prices.length,e)}}}])}(H);function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function et(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function rt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,at(n.key),n)}}function nt(t,e,r){return e&&rt(t.prototype,e),r&&rt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function it(t,e,r){return e=ut(e),function(t,e){if(e&&("object"==tt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ot()?Reflect.construct(e,r||[],ut(t).constructor):e.apply(t,r))}function ot(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(ot=function(){return!!t})()}function ut(t){return ut=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ut(t)}function st(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&<(t,e)}function lt(t,e){return lt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},lt(t,e)}function ct(t,e,r){return(e=at(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function at(t){var e=function(t,e){if("object"!=tt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==tt(e)?e:e+""}var ft=function(t){function e(t){var r;return et(this,e),ct(r=it(this,e,[t]),"interval",void 0),ct(r,"indicator",void 0),ct(r,"smoothingFactor",void 0),r.interval=t,r.indicator=new Y(t),r.smoothingFactor=new v(1).div(r.interval),r}return st(e,t),nt(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=this.indicator.update(t,e);if(e&&this.previousResult){var n=new v(t).minus(this.previousResult).mul(this.smoothingFactor);return this.setResult(n.plus(this.previousResult),e)}if(!e&&this.result){var i=new v(t).minus(this.result).mul(this.smoothingFactor);return this.setResult(i.plus(this.result),e)}if(void 0===this.result&&r)return this.setResult(r,e)}}])}(N),ht=function(t){function e(t){var r;return et(this,e),ct(r=it(this,e),"interval",void 0),ct(r,"indicator",void 0),ct(r,"smoothingFactor",void 0),r.interval=t,r.indicator=new Z(t),r.smoothingFactor=1/r.interval,r}return st(e,t),nt(e,[{key:"updates",value:function(t){var e=this;return t.forEach((function(t){return e.update(t)})),this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=this.indicator.update(t);if(e&&void 0!==this.previousResult){var n=(t-this.previousResult)*this.smoothingFactor;return this.setResult(n+this.previousResult,e)}if(!e&&void 0!==this.result){var i=(t-this.result)*this.smoothingFactor;return this.setResult(i+this.result,e)}if(void 0===this.result&&void 0!==r)return this.setResult(r,e)}}])}(R);function vt(t){return t.reduce((function(t,e){return t.add(e)}),new v(0)).div(t.length||1)}function pt(t){return t.length?t.reduce((function(t,e){return t+e}),0)/t.length:0}function yt(t){return yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},yt(t)}function dt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function bt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,wt(n.key),n)}}function gt(t,e,r){return e&&bt(t.prototype,e),r&&bt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function mt(t,e,r){return(e=wt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function wt(t){var e=function(t,e){if("object"!=yt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=yt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==yt(e)?e:e+""}var Ot=function(){return gt((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;dt(this,t),mt(this,"interval",void 0),mt(this,"deviationMultiplier",void 0),mt(this,"prices",[]),mt(this,"result",void 0),this.interval=e,this.deviationMultiplier=r}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"update",value:function(t){if(this.prices.push(new v(t)),this.prices.length>this.interval){this.prices.shift();var e=Y.getResultFromBatch(this.prices),r=function(t,e){var r=e||vt(t);return vt(t.map((function(t){return new v(t).sub(r).pow(2)}))).sqrt()}(this.prices,e);return this.result={lower:e.sub(r.times(this.deviationMultiplier)),middle:e,upper:e.add(r.times(this.deviationMultiplier))}}}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}}])}(),jt=function(){return gt((function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;dt(this,t),mt(this,"interval",void 0),mt(this,"deviationMultiplier",void 0),mt(this,"prices",[]),mt(this,"result",void 0),this.interval=e,this.deviationMultiplier=r}),[{key:"update",value:function(t){if(this.prices.push(t),this.prices.length>this.interval){this.prices.shift();var e=pt(this.prices),r=function(t,e){var r=e||pt(t),n=pt(t.map((function(t){return t-r})).map((function(t){return t*t})));return Math.sqrt(n)}(this.prices,e);return this.result={lower:e-r*this.deviationMultiplier,middle:e,upper:e+r*this.deviationMultiplier}}}},{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"isStable",get:function(){return void 0!==this.result}}])}();function St(t){return St="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},St(t)}function Pt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Mt(n.key),n)}}function Et(t,e,r){return e&&_t(t.prototype,e),r&&_t(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function Rt(t,e,r){return e=At(e),function(t,e){if(e&&("object"==St(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,kt()?Reflect.construct(e,r||[],At(t).constructor):e.apply(t,r))}function kt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(kt=function(){return!!t})()}function At(t){return At=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},At(t)}function Tt(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Ct(t,e)}function Ct(t,e){return Ct=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ct(t,e)}function xt(t,e,r){return(e=Mt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Mt(t){var e=function(t,e){if("object"!=St(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=St(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==St(e)?e:e+""}var It=function(t){function e(t){var r;return Pt(this,e),xt(r=Rt(this,e,[t]),"interval",void 0),xt(r,"pricesCounter",0),xt(r,"weightFactor",void 0),r.interval=t,r.weightFactor=2/(r.interval+1),r}return Tt(e,t),Et(e,[{key:"update",value:function(t){var e,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];r?r&&0===this.pricesCounter&&this.pricesCounter++:this.pricesCounter++;var n=new v(t);return r&&this.previousResult?this.setResult(n.times(this.weightFactor).add(this.previousResult.times(1-this.weightFactor)),r):this.setResult(n.times(this.weightFactor).add((null!==(e=this.result)&&void 0!==e?e:n).times(1-this.weightFactor)),r)}},{key:"getResult",value:function(){if(this.pricesCounter<this.interval)throw new m;return this.result}},{key:"isStable",get:function(){try{return this.getResult(),!0}catch(t){return!1}}}])}(N),Ft=function(t){function e(t){var r;return Pt(this,e),xt(r=Rt(this,e,[t]),"interval",void 0),xt(r,"pricesCounter",0),xt(r,"weightFactor",void 0),r.interval=t,r.weightFactor=2/(r.interval+1),r}return Tt(e,t),Et(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e?e&&0===this.pricesCounter&&this.pricesCounter++:this.pricesCounter++,e&&void 0!==this.previousResult?this.setResult(t*this.weightFactor+this.previousResult*(1-this.weightFactor),e):this.setResult(t*this.weightFactor+(void 0!==this.result?this.result:t)*(1-this.weightFactor),e)}},{key:"getResult",value:function(){if(this.pricesCounter<this.interval)throw new m;return this.result}},{key:"isStable",get:function(){try{return this.getResult(),!0}catch(t){return!1}}}])}(H);function Lt(t){return Lt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Lt(t)}function Dt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Bt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Gt(n.key),n)}}function Nt(t,e,r){return e&&Bt(t.prototype,e),r&&Bt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function Ht(t,e,r){return(e=Gt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Gt(t){var e=function(t,e){if("object"!=Lt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=Lt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Lt(e)?e:e+""}var qt=function(){return Nt((function t(e){Dt(this,t),Ht(this,"prices",[]),Ht(this,"long",void 0),Ht(this,"short",void 0),Ht(this,"signal",void 0),Ht(this,"result",void 0),this.long=new e.indicator(e.longInterval),this.short=new e.indicator(e.shortInterval),this.signal=new e.indicator(e.signalInterval)}),[{key:"isStable",get:function(){return void 0!==this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=new v(t);this.prices.length&&e?this.prices[this.prices.length-1]=r:this.prices.push(r);var n=this.short.update(r,e),i=this.long.update(r,e);if(this.prices.length>this.long.interval&&this.prices.shift(),this.prices.length===this.long.interval){var o=n.sub(i),u=this.signal.update(o);return this.result={histogram:o.sub(u),macd:o,signal:u}}}},{key:"getResult",value:function(){if(!this.isStable||void 0===this.result)throw new m;return this.result}}])}(),Vt=function(){return Nt((function t(e,r,n){Dt(this,t),Ht(this,"short",void 0),Ht(this,"long",void 0),Ht(this,"signal",void 0),Ht(this,"prices",[]),Ht(this,"result",void 0),this.short=e,this.long=r,this.signal=n}),[{key:"getResult",value:function(){if(void 0===this.result)throw new m;return this.result}},{key:"isStable",get:function(){return void 0!==this.result}},{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.prices.length&&e?this.prices[this.prices.length-1]=t:this.prices.push(t);var r=this.short.update(t,e),n=this.long.update(t,e);if(this.prices.length>this.long.interval&&this.prices.shift(),this.prices.length===this.long.interval){var i=r-n,o=this.signal.update(i,e);return this.result={histogram:i-o,macd:i,signal:o}}}}])}();function zt(t){return zt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},zt(t)}function Ut(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function $t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,te(n.key),n)}}function Jt(t,e,r){return e&&$t(t.prototype,e),r&&$t(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function Kt(t,e,r){return e=Wt(e),function(t,e){if(e&&("object"==zt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Qt()?Reflect.construct(e,r||[],Wt(t).constructor):e.apply(t,r))}function Qt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(Qt=function(){return!!t})()}function Wt(t){return Wt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Wt(t)}function Xt(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Yt(t,e)}function Yt(t,e){return Yt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Yt(t,e)}function Zt(t,e,r){return(e=te(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function te(t){var e=function(t,e){if("object"!=zt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=zt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==zt(e)?e:e+""}var ee=function(t){function e(t){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ft;return Ut(this,e),Zt(r=Kt(this,e),"interval",void 0),Zt(r,"previousPrices",[]),Zt(r,"avgGain",void 0),Zt(r,"avgLoss",void 0),Zt(r,"maxValue",new v(100)),r.interval=t,r.avgGain=new n(r.interval),r.avgLoss=new n(r.interval),r}return Xt(e,t),Jt(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.previousPrices.length&&e?this.previousPrices[this.previousPrices.length-1]=t:this.previousPrices.push(t),!(this.previousPrices.length<2)){var r=new v(t),n=new v(this.previousPrices[this.previousPrices.length-2]);if(r.gt(n)?(this.avgLoss.update(new v(0),e),this.avgGain.update(r.sub(n),e)):(this.avgLoss.update(n.sub(r),e),this.avgGain.update(new v(0),e)),this.avgGain.isStable){var i=this.avgLoss.getResult();if(i.eq(0))return this.setResult(new v(100),e);var o=this.avgGain.getResult().div(i);return this.setResult(this.maxValue.minus(this.maxValue.div(o.add(1))),e)}}}}])}(E),re=function(t){function e(t){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ht;return Ut(this,e),Zt(r=Kt(this,e),"interval",void 0),Zt(r,"previousPrices",[]),Zt(r,"avgGain",void 0),Zt(r,"avgLoss",void 0),Zt(r,"maxValue",100),r.interval=t,r.avgGain=new n(r.interval),r.avgLoss=new n(r.interval),r}return Xt(e,t),Jt(e,[{key:"update",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.previousPrices.length&&e?this.previousPrices[this.previousPrices.length-1]=t:this.previousPrices.push(t),!(this.previousPrices.length<2)){var r=t,n=this.previousPrices[this.previousPrices.length-2];if(r>n?(this.avgLoss.update(0,e),this.avgGain.update(t-n,e)):(this.avgLoss.update(n-r,e),this.avgGain.update(0,e)),this.avgGain.isStable){var i=this.avgLoss.getResult();if(0===i)return this.setResult(100,e);var o=this.avgGain.getResult()/i;return this.setResult(this.maxValue-this.maxValue/(o+1),e)}}}}])}(R);function ne(t){return ne="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ne(t)}var ie=function(t,e,r){if(void 0===r||void 0===t||void 0===e)throw Error("undefined param in getEMA");for(var n=t.length,i=new Array(n).fill(null),o=r?new It(e):new Ft(e),u=0;u<n;u++){var s=null;if(null!==t[u]){o.update(t[u]);try{s=o.getResult()}catch(t){s=null}}i[u]=s}return i};function oe(t){return oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},oe(t)}var ue=function(t,e,r){if(void 0===r||void 0===t||void 0===e)throw Error("undefined param in getSMA");for(var n=t.length,i=new Array(n).fill(null),o=r?new Y(e):new Z(e),u=0;u<n;u++){var s=null;if(null!==t[u]){o.update(t[u]);try{s=o.getResult()}catch(t){s=null}}i[u]=s}return i};function se(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var le=function(t){var e,r,n,i=t.fast,o=t.slow,u=t.precision,s=i.length;if(s==!o.length)throw Error("fast and slow do not have the same length");u?(e=function(t,e){return t.eq(e)},r=function(t,e){return t.gt(e)},n=function(t,e){return t.lt(e)}):(e=function(t,e){return t===e},r=function(t,e){return t>e},n=function(t,e){return t<e});for(var l=new Array(s).fill(null),c=0;c<s;c++){var a=i[c],f=o[c],h=void 0;null===a||null===f?h="neutral":e(a,f)?h=r(i[c-1],o[c-1])?"up":n(i[c-1],o[c-1])?"down":"neutral":r(a,f)?h="up":n(a,f)&&(h="down"),l[c]=h}var v=ce(l),p=v.map((function(t){return t.length}));return v.map((function(t,e){var r=p[e];return t.map((function(t,e){var n=r-e;return"neutral"===t&&(n=0),"up"===t&&(n*=1),"down"===t&&(n*=-1),n})).reverse()})).flat()},ce=function(t){return 0===t.length?[]:t.reduce((function(t,e,r,n){if(0===r)t.push([e]);else{var i=n[r-1],o=t[t.length-1];e!==i?t.push([e]):o.push(e)}return t}),[])};function ae(t){return ae="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ae(t)}var fe={getSMA:ue,getEMA:ie},he=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:14,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"SMA",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:14,i=arguments.length>4?arguments[4]:void 0,o=t.length;if(o<e)return[];for(var u=new Array(o).fill(null),s=i?new ee(e):new re(e),l=0;l<o;l++){var c=null;if(null!==t[l]){s.update(t[l]);try{c=s.getResult()}catch(t){c=null}}u[l]=c}var a,f,h,v=(a={},f="rsi_".concat(e),h=u,(f=function(t){var e=function(t,e){if("object"!=ae(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=ae(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ae(e)?e:e+""}(f))in a?Object.defineProperty(a,f,{value:h,enumerable:!0,configurable:!0,writable:!0}):a[f]=h,a);if("string"==typeof r&&"number"==typeof n&&fe.hasOwnProperty("get".concat(r))){var p=fe["get".concat(r)](u,n,i);v["rsi_".concat(r,"_").concat(n)]=p,v["rsi_".concat(e,"_x_rsi_").concat(r,"_").concat(n)]=le({fast:u,slow:p,precision:i})}return v};function ve(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return pe(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?pe(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){s=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(s)throw o}}}}function pe(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var ye=function(t,e){return null===t||null===e?null:t>1.25*e?1:t<.75*e?0:.5};function de(t){return de="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},de(t)}function be(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,u,s=[],l=!0,c=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=o.call(r)).done)&&(s.push(n.value),s.length!==e);l=!0);}catch(t){c=!0,i=t}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw i}}return s}}(t,e)||function(t,e){if(t){if("string"==typeof t)return ge(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ge(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ge(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function me(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,we(n.key),n)}}function we(t){var e=function(t,e){if("object"!=de(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=de(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==de(e)?e:e+""}var Oe=function(){return t=function t(e){var r=this,n=e.input,i=e.precision,o=void 0!==i&&i,u=e.ticker,s=void 0===u?"undefined":u;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),!Array.isArray(n))throw Error("input ohlcv must be an array: "+s);if(0===n.length)throw Error("input ohlcv must not be empty: "+s);if(!n[0].hasOwnProperty("close"))throw Error("input ohlcv array objects require at least close property: "+s);var l=function(t){return r.precision?new v(t):t};return this.len=n.length,this.precision=o,this.big=l,this.crossPairsArr=[],this.inputOhlcv=n,this.verticalOhlcv=function(t,e,r){for(var n=["open","high","low","close","volume"],i=new Set(n),o={},u=0,s=n;u<s.length;u++)o[s[u]]=new Array(e);for(var l,c=[],a=0,f=Object.keys(t[0]);a<f.length;a++){var h=f[a];i.has(h)||(o[h]=new Array(e),c.push(h))}var v,p=0,y=0,d=(v=t)[0].hasOwnProperty("date")&&"string"==typeof v[0].date&&/^\d{4}-\d{2}-\d{2}/.test(v[0].date);d&&(o.session_index=new Array(e),o.session_intraday_index=new Array(e),l=t[0].date.slice(0,10));for(var b=0;b<e;b++){var g=t[b];o.open[b]=r(g.open),o.high[b]=r(g.high),o.low[b]=r(g.low),o.close[b]=r(g.close),o.volume[b]=r(g.volume);var m,w=ve(c);try{for(w.s();!(m=w.n()).done;){var O=m.value;o[O][b]=g[O]}}catch(t){w.e(t)}finally{w.f()}if(d){var j=g.date.slice(0,10);j!==l&&(l=j,p++,y=0),o.session_index[b]=p,o.session_intraday_index[b]=y,y++}}return o}(n,this.len,l),this.indicators={},this.studies={},this.isComputed=!1,this},(e=[{key:"getData",value:function(){this.computeIndicators();var t=this.verticalOhlcv,e=this.precision,r=Object.keys(t),n=r.length;return t.open.map((function(i,o){for(var u={},s=0;s<n;s++){var l=r[s],c=t[l][o];u[l]=e&&c instanceof v?c.toNumber():c}return u}))}},{key:"getLastValues",value:function(){this.computeIndicators();for(var t=this.verticalOhlcv,e=this.precision,r=this.len,n={},i=0,o=Object.entries(t);i<o.length;i++){var u=be(o[i],2),s=u[0],l=u[1][r-1];n[s]=e&&l instanceof v?l.toNumber():l}return Object.assign(n,this.studies),n}},{key:"computeIndicators",value:function(){if(!0===this.isComputed)return!1;this.isComputed;for(var t=this.indicators,e=this.addColumn.bind(this),r=0,n=Object.entries(t);r<n.length;r++){var i=be(n[r],2),o=i[0],u=i[1];this.verticalOhlcv.hasOwnProperty(o)?delete this.indicators[o]:e(o,u)}return!0}},{key:"addColumn",value:function(t,e){var r=this.len;if(t=t.toLowerCase(),e.length>r)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");if(e.length<r){var n=r-e.length;e=new Array(n).fill(null).concat(e)}this.verticalOhlcv[t]=e}},{key:"crossPairs",value:function(t){this.computeIndicators();var e=function(t,e){var r,n=t.verticalOhlcv,i=t.precision,o=t.big,u=t.len,s={},l={},c={},a=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return se(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?se(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){s=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(s)throw o}}}}(e);try{var f=function(){var t=r.value,e=t.fast,a=t.slow,f=t.count;if(!e||!a)return 1;"number"!=typeof a||s[a]||(s[a]=Array(u).fill(o(a)));var h="".concat(e,"_x_").concat(a),v="".concat(e,"_c_").concat(a),p=function(t){return void 0!==f?t.slice(-f).filter((function(t){return 1===t||-1===t})).length:0};if(n[h]){var y=n[h];l[h]=y,void 0!==f&&(c[v]=p(y))}else if(n[e]&&n[a]){var d=le({fast:n[e],slow:n[a],precision:i});l[h]=d,void 0!==f&&(c[v]=p(d))}else if(n[e]&&s[a]){var b=le({fast:n[e],slow:s[a],precision:i});l[h]=b,void 0!==f&&(c[v]=p(b))}else console.log("Missing ohlcv properties for ".concat(e," or ").concat(a))};for(a.s();!(r=a.n()).done;)f()}catch(t){a.e(t)}finally{a.f()}return{x:l,c}}(this,t),r=e.x,n=e.c;return Object.assign(this.indicators,r),Object.assign(this.studies,n),this.computeIndicators(),this}},{key:"ema",value:function(t){var e=function(t,e){var r=t.verticalOhlcv,n=t.precision,i=r.close,o=ie(i,e,n);return function(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=ne(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=ne(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ne(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}({},"ema_".concat(e),o)}(this,t);return Object.assign(this.indicators,e),this}},{key:"sma",value:function(t){var e=function(t,e){var r=t.verticalOhlcv,n=t.precision,i=r.close,o=ue(i,e,n);return function(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=oe(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==oe(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}({},"sma_".concat(e),o)}(this,t);return Object.assign(this.indicators,e),this}},{key:"macd",value:function(t,e,r){var n=function(t,e,r,n){var i=t.verticalOhlcv,o=t.precision;return function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:12,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:26,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:9,i=arguments.length>4?arguments[4]:void 0,o=t.length,u=new Array(o).fill(null),s=new Array(o).fill(null),l=new Array(o).fill(null),c=i?new qt({indicator:It,shortInterval:e,longInterval:r,signalInterval:n}):new Vt(new Ft(e),new Ft(r),new Ft(n)),a=0;a<o;a++){var f={};c.update(t[a]);try{f=c.getResult()}catch(t){f={macd:null,signal:null,histogram:null}}u[a]=f.macd,s[a]=f.signal,l[a]=f.histogram}return{macd_diff:u,macd_dea:s,macd_histogram:l,macd_diff_x_macd_dea:le({fast:u,slow:s,precision:i})}}(i.close,e,r,n,o)}(this,t,e,r);return Object.assign(this.indicators,n),this}},{key:"bollingerBands",value:function(t,e){var r=function(t,e,r){var n=t.verticalOhlcv,i=t.precision;return function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,o=arguments.length>3?arguments[3]:void 0,u=t.length,s=Array(u).fill(null),l=Array(u).fill(null),c=Array(u).fill(null),a=Array(u).fill(null),f=Array(u).fill(null),h=null,v=null;o?(r=new Ot(n,i),e=function(t,e,r){return{range:t.minus(r).div(e.minus(r)).times(100),height:e.minus(r).div(r).times(100)}}):(r=new jt(n,i),e=function(t,e,r){return{range:(t-r)/(e-r)*100,height:(e-r)/r*100}});for(var p=0;p<u;p++){var y={};r.update(t[p]);var d=!1;try{y=r.getResult()}catch(t){d=!0,y={upper:null,middle:null,lower:null}}if(s[p]=y.upper,l[p]=y.middle,c[p]=y.lower,d)a[p]=null,f[p]=null;else{var b=e(t[p],y.upper,y.lower);h=b.range,v=b.height}a[p]=h,f[p]=v}return{bollinger_bands_upper:s,bollinger_bands_middle:l,bollinger_bands_lower:c,bollinger_bands_range:a,bollinger_bands_height:f}}(n.close,e,r,i)}(this,t,e);return Object.assign(this.indicators,r),this}},{key:"rsi",value:function(t,e,r){var n=function(t,e,r,n){var i=t.verticalOhlcv,o=t.precision,u=i.close;return"number"==typeof e&&void 0===n&&(n=e),he(u,e,r,n,o)}(this,t,e,r);return Object.assign(this.indicators,n),this}},{key:"orb",value:function(){var t,e,r,n=(e=(t=this).inputOhlcv,r=t.len,t.precision,t.verticalOhlcv.close,function(t,e,r,n){for(var i=new Array(r).fill(0),o=new Array(r).fill(0),u=0,s=null,l=0,c=0,a=0;a<r;a++){var f=t[a];if(0===a&&!f.hasOwnProperty("date"))throw Error("input ohlcv array must have a date property available in candle datapoint");var h=f.date.split(" ")[0];h!==s&&(s=h,l=f.high,c=f.low),i[u]=l,o[u]=c,u++}return{orb_high:i,orb_low:o}}(e,0,r));return Object.assign(this.indicators,n),this}},{key:"donchianChannels",value:function(t,e){var r=function(t,e,r){var n=t.verticalOhlcv,i=t.precision,o=t.len;return function(t,e,r,n,i,o){for(var u=new Array(o).fill(null),s=new Array(o).fill(null),l=new Array(o).fill(null),c=[],a=[],f=i?function(t,e){return t.plus(e).div(2)}:function(t,e){return(t+e)/2},h=0;h<o;h++){for(;c.length&&c[0]<=h-r;)c.shift();for(;c.length&&t[c[c.length-1]]<=t[h];)c.pop();for(c.push(h);a.length&&a[0]<=h-r;)a.shift();for(;a.length&&e[a[a.length-1]]>=e[h];)a.pop();if(a.push(h),h>=r-1){var v=t[c[0]],p=e[a[0]],y=f(v,p),d=h+n;d>=0&&d<o&&(u[d]=v,s[d]=p,l[d]=y)}}return{donchian_channel_upper:u,donchian_channel_lower:s,donchian_channel_basis:l}}(n.high,n.low,e,r,i,o)}(this,t,e);return Object.assign(this.indicators,r),this}},{key:"candlesStudies",value:function(t){var e=function(t,e){return function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,r=arguments.length>2?arguments[2]:void 0,n=function(t,e){return Math.abs(t-e)},i=new Array(r).fill(null),o=new Array(r).fill(null),u=new Array(r).fill(null),s=new Array(r).fill(null),l=new Array(r).fill(null),c=new Z(e),a=0;a<r;a++){var f=t[a-1],h=t[a],v=h.open,p=h.high,y=h.low,d=h.close,b=void 0!==f?Math.abs(f.close-v):null,g=null,m=n(v,d),w=void 0,O=void 0,j=d>v?1:0;1===j?(w=n(p,d),O=n(v,y)):(w=n(p,v),O=n(d,y)),c.update(m);try{g=c.getResult()}catch(t){g=null}i[a]=j,o[a]=ye(m,g),u[a]=ye(w,g),s[a]=ye(O,g),l[a]=ye(b,g)}return{candle_direction:i,candle_gap_size:l,candle_body_size:o,candle_top_size:u,candle_bottom_size:s}}(t.inputOhlcv,e,t.len)}(this,t);return Object.assign(this.indicators,e),this}}])&&me(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}()})(),OHLCV_INDICATORS=e})();
|
package/index.js
CHANGED
|
@@ -4,12 +4,12 @@ import {macd} from './src/moving-averages/macd.js'
|
|
|
4
4
|
import {bollingerBands} from './src/moving-averages/bollingerBands.js'
|
|
5
5
|
import { rsi } from './src/oscillators/rsi.js'
|
|
6
6
|
import {crossPairs} from './src/studies/findCrosses.js'
|
|
7
|
-
import { candles } from './src/studies/candles.js'
|
|
8
7
|
import { orb } from './src/studies/orb.js'
|
|
9
8
|
import { donchianChannels } from './src/moving-averages/donchianChannel.js'
|
|
10
9
|
import {Big} from 'trading-signals';
|
|
11
10
|
import { parseOhlcvToVertical } from './src/utilities/parsing-utilities.js'
|
|
12
11
|
import { candlesStudies } from './src/studies/candleStudies.js'
|
|
12
|
+
import { correlation } from './src/studies/correlation.js'
|
|
13
13
|
|
|
14
14
|
export default class OHLCV_INDICATORS {
|
|
15
15
|
constructor({input, precision = false, ticker = 'undefined'}) {
|
|
@@ -18,6 +18,7 @@ export default class OHLCV_INDICATORS {
|
|
|
18
18
|
if(input.length === 0) throw Error('input ohlcv must not be empty: ' + ticker)
|
|
19
19
|
if(!input[0].hasOwnProperty('close')) throw Error('input ohlcv array objects require at least close property: ' + ticker)
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
const big = num => (this.precision) ? new Big(num) : num
|
|
22
23
|
|
|
23
24
|
this.len = input.length
|
|
@@ -28,7 +29,10 @@ export default class OHLCV_INDICATORS {
|
|
|
28
29
|
this.verticalOhlcv = parseOhlcvToVertical(input, this.len, big)
|
|
29
30
|
this.indicators = {}
|
|
30
31
|
this.studies = {}
|
|
31
|
-
this.isComputed = false
|
|
32
|
+
this.isComputed = false
|
|
33
|
+
this.studies = {
|
|
34
|
+
correlation
|
|
35
|
+
}
|
|
32
36
|
return this
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -182,13 +186,6 @@ export default class OHLCV_INDICATORS {
|
|
|
182
186
|
|
|
183
187
|
return this
|
|
184
188
|
}
|
|
185
|
-
candles()
|
|
186
|
-
{
|
|
187
|
-
const result = candles(this)
|
|
188
|
-
Object.assign(this.indicators, result)
|
|
189
|
-
|
|
190
|
-
return this
|
|
191
|
-
}
|
|
192
189
|
orb()
|
|
193
190
|
{
|
|
194
191
|
const result = orb(this)
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}]. This library is optimized for backtesting and trading bot development.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "node test/test.js",
|
|
9
|
+
"study": "node test/study.js",
|
|
9
10
|
"build": "npx webpack"
|
|
10
11
|
},
|
|
11
12
|
"author": "https://jaimelias.com/",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {FasterSMA} from 'trading-signals';
|
|
2
2
|
|
|
3
3
|
export const candlesStudies = (main, period) => {
|
|
4
4
|
|
|
@@ -16,38 +16,31 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
16
16
|
|
|
17
17
|
//body
|
|
18
18
|
let candle_body_size = new Array(len).fill(null)
|
|
19
|
-
let candle_body_size_mean = new Array(len).fill(null)
|
|
20
|
-
let candle_body_size_label = new Array(len).fill(null)
|
|
21
19
|
|
|
22
20
|
//top
|
|
23
|
-
let candle_top_size_mean = new Array(len).fill(null)
|
|
24
21
|
let candle_top_size = new Array(len).fill(null)
|
|
25
|
-
let candle_top_size_label = new Array(len).fill(null)
|
|
26
22
|
|
|
27
23
|
//bottom
|
|
28
|
-
let candle_bottom_size_mean = new Array(len).fill(null)
|
|
29
24
|
let candle_bottom_size = new Array(len).fill(null)
|
|
30
|
-
let candle_bottom_size_label = new Array(len).fill(null)
|
|
31
25
|
|
|
26
|
+
//gap between the current open and previous close
|
|
27
|
+
let candle_gap_size = new Array(len).fill(null)
|
|
32
28
|
|
|
33
29
|
//instances
|
|
34
30
|
let bodyInstance = new FasterSMA(period)
|
|
35
|
-
let topInstance = new FasterSMA(period)
|
|
36
|
-
let bottomInstance = new FasterSMA(period)
|
|
37
|
-
|
|
38
31
|
|
|
39
32
|
for(let x = 0; x < len; x++)
|
|
40
33
|
{
|
|
34
|
+
const prev = inputOhlcv[x-1]
|
|
41
35
|
const {open, high, low, close} = inputOhlcv[x]
|
|
36
|
+
const gapSize = (typeof prev !== 'undefined') ? Math.abs(prev.close - open) : null
|
|
42
37
|
let bodySizeMean = null
|
|
43
|
-
let topSizeMean = null
|
|
44
|
-
let bottomSizeMean = null
|
|
45
38
|
const bodySize = getSize(open, close)
|
|
46
39
|
let topSize
|
|
47
40
|
let bottomSize
|
|
48
|
-
let candleDirection = (close > open) ?
|
|
41
|
+
let candleDirection = (close > open) ? 1 : 0 // 1 for bullish and 0 for bearish
|
|
49
42
|
|
|
50
|
-
if(candleDirection ===
|
|
43
|
+
if(candleDirection === 1)
|
|
51
44
|
{
|
|
52
45
|
topSize = getSize(high, close)
|
|
53
46
|
bottomSize = getSize(open, low)
|
|
@@ -59,14 +52,10 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
59
52
|
}
|
|
60
53
|
|
|
61
54
|
bodyInstance.update(bodySize)
|
|
62
|
-
topInstance.update(topSize)
|
|
63
|
-
bottomInstance.update(bottomSize)
|
|
64
55
|
|
|
65
56
|
try
|
|
66
57
|
{
|
|
67
58
|
bodySizeMean = bodyInstance.getResult()
|
|
68
|
-
topSizeMean = topInstance.getResult()
|
|
69
|
-
bottomSizeMean = bottomInstance.getResult()
|
|
70
59
|
}
|
|
71
60
|
catch(err)
|
|
72
61
|
{
|
|
@@ -76,41 +65,33 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
|
|
|
76
65
|
candle_direction[x] = candleDirection
|
|
77
66
|
|
|
78
67
|
//body
|
|
79
|
-
candle_body_size[x] = bodySize
|
|
80
|
-
candle_body_size_mean[x] = bodySizeMean
|
|
81
|
-
candle_body_size_label[x] = labelSize(bodySize, bodySizeMean)
|
|
68
|
+
candle_body_size[x] = classifySize(bodySize, bodySizeMean)
|
|
82
69
|
|
|
83
70
|
//top
|
|
84
|
-
candle_top_size[x] = topSize
|
|
85
|
-
candle_top_size_mean[x] = topSizeMean
|
|
86
|
-
candle_top_size_label[x] = labelSize(topSize, topSizeMean)
|
|
71
|
+
candle_top_size[x] = classifySize(topSize, bodySizeMean)
|
|
87
72
|
|
|
88
|
-
|
|
89
73
|
//bottom
|
|
90
|
-
candle_bottom_size[x] = bottomSize
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
74
|
+
candle_bottom_size[x] = classifySize(bottomSize, bodySizeMean)
|
|
75
|
+
|
|
76
|
+
//gap
|
|
77
|
+
candle_gap_size[x] = classifySize(gapSize, bodySizeMean)
|
|
94
78
|
}
|
|
95
79
|
|
|
96
80
|
return {
|
|
97
81
|
candle_direction,
|
|
98
|
-
|
|
82
|
+
candle_gap_size,
|
|
99
83
|
candle_body_size,
|
|
100
|
-
candle_body_size_label,
|
|
101
|
-
candle_top_size_mean,
|
|
102
84
|
candle_top_size,
|
|
103
|
-
|
|
104
|
-
candle_bottom_size_mean,
|
|
105
|
-
candle_bottom_size,
|
|
106
|
-
candle_bottom_size_label
|
|
85
|
+
candle_bottom_size
|
|
107
86
|
}
|
|
108
87
|
}
|
|
109
88
|
|
|
110
|
-
|
|
89
|
+
|
|
90
|
+
// 1 for large, 0.5 for medium and 0 for small
|
|
91
|
+
const classifySize = (value, mean) => {
|
|
111
92
|
|
|
112
93
|
if(value === null || mean === null) return null
|
|
113
|
-
if(value > mean * 1.25) return
|
|
114
|
-
else if(value < mean * 0.75) return
|
|
115
|
-
else return
|
|
94
|
+
if(value > mean * 1.25) return 1
|
|
95
|
+
else if(value < mean * 0.75) return 0
|
|
96
|
+
else return 0.5
|
|
116
97
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { FasterSMA } from "trading-signals";
|
|
2
|
+
|
|
3
|
+
// Normalize the array (z-score normalization)
|
|
4
|
+
const smoothNormalize = (arr, smoothing) => {
|
|
5
|
+
const len = arr.length;
|
|
6
|
+
const instance = new FasterSMA(smoothing);
|
|
7
|
+
const smoothedArr = new Array(len);
|
|
8
|
+
let sum = 0;
|
|
9
|
+
let sumSq = 0;
|
|
10
|
+
let count = 0;
|
|
11
|
+
|
|
12
|
+
for (let x = 0; x < len; x++) {
|
|
13
|
+
instance.update(arr[x]);
|
|
14
|
+
|
|
15
|
+
if (instance.isStable) {
|
|
16
|
+
const value = instance.getResult();
|
|
17
|
+
smoothedArr[x] = value;
|
|
18
|
+
sum += value;
|
|
19
|
+
sumSq += value * value;
|
|
20
|
+
count++;
|
|
21
|
+
} else {
|
|
22
|
+
smoothedArr[x] = null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const meanValue = sum / count;
|
|
27
|
+
const variance = (sumSq / count) - (meanValue * meanValue);
|
|
28
|
+
const stdDev = Math.sqrt(variance);
|
|
29
|
+
|
|
30
|
+
return smoothedArr.map(val => (val !== null ? (val - meanValue) / stdDev : null));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Calculate Pearson Correlation
|
|
34
|
+
export const correlation = (x, y, smoothing = 5) => {
|
|
35
|
+
if (x.length !== y.length) {
|
|
36
|
+
throw new Error('Both arrays must have the same length');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const normX = smoothNormalize(x, smoothing);
|
|
40
|
+
const normY = smoothNormalize(y, smoothing);
|
|
41
|
+
const n = x.length;
|
|
42
|
+
const result = [];
|
|
43
|
+
|
|
44
|
+
let sumX = 0, sumY = 0, sumXY = 0;
|
|
45
|
+
let sumXSquare = 0, sumYSquare = 0;
|
|
46
|
+
let count = 0;
|
|
47
|
+
|
|
48
|
+
// Find the first index where both normX and normY have valid values
|
|
49
|
+
let firstValidIndex = -1;
|
|
50
|
+
for (let i = 0; i < n; i++) {
|
|
51
|
+
if (normX[i] !== null && normY[i] !== null) {
|
|
52
|
+
firstValidIndex = i;
|
|
53
|
+
break;
|
|
54
|
+
} else {
|
|
55
|
+
result.push(0); // Fill initial invalid indices with 0
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (firstValidIndex === -1) {
|
|
60
|
+
// No valid data points
|
|
61
|
+
return new Array(n).fill(0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (let i = firstValidIndex; i < n; i++) {
|
|
65
|
+
const xVal = normX[i];
|
|
66
|
+
const yVal = normY[i];
|
|
67
|
+
|
|
68
|
+
if (xVal === null || yVal === null) {
|
|
69
|
+
// Reset sums and counts when encountering null values
|
|
70
|
+
sumX = sumY = sumXY = sumXSquare = sumYSquare = count = 0;
|
|
71
|
+
result.push(0);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
sumX += xVal;
|
|
76
|
+
sumY += yVal;
|
|
77
|
+
sumXY += xVal * yVal;
|
|
78
|
+
sumXSquare += xVal * xVal;
|
|
79
|
+
sumYSquare += yVal * yVal;
|
|
80
|
+
count++;
|
|
81
|
+
|
|
82
|
+
if (count < 2) {
|
|
83
|
+
result.push(0); // Not enough data points to calculate correlation
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const numerator = (count * sumXY) - (sumX * sumY);
|
|
88
|
+
const denominator = Math.sqrt(
|
|
89
|
+
(count * sumXSquare - sumX * sumX) *
|
|
90
|
+
(count * sumYSquare - sumY * sumY)
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const correlation = denominator === 0 ? 0 : numerator / denominator;
|
|
94
|
+
result.push(correlation);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//true if first row date starts with yyyy-mm-dd date
|
|
2
|
-
const validateFirstDate = arr => arr[0].hasOwnProperty('date') && /^\d{4}-\d{2}-\d{2}/.test(arr[0].date)
|
|
2
|
+
const validateFirstDate = arr => arr[0].hasOwnProperty('date') && typeof arr[0].date === 'string' && /^\d{4}-\d{2}-\d{2}/.test(arr[0].date)
|
|
3
3
|
|
|
4
4
|
export const parseOhlcvToVertical = (input, len, big) => {
|
|
5
5
|
const numberColsKeys = ['open', 'high', 'low', 'close', 'volume']
|
package/src/studies/candles.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
export const candles = main => {
|
|
2
|
-
|
|
3
|
-
const {inputOhlcv, len} = main
|
|
4
|
-
const cols = getCandlestickPattern(inputOhlcv, len);
|
|
5
|
-
return cols;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const getCandlestickPattern = (inputOhlcv, len) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const candle_pattern = [];
|
|
12
|
-
const candle_name = [];
|
|
13
|
-
const candle_score = [];
|
|
14
|
-
|
|
15
|
-
for (let x = 1; x < len; x++) {
|
|
16
|
-
const curr = inputOhlcv[x];
|
|
17
|
-
const prev = inputOhlcv[x - 1];
|
|
18
|
-
|
|
19
|
-
let pattern = 'Neutral';
|
|
20
|
-
let name = 'None';
|
|
21
|
-
let score = 0;
|
|
22
|
-
|
|
23
|
-
for (const patternObj of candlePatterns) {
|
|
24
|
-
const { isSingleCandle, candle_name: patternName, candle_score: patternScore } = patternObj;
|
|
25
|
-
const isMatch = isSingleCandle
|
|
26
|
-
? candleFunctions[patternName](curr)
|
|
27
|
-
: candleFunctions[patternName](prev, curr);
|
|
28
|
-
|
|
29
|
-
if (isMatch) {
|
|
30
|
-
if (score === 0) {
|
|
31
|
-
pattern = patternScore === 1 ? 'Bullish' : 'Bearish';
|
|
32
|
-
name = patternName;
|
|
33
|
-
score = patternScore;
|
|
34
|
-
} else if (score !== patternScore) {
|
|
35
|
-
pattern = 'Neutral';
|
|
36
|
-
name = 'None';
|
|
37
|
-
score = 0;
|
|
38
|
-
break;
|
|
39
|
-
} else {
|
|
40
|
-
name += `,${patternName}`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
candle_pattern.push(pattern);
|
|
46
|
-
candle_name.push(name);
|
|
47
|
-
candle_score.push(score);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
candle_pattern,
|
|
52
|
-
candle_name,
|
|
53
|
-
candle_score
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const candlePatterns = [
|
|
61
|
-
{
|
|
62
|
-
candle_name: "isHammer",
|
|
63
|
-
candle_score: 1,
|
|
64
|
-
isSingleCandle: true
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
candle_name: "isInvertedHammer",
|
|
68
|
-
candle_score: 1,
|
|
69
|
-
isSingleCandle: true
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
candle_name: "isBullishHammer",
|
|
73
|
-
candle_score: 1,
|
|
74
|
-
isSingleCandle: true
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
candle_name: "isBearishHammer",
|
|
78
|
-
candle_score: -1,
|
|
79
|
-
isSingleCandle: true
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
candle_name: "isBullishInvertedHammer",
|
|
83
|
-
candle_score: 1,
|
|
84
|
-
isSingleCandle: true
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
candle_name: "isBearishInvertedHammer",
|
|
88
|
-
candle_score: -1,
|
|
89
|
-
isSingleCandle: true
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
candle_name: "isHangingMan",
|
|
93
|
-
candle_score: -1,
|
|
94
|
-
isSingleCandle: false
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
candle_name: "isShootingStar",
|
|
98
|
-
candle_score: -1,
|
|
99
|
-
isSingleCandle: false
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
candle_name: "isBullishEngulfing",
|
|
103
|
-
candle_score: 1,
|
|
104
|
-
isSingleCandle: false
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
candle_name: "isBearishEngulfing",
|
|
108
|
-
candle_score: -1,
|
|
109
|
-
isSingleCandle: false
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
candle_name: "isBullishHarami",
|
|
113
|
-
candle_score: 1,
|
|
114
|
-
isSingleCandle: false
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
candle_name: "isBearishHarami",
|
|
118
|
-
candle_score: -1
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
candle_name: "isBullishKicker",
|
|
122
|
-
candle_score: 1,
|
|
123
|
-
isSingleCandle: false
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
candle_name: "isBearishKicker",
|
|
127
|
-
candle_score: -1,
|
|
128
|
-
isSingleCandle: false
|
|
129
|
-
}
|
|
130
|
-
]
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const bodyLen = candlestick => Math.abs(candlestick.open - candlestick.close);
|
|
134
|
-
|
|
135
|
-
const wickLen = candlestick => candlestick.high - Math.max(candlestick.open, candlestick.close);
|
|
136
|
-
|
|
137
|
-
const tailLen = candlestick => Math.min(candlestick.open, candlestick.close) - candlestick.low;
|
|
138
|
-
|
|
139
|
-
const bodyEnds = candlestick => candlestick.open <= candlestick.close ?
|
|
140
|
-
{ bottom: candlestick.open, top: candlestick.close } :
|
|
141
|
-
{ bottom: candlestick.close, top: candlestick.open };
|
|
142
|
-
|
|
143
|
-
const isBullish = candlestick => candlestick.open < candlestick.close;
|
|
144
|
-
|
|
145
|
-
const isBearish = candlestick => candlestick.open > candlestick.close;
|
|
146
|
-
|
|
147
|
-
const isEngulfed = (previous, current) =>
|
|
148
|
-
bodyEnds(previous).top <= bodyEnds(current).top &&
|
|
149
|
-
bodyEnds(previous).bottom >= bodyEnds(current).bottom;
|
|
150
|
-
|
|
151
|
-
const hasGapUp = (previous, current) =>
|
|
152
|
-
bodyEnds(previous).top < bodyEnds(current).bottom;
|
|
153
|
-
|
|
154
|
-
const hasGapDown = (previous, current) =>
|
|
155
|
-
bodyEnds(previous).bottom > bodyEnds(current).top;
|
|
156
|
-
|
|
157
|
-
const isHammer = candlestick =>
|
|
158
|
-
tailLen(candlestick) > (bodyLen(candlestick) * 2) &&
|
|
159
|
-
wickLen(candlestick) < bodyLen(candlestick);
|
|
160
|
-
|
|
161
|
-
const isInvertedHammer = candlestick =>
|
|
162
|
-
wickLen(candlestick) > (bodyLen(candlestick) * 2) &&
|
|
163
|
-
tailLen(candlestick) < bodyLen(candlestick);
|
|
164
|
-
|
|
165
|
-
const isBullishHammer = candlestick =>
|
|
166
|
-
isBullish(candlestick) && isHammer(candlestick);
|
|
167
|
-
|
|
168
|
-
const isBearishHammer = candlestick =>
|
|
169
|
-
isBearish(candlestick) && isHammer(candlestick);
|
|
170
|
-
|
|
171
|
-
const isBullishInvertedHammer = candlestick =>
|
|
172
|
-
isBullish(candlestick) && isInvertedHammer(candlestick);
|
|
173
|
-
|
|
174
|
-
const isBearishInvertedHammer = candlestick =>
|
|
175
|
-
isBearish(candlestick) && isInvertedHammer(candlestick);
|
|
176
|
-
|
|
177
|
-
const isHangingMan = (previous, current) =>
|
|
178
|
-
isBullish(previous) && isBearishHammer(current) && hasGapUp(previous, current);
|
|
179
|
-
|
|
180
|
-
const isShootingStar = (previous, current) =>
|
|
181
|
-
isBullish(previous) && isBearishInvertedHammer(current) && hasGapUp(previous, current);
|
|
182
|
-
|
|
183
|
-
const isBullishEngulfing = (previous, current) =>
|
|
184
|
-
isBearish(previous) && isBullish(current) && isEngulfed(previous, current);
|
|
185
|
-
|
|
186
|
-
const isBearishEngulfing = (previous, current) =>
|
|
187
|
-
isBullish(previous) && isBearish(current) && isEngulfed(previous, current);
|
|
188
|
-
|
|
189
|
-
const isBullishHarami = (previous, current) =>
|
|
190
|
-
isBearish(previous) && isBullish(current) && isEngulfed(current, previous);
|
|
191
|
-
|
|
192
|
-
const isBearishHarami = (previous, current) =>
|
|
193
|
-
isBullish(previous) && isBearish(current) && isEngulfed(current, previous);
|
|
194
|
-
|
|
195
|
-
const isBullishKicker = (previous, current) =>
|
|
196
|
-
isBearish(previous) && isBullish(current) && hasGapUp(previous, current) &&
|
|
197
|
-
!(isHammer(current) || isInvertedHammer(current));
|
|
198
|
-
|
|
199
|
-
const isBearishKicker = (previous, current) =>
|
|
200
|
-
isBullish(previous) && isBearish(current) && hasGapDown(previous, current) &&
|
|
201
|
-
!(isHammer(current) || isInvertedHammer(current));
|
|
202
|
-
|
|
203
|
-
const findPattern = (dataArray, callback) => {
|
|
204
|
-
const paramCount = callback.length;
|
|
205
|
-
const upperBound = dataArray.length - paramCount;
|
|
206
|
-
const results = [];
|
|
207
|
-
|
|
208
|
-
for (let i = 0; i <= upperBound; i++) {
|
|
209
|
-
const values = [];
|
|
210
|
-
|
|
211
|
-
for (let j = 0; j < paramCount; j++) {
|
|
212
|
-
values.push(dataArray[i + j]);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (callback(...values)) {
|
|
216
|
-
results.push(i);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return results;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const hammer = dataArray => findPattern(dataArray, isHammer);
|
|
224
|
-
|
|
225
|
-
const invertedHammer = dataArray => findPattern(dataArray, isInvertedHammer);
|
|
226
|
-
|
|
227
|
-
const bullishHammer = dataArray => findPattern(dataArray, isBullishHammer);
|
|
228
|
-
|
|
229
|
-
const bearishHammer = dataArray => findPattern(dataArray, isBearishHammer);
|
|
230
|
-
|
|
231
|
-
const bullishInvertedHammer = dataArray => findPattern(dataArray, isBullishInvertedHammer);
|
|
232
|
-
|
|
233
|
-
const bearishInvertedHammer = dataArray => findPattern(dataArray, isBearishInvertedHammer);
|
|
234
|
-
|
|
235
|
-
const hangingMan = dataArray => findPattern(dataArray, isHangingMan);
|
|
236
|
-
|
|
237
|
-
const shootingStar = dataArray => findPattern(dataArray, isShootingStar);
|
|
238
|
-
|
|
239
|
-
const bullishEngulfing = dataArray => findPattern(dataArray, isBullishEngulfing);
|
|
240
|
-
|
|
241
|
-
const bearishEngulfing = dataArray => findPattern(dataArray, isBearishEngulfing);
|
|
242
|
-
|
|
243
|
-
const bullishHarami = dataArray => findPattern(dataArray, isBullishHarami);
|
|
244
|
-
|
|
245
|
-
const bearishHarami = dataArray => findPattern(dataArray, isBearishHarami);
|
|
246
|
-
|
|
247
|
-
const bullishKicker = dataArray => findPattern(dataArray, isBullishKicker);
|
|
248
|
-
|
|
249
|
-
const bearishKicker = dataArray => findPattern(dataArray, isBearishKicker)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const candleFunctions = {
|
|
253
|
-
isHammer,
|
|
254
|
-
isInvertedHammer,
|
|
255
|
-
isBullishHammer,
|
|
256
|
-
isBearishHammer,
|
|
257
|
-
isBullishInvertedHammer,
|
|
258
|
-
isBearishInvertedHammer,
|
|
259
|
-
isHangingMan,
|
|
260
|
-
isShootingStar,
|
|
261
|
-
isBullishEngulfing,
|
|
262
|
-
isBearishEngulfing,
|
|
263
|
-
isBullishHarami,
|
|
264
|
-
isBearishHarami,
|
|
265
|
-
isBullishKicker,
|
|
266
|
-
isBearishKicker
|
|
267
|
-
}
|