ohlcv-indicators 1.5.7 → 1.5.9

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:()=>Se});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 M(t,e,r){return e=F(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,x()?Reflect.construct(e,r||[],F(t).constructor):e.apply(t,r))}function x(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(x=function(){return!!t})()}function F(t){return F=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},F(t)}function L(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&&I(t,e)}function I(t,e){return I=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},I(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=M(this,e),"interval",void 0),r.interval=t,r}return L(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),q=function(t){function e(t){var r;return A(this,e),D(r=M(this,e),"interval",void 0),r.interval=t,r}return L(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 H(t){return H="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},H(t)}function G(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"==H(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"!=H(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=H(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==H(e)?e:e+""}var Y=function(t){function e(){var t;G(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;G(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)}}}])}(q);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&&lt(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,xt(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 Mt(t,e,r){return(e=xt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function xt(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 Ft=function(t){function e(t){var r;return Pt(this,e),Mt(r=Rt(this,e,[t]),"interval",void 0),Mt(r,"pricesCounter",0),Mt(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),Lt=function(t){function e(t){var r;return Pt(this,e),Mt(r=Rt(this,e,[t]),"interval",void 0),Mt(r,"pricesCounter",0),Mt(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}}}])}(q);function It(t){return It="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},It(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,Ht(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 qt(t,e,r){return(e=Ht(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Ht(t){var e=function(t,e){if("object"!=It(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=It(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==It(e)?e:e+""}var Gt=function(){return Nt((function t(e){Dt(this,t),qt(this,"prices",[]),qt(this,"long",void 0),qt(this,"short",void 0),qt(this,"signal",void 0),qt(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),qt(this,"short",void 0),qt(this,"long",void 0),qt(this,"signal",void 0),qt(this,"prices",[]),qt(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 Ft(e):new Lt(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},de=function(t,e){for(var r=t.length,n=new Z(e),i=new Array(r),o=0,u=0,s=0,l=0;l<r;l++)if(n.update(t[l]),n.isStable){var c=n.getResult();i[l]=c,o+=c,u+=c*c,s++}else i[l]=null;var a=o/s,f=u/s-a*a,h=Math.sqrt(f);return i.map((function(t){return null!==t?(t-a)/h:null}))},be=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5;if(t.length!==e.length)throw new Error("Both arrays must have the same length");for(var n=de(t,r),i=de(e,r),o=t.length,u=[],s=0,l=0,c=0,a=0,f=0,h=0,v=-1,p=0;p<o;p++){if(null!==n[p]&&null!==i[p]){v=p;break}u.push(0)}if(-1===v)return new Array(o).fill(0);for(var y=v;y<o;y++){var d=n[y],b=i[y];if(null!==d&&null!==b)if(s+=d,l+=b,c+=d*b,a+=d*d,f+=b*b,++h<2)u.push(0);else{var g=h*c-s*l,m=Math.sqrt((h*a-s*s)*(h*f-l*l)),w=0===m?0:g/m;u.push(w)}else s=l=c=a=f=h=0,u.push(0)}return u};function ge(t){return ge="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},ge(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,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 we(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)?we(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 we(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 Oe(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,je(n.key),n)}}function je(t){var e=function(t,e){if("object"!=ge(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=ge(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ge(e)?e:e+""}var Se=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.utilities={correlation:be},this},(e=[{key:"getData",value:function(){this.compute();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.compute();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:"compute",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 this}},{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.compute();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.compute(),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 Gt({indicator:Ft,shortInterval:e,longInterval:r,signalInterval:n}):new Vt(new Lt(e),new Lt(r),new Lt(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}}])&&Oe(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:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};(()=>{t.r(r),t.d(r,{default:()=>tr});var e=1e6,n="[big.js] ",o=n+"Invalid ",i=o+"decimal places",u=o+"rounding mode",l=n+"Division by zero",a={},c=void 0,s=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function f(t,r,e,n){var o=t.c;if(e===c&&(e=t.constructor.RM),0!==e&&1!==e&&2!==e&&3!==e)throw Error(u);if(r<1)n=3===e&&(n||!!o[0])||0===r&&(1===e&&o[0]>=5||2===e&&(o[0]>5||5===o[0]&&(n||o[1]!==c))),o.length=1,n?(t.e=t.e-r+1,o[0]=1):o[0]=t.e=0;else if(r<o.length){if(n=1===e&&o[r]>=5||2===e&&(o[r]>5||5===o[r]&&(n||o[r+1]!==c||1&o[r-1]))||3===e&&(n||!!o[0]),o.length=r,n)for(;++o[--r]>9;)if(o[r]=0,0===r){++t.e,o.unshift(1);break}for(r=o.length;!o[--r];)o.pop()}return t}function h(t,r,e){var n=t.e,o=t.c.join(""),i=o.length;if(r)o=o.charAt(0)+(i>1?"."+o.slice(1):"")+(n<0?"e":"e+")+n;else if(n<0){for(;++n;)o="0"+o;o="0."+o}else if(n>0)if(++n>i)for(n-=i;n--;)o+="0";else n<i&&(o=o.slice(0,n)+"."+o.slice(n));else i>1&&(o=o.charAt(0)+"."+o.slice(1));return t.s<0&&e?"-"+o:o}function v(t){return v="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},v(t)}function p(t){var r="function"==typeof Map?new Map:void 0;return p=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(r){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!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return function(t,r,e){if(y())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,r);var o=new(t.bind.apply(t,n));return e&&b(o,e.prototype),o}(t,arguments,d(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),b(e,t)},p(t)}function y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(y=function(){return!!t})()}function b(t,r){return b=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},b(t,r)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}a.abs=function(){var t=new this.constructor(this);return t.s=1,t},a.cmp=function(t){var r,e=this,n=e.c,o=(t=new e.constructor(t)).c,i=e.s,u=t.s,l=e.e,a=t.e;if(!n[0]||!o[0])return n[0]?i:o[0]?-u:0;if(i!=u)return i;if(r=i<0,l!=a)return l>a^r?1:-1;for(u=(l=n.length)<(a=o.length)?l:a,i=-1;++i<u;)if(n[i]!=o[i])return n[i]>o[i]^r?1:-1;return l==a?0:l>a^r?1:-1},a.div=function(t){var r=this,n=r.constructor,o=r.c,u=(t=new n(t)).c,a=r.s==t.s?1:-1,s=n.DP;if(s!==~~s||s<0||s>e)throw Error(i);if(!u[0])throw Error(l);if(!o[0])return t.s=a,t.c=[t.e=0],t;var h,v,p,y,b,d=u.slice(),m=h=u.length,g=o.length,w=o.slice(0,h),O=w.length,j=t,S=j.c=[],P=0,_=s+(j.e=r.e-t.e)+1;for(j.s=a,a=_<0?0:_,d.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(b=-1,y=0;++b<h;)if(u[b]!=w[b]){y=u[b]>w[b]?1:-1;break}if(!(y<0))break;for(v=O==h?u:d;O;){if(w[--O]<v[O]){for(b=O;b&&!w[--b];)w[b]=9;--w[b],w[O]+=10}w[O]-=v[O]}for(;!w[0];)w.shift()}S[P++]=y?p:++p,w[0]&&y?w[O]=o[m]||0:w=[o[m]]}while((m++<g||w[0]!==c)&&a--);return S[0]||1==P||(S.shift(),j.e--,_--),P>_&&f(j,_,n.RM,w[0]!==c),j},a.eq=function(t){return 0===this.cmp(t)},a.gt=function(t){return this.cmp(t)>0},a.gte=function(t){return this.cmp(t)>-1},a.lt=function(t){return this.cmp(t)<0},a.lte=function(t){return this.cmp(t)<1},a.minus=a.sub=function(t){var r,e,n,o,i=this,u=i.constructor,l=i.s,a=(t=new u(t)).s;if(l!=a)return t.s=-a,i.plus(t);var c=i.c.slice(),s=i.e,f=t.c,h=t.e;if(!c[0]||!f[0])return f[0]?t.s=-a:c[0]?t=new u(i):t.s=1,t;if(l=s-h){for((o=l<0)?(l=-l,n=c):(h=s,n=f),n.reverse(),a=l;a--;)n.push(0);n.reverse()}else for(e=((o=c.length<f.length)?c:f).length,l=a=0;a<e;a++)if(c[a]!=f[a]){o=c[a]<f[a];break}if(o&&(n=c,c=f,f=n,t.s=-t.s),(a=(e=f.length)-(r=c.length))>0)for(;a--;)c[r++]=0;for(a=r;e>l;){if(c[--e]<f[e]){for(r=e;r&&!c[--r];)c[r]=9;--c[r],c[e]+=10}c[e]-=f[e]}for(;0===c[--a];)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},a.mod=function(t){var r,e=this,n=e.constructor,o=e.s,i=(t=new n(t)).s;if(!t.c[0])throw Error(l);return e.s=t.s=1,r=1==t.cmp(e),e.s=o,t.s=i,r?new n(e):(o=n.DP,i=n.RM,n.DP=n.RM=0,e=e.div(t),n.DP=o,n.RM=i,this.minus(e.times(t)))},a.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t},a.plus=a.add=function(t){var r,e,n,o=this,i=o.constructor;if(t=new i(t),o.s!=t.s)return t.s=-t.s,o.minus(t);var u=o.e,l=o.c,a=t.e,c=t.c;if(!l[0]||!c[0])return c[0]||(l[0]?t=new i(o):t.s=o.s),t;if(l=l.slice(),r=u-a){for(r>0?(a=u,n=c):(r=-r,n=l),n.reverse();r--;)n.push(0);n.reverse()}for(l.length-c.length<0&&(n=c,c=l,l=n),r=c.length,e=0;r;l[r]%=10)e=(l[--r]=l[r]+c[r]+e)/10|0;for(e&&(l.unshift(e),++a),r=l.length;0===l[--r];)l.pop();return t.c=l,t.e=a,t},a.pow=function(t){var r=this,e=new r.constructor("1"),n=e,i=t<0;if(t!==~~t||t<-1e6||t>1e6)throw Error(o+"exponent");for(i&&(t=-t);1&t&&(n=n.times(r)),t>>=1;)r=r.times(r);return i?e.div(n):n},a.prec=function(t,r){if(t!==~~t||t<1||t>e)throw Error(o+"precision");return f(new this.constructor(this),t,r)},a.round=function(t,r){if(t===c)t=0;else if(t!==~~t||t<-e||t>e)throw Error(i);return f(new this.constructor(this),t+this.e+1,r)},a.sqrt=function(){var t,r,e,o=this,i=o.constructor,u=o.s,l=o.e,a=new i("0.5");if(!o.c[0])return new i(o);if(u<0)throw Error(n+"No square root");0===(u=Math.sqrt(o+""))||u===1/0?((r=o.c.join("")).length+l&1||(r+="0"),l=((l+1)/2|0)-(l<0||1&l),t=new i(((u=Math.sqrt(r))==1/0?"5e":(u=u.toExponential()).slice(0,u.indexOf("e")+1))+l)):t=new i(u+""),l=t.e+(i.DP+=4);do{e=t,t=a.times(e.plus(o.div(e)))}while(e.c.slice(0,l).join("")!==t.c.slice(0,l).join(""));return f(t,(i.DP-=4)+t.e+1,i.RM)},a.times=a.mul=function(t){var r,e=this,n=e.constructor,o=e.c,i=(t=new n(t)).c,u=o.length,l=i.length,a=e.e,c=t.e;if(t.s=e.s==t.s?1:-1,!o[0]||!i[0])return t.c=[t.e=0],t;for(t.e=a+c,u<l&&(r=o,o=i,i=r,c=u,u=l,l=c),r=new Array(c=u+l);c--;)r[c]=0;for(a=l;a--;){for(l=0,c=u+a;c>a;)l=r[c]+i[a]*o[c-a-1]+l,r[c--]=l%10,l=l/10|0;r[c]=l}for(l?++t.e:r.shift(),a=r.length;!r[--a];)r.pop();return t.c=r,t},a.toExponential=function(t,r){var n=this,o=n.c[0];if(t!==c){if(t!==~~t||t<0||t>e)throw Error(i);for(n=f(new n.constructor(n),++t,r);n.c.length<t;)n.c.push(0)}return h(n,!0,!!o)},a.toFixed=function(t,r){var n=this,o=n.c[0];if(t!==c){if(t!==~~t||t<0||t>e)throw Error(i);for(t=t+(n=f(new n.constructor(n),t+n.e+1,r)).e+1;n.c.length<t;)n.c.push(0)}return h(n,!1,!!o)},a[Symbol.for("nodejs.util.inspect.custom")]=a.toJSON=a.toString=function(){var t=this,r=t.constructor;return h(t,t.e<=r.NE||t.e>=r.PE,!!t.c[0])},a.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},a.toPrecision=function(t,r){var n=this,i=n.constructor,u=n.c[0];if(t!==c){if(t!==~~t||t<1||t>e)throw Error(o+"precision");for(n=f(new i(n),t,r);n.c.length<t;)n.c.push(0)}return h(n,t<=n.e||n.e<=i.NE||n.e>=i.PE,!!u)},a.valueOf=function(){var t=this,r=t.constructor;if(!0===r.strict)throw Error(n+"valueOf disallowed");return h(t,t.e<=r.NE||t.e>=r.PE,!0)},function t(){function r(e){var n=this;if(!(n instanceof r))return e===c?t():new r(e);if(e instanceof r)n.s=e.s,n.e=e.e,n.c=e.c.slice();else{if("string"!=typeof e){if(!0===r.strict&&"bigint"!=typeof e)throw TypeError(o+"value");e=0===e&&1/e<0?"-0":String(e)}!function(t,r){var e,n,i;if(!s.test(r))throw Error(o+"number");for(t.s="-"==r.charAt(0)?(r=r.slice(1),-1):1,(e=r.indexOf("."))>-1&&(r=r.replace(".","")),(n=r.search(/e/i))>0?(e<0&&(e=n),e+=+r.slice(n+1),r=r.substring(0,n)):e<0&&(e=r.length),i=r.length,n=0;n<i&&"0"==r.charAt(n);)++n;if(n==i)t.c=[t.e=0];else{for(;i>0&&"0"==r.charAt(--i););for(t.e=e-n-1,t.c=[],e=0;n<=i;)t.c[e++]=+r.charAt(n++)}}(n,e)}n.constructor=r}return r.prototype=a,r.DP=20,r.RM=1,r.NE=-7,r.PE=21,r.strict=!1,r.roundDown=0,r.roundHalfUp=1,r.roundHalfEven=2,r.roundUp=3,r}();var m=function(t){function r(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not enough data";return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),t=function(t,r,e){return r=d(r),function(t,r){if(r&&("object"==v(r)||"function"==typeof r))return r;if(void 0!==r)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,y()?Reflect.construct(r,e||[],d(t).constructor):r.apply(t,e))}(this,r,[e]),Object.setPrototypeOf(t,(this instanceof r?this.constructor:void 0).prototype),t.name="NotEnoughDataError",t}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&b(t,r)}(r,t),e=r,Object.defineProperty(e,"prototype",{writable:!1}),e;var e}(p(Error));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 w(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,j(n.key),n)}}function O(t,r,e){return(r=j(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function j(t){var r=function(t,r){if("object"!=g(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.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(r)?r:r+""}var S=function(){return t=function t(){(function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")})(this,t),O(this,"previousHighest",void 0),O(this,"highest",void 0),O(this,"previousLowest",void 0),O(this,"lowest",void 0),O(this,"previousResult",void 0),O(this,"result",void 0)},(r=[{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,r){return r&&(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)}}])&&w(t.prototype,r),e&&w(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,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 _(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,T(n.key),n)}}function E(t,r,e){return r=R(r),function(t,r){if(r&&("object"==P(r)||"function"==typeof r))return r;if(void 0!==r)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,A()?Reflect.construct(r,e||[],R(t).constructor):r.apply(t,e))}function A(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(A=function(){return!!t})()}function R(t){return R=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},R(t)}function k(t,r){return k=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},k(t,r)}function T(t){var r=function(t,r){if("object"!=P(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=P(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==P(r)?r:r+""}var M=function(t){function r(t){var e,n,o,i;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),n=e=E(this,r),i=void 0,(o=T(o="interval"))in n?Object.defineProperty(n,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[o]=i,e.interval=t,e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&k(t,r)}(r,t),e=r,(n=[{key:"updates",value:function(t){var r=this;return t.forEach((function(t){return r.update(t)})),this.result}},{key:"replace",value:function(t){return this.update(t,!0)}}])&&_(e.prototype,n),o&&_(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n,o}(S);function x(t){return x="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},x(t)}function C(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,N(n.key),n)}}function D(t,r,e){return r=B(r),function(t,r){if(r&&("object"==x(r)||"function"==typeof r))return r;if(void 0!==r)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,I()?Reflect.construct(r,e||[],B(t).constructor):r.apply(t,e))}function I(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(I=function(){return!!t})()}function B(t){return B=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},B(t)}function L(t,r){return L=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},L(t,r)}function N(t){var r=function(t,r){if("object"!=x(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=x(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==x(r)?r:r+""}var z=function(t){function r(){var t,e,n,o;!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r);for(var i=arguments.length,u=new Array(i),l=0;l<i;l++)u[l]=arguments[l];return e=t=D(this,r,[].concat(u)),o=[],(n=N(n="prices"))in e?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o,t}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&L(t,r)}(r,t),e=r,n=[{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){var e=this.prices.reduce((function(t,r){return t+r}),0);return this.setResult(e/this.prices.length,r)}}}],n&&C(e.prototype,n),o&&C(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n,o}(M);function F(t){return F="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},F(t)}function q(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,J(n.key),n)}}function H(t,r,e){return r=G(r),function(t,r){if(r&&("object"==F(r)||"function"==typeof r))return r;if(void 0!==r)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,V()?Reflect.construct(r,e||[],G(t).constructor):r.apply(t,e))}function V(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(V=function(){return!!t})()}function G(t){return G=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},G(t)}function U(t,r){return U=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},U(t,r)}function $(t,r,e){return(r=J(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function J(t){var r=function(t,r){if("object"!=F(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=F(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==F(r)?r:r+""}var K=function(t){function r(t){var e;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),$(e=H(this,r),"interval",void 0),$(e,"indicator",void 0),$(e,"smoothingFactor",void 0),e.interval=t,e.indicator=new z(t),e.smoothingFactor=1/e.interval,e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&U(t,r)}(r,t),e=r,n=[{key:"updates",value:function(t){var r=this;return t.forEach((function(t){return r.update(t)})),this.result}},{key:"update",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],e=this.indicator.update(t);if(r&&void 0!==this.previousResult){var n=(t-this.previousResult)*this.smoothingFactor;return this.setResult(n+this.previousResult,r)}if(!r&&void 0!==this.result){var o=(t-this.result)*this.smoothingFactor;return this.setResult(o+this.result,r)}if(void 0===this.result&&void 0!==e)return this.setResult(e,r)}}],n&&q(e.prototype,n),o&&q(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n,o}(S);function Q(t){return t.length?t.reduce((function(t,r){return t+r}),0)/t.length:0}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 X(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Z(n.key),n)}}function Y(t,r,e){return(r=Z(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function Z(t){var r=function(t,r){if("object"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.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(r)?r:r+""}var tt=function(){return t=function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;(function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")})(this,t),Y(this,"interval",void 0),Y(this,"deviationMultiplier",void 0),Y(this,"prices",[]),Y(this,"result",void 0),this.interval=r,this.deviationMultiplier=e},(r=[{key:"update",value:function(t){if(this.prices.push(t),this.prices.length>this.interval){this.prices.shift();var r=Q(this.prices),e=function(t,r){var e=r||Q(t),n=Q(t.map((function(t){return t-e})).map((function(t){return t*t})));return Math.sqrt(n)}(this.prices,r);return this.result={lower:r-e*this.deviationMultiplier,middle:r,upper:r+e*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}}])&&X(t.prototype,r),e&&X(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function rt(t){return rt="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},rt(t)}function et(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,at(n.key),n)}}function nt(t,r,e){return r=it(r),function(t,r){if(r&&("object"==rt(r)||"function"==typeof r))return r;if(void 0!==r)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(r,e||[],it(t).constructor):r.apply(t,e))}function ot(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(ot=function(){return!!t})()}function it(t){return it=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},it(t)}function ut(t,r){return ut=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},ut(t,r)}function lt(t,r,e){return(r=at(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function at(t){var r=function(t,r){if("object"!=rt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=rt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==rt(r)?r:r+""}var ct=function(t){function r(t){var e;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),lt(e=nt(this,r,[t]),"interval",void 0),lt(e,"pricesCounter",0),lt(e,"weightFactor",void 0),e.interval=t,e.weightFactor=2/(e.interval+1),e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&ut(t,r)}(r,t),e=r,n=[{key:"update",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return r?r&&0===this.pricesCounter&&this.pricesCounter++:this.pricesCounter++,r&&void 0!==this.previousResult?this.setResult(t*this.weightFactor+this.previousResult*(1-this.weightFactor),r):this.setResult(t*this.weightFactor+(void 0!==this.result?this.result:t)*(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&&et(e.prototype,n),o&&et(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n,o}(M);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 ft(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,vt(n.key),n)}}function ht(t,r,e){return(r=vt(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function vt(t){var r=function(t,r){if("object"!=st(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.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(r)?r:r+""}var pt=function(){return t=function t(r,e,n){(function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")})(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=r,this.long=e,this.signal=n},r=[{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 r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.prices.length&&r?this.prices[this.prices.length-1]=t:this.prices.push(t);var e=this.short.update(t,r),n=this.long.update(t,r);if(this.prices.length>this.long.interval&&this.prices.shift(),this.prices.length===this.long.interval){var o=e-n,i=this.signal.update(o,r);return this.result={histogram:o-i,macd:o,signal:i}}}}],r&&ft(t.prototype,r),e&&ft(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();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 bt(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,jt(n.key),n)}}function dt(t,r,e){return r=gt(r),function(t,r){if(r&&("object"==yt(r)||"function"==typeof r))return r;if(void 0!==r)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,mt()?Reflect.construct(r,e||[],gt(t).constructor):r.apply(t,e))}function mt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(mt=function(){return!!t})()}function gt(t){return gt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},gt(t)}function wt(t,r){return wt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},wt(t,r)}function Ot(t,r,e){return(r=jt(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function jt(t){var r=function(t,r){if("object"!=yt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.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(r)?r:r+""}var St=function(t){function r(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:K;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),Ot(e=dt(this,r),"interval",void 0),Ot(e,"previousPrices",[]),Ot(e,"avgGain",void 0),Ot(e,"avgLoss",void 0),Ot(e,"maxValue",100),e.interval=t,e.avgGain=new n(e.interval),e.avgLoss=new n(e.interval),e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&wt(t,r)}(r,t),e=r,n=[{key:"update",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.previousPrices.length&&r?this.previousPrices[this.previousPrices.length-1]=t:this.previousPrices.push(t),!(this.previousPrices.length<2)){var e=t,n=this.previousPrices[this.previousPrices.length-2];if(e>n?(this.avgLoss.update(0,r),this.avgGain.update(t-n,r)):(this.avgLoss.update(n-e,r),this.avgGain.update(0,r)),this.avgGain.isStable){var o=this.avgLoss.getResult();if(0===o)return this.setResult(100,r);var i=this.avgGain.getResult()/o;return this.setResult(this.maxValue-this.maxValue/(i+1),r)}}}}],n&&bt(e.prototype,n),o&&bt(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n,o}(S);function Pt(t){return Pt="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},Pt(t)}var _t=function(t,r){if(void 0===t||void 0===r)throw Error("undefined param in getEMA");for(var e=t.length,n=new Array(e).fill(null),o=new ct(r),i=0;i<e;i++){var u=null;if(null!==t[i]){o.update(t[i]);try{u=o.getResult()}catch(t){u=null}}n[i]=u}return n};function Et(t){return Et="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},Et(t)}var At=function(t,r){if(void 0===t||void 0===r)throw Error("undefined param in getSMA");for(var e=t.length,n=new Array(e).fill(null),o=new z(r),i=0;i<e;i++){var u=null;if(null!==t[i]){o.update(t[i]);try{u=o.getResult()}catch(t){u=null}}n[i]=u}return n};function Rt(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}var kt=function(t,r){return t>r},Tt=function(t,r){return t<r},Mt=function(t){var r=t.fast,e=t.slow,n=r.length;if(n==!e.length)throw Error("fast and slow do not have the same length");for(var o=new Array(n).fill(null),i=0;i<n;i++){var u=r[i],l=e[i],a=void 0;null===u||null===l?a="neutral":u===l?a=kt(r[i-1],e[i-1])?1:Tt(r[i-1],e[i-1])?0:.5:kt(u,l)?a=1:Tt(u,l)&&(a=0),o[i]=a}var c=Ct(o);return xt(c)},xt=function(t){var r=t.map((function(t){return t.length}));return t.map((function(t,e){var n=r[e];return t.map((function(t,r){var e=n-r;return.5===t&&(e=0),1===t&&(e*=1),0===t&&(e*=-1),e})).reverse()})).flat()},Ct=function(t){return 0===t.length?[]:t.reduce((function(t,r,e,n){if(0===e)t.push([r]);else{var o=n[e-1],i=t[t.length-1];r!==o?t.push([r]):i.push(r)}return t}),[])},Dt=function(t,r){if(!t.verticalOhlcv.hasOwnProperty(r))throw Error("property ".concat(r," not found in verticalOhlcv. Invoked by findDirectionCross."));var e=function(t,r){var e=t.verticalOhlcv;if(!e.hasOwnProperty(r))throw Error("property ".concat(r," not found in verticalOhlcv. Invoked by findDirectionCross."));for(var n=e[r],o=n.length,i=new Array(o).fill(null),u=0;u<o;u++)if(u>0&&null!==n[u]){var l=n[u],a=n[u-1];kt(l,a)?i[u]=1:Tt(l,a)?i[u]=0:i[u]=.5}return i}(t,r),n=Ct(e);return xt(n)};function It(t){return It="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},It(t)}var Bt={getSMA:At,getEMA:_t},Lt=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:14,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"SMA",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:14,o=t.length;if(o<r)return[];for(var i=new Array(o).fill(null),u=new St(r),l=0;l<o;l++){var a=null;if(null!==t[l]){u.update(t[l]);try{a=u.getResult()}catch(t){a=null}}i[l]=a}var c,s,f,h=(c={},s="rsi_".concat(r),f=i,(s=function(t){var r=function(t,r){if("object"!=It(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=It(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==It(r)?r:r+""}(s))in c?Object.defineProperty(c,s,{value:f,enumerable:!0,configurable:!0,writable:!0}):c[s]=f,c);if("string"==typeof e&&"number"==typeof n&&Bt.hasOwnProperty("get".concat(e))){var v=Bt["get".concat(e)](i,n);h["rsi_".concat(e,"_").concat(n)]=v,h["rsi_".concat(r,"_x_rsi_").concat(e,"_").concat(n)]=Mt({fast:i,slow:v})}return h};function Nt(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(t){if("string"==typeof t)return zt(t,r);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?zt(t,r):void 0}}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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 i,u=!0,l=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return u=t.done,t},e:function(t){l=!0,i=t},f:function(){try{u||null==e.return||e.return()}finally{if(l)throw i}}}}function zt(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}var Ft=function(t){var r,e=1/0,n=-1/0,o=Nt(t);try{for(o.s();!(r=o.n()).done;){var i=r.value;i<e&&(e=i),i>n&&(n=i)}}catch(t){o.e(t)}finally{o.f()}var u=n-e;return{normalizedDataset:0===u?t.map((function(){return 0})):t.map((function(t){return(t-e)/u})),min:e,max:n}},qt=function(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.25;return null===t||null===r?null:t>r*(5*e)?1:t<r*(3*e)?0:2*e},Ht=function(t,r){if(!r)return null;var e=t.open,n=t.high,o=t.low,i=t.close,u=r.high,l=r.low,a=[n,u],c=[o,l];i>e?(a.push(i),c.push(e)):(a.push(e),c.push(i));var s=Math.max(n,u)-Math.min(o,l)-(Math.abs(u-l)+Math.abs(n-o));return s>0?s:.01},Vt=function(t,r){for(var e=t.length,n=new z(r),o=new Array(e),i=0,u=0,l=0,a=0;a<e;a++)if(n.update(t[a]),n.isStable){var c=n.getResult();o[a]=c,i+=c,u+=c*c,l++}else o[a]=null;var s=i/l,f=u/l-s*s,h=Math.sqrt(f);return o.map((function(t){return null!==t?(t-s)/h:null}))},Gt=function(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5;if(t.length!==r.length)throw new Error("Both arrays must have the same length");for(var n=Vt(t,e),o=Vt(r,e),i=t.length,u=[],l=0,a=0,c=0,s=0,f=0,h=0,v=-1,p=0;p<i;p++){if(null!==n[p]&&null!==o[p]){v=p;break}u.push(0)}if(-1===v)return new Array(i).fill(0);for(var y=v;y<i;y++){var b=n[y],d=o[y];if(null!==b&&null!==d)if(l+=b,a+=d,c+=b*d,s+=b*b,f+=d*d,++h<2)u.push(0);else{var m=h*c-l*a,g=Math.sqrt((h*s-l*l)*(h*f-a*a)),w=0===g?0:m/g;u.push(w)}else l=a=c=s=f=h=0,u.push(0)}return u};function Ut(t){return Ut="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},Ut(t)}function $t(t,r,e){return(r=Zt(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function Jt(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,u,l=[],a=!0,c=!1;try{if(i=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;a=!1}else for(;!(a=(n=i.call(e)).done)&&(l.push(n.value),l.length!==r);a=!0);}catch(t){c=!0,o=t}finally{try{if(!a&&null!=e.return&&(u=e.return(),Object(u)!==u))return}finally{if(c)throw o}}return l}}(t,r)||Wt(t,r)||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 Kt(t){return function(t){if(Array.isArray(t))return Xt(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||Wt(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Qt(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=Wt(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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 i,u=!0,l=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return u=t.done,t},e:function(t){l=!0,i=t},f:function(){try{u||null==e.return||e.return()}finally{if(l)throw i}}}}function Wt(t,r){if(t){if("string"==typeof t)return Xt(t,r);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?Xt(t,r):void 0}}function Xt(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function Yt(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Zt(n.key),n)}}function Zt(t){var r=function(t,r){if("object"!=Ut(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ut(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ut(r)?r:r+""}var tr=function(){return t=function t(r){var e=r.input,n=r.ticker,o=void 0===n?"undefined":n;if(function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t),!Array.isArray(e))throw Error("input ohlcv must be an array: "+o);if(0===e.length)throw Error("input ohlcv must not be empty: "+o);if(!e[0].hasOwnProperty("close"))throw Error("input ohlcv array objects require at least close property: "+o);return this.len=e.length,this.crossPairsArr=[],this.inputOhlcv=e,this.verticalOhlcv=function(t,r){for(var e=["open","high","low","close","volume"],n=new Set(e),o={},i=0,u=e;i<u.length;i++)o[u[i]]=new Array(r);for(var l,a=[],c=0,s=Object.keys(t[0]);c<s.length;c++){var f=s[c];n.has(f)||(o[f]=new Array(r),a.push(f))}var h,v=0,p=0,y=(h=t)[0].hasOwnProperty("date")&&"string"==typeof h[0].date&&/^\d{4}-\d{2}-\d{2}/.test(h[0].date);y&&(o.session_index=new Array(r),o.session_intraday_index=new Array(r),l=t[0].date.slice(0,10));for(var b=0;b<r;b++){var d=t[b];o.open[b]=d.open,o.high[b]=d.high,o.low[b]=d.low,o.close[b]=d.close,o.volume[b]=d.volume;var m,g=Nt(a);try{for(g.s();!(m=g.n()).done;){var w=m.value;o[w][b]=d[w]}}catch(t){g.e(t)}finally{g.f()}if(y){var O=d.date.slice(0,10);O!==l&&(l=O,v++,p=0),o.session_index[b]=v,o.session_intraday_index[b]=p,p++}}return o}(e,this.len),this.indicators={},this.studies={},this.utilities={correlation:Gt},this},r=[{key:"getNormalizedData",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["open"];this.compute();var r,e=this.verticalOhlcv,n={},o={},i=1/0,u={},l=Object.entries(e).filter((function(r){return t.includes(r[0])})),a=Qt(l);try{for(a.s();!(r=a.n()).done;){var c=Jt(r.value,2),s=c[0],f=c[1].filter((function(t){return null!==t}));f.length<i&&(i=f.length);var h=Ft(f);n[s]=h.min,o[s]=h.max,u[s]=h.normalizedDataset}}catch(t){a.e(t)}finally{a.f()}var v,p=Qt(l);try{for(p.s();!(v=p.n()).done;){var y=Jt(v.value,2),b=y[0];y[1],u[b]=u[b].slice(-i)}}catch(t){p.e(t)}finally{p.f()}return{normalizedMin:n,normalizedMax:o,normalizedCols:Kt(new Set([].concat(Kt(Object.keys(n)),Kt(Object.keys(o))))),normalizedDataset:this.getData(u).map((function(t){return Object.values(t)}))}}},{key:"getData",value:function(t){this.compute();for(var r=this.len,e=t||this.verticalOhlcv,n=Object.keys(e),o=n.length,i=[],u=0;u<r;u++){for(var l={},a=!1,c=0;c<o;c++){var s=n[c],f=e[s][u];if(null===f){a=!0;break}l[s]=f}a||i.push(l)}return i}},{key:"getLastValues",value:function(){this.compute();for(var t=this.verticalOhlcv,r=this.len,e={},n=0,o=Object.entries(t);n<o.length;n++){var i=Jt(o[n],2),u=i[0],l=i[1][r-1];e[u]=l}return Object.assign(e,this.studies),e}},{key:"compute",value:function(){for(var t=this.indicators,r=this.addColumn.bind(this),e=0,n=Object.entries(t);e<n.length;e++){var o=Jt(n[e],2),i=o[0],u=o[1];this.verticalOhlcv.hasOwnProperty(i)?delete this.indicators[i]:r(i,u)}return this}},{key:"addColumn",value:function(t,r){var e=this.len;if(t=t.toLowerCase(),r.length>e)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");if(r.length<e){var n=e-r.length;r=new Array(n).fill(null).concat(r)}this.verticalOhlcv[t]=r}},{key:"crossPairs",value:function(t){this.compute();var r=function(t,r){var e,n=t.verticalOhlcv,o=t.len,i={},u={},l={},a=function(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(t){if("string"==typeof t)return Rt(t,r);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?Rt(t,r):void 0}}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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 i,u=!0,l=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return u=t.done,t},e:function(t){l=!0,i=t},f:function(){try{u||null==e.return||e.return()}finally{if(l)throw i}}}}(r);try{var c=function(){var t=e.value,r=t.fast,a=t.slow,c=t.count;if(!r||!a)return 1;"number"!=typeof a||i[a]||(i[a]=Array(o).fill(a));var s="".concat(r,"_x_").concat(a),f="".concat(r,"_c_").concat(a),h=function(t){return void 0!==c?t.slice(-c).filter((function(t){return 1===t||-1===t})).length:0};if(n[s]){var v=n[s];u[s]=v,void 0!==c&&(l[f]=h(v))}else if(n[r]&&n[a]){var p=Mt({fast:n[r],slow:n[a]});u[s]=p,void 0!==c&&(l[f]=h(p))}else if(n[r]&&i[a]){var y=Mt({fast:n[r],slow:i[a]});u[s]=y,void 0!==c&&(l[f]=h(y))}else console.log("Missing ohlcv properties for ".concat(r," or ").concat(a))};for(a.s();!(e=a.n()).done;)c()}catch(t){a.e(t)}finally{a.f()}return{x:u,c:l}}(this,t),e=r.x,n=r.c;return Object.assign(this.indicators,e),Object.assign(this.studies,n),this.compute(),this}},{key:"lag",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["close"],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;this.compute();for(var e=this.verticalOhlcv,n=0;n<t.length;n++)for(var o=1;o<=r;o++){var i="".concat(t[n],"_lag_").concat(o),u=e[t[n]].slice(0,-o);Object.assign(this.indicators,$t({},i,u))}return this.compute(),this}},{key:"ema",value:function(t){var r=function(t,r){var e=t.verticalOhlcv.close,n=_t(e,r);return function(t,r,e){return(r=function(t){var r=function(t,r){if("object"!=Pt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Pt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Pt(r)?r:r+""}(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}({},"ema_".concat(r),n)}(this,t);return Object.assign(this.indicators,r),this}},{key:"sma",value:function(t){var r=function(t,r){var e=t.verticalOhlcv.close,n=At(e,r);return function(t,r,e){return(r=function(t){var r=function(t,r){if("object"!=Et(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Et(r)?r:r+""}(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}({},"sma_".concat(r),n)}(this,t);return Object.assign(this.indicators,r),this}},{key:"macd",value:function(t,r,e){var n=function(t,r,e,n){return function(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:12,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:26,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:9,o=t.length,i=new Array(o).fill(null),u=new Array(o).fill(null),l=new Array(o).fill(null),a=new pt(new ct(r),new ct(e),new ct(n)),c=0;c<o;c++){var s={};a.update(t[c]);try{s=a.getResult()}catch(t){s={macd:null,signal:null,histogram:null}}i[c]=s.macd,u[c]=s.signal,l[c]=s.histogram}return{macd_diff:i,macd_dea:u,macd_histogram:l,macd_diff_x_macd_dea:Mt({fast:i,slow:u})}}(t.verticalOhlcv.close,r,e,n)}(this,t,r,e);return Object.assign(this.indicators,n),this}},{key:"bollingerBands",value:function(t,r){var e=function(t,r,e){return function(t){for(var r,e,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,u=t.length,l=Array(u).fill(null),a=Array(u).fill(null),c=Array(u).fill(null),s=Array(u).fill(null),f=Array(u).fill(null),h=null,v=null,p=new tt(o,i),y=0;y<u;y++){var b={};p.update(t[y]);var d=!1;try{b=p.getResult()}catch(t){d=!0,b={upper:null,middle:null,lower:null}}if(l[y]=b.upper,a[y]=b.middle,c[y]=b.lower,d)s[y]=null,f[y]=null;else{var m=(r=t[y],e=b.upper,{range:(r-(n=b.lower))/(e-n)*100,height:(e-n)/n*100});h=m.range,v=m.height}s[y]=h,f[y]=v}return{bollinger_bands_upper:l,bollinger_bands_middle:a,bollinger_bands_lower:c,bollinger_bands_range:s,bollinger_bands_height:f}}(t.verticalOhlcv.close,r,e)}(this,t,r);return Object.assign(this.indicators,e),this}},{key:"rsi",value:function(t,r,e){var n=function(t,r,e,n){var o=t.verticalOhlcv.close;return"number"==typeof r&&void 0===n&&(n=r),Lt(o,r,e,n)}(this,t,r,e);return Object.assign(this.indicators,n),this}},{key:"orb",value:function(){var t=function(t,r){for(var e=new Array(r).fill(0),n=new Array(r).fill(0),o=0,i=null,u=0,l=0,a=0;a<r;a++){var c=t[a];if(0===a&&!c.hasOwnProperty("date"))throw Error("input ohlcv array must have a date property available in candle datapoint");var s=c.date.split(" ")[0];s!==i&&(i=s,u=c.high,l=c.low),e[o]=u,n[o]=l,o++}return{orb_high:e,orb_low:n}}(this.inputOhlcv,this.len);return Object.assign(this.indicators,t),this}},{key:"donchianChannels",value:function(t,r){var e=function(t,r,e){var n=t.verticalOhlcv,o=t.len;return function(t,r,e,n,o){for(var i=new Array(o).fill(null),u=new Array(o).fill(null),l=new Array(o).fill(null),a=[],c=[],s=0;s<o;s++){for(;a.length&&a[0]<=s-e;)a.shift();for(;a.length&&t[a[a.length-1]]<=t[s];)a.pop();for(a.push(s);c.length&&c[0]<=s-e;)c.shift();for(;c.length&&r[c[c.length-1]]>=r[s];)c.pop();if(c.push(s),s>=e-1){var f=t[a[0]],h=r[c[0]],v=(f+h)/2,p=s+n;p>=0&&p<o&&(i[p]=f,u[p]=h,l[p]=v)}}return{donchian_channel_upper:i,donchian_channel_lower:u,donchian_channel_basis:l}}(n.high,n.low,r,e,o)}(this,t,r);return Object.assign(this.indicators,e),this}},{key:"candlesStudies",value:function(t){var r=function(t,r){return function(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,e=arguments.length>2?arguments[2]:void 0,n=function(t,r){return Math.abs(t-r)},o=new Array(e).fill(null),i=new Array(e).fill(null),u=new Array(e).fill(null),l=new Array(e).fill(null),a=new Array(e).fill(null),c=new z(r),s=new z(parseInt(r/2)),f=0;f<e;f++){var h=t[f],v=h.open,p=h.high,y=h.low,b=h.close,d=void 0!==t[f-1]?Ht(t[f],t[f-1]):null,m=null,g=null,w=n(v,b),O=void 0,j=void 0,S=b>v?1:0;1===S?(O=n(p,b),j=n(v,y)):(O=n(p,v),j=n(b,y)),c.update(w),d&&s.update(d);try{m=c.getResult(),g=s.getResult()}catch(t){m=null,g=null}o[f]=S,i[f]=qt(w,m,.25),u[f]=qt(O,m,.25),l[f]=qt(j,m,.25),a[f]=qt(d,g,.25)}return{candle_direction:o,candle_gap_size:a,candle_body_size:i,candle_top_size:u,candle_bottom_size:l}}(t.inputOhlcv,r,t.len)}(this,t);return Object.assign(this.indicators,r),this}},{key:"findDirectionCross",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["close","low"];this.compute();for(var r=0;r<t.length;r++){var e=t[r],n=Dt(this,e);Object.assign(this.indicators,$t({},"".concat(e,"_linear_direction"),n))}return this.compute(),this}}],r&&Yt(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r}()})(),OHLCV_INDICATORS=r})();
package/index.js CHANGED
@@ -3,85 +3,120 @@ import {sma} from './src/moving-averages/sma.js'
3
3
  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
- import {crossPairs} from './src/studies/findCrosses.js'
7
- import { orb } from './src/studies/orb.js'
6
+ import {crossPairs, findDirectionCross, findLinearDirection} from './src/studies/findCrosses.js'
7
+ import { orb } from './src/oscillators/orb.js'
8
8
  import { donchianChannels } from './src/moving-averages/donchianChannel.js'
9
- import {Big} from 'trading-signals';
10
- import { parseOhlcvToVertical } from './src/utilities/parsing-utilities.js'
9
+ import { normalize, parseOhlcvToVertical } from './src/utilities/parsing-utilities.js'
11
10
  import { candlesStudies } from './src/studies/candleStudies.js'
12
11
  import { correlation } from './src/studies/correlation.js'
13
12
 
14
13
  export default class OHLCV_INDICATORS {
15
- constructor({input, precision = false, ticker = 'undefined'}) {
14
+ constructor({input, ticker = 'undefined'}) {
16
15
 
17
16
  if(!Array.isArray(input)) throw Error('input ohlcv must be an array: ' + ticker)
18
17
  if(input.length === 0) throw Error('input ohlcv must not be empty: ' + ticker)
19
18
  if(!input[0].hasOwnProperty('close')) throw Error('input ohlcv array objects require at least close property: ' + ticker)
20
19
 
21
-
22
- const big = num => (this.precision) ? new Big(num) : num
23
-
24
20
  this.len = input.length
25
- this.precision = precision
26
- this.big = big
27
21
  this.crossPairsArr = []
28
22
  this.inputOhlcv = input
29
- this.verticalOhlcv = parseOhlcvToVertical(input, this.len, big)
23
+ this.verticalOhlcv = parseOhlcvToVertical(input, this.len)
30
24
  this.indicators = {}
31
25
  this.studies = {}
32
- this.isComputed = false
33
26
  this.utilities = {
34
27
  correlation
35
28
  }
36
29
  return this
37
30
  }
38
31
 
39
- getData() {
32
+ getNormalizedData(colKeys = ['open']) {
33
+ this.compute();
34
+ const { verticalOhlcv } = this;
35
+ const min = {};
36
+ const max = {};
37
+ let minLen = Infinity
38
+ const normalizedDataset = {};
39
+ const entries = Object.entries(verticalOhlcv)
40
+ .filter(o => colKeys.includes(o[0]))
41
+
42
+ for (const [key, values] of entries) {
40
43
 
41
- this.compute()
42
- const {verticalOhlcv, precision} = this
43
- const keys = Object.keys(verticalOhlcv)
44
- const keysLength = keys.length
44
+ const filteredValues = values.filter(o => o !== null)
45
45
 
46
- return verticalOhlcv.open.map((_, i) => {
46
+ if(filteredValues.length < minLen)
47
+ {
48
+ minLen = filteredValues.length
49
+ }
47
50
 
48
- const row = {}
51
+ const normalized = normalize(filteredValues)
52
+ min[key] = normalized.min
53
+ max[key] = normalized.max
54
+ normalizedDataset[key] = normalized.normalizedDataset
55
+ }
49
56
 
50
- for(let x = 0; x < keysLength; x++)
51
- {
52
- const header = keys[x]
53
- const value = verticalOhlcv[header][i]
57
+ for (const [key, _] of entries)
58
+ {
59
+ normalizedDataset[key] = normalizedDataset[key].slice(-minLen)
60
+ }
54
61
 
55
- if(precision)
56
- {
57
- row[header] = (value instanceof Big) ? value.toNumber() : value
58
- }
59
- else
60
- {
61
- row[header] = value
62
+ return {
63
+ normalizedMin: min,
64
+ normalizedMax: max,
65
+ normalizedCols: [...new Set([...Object.keys(min), ...Object.keys(max)])],
66
+ normalizedDataset: (this.getData(normalizedDataset)).map(o => Object.values(o))
67
+ }
68
+ }
69
+
70
+
71
+ getData(verticalOhlcvArg) {
72
+ this.compute();
73
+ const verticalOhlcv = verticalOhlcvArg || this.verticalOhlcv;
74
+ const keys = Object.keys(verticalOhlcv);
75
+ const len = verticalOhlcv[keys[0]].length;
76
+ const keysLength = keys.length;
77
+
78
+ // Pre-allocate array to improve memory efficiency
79
+ const result = [];
80
+
81
+ // Iterate over the rows
82
+ for (let i = 0; i < len; i++) {
83
+ const row = {};
84
+ let hasNull = false; // Flag to track if any null value is found
85
+
86
+ // Loop over keys to fill row data
87
+ for (let x = 0; x < keysLength; x++) {
88
+ const header = keys[x];
89
+ const value = verticalOhlcv[header][i];
90
+
91
+ // If value is null, mark the row to be skipped and break
92
+ if (value === null) {
93
+ hasNull = true;
94
+ break;
62
95
  }
96
+
97
+ row[header] = value
63
98
  }
64
-
65
- return row
66
- })
99
+
100
+ // If no null values were found, add row to result
101
+ if (!hasNull) {
102
+ result.push(row);
103
+ }
104
+ }
105
+
106
+ return result;
67
107
  }
108
+
109
+
68
110
  getLastValues(){
69
111
 
70
112
  this.compute()
71
- const {verticalOhlcv, precision, len} = this
113
+ const {verticalOhlcv, len} = this
72
114
  const output = {}
73
115
 
74
116
  for (const [k, arr] of Object.entries(verticalOhlcv)) {
75
117
  let value = arr[len - 1]
76
118
 
77
- if(precision)
78
- {
79
- output[k] = (value instanceof Big) ? value.toNumber(): value
80
- }
81
- else
82
- {
83
- output[k] = value
84
- }
119
+ output[k] = value
85
120
 
86
121
  }
87
122
 
@@ -92,12 +127,6 @@ export default class OHLCV_INDICATORS {
92
127
 
93
128
  compute() {
94
129
 
95
- if(this.isComputed === true){
96
- return false
97
- }
98
-
99
- this.isComputed === true
100
-
101
130
  const indicators = this.indicators
102
131
  const addColumn = this.addColumn.bind(this)
103
132
 
@@ -147,6 +176,25 @@ export default class OHLCV_INDICATORS {
147
176
  return this
148
177
  }
149
178
 
179
+ lag(colKeys = ['close'], lags = 1) {
180
+ this.compute();
181
+ const {verticalOhlcv} = this;
182
+
183
+ for (let x = 0; x < colKeys.length; x++) {
184
+ for (let lag = 1; lag <= lags; lag++) {
185
+ // Create lagged column name and slice the array with the correct lag
186
+ const key = `${colKeys[x]}_lag_${lag}`;
187
+ const values = verticalOhlcv[colKeys[x]].slice(0, -(lag));
188
+
189
+ Object.assign(this.indicators, {[key]: values})
190
+ }
191
+ }
192
+
193
+ this.compute();
194
+ return this;
195
+ }
196
+
197
+
150
198
  ema(size) {
151
199
 
152
200
 
@@ -206,5 +254,52 @@ export default class OHLCV_INDICATORS {
206
254
  Object.assign(this.indicators, result)
207
255
 
208
256
  return this
209
- }
257
+ }
258
+
259
+ findDirectionCross(keyNames = ['close', 'low'])
260
+ {
261
+ this.compute()
262
+
263
+ for(let x = 0; x < keyNames.length; x++)
264
+ {
265
+ const keyName = keyNames[x]
266
+ const result = findDirectionCross(this, keyName)
267
+ Object.assign(this.indicators, {[`${keyName}_direction_cross`]: result})
268
+ }
269
+
270
+ this.compute()
271
+ return this
272
+ }
273
+
274
+ findLinearDirection(keyNames = ['close', 'low'])
275
+ {
276
+ this.compute()
277
+
278
+ for(let x = 0; x < keyNames.length; x++)
279
+ {
280
+ const keyName = keyNames[x]
281
+ const result = findLinearDirection(this, keyName)
282
+ Object.assign(this.indicators, {[`${keyName}_linear_direction`]: result})
283
+ }
284
+
285
+ this.compute()
286
+ return this
287
+ }
288
+ gt(arr = [{a: 'high', b: 'low'}])
289
+ {
290
+ this.compute()
291
+
292
+ const {verticalOhlcv} = this
293
+
294
+ for(let x = 0; x < arr.length; x++)
295
+ {
296
+ const {a, b} = arr[x]
297
+ const result = verticalOhlcv[a].map((v, i) => (v > verticalOhlcv[b][i]) ? 1 : 0)
298
+ Object.assign(this.indicators, {[`${a}_gt_${b}`]: result})
299
+ }
300
+
301
+ this.compute()
302
+
303
+ return this
304
+ }
210
305
  }
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
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
9
  "study": "node test/study.js",
10
+ "knn": "node test/knn.js",
10
11
  "build": "npx webpack"
11
12
  },
12
13
  "author": "https://jaimelias.com/",
13
14
  "license": "ISC",
14
15
  "dependencies": {
16
+ "ml-knn": "^3.0.0",
15
17
  "trading-signals": "^5.0.4"
16
18
  },
17
19
  "devDependencies": {
@@ -3,14 +3,14 @@ import {BollingerBands, FasterBollingerBands, Big} from 'trading-signals';
3
3
 
4
4
  export const bollingerBands = (main, size, times) => {
5
5
 
6
- const {verticalOhlcv, precision} = main
6
+ const {verticalOhlcv} = main
7
7
  const {close} = verticalOhlcv
8
8
 
9
- const col = getBollingerBands(close, size, times, precision)
9
+ const col = getBollingerBands(close, size, times)
10
10
  return col
11
11
  }
12
12
 
13
- export const getBollingerBands = (data, size = 20, times = 2, precision) => {
13
+ export const getBollingerBands = (data, size = 20, times = 2) => {
14
14
 
15
15
  const dataLength = data.length
16
16
  const bollinger_bands_upper = Array(dataLength).fill(null)
@@ -21,22 +21,12 @@ export const getBollingerBands = (data, size = 20, times = 2, precision) => {
21
21
  let range = null
22
22
  let height = null
23
23
 
24
- let getRange
25
- let instance
24
+ let getRange = (value, upper, lower) => ({
25
+ range: ((value - lower) / (upper - lower)) * 100,
26
+ height: ((upper-lower)/lower) * 100
27
+ })
28
+ let instance = new FasterBollingerBands(size, times)
26
29
 
27
- if (precision) {
28
- instance = new BollingerBands(size, times)
29
- getRange = (value, upper, lower) => ({
30
- range: ((value.minus(lower)).div((upper.minus(lower)))).times(100),
31
- height: ((upper.minus(lower)).div(lower)).times(100)
32
- })
33
- } else {
34
- instance = new FasterBollingerBands(size, times)
35
- getRange = (value, upper, lower) => ({
36
- range: ((value - lower) / (upper - lower)) * 100,
37
- height: ((upper-lower)/lower) * 100
38
- })
39
- }
40
30
 
41
31
  for (let x = 0; x < dataLength; x++) {
42
32
  let obj = {};
@@ -1,12 +1,12 @@
1
1
  export const donchianChannels = (main, period, offset) => {
2
2
 
3
- const {verticalOhlcv, precision, len} = main
3
+ const {verticalOhlcv, len} = main
4
4
  const {high, low} = verticalOhlcv
5
5
 
6
- return getDonchianChannels(high, low, period, offset, precision, len)
6
+ return getDonchianChannels(high, low, period, offset, len)
7
7
  }
8
8
 
9
- export const getDonchianChannels = (high, low, period, offset, precision, len) => {
9
+ export const getDonchianChannels = (high, low, period, offset, len) => {
10
10
  const donchian_channel_upper = new Array(len).fill(null)
11
11
  const donchian_channel_lower = new Array(len).fill(null)
12
12
  const donchian_channel_basis = new Array(len).fill(null)
@@ -14,10 +14,8 @@ export const getDonchianChannels = (high, low, period, offset, precision, len) =
14
14
  const maxQueue = []
15
15
  const minQueue = []
16
16
 
17
- const avg = (precision)
18
- ? ((h, l) => (h.plus(l)).div(2))
19
- : ((h, l) => (h + l) / 2)
20
-
17
+ const avg = ((h, l) => (h + l) / 2)
18
+
21
19
  for (let i = 0; i < len; i++) {
22
20
 
23
21
  while (maxQueue.length && maxQueue[0] <= i - period) {
@@ -3,27 +3,27 @@ import {EMA, FasterEMA} from 'trading-signals'
3
3
 
4
4
  export const ema = (main, size) => {
5
5
 
6
- const {verticalOhlcv, precision} = main
6
+ const {verticalOhlcv} = main
7
7
  const {close} = verticalOhlcv
8
8
 
9
- const col = getEMA(close, size, precision)
9
+ const col = getEMA(close, size)
10
10
 
11
11
  return {
12
12
  [`ema_${size}`]: col
13
13
  }
14
14
  }
15
15
 
16
- export const getEMA = (data, size, precision) => {
16
+ export const getEMA = (data, size) => {
17
17
 
18
18
 
19
- if(typeof precision === 'undefined' || typeof data === 'undefined' || typeof size === 'undefined')
19
+ if(typeof data === 'undefined' || typeof size === 'undefined')
20
20
  {
21
21
  throw Error('undefined param in getEMA')
22
22
  }
23
23
 
24
24
  const dataLength = data.length
25
25
  const output = new Array(dataLength).fill(null)
26
- const instance = (precision) ? new EMA(size) : new FasterEMA(size)
26
+ const instance = new FasterEMA(size)
27
27
 
28
28
  for(let x = 0; x < dataLength; x++)
29
29
  {
@@ -4,26 +4,21 @@ import {EMA, MACD, FasterEMA, FasterMACD} from 'trading-signals';
4
4
 
5
5
  export const macd = (main, fastLine, slowLine, signalLine) => {
6
6
 
7
- const {verticalOhlcv, precision} = main
7
+ const {verticalOhlcv} = main
8
8
  const {close} = verticalOhlcv
9
- const col = getMACD(close, fastLine, slowLine, signalLine, precision)
9
+ const col = getMACD(close, fastLine, slowLine, signalLine)
10
10
 
11
11
  return col
12
12
  }
13
13
 
14
- export const getMACD = (data, fastLine = 12, slowLine = 26, signalLine = 9, precision) => {
14
+ export const getMACD = (data, fastLine = 12, slowLine = 26, signalLine = 9) => {
15
15
 
16
16
  const dataLength = data.length
17
17
  const diff = new Array(dataLength).fill(null)
18
18
  const dea = new Array(dataLength).fill(null)
19
19
  const histogram = new Array(dataLength).fill(null)
20
20
 
21
- const instance = (precision) ? new MACD({
22
- indicator: EMA,
23
- shortInterval: fastLine,
24
- longInterval: slowLine,
25
- signalInterval: signalLine
26
- }) : new FasterMACD(new FasterEMA(fastLine), new FasterEMA(slowLine), new FasterEMA(signalLine))
21
+ const instance = new FasterMACD(new FasterEMA(fastLine), new FasterEMA(slowLine), new FasterEMA(signalLine))
27
22
 
28
23
  for(let x = 0; x < dataLength; x++)
29
24
  {
@@ -44,7 +39,7 @@ export const getMACD = (data, fastLine = 12, slowLine = 26, signalLine = 9, prec
44
39
  histogram[x] = obj.histogram
45
40
  }
46
41
 
47
- const x = findCrosses({fast: diff, slow: dea, precision})
42
+ const x = findCrosses({fast: diff, slow: dea})
48
43
 
49
44
  return {
50
45
  macd_diff: diff,
@@ -3,27 +3,26 @@ import {SMA, FasterSMA} from 'trading-signals';
3
3
 
4
4
  export const sma = (main, size) => {
5
5
 
6
- const {verticalOhlcv, precision} = main
6
+ const {verticalOhlcv} = main
7
7
  const {close} = verticalOhlcv
8
8
 
9
- const col = getSMA(close, size, precision)
9
+ const col = getSMA(close, size)
10
10
 
11
11
  return {
12
12
  [`sma_${size}`]: col
13
13
  }
14
14
  }
15
15
 
16
- export const getSMA = (data, size, precision) => {
16
+ export const getSMA = (data, size) => {
17
17
 
18
- if(typeof precision === 'undefined' || typeof data === 'undefined' || typeof size === 'undefined')
18
+ if(typeof data === 'undefined' || typeof size === 'undefined')
19
19
  {
20
20
  throw Error('undefined param in getSMA')
21
21
  }
22
22
 
23
23
  const dataLength = data.length
24
24
  const output = new Array(dataLength).fill(null)
25
- const instance = (precision) ? new SMA(size) : new FasterSMA(size)
26
-
25
+ const instance = new FasterSMA(size)
27
26
 
28
27
  for(let x = 0; x < dataLength; x++)
29
28
  {
@@ -1,13 +1,12 @@
1
- import { findCrosses } from "./findCrosses.js"
1
+ import { findCrosses } from "../studies/findCrosses.js"
2
2
 
3
3
  export const orb = main => {
4
- const {inputOhlcv, len, precision, verticalOhlcv} = main
5
- const {close} = verticalOhlcv
6
- const cols = getOrbOfTheFirstCandle(inputOhlcv, close, len, precision)
4
+ const {inputOhlcv, len} = main
5
+ const cols = getOrbOfTheFirstCandle(inputOhlcv, len)
7
6
  return cols
8
7
  }
9
8
 
10
- const getOrbOfTheFirstCandle = (inputOhlcv, close, len, precision) => {
9
+ const getOrbOfTheFirstCandle = (inputOhlcv, len) => {
11
10
  const orb_high = new Array(len).fill(0)
12
11
  const orb_low = new Array(len).fill(0)
13
12
  let startIndex = 0
@@ -7,7 +7,7 @@ const ma = {getSMA, getEMA}
7
7
 
8
8
  export const rsi = (main, period, movingAverage, movingAveragePeriod) => {
9
9
 
10
- const {verticalOhlcv, precision} = main
10
+ const {verticalOhlcv} = main
11
11
  const {close} = verticalOhlcv
12
12
 
13
13
  if(typeof period === 'number' && typeof movingAveragePeriod === 'undefined')
@@ -15,12 +15,12 @@ export const rsi = (main, period, movingAverage, movingAveragePeriod) => {
15
15
  movingAveragePeriod = period
16
16
  }
17
17
 
18
- const col = getRSI(close, period, movingAverage, movingAveragePeriod, precision)
18
+ const col = getRSI(close, period, movingAverage, movingAveragePeriod)
19
19
 
20
20
  return col
21
21
  }
22
22
 
23
- export const getRSI = (data, period = 14, movingAverage = 'SMA', movingAveragePeriod = 14, precision) => {
23
+ export const getRSI = (data, period = 14, movingAverage = 'SMA', movingAveragePeriod = 14) => {
24
24
 
25
25
  const dataLength = data.length
26
26
 
@@ -29,7 +29,7 @@ export const getRSI = (data, period = 14, movingAverage = 'SMA', movingAveragePe
29
29
  }
30
30
 
31
31
  let rsi = new Array(dataLength).fill(null)
32
- const instance = (precision) ? new RSI(period) : new FasterRSI(period)
32
+ const instance = new FasterRSI(period)
33
33
 
34
34
  for(let x = 0; x < dataLength; x++)
35
35
  {
@@ -58,9 +58,9 @@ export const getRSI = (data, period = 14, movingAverage = 'SMA', movingAveragePe
58
58
  {
59
59
  if(ma.hasOwnProperty(`get${movingAverage}`))
60
60
  {
61
- const rsi_smoothed = ma[`get${movingAverage}`](rsi, movingAveragePeriod, precision)
61
+ const rsi_smoothed = ma[`get${movingAverage}`](rsi, movingAveragePeriod)
62
62
  output[`rsi_${movingAverage}_${movingAveragePeriod}`] = rsi_smoothed
63
- output[`rsi_${period}_x_rsi_${movingAverage}_${movingAveragePeriod}`] = findCrosses({fast: rsi, slow: rsi_smoothed, precision})
63
+ output[`rsi_${period}_x_rsi_${movingAverage}_${movingAveragePeriod}`] = findCrosses({fast: rsi, slow: rsi_smoothed})
64
64
  }
65
65
  }
66
66
 
@@ -28,13 +28,16 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
28
28
 
29
29
  //instances
30
30
  let bodyInstance = new FasterSMA(period)
31
+ let gapInstance = new FasterSMA(parseInt(period/2))
31
32
 
32
33
  for(let x = 0; x < len; x++)
33
34
  {
34
- const prev = inputOhlcv[x-1]
35
35
  const {open, high, low, close} = inputOhlcv[x]
36
- const gapSize = (typeof prev !== 'undefined') ? Math.abs(prev.close - open) : null
36
+ const gapSize = (typeof inputOhlcv[x-1] !== 'undefined')
37
+ ? calculateHighLowEmptyGaps(inputOhlcv[x], inputOhlcv[x-1])
38
+ : null
37
39
  let bodySizeMean = null
40
+ let gapSizeMean = null
38
41
  const bodySize = getSize(open, close)
39
42
  let topSize
40
43
  let bottomSize
@@ -53,28 +56,36 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
53
56
 
54
57
  bodyInstance.update(bodySize)
55
58
 
59
+ if(gapSize)
60
+ {
61
+ gapInstance.update(gapSize)
62
+ }
63
+
64
+
56
65
  try
57
66
  {
58
67
  bodySizeMean = bodyInstance.getResult()
68
+ gapSizeMean = gapInstance.getResult()
59
69
  }
60
70
  catch(err)
61
71
  {
62
72
  bodySizeMean = null
73
+ gapSizeMean = null
63
74
  }
64
75
 
65
76
  candle_direction[x] = candleDirection
66
77
 
67
78
  //body
68
- candle_body_size[x] = classifySize(bodySize, bodySizeMean)
79
+ candle_body_size[x] = classifySize(bodySize, bodySizeMean, 0.25)
69
80
 
70
81
  //top
71
- candle_top_size[x] = classifySize(topSize, bodySizeMean)
82
+ candle_top_size[x] = classifySize(topSize, bodySizeMean, 0.25)
72
83
 
73
84
  //bottom
74
- candle_bottom_size[x] = classifySize(bottomSize, bodySizeMean)
85
+ candle_bottom_size[x] = classifySize(bottomSize, bodySizeMean, 0.25)
75
86
 
76
87
  //gap
77
- candle_gap_size[x] = classifySize(gapSize, bodySizeMean)
88
+ candle_gap_size[x] = classifySize(gapSize, gapSizeMean, 0.25)
78
89
  }
79
90
 
80
91
  return {
@@ -88,10 +99,46 @@ const getCandlesStudies = (inputOhlcv, period = 20, len) => {
88
99
 
89
100
 
90
101
  // 1 for large, 0.5 for medium and 0 for small
91
- const classifySize = (value, mean) => {
102
+ const classifySize = (value, mean, number = 0.25) => {
92
103
 
93
104
  if(value === null || mean === null) return null
94
- if(value > mean * 1.25) return 1
95
- else if(value < mean * 0.75) return 0
96
- else return 0.5
105
+ if(value > mean * (number*5)) return 1
106
+ else if(value < mean * (number*3)) return 0
107
+ else return number * 2
108
+ }
109
+
110
+ const calculateHighLowEmptyGaps = (current, prev) => {
111
+ // This function calculates the empty gaps between the current high/low and the previous high/low.
112
+ // Gaps are zones where the highest highs and lowest lows of the previous and current candles do not touch.
113
+ // If any of the values overlap, the gapSize is 0.
114
+
115
+ if (!prev) return null; // No previous candle, so no gap
116
+
117
+ const {open, high, low, close } = current;
118
+ const { high: prevHigh, low: prevLow } = prev;
119
+
120
+ const highs = [high, prevHigh]
121
+ const lows = [low, prevLow]
122
+
123
+
124
+ if(close > open)
125
+ {
126
+ highs.push(close)
127
+ lows.push(open)
128
+ }
129
+ else
130
+ {
131
+ highs.push(open)
132
+ lows.push(close)
133
+ }
134
+
135
+
136
+ const maxHigh = Math.max(high, prevHigh)
137
+ const minLow = Math.min(low, prevLow)
138
+ const fullSize = maxHigh - minLow
139
+ const prevSize = Math.abs(prevHigh - prevLow)
140
+ const currentSize = Math.abs(high-low)
141
+ const gapSize = fullSize - (prevSize+currentSize)
142
+
143
+ return (gapSize > 0) ? gapSize : 0.01
97
144
  }
@@ -1,6 +1,10 @@
1
+ const eq = (a, b) => a === b
2
+ const gt = (a, b) => a > b
3
+ const lt = (a, b) => a < b
4
+
1
5
 
2
6
  // Function to find crosses between two arrays: fast and slow
3
- export const findCrosses = ({fast, slow, precision}) => {
7
+ export const findCrosses = ({fast, slow}) => {
4
8
  // Map states based on comparison of fast and slow arrays
5
9
 
6
10
  const dataLength = fast.length
@@ -10,23 +14,6 @@ export const findCrosses = ({fast, slow, precision}) => {
10
14
  throw Error('fast and slow do not have the same length')
11
15
  }
12
16
 
13
- let eq
14
- let gt
15
- let lt
16
-
17
- if(precision)
18
- {
19
- eq = (a, b) => a.eq(b)
20
- gt = (a, b) => a.gt(b)
21
- lt = (a, b) => a.lt(b)
22
- }
23
- else
24
- {
25
- eq = (a, b) => a === b
26
- gt = (a, b) => a > b
27
- lt = (a, b) => a < b
28
- }
29
-
30
17
  const state = new Array(dataLength).fill(null)
31
18
 
32
19
  for(let x = 0; x < dataLength; x++)
@@ -39,19 +26,19 @@ export const findCrosses = ({fast, slow, precision}) => {
39
26
  else if(eq(f, s)){
40
27
  if(gt(fast[x-1], slow[x-1]))
41
28
  {
42
- value = 'up'
29
+ value = 1 //up
43
30
  }
44
31
  else if(lt(fast[x-1], slow[x-1]))
45
32
  {
46
- value = 'down'
33
+ value = 0 //down
47
34
  }
48
35
  else
49
36
  {
50
- value = 'neutral'
37
+ value = 0.5 //neutral
51
38
  }
52
39
  }
53
- else if(gt(f, s)) value = 'up'
54
- else if(lt(f, s)) value = 'down'
40
+ else if(gt(f, s)) value = 1
41
+ else if(lt(f, s)) value = 0
55
42
 
56
43
  state[x] = value
57
44
  }
@@ -59,9 +46,14 @@ export const findCrosses = ({fast, slow, precision}) => {
59
46
 
60
47
 
61
48
  const groups = groupConsecutiveValues(state)
62
- const groupLengths = groups.map(g => g.length)
63
49
 
64
- //console.log(JSON.stringify(groups))
50
+ return flatGroupsToNumArr(groups)
51
+ }
52
+
53
+
54
+ const flatGroupsToNumArr = groups => {
55
+
56
+ const groupLengths = groups.map(g => g.length)
65
57
 
66
58
  return groups.map((group, gIndex) => {
67
59
  let initialValue = groupLengths[gIndex]
@@ -69,15 +61,15 @@ export const findCrosses = ({fast, slow, precision}) => {
69
61
  return group.map((s, i) => {
70
62
  let v = initialValue - i
71
63
 
72
- if(s === 'neutral')
64
+ if(s === 0.5)
73
65
  {
74
66
  v = 0
75
67
  }
76
- if(s === 'up')
68
+ if(s === 1)
77
69
  {
78
70
  v = v * 1
79
71
  }
80
- if(s === 'down')
72
+ if(s === 0)
81
73
  {
82
74
  v = v * -1
83
75
  }
@@ -85,11 +77,11 @@ export const findCrosses = ({fast, slow, precision}) => {
85
77
  return v
86
78
  }).reverse()
87
79
  }).flat()
88
-
89
80
  }
90
81
 
82
+
91
83
  // Helper function to group consecutive values
92
- const groupConsecutiveValues = arr => {
84
+ export const groupConsecutiveValues = arr => {
93
85
  if (arr.length === 0) return []
94
86
 
95
87
  return arr.reduce((acc, currentValue, index, array) => {
@@ -118,7 +110,7 @@ const groupConsecutiveValues = arr => {
118
110
 
119
111
  export const crossPairs = (main, arr) => {
120
112
 
121
- const {verticalOhlcv, precision, big, len} = main
113
+ const {verticalOhlcv, len} = main
122
114
  const slowNumArrCache = {};
123
115
  const x = {}
124
116
  const c = {}
@@ -130,7 +122,7 @@ export const crossPairs = (main, arr) => {
130
122
  // Prepare slowNumArr if 'slow' is a number
131
123
  if (typeof slow === 'number' && !slowNumArrCache[slow]) {
132
124
 
133
- slowNumArrCache[slow] = Array(len).fill(big(slow))
125
+ slowNumArrCache[slow] = Array(len).fill(slow)
134
126
  }
135
127
 
136
128
  const crossName = `${fast}_x_${slow}`
@@ -153,7 +145,7 @@ export const crossPairs = (main, arr) => {
153
145
  //cross created from 2 columns
154
146
  else if (verticalOhlcv[fast] && verticalOhlcv[slow]) {
155
147
 
156
- const cross = findCrosses({fast: verticalOhlcv[fast], slow: verticalOhlcv[slow], precision});
148
+ const cross = findCrosses({fast: verticalOhlcv[fast], slow: verticalOhlcv[slow]});
157
149
  x[crossName] = cross
158
150
 
159
151
  if(typeof count !== 'undefined')
@@ -164,7 +156,7 @@ export const crossPairs = (main, arr) => {
164
156
  }
165
157
  //cross created from 1 column and an number
166
158
  else if (verticalOhlcv[fast] && slowNumArrCache[slow]) {
167
- const cross = findCrosses({fast: verticalOhlcv[fast], slow: slowNumArrCache[slow], precision})
159
+ const cross = findCrosses({fast: verticalOhlcv[fast], slow: slowNumArrCache[slow]})
168
160
  x[crossName] = cross
169
161
 
170
162
  if(typeof count !== 'undefined'){
@@ -177,4 +169,54 @@ export const crossPairs = (main, arr) => {
177
169
  }
178
170
 
179
171
  return {x, c}
172
+ }
173
+
174
+
175
+ export const findLinearDirection = (main, keyName) => {
176
+
177
+ const {verticalOhlcv} = main
178
+
179
+ if(!verticalOhlcv.hasOwnProperty(keyName)) throw Error(`property ${keyName} not found in verticalOhlcv. Invoked by findDirectionCross.`)
180
+
181
+ const arr = verticalOhlcv[keyName]
182
+ const len = arr.length
183
+ const state = new Array(len).fill(null)
184
+
185
+
186
+ for(let x = 0; x < len; x++)
187
+ {
188
+ if(x > 0 && arr[x] !== null)
189
+ {
190
+ let curr = arr[x]
191
+ let prev = arr[x-1]
192
+
193
+ if(gt(curr, prev))
194
+ {
195
+ state[x] = 1 //up
196
+ }
197
+ else if(lt(curr, prev))
198
+ {
199
+ state[x] = 0 //down
200
+ }
201
+ else
202
+ {
203
+ state[x] = 0.5 //neutral
204
+ }
205
+ }
206
+ }
207
+
208
+ return state
209
+ }
210
+
211
+ export const findDirectionCross = (main, keyName) => {
212
+
213
+
214
+ const {verticalOhlcv} = main
215
+
216
+ if(!verticalOhlcv.hasOwnProperty(keyName)) throw Error(`property ${keyName} not found in verticalOhlcv. Invoked by findDirectionCross.`)
217
+
218
+ const state = findLinearDirection(main, keyName)
219
+ const groups = groupConsecutiveValues(state)
220
+
221
+ return flatGroupsToNumArr(groups)
180
222
  }
@@ -1,7 +1,7 @@
1
1
  //true if first row date starts with yyyy-mm-dd date
2
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
- export const parseOhlcvToVertical = (input, len, big) => {
4
+ export const parseOhlcvToVertical = (input, len) => {
5
5
  const numberColsKeys = ['open', 'high', 'low', 'close', 'volume']
6
6
  const numberColsKeysSet = new Set(numberColsKeys)
7
7
  const verticalOhlcv = {}
@@ -38,12 +38,11 @@ export const parseOhlcvToVertical = (input, len, big) => {
38
38
  for (let x = 0; x < len; x++) {
39
39
  const current = input[x]
40
40
 
41
- // Process numerical columns with 'big' function
42
- verticalOhlcv.open[x] = big(current.open)
43
- verticalOhlcv.high[x] = big(current.high)
44
- verticalOhlcv.low[x] = big(current.low)
45
- verticalOhlcv.close[x] = big(current.close)
46
- verticalOhlcv.volume[x] = big(current.volume)
41
+ verticalOhlcv.open[x] = current.open
42
+ verticalOhlcv.high[x] = current.high
43
+ verticalOhlcv.low[x] = current.low
44
+ verticalOhlcv.close[x] = current.close
45
+ verticalOhlcv.volume[x] = current.volume
47
46
 
48
47
  // Process other keys
49
48
  for (const key of otherKeys) {
@@ -70,5 +69,30 @@ export const parseOhlcvToVertical = (input, len, big) => {
70
69
  }
71
70
 
72
71
 
72
+ // Memory-efficient and fast normalize function with zero-division handling
73
+ export const normalize = values => {
74
+ let min = Infinity;
75
+ let max = -Infinity;
76
+
77
+ // Single pass to find min and max
78
+ for (let value of values) {
79
+ if (value < min) min = value;
80
+ if (value > max) max = value;
81
+ }
73
82
 
74
-
83
+ const range = max - min;
84
+
85
+ // If range is 0, return an array of 0s (all values are the same)
86
+ return {
87
+ normalizedDataset: range === 0 ? values.map(() => 0) : values.map(value => (value - min) / range),
88
+ min,
89
+ max
90
+ };
91
+ };
92
+
93
+ // Memory-efficient and fast denormalize function
94
+ export const denormalize = (normalizedDataset, min, max) => {
95
+ const range = max - min;
96
+ // If range is 0, return the original min value (all values were the same)
97
+ return range === 0 ? normalizedDataset.map(() => min) : normalizedDataset.map(value => value * range + min);
98
+ };