ohlcv-indicators 1.2.8 → 1.3.0
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.
- package/.babelrc +4 -0
- package/dist/ohlcv-indicators.min.js +1 -1
- package/package.json +7 -3
- package/src/moving-averages/bollingerBands.js +2 -2
- package/webpack.config.js +40 -10
package/.babelrc
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
var OHLCV_INDICATORS;(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},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:()=>V});var s=1e6,i="[big.js] ",o=i+"Invalid ",h=o+"decimal places",r=o+"rounding mode",n=i+"Division by zero",l={},c=void 0,a=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function u(t,e,s,i){var o=t.c;if(s===c&&(s=t.constructor.RM),0!==s&&1!==s&&2!==s&&3!==s)throw Error(r);if(e<1)i=3===s&&(i||!!o[0])||0===e&&(1===s&&o[0]>=5||2===s&&(o[0]>5||5===o[0]&&(i||o[1]!==c))),o.length=1,i?(t.e=t.e-e+1,o[0]=1):o[0]=t.e=0;else if(e<o.length){if(i=1===s&&o[e]>=5||2===s&&(o[e]>5||5===o[e]&&(i||o[e+1]!==c||1&o[e-1]))||3===s&&(i||!!o[0]),o.length=e,i)for(;++o[--e]>9;)if(o[e]=0,0===e){++t.e,o.unshift(1);break}for(e=o.length;!o[--e];)o.pop()}return t}function p(t,e,s){var i=t.e,o=t.c.join(""),h=o.length;if(e)o=o.charAt(0)+(h>1?"."+o.slice(1):"")+(i<0?"e":"e+")+i;else if(i<0){for(;++i;)o="0"+o;o="0."+o}else if(i>0)if(++i>h)for(i-=h;i--;)o+="0";else i<h&&(o=o.slice(0,i)+"."+o.slice(i));else h>1&&(o=o.charAt(0)+"."+o.slice(1));return t.s<0&&s?"-"+o:o}l.abs=function(){var t=new this.constructor(this);return t.s=1,t},l.cmp=function(t){var e,s=this,i=s.c,o=(t=new s.constructor(t)).c,h=s.s,r=t.s,n=s.e,l=t.e;if(!i[0]||!o[0])return i[0]?h:o[0]?-r:0;if(h!=r)return h;if(e=h<0,n!=l)return n>l^e?1:-1;for(r=(n=i.length)<(l=o.length)?n:l,h=-1;++h<r;)if(i[h]!=o[h])return i[h]>o[h]^e?1:-1;return n==l?0:n>l^e?1:-1},l.div=function(t){var e=this,i=e.constructor,o=e.c,r=(t=new i(t)).c,l=e.s==t.s?1:-1,a=i.DP;if(a!==~~a||a<0||a>s)throw Error(h);if(!r[0])throw Error(n);if(!o[0])return t.s=l,t.c=[t.e=0],t;var p,g,v,f,d,m=r.slice(),w=p=r.length,M=o.length,b=o.slice(0,p),x=b.length,R=t,B=R.c=[],y=0,P=a+(R.e=e.e-t.e)+1;for(R.s=l,l=P<0?0:P,m.unshift(0);x++<p;)b.push(0);do{for(v=0;v<10;v++){if(p!=(x=b.length))f=p>x?1:-1;else for(d=-1,f=0;++d<p;)if(r[d]!=b[d]){f=r[d]>b[d]?1:-1;break}if(!(f<0))break;for(g=x==p?r:m;x;){if(b[--x]<g[x]){for(d=x;d&&!b[--d];)b[d]=9;--b[d],b[x]+=10}b[x]-=g[x]}for(;!b[0];)b.shift()}B[y++]=f?v:++v,b[0]&&f?b[x]=o[w]||0:b=[o[w]]}while((w++<M||b[0]!==c)&&l--);return B[0]||1==y||(B.shift(),R.e--,P--),y>P&&u(R,P,i.RM,b[0]!==c),R},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,s,i,o,h=this,r=h.constructor,n=h.s,l=(t=new r(t)).s;if(n!=l)return t.s=-l,h.plus(t);var c=h.c.slice(),a=h.e,u=t.c,p=t.e;if(!c[0]||!u[0])return u[0]?t.s=-l:c[0]?t=new r(h):t.s=1,t;if(n=a-p){for((o=n<0)?(n=-n,i=c):(p=a,i=u),i.reverse(),l=n;l--;)i.push(0);i.reverse()}else for(s=((o=c.length<u.length)?c:u).length,n=l=0;l<s;l++)if(c[l]!=u[l]){o=c[l]<u[l];break}if(o&&(i=c,c=u,u=i,t.s=-t.s),(l=(s=u.length)-(e=c.length))>0)for(;l--;)c[e++]=0;for(l=e;s>n;){if(c[--s]<u[s]){for(e=s;e&&!c[--e];)c[e]=9;--c[e],c[s]+=10}c[s]-=u[s]}for(;0===c[--l];)c.pop();for(;0===c[0];)c.shift(),--p;return c[0]||(t.s=1,c=[p=0]),t.c=c,t.e=p,t},l.mod=function(t){var e,s=this,i=s.constructor,o=s.s,h=(t=new i(t)).s;if(!t.c[0])throw Error(n);return s.s=t.s=1,e=1==t.cmp(s),s.s=o,t.s=h,e?new i(s):(o=i.DP,h=i.RM,i.DP=i.RM=0,s=s.div(t),i.DP=o,i.RM=h,this.minus(s.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,s,i,o=this,h=o.constructor;if(t=new h(t),o.s!=t.s)return t.s=-t.s,o.minus(t);var r=o.e,n=o.c,l=t.e,c=t.c;if(!n[0]||!c[0])return c[0]||(n[0]?t=new h(o):t.s=o.s),t;if(n=n.slice(),e=r-l){for(e>0?(l=r,i=c):(e=-e,i=n),i.reverse();e--;)i.push(0);i.reverse()}for(n.length-c.length<0&&(i=c,c=n,n=i),e=c.length,s=0;e;n[e]%=10)s=(n[--e]=n[e]+c[e]+s)/10|0;for(s&&(n.unshift(s),++l),e=n.length;0===n[--e];)n.pop();return t.c=n,t.e=l,t},l.pow=function(t){var e=this,s=new e.constructor("1"),i=s,h=t<0;if(t!==~~t||t<-1e6||t>1e6)throw Error(o+"exponent");for(h&&(t=-t);1&t&&(i=i.times(e)),t>>=1;)e=e.times(e);return h?s.div(i):i},l.prec=function(t,e){if(t!==~~t||t<1||t>s)throw Error(o+"precision");return u(new this.constructor(this),t,e)},l.round=function(t,e){if(t===c)t=0;else if(t!==~~t||t<-s||t>s)throw Error(h);return u(new this.constructor(this),t+this.e+1,e)},l.sqrt=function(){var t,e,s,o=this,h=o.constructor,r=o.s,n=o.e,l=new h("0.5");if(!o.c[0])return new h(o);if(r<0)throw Error(i+"No square root");0===(r=Math.sqrt(o+""))||r===1/0?((e=o.c.join("")).length+n&1||(e+="0"),n=((n+1)/2|0)-(n<0||1&n),t=new h(((r=Math.sqrt(e))==1/0?"5e":(r=r.toExponential()).slice(0,r.indexOf("e")+1))+n)):t=new h(r+""),n=t.e+(h.DP+=4);do{s=t,t=l.times(s.plus(o.div(s)))}while(s.c.slice(0,n).join("")!==t.c.slice(0,n).join(""));return u(t,(h.DP-=4)+t.e+1,h.RM)},l.times=l.mul=function(t){var e,s=this,i=s.constructor,o=s.c,h=(t=new i(t)).c,r=o.length,n=h.length,l=s.e,c=t.e;if(t.s=s.s==t.s?1:-1,!o[0]||!h[0])return t.c=[t.e=0],t;for(t.e=l+c,r<n&&(e=o,o=h,h=e,c=r,r=n,n=c),e=new Array(c=r+n);c--;)e[c]=0;for(l=n;l--;){for(n=0,c=r+l;c>l;)n=e[c]+h[l]*o[c-l-1]+n,e[c--]=n%10,n=n/10|0;e[c]=n}for(n?++t.e:e.shift(),l=e.length;!e[--l];)e.pop();return t.c=e,t},l.toExponential=function(t,e){var i=this,o=i.c[0];if(t!==c){if(t!==~~t||t<0||t>s)throw Error(h);for(i=u(new i.constructor(i),++t,e);i.c.length<t;)i.c.push(0)}return p(i,!0,!!o)},l.toFixed=function(t,e){var i=this,o=i.c[0];if(t!==c){if(t!==~~t||t<0||t>s)throw Error(h);for(t=t+(i=u(new i.constructor(i),t+i.e+1,e)).e+1;i.c.length<t;)i.c.push(0)}return p(i,!1,!!o)},l[Symbol.for("nodejs.util.inspect.custom")]=l.toJSON=l.toString=function(){var t=this,e=t.constructor;return p(t,t.e<=e.NE||t.e>=e.PE,!!t.c[0])},l.toNumber=function(){var t=Number(p(this,!0,!0));if(!0===this.constructor.strict&&!this.eq(t.toString()))throw Error(i+"Imprecise conversion");return t},l.toPrecision=function(t,e){var i=this,h=i.constructor,r=i.c[0];if(t!==c){if(t!==~~t||t<1||t>s)throw Error(o+"precision");for(i=u(new h(i),t,e);i.c.length<t;)i.c.push(0)}return p(i,t<=i.e||i.e<=h.NE||i.e>=h.PE,!!r)},l.valueOf=function(){var t=this,e=t.constructor;if(!0===e.strict)throw Error(i+"valueOf disallowed");return p(t,t.e<=e.NE||t.e>=e.PE,!0)};const g=function t(){function e(s){var i=this;if(!(i instanceof e))return s===c?t():new e(s);if(s instanceof e)i.s=s.s,i.e=s.e,i.c=s.c.slice();else{if("string"!=typeof s){if(!0===e.strict&&"bigint"!=typeof s)throw TypeError(o+"value");s=0===s&&1/s<0?"-0":String(s)}!function(t,e){var s,i,h;if(!a.test(e))throw Error(o+"number");for(t.s="-"==e.charAt(0)?(e=e.slice(1),-1):1,(s=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(s<0&&(s=i),s+=+e.slice(i+1),e=e.substring(0,i)):s<0&&(s=e.length),h=e.length,i=0;i<h&&"0"==e.charAt(i);)++i;if(i==h)t.c=[t.e=0];else{for(;h>0&&"0"==e.charAt(--h););for(t.e=s-i-1,t.c=[],s=0;i<=h;)t.c[s++]=+e.charAt(i++)}}(i,s)}i.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}();class v extends Error{constructor(t="Not enough data"){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name="NotEnoughDataError"}}class f{previousHighest;highest;previousLowest;lowest;previousResult;result;get isStable(){return void 0!==this.result}getResult(){if(void 0===this.result)throw new v;return this.result}setResult(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}replace(t){return this.update(t,!0)}}class d extends f{interval;constructor(t){super(),this.interval=t}updates(t){return t.forEach((t=>this.update(t))),this.result}replace(t){return this.update(t,!0)}}class m extends d{prices=[];update(t,e=!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)return this.setResult(m.getResultFromBatch(this.prices),e)}static getResultFromBatch(t){return t.reduce(((t,e)=>t.plus(e)),new g("0")).div(t.length||1)}}class w extends d{interval;indicator;smoothingFactor;constructor(t){super(t),this.interval=t,this.indicator=new m(t),this.smoothingFactor=new g(1).div(this.interval)}updates(t){return t.forEach((t=>this.update(t))),this.result}update(t,e=!1){const s=this.indicator.update(t,e);if(e&&this.previousResult){const s=new g(t).minus(this.previousResult).mul(this.smoothingFactor);return this.setResult(s.plus(this.previousResult),e)}if(!e&&this.result){const s=new g(t).minus(this.result).mul(this.smoothingFactor);return this.setResult(s.plus(this.result),e)}if(void 0===this.result&&s)return this.setResult(s,e)}}function M(t){return t.reduce(((t,e)=>t.add(e)),new g(0)).div(t.length||1)}class b{interval;deviationMultiplier;prices=[];result;constructor(t,e=2){this.interval=t,this.deviationMultiplier=e}get isStable(){return void 0!==this.result}update(t){if(this.prices.push(new g(t)),this.prices.length>this.interval){this.prices.shift();const t=m.getResultFromBatch(this.prices),e=function(t,e){const s=e||M(t);return M(t.map((t=>new g(t).sub(s).pow(2)))).sqrt()}(this.prices,t);return this.result={lower:t.sub(e.times(this.deviationMultiplier)),middle:t,upper:t.add(e.times(this.deviationMultiplier))}}}getResult(){if(void 0===this.result)throw new v;return this.result}}class x extends d{interval;pricesCounter=0;weightFactor;constructor(t){super(t),this.interval=t,this.weightFactor=2/(this.interval+1)}update(t,e=!1){e?e&&0===this.pricesCounter&&this.pricesCounter++:this.pricesCounter++;const s=new g(t);return e&&this.previousResult?this.setResult(s.times(this.weightFactor).add(this.previousResult.times(1-this.weightFactor)),e):this.setResult(s.times(this.weightFactor).add((this.result??s).times(1-this.weightFactor)),e)}getResult(){if(this.pricesCounter<this.interval)throw new v;return this.result}get isStable(){try{return this.getResult(),!0}catch{return!1}}}class R{prices=[];long;short;signal;result;constructor(t){this.long=new t.indicator(t.longInterval),this.short=new t.indicator(t.shortInterval),this.signal=new t.indicator(t.signalInterval)}get isStable(){return void 0!==this.result}update(t,e=!1){const s=new g(t);this.prices.length&&e?this.prices[this.prices.length-1]=s:this.prices.push(s);const i=this.short.update(s,e),o=this.long.update(s,e);if(this.prices.length>this.long.interval&&this.prices.shift(),this.prices.length===this.long.interval){const t=i.sub(o),e=this.signal.update(t);return this.result={histogram:t.sub(e),macd:t,signal:e}}}getResult(){if(!this.isStable||void 0===this.result)throw new v;return this.result}}class B extends f{interval;previousPrices=[];avgGain;avgLoss;maxValue=new g(100);constructor(t,e=w){super(),this.interval=t,this.avgGain=new e(this.interval),this.avgLoss=new e(this.interval)}update(t,e=!1){if(this.previousPrices.length&&e?this.previousPrices[this.previousPrices.length-1]=t:this.previousPrices.push(t),this.previousPrices.length<2)return;const s=new g(t),i=new g(this.previousPrices[this.previousPrices.length-2]);if(s.gt(i)?(this.avgLoss.update(new g(0),e),this.avgGain.update(s.sub(i),e)):(this.avgLoss.update(i.sub(s),e),this.avgGain.update(new g(0),e)),this.avgGain.isStable){const t=this.avgLoss.getResult();if(t.eq(0))return this.setResult(new g(100),e);const s=this.avgGain.getResult().div(t);return this.setResult(this.maxValue.minus(this.maxValue.div(s.add(1))),e)}}}const y=(t,e)=>{const s=[],i=new x(e),o=t.length;for(let e=0;e<o;e++){let o=null;i.update(t[e]);try{o=i.getResult()}catch(t){o=null}s.push(o)}return s},P=(t,e)=>{const s=[],i=new m(e),o=t.length;for(let e=0;e<o;e++){let o=null;i.update(t[e]);try{o=i.getResult()}catch(t){o=null}s.push(o)}return s},E=(t,e)=>{t=t.filter((t=>t instanceof g)),e=e.filter((t=>t instanceof g));const s=Math.min(t.length,e.length);t=t.slice(-s),e=e.slice(-s);let i=t.map(((t,s)=>{if(t.eq(e[s]))return"neutral";if(t.gt(e[s]))return"up";if(t.lt(e[s]))return"down";throw Error("undefined error in findCrosses")}));const o=_(i),h=o.map((t=>t.length));return o.map(((t,e)=>{let s=h[e];return t.map(((t,e)=>{let i=s-e;return"neutral"===t&&(i=0),"up"===t&&(i*=1),"down"===t&&(i*=-1),i})).reverse()})).flat()},_=t=>0===t.length?[]:t.reduce(((t,e,s,i)=>{if(0===s)t.push([e]);else{const o=i[s-1],h=t[t.length-1];e!==o?t.push([e]):h.push(e)}return t}),[]),S=(t,e)=>{const{upper:s,lower:i}=e,o=new Array(t.length);for(let e=0;e<t.length;e++)if(null!=s[e]&&null!=i[e]&&null!=t[e]){const h=new g(s[e]),r=new g(i[e]),n=new g(t[e]),l=h.minus(r);o[e]=n.minus(r).div(l).times(100).toNumber()}else o[e]=null;return o},C={getSMA:P,getEMA:y},D=t=>{if(!t||0===t.length)throw new Error("Bins array is empty or not provided");let e=t[0],s=t[0];return t.forEach((t=>{t.grossVolume>e.grossVolume&&(e=t),t.grossVolume<s.grossVolume&&(s=t)})),{high:e,low:s}};class A{constructor(t,e=100){const s=["open","high","low","close"];this.ohlcv={};for(let i of Object.keys(t))s.includes(i)&&(this.ohlcv[i]=t[i].slice(-e))}init(){if(this.ohlcv.close.length<50)return console.log("PatternRecognizer requires at least 50 datapoints"),{chart_pattern:"Neutral",chart_score:0};const t=[{name:"Bullish Flag",condition:this.isBullishFlag.bind(this),score:2},{name:"Bearish Flag",condition:this.isBearishFlag.bind(this),score:-2},{name:"Bullish Pennant",condition:this.isBullishPennant.bind(this),score:2},{name:"Bearish Pennant",condition:this.isBearishPennant.bind(this),score:-2},{name:"Bearish Double Top",condition:this.isDoubleTop.bind(this),score:-1},{name:"Bullish Double Bottom",condition:this.isDoubleBottom.bind(this),score:1},{name:"Bearish Triple Top",condition:this.isTripleTop.bind(this),score:-1},{name:"Bullish Triple Bottom",condition:this.isTripleBottom.bind(this),score:1},{name:"Bearish Head And Shoulders",condition:this.isHeadAndShoulders.bind(this),score:-1},{name:"Bullish Inverse Head And Shoulders",condition:this.isInverseHeadAndShoulders.bind(this),score:1},{name:"Bearish Rising Wedge",condition:this.isRisingWedge.bind(this),score:-1},{name:"Bullish Falling Wedge",condition:this.isFallingWedge.bind(this),score:1},{name:"Bullish Triangle",condition:this.isBullishTriangle.bind(this),score:1},{name:"Bearish Triangle",condition:this.isBearishTriangle.bind(this),score:-1},{name:"Bullish Rectangle",condition:this.isBullishRectangle.bind(this),score:1},{name:"Bearish Rectangle",condition:this.isBearishRectangle.bind(this),score:-1}];for(const{name:e,condition:s,score:i}of t)if(s())return{chart_pattern:e,chart_score:i};return{chart_pattern:"Neutral",chart_score:0}}isBullishFlag(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=(Math.floor(e/2),this.ohlcv.close[t-2*e]);if((this.ohlcv.close[t-e]-s)/s<.15)return!1;const i=this.ohlcv.close[t-e];if((i-this.ohlcv.close[t-1])/i>.05)return!1;for(let s=t-e;s<t-1;s++)if(this.ohlcv.high[s]>this.ohlcv.high[s+1]||this.ohlcv.low[s]>this.ohlcv.low[s+1])return!1;return!0}isBearishFlag(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=(Math.floor(e/2),this.ohlcv.close[t-2*e]);if((s-this.ohlcv.close[t-e])/s<.15)return!1;const i=this.ohlcv.close[t-e];if((this.ohlcv.close[t-1]-i)/i>.05)return!1;for(let s=t-e;s<t-1;s++)if(this.ohlcv.high[s]<this.ohlcv.high[s+1]||this.ohlcv.low[s]<this.ohlcv.low[s+1])return!1;return!0}isBullishPennant(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.floor(e/2),i=this.ohlcv.close[t-2*e];if((this.ohlcv.close[t-e]-i)/i<.15)return!1;const o=this.ohlcv.close[t-e];if((o-this.ohlcv.close[t-1])/o>.05)return!1;for(let e=t-s;e<t-1;e++)if(this.ohlcv.high[e]<this.ohlcv.high[e+1]&&this.ohlcv.low[e]<this.ohlcv.low[e+1]||this.ohlcv.high[e]>this.ohlcv.high[e+1]&&this.ohlcv.low[e]>this.ohlcv.low[e+1])return!1;return!0}isBearishPennant(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.floor(e/2),i=this.ohlcv.close[t-2*e];if((i-this.ohlcv.close[t-e])/i<.15)return!1;const o=this.ohlcv.close[t-e];if((this.ohlcv.close[t-1]-o)/o>.05)return!1;for(let e=t-s;e<t-1;e++)if(this.ohlcv.high[e]>this.ohlcv.high[e+1]&&this.ohlcv.low[e]>this.ohlcv.low[e+1]||this.ohlcv.high[e]<this.ohlcv.high[e+1]&&this.ohlcv.low[e]<this.ohlcv.low[e+1])return!1;return!0}isDoubleTop(){const t=this.ohlcv.close.length,e=Math.floor(t/2),s=Math.max(...this.ohlcv.close.slice(0,e)),i=Math.max(...this.ohlcv.close.slice(e));if(s<=0||i<=0)return!1;const o=Math.min(...this.ohlcv.close.slice(0,e)),h=Math.min(...this.ohlcv.close.slice(e));return!((s-o)/s<.1||(i-h)/i<.1)&&Math.abs(s-i)/s<.03}isDoubleBottom(){const t=this.ohlcv.close.length,e=Math.floor(t/2),s=Math.min(...this.ohlcv.close.slice(0,e)),i=Math.min(...this.ohlcv.close.slice(e));if(s<=0||i<=0)return!1;const o=Math.max(...this.ohlcv.close.slice(0,e)),h=Math.max(...this.ohlcv.close.slice(e));return!((o-s)/s<.1||(h-i)/i<.1)&&Math.abs(s-i)/s<.03}isTripleTop(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.max(...this.ohlcv.close.slice(0,e)),i=Math.max(...this.ohlcv.close.slice(e,2*e)),o=Math.max(...this.ohlcv.close.slice(2*e));if(s<=0||i<=0||o<=0)return!1;const h=(s-Math.min(...this.ohlcv.close.slice(0,e)))/s,r=(i-Math.min(...this.ohlcv.close.slice(e,2*e)))/i,n=(o-Math.min(...this.ohlcv.close.slice(2*e)))/o;return!(h<.1||r<.1||n<.1)&&Math.abs(s-i)/s<.03&&Math.abs(s-o)/s<.03}isTripleBottom(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.min(...this.ohlcv.close.slice(0,e)),i=Math.min(...this.ohlcv.close.slice(e,2*e)),o=Math.min(...this.ohlcv.close.slice(2*e));if(s<=0||i<=0||o<=0)return!1;const h=(Math.max(...this.ohlcv.close.slice(0,e))-s)/s,r=(Math.max(...this.ohlcv.close.slice(e,2*e))-i)/i,n=(Math.max(...this.ohlcv.close.slice(2*e))-o)/o;return!(h<.1||r<.1||n<.1)&&Math.abs(s-i)/s<.03&&Math.abs(s-o)/s<.03}isHeadAndShoulders(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.max(...this.ohlcv.close.slice(0,e)),i=Math.max(...this.ohlcv.close.slice(e,2*e)),o=Math.max(...this.ohlcv.close.slice(2*e));if(s<=0||i<=0||o<=0)return!1;const h=Math.min(...this.ohlcv.close.slice(0,e)),r=Math.min(...this.ohlcv.close.slice(e,2*e)),n=Math.min(...this.ohlcv.close.slice(2*e)),l=(i-r)/i,c=(Math.max(h,n)-Math.min(h,n))/Math.min(h,n);return l>.15&&c<.03}isInverseHeadAndShoulders(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.min(...this.ohlcv.close.slice(0,e)),i=Math.min(...this.ohlcv.close.slice(e,2*e)),o=Math.min(...this.ohlcv.close.slice(2*e));if(s<=0||i<=0||o<=0)return!1;const h=Math.max(...this.ohlcv.close.slice(0,e)),r=Math.max(...this.ohlcv.close.slice(e,2*e)),n=Math.max(...this.ohlcv.close.slice(2*e)),l=(r-i)/i,c=(Math.min(h,n)-Math.max(h,n))/Math.max(h,n);return l>.15&&c<.03}isRisingWedge(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.max(...this.ohlcv.close.slice(0,e)),i=Math.max(...this.ohlcv.close.slice(e,2*e)),o=Math.max(...this.ohlcv.close.slice(2*e)),h=Math.min(...this.ohlcv.close.slice(0,e)),r=Math.min(...this.ohlcv.close.slice(e,2*e)),n=Math.min(...this.ohlcv.close.slice(2*e));return s<i&&i<o&&h<r&&r<n}isFallingWedge(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.max(...this.ohlcv.close.slice(0,e)),i=Math.max(...this.ohlcv.close.slice(e,2*e)),o=Math.max(...this.ohlcv.close.slice(2*e)),h=Math.min(...this.ohlcv.close.slice(0,e)),r=Math.min(...this.ohlcv.close.slice(e,2*e)),n=Math.min(...this.ohlcv.close.slice(2*e));return s>i&&i>o&&h>r&&r>n}isBullishTriangle(){const t=this.ohlcv.close.length,e=Math.floor(t/2),s=Math.max(...this.ohlcv.high.slice(0,e)),i=Math.max(...this.ohlcv.high.slice(e)),o=Math.min(...this.ohlcv.low.slice(0,e)),h=Math.min(...this.ohlcv.low.slice(e));return s>i&&o<h}isBearishTriangle(){const t=this.ohlcv.close.length,e=Math.floor(t/2),s=Math.max(...this.ohlcv.high.slice(0,e)),i=Math.max(...this.ohlcv.high.slice(e));return Math.min(...this.ohlcv.low.slice(0,e))<Math.min(...this.ohlcv.low.slice(e))&&s>i}isBullishRectangle(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.max(...this.ohlcv.high.slice(0,e)),i=Math.max(...this.ohlcv.high.slice(e,2*e)),o=Math.max(...this.ohlcv.high.slice(2*e)),h=Math.min(...this.ohlcv.low.slice(0,e)),r=Math.min(...this.ohlcv.low.slice(e,2*e)),n=Math.min(...this.ohlcv.low.slice(2*e)),l=Math.abs(s-i)/s<.03&&Math.abs(i-o)/i<.03,c=Math.abs(h-r)/h<.03&&Math.abs(r-n)/r<.03;return l&&c}isBearishRectangle(){const t=this.ohlcv.close.length,e=Math.floor(t/3),s=Math.max(...this.ohlcv.high.slice(0,e)),i=Math.max(...this.ohlcv.high.slice(e,2*e)),o=Math.max(...this.ohlcv.high.slice(2*e)),h=Math.min(...this.ohlcv.low.slice(0,e)),r=Math.min(...this.ohlcv.low.slice(e,2*e)),n=Math.min(...this.ohlcv.low.slice(2*e)),l=Math.abs(s-i)/s<.03&&Math.abs(i-o)/i<.03,c=Math.abs(h-r)/h<.03&&Math.abs(r-n)/r<.03;return l&&c}}class V{constructor(){this.ChartPatterns=t=>new A(t).init()}init(t){return this.ohlcv=t.reduce(((t,{open:e,high:s,low:i,close:o,volume:h,...r})=>{t.open.push(e),t.high.push(s),t.low.push(i),t.close.push(o),t.volume.push(h);for(const e of Object.keys(r))t[e]||(t[e]=[]),t[e].push(r[e]);return t}),{open:[],high:[],low:[],close:[],volume:[]}),this}getHeaders(){return Object.keys(this.ohlcv)}getData(){const{ohlcv:t}=this,e=Object.keys(t),s=e.length;return t.open.map(((i,o)=>{const h={};for(let i=0;i<s;i++){const s=e[i],r=t[s][o];h[s]=r instanceof g?r.toNumber():r}return h}))}getLastValues(){const t={};for(const[e,s]of Object.entries(this.ohlcv)){let i=s[s.length-1];t[e]=i instanceof g?i.toNumber():i}return t}addColumn(t,e){const s=this.ohlcv.open.length;if(e.length>s)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");e=[...new Array(s-e.length).fill(null),...e],this.ohlcv[t]=e}crossPairs(t){const e=this.ohlcv,s={},i=t=>{if(!e.hasOwnProperty(t)&&"string"==typeof t){const[e,...s]=t.split("_");this[e]&&s.length>0&&this[e](...s)}};for(const{fast:o,slow:h}of t)if(o&&h)if(i(o),i(h),"number"!=typeof h||s[h]||(s[h]=e.close.map((()=>new g(h)))),e[o]&&e[h]){const t=E(e[o],e[h]);this.addColumn(`${o}_x_${h}`,t)}else if(e[o]&&s[h]){const t=E(e[o],s[h]);this.addColumn(`${o}_x_${h}`,t)}else console.error(`Missing ohlcv properties for ${o} or ${h}`)}ema(t){return((t,e)=>{const{ohlcv:s}=t,i=s.close,o=y(i,e);t.addColumn(`ema_${e}`,o)})(this,t),this}sma(t){return((t,e)=>{const{ohlcv:s}=t,i=s.close,o=P(i,e);t.addColumn(`sma_${e}`,o)})(this,t),this}macd(t,e,s){return((t,e=12,s=26,i=9)=>{const{ohlcv:o}=t,h=((t,e=12,s=26,i=9)=>{const o=[],h=[],r=[],n=new R({indicator:x,shortInterval:e,longInterval:s,signalInterval:i}),l=t.length;for(let e=0;e<l;e++){let s={};n.update(t[e]);try{s=n.getResult()}catch(t){s={macd:null,signal:null,histogram:null}}o.push(s.macd),h.push(s.signal),r.push(s.histogram)}return{macd_diff:o,macd_dea:h,macd_histogram:r,macd_diff_x_macd_dea:E(o,h)}})(o.close,e,s,i);for(let e in h)t.addColumn(e,h[e])})(this,t,e,s),this}bollingerBands(t,e,s){return((t,e,s)=>{const{ohlcv:i}=t,o=((t,e=20,s=2)=>{const i=t.length,o={upper:[],middle:[],lower:[]},h=new b(e,s);for(let e=0;e<i;e++){let s={};h.update(t[e]);try{s=h.getResult()}catch(t){s={upper:null,middle:null,lower:null}}o.upper.push(s.upper),o.middle.push(s.middle),o.lower.push(s.lower)}const r=S(t,{upper:o.upper,lower:o.lower});return{...o,range:r}})(i.close,e,s);for(let e in o)t.addColumn(`bollinger_bands_${e}`,o[e])})(this,t,e),this}rsi(t,e,s){return((t,e,s,i)=>{const{ohlcv:o}=t;"number"==typeof e&&void 0===i&&(i=e);const h=((t,e=14,s="SMA",i=14)=>{if(t.length<e)return[];let o=[];e=parseInt(e),i=parseInt(i);const h=new B(e),r=t.length;for(let e=0;e<r;e++){let s=null;h.update(t[e]);try{s=h.getResult()}catch(t){s=null}o.push(s)}o=o.filter((t=>t));let n={[`rsi_${e}`]:o};if("string"==typeof s&&"number"==typeof i&&C.hasOwnProperty(`get${s}`)){const t=C[`get${s}`](o,i);n[`rsi_${s}_${i}`]=t,n[`rsi_${e}_x_rsi_${s}_${i}`]=E(o,t)}return n})(o.close,e,s,i);for(let e in h)t.addColumn(`${e}`.toLowerCase(),h[e])})(this,t,e,s),this}candles(){return(t=>{const{ohlcv:e}=t,s=(t=>{const{open:e,high:s,low:i,close:o}=t,h=e.length;if(![e,s,i,o].every((t=>Array.isArray(t)&&t.length>1&&t.length===h)))return{pattern:Array(h).fill("Neutral"),name:Array(h).fill("No Pattern"),score:Array(h).fill(0)};const r=(t,e,s=1e-4)=>Math.abs(t-e)<s,n={bullish:[{name:"Marubozu",condition:(t,e)=>r(e.open,e.low)&&r(e.close,e.high),score:2},{name:"Engulfing",condition:(t,e)=>e.open<t.close&&e.close>t.open&&e.low<t.low&&e.high>t.high,score:2},{name:"Kicker",condition:(t,e)=>e.open<t.open&&e.close>e.open&&t.close<t.open,score:2},{name:"Morning Star",condition:(t,e)=>e.close>t.close&&e.open<t.open&&t.close<t.open,score:2},{name:"Piercing Line",condition:(t,e)=>e.close>t.close&&e.open<t.open&&e.close>(t.open+t.close)/2,score:1},{name:"Belt Hold",condition:(t,e)=>e.open>t.open&&r(e.close,e.high)&&r(t.close,t.low),score:1},{name:"Harami",condition:(t,e)=>e.open>t.close&&e.close<t.open&&e.open<t.open&&e.close>t.close,score:1},{name:"Doji",condition:(t,e)=>r(e.close,e.open)&&e.high-e.low>Math.abs(e.close-e.open),score:0}],bearish:[{name:"Marubozu",condition:(t,e)=>r(e.open,e.high)&&r(e.close,e.low),score:-2},{name:"Engulfing",condition:(t,e)=>e.open>t.close&&e.close<t.open&&e.high>t.high&&e.low<t.low,score:-2},{name:"Kicker",condition:(t,e)=>e.open>t.open&&e.close<e.open&&t.close>t.open,score:-2},{name:"Evening Star",condition:(t,e)=>e.close<t.close&&e.open>t.open&&t.close<t.open,score:-2},{name:"Dark Cloud Cover",condition:(t,e)=>e.close<t.close&&e.open>t.open&&e.close<(t.open+t.close)/2,score:-1},{name:"Belt Hold",condition:(t,e)=>e.open<t.open&&r(e.close,e.low)&&r(t.close,t.high),score:-1},{name:"Harami",condition:(t,e)=>e.open<t.close&&e.close>t.open&&e.open>t.open&&e.close<t.close,score:-1},{name:"Doji",condition:(t,e)=>r(e.close,e.open)&&e.high-e.low>Math.abs(e.close-e.open),score:0}]},l=(t,e,s)=>{for(const{name:i,condition:o,score:h}of s)if(o(t,e))return{name:i,score:h};return null},c=["Neutral"],a=["No Pattern"],u=[0];for(let t=1;t<h;t++){const h={open:e[t-1],high:s[t-1],low:i[t-1],close:o[t-1]},r={open:e[t],high:s[t],low:i[t],close:o[t]},p=l(h,r,n.bullish)||l(h,r,n.bearish);p?(c.push(p.score>0?"Bullish":"Bearish"),a.push(p.name),u.push(p.score)):(c.push("Neutral"),a.push("No Pattern"),u.push(0))}return{pattern:c,name:a,score:u}})(e);for(let e in s)t.addColumn(`candle_${e}`.toLowerCase(),s[e])})(this),this}volumeProfile(t,e,s){return((t,e,s=1,i)=>{let{ohlcv:o}=t;const h=((t,e,s)=>{const i=new Date(t[s][t[s].length-1]),o=new Date(i);o.setDate(o.getDate()-e),o.setHours(0,0,0,0);const h={open:[],high:[],low:[],close:[],volume:[],[s]:[]};for(let e=0;e<t[s].length;e++)new Date(t[s][e])>=o&&(h.open.push(t.open[e]),h.high.push(t.high[e]),h.low.push(t.low[e]),h.close.push(t.close[e]),h.volume.push(t.volume[e]),h[s].push(t[s][e]));return h})(o,s,i),r=((t,e=5)=>{const{open:s,high:i,low:o,close:h,volume:r}=t,n=Math.min(...o),l=(Math.max(...i)-n)/e,c={upVolume:0,downVolume:0,grossVolume:0},a=Array.from({length:e},((t,e)=>({price:n+l*e,upVolume:0,downVolume:0,grossVolume:0}))),u=1/l;for(let t=0;t<h.length;t++){const l=h[t],c=s[t],p=i[t],g=o[t],v=r[t],f=l>=c?v:0,d=l<c?v:0,m=Math.max(0,Math.floor((g-n)*u)),w=Math.min(e,Math.ceil((p-n)*u));for(let t=m;t<w;t++)a[t].upVolume+=f,a[t].downVolume+=d,a[t].grossVolume+=f+d}for(const{upVolume:t,downVolume:e,grossVolume:s}of a)c.upVolume+=t,c.downVolume+=e,c.grossVolume+=s;return{bins:a,nodes:D(a)}})(h,e),n=r.nodes.high.price,l=r.nodes.low.price;t.addColumn("volume_profile_high",[n]),t.addColumn("volume_profile_low",[l])})(this,t,e,s),this}}})(),OHLCV_INDICATORS=e})();
|
|
1
|
+
var OHLCV_INDICATORS;(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};(()=>{t.r(e),t.d(e,{default:()=>ce});var r=1e6,n="[big.js] ",o=n+"Invalid ",i=o+"decimal places",l=o+"rounding mode",c=n+"Division by zero",u={},a=void 0,s=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function h(t,e,r,n){var o=t.c;if(r===a&&(r=t.constructor.RM),0!==r&&1!==r&&2!==r&&3!==r)throw Error(l);if(e<1)n=3===r&&(n||!!o[0])||0===e&&(1===r&&o[0]>=5||2===r&&(o[0]>5||5===o[0]&&(n||o[1]!==a))),o.length=1,n?(t.e=t.e-e+1,o[0]=1):o[0]=t.e=0;else if(e<o.length){if(n=1===r&&o[e]>=5||2===r&&(o[e]>5||5===o[e]&&(n||o[e+1]!==a||1&o[e-1]))||3===r&&(n||!!o[0]),o.length=e,n)for(;++o[--e]>9;)if(o[e]=0,0===e){++t.e,o.unshift(1);break}for(e=o.length;!o[--e];)o.pop()}return t}function f(t,e,r){var n=t.e,o=t.c.join(""),i=o.length;if(e)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&&r?"-"+o:o}u.abs=function(){var t=new this.constructor(this);return t.s=1,t},u.cmp=function(t){var e,r=this,n=r.c,o=(t=new r.constructor(t)).c,i=r.s,l=t.s,c=r.e,u=t.e;if(!n[0]||!o[0])return n[0]?i:o[0]?-l:0;if(i!=l)return i;if(e=i<0,c!=u)return c>u^e?1:-1;for(l=(c=n.length)<(u=o.length)?c:u,i=-1;++i<l;)if(n[i]!=o[i])return n[i]>o[i]^e?1:-1;return c==u?0:c>u^e?1:-1},u.div=function(t){var e=this,n=e.constructor,o=e.c,l=(t=new n(t)).c,u=e.s==t.s?1:-1,s=n.DP;if(s!==~~s||s<0||s>r)throw Error(i);if(!l[0])throw Error(c);if(!o[0])return t.s=u,t.c=[t.e=0],t;var f,p,v,y,m,b=l.slice(),d=f=l.length,g=o.length,w=o.slice(0,f),M=w.length,O=t,S=O.c=[],j=0,P=s+(O.e=e.e-t.e)+1;for(O.s=u,u=P<0?0:P,b.unshift(0);M++<f;)w.push(0);do{for(v=0;v<10;v++){if(f!=(M=w.length))y=f>M?1:-1;else for(m=-1,y=0;++m<f;)if(l[m]!=w[m]){y=l[m]>w[m]?1:-1;break}if(!(y<0))break;for(p=M==f?l:b;M;){if(w[--M]<p[M]){for(m=M;m&&!w[--m];)w[m]=9;--w[m],w[M]+=10}w[M]-=p[M]}for(;!w[0];)w.shift()}S[j++]=y?v:++v,w[0]&&y?w[M]=o[d]||0:w=[o[d]]}while((d++<g||w[0]!==a)&&u--);return S[0]||1==j||(S.shift(),O.e--,P--),j>P&&h(O,P,n.RM,w[0]!==a),O},u.eq=function(t){return 0===this.cmp(t)},u.gt=function(t){return this.cmp(t)>0},u.gte=function(t){return this.cmp(t)>-1},u.lt=function(t){return this.cmp(t)<0},u.lte=function(t){return this.cmp(t)<1},u.minus=u.sub=function(t){var e,r,n,o,i=this,l=i.constructor,c=i.s,u=(t=new l(t)).s;if(c!=u)return t.s=-u,i.plus(t);var a=i.c.slice(),s=i.e,h=t.c,f=t.e;if(!a[0]||!h[0])return h[0]?t.s=-u:a[0]?t=new l(i):t.s=1,t;if(c=s-f){for((o=c<0)?(c=-c,n=a):(f=s,n=h),n.reverse(),u=c;u--;)n.push(0);n.reverse()}else for(r=((o=a.length<h.length)?a:h).length,c=u=0;u<r;u++)if(a[u]!=h[u]){o=a[u]<h[u];break}if(o&&(n=a,a=h,h=n,t.s=-t.s),(u=(r=h.length)-(e=a.length))>0)for(;u--;)a[e++]=0;for(u=e;r>c;){if(a[--r]<h[r]){for(e=r;e&&!a[--e];)a[e]=9;--a[e],a[r]+=10}a[r]-=h[r]}for(;0===a[--u];)a.pop();for(;0===a[0];)a.shift(),--f;return a[0]||(t.s=1,a=[f=0]),t.c=a,t.e=f,t},u.mod=function(t){var e,r=this,n=r.constructor,o=r.s,i=(t=new n(t)).s;if(!t.c[0])throw Error(c);return r.s=t.s=1,e=1==t.cmp(r),r.s=o,t.s=i,e?new n(r):(o=n.DP,i=n.RM,n.DP=n.RM=0,r=r.div(t),n.DP=o,n.RM=i,this.minus(r.times(t)))},u.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t},u.plus=u.add=function(t){var e,r,n,o=this,i=o.constructor;if(t=new i(t),o.s!=t.s)return t.s=-t.s,o.minus(t);var l=o.e,c=o.c,u=t.e,a=t.c;if(!c[0]||!a[0])return a[0]||(c[0]?t=new i(o):t.s=o.s),t;if(c=c.slice(),e=l-u){for(e>0?(u=l,n=a):(e=-e,n=c),n.reverse();e--;)n.push(0);n.reverse()}for(c.length-a.length<0&&(n=a,a=c,c=n),e=a.length,r=0;e;c[e]%=10)r=(c[--e]=c[e]+a[e]+r)/10|0;for(r&&(c.unshift(r),++u),e=c.length;0===c[--e];)c.pop();return t.c=c,t.e=u,t},u.pow=function(t){var e=this,r=new e.constructor("1"),n=r,i=t<0;if(t!==~~t||t<-1e6||t>1e6)throw Error(o+"exponent");for(i&&(t=-t);1&t&&(n=n.times(e)),t>>=1;)e=e.times(e);return i?r.div(n):n},u.prec=function(t,e){if(t!==~~t||t<1||t>r)throw Error(o+"precision");return h(new this.constructor(this),t,e)},u.round=function(t,e){if(t===a)t=0;else if(t!==~~t||t<-r||t>r)throw Error(i);return h(new this.constructor(this),t+this.e+1,e)},u.sqrt=function(){var t,e,r,o=this,i=o.constructor,l=o.s,c=o.e,u=new i("0.5");if(!o.c[0])return new i(o);if(l<0)throw Error(n+"No square root");0===(l=Math.sqrt(o+""))||l===1/0?((e=o.c.join("")).length+c&1||(e+="0"),c=((c+1)/2|0)-(c<0||1&c),t=new i(((l=Math.sqrt(e))==1/0?"5e":(l=l.toExponential()).slice(0,l.indexOf("e")+1))+c)):t=new i(l+""),c=t.e+(i.DP+=4);do{r=t,t=u.times(r.plus(o.div(r)))}while(r.c.slice(0,c).join("")!==t.c.slice(0,c).join(""));return h(t,(i.DP-=4)+t.e+1,i.RM)},u.times=u.mul=function(t){var e,r=this,n=r.constructor,o=r.c,i=(t=new n(t)).c,l=o.length,c=i.length,u=r.e,a=t.e;if(t.s=r.s==t.s?1:-1,!o[0]||!i[0])return t.c=[t.e=0],t;for(t.e=u+a,l<c&&(e=o,o=i,i=e,a=l,l=c,c=a),e=new Array(a=l+c);a--;)e[a]=0;for(u=c;u--;){for(c=0,a=l+u;a>u;)c=e[a]+i[u]*o[a-u-1]+c,e[a--]=c%10,c=c/10|0;e[a]=c}for(c?++t.e:e.shift(),u=e.length;!e[--u];)e.pop();return t.c=e,t},u.toExponential=function(t,e){var n=this,o=n.c[0];if(t!==a){if(t!==~~t||t<0||t>r)throw Error(i);for(n=h(new n.constructor(n),++t,e);n.c.length<t;)n.c.push(0)}return f(n,!0,!!o)},u.toFixed=function(t,e){var n=this,o=n.c[0];if(t!==a){if(t!==~~t||t<0||t>r)throw Error(i);for(t=t+(n=h(new n.constructor(n),t+n.e+1,e)).e+1;n.c.length<t;)n.c.push(0)}return f(n,!1,!!o)},u[Symbol.for("nodejs.util.inspect.custom")]=u.toJSON=u.toString=function(){var t=this,e=t.constructor;return f(t,t.e<=e.NE||t.e>=e.PE,!!t.c[0])},u.toNumber=function(){var t=Number(f(this,!0,!0));if(!0===this.constructor.strict&&!this.eq(t.toString()))throw Error(n+"Imprecise conversion");return t},u.toPrecision=function(t,e){var n=this,i=n.constructor,l=n.c[0];if(t!==a){if(t!==~~t||t<1||t>r)throw Error(o+"precision");for(n=h(new i(n),t,e);n.c.length<t;)n.c.push(0)}return f(n,t<=n.e||n.e<=i.NE||n.e>=i.PE,!!l)},u.valueOf=function(){var t=this,e=t.constructor;if(!0===e.strict)throw Error(n+"valueOf disallowed");return f(t,t.e<=e.NE||t.e>=e.PE,!0)};const p=function t(){function e(r){var n=this;if(!(n instanceof e))return r===a?t():new e(r);if(r instanceof e)n.s=r.s,n.e=r.e,n.c=r.c.slice();else{if("string"!=typeof r){if(!0===e.strict&&"bigint"!=typeof r)throw TypeError(o+"value");r=0===r&&1/r<0?"-0":String(r)}!function(t,e){var r,n,i;if(!s.test(e))throw Error(o+"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),i=e.length,n=0;n<i&&"0"==e.charAt(n);)++n;if(n==i)t.c=[t.e=0];else{for(;i>0&&"0"==e.charAt(--i););for(t.e=r-n-1,t.c=[],r=0;n<=i;)t.c[r++]=+e.charAt(n++)}}(n,r)}n.constructor=e}return e.prototype=u,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 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 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(m())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&b(o,r.prototype),o}(t,arguments,d(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),b(r,t)},y(t)}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(m=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 d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}var g=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=d(e),function(t,e){if(e&&("object"==v(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,m()?Reflect.construct(e,r||[],d(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 M(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,S(n.key),n)}}function O(t,e,r){return(e=S(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function S(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 j=function(){return t=function t(){(function(t,e){if(!(t instanceof e))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)},(e=[{key:"isStable",get:function(){return void 0!==this.result}},{key:"getResult",value:function(){if(void 0===this.result)throw new g;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)}}])&&M(t.prototype,e),r&&M(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r}();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 E(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 _(t,e,r){return e=R(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,k()?Reflect.construct(e,r||[],R(t).constructor):e.apply(t,r))}function k(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(k=function(){return!!t})()}function R(t){return R=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},R(t)}function T(t,e){return T=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},T(t,e)}function x(t){var e=function(t,e){if("object"!=P(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.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(e)?e:e+""}var B=function(t){function e(t){var r,n,o,i;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),n=r=_(this,e),i=void 0,(o=x(o="interval"))in n?Object.defineProperty(n,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[o]=i,r.interval=t,r}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&&T(t,e)}(e,t),r=e,(n=[{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(r.prototype,n),o&&E(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(j);function A(t){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},A(t)}function C(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,N(n.key),n)}}function D(t,e,r){return e=V(e),function(t,e){if(e&&("object"==A(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,I()?Reflect.construct(e,r||[],V(t).constructor):e.apply(t,r))}function I(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(I=function(){return!!t})()}function V(t){return V=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},V(t)}function F(t,e){return F=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},F(t,e)}function N(t){var e=function(t,e){if("object"!=A(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=A(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==A(e)?e:e+""}var H=function(t){function e(){var t,r,n,o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);for(var i=arguments.length,l=new Array(i),c=0;c<i;c++)l[c]=arguments[c];return r=t=D(this,e,[].concat(l)),o=[],(n=N(n="prices"))in r?Object.defineProperty(r,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):r[n]=o,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&&F(t,e)}(e,t),r=e,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)return this.setResult(e.getResultFromBatch(this.prices),r)}}],o=[{key:"getResultFromBatch",value:function(t){return t.reduce((function(t,e){return t.plus(e)}),new p("0")).div(t.length||1)}}],n&&C(r.prototype,n),o&&C(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(B);function L(t){return L="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},L(t)}function q(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,K(n.key),n)}}function G(t,e,r){return e=W(e),function(t,e){if(e&&("object"==L(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,U()?Reflect.construct(e,r||[],W(t).constructor):e.apply(t,r))}function U(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(U=function(){return!!t})()}function W(t){return W=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},W(t)}function $(t,e){return $=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},$(t,e)}function z(t,e,r){return(e=K(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function K(t){var e=function(t,e){if("object"!=L(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=L(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==L(e)?e:e+""}var J=function(t){function e(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),z(r=G(this,e,[t]),"interval",void 0),z(r,"indicator",void 0),z(r,"smoothingFactor",void 0),r.interval=t,r.indicator=new H(t),r.smoothingFactor=new p(1).div(r.interval),r}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&&$(t,e)}(e,t),r=e,n=[{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 p(t).minus(this.previousResult).mul(this.smoothingFactor);return this.setResult(n.plus(this.previousResult),e)}if(!e&&this.result){var o=new p(t).minus(this.result).mul(this.smoothingFactor);return this.setResult(o.plus(this.result),e)}if(void 0===this.result&&r)return this.setResult(r,e)}}],n&&q(r.prototype,n),o&&q(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(B);function Q(t){return t.reduce((function(t,e){return t.add(e)}),new p(0)).div(t.length||1)}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 Y(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,tt(n.key),n)}}function Z(t,e,r){return(e=tt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function tt(t){var e=function(t,e){if("object"!=X(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.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(e)?e:e+""}var et=function(){return t=function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),Z(this,"interval",void 0),Z(this,"deviationMultiplier",void 0),Z(this,"prices",[]),Z(this,"result",void 0),this.interval=e,this.deviationMultiplier=r},(e=[{key:"isStable",get:function(){return void 0!==this.result}},{key:"update",value:function(t){if(this.prices.push(new p(t)),this.prices.length>this.interval){this.prices.shift();var e=H.getResultFromBatch(this.prices),r=function(t,e){var r=e||Q(t);return Q(t.map((function(t){return new p(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 g;return this.result}}])&&Y(t.prototype,e),r&&Y(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r}();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 nt(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 ot(t,e,r){return e=lt(e),function(t,e){if(e&&("object"==rt(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,it()?Reflect.construct(e,r||[],lt(t).constructor):e.apply(t,r))}function it(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(it=function(){return!!t})()}function lt(t){return lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},lt(t)}function ct(t,e){return ct=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ct(t,e)}function ut(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"!=rt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.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(e)?e:e+""}var st=function(t){function e(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),ut(r=ot(this,e,[t]),"interval",void 0),ut(r,"pricesCounter",0),ut(r,"weightFactor",void 0),r.interval=t,r.weightFactor=2/(r.interval+1),r}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&&ct(t,e)}(e,t),r=e,n=[{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 p(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 g;return this.result}},{key:"isStable",get:function(){try{return this.getResult(),!0}catch(t){return!1}}}],n&&nt(r.prototype,n),o&&nt(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(B);function ht(t){return ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ht(t)}function ft(t,e){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,vt(n.key),n)}}function pt(t,e,r){return(e=vt(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function vt(t){var e=function(t,e){if("object"!=ht(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=ht(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ht(e)?e:e+""}var yt=function(){return t=function t(e){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),pt(this,"prices",[]),pt(this,"long",void 0),pt(this,"short",void 0),pt(this,"signal",void 0),pt(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)},e=[{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 p(t);this.prices.length&&e?this.prices[this.prices.length-1]=r:this.prices.push(r);var n=this.short.update(r,e),o=this.long.update(r,e);if(this.prices.length>this.long.interval&&this.prices.shift(),this.prices.length===this.long.interval){var i=n.sub(o),l=this.signal.update(i);return this.result={histogram:i.sub(l),macd:i,signal:l}}}},{key:"getResult",value:function(){if(!this.isStable||void 0===this.result)throw new g;return this.result}}],e&&ft(t.prototype,e),r&&ft(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r}();function mt(t){return mt="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},mt(t)}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,St(n.key),n)}}function dt(t,e,r){return e=wt(e),function(t,e){if(e&&("object"==mt(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,gt()?Reflect.construct(e,r||[],wt(t).constructor):e.apply(t,r))}function gt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(gt=function(){return!!t})()}function wt(t){return wt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},wt(t)}function Mt(t,e){return Mt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Mt(t,e)}function Ot(t,e,r){return(e=St(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function St(t){var e=function(t,e){if("object"!=mt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=mt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==mt(e)?e:e+""}var jt=function(t){function e(t){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:J;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),Ot(r=dt(this,e),"interval",void 0),Ot(r,"previousPrices",[]),Ot(r,"avgGain",void 0),Ot(r,"avgLoss",void 0),Ot(r,"maxValue",new p(100)),r.interval=t,r.avgGain=new n(r.interval),r.avgLoss=new n(r.interval),r}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&&Mt(t,e)}(e,t),r=e,n=[{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 p(t),n=new p(this.previousPrices[this.previousPrices.length-2]);if(r.gt(n)?(this.avgLoss.update(new p(0),e),this.avgGain.update(r.sub(n),e)):(this.avgLoss.update(n.sub(r),e),this.avgGain.update(new p(0),e)),this.avgGain.isStable){var o=this.avgLoss.getResult();if(o.eq(0))return this.setResult(new p(100),e);var i=this.avgGain.getResult().div(o);return this.setResult(this.maxValue.minus(this.maxValue.div(i.add(1))),e)}}}}],n&&bt(r.prototype,n),o&&bt(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(j),Pt=function(t,e){for(var r=[],n=new st(e),o=t.length,i=0;i<o;i++){var l=null;n.update(t[i]);try{l=n.getResult()}catch(t){l=null}r.push(l)}return r},Et=function(t,e){for(var r=[],n=new H(e),o=t.length,i=0;i<o;i++){var l=null;n.update(t[i]);try{l=n.getResult()}catch(t){l=null}r.push(l)}return r},_t=function(t,e){t=t.filter((function(t){return t instanceof p})),e=e.filter((function(t){return t instanceof p}));var r=Math.min(t.length,e.length);t=t.slice(-r),e=e.slice(-r);var n=t.map((function(t,r){if(t.eq(e[r]))return"neutral";if(t.gt(e[r]))return"up";if(t.lt(e[r]))return"down";throw Error("undefined error in findCrosses")})),o=kt(n),i=o.map((function(t){return t.length}));return o.map((function(t,e){var r=i[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()},kt=function(t){return 0===t.length?[]:t.reduce((function(t,e,r,n){if(0===r)t.push([e]);else{var o=n[r-1],i=t[t.length-1];e!==o?t.push([e]):i.push(e)}return t}),[])};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 Tt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function xt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?Tt(Object(r),!0).forEach((function(e){Bt(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):Tt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function Bt(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=Rt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.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(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var At=function(t,e){for(var r=e.upper,n=e.lower,o=new Array(t.length),i=0;i<t.length;i++)if(null!=r[i]&&null!=n[i]&&null!=t[i]){var l=new p(r[i]),c=new p(n[i]),u=new p(t[i]),a=l.minus(c);o[i]=u.minus(c).div(a).times(100)}else o[i]=null;return o};function Ct(t){return Ct="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},Ct(t)}var Dt={getSMA:Et,getEMA:Pt},It=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;if(t.length<e)return[];var o=[];e=parseInt(e),n=parseInt(n);for(var i=new jt(e),l=t.length,c=0;c<l;c++){var u=null;i.update(t[c]);try{u=i.getResult()}catch(t){u=null}o.push(u)}o=o.filter((function(t){return t}));var a,s,h,f=(a={},s="rsi_".concat(e),h=o,(s=function(t){var e=function(t,e){if("object"!=Ct(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=Ct(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ct(e)?e:e+""}(s))in a?Object.defineProperty(a,s,{value:h,enumerable:!0,configurable:!0,writable:!0}):a[s]=h,a);if("string"==typeof r&&"number"==typeof n&&Dt.hasOwnProperty("get".concat(r))){var p=Dt["get".concat(r)](o,n);f["rsi_".concat(r,"_").concat(n)]=p,f["rsi_".concat(e,"_x_rsi_").concat(r,"_").concat(n)]=_t(o,p)}return f};function Vt(t){return Vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Vt(t)}function Ft(t){return function(t){if(Array.isArray(t))return Nt(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return Nt(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)?Nt(t,e):void 0}}(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 Nt(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 Ht=function(t){if(!t||0===t.length)throw new Error("Bins array is empty or not provided");var e=t[0],r=t[0];return t.forEach((function(t){t.grossVolume>e.grossVolume&&(e=t),t.grossVolume<r.grossVolume&&(r=t)})),{high:e,low:r}},Lt=function(t,e,r){var n,o,i,l=new Date(t[r][t[r].length-1]),c=new Date(l);c.setDate(c.getDate()-e),c.setHours(0,0,0,0);for(var u=(n={open:[],high:[],low:[],close:[],volume:[]},i=[],(o=function(t){var e=function(t,e){if("object"!=Vt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=Vt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Vt(e)?e:e+""}(o=r))in n?Object.defineProperty(n,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[o]=i,n),a=0;a<t[r].length;a++)new Date(t[r][a])>=c&&(u.open.push(t.open[a]),u.high.push(t.high[a]),u.low.push(t.low[a]),u.close.push(t.close[a]),u.volume.push(t.volume[a]),u[r].push(t[r][a]));return u};function qt(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 Gt=function(t){var e=t.open,r=t.high,n=t.low,o=t.close,i=e.length;if(![e,r,n,o].every((function(t){return Array.isArray(t)&&t.length>1&&t.length===i})))return{pattern:Array(i).fill("Neutral"),name:Array(i).fill("No Pattern"),score:Array(i).fill(0)};for(var l=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-4;return Math.abs(t-e)<r},c={bullish:[{name:"Marubozu",condition:function(t,e){return l(e.open,e.low)&&l(e.close,e.high)},score:2},{name:"Engulfing",condition:function(t,e){return e.open<t.close&&e.close>t.open&&e.low<t.low&&e.high>t.high},score:2},{name:"Kicker",condition:function(t,e){return e.open<t.open&&e.close>e.open&&t.close<t.open},score:2},{name:"Morning Star",condition:function(t,e){return e.close>t.close&&e.open<t.open&&t.close<t.open},score:2},{name:"Piercing Line",condition:function(t,e){return e.close>t.close&&e.open<t.open&&e.close>(t.open+t.close)/2},score:1},{name:"Belt Hold",condition:function(t,e){return e.open>t.open&&l(e.close,e.high)&&l(t.close,t.low)},score:1},{name:"Harami",condition:function(t,e){return e.open>t.close&&e.close<t.open&&e.open<t.open&&e.close>t.close},score:1},{name:"Doji",condition:function(t,e){return l(e.close,e.open)&&e.high-e.low>Math.abs(e.close-e.open)},score:0}],bearish:[{name:"Marubozu",condition:function(t,e){return l(e.open,e.high)&&l(e.close,e.low)},score:-2},{name:"Engulfing",condition:function(t,e){return e.open>t.close&&e.close<t.open&&e.high>t.high&&e.low<t.low},score:-2},{name:"Kicker",condition:function(t,e){return e.open>t.open&&e.close<e.open&&t.close>t.open},score:-2},{name:"Evening Star",condition:function(t,e){return e.close<t.close&&e.open>t.open&&t.close<t.open},score:-2},{name:"Dark Cloud Cover",condition:function(t,e){return e.close<t.close&&e.open>t.open&&e.close<(t.open+t.close)/2},score:-1},{name:"Belt Hold",condition:function(t,e){return e.open<t.open&&l(e.close,e.low)&&l(t.close,t.high)},score:-1},{name:"Harami",condition:function(t,e){return e.open<t.close&&e.close>t.open&&e.open>t.open&&e.close<t.close},score:-1},{name:"Doji",condition:function(t,e){return l(e.close,e.open)&&e.high-e.low>Math.abs(e.close-e.open)},score:0}]},u=function(t,e,r){var n,o=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 qt(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)?qt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);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,l=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return l=t.done,t},e:function(t){c=!0,i=t},f:function(){try{l||null==r.return||r.return()}finally{if(c)throw i}}}}(r);try{for(o.s();!(n=o.n()).done;){var i=n.value,l=i.name,c=i.condition,u=i.score;if(c(t,e))return{name:l,score:u}}}catch(t){o.e(t)}finally{o.f()}return null},a=["Neutral"],s=["No Pattern"],h=[0],f=1;f<i;f++){var p={open:e[f-1],high:r[f-1],low:n[f-1],close:o[f-1]},v={open:e[f],high:r[f],low:n[f],close:o[f]},y=u(p,v,c.bullish)||u(p,v,c.bearish);y?(a.push(y.score>0?"Bullish":"Bearish"),s.push(y.name),h.push(y.score)):(a.push("Neutral"),s.push("No Pattern"),h.push(0))}return{pattern:a,name:s,score:h}};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 Wt(t){return function(t){if(Array.isArray(t))return $t(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return $t(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)?$t(t,e):void 0}}(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 $t(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 zt(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,Kt(n.key),n)}}function Kt(t){var e=function(t,e){if("object"!=Ut(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.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(e)?e:e+""}var Jt=function(){return t=function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var n=["open","high","low","close"];this.ohlcv={};for(var o=0,i=Object.keys(e);o<i.length;o++){var l=i[o];n.includes(l)&&(this.ohlcv[l]=e[l].slice(-r))}},(e=[{key:"init",value:function(){if(this.ohlcv.close.length<50)return console.log("PatternRecognizer requires at least 50 datapoints"),{chart_pattern:"Neutral",chart_score:0};for(var t=0,e=[{name:"Bullish Flag",condition:this.isBullishFlag.bind(this),score:2},{name:"Bearish Flag",condition:this.isBearishFlag.bind(this),score:-2},{name:"Bullish Pennant",condition:this.isBullishPennant.bind(this),score:2},{name:"Bearish Pennant",condition:this.isBearishPennant.bind(this),score:-2},{name:"Bearish Double Top",condition:this.isDoubleTop.bind(this),score:-1},{name:"Bullish Double Bottom",condition:this.isDoubleBottom.bind(this),score:1},{name:"Bearish Triple Top",condition:this.isTripleTop.bind(this),score:-1},{name:"Bullish Triple Bottom",condition:this.isTripleBottom.bind(this),score:1},{name:"Bearish Head And Shoulders",condition:this.isHeadAndShoulders.bind(this),score:-1},{name:"Bullish Inverse Head And Shoulders",condition:this.isInverseHeadAndShoulders.bind(this),score:1},{name:"Bearish Rising Wedge",condition:this.isRisingWedge.bind(this),score:-1},{name:"Bullish Falling Wedge",condition:this.isFallingWedge.bind(this),score:1},{name:"Bullish Triangle",condition:this.isBullishTriangle.bind(this),score:1},{name:"Bearish Triangle",condition:this.isBearishTriangle.bind(this),score:-1},{name:"Bullish Rectangle",condition:this.isBullishRectangle.bind(this),score:1},{name:"Bearish Rectangle",condition:this.isBearishRectangle.bind(this),score:-1}];t<e.length;t++){var r=e[t],n=r.name,o=r.condition,i=r.score;if(o())return{chart_pattern:n,chart_score:i}}return{chart_pattern:"Neutral",chart_score:0}}},{key:"isBullishFlag",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=(Math.floor(e/2),this.ohlcv.close[t-2*e]);if((this.ohlcv.close[t-e]-r)/r<.15)return!1;var n=this.ohlcv.close[t-e];if((n-this.ohlcv.close[t-1])/n>.05)return!1;for(var o=t-e;o<t-1;o++)if(this.ohlcv.high[o]>this.ohlcv.high[o+1]||this.ohlcv.low[o]>this.ohlcv.low[o+1])return!1;return!0}},{key:"isBearishFlag",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=(Math.floor(e/2),this.ohlcv.close[t-2*e]);if((r-this.ohlcv.close[t-e])/r<.15)return!1;var n=this.ohlcv.close[t-e];if((this.ohlcv.close[t-1]-n)/n>.05)return!1;for(var o=t-e;o<t-1;o++)if(this.ohlcv.high[o]<this.ohlcv.high[o+1]||this.ohlcv.low[o]<this.ohlcv.low[o+1])return!1;return!0}},{key:"isBullishPennant",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.floor(e/2),n=this.ohlcv.close[t-2*e];if((this.ohlcv.close[t-e]-n)/n<.15)return!1;var o=this.ohlcv.close[t-e];if((o-this.ohlcv.close[t-1])/o>.05)return!1;for(var i=t-r;i<t-1;i++)if(this.ohlcv.high[i]<this.ohlcv.high[i+1]&&this.ohlcv.low[i]<this.ohlcv.low[i+1]||this.ohlcv.high[i]>this.ohlcv.high[i+1]&&this.ohlcv.low[i]>this.ohlcv.low[i+1])return!1;return!0}},{key:"isBearishPennant",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.floor(e/2),n=this.ohlcv.close[t-2*e];if((n-this.ohlcv.close[t-e])/n<.15)return!1;var o=this.ohlcv.close[t-e];if((this.ohlcv.close[t-1]-o)/o>.05)return!1;for(var i=t-r;i<t-1;i++)if(this.ohlcv.high[i]>this.ohlcv.high[i+1]&&this.ohlcv.low[i]>this.ohlcv.low[i+1]||this.ohlcv.high[i]<this.ohlcv.high[i+1]&&this.ohlcv.low[i]<this.ohlcv.low[i+1])return!1;return!0}},{key:"isDoubleTop",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/2),r=Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.close.slice(e)));if(r<=0||n<=0)return!1;var o=Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))),i=Math.min.apply(Math,Wt(this.ohlcv.close.slice(e)));return!((r-o)/r<.1||(n-i)/n<.1)&&Math.abs(r-n)/r<.03}},{key:"isDoubleBottom",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/2),r=Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.min.apply(Math,Wt(this.ohlcv.close.slice(e)));if(r<=0||n<=0)return!1;var o=Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e))),i=Math.max.apply(Math,Wt(this.ohlcv.close.slice(e)));return!((o-r)/r<.1||(i-n)/n<.1)&&Math.abs(r-n)/r<.03}},{key:"isTripleTop",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),o=Math.max.apply(Math,Wt(this.ohlcv.close.slice(2*e)));if(r<=0||n<=0||o<=0)return!1;var i=(r-Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))))/r,l=(n-Math.min.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))))/n,c=(o-Math.min.apply(Math,Wt(this.ohlcv.close.slice(2*e))))/o;return!(i<.1||l<.1||c<.1)&&Math.abs(r-n)/r<.03&&Math.abs(r-o)/r<.03}},{key:"isTripleBottom",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.min.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),o=Math.min.apply(Math,Wt(this.ohlcv.close.slice(2*e)));if(r<=0||n<=0||o<=0)return!1;var i=(Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e)))-r)/r,l=(Math.max.apply(Math,Wt(this.ohlcv.close.slice(e,2*e)))-n)/n,c=(Math.max.apply(Math,Wt(this.ohlcv.close.slice(2*e)))-o)/o;return!(i<.1||l<.1||c<.1)&&Math.abs(r-n)/r<.03&&Math.abs(r-o)/r<.03}},{key:"isHeadAndShoulders",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),o=Math.max.apply(Math,Wt(this.ohlcv.close.slice(2*e)));if(r<=0||n<=0||o<=0)return!1;var i=Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))),l=Math.min.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),c=Math.min.apply(Math,Wt(this.ohlcv.close.slice(2*e))),u=(n-l)/n,a=(Math.max(i,c)-Math.min(i,c))/Math.min(i,c);return u>.15&&a<.03}},{key:"isInverseHeadAndShoulders",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.min.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),o=Math.min.apply(Math,Wt(this.ohlcv.close.slice(2*e)));if(r<=0||n<=0||o<=0)return!1;var i=Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e))),l=Math.max.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),c=Math.max.apply(Math,Wt(this.ohlcv.close.slice(2*e))),u=(l-n)/n,a=(Math.min(i,c)-Math.max(i,c))/Math.max(i,c);return u>.15&&a<.03}},{key:"isRisingWedge",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),o=Math.max.apply(Math,Wt(this.ohlcv.close.slice(2*e))),i=Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))),l=Math.min.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),c=Math.min.apply(Math,Wt(this.ohlcv.close.slice(2*e)));return r<n&&n<o&&i<l&&l<c}},{key:"isFallingWedge",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.max.apply(Math,Wt(this.ohlcv.close.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),o=Math.max.apply(Math,Wt(this.ohlcv.close.slice(2*e))),i=Math.min.apply(Math,Wt(this.ohlcv.close.slice(0,e))),l=Math.min.apply(Math,Wt(this.ohlcv.close.slice(e,2*e))),c=Math.min.apply(Math,Wt(this.ohlcv.close.slice(2*e)));return r>n&&n>o&&i>l&&l>c}},{key:"isBullishTriangle",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/2),r=Math.max.apply(Math,Wt(this.ohlcv.high.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.high.slice(e))),o=Math.min.apply(Math,Wt(this.ohlcv.low.slice(0,e))),i=Math.min.apply(Math,Wt(this.ohlcv.low.slice(e)));return r>n&&o<i}},{key:"isBearishTriangle",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/2),r=Math.max.apply(Math,Wt(this.ohlcv.high.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.high.slice(e)));return Math.min.apply(Math,Wt(this.ohlcv.low.slice(0,e)))<Math.min.apply(Math,Wt(this.ohlcv.low.slice(e)))&&r>n}},{key:"isBullishRectangle",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.max.apply(Math,Wt(this.ohlcv.high.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.high.slice(e,2*e))),o=Math.max.apply(Math,Wt(this.ohlcv.high.slice(2*e))),i=Math.min.apply(Math,Wt(this.ohlcv.low.slice(0,e))),l=Math.min.apply(Math,Wt(this.ohlcv.low.slice(e,2*e))),c=Math.min.apply(Math,Wt(this.ohlcv.low.slice(2*e))),u=Math.abs(r-n)/r<.03&&Math.abs(n-o)/n<.03,a=Math.abs(i-l)/i<.03&&Math.abs(l-c)/l<.03;return u&&a}},{key:"isBearishRectangle",value:function(){var t=this.ohlcv.close.length,e=Math.floor(t/3),r=Math.max.apply(Math,Wt(this.ohlcv.high.slice(0,e))),n=Math.max.apply(Math,Wt(this.ohlcv.high.slice(e,2*e))),o=Math.max.apply(Math,Wt(this.ohlcv.high.slice(2*e))),i=Math.min.apply(Math,Wt(this.ohlcv.low.slice(0,e))),l=Math.min.apply(Math,Wt(this.ohlcv.low.slice(e,2*e))),c=Math.min.apply(Math,Wt(this.ohlcv.low.slice(2*e))),u=Math.abs(r-n)/r<.03&&Math.abs(n-o)/n<.03,a=Math.abs(i-l)/i<.03&&Math.abs(l-c)/l<.03;return u&&a}}])&&zt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}(),Qt=["open","high","low","close","volume"];function Xt(t){return Xt="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},Xt(t)}function Yt(t){return function(t){if(Array.isArray(t))return ne(t)}(t)||Zt(t)||re(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 Zt(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function te(t,e){return oe(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,l,c=[],u=!0,a=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(t){a=!0,o=t}finally{try{if(!u&&null!=r.return&&(l=r.return(),Object(l)!==l))return}finally{if(a)throw o}}return c}}(t,e)||re(t,e)||ee()}function ee(){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 re(t,e){if(t){if("string"==typeof t)return ne(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)?ne(t,e):void 0}}function ne(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){if(Array.isArray(t))return t}function ie(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,le(n.key),n)}}function le(t){var e=function(t,e){if("object"!=Xt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=Xt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Xt(e)?e:e+""}var ce=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.ChartPatterns=function(t){return new Jt(t).init()}},e=[{key:"init",value:function(t){return this.ohlcv=t.reduce((function(t,e){var r=e.open,n=e.high,o=e.low,i=e.close,l=e.volume,c=function(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(e.includes(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)r=i[n],e.includes(r)||{}.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}(e,Qt);t.open.push(r),t.high.push(n),t.low.push(o),t.close.push(i),t.volume.push(l);for(var u=0,a=Object.keys(c);u<a.length;u++){var s=a[u];t[s]||(t[s]=[]),t[s].push(c[s])}return t}),{open:[],high:[],low:[],close:[],volume:[]}),this}},{key:"getHeaders",value:function(){return Object.keys(this.ohlcv)}},{key:"getData",value:function(){var t=this.ohlcv,e=Object.keys(t),r=e.length;return t.open.map((function(n,o){for(var i={},l=0;l<r;l++){var c=e[l],u=t[c][o];i[c]=u instanceof p?u.toNumber():u}return i}))}},{key:"getLastValues",value:function(){for(var t={},e=0,r=Object.entries(this.ohlcv);e<r.length;e++){var n=te(r[e],2),o=n[0],i=n[1],l=i[i.length-1];t[o]=l instanceof p?l.toNumber():l}return t}},{key:"addColumn",value:function(t,e){var r=this.ohlcv.open.length;if(e.length>r)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");var n=new Array(r-e.length).fill(null);e=[].concat(Yt(n),Yt(e)),this.ohlcv[t]=e}},{key:"crossPairs",value:function(t){var e,r=this,n=this.ohlcv,o={},i=function(t){if(!n.hasOwnProperty(t)&&"string"==typeof t){var e=oe(l=t.split("_"))||Zt(l)||re(l)||ee(),o=e[0],i=e.slice(1);r[o]&&i.length>0&&r[o].apply(r,Yt(i))}var l},l=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=re(t))){r&&(t=r);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,l=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return l=t.done,t},e:function(t){c=!0,i=t},f:function(){try{l||null==r.return||r.return()}finally{if(c)throw i}}}}(t);try{var c=function(){var t=e.value,l=t.fast,c=t.slow;if(!l||!c)return 1;if(i(l),i(c),"number"!=typeof c||o[c]||(o[c]=n.close.map((function(){return new p(c)}))),n[l]&&n[c]){var u=_t(n[l],n[c]);r.addColumn("".concat(l,"_x_").concat(c),u)}else if(n[l]&&o[c]){var a=_t(n[l],o[c]);r.addColumn("".concat(l,"_x_").concat(c),a)}else console.error("Missing ohlcv properties for ".concat(l," or ").concat(c))};for(l.s();!(e=l.n()).done;)c()}catch(t){l.e(t)}finally{l.f()}}},{key:"ema",value:function(t){return function(t,e){var r=t.ohlcv.close,n=Pt(r,e);t.addColumn("ema_".concat(e),n)}(this,t),this}},{key:"sma",value:function(t){return function(t,e){var r=t.ohlcv.close,n=Et(r,e);t.addColumn("sma_".concat(e),n)}(this,t),this}},{key:"macd",value:function(t,e,r){return function(t){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,o=function(t){for(var e=[],r=[],n=[],o=new yt({indicator:st,shortInterval:arguments.length>1&&void 0!==arguments[1]?arguments[1]:12,longInterval:arguments.length>2&&void 0!==arguments[2]?arguments[2]:26,signalInterval:arguments.length>3&&void 0!==arguments[3]?arguments[3]:9}),i=t.length,l=0;l<i;l++){var c={};o.update(t[l]);try{c=o.getResult()}catch(t){c={macd:null,signal:null,histogram:null}}e.push(c.macd),r.push(c.signal),n.push(c.histogram)}return{macd_diff:e,macd_dea:r,macd_histogram:n,macd_diff_x_macd_dea:_t(e,r)}}(t.ohlcv.close,e,r,n);for(var i in o)t.addColumn(i,o[i])}(this,t,e,r),this}},{key:"bollingerBands",value:function(t,e,r){return function(t,e,r){var n=function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,n=t.length,o={upper:[],middle:[],lower:[]},i=new et(e,r),l=0;l<n;l++){var c={};i.update(t[l]);try{c=i.getResult()}catch(t){c={upper:null,middle:null,lower:null}}o.upper.push(c.upper),o.middle.push(c.middle),o.lower.push(c.lower)}var u=At(t,{upper:o.upper,lower:o.lower});return xt(xt({},o),{},{range:u})}(t.ohlcv.close,e,r);for(var o in n)t.addColumn("bollinger_bands_".concat(o),n[o])}(this,t,e),this}},{key:"rsi",value:function(t,e,r){return function(t,e,r,n){var o=t.ohlcv.close;"number"==typeof e&&void 0===n&&(n=e);var i=It(o,e,r,n);for(var l in i)t.addColumn("".concat(l).toLowerCase(),i[l])}(this,t,e,r),this}},{key:"candles",value:function(){return function(t){var e=t.ohlcv,r=Gt(e);for(var n in r)t.addColumn("candle_".concat(n).toLowerCase(),r[n])}(this),this}},{key:"volumeProfile",value:function(t,e,r){return function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=arguments.length>3?arguments[3]:void 0,o=t.ohlcv,i=function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5,r=t.open,n=t.high,o=t.low,i=t.close,l=t.volume,c=Math.min.apply(Math,Ft(o)),u=(Math.max.apply(Math,Ft(n))-c)/e,a={upVolume:0,downVolume:0,grossVolume:0},s=Array.from({length:e},(function(t,e){return{price:c+u*e,upVolume:0,downVolume:0,grossVolume:0}})),h=1/u,f=0;f<i.length;f++)for(var p=i[f],v=r[f],y=n[f],m=o[f],b=l[f],d=p>=v?b:0,g=p<v?b:0,w=Math.max(0,Math.floor((m-c)*h)),M=Math.min(e,Math.ceil((y-c)*h)),O=w;O<M;O++)s[O].upVolume+=d,s[O].downVolume+=g,s[O].grossVolume+=d+g;for(var S=0,j=s;S<j.length;S++){var P=j[S],E=P.upVolume,_=P.downVolume,k=P.grossVolume;a.upVolume+=E,a.downVolume+=_,a.grossVolume+=k}return{bins:s,nodes:Ht(s)}}(Lt(o,r,n),e),l=i.nodes.high.price,c=i.nodes.low.price;t.addColumn("volume_profile_high",[l]),t.addColumn("volume_profile_low",[c])}(this,t,e,r),this}}],e&&ie(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}()})(),OHLCV_INDICATORS=e})();
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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
|
-
"build": "webpack"
|
|
9
|
+
"build": "npx webpack"
|
|
10
10
|
},
|
|
11
11
|
"author": "https://jaimelias.com/",
|
|
12
12
|
"license": "ISC",
|
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
"trading-signals": "^5.0.4"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@babel/core": "^7.25.2",
|
|
18
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
19
|
+
"@babel/preset-env": "^7.25.3",
|
|
20
|
+
"babel-loader": "^9.1.3",
|
|
17
21
|
"dotenv": "^16.4.5",
|
|
18
|
-
"webpack": "^5.
|
|
22
|
+
"webpack": "^5.93.0",
|
|
19
23
|
"webpack-cli": "^5.1.4"
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -59,11 +59,11 @@ const bollingerBandsRange = (data, bollingerBands) => {
|
|
|
59
59
|
const dataBig = new Big(data[i]);
|
|
60
60
|
|
|
61
61
|
const range = upperBig.minus(lowerBig);
|
|
62
|
-
output[i] = dataBig.minus(lowerBig).div(range).times(100)
|
|
62
|
+
output[i] = dataBig.minus(lowerBig).div(range).times(100)
|
|
63
63
|
} else {
|
|
64
64
|
output[i] = null;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
return output;
|
|
69
69
|
}
|
package/webpack.config.js
CHANGED
|
@@ -1,13 +1,43 @@
|
|
|
1
|
-
import {resolve, dirname } from 'path'
|
|
2
|
-
import { fileURLToPath } from 'url'
|
|
3
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
1
|
+
import { resolve, dirname } from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const entry = './index.js'
|
|
5
|
+
const entry = './index.js';
|
|
7
6
|
const output = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
7
|
+
filename: 'ohlcv-indicators.min.js',
|
|
8
|
+
path: resolve(__dirname, './dist'),
|
|
9
|
+
library: 'OHLCV_INDICATORS'
|
|
10
|
+
};
|
|
12
11
|
|
|
13
|
-
export default {
|
|
12
|
+
export default {
|
|
13
|
+
entry,
|
|
14
|
+
output,
|
|
15
|
+
mode: 'production',
|
|
16
|
+
target: 'web',
|
|
17
|
+
module: {
|
|
18
|
+
rules: [
|
|
19
|
+
{
|
|
20
|
+
test: /\.js$/,
|
|
21
|
+
exclude: /node_modules/,
|
|
22
|
+
use: {
|
|
23
|
+
loader: 'babel-loader',
|
|
24
|
+
options: {
|
|
25
|
+
presets: ['@babel/preset-env'],
|
|
26
|
+
plugins: ['@babel/plugin-proposal-class-properties']
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
test: /\.js$/,
|
|
32
|
+
include: /node_modules\/trading-signals/,
|
|
33
|
+
use: {
|
|
34
|
+
loader: 'babel-loader',
|
|
35
|
+
options: {
|
|
36
|
+
presets: ['@babel/preset-env'],
|
|
37
|
+
plugins: ['@babel/plugin-proposal-class-properties']
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
};
|