ohlcv-indicators 1.1.6 → 1.1.8
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/dist/ohlcv-indicators.min.js +2 -1
- package/dist/ohlcv-indicators.min.js.LICENSE.txt +14 -0
- package/index.js +33 -51
- package/package.json +4 -2
- package/src/moving-averages/bollingerBands.js +43 -46
- package/src/moving-averages/ema.js +20 -49
- package/src/moving-averages/macd.js +12 -13
- package/src/moving-averages/sma.js +21 -30
- package/src/oscillators/rsi.js +16 -49
- package/src/studies/volumeProfile.js +23 -25
- package/src/utilities.js +46 -38
- package/src/moving-averages/ichimokuCloud.js +0 -64
- package/src/moving-averages/relativeVolume.js +0 -19
- package/src/oscillators/mfi.js +0 -62
- package/test/fetchLiveData.js +0 -61
- package/test/test.js +0 -50
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var OHLCV_INDICATORS;(()=>{"use strict";var e={d:(r,n)=>{for(var t in n)e.o(n,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:n[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};(()=>{e.r(r),e.d(r,{default:()=>R});var n=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,t=Math.ceil,i=Math.floor,o="[BigNumber Error] ",s=o+"Number primitive has more than 15 significant digits: ",l=1e14,u=14,c=9007199254740991,f=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],a=1e7,h=1e9;function p(e){var r=0|e;return e>0||e===r?r:r-1}function m(e){for(var r,n,t=1,i=e.length,o=e[0]+"";t<i;){for(r=e[t++]+"",n=u-r.length;n--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function g(e,r){var n,t,i=e.c,o=r.c,s=e.s,l=r.s,u=e.e,c=r.e;if(!s||!l)return null;if(n=i&&!i[0],t=o&&!o[0],n||t)return n?t?0:-l:s;if(s!=l)return s;if(n=s<0,t=u==c,!i||!o)return t?0:!i^n?1:-1;if(!t)return u>c^n?1:-1;for(l=(u=i.length)<(c=o.length)?u:c,s=0;s<l;s++)if(i[s]!=o[s])return i[s]>o[s]^n?1:-1;return u==c?0:u>c^n?1:-1}function d(e,r,n,t){if(e<r||e>n||e!==i(e))throw Error(o+(t||"Argument")+("number"==typeof e?e<r||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function w(e){var r=e.c.length-1;return p(e.e/u)==r&&e.c[r]%2!=0}function v(e,r){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function y(e,r,n){var t,i;if(r<0){for(i=n+".";++r;i+=n);e=i+e}else if(++r>(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else r<t&&(e=e.slice(0,r)+"."+e.slice(r));return e}const b=function e(r){var b,N,O,B,_,E,A,T,C,S,V=F.prototype={constructor:F,toString:null,valueOf:null},L=new F(1),P=20,R=4,x=-7,D=21,I=-1e7,M=1e7,$=!1,U=1,j=0,G={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},k="0123456789abcdefghijklmnopqrstuvwxyz",q=!0;function F(e,r){var t,o,l,f,a,h,p,m,g=this;if(!(g instanceof F))return new F(e,r);if(null==r){if(e&&!0===e._isBigNumber)return g.s=e.s,void(!e.c||e.e>M?g.c=g.e=null:e.e<I?g.c=[g.e=0]:(g.e=e.e,g.c=e.c.slice()));if((h="number"==typeof e)&&0*e==0){if(g.s=1/e<0?(e=-e,-1):1,e===~~e){for(f=0,a=e;a>=10;a/=10,f++);return void(f>M?g.c=g.e=null:(g.e=f,g.c=[e]))}m=String(e)}else{if(!n.test(m=String(e)))return O(g,m,h);g.s=45==m.charCodeAt(0)?(m=m.slice(1),-1):1}(f=m.indexOf("."))>-1&&(m=m.replace(".","")),(a=m.search(/e/i))>0?(f<0&&(f=a),f+=+m.slice(a+1),m=m.substring(0,a)):f<0&&(f=m.length)}else{if(d(r,2,k.length,"Base"),10==r&&q)return X(g=new F(e),P+g.e+1,R);if(m=String(e),h="number"==typeof e){if(0*e!=0)return O(g,m,h,r);if(g.s=1/e<0?(m=m.slice(1),-1):1,F.DEBUG&&m.replace(/^0\.0*|\./,"").length>15)throw Error(s+e)}else g.s=45===m.charCodeAt(0)?(m=m.slice(1),-1):1;for(t=k.slice(0,r),f=a=0,p=m.length;a<p;a++)if(t.indexOf(o=m.charAt(a))<0){if("."==o){if(a>f){f=p;continue}}else if(!l&&(m==m.toUpperCase()&&(m=m.toLowerCase())||m==m.toLowerCase()&&(m=m.toUpperCase()))){l=!0,a=-1,f=0;continue}return O(g,String(e),h,r)}h=!1,(f=(m=N(m,r,10,g.s)).indexOf("."))>-1?m=m.replace(".",""):f=m.length}for(a=0;48===m.charCodeAt(a);a++);for(p=m.length;48===m.charCodeAt(--p););if(m=m.slice(a,++p)){if(p-=a,h&&F.DEBUG&&p>15&&(e>c||e!==i(e)))throw Error(s+g.s*e);if((f=f-a-1)>M)g.c=g.e=null;else if(f<I)g.c=[g.e=0];else{if(g.e=f,g.c=[],a=(f+1)%u,f<0&&(a+=u),a<p){for(a&&g.c.push(+m.slice(0,a)),p-=u;a<p;)g.c.push(+m.slice(a,a+=u));a=u-(m=m.slice(a)).length}else a-=p;for(;a--;m+="0");g.c.push(+m)}}else g.c=[g.e=0]}function H(e,r,n,t){var i,o,s,l,u;if(null==n?n=R:d(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==r)u=m(e.c),u=1==t||2==t&&(s<=x||s>=D)?v(u,s):y(u,s,"0");else if(o=(e=X(new F(e),r,n)).e,l=(u=m(e.c)).length,1==t||2==t&&(r<=o||o<=x)){for(;l<r;u+="0",l++);u=v(u,o)}else if(r-=s,u=y(u,o,"0"),o+1>l){if(--r>0)for(u+=".";r--;u+="0");}else if((r+=o-l)>0)for(o+1==l&&(u+=".");r--;u+="0");return e.s<0&&i?"-"+u:u}function z(e,r){for(var n,t,i=1,o=new F(e[0]);i<e.length;i++)(!(t=new F(e[i])).s||(n=g(o,t))===r||0===n&&o.s===r)&&(o=t);return o}function W(e,r,n){for(var t=1,i=r.length;!r[--i];r.pop());for(i=r[0];i>=10;i/=10,t++);return(n=t+n*u-1)>M?e.c=e.e=null:n<I?e.c=[e.e=0]:(e.e=n,e.c=r),e}function X(e,r,n,o){var s,c,a,h,p,m,g,d=e.c,w=f;if(d){e:{for(s=1,h=d[0];h>=10;h/=10,s++);if((c=r-s)<0)c+=u,a=r,p=d[m=0],g=i(p/w[s-a-1]%10);else if((m=t((c+1)/u))>=d.length){if(!o)break e;for(;d.length<=m;d.push(0));p=g=0,s=1,a=(c%=u)-u+1}else{for(p=h=d[m],s=1;h>=10;h/=10,s++);g=(a=(c%=u)-u+s)<0?0:i(p/w[s-a-1]%10)}if(o=o||r<0||null!=d[m+1]||(a<0?p:p%w[s-a-1]),o=n<4?(g||o)&&(0==n||n==(e.s<0?3:2)):g>5||5==g&&(4==n||o||6==n&&(c>0?a>0?p/w[s-a]:0:d[m-1])%10&1||n==(e.s<0?8:7)),r<1||!d[0])return d.length=0,o?(r-=e.e+1,d[0]=w[(u-r%u)%u],e.e=-r||0):d[0]=e.e=0,e;if(0==c?(d.length=m,h=1,m--):(d.length=m+1,h=w[u-c],d[m]=a>0?i(p/w[s-a]%w[a])*h:0),o)for(;;){if(0==m){for(c=1,a=d[0];a>=10;a/=10,c++);for(a=d[0]+=h,h=1;a>=10;a/=10,h++);c!=h&&(e.e++,d[0]==l&&(d[0]=1));break}if(d[m]+=h,d[m]!=l)break;d[m--]=0,h=1}for(c=d.length;0===d[--c];d.pop());}e.e>M?e.c=e.e=null:e.e<I&&(e.c=[e.e=0])}return e}function Y(e){var r,n=e.e;return null===n?e.toString():(r=m(e.c),r=n<=x||n>=D?v(r,n):y(r,n,"0"),e.s<0?"-"+r:r)}return F.clone=e,F.ROUND_UP=0,F.ROUND_DOWN=1,F.ROUND_CEIL=2,F.ROUND_FLOOR=3,F.ROUND_HALF_UP=4,F.ROUND_HALF_DOWN=5,F.ROUND_HALF_EVEN=6,F.ROUND_HALF_CEIL=7,F.ROUND_HALF_FLOOR=8,F.EUCLID=9,F.config=F.set=function(e){var r,n;if(null!=e){if("object"!=typeof e)throw Error(o+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(d(n=e[r],0,h,r),P=n),e.hasOwnProperty(r="ROUNDING_MODE")&&(d(n=e[r],0,8,r),R=n),e.hasOwnProperty(r="EXPONENTIAL_AT")&&((n=e[r])&&n.pop?(d(n[0],-h,0,r),d(n[1],0,h,r),x=n[0],D=n[1]):(d(n,-h,h,r),x=-(D=n<0?-n:n))),e.hasOwnProperty(r="RANGE"))if((n=e[r])&&n.pop)d(n[0],-h,-1,r),d(n[1],1,h,r),I=n[0],M=n[1];else{if(d(n,-h,h,r),!n)throw Error(o+r+" cannot be zero: "+n);I=-(M=n<0?-n:n)}if(e.hasOwnProperty(r="CRYPTO")){if((n=e[r])!==!!n)throw Error(o+r+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw $=!n,Error(o+"crypto unavailable");$=n}else $=n}if(e.hasOwnProperty(r="MODULO_MODE")&&(d(n=e[r],0,9,r),U=n),e.hasOwnProperty(r="POW_PRECISION")&&(d(n=e[r],0,h,r),j=n),e.hasOwnProperty(r="FORMAT")){if("object"!=typeof(n=e[r]))throw Error(o+r+" not an object: "+n);G=n}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(n=e[r])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(o+r+" invalid: "+n);q="0123456789"==n.slice(0,10),k=n}}return{DECIMAL_PLACES:P,ROUNDING_MODE:R,EXPONENTIAL_AT:[x,D],RANGE:[I,M],CRYPTO:$,MODULO_MODE:U,POW_PRECISION:j,FORMAT:G,ALPHABET:k}},F.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!F.DEBUG)return!0;var r,n,t=e.c,s=e.e,c=e.s;e:if("[object Array]"=={}.toString.call(t)){if((1===c||-1===c)&&s>=-h&&s<=h&&s===i(s)){if(0===t[0]){if(0===s&&1===t.length)return!0;break e}if((r=(s+1)%u)<1&&(r+=u),String(t[0]).length==r){for(r=0;r<t.length;r++)if((n=t[r])<0||n>=l||n!==i(n))break e;if(0!==n)return!0}}}else if(null===t&&null===s&&(null===c||1===c||-1===c))return!0;throw Error(o+"Invalid BigNumber: "+e)},F.maximum=F.max=function(){return z(arguments,-1)},F.minimum=F.min=function(){return z(arguments,1)},F.random=(B=9007199254740992,_=Math.random()*B&2097151?function(){return i(Math.random()*B)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,n,s,l,c,a=0,p=[],m=new F(L);if(null==e?e=P:d(e,0,h),l=t(e/u),$)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(l*=2));a<l;)(c=131072*r[a]+(r[a+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),r[a]=n[0],r[a+1]=n[1]):(p.push(c%1e14),a+=2);a=l/2}else{if(!crypto.randomBytes)throw $=!1,Error(o+"crypto unavailable");for(r=crypto.randomBytes(l*=7);a<l;)(c=281474976710656*(31&r[a])+1099511627776*r[a+1]+4294967296*r[a+2]+16777216*r[a+3]+(r[a+4]<<16)+(r[a+5]<<8)+r[a+6])>=9e15?crypto.randomBytes(7).copy(r,a):(p.push(c%1e14),a+=7);a=l/7}if(!$)for(;a<l;)(c=_())<9e15&&(p[a++]=c%1e14);for(l=p[--a],e%=u,l&&e&&(c=f[u-e],p[a]=i(l/c)*c);0===p[a];p.pop(),a--);if(a<0)p=[s=0];else{for(s=-1;0===p[0];p.splice(0,1),s-=u);for(a=1,c=p[0];c>=10;c/=10,a++);a<u&&(s-=u-a)}return m.e=s,m.c=p,m}),F.sum=function(){for(var e=1,r=arguments,n=new F(r[0]);e<r.length;)n=n.plus(r[e++]);return n},N=function(){var e="0123456789";function r(e,r,n,t){for(var i,o,s=[0],l=0,u=e.length;l<u;){for(o=s.length;o--;s[o]*=r);for(s[0]+=t.indexOf(e.charAt(l++)),i=0;i<s.length;i++)s[i]>n-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(n,t,i,o,s){var l,u,c,f,a,h,p,g,d=n.indexOf("."),w=P,v=R;for(d>=0&&(f=j,j=0,n=n.replace(".",""),h=(g=new F(t)).pow(n.length-d),j=f,g.c=r(y(m(h.c),h.e,"0"),10,i,e),g.e=g.c.length),c=f=(p=r(n,t,i,s?(l=k,e):(l=e,k))).length;0==p[--f];p.pop());if(!p[0])return l.charAt(0);if(d<0?--c:(h.c=p,h.e=c,h.s=o,p=(h=b(h,g,w,v,i)).c,a=h.r,c=h.e),d=p[u=c+w+1],f=i/2,a=a||u<0||null!=p[u+1],a=v<4?(null!=d||a)&&(0==v||v==(h.s<0?3:2)):d>f||d==f&&(4==v||a||6==v&&1&p[u-1]||v==(h.s<0?8:7)),u<1||!p[0])n=a?y(l.charAt(1),-w,l.charAt(0)):l.charAt(0);else{if(p.length=u,a)for(--i;++p[--u]>i;)p[u]=0,u||(++c,p=[1].concat(p));for(f=p.length;!p[--f];);for(d=0,n="";d<=f;n+=l.charAt(p[d++]));n=y(n,c,l.charAt(0))}return n}}(),b=function(){function e(e,r,n){var t,i,o,s,l=0,u=e.length,c=r%a,f=r/a|0;for(e=e.slice();u--;)l=((i=c*(o=e[u]%a)+(t=f*o+(s=e[u]/a|0)*c)%a*a+l)/n|0)+(t/a|0)+f*s,e[u]=i%n;return l&&(e=[l].concat(e)),e}function r(e,r,n,t){var i,o;if(n!=t)o=n>t?1:-1;else for(i=o=0;i<n;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function n(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n]<r[n]?1:0,e[n]=i*t+e[n]-r[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(t,o,s,c,f){var a,h,m,g,d,w,v,y,b,N,O,B,_,E,A,T,C,S=t.s==o.s?1:-1,V=t.c,L=o.c;if(!(V&&V[0]&&L&&L[0]))return new F(t.s&&o.s&&(V?!L||V[0]!=L[0]:L)?V&&0==V[0]||!L?0*S:S/0:NaN);for(b=(y=new F(S)).c=[],S=s+(h=t.e-o.e)+1,f||(f=l,h=p(t.e/u)-p(o.e/u),S=S/u|0),m=0;L[m]==(V[m]||0);m++);if(L[m]>(V[m]||0)&&h--,S<0)b.push(1),g=!0;else{for(E=V.length,T=L.length,m=0,S+=2,(d=i(f/(L[0]+1)))>1&&(L=e(L,d,f),V=e(V,d,f),T=L.length,E=V.length),_=T,O=(N=V.slice(0,T)).length;O<T;N[O++]=0);C=L.slice(),C=[0].concat(C),A=L[0],L[1]>=f/2&&A++;do{if(d=0,(a=r(L,N,T,O))<0){if(B=N[0],T!=O&&(B=B*f+(N[1]||0)),(d=i(B/A))>1)for(d>=f&&(d=f-1),v=(w=e(L,d,f)).length,O=N.length;1==r(w,N,v,O);)d--,n(w,T<v?C:L,v,f),v=w.length,a=1;else 0==d&&(a=d=1),v=(w=L.slice()).length;if(v<O&&(w=[0].concat(w)),n(N,w,O,f),O=N.length,-1==a)for(;r(L,N,T,O)<1;)d++,n(N,T<O?C:L,O,f),O=N.length}else 0===a&&(d++,N=[0]);b[m++]=d,N[0]?N[O++]=V[_]||0:(N=[V[_]],O=1)}while((_++<E||null!=N[0])&&S--);g=null!=N[0],b[0]||b.splice(0,1)}if(f==l){for(m=1,S=b[0];S>=10;S/=10,m++);X(y,s+(y.e=m+h*u-1)+1,c,g)}else y.e=h,y.r=+g;return y}}(),E=/^(-?)0([xbo])(?=\w[\w.]*$)/i,A=/^([^.]+)\.$/,T=/^\.([^.]+)$/,C=/^-?(Infinity|NaN)$/,S=/^\s*\+(?=[\w.])|^\s+|\s+$/g,O=function(e,r,n,t){var i,s=n?r:r.replace(S,"");if(C.test(s))e.s=isNaN(s)?null:s<0?-1:1;else{if(!n&&(s=s.replace(E,(function(e,r,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,t&&t!=i?e:r})),t&&(i=t,s=s.replace(A,"$1").replace(T,"0.$1")),r!=s))return new F(s,i);if(F.DEBUG)throw Error(o+"Not a"+(t?" base "+t:"")+" number: "+r);e.s=null}e.c=e.e=null},V.absoluteValue=V.abs=function(){var e=new F(this);return e.s<0&&(e.s=1),e},V.comparedTo=function(e,r){return g(this,new F(e,r))},V.decimalPlaces=V.dp=function(e,r){var n,t,i,o=this;if(null!=e)return d(e,0,h),null==r?r=R:d(r,0,8),X(new F(o),e+o.e+1,r);if(!(n=o.c))return null;if(t=((i=n.length-1)-p(this.e/u))*u,i=n[i])for(;i%10==0;i/=10,t--);return t<0&&(t=0),t},V.dividedBy=V.div=function(e,r){return b(this,new F(e,r),P,R)},V.dividedToIntegerBy=V.idiv=function(e,r){return b(this,new F(e,r),0,1)},V.exponentiatedBy=V.pow=function(e,r){var n,s,l,c,f,a,h,p,m=this;if((e=new F(e)).c&&!e.isInteger())throw Error(o+"Exponent not an integer: "+Y(e));if(null!=r&&(r=new F(r)),f=e.e>14,!m.c||!m.c[0]||1==m.c[0]&&!m.e&&1==m.c.length||!e.c||!e.c[0])return p=new F(Math.pow(+Y(m),f?e.s*(2-w(e)):+Y(e))),r?p.mod(r):p;if(a=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new F(NaN);(s=!a&&m.isInteger()&&r.isInteger())&&(m=m.mod(r))}else{if(e.e>9&&(m.e>0||m.e<-1||(0==m.e?m.c[0]>1||f&&m.c[1]>=24e7:m.c[0]<8e13||f&&m.c[0]<=9999975e7)))return c=m.s<0&&w(e)?-0:0,m.e>-1&&(c=1/c),new F(a?1/c:c);j&&(c=t(j/u+2))}for(f?(n=new F(.5),a&&(e.s=1),h=w(e)):h=(l=Math.abs(+Y(e)))%2,p=new F(L);;){if(h){if(!(p=p.times(m)).c)break;c?p.c.length>c&&(p.c.length=c):s&&(p=p.mod(r))}if(l){if(0===(l=i(l/2)))break;h=l%2}else if(X(e=e.times(n),e.e+1,1),e.e>14)h=w(e);else{if(0==(l=+Y(e)))break;h=l%2}m=m.times(m),c?m.c&&m.c.length>c&&(m.c.length=c):s&&(m=m.mod(r))}return s?p:(a&&(p=L.div(p)),r?p.mod(r):c?X(p,j,R,void 0):p)},V.integerValue=function(e){var r=new F(this);return null==e?e=R:d(e,0,8),X(r,r.e+1,e)},V.isEqualTo=V.eq=function(e,r){return 0===g(this,new F(e,r))},V.isFinite=function(){return!!this.c},V.isGreaterThan=V.gt=function(e,r){return g(this,new F(e,r))>0},V.isGreaterThanOrEqualTo=V.gte=function(e,r){return 1===(r=g(this,new F(e,r)))||0===r},V.isInteger=function(){return!!this.c&&p(this.e/u)>this.c.length-2},V.isLessThan=V.lt=function(e,r){return g(this,new F(e,r))<0},V.isLessThanOrEqualTo=V.lte=function(e,r){return-1===(r=g(this,new F(e,r)))||0===r},V.isNaN=function(){return!this.s},V.isNegative=function(){return this.s<0},V.isPositive=function(){return this.s>0},V.isZero=function(){return!!this.c&&0==this.c[0]},V.minus=function(e,r){var n,t,i,o,s=this,c=s.s;if(r=(e=new F(e,r)).s,!c||!r)return new F(NaN);if(c!=r)return e.s=-r,s.plus(e);var f=s.e/u,a=e.e/u,h=s.c,m=e.c;if(!f||!a){if(!h||!m)return h?(e.s=-r,e):new F(m?s:NaN);if(!h[0]||!m[0])return m[0]?(e.s=-r,e):new F(h[0]?s:3==R?-0:0)}if(f=p(f),a=p(a),h=h.slice(),c=f-a){for((o=c<0)?(c=-c,i=h):(a=f,i=m),i.reverse(),r=c;r--;i.push(0));i.reverse()}else for(t=(o=(c=h.length)<(r=m.length))?c:r,c=r=0;r<t;r++)if(h[r]!=m[r]){o=h[r]<m[r];break}if(o&&(i=h,h=m,m=i,e.s=-e.s),(r=(t=m.length)-(n=h.length))>0)for(;r--;h[n++]=0);for(r=l-1;t>c;){if(h[--t]<m[t]){for(n=t;n&&!h[--n];h[n]=r);--h[n],h[t]+=l}h[t]-=m[t]}for(;0==h[0];h.splice(0,1),--a);return h[0]?W(e,h,a):(e.s=3==R?-1:1,e.c=[e.e=0],e)},V.modulo=V.mod=function(e,r){var n,t,i=this;return e=new F(e,r),!i.c||!e.s||e.c&&!e.c[0]?new F(NaN):!e.c||i.c&&!i.c[0]?new F(i):(9==U?(t=e.s,e.s=1,n=b(i,e,0,3),e.s=t,n.s*=t):n=b(i,e,0,U),(e=i.minus(n.times(e))).c[0]||1!=U||(e.s=i.s),e)},V.multipliedBy=V.times=function(e,r){var n,t,i,o,s,c,f,h,m,g,d,w,v,y,b,N=this,O=N.c,B=(e=new F(e,r)).c;if(!(O&&B&&O[0]&&B[0]))return!N.s||!e.s||O&&!O[0]&&!B||B&&!B[0]&&!O?e.c=e.e=e.s=null:(e.s*=N.s,O&&B?(e.c=[0],e.e=0):e.c=e.e=null),e;for(t=p(N.e/u)+p(e.e/u),e.s*=N.s,(f=O.length)<(g=B.length)&&(v=O,O=B,B=v,i=f,f=g,g=i),i=f+g,v=[];i--;v.push(0));for(y=l,b=a,i=g;--i>=0;){for(n=0,d=B[i]%b,w=B[i]/b|0,o=i+(s=f);o>i;)n=((h=d*(h=O[--s]%b)+(c=w*h+(m=O[s]/b|0)*d)%b*b+v[o]+n)/y|0)+(c/b|0)+w*m,v[o--]=h%y;v[o]=n}return n?++t:v.splice(0,1),W(e,v,t)},V.negated=function(){var e=new F(this);return e.s=-e.s||null,e},V.plus=function(e,r){var n,t=this,i=t.s;if(r=(e=new F(e,r)).s,!i||!r)return new F(NaN);if(i!=r)return e.s=-r,t.minus(e);var o=t.e/u,s=e.e/u,c=t.c,f=e.c;if(!o||!s){if(!c||!f)return new F(i/0);if(!c[0]||!f[0])return f[0]?e:new F(c[0]?t:0*i)}if(o=p(o),s=p(s),c=c.slice(),i=o-s){for(i>0?(s=o,n=f):(i=-i,n=c),n.reverse();i--;n.push(0));n.reverse()}for((i=c.length)-(r=f.length)<0&&(n=f,f=c,c=n,r=i),i=0;r;)i=(c[--r]=c[r]+f[r]+i)/l|0,c[r]=l===c[r]?0:c[r]%l;return i&&(c=[i].concat(c),++s),W(e,c,s)},V.precision=V.sd=function(e,r){var n,t,i,o=this;if(null!=e&&e!==!!e)return d(e,1,h),null==r?r=R:d(r,0,8),X(new F(o),e,r);if(!(n=o.c))return null;if(t=(i=n.length-1)*u+1,i=n[i]){for(;i%10==0;i/=10,t--);for(i=n[0];i>=10;i/=10,t++);}return e&&o.e+1>t&&(t=o.e+1),t},V.shiftedBy=function(e){return d(e,-9007199254740991,c),this.times("1e"+e)},V.squareRoot=V.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,l=o.s,u=o.e,c=P+4,f=new F("0.5");if(1!==l||!s||!s[0])return new F(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);if(0==(l=Math.sqrt(+Y(o)))||l==1/0?(((r=m(s)).length+u)%2==0&&(r+="0"),l=Math.sqrt(+r),u=p((u+1)/2)-(u<0||u%2),n=new F(r=l==1/0?"5e"+u:(r=l.toExponential()).slice(0,r.indexOf("e")+1)+u)):n=new F(l+""),n.c[0])for((l=(u=n.e)+c)<3&&(l=0);;)if(i=n,n=f.times(i.plus(b(o,i,c,1))),m(i.c).slice(0,l)===(r=m(n.c)).slice(0,l)){if(n.e<u&&--l,"9999"!=(r=r.slice(l-3,l+1))&&(t||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(X(n,n.e+P+2,1),e=!n.times(n).eq(o));break}if(!t&&(X(i,i.e+P+2,0),i.times(i).eq(o))){n=i;break}c+=4,l+=4,t=1}return X(n,n.e+P+1,R,e)},V.toExponential=function(e,r){return null!=e&&(d(e,0,h),e++),H(this,e,r,1)},V.toFixed=function(e,r){return null!=e&&(d(e,0,h),e=e+this.e+1),H(this,e,r)},V.toFormat=function(e,r,n){var t,i=this;if(null==n)null!=e&&r&&"object"==typeof r?(n=r,r=null):e&&"object"==typeof e?(n=e,e=r=null):n=G;else if("object"!=typeof n)throw Error(o+"Argument not an object: "+n);if(t=i.toFixed(e,r),i.c){var s,l=t.split("."),u=+n.groupSize,c=+n.secondaryGroupSize,f=n.groupSeparator||"",a=l[0],h=l[1],p=i.s<0,m=p?a.slice(1):a,g=m.length;if(c&&(s=u,u=c,c=s,g-=s),u>0&&g>0){for(s=g%u||u,a=m.substr(0,s);s<g;s+=u)a+=f+m.substr(s,u);c>0&&(a+=f+m.slice(s)),p&&(a="-"+a)}t=h?a+(n.decimalSeparator||"")+((c=+n.fractionGroupSize)?h.replace(new RegExp("\\d{"+c+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):h):a}return(n.prefix||"")+t+(n.suffix||"")},V.toFraction=function(e){var r,n,t,i,s,l,c,a,h,p,g,d,w=this,v=w.c;if(null!=e&&(!(c=new F(e)).isInteger()&&(c.c||1!==c.s)||c.lt(L)))throw Error(o+"Argument "+(c.isInteger()?"out of range: ":"not an integer: ")+Y(c));if(!v)return new F(w);for(r=new F(L),h=n=new F(L),t=a=new F(L),d=m(v),s=r.e=d.length-w.e-1,r.c[0]=f[(l=s%u)<0?u+l:l],e=!e||c.comparedTo(r)>0?s>0?r:h:c,l=M,M=1/0,c=new F(d),a.c[0]=0;p=b(c,r,0,1),1!=(i=n.plus(p.times(t))).comparedTo(e);)n=t,t=i,h=a.plus(p.times(i=h)),a=i,r=c.minus(p.times(i=r)),c=i;return i=b(e.minus(n),t,0,1),a=a.plus(i.times(h)),n=n.plus(i.times(t)),a.s=h.s=w.s,g=b(h,t,s*=2,R).minus(w).abs().comparedTo(b(a,n,s,R).minus(w).abs())<1?[h,t]:[a,n],M=l,g},V.toNumber=function(){return+Y(this)},V.toPrecision=function(e,r){return null!=e&&d(e,1,h),H(this,e,r,2)},V.toString=function(e){var r,n=this,t=n.s,i=n.e;return null===i?t?(r="Infinity",t<0&&(r="-"+r)):r="NaN":(null==e?r=i<=x||i>=D?v(m(n.c),i):y(m(n.c),i,"0"):10===e&&q?r=y(m((n=X(new F(n),P+i+1,R)).c),n.e,"0"):(d(e,2,k.length,"Base"),r=N(y(m(n.c),i,"0"),10,e,t,!0)),t<0&&n.c[0]&&(r="-"+r)),r},V.valueOf=V.toJSON=function(){return Y(this)},V._isBigNumber=!0,V[Symbol.toStringTag]="BigNumber",V[Symbol.for("nodejs.util.inspect.custom")]=V.valueOf,null!=r&&F.set(r),F}(),N=(e,r,n)=>{const t=e(2/(n+1)),i=r.length,o=[];if(t.isGreaterThan(1))return Array(i);if(t.isEqualTo(1))return[...r];let s=0,l=0;for(;l<i;l++){const e=r[l];if("object"==typeof e){o[l]=e,s=e,l++;break}}if(Array.isArray(t))for(;l<i;l++){const e=r[l];"object"==typeof e&&"object"==typeof t[l]?s=o[l]=t[l].multipliedBy(e).plus(t[l].minus(1).multipliedBy(s)):o[l]=o[l-1]}else{const n=e(1).minus(t);for(;l<i;l++){const e=r[l];s="object"==typeof e?t.multipliedBy(e).plus(n.multipliedBy(s)):o[l-1],o[l]=s}}return o},O=(e,r,n)=>{let t=[],i=e(0),o=[];for(let e=0;e<r.length;e++)o.push(r[e]),i=i.plus(r[e]),o.length>n&&(i=i.minus(o.shift())),e>=n-1?t.push(i.dividedBy(n)):t.push(i.dividedBy(o.length));return t},B=(e,r,n)=>{let t=new Array(r.length).fill(0),i=0;const o=new e(r[0]),s=new e(n[0]);o.isGreaterThan(s)?(i=1,t[0]=1):o.isLessThan(s)?(i=-1,t[0]=-1):(i=0,t[0]=0);for(let o=1;o<r.length;o++){const s=new e(r[o]),l=new e(n[o]),u=new e(r[o-1]),c=new e(n[o-1]);s.isGreaterThan(l)&&u.isLessThanOrEqualTo(c)?(i=1,t[o]=1):s.isLessThan(l)&&u.isGreaterThanOrEqualTo(c)?(i=-1,t[o]=-1):t[o]=1===i?t[o-1]+1:-1===i?t[o-1]-1:0}return t},_=(e,r,n)=>{const t=new e(0),i=r.length,o=O(e,r,n),s=new Array(i).fill(t);for(let e=n-1;e<i;e++){let i=t;for(let t=e-n+1;t<=e;t++)i=i.plus(r[t].minus(o[e]).pow(2));s[e]=i.dividedBy(n).sqrt()}return s},E=(e,r)=>{let{upper:n,lower:t}=r;const i=n.map(((e,r)=>e.minus(t[r])));return e.map(((e,r)=>e.minus(t[r]).dividedBy(i[r]).times(100)))},A=(e,r,n,t)=>r.slice(0,r.length-t+1).map(((i,o)=>{const s=r.slice(o,o+t),l=n.slice(o,o+t);return e.maximum(...s).plus(e.minimum(...l)).dividedBy(2)})),T=(e,r,n,t)=>{const i=e.slice(n).map(((e,n)=>n<r.length?e.plus(r[n]).dividedBy(2):null)).filter((e=>null!==e));return i.slice(0,i.length-t+1)},C=(e,r,n,t,i)=>{let o=r.slice(t).map(((i,o)=>{const s=r.slice(o,o+t),l=n.slice(o,o+t);return e.maximum(...s).plus(e.minimum(...l)).dividedBy(2)}));return o.slice(0,o.length-i+2)},S=(e,r)=>e.slice(0,e.length-r+1),V={getSMA:O,getEMA:N},L=(e,r,n=10,t)=>{const{open:i,high:o,low:s,close:l,volume:u}=r,c=e.min(...s),f=e.max(...o).minus(c).dividedBy(n),a=e(0),h={upVolume:a,downVolume:a,grossVolume:a},p=Array.from({length:n},((e,r)=>({price:c.plus(f.multipliedBy(r)),upVolume:a,downVolume:a,grossVolume:a}))),m=e(1).dividedBy(f);for(let r=0;r<l.length;r++){const t=l[r],f=i[r],h=o[r],g=s[r],d=u[r],w=t.isGreaterThanOrEqualTo(f)?d:a,v=t.isLessThan(f)?d:a,y=Math.max(0,g.minus(c).multipliedBy(m).integerValue(e.ROUND_FLOOR).toNumber()),b=Math.min(n,h.minus(c).multipliedBy(m).integerValue(e.ROUND_CEIL).toNumber());for(let e=y;e<b;e++)p[e].upVolume=p[e].upVolume.plus(w),p[e].downVolume=p[e].downVolume.plus(v),p[e].grossVolume=p[e].grossVolume.plus(w.plus(v))}for(const{upVolume:e,downVolume:r,grossVolume:n}of p)h.upVolume=h.upVolume.plus(e),h.downVolume=h.downVolume.plus(r),h.grossVolume=h.grossVolume.plus(n);return{bins:p,nodes:P(p)}},P=e=>{if(!e||0===e.length)throw new Error("Bins array is empty or not provided");let r=e[0],n=e[0];return e.forEach((e=>{e.grossVolume.isGreaterThan(r.grossVolume)&&(r=e),e.grossVolume.isLessThan(n.grossVolume)&&(n=e)})),{highestVolumeNode:r,lowestVolumeNode:n}};class R{constructor(){this.BigNumber=b,this.VolumeProfile=L}init(e){const{BigNumber:r}=this;return this.ohlcv=e.reduce(((e,{open:n,high:t,low:i,close:o,volume:s,...l})=>{e.open.push(r(n)),e.high.push(r(t)),e.low.push(r(i)),e.close.push(r(o)),e.volume.push(r(s));for(const r of Object.keys(l))e[r]||(e[r]=[]),e[r].push(l[r]);return e}),{open:[],high:[],low:[],close:[],volume:[]}),this}getHeaders(){return Object.keys(this.ohlcv)}getData(){const{BigNumber:e,ohlcv:r}=this,n={};for(const[t,i]of Object.entries(r))n[t]=i.map((r=>e.isBigNumber(r)?r.toNumber():r));return n}getLastValues(){const e={};for(const[r,n]of Object.entries(this.ohlcv)){let t=n[n.length-1];e[r]=b.isBigNumber(t)?t.toNumber():t}return e}addColumn(e,r){const n=this.ohlcv.open.length;if(r.length>n)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");r=[...new Array(n-r.length).fill(NaN),...r],this.ohlcv[e]=r}crossPairs(e){const r=this.ohlcv,n={},t=e=>{if(!r.hasOwnProperty(e)&&"string"==typeof e){const[r,...n]=e.split("_");this[r.toUpperCase()]&&n.length>0&&this[r.toUpperCase()](...n)}};for(const{fast:i,slow:o}of e)if(i&&o)if(t(i),t(o),"number"!=typeof o||n[o]||(n[o]=r.close.map((()=>o))),r[i]&&r[o]){const e=B(this.BigNumber,r[i],r[o]);this.addColumn(`${i}_x_${o}`,e)}else if(r[i]&&n[o]){const e=B(this.BigNumber,r[i],n[o]);this.addColumn(`${i}_x_${o}`,e)}else console.error(`Missing ohlcv properties for ${i} or ${o}`)}EMA(e){return((e,r)=>{const{ohlcv:n}=e,t=n.close,i=N(e.BigNumber,t,r);e.addColumn(`ema_${r}`,i)})(this,e),this}SMA(e){return((e,r)=>{const{ohlcv:n}=e,t=n.close,i=O(e.BigNumber,t,r);e.addColumn(`sma_${r}`,i)})(this,e),this}MACD(e,r,n){return((e,r=12,n=26,t=9)=>{const{ohlcv:i}=e,o=i.close,s=((e,r,n=12,t=26,i=9)=>{const o=N(e,r,n),s=N(e,r,t),l=o.map(((e,r)=>e.minus(s[r]))),u=N(e,l,i),c=l.map(((e,r)=>e.minus(u[r]))),f=B(e,l,u);return{macd_diff:l,macd_dea:u,macd_histogram:c,macd_diff_x_macd_dea:f}})(e.BigNumber,o,r,n,t);for(let r in s)e.addColumn(r,s[r])})(this,e,r,n),this}BollingerBands(e,r,n){return((e,r,n)=>{const{ohlcv:t}=e,i=t.close,o=((e,r,n=20,t=2)=>{t=new e(t);const i=O(e,r,n),o=_(e,r,n).map((e=>e.times(t)));let s=i.map(((e,r)=>e.plus(o[r]))),l=i,u=i.map(((e,r)=>e.minus(o[r])));return{upper:s,mid:l,lower:u,range:E(r,{upper:s,lower:u})}})(e.BigNumber,i,r,n);for(let r in o)e.addColumn(`bollinger_bands_${r}`,o[r])})(this,e,r),this}IchimokuCloud(e,r,n){return((e,r,n,t)=>{const{ohlcv:i}=e,o=((e,r,n=9,t=26,i=52)=>{const o=n,s=t,l=s-o,u=i,{high:c,low:f,close:a}=r,h=A(e,c,f,o),p=A(e,c,f,s);return{conversion_line:h,base_line:p,leading_span_a:T(h,p,l,s),leading_span_b:C(e,c,f,u,s),lagging_span:S(a,s)}})(e.BigNumber,i,r,n,t);for(let r in o)e.addColumn(`ichimoku_${r}`,o[r])})(this,e,r,n),this}RSI(e,r,n){return((e,r,n,t)=>{const{ohlcv:i}=e,o=i.close,s=((e,r,n=14,t="SMA",i=14)=>{if(r.length<n)return[];const o=new e(0),s=new e(100),l=new e(1);let u=[],c=o,f=o;for(let t=1;t<=n;t++){const n=new e(r[t]),i=new e(r[t-1]),s=n.minus(i);s.isLessThan(o)?f=f.plus(s.abs()):c=c.plus(s)}let a=c.dividedBy(n),h=f.dividedBy(n),p=h.isEqualTo(o)?o:a.dividedBy(h);u.push(s.minus(s.dividedBy(l.plus(p))));for(let t=n+1;t<r.length;t++){const i=new e(r[t]),m=new e(r[t-1]),g=i.minus(m);g.isLessThan(o)?(f=g.abs(),c=o):(c=g,f=o),a=a.times(n-1).plus(c).dividedBy(n),h=h.times(n-1).plus(f).dividedBy(n),p=h.isEqualTo(o)?o:a.dividedBy(h),u.push(s.minus(s.dividedBy(l.plus(p))))}let m={[`rsi_${n}`]:u};if("string"==typeof t&&"number"==typeof i&&V.hasOwnProperty(`get${t}`)){const r=V[`get${t}`](e,u,i);m[`rsi_${t}_${i}`]=r,m[`rsi_${n}_x_rsi_${t}_${i}`]=B(e,u,r)}return m})(e.BigNumber,o,r,n,t);for(let r in s)e.addColumn(`${r}`.toLowerCase(),s[r])})(this,e,r,n),this}MFI(e){return((e,r=14)=>{const{ohlcv:n}=e,t=((e,r,n=14)=>{const{high:t,low:i,close:o,volume:s}=r,l=e(0),u=e(100),c=e(1),f=[],a=[],h=[],p=[],m=[],g=[];for(let e=0;e<o.length;e++){const r=t[e].plus(i[e]).plus(o[e]).dividedBy(3),n=r.times(s[e]);f.push(r),a.push(n)}for(let e=1;e<f.length;e++)f[e].isGreaterThan(f[e-1])?(h.push(a[e]),p.push(l)):f[e].isLessThan(f[e-1])?(h.push(l),p.push(a[e])):(h.push(l),p.push(l));for(let e=n;e<=h.length;e++){const r=h.slice(e-n,e),t=p.slice(e-n,e),i=r.reduce(((e,r)=>e.plus(r)),l),o=t.reduce(((e,r)=>e.plus(r)),l),s=i.dividedBy(o);m.push(s)}for(let e=0;e<m.length;e++){const r=u.minus(u.dividedBy(c.plus(m[e])));g.push(r)}return g})(e.BigNumber,n,r);e.addColumn(`mfi_${r}`,t)})(this,e),this}RelativeVolume(e){return((e,r)=>{const{ohlcv:n}=e,t=n.volume,i=((e,r,n=10)=>{const t=O(e,r,n);return r.map(((e,r)=>0!==r&&t[r-2]?t[r-2].isZero()?NaN:e.dividedBy(t[r-2]):NaN)).filter((e=>!Number.isNaN(e)))})(e.BigNumber,t,r);e.addColumn(`relative_volume_${r}`,i)})(this,e),this}}})(),OHLCV_INDICATORS=r})();
|
|
1
|
+
/*! For license information please see ohlcv-indicators.min.js.LICENSE.txt */
|
|
2
|
+
var OHLCV_INDICATORS;(()=>{var t={978:function(t,i){!function(t){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(t,e)},e=function(){return(e=Object.assign||function(t){for(var i,e=arguments,s=1,n=arguments.length;s<n;s++)for(var r in i=e[s])Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r]);return t}).apply(this,arguments)};function s(){for(var t=arguments,i=0,e=0,s=arguments.length;e<s;e++)i+=t[e].length;var n=Array(i),r=0;for(e=0;e<s;e++)for(var o=arguments[e],h=0,a=o.length;h<a;h++,r++)n[r]=o[h];return n}var n=function(){function t(t,i,e,s,n,r){void 0===r&&(r=null),this.forked=!1,this.forkedAt=0,this.lastForkY=null,this.step=s,this.index=n,this.length=0,this.startPoint=r?{y:t?r.h:r.l,x:r.x}:{y:t||i,x:e},this.init(t,i,e),this.thisPoint=this.startPoint}return t.prototype.init=function(t,i,e){this.type||(this.type=t?"h":"l"),this.candlePoint={y:"h"==this.type?t:i,x:e},this.thisPoint&&(this.prevPoint=this.thisPoint,this.nextPoint&&(this.thisPoint=this.nextPoint),this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step})},t.prototype.update=function(t,i,e){var s=null;if(this.length++,this.init(t,i,e),this.k&&!isNaN(this.k)||(this.k=(this.candlePoint.y-this.startPoint.y)/(this.candlePoint.x-this.startPoint.x),this.b=this.candlePoint.y-this.k*this.candlePoint.x,this.prevPoint=this.startPoint,this.thisPoint=this.candlePoint,this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step},s={condition:"h"==this.type?"lt":"gt",value:this.nextPoint.y,action:"fork",lineIndex:this.index}),"h"==this.type&&this.thisPoint.y<=this.candlePoint.y||"l"==this.type&&this.thisPoint.y>=this.candlePoint.y){this.k=(this.candlePoint.y-this.startPoint.y)/(this.candlePoint.x-this.startPoint.x),this.b=this.candlePoint.y-this.k*this.candlePoint.x,this.thisPoint=this.candlePoint,this.length=0,this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step};var n=this.rollback?this.rollback.length:0,r=this.candlePoint.y-this.prevPoint.y;("h"==this.type?r>0:r<0)?(this.rollback={k:r,b:this.candlePoint.y-r*this.candlePoint.x,length:n+1,lastForkTime:this.forkedAt||(this.rollback?this.rollback.lastForkTime:0),lastForkValue:this.forkedValue||(this.rollback?this.rollback.lastForkValue:0)},this.forked=!1,this.forkedAt=null,this.forkedValue=null):(this.forkedAt=this.candlePoint.x,this.forkedValue=this.candlePoint.y,this.forked=!0,this.rollback=null),s={condition:"h"==this.type?"lt":"gt",value:this.nextPoint.y,action:"fork",lineIndex:this.index}}else this.rollback=null;return s},t.prototype.updateStep=function(t){this.step=t},t}(),r=function(){function t(t){this.lineIndex=0,this.forkDiffH=null,this.forkDiffL=null,this.step=t,this.list=[[],[]],this.id={}}return t.prototype.add=function(t,i,e,s,r){void 0===s&&(s=null),void 0===r&&(r=null);var o,h,a,l=null;if(null==r?(o=this.lineIndex,this.lineIndex++,null!=t?this.list[0].push(o):this.list[1].push(o)):(o=r,l=this.id[o].lastForkY||(null!=t?s.h:s.l)),this.id[o]=new n(t,i,e,this.step,o,s),l&&(this.id[o].lastForkY=l),o>1||null!=r&&null!=this.id[r]){h=null!=r?r:this.list["h"==this.id[o].type?0:1][this.list["h"==this.id[o].type?0:1].indexOf(o)-1],a=null!=r?r:this.list["h"==this.id[o].type?0:1][this.list["h"==this.id[o].type?0:1].indexOf(o)-2];var u=this.id[h].lastForkY;a&&!u&&(u=this.id[a].lastForkY);var p=null!=t?s.h:s.l;u&&(t?this.forkDiffH=u>=p?-h-1:h+1:this.forkDiffL=u>=p?-h-1:h+1),this.id[h].lastForkY=p}return o},t.prototype.update=function(t,i,e,s){return this.id[t].update(i,e,s)},t.prototype.delete=function(t){this.id[t]&&("h"==this.id[t].type?this.list[0].splice(this.list[0].indexOf(t),1):this.list[1].splice(this.list[1].indexOf(t),1),delete this.id[t])},t}(),o=function(){function t(t,i){this.kdiff=[],this.env=i,this.lines=t,this.in={state:null,lineIndex:null,line:null},this.is={state:null,lineIndex:null,line:null,start:null,size:0},this.was={state:null,lineIndex:null,line:null,size:null},this.width=0,this.speed=0,this.at=0}return t.prototype.update=function(t,i){var s=this;if(t.length>1?this.hlMaxDuration=t.map((function(t){return s.lines.id[t]})).filter((function(t){return!s.is.line||(t.forkedAt?t.forkedAt>s.is.line.startPoint.x:!!t.rollback&&t.rollback.lastForkTime>s.is.line.startPoint.x)})).reduce((function(t,i){return t.length>i.length?t:i}),this.lines.id[t[0]]):this.hlMaxDuration=this.lines.id[t[0]],i.length>1?this.llMaxDuration=i.map((function(t){return s.lines.id[t]})).filter((function(t){return!s.is.line||(t.forkedAt?t.forkedAt>s.is.line.startPoint.x:!!t.rollback&&t.rollback.lastForkTime>s.is.line.startPoint.x)})).reduce((function(t,i){return t.length>i.length?t:i}),this.lines.id[i[0]]):this.llMaxDuration=this.lines.id[i[0]],null==this.is.state&&null==this.was.state&&(this.is.line=this.llMaxDuration&&this.llMaxDuration.length>this.env.minLength&&this.hlMaxDuration.length<this.env.minLength?this.llMaxDuration:this.hlMaxDuration&&this.hlMaxDuration.length>this.env.minLength&&this.llMaxDuration.length<this.env.minLength?this.hlMaxDuration:null,this.is.line&&(this.is.lineIndex=this.is.line.index,this.is.state="h"==this.is.line.type?"fall":"rise",this.is.start=this.is.line.candlePoint)),this.is.state){this.is.size=Math.max(this.is.size,Math.abs(this.is.start.y-this.is.line.candlePoint.y));var n,r=this.lines.id[this.is.lineIndex]||this.lines.id["h"==this.is.line.type?0:1],o=null,h=null,a=this.lines.list["h"==r.type?1:0].filter((function(t){return s.lines.id[t].forked&&s.lines.id[t].thisPoint.x-s.lines.id[t].forkedAt>12}));a.length>1?a[1]:a.length>0&&a[0];var l=a.filter((function(t){return s.lines.id[t].forkedAt>s.is.start.x}));if(r&&this.lines.list["h"==r.type?0:1].forEach((function(t,i){var e=s.lines.id[t];if(t>=r.index&&null!=e.rollback){n=s.lines.list["h"==r.type?0:1][i-1];var a=1==s.env.deltaModel&&i>1&&n&&s.lines.id[n]?i>1&&n&&s.lines.id[n].lastForkY:s.lines.id[t>0?t-1:0];h=a?s.lines.id[t>1?n:"h"==r.type?0:1].lastForkY-e.candlePoint.y:e.rollback?e.rollback.lastForkValue-e.candlePoint.y:0,e.rollback.lastForkValue>0&&e.thisPoint.x-e.rollback.lastForkTime>s.env.minRightLeg&&("fall"==s.is.state?s.llMaxDuration.length>1:s.hlMaxDuration.length>1)&&(("h"==r.type?h<0:h>0)||e.rollback.length>s.env.rollbackLength||2*s.is.size/3>Math.abs(s.is.start.y-s.is.line.candlePoint.y)&&s.is.size>s.is.line.candlePoint.y*s.env.minIsSizeOnRollback&&l.length>1||("h"==r.type?e.candlePoint.y>s.is.start.y&&1==s.lines.list[0].length:e.candlePoint.y<s.is.start.y&&1==s.lines.list[1].length))&&(e.candlePoint.x-e.rollback.lastForkTime>s.env.forkDurationMin&&e.candlePoint.x-e.rollback.lastForkTime<s.env.forkDurationMax||("h"==r.type?e.candlePoint.y>e.startPoint.y:e.candlePoint.y<e.startPoint.y)||("h"==r.type?e.candlePoint.y>s.is.start.y&&1==s.lines.list[0].length:e.candlePoint.y<s.is.start.y&&1==s.lines.list[1].length))&&(o=t+1)}})),o){this.in.size=(this.was.size||0)+this.is.size;var u=this.lines.id[0].candlePoint.y-this.is.start.y,p="rise"==this.is.state?u>=0:u<0;this.was.size&&(this.in.state=this.was.size>this.is.size?this.was.state:this.is.state),this.was=e({},this.is),this.was.success=p,this.is.line="fall"==this.is.state?this.llMaxDuration:this.hlMaxDuration,this.is.state="h"==this.is.line.type?"fall":"rise",this.is.lineIndex=this.is.line.index,this.is.start=this.lines.id[0].candlePoint,this.is.size=0}}},t}(),h=function(){function t(t){this.hLineDirectives=[],this.lLineDirectives=[],this.step=1,this.i=0,this.localCounter=0,this.prevPoint=null,this.env=Object.assign({step:1,minLength:5,minRightLeg:3,maxForks:500,minLog:0,maxLog:0,rollbackLength:3,deltaModel:1,minIsSizeOnRollback:.05},t),this.env.minLength=Math.round(this.env.minLength/this.env.step)||1,this.env.minRightLeg=Math.round(this.env.minRightLeg/this.env.step)||1,this.env.rollbackLength=Math.round(this.env.rollbackLength/this.env.step)||1,this.env.forkDurationMin=Math.round(this.env.forkDurationMin/this.env.step)||1,this.env.forkDurationMax=Math.round(this.env.forkDurationMax/this.env.step)||1,this.lines=new r(this.step),this.trend=new o(this.lines,this.env)}return t.prototype.log=function(t){for(var i=arguments,e=[],n=1;n<arguments.length;n++)e[n-1]=i[n];this.consoleWindow=this.env.minLog<this.localCounter&&this.localCounter<this.env.maxLog,this.consoleWindow&&console.log.apply(console,s([t],e))},t.prototype.nextValue=function(t,i,e,s){var n,r=this;this.localCounter++,this.lLineDirectives.length>0&&this.lLineDirectives.forEach((function(t,i){var e=r.lines.id[t.lineIndex];"gt"==t.condition&&s>t.value&&"fork"==t.action&&e&&(null!=t.lineIndex&&null!=e&&e.k<0?r.lines.add(null,s,r.i-1,r.prevPoint,t.lineIndex):(e.forked=!0,e.forkedAt=e.thisPoint.x,e.forkedValue=e.thisPoint.y,r.lines.add(null,s,r.i-1,r.prevPoint)))})),this.hLineDirectives.length>0&&this.hLineDirectives.forEach((function(t,i){var s=r.lines.id[t.lineIndex];"lt"==t.condition&&e<t.value&&"fork"==t.action&&s&&(s.k>0?r.lines.add(e,null,r.i-1,r.prevPoint,t.lineIndex):(s.forked=!0,s.forkedAt=s.thisPoint.x,s.forkedValue=s.thisPoint.y,r.lines.add(e,null,r.i-1,r.prevPoint)))})),this.hLineDirectives.length=0,this.lLineDirectives.length=0,this.lines.list[0].length<1?(this.lines.add(e,null,this.i),this.lines.add(null,s,this.i)):this.lines.list.forEach((function(t){return t.forEach((function(t){var i=r.lines.id[t];if(i&&i.type){n=null,i&&i.startPoint.x<r.i&&(n=r.lines.update(t,e,s,r.i));var o=i.type;n&&("h"==o?r.hLineDirectives.push(n):r.lLineDirectives.push(n))}}))}));var o=[];return this.lines.list.forEach((function(t){t&&(o=[],t.forEach((function(i,e){var s=r.lines.id[t[e]],n=r.lines.id[t[e-1]];(e>0&&s&&n&&"h"==s.type&&s.thisPoint&&n.thisPoint.y<=s.thisPoint.y||e>r.env.maxForks||e>0&&s&&n&&"l"==s.type&&s.thisPoint&&n.thisPoint.y>=s.thisPoint.y||e>r.env.maxForks)&&o.push(i)})),o.forEach((function(t){return r.lines.delete(t)})))})),this.prevPoint={x:this.i,h:e,l:s},this.trend.update(this.lines.list[0],this.lines.list[1]),this.i++,this.lines},t}(),a=Object.freeze({__proto__:null,Indicator:h}),l=function(){function t(t){this.length=t,this.filled=!1,this.pointer=0,this.buffer=new Array(t),this.maxIndex=t-1}return t.prototype.push=function(t){var i=this.buffer[this.pointer];return this.buffer[this.pointer]=t,this.iteratorNext(),i},t.prototype.pushback=function(t){this.iteratorPrev();var i=this.buffer[this.pointer];return this.buffer[this.pointer]=t,i},t.prototype.peek=function(){return this.buffer[this.pointer]},t.prototype.forEach=function(t){for(var i=this.pointer,e=0;e!==this.length;)t(this.buffer[i],e),i=(this.length+i+1)%this.length,e++},t.prototype.forEachRight=function(t){for(var i=(this.length+this.pointer-1)%this.length,e=this.length-1;e!==this.length;)t(this.buffer[i],e),i=(this.length+i-1)%this.length,e--},t.prototype.fill=function(t){this.buffer.fill(t),this.filled=!0},t.prototype.toArray=function(){return this.buffer},t.prototype.iteratorNext=function(){this.pointer++,this.pointer>this.maxIndex&&(this.pointer=0,this.filled=!0)},t.prototype.iteratorPrev=function(){this.pointer--,this.pointer<0&&(this.pointer=this.maxIndex)},t}(),u=function(t){function e(i,e){void 0===i&&(i=100);var s=t.call(this,i)||this;return s.period=i,s.mode=e,s.comparator="max"===e?s.maxComporator:s.mminComporator,s}return function(t,e){function s(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}(e,t),e.prototype.nextValue=function(t){return this.push(t),this.getExtremum()},e.prototype.momentValue=function(t){var i=this.push(t),e=this.getExtremum();return this.pushback(i),e},e.prototype.maxComporator=function(t,i){return t>i},e.prototype.mminComporator=function(t,i){return t<i},e.prototype.getExtremum=function(t){var i=(this.length+this.pointer-2)%this.length,e="max"===this.mode?-1/0:1/0;if(!this.filled)return 0;for(;i!==this.pointer;){var s=this.buffer[(this.length+i-1)%this.length],n=this.buffer[(this.length+i+1)%this.length],r=this.buffer[i];if(this.comparator(r,e)&&this.comparator(r,s)&&this.comparator(r,n)){if(e=r,this.prevIx===i)return null;if(this.prevIx=i,t)return e}i=(this.length+i-1)%this.length}return isFinite(e)?e:(this.prevIx=null,null)},e}(l),p=function(){function t(t){this.period=t,this.sum=0,this.circular=new l(t)}return t.prototype.nextValue=function(t){var i=this;if(this.circular.push(t),this.sum+=t,this.circular.filled)return this.nextValue=function(t){return i.sum=i.sum-i.circular.push(t)+t,i.sum/i.period},this.momentValue=function(t){return(i.sum-i.circular.peek()+t)/i.period},this.sum/this.period},t.prototype.momentValue=function(t){},t}(),c=function(){function t(t){this.period=t,this.smooth=1/this.period,this.sma=new p(this.period)}return t.prototype.nextValue=function(t){return this.wema?this.wema=(t-this.wema)*this.smooth+this.wema:this.wema=this.sma.nextValue(t)},t.prototype.momentValue=function(t){return this.wema?(t-this.wema)*this.smooth+this.wema:this.sma.momentValue(t)},t}(),f=function(){function t(t){this.period=t,this.smooth=2/(this.period+1),this.sma=new p(this.period)}return t.prototype.nextValue=function(t){var i=this,e=this.sma.nextValue(t);return e&&(this.ema=e,this.nextValue=function(t){return i.ema=(t-i.ema)*i.smooth+i.ema},this.momentValue=function(t){return(t-i.ema)*i.smooth+i.ema}),e},t.prototype.momentValue=function(t){},t}(),d=function(){function t(t,i){this.indicator=t,this.samples=i,this._indicators=[]}return t.prototype.create=function(){for(var t,i=arguments,e=[],n=0;n<arguments.length;n++)e[n]=i[n];for(var r=0;r<this.samples;r++)this._indicators.push(new((t=this.indicator).bind.apply(t,s([void 0],e))))},t.prototype.nextValue=function(t){for(var i=0;i<this.samples;i++)if(void 0===(t=this._indicators[i].nextValue(t)))return t;return t},t.prototype.momentValue=function(t){for(var i=0;i<this.samples;i++)if(null==(t=this._indicators[i].momentValue(t)))return t;return t},t}(),m=function(){function t(t,i,e,s,n){void 0===t&&(t=.85),void 0===s&&(s=1),void 0===n&&(n=1),this.redunant=t,this.multiplier=s,this.offset=n,this.prevValue=0,this.lastUpperValue=0,this.lastLowerValue=0,this.samplerUp=new d(i,e),this.samplerLow=new d(i,e)}return t.prototype.create=function(){for(var t,i,e=arguments,s=[],n=0;n<arguments.length;n++)s[n]=e[n];(t=this.samplerUp).create.apply(t,s),(i=this.samplerLow).create.apply(i,s)},t.prototype.nextValue=function(t){this.lastUpperValue=t>0?Math.max(t,this.prevValue):Math.max(0,this.lastUpperValue)*this.redunant,this.lastLowerValue=t<=0?Math.min(t,this.prevValue):Math.min(0,this.lastLowerValue)*this.redunant;var i=(t<=0?t:this.lastLowerValue)*this.multiplier,e=(t>=0?t:this.lastUpperValue)*this.multiplier;return[this.samplerUp.nextValue(e)+this.offset,this.samplerLow.nextValue(i)-this.offset]},t}(),v=function(){function t(t,i,e,s){void 0===e&&(e=.85),void 0===s&&(s="WEMA"),this.period=t,this.samples=i,this.redunant=e,this.type=s,this.upper=0,this.lower=0,this.lastUpperValue=0,this.lastLowerValue=0,this.sample1Up=this.createSample(),this.sample2Up=this.createSample(),this.sample3Up=this.createSample(),this.sample1Low=this.createSample(),this.sample2Low=this.createSample(),this.sample3Low=this.createSample()}return t.prototype.nextValue=function(t){return t>0?(this.upper=this.getUp(t),this.lastLowerValue*=this.redunant,this.lower=this.getDown(this.lastLowerValue),this.lastUpperValue=t):t<0&&(this.lower=this.getDown(t),this.lastUpperValue*=this.redunant,this.upper=this.getUp(this.lastUpperValue),this.lastLowerValue=t),{upper:this.upper,lower:this.lower}},t.prototype.getUp=function(t){var i=this.sample1Up.nextValue(t),e=null;return 1===this.samples?i:(i&&(e=this.sample2Up.nextValue(i)),2===this.samples?e:e?this.sample3Up.nextValue(e):null)},t.prototype.getDown=function(t){var i=this.sample1Low.nextValue(t),e=null;return 1===this.samples?i:(i&&(e=this.sample2Low.nextValue(i)),2===this.samples?e:e?this.sample3Low.nextValue(e):null)},t.prototype.createSample=function(){switch(this.type){case"EMA":return new f(this.period);case"WEMA":return new c(this.period);case"SMA":return new p(this.period)}},t}(),V=function(){function t(t){this.period=t,this.SMAx=new p(this.period),this.SMAy=new p(this.period),this.pricesX=new l(this.period),this.pricesY=new l(this.period)}return t.prototype.nextValue=function(t,i){this.pricesX.push(t),this.pricesY.push(i),this.SMAxValue=this.SMAx.nextValue(t),this.SMAyValue=this.SMAy.nextValue(i);for(var e=0,s=0,n=0,r=0;r<this.period;r++){var o=this.pricesX.toArray()[r],h=this.pricesY.toArray()[r];e+=(o-this.SMAxValue)*(h-this.SMAyValue),s+=Math.pow(o-this.SMAxValue,2),n+=Math.pow(h-this.SMAyValue,2)}return e/Math.sqrt(s*n)},t}(),w=function(){function t(t){this.period=t,this.denominator=t*(t+1)/2,this.buffer=new l(t),this.values=[]}return t.prototype.nextValue=function(t){var i=this;if(this.buffer.push(t),this.buffer.filled){var e=0;return this.buffer.forEach((function(t,s){e+=t*(s+1)/i.denominator})),e}},t.prototype.momentValue=function(t){var i=this,e=this.buffer.push(t);if(this.buffer.filled){var s=0;return this.buffer.forEach((function(t,e){s+=t*(e+1)/i.denominator})),this.buffer.pushback(e),s}this.buffer.pushback(e)},t}(),x=function(){function t(t){void 0===t&&(t=.2),this.alpha=t,this.filled=!1}return t.prototype.nextValue=function(t){var i=this.alpha*t+(1-this.alpha)*(this.prevValue||1);if(this.filled=this.filled||void 0!==this.prevValue,this.prevValue=i,this.filled)return i},t.prototype.momentValue=function(t){if(this.filled)return this.alpha*t+(1-this.alpha)*(this.prevValue||1)},t}(),y=function(){function t(t){this.period=t,this.sum=0,this.avg=0,this.filled=!1,this.fill=0}return t.prototype.nextValue=function(t){var i=this;return this.filled?(this.nextValue=function(t){return i.avg=(i.avg*(i.period-1)+t)/i.period},this.nextValue(t)):(this.sum+=t,this.fill++,this.fill===this.period?(this.filled=!0,this.avg=this.sum/this.period,this.avg):void 0)},t.prototype.momentValue=function(t){if(this.filled)return(this.avg*(this.period-1)+t)/this.period},t}(),g=function(){function t(t){void 0===t&&(t=14),this.period=t,this.alpha=1/t,this.sma=new p(this.period)}return t.prototype.nextValue=function(t){var i=this;return this.prevValue?(this.prevValue=this.alpha*t+(1-this.alpha)*this.prevValue,this.nextValue=function(t){return i.prevValue=i.alpha*t+(1-i.alpha)*i.prevValue,i.prevValue}):this.prevValue=this.sma.nextValue(t),this.prevValue},t.prototype.momentValue=function(t){if(this.prevValue)return this.alpha*t+(1-this.alpha)*this.prevValue},t}(),P=function(){function t(t,i){void 0===t&&(t=5),void 0===i&&(i=34),this.smaSlow=new p(i),this.smaFast=new p(t)}return t.prototype.nextValue=function(t,i){var e=this;if(this.smaSlowValue=this.smaSlow.nextValue((t+i)/2),this.smaFastValue=this.smaFast.nextValue((t+i)/2),void 0!==this.smaSlowValue&&void 0!==this.smaFastValue)return this.nextValue=function(t,i){return e.smaSlowValue=e.smaSlow.nextValue((t+i)/2),e.smaFastValue=e.smaFast.nextValue((t+i)/2),e.smaFastValue-e.smaSlowValue},this.momentValue=function(t,i){return e.smaFast.momentValue((t+i)/2)-e.smaSlow.momentValue((t+i)/2)},this.smaFastValue-this.smaSlowValue},t.prototype.momentValue=function(t,i){},t}(),k=function(){function t(){this.sma=new p(5),this.ao=new P}return t.prototype.nextValue=function(t,i){var e=this;if(this.aoValue=this.ao.nextValue(t,i),void 0!==this.aoValue&&(this.smaValue=this.sma.nextValue(this.aoValue),void 0!==this.smaValue))return this.nextValue=function(t,i){return e.aoValue=e.ao.nextValue(t,i),e.smaValue=e.sma.nextValue(e.aoValue),e.aoValue-e.smaValue},this.momentValue=function(t,i){return e.ao.momentValue(t,i)-e.sma.momentValue(e.aoValue)},this.aoValue-this.smaValue},t.prototype.momentValue=function(t,i){},t}(),b=function(t,i){return(t-i)/i*100},M=function(){function t(t){this.period=t,this.value=0,this.changes=new l(t)}return t.prototype.nextValue=function(t){if(this.prevPrice){var i=b(t,this.prevPrice);return this.calculate(i),this.prevPrice=t,this.value}this.prevPrice=t},t.prototype.calculate=function(t){return this.value+=t,this.value-=this.changes.push(t),this.value},t}();function A(t){return t.consolidate=0,t.power=0,t.streak=0,t.diff=0,t.startPrice=0,t.prevPeak=0,t}var L=function(){function t(){this.up={consolidate:0,power:0,streak:0,startPrice:0,diff:0,prevPeak:0},this.down={consolidate:0,power:0,streak:0,startPrice:0,diff:0,prevPeak:0}}return t.prototype.nextValue=function(t,i,s,n){if(t<i||this.up.streak&&this.up.prevPeak<n){this.up.startPrice||(this.up.startPrice=t),this.down.streak&&A(this.down);var r=i-t;this.up.streak++,this.up.prevPeak=n,this.up.diff>r?this.up.consolidate++:this.up.consolidate=0,this.up.diff=r,this.up.power=b(i,this.up.startPrice)}return(t>i||this.down.streak&&this.down.prevPeak>s)&&(this.down.startPrice||(this.down.startPrice=t),this.up.streak&&A(this.up),r=t-i,this.down.streak++,this.down.prevPeak=s,this.down.diff>r?this.down.consolidate++:this.down.consolidate=0,this.down.diff=r,this.down.power=b(i,this.down.startPrice)),t===i&&(this.up.streak++,this.down.streak++,this.up.diff=this.down.diff=0),this.up.streak>this.down.streak?e({},this.up):e({},this.down)},t}(),S=function(){function t(t){this.max=-1/0,this.highest=new l(t)}return t.prototype.filled=function(){return this.highest.filled},t.prototype.nextValue=function(t){return this.max<t&&(this.max=t),this.highest.push(t)===this.max&&t!==this.max&&(this.max=function(t){for(var i=-1/0,e=t.length-1;e>=0;e--){var s=t[e];i<s&&(i=s)}return i}(this.highest.toArray())),this.max},t.prototype.momentValue=function(t){return this.max>t?this.max:t},t}(),C=function(){function t(t){this.min=1/0,this.lowest=new l(t)}return t.prototype.filled=function(){return this.lowest.filled},t.prototype.nextValue=function(t){return this.min>t&&(this.min=t),this.lowest.push(t)===this.min&&t!==this.min&&(this.min=function(t){for(var i=1/0,e=t.length-1;e>=0;e--){var s=t[e];i>s&&(i=s)}return i}(this.lowest.toArray())),this.min},t.prototype.momentValue=function(t){return this.min<t?this.min:t},t}(),D=function(){function t(t,i){void 0===t&&(t=14),void 0===i&&(i=3),this.period=t,this.smaPeriod=i,this.sma=new p(this.smaPeriod),this.max=new S(t),this.min=new C(t)}return t.prototype.nextValue=function(t,i,e){var s=this.max.nextValue(t),n=this.min.nextValue(i);if(this.max.filled()){var r=(e-n)/(s-n)*100;return{k:r,d:this.sma.nextValue(r)}}},t.prototype.momentValue=function(t,i,e){if(this.max.filled()){var s=this.max.momentValue(t),n=this.min.momentValue(i),r=(e-n)/(s-n)*100;return{k:r,d:this.sma.momentValue(r)}}},t}(),F=function(){function t(t){this.avgGain=new y(t),this.avgLoss=new y(t)}return t.prototype.nextValue=function(t){var i=t-this.prev;if(this.prev){var e=i>0?i:0,s=i<0?i:0,n=this.avgGain.nextValue(e),r=this.avgLoss.nextValue(s);return this.prev=t,{upAvg:n,downAvg:r}}this.prev=t},t.prototype.momentValue=function(t){var i=t-this.prev,e=i>0?i:0,s=i<0?i:0;return{upAvg:this.avgGain.momentValue(e),downAvg:this.avgLoss.momentValue(s)}},t}(),I=function(){function t(t){void 0===t&&(t=14),this.period=t,this.change=new F(this.period)}return t.prototype.nextValue=function(t){var i=this.change.nextValue(t)||{},e=i.downAvg,s=i.upAvg;if(void 0!==s&&void 0!==e)return 100-100/(1+s/-e)},t.prototype.momentValue=function(t){var i=this.change.momentValue(t)||{},e=i.downAvg,s=i.upAvg;if(void 0!==s&&void 0!==e)return 100-100/(1+s/-e)},t}(),_=function(){function t(t,i,e,s){void 0===t&&(t=14),void 0===i&&(i=3),void 0===e&&(e=3),void 0===s&&(s=14),this.rsi=new I(t),this.sma1=new p(i),this.sma2=new p(e),this.max=new S(s),this.min=new C(s)}return t.prototype.nextValue=function(t){var i=this.rsi.nextValue(t);if(void 0!==i){var e=this.max.nextValue(i),s=this.min.nextValue(i);if(this.max.filled()){var n=(i-s)/(e-s)*100,r=this.sma1.nextValue(n);if(void 0!==r)return{k:r,d:this.sma2.nextValue(r),stochRsi:n}}}},t.prototype.momentValue=function(t){if(this.max.filled()){var i=this.rsi.momentValue(t),e=this.max.momentValue(i),s=this.min.momentValue(i),n=(i-s)/(e-s)*100,r=this.sma1.momentValue(n);return{k:r,d:this.sma2.momentValue(r),stochRsi:n}}},t}(),O=function(){function t(t){this.period=t,this.values=new l(t)}return t.prototype.nextValue=function(t,i){if(i)return this.nextValue=this.pureNextValue,this.momentValue=this.pureMomentValue,this.pureNextValue(t,i);this.values.push(t)},t.prototype.momentValue=function(t,i){},t.prototype.pureNextValue=function(t,i){var e=this;return this.values.push(t),this.values.toArray().reduce((function(t,s){return t+e.positiveDelta(i,s)}),0)/this.period},t.prototype.pureMomentValue=function(t,i){var e=this,s=this.values.push(t),n=this.values.toArray().reduce((function(t,s){return t+e.positiveDelta(i,s)}),0);return this.values.pushback(s),n/this.period},t.prototype.positiveDelta=function(t,i){return t>i?t-i:i-t},t}(),E=function(){function t(t){void 0===t&&(t=20),this.md=new O(t),this.sma=new p(t)}return t.prototype.nextValue=function(t,i,e){var s=(t+i+e)/3,n=this.sma.nextValue(s),r=this.md.nextValue(s,n);return r&&(s-n)/(.015*r)},t.prototype.momentValue=function(t,i,e){var s=(t+i+e)/3,n=this.sma.momentValue(s),r=this.md.momentValue(s,n);return r&&(s-n)/(.015*r)},t}(),U=function(){function t(t){this.period=t,this.arr=[],this.filled=!1,this.devider=0,this.lastSum=0,this.devider=function(t){for(var i=0,e=t.length;e>0;)i+=t[--e];return i}(Array.from(Array(this.period).keys()).map((function(t){return t+1})))}return t.prototype.nextValue=function(t){if(this.filled=this.filled||this.arr.length===this.period,this.arr.push(t),this.filled)return this.arr.shift(),this.arr.reduce((function(t,i,e){return t+i*(e+1)}),0)/this.devider},t.prototype.momentValue=function(t){if(this.filled){var i=this.arr.slice(1);return i.push(t),i.reduce((function(t,i,e){return t+i*(e+1)}),0)/this.devider}},t}();function R(t,i,e){if(e){var s=t-i,n=t>e?t-e:e-t,r=i>e?i-e:e-i;return s>=n&&s>=r?s:n>=s&&n>=r?n:r}}var T=function(){function t(t,i){switch(void 0===t&&(t=14),void 0===i&&(i="WEMA"),i){case"SMA":this.avg=new p(t);break;case"EMA":this.avg=new f(t);break;case"SMMA":this.avg=new y(t);break;case"WEMA":this.avg=new c(t);break;case"LWMA":this.avg=new U(t);break;case"EWMA":this.avg=new x(.2);break;case"RMA":this.avg=new g(t)}this.prevClose=0}return t.prototype.nextValue=function(t,i,e){var s=R(t,i,this.prevClose);if(this.prevClose=e,void 0!==s)return this.avg.nextValue(s)},t.prototype.momentValue=function(t,i){var e=R(t,i,this.prevClose);if(void 0!==e)return this.avg.momentValue(e)},t}(),N=function(){function t(t){void 0===t&&(t=5),this.values=new l(t)}return t.prototype.nextValue=function(t){var i=this.values.push(t);if(i)return(t-i)/i*100},t.prototype.momentValue=function(t){var i=this.values.peek();if(i)return(t-i)/i*100},t}(),W=function(){function t(t){void 0===t&&(t=20),this.maxProvider=new S(t),this.minProvider=new C(t)}return t.prototype.nextValue=function(t,i){var e=this.maxProvider.nextValue(t),s=this.minProvider.nextValue(i);return{upper:e,middle:(e+s)/2,lower:s}},t.prototype.momentValue=function(t,i){var e=this.maxProvider.momentValue(t),s=this.minProvider.momentValue(i);return{upper:e,middle:(e+s)/2,lower:s}},t}(),$=function(){function t(t){this.period=t,this.fill=0,this.values=new l(t)}return t.prototype.nextValue=function(t){var i=this;if(this.values.push(t),this.fill++,this.fill===this.period)return this.nextValue=function(t){var e=i.calc(t);return i.values.push(t),e},this.momentValue=this.calc,this.calc(t)},t.prototype.momentValue=function(t){},t.prototype.calc=function(t){var i=0;return this.values.toArray().forEach((function(e){e<=t&&i++})),i/this.period*100},t}(),j=function(){function t(t,i,e){void 0===t&&(t=3),void 0===i&&(i=2),void 0===e&&(e=100),this.period=t,this.rsi=new I(this.period),this.updownRsi=new I(i),this.roc=new N(1),this.percentRank=new $(e),this.updownPeriod=0,this.prevClose=0}return t.prototype.nextValue=function(t){var i=this.rsi.nextValue(t),e=this.percentRank.nextValue(this.roc.nextValue(t));if(this.updownPeriod=this.getUpdownPeriod(t),this.prevClose=t,this.updownValue=this.updownRsi.nextValue(this.updownPeriod),this.updownValue)return(i+this.updownValue+e)/3},t.prototype.momentValue=function(t){var i=this.rsi.momentValue(t),e=this.percentRank.momentValue(this.roc.momentValue(t)),s=this.getUpdownPeriod(t),n=this.updownRsi.momentValue(s);if(void 0!==n)return(i+n+e)/3},t.prototype.getUpdownPeriod=function(t){var i=this.updownPeriod;return t>this.prevClose?(this.updownPeriod<0&&(i=0),i++):t<this.prevClose?(this.updownPeriod>0&&(i=0),i--):i=0,i},t}(),z=function(){function t(t){this.period=t,this.values=new l(t)}return t.prototype.nextValue=function(t,i){return this.values.push(t),Math.sqrt(this.values.toArray().reduce((function(t,e){return t+Math.pow(e-i,2)}),0)/this.period)},t.prototype.momentValue=function(t,i){var e=this.values.push(t),s=Math.sqrt(this.values.toArray().reduce((function(t,e){return t+Math.pow(e-i,2)}),0)/this.period);return this.values.pushback(e),s},t}(),B=function(){function t(t,i){void 0===t&&(t=20),void 0===i&&(i=2),this.period=t,this.stdDev=i,this.fill=0,this.sma=new p(t),this.sd=new z(t)}return t.prototype.nextValue=function(t){var i=this,e=this.sma.nextValue(t),s=this.sd.nextValue(t,e);if(this.fill++,this.fill===this.period){var n=e-this.stdDev*s,r=e+this.stdDev*s;return this.nextValue=function(t){var e=i.sma.nextValue(t),s=i.sd.nextValue(t,e);return{lower:e-i.stdDev*s,middle:e,upper:e+i.stdDev*s}},{lower:n,middle:e,upper:r}}},t.prototype.momentValue=function(t){var i=this.sma.momentValue(t),e=this.sd.momentValue(t,i);return{lower:i-this.stdDev*e,middle:i,upper:i+this.stdDev*e}},t}(),H=function(){function t(t,i,e){void 0===t&&(t=12),void 0===i&&(i=26),void 0===e&&(e=9),this.periodEmaFast=t,this.periodEmaSlow=i,this.periodSignal=e,this.emaFastIndicator=new f(t),this.emaSlowIndicator=new f(i),this.emaSignalIndicator=new f(e)}return t.prototype.nextValue=function(t){var i=this.emaFastIndicator.nextValue(t),e=this.emaSlowIndicator.nextValue(t),s=i-e,n=s&&this.emaSignalIndicator.nextValue(s)||void 0,r=s-n||void 0;if(!isNaN(s))return{macd:s,emaFast:i,emaSlow:e,signal:n,histogram:r}},t.prototype.momentValue=function(t){var i=this.emaFastIndicator.momentValue(t),e=this.emaSlowIndicator.momentValue(t),s=i-e,n=s&&this.emaSignalIndicator.momentValue(s);return{macd:s,emaFast:i,emaSlow:e,signal:n,histogram:s-n}},t}(),Y=function(){function t(){this.prevOpen=0,this.prevClose=0}return t.prototype.nextValue=function(t,i,e,s){var n=this.calculate(t,i,e,s);return this.prevClose=n.c,this.prevOpen=n.o,n},t.prototype.momentValue=function(t,i,e,s){return this.calculate(t,i,e,s)},t.prototype.calculate=function(t,i,e,s){return s=(t+i+e+s)/4,this.prevOpen&&(t=(this.prevOpen+this.prevClose)/2),{o:t,h:i=Math.max(i,t,s),l:e=Math.min(e,t,s),c:s}},t}(),X=function(){function t(t){switch(void 0===t&&(t="classic"),this.mode=t,this.mode){case"classic":this.calculator=this.classic;break;case"camarilla":this.calculator=this.camarilla;break;case"woodie":this.calculator=this.woodie;break;case"fibonacci":this.calculator=this.fibonacci}}return t.prototype.nextValue=function(t,i,e){return this.calculator(t,i,e)},t.prototype.classic=function(t,i,e){var s=(t+i+e)/3;return{r3:t+2*(s-i),r2:s+(t-i),r1:2*s-i,pp:s,s1:2*s-t,s2:s-(t-i),s3:i-2*(t-s)}},t.prototype.woodie=function(t,i,e){var s=(t+i+2*e)/4;return{r2:s+t-i,r1:2*s-i,pp:s,s1:2*s-t,s2:s-t+i}},t.prototype.camarilla=function(t,i,e){var s=1.1*(t-i),n=t/i*e,r=e+s/2,o=n+1.168*(n-r);return{r6:o,r5:n,r4:r,r3:e+s/4,r2:e+s/6,r1:e+s/12,pp:(t+i+e)/3,s1:e-s/12,s2:e-s/6,s3:e-s/4,s4:e-s/2,s5:e-(n-e),s6:e-(o-e)}},t.prototype.fibonacci=function(t,i,e){var s=t-i,n=(t+i+e)/3;return{r3:n+s,r2:n+.618*s,r1:n+.382*s,pp:n,s1:n-.382*s,s2:n-.618*s,s3:n-s}},t}(),q=function(){function t(t,i,e){void 0===t&&(t=.02),void 0===i&&(i=.02),void 0===e&&(e=.2),this.start=t,this.acceleration=i,this.max=e,this.result=0,this.isBullTrend=!0}return t.prototype.nextValue=function(t,i,e){if(!this.result)return this.result=e,this.low1=i,this.high1=t,this.low2=i,this.high2=t,this.highest=t,this.lowest=i,this.accelerationFactor=this.start,i;if(this.isBullTrend?this.psar=this.result+this.accelerationFactor*(this.highest-this.result):this.psar=this.result+this.accelerationFactor*(this.lowest-this.result),this.isBullTrend)if(i<this.psar)this.isBullTrend=!1,this.psar=this.highest,this.lowest=i,this.accelerationFactor=this.start;else{if(t>this.highest){this.highest=t;var s=this.accelerationFactor+this.acceleration;this.accelerationFactor=s>this.max?this.max:s}this.low1<this.psar&&(this.psar=this.low1),this.low2<this.psar&&(this.psar=this.low2)}else t>this.psar?(this.isBullTrend=!0,this.psar=this.lowest,this.highest=t,this.accelerationFactor=this.start):(i<this.lowest&&(this.lowest=i,s=this.accelerationFactor+this.acceleration,this.accelerationFactor=s>this.max?this.max:s),this.high1>this.psar&&(this.psar=this.high1),this.high2>this.psar&&(this.psar=this.high2));return this.low2=this.low1,this.low1=i,this.high2=this.high1,this.high1=t,this.result=this.psar,this.result},t.prototype.momentValue=function(t,i){if(!this.result)return i;var e,s=this.isBullTrend,n=this.result,r=this.low1,o=this.high1,h=this.low2,a=this.high2,l=this.highest,u=this.lowest,p=this.accelerationFactor;return e=s?n+p*(l-n):n+p*(u-n),s?i<e?e=l:(r<e&&(e=r),h<e&&(e=h)):t>e?e=u:(o>e&&(e=o),a>e&&(e=a)),e},t}(),G=function(){function t(t){this.period=t,this.prevValue=0,this.sumCount=1}return t.prototype.nextValue=function(t){var i=this;return this.sumCount<this.period?(this.prevValue+=t,void this.sumCount++):this.sumCount===this.period?(this.prevValue+=t,this.sumCount++,this.nextValue=function(t){return i.prevValue=i.prevValue-i.prevValue/i.period+t},this.prevValue):void 0},t.prototype.momentValue=function(t){if(!(this.sumCount<this.period))return this.prevValue-this.prevValue/this.period+t},t}(),J=function(){function t(t){void 0===t&&(t=14),this.period=t,this.wma1=new G(t),this.wma2=new G(t),this.wma3=new G(t),this.wema=new c(t)}return t.prototype.nextValue=function(t,i,e){if(!this.prevClose)return this.prevHigh=t,this.prevLow=i,void(this.prevClose=e);var s=0,n=0,r=t-this.prevHigh,o=this.prevLow-i;r>o&&r>0&&(s=r),o>r&&o>0&&(n=o),(s>n||n<0)&&(n=0);var h=this.wma1.nextValue(R(t,i,this.prevClose)),a=this.wma2.nextValue(s),l=this.wma3.nextValue(n);if(this.prevHigh=t,this.prevLow=i,this.prevClose=e,void 0!==a&&void 0!==l){var u=100*a/h,p=100*l/h,c=u>p?u-p:p-u;return{adx:this.wema.nextValue(c/(u+p)*100),pdi:u,mdi:p}}},t.prototype.momentValue=function(t,i,e){if(this.prevClose){var s=0,n=0,r=t-this.prevHigh,o=this.prevLow-i;r>o&&r>0&&(s=r),o>r&&o>0&&(n=o),(s>n||n<0)&&(n=0);var h=this.wma1.momentValue(R(t,i,this.prevClose)),a=this.wma2.momentValue(s),l=this.wma3.momentValue(n);if(void 0!==a&&void 0!==l){var u=100*a/h,p=100*l/h,c=u>p?u-p:p-u;return{adx:this.wema.momentValue(c/(u+p)*100),pdi:u,mdi:p}}}},t}(),K=function(){function t(t,i,e){void 0===t&&(t=10),void 0===i&&(i=3),void 0===e&&(e="WEMA"),this.multiplier=i,this.atr=new T(t,e)}return t.prototype.nextValue=function(t,i,e){var s=this.atr.nextValue(t,i,e);if(s){var n=(t+i)/2,r=n+this.multiplier*s,o=n-this.multiplier*s;this.prevLower&&(o=o>this.prevLower||this.prevClose<this.prevLower?o:this.prevLower,r=r<this.prevUpper||this.prevClose>this.prevUpper?r:this.prevUpper);var h,a=(h=this.prevSuper===this.prevUpper?e>r?o:r:e<o?r:o)===r?1:-1;return this.prevUpper=r,this.prevLower=o,this.prevSuper=h,this.prevClose=e,{upper:r,lower:o,superTrend:h,direction:a}}},t.prototype.momentValue=function(t,i,e){var s=this.atr.momentValue(t,i),n=(t+i)/2,r=n+this.multiplier*s,o=n-this.multiplier*s;this.prevLower&&(o=o>this.prevLower||this.prevClose<this.prevLower?o:this.prevLower,r=r<this.prevSuper||this.prevClose>this.prevUpper?r:this.prevUpper);var h;return{upper:r,lower:o,superTrend:h=this.prevSuper===this.prevUpper?e>r?o:r:e<o?r:o,direction:h===r?1:-1}},t}(),Q=function(t){return(t.o+t.h+t.l+t.c)/4},Z=function(){function t(t,i){void 0===t&&(t=4),void 0===i&&(i=Q),this.sum=0,this.sessionPricesLookup=new Set,this.sessionVolumes={},this.prevCandle=null,this.source=i,this.precision=t,this.valueToRoundWith=Math.pow(10,this.precision)}return t.prototype.getSession=function(t,i){var e=this;void 0===i&&(i=15);var s=this.source(t),n=1/0,r=s;this.sessionPricesLookup.forEach((function(t){var o=e.diffPercent(t,s);o>i?(e.sessionPricesLookup.delete(t),delete e.sessionVolumes[t]):o<n&&(n=o,r=t)}));var o=Array.from(this.sessionPricesLookup).sort(),h=o.indexOf(r),a=new Map;if(-1===h)return a;for(var l=Math.round(o.length/4),u=0,p=0;p<4;p++){for(var c=p*l,f=c+l,d=0,m=0,v=c;v<f;v++){var V=o[c],w=this.sessionVolumes[V];d<w&&(d=w,m=V)}this.diffPercent(u,m)<1&&(d=a.get(u)+d,m=this.roundPrice((m+u)/2),a.delete(u)),a.set(m,d),u=m}return a},t.prototype.getSessionAvg=function(){return this.sum/this.sessionPricesLookup.size},t.prototype.getRawSession=function(){return this.sessionVolumes},t.prototype.nextValue=function(t){var i,e=this.roundPrice(this.source(t)),s=(null===(i=this.prevCandle)||void 0===i?void 0:i.time)===t.time?t.v-this.prevCandle.v:t.v;this.addToSession(e,s),this.sum+=s,this.lastPrice=e,this.prevCandle=t},t.prototype.roundPrice=function(t){return Math.round((t+Number.EPSILON)*this.valueToRoundWith)/this.valueToRoundWith},t.prototype.addToSession=function(t,i){this.sessionPricesLookup.has(t)?this.sessionVolumes[t]+=i:(this.sessionPricesLookup.add(t),this.sessionVolumes[t]=i)},t.prototype.diffPercent=function(t,i){return t<i?100*(i-t)/t:100*(t-i)/i},t}(),tt=function(){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=10),this.accDistribution=0,this.emaFast=new f(t),this.emaSlow=new f(i)}return t.prototype.nextValue=function(t,i,e,s){return this.accDistribution+=e===t&&e===i||t===i?0:(2*e-i-t)/(t-i)*s,this.emaFast.nextValue(this.accDistribution)-this.emaSlow.nextValue(this.accDistribution)},t.prototype.momentValue=function(t,i,e,s){var n=this.accDistribution+(e===t&&e===i||t===i?0:(2*e-i-t)/(t-i)*s);return this.emaFast.momentValue(n)-this.emaSlow.momentValue(n)},t}();t.AC=k,t.ADX=J,t.AO=P,t.ATR=T,t.BollingerBands=B,t.CCI=E,t.ChaikinOscillator=tt,t.CircularBuffer=l,t.Correlation=V,t.DC=W,t.EMA=f,t.EWMA=x,t.Extremums=u,t.HeikenAshi=Y,t.LWMA=U,t.Level=v,t.MACD=H,t.Move=M,t.PSAR=q,t.Pivot=X,t.RMA=g,t.ROC=N,t.RSI=I,t.SMA=p,t.SMMA=y,t.Sampler=d,t.StandardDeviation=z,t.Stochastic=D,t.StochasticRSI=_,t.SuperTrend=K,t.TrendLines=a,t.UniLevel=m,t.VolumeProfile=Z,t.WEMA=c,t.WMA=w,t.WWS=G,t.Wave=L,t.cRSI=j,Object.defineProperty(t,"__esModule",{value:!0})}(i)}},i={};function e(s){var n=i[s];if(void 0!==n)return n.exports;var r=i[s]={exports:{}};return t[s].call(r.exports,r,r.exports,e),r.exports}e.d=(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},e.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),e.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};(()=>{"use strict";e.r(s),e.d(s,{default:()=>u});var t=e(978);const i=(i,e)=>{const s=[],n=new t.EMA(e);return i.forEach((t=>{s.push(n.nextValue(t))})),s},n=(i,e)=>{const s=[],n=new t.SMA(e);return i.forEach((t=>{s.push(n.nextValue(t))})),s},r=(t,i)=>{var e;return(0===(e=t.map(((t,e)=>t>i[e]?"up":t<i[e]?"down":"neutral")).reverse()).length?[]:e.reduce(((t,i,e,s)=>{if(0===e)t.push([i]);else{const n=s[e-1],r=t[t.length-1];i!==n?t.push([i]):r.push(i)}return t}),[])).map((t=>{const i=t.length;return t.map(((t,e)=>{let s=i-e;return"down"===t?-s:"up"===t?s:0}))})).flat().reverse()},o=(t,i)=>{let{upper:e,lower:s}=i;const n=e.map(((t,i)=>t-s[i]));return t.map(((t,i)=>(t-s[i])/n[i]*100))},h={getSMA:n,getEMA:i},a=(t,i=10)=>{const{open:e,high:s,low:n,close:r,volume:o}=t,h=Math.min(...n),a=(Math.max(...s)-h)/i,u={upVolume:0,downVolume:0,grossVolume:0},p=Array.from({length:i},((t,i)=>({price:h+a*i,upVolume:0,downVolume:0,grossVolume:0}))),c=1/a;for(let t=0;t<r.length;t++){const a=r[t],l=e[t],u=s[t],f=n[t],d=o[t],m=a>=l?d:0,v=a<l?d:0,V=Math.max(0,Math.floor((f-h)*c)),w=Math.min(i,Math.ceil((u-h)*c));for(let t=V;t<w;t++)p[t].upVolume+=m,p[t].downVolume+=v,p[t].grossVolume+=m+v}for(const{upVolume:t,downVolume:i,grossVolume:e}of p)u.upVolume+=t,u.downVolume+=i,u.grossVolume+=e;return{bins:p,nodes:l(p)}},l=t=>{if(!t||0===t.length)throw new Error("Bins array is empty or not provided");let i=t[0],e=t[0];return t.forEach((t=>{t.grossVolume>i.grossVolume&&(i=t),t.grossVolume<e.grossVolume&&(e=t)})),{highestVolumeNode:i,lowestVolumeNode:e}};class u{constructor(){this.VolumeProfile=a}init(t){return this.ohlcv=t.reduce(((t,{open:i,high:e,low:s,close:n,volume:r,...o})=>{t.open.push(i),t.high.push(e),t.low.push(s),t.close.push(n),t.volume.push(r);for(const i of Object.keys(o))t[i]||(t[i]=[]),t[i].push(o[i]);return t}),{open:[],high:[],low:[],close:[],volume:[]}),this}getHeaders(){return Object.keys(this.ohlcv)}getData(){const{ohlcv:t}=this,i={};for(const[e,s]of Object.entries(t))i[e]=s;return i}getLastValues(){const t={};for(const[i,e]of Object.entries(this.ohlcv)){let s=e[e.length-1];t[i]=s}return t}addColumn(t,i){const e=this.ohlcv.open.length;if(i.length>e)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");i=[...new Array(e-i.length).fill(null),...i],this.ohlcv[t]=i}crossPairs(t){const i=this.ohlcv,e={},s=t=>{if(!i.hasOwnProperty(t)&&"string"==typeof t){const[i,...e]=t.split("_");this[i]&&e.length>0&&this[i](...e)}};for(const{fast:n,slow:o}of t)if(n&&o)if(s(n),s(o),"number"!=typeof o||e[o]||(e[o]=i.close.map((()=>o))),i[n]&&i[o]){const t=r(i[n],i[o]);this.addColumn(`${n}_x_${o}`,t)}else if(i[n]&&e[o]){const t=r(i[n],e[o]);this.addColumn(`${n}_x_${o}`,t)}else console.error(`Missing ohlcv properties for ${n} or ${o}`)}ema(t){return((t,e)=>{const{ohlcv:s}=t,n=s.close,r=i(n,e);t.addColumn(`ema_${e}`,r)})(this,t),this}sma(t){return((t,i)=>{const{ohlcv:e}=t,s=e.close,r=n(s,i);t.addColumn(`sma_${i}`,r)})(this,t),this}macd(t,e,s){return((t,e=12,s=26,n=9)=>{const{ohlcv:o}=t,h=((t,e=12,s=26,n=9)=>{const o=i(t,e),h=i(t,s),a=o.map(((t,i)=>isNaN(t)||isNaN(h[i])?null:t-h[i])),l=i(a,n),u=a.map(((t,i)=>t-l[i])),p=r(a,l);return{macd_diff:a,macd_dea:l,macd_histogram:u,macd_diff_x_macd_dea:p}})(o.close,e,s,n);for(let i in h)t.addColumn(i,h[i])})(this,t,e,s),this}bollingerBands(i,e,s){return((i,e,s)=>{const{ohlcv:n}=i,r=((i,e=20,s=2)=>{const n={lower:[],middle:[],upper:[]},r=new t.BollingerBands(e,s);i.forEach((t=>{const i=r.nextValue(t);if("object"==typeof i){const{lower:t,middle:e,upper:s}=i;n.lower.push(t),n.middle.push(e),n.upper.push(s)}else n.lower.push(null),n.middle.push(null),n.upper.push(null)}));const h=o(i,{upper:n.upper,lower:n.lower});return{...n,range:h}})(n.close,e,s);for(let t in r)i.addColumn(`bollinger_bands_${t}`,r[t])})(this,i,e),this}rsi(i,e,s){return((i,e,s,n)=>{const{ohlcv:o}=i,a=((i,e=14,s="SMA",n=14)=>{if(i.length<e)return[];let o=[];e=parseInt(e),n=parseInt(n);const a=new t.RSI(e);i.forEach((t=>{o.push(a.nextValue(t))})),o=o.filter((t=>t));let l={[`rsi_${e}`]:o};if("string"==typeof s&&"number"==typeof n&&h.hasOwnProperty(`get${s}`)){const t=h[`get${s}`](o,n);l[`rsi_${s}_${n}`]=t,l[`rsi_${e}_x_rsi_${s}_${n}`]=r(o,t)}return l})(o.close,e,s,n);for(let t in a)i.addColumn(`${t}`.toLowerCase(),a[t])})(this,i,e,s),this}}})(),OHLCV_INDICATORS=s})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
package/index.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { IchimokuCloud } from './src/moving-averages/ichimokuCloud.js'
|
|
7
|
-
import { RSI} from './src/oscillators/rsi.js'
|
|
8
|
-
import { MFI} from './src/oscillators/mfi.js'
|
|
9
|
-
import { RelativeVolume} from './src/moving-averages/relativeVolume.js'
|
|
1
|
+
import {ema} from './src/moving-averages/ema.js'
|
|
2
|
+
import {sma} from './src/moving-averages/sma.js'
|
|
3
|
+
import {macd} from './src/moving-averages/macd.js'
|
|
4
|
+
import {bollingerBands} from './src/moving-averages/bollingerBands.js'
|
|
5
|
+
import { rsi } from './src/oscillators/rsi.js'
|
|
10
6
|
import { VolumeProfile } from './src/studies/volumeProfile.js'
|
|
11
7
|
import {findCrosses} from './src/utilities.js'
|
|
12
8
|
|
|
13
9
|
export default class OHLCV_INDICATORS {
|
|
14
10
|
constructor() {
|
|
15
|
-
this.BigNumber = BigNumber
|
|
16
11
|
this.VolumeProfile = VolumeProfile
|
|
17
12
|
}
|
|
18
13
|
|
|
19
14
|
init(ohlcv) {
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
|
|
22
16
|
this.ohlcv = ohlcv.reduce((acc, { open, high, low, close, volume, ...rest }) => {
|
|
23
|
-
acc.open.push(
|
|
24
|
-
acc.high.push(
|
|
25
|
-
acc.low.push(
|
|
26
|
-
acc.close.push(
|
|
27
|
-
acc.volume.push(
|
|
17
|
+
acc.open.push(open)
|
|
18
|
+
acc.high.push(high)
|
|
19
|
+
acc.low.push(low)
|
|
20
|
+
acc.close.push(close)
|
|
21
|
+
acc.volume.push(volume)
|
|
28
22
|
for (const key of Object.keys(rest)) {
|
|
29
23
|
if (!acc[key]) acc[key] = [];
|
|
30
24
|
acc[key].push(rest[key]);
|
|
@@ -41,12 +35,12 @@ export default class OHLCV_INDICATORS {
|
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
getData() {
|
|
44
|
-
const {
|
|
38
|
+
const {ohlcv} = this
|
|
45
39
|
const output = {}
|
|
46
40
|
|
|
47
41
|
for(const[key, arr] of Object.entries(ohlcv))
|
|
48
42
|
{
|
|
49
|
-
output[key] = arr
|
|
43
|
+
output[key] = arr
|
|
50
44
|
}
|
|
51
45
|
|
|
52
46
|
return output
|
|
@@ -56,7 +50,7 @@ export default class OHLCV_INDICATORS {
|
|
|
56
50
|
|
|
57
51
|
for (const [k, arr] of Object.entries(this.ohlcv)) {
|
|
58
52
|
let value = arr[arr.length - 1];
|
|
59
|
-
output[k] =
|
|
53
|
+
output[k] = value;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
return output
|
|
@@ -69,8 +63,8 @@ export default class OHLCV_INDICATORS {
|
|
|
69
63
|
throw new Error(`Invalid column data: The length of the new column exceeds the length of the OHLCV data`);
|
|
70
64
|
}
|
|
71
65
|
|
|
72
|
-
// Use Array.prototype.unshift to add
|
|
73
|
-
const nanArray = new Array(ohlcvLength - arr.length).fill(
|
|
66
|
+
// Use Array.prototype.unshift to add null elements efficiently
|
|
67
|
+
const nanArray = new Array(ohlcvLength - arr.length).fill(null)
|
|
74
68
|
arr = [...nanArray, ...arr]
|
|
75
69
|
|
|
76
70
|
this.ohlcv[key] = arr
|
|
@@ -83,10 +77,13 @@ export default class OHLCV_INDICATORS {
|
|
|
83
77
|
|
|
84
78
|
// Helper function to create column if it doesn't exist
|
|
85
79
|
const createColumnIfNeeded = (v) => {
|
|
80
|
+
|
|
86
81
|
if (!ohlcv.hasOwnProperty(v) && typeof v === 'string') {
|
|
82
|
+
|
|
87
83
|
const [funcName, ...params] = v.split('_');
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
|
|
85
|
+
if (this[funcName] && params.length > 0) {
|
|
86
|
+
this[funcName](...params);
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
89
|
};
|
|
@@ -106,10 +103,10 @@ export default class OHLCV_INDICATORS {
|
|
|
106
103
|
|
|
107
104
|
// Find and add crosses
|
|
108
105
|
if (ohlcv[fast] && ohlcv[slow]) {
|
|
109
|
-
const cross = findCrosses(
|
|
106
|
+
const cross = findCrosses(ohlcv[fast], ohlcv[slow]);
|
|
110
107
|
this.addColumn(`${fast}_x_${slow}`, cross);
|
|
111
108
|
} else if (ohlcv[fast] && slowNumArrCache[slow]) {
|
|
112
|
-
const cross = findCrosses(
|
|
109
|
+
const cross = findCrosses(ohlcv[fast], slowNumArrCache[slow]);
|
|
113
110
|
this.addColumn(`${fast}_x_${slow}`, cross);
|
|
114
111
|
} else {
|
|
115
112
|
console.error(`Missing ohlcv properties for ${fast} or ${slow}`);
|
|
@@ -118,41 +115,26 @@ export default class OHLCV_INDICATORS {
|
|
|
118
115
|
|
|
119
116
|
}
|
|
120
117
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return this
|
|
124
|
-
}
|
|
125
|
-
SMA(size) {
|
|
126
|
-
SMA(this, size)
|
|
118
|
+
ema(size) {
|
|
119
|
+
ema(this, size)
|
|
127
120
|
return this
|
|
128
121
|
}
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
sma(size) {
|
|
123
|
+
sma(this, size)
|
|
131
124
|
return this
|
|
132
125
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
BollingerBands(this, data, size, times)
|
|
136
|
-
return this
|
|
137
|
-
}
|
|
138
|
-
IchimokuCloud(tenkan, kijun, senkou)
|
|
139
|
-
{
|
|
140
|
-
IchimokuCloud(this, tenkan, kijun, senkou)
|
|
141
|
-
return this
|
|
142
|
-
}
|
|
143
|
-
RSI(period, movingAverage, movingAveragePeriod)
|
|
144
|
-
{
|
|
145
|
-
RSI(this, period, movingAverage, movingAveragePeriod)
|
|
126
|
+
macd(fastLine, slowLine, signalLine) {
|
|
127
|
+
macd(this, fastLine, slowLine, signalLine)
|
|
146
128
|
return this
|
|
147
129
|
}
|
|
148
|
-
|
|
130
|
+
bollingerBands(data, size, times)
|
|
149
131
|
{
|
|
150
|
-
|
|
132
|
+
bollingerBands(this, data, size, times)
|
|
151
133
|
return this
|
|
152
134
|
}
|
|
153
|
-
|
|
135
|
+
rsi(period, movingAverage, movingAveragePeriod)
|
|
154
136
|
{
|
|
155
|
-
|
|
137
|
+
rsi(this, period, movingAverage, movingAveragePeriod)
|
|
156
138
|
return this
|
|
157
139
|
}
|
|
158
140
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}]
|
|
3
|
+
"version": "1.1.8",
|
|
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": {
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"author": "https://jaimelias.com/",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@debut/indicators": "^1.3.20",
|
|
14
15
|
"bignumber.js": "^9.1.2"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
18
|
+
"dotenv": "^16.4.5",
|
|
17
19
|
"webpack": "^5.92.1",
|
|
18
20
|
"webpack-cli": "^5.1.4"
|
|
19
21
|
}
|
|
@@ -1,64 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BollingerBands } from '@debut/indicators';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const bollingerBands = (main, size, times) => {
|
|
5
5
|
const {ohlcv} = main
|
|
6
6
|
const data = ohlcv['close'];
|
|
7
|
-
const
|
|
7
|
+
const col = getBollingerBands(data, size, times)
|
|
8
8
|
|
|
9
|
-
for(let k in
|
|
9
|
+
for(let k in col)
|
|
10
10
|
{
|
|
11
|
-
main.addColumn(`bollinger_bands_${k}`,
|
|
11
|
+
main.addColumn(`bollinger_bands_${k}`, col[k])
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
export const getBollingerBands = (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const deviation = (BigNumber, data, size) => {
|
|
37
|
-
const zero = new BigNumber(0)
|
|
38
|
-
const length = data.length
|
|
39
|
-
const avg = getSMA(BigNumber, data, size)
|
|
40
|
-
const ret = new Array(length).fill(zero) // Initialize ret array with zeros
|
|
41
|
-
|
|
42
|
-
for (let i = size - 1; i < length; i++) {
|
|
43
|
-
let sum = zero
|
|
44
|
-
|
|
45
|
-
for (let j = i - size + 1; j <= i; j++) {
|
|
46
|
-
sum = sum.plus(data[j].minus(avg[i]).pow(2))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
ret[i] = sum.dividedBy(size).sqrt()
|
|
17
|
+
export const getBollingerBands = (data, size = 20, times = 2) => {
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const output = {lower: [], middle: [], upper: []}
|
|
21
|
+
const instance = new BollingerBands(size, times)
|
|
22
|
+
|
|
23
|
+
data.forEach(c => {
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const bb = instance.nextValue(c)
|
|
27
|
+
|
|
28
|
+
if(typeof bb === 'object')
|
|
29
|
+
{
|
|
30
|
+
const {lower, middle, upper} = bb
|
|
31
|
+
output.lower.push(lower)
|
|
32
|
+
output.middle.push(middle)
|
|
33
|
+
output.upper.push(upper)
|
|
34
|
+
|
|
50
35
|
}
|
|
36
|
+
else
|
|
37
|
+
{
|
|
38
|
+
output.lower.push(null)
|
|
39
|
+
output.middle.push(null)
|
|
40
|
+
output.upper.push(null)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const range = bollingerBandsRange(data, {upper: output.upper, lower: output.lower})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
return {...output, range}
|
|
48
|
+
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
return ret
|
|
53
|
-
}
|
|
54
51
|
|
|
55
52
|
|
|
56
53
|
const bollingerBandsRange = (data, bollingerBands) => {
|
|
57
|
-
|
|
54
|
+
let {upper, lower} = bollingerBands;
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
const range = upper.map((v, i) => v - lower[i]);
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
const output = data.map((v, i) => ((v - lower[i]) / range[i]) * 100);
|
|
59
|
+
|
|
60
|
+
return output;
|
|
61
|
+
};
|
|
@@ -1,55 +1,26 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
import { EMA } from '@debut/indicators';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const ema = (main, size) => {
|
|
3
6
|
const {ohlcv} = main
|
|
4
7
|
const data = ohlcv['close']
|
|
5
|
-
const
|
|
6
|
-
main.addColumn(`ema_${size}`,
|
|
8
|
+
const col = getEMA(data, size)
|
|
9
|
+
main.addColumn(`ema_${size}`, col)
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
export const getEMA = (
|
|
10
|
-
const alpha = BigNumber(2 / (size + 1))
|
|
11
|
-
const length = data.length
|
|
12
|
-
const ret = []
|
|
13
|
-
|
|
14
|
-
if (alpha.isGreaterThan(1)) {
|
|
15
|
-
return Array(length)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (alpha.isEqualTo(1)) {
|
|
19
|
-
return [...data]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let s = 0
|
|
23
|
-
|
|
24
|
-
// Handles head
|
|
25
|
-
let i = 0;
|
|
26
|
-
for (; i < length; i++) {
|
|
27
|
-
const datum = data[i]
|
|
28
|
-
if (typeof datum === 'object') {
|
|
29
|
-
ret[i] = datum
|
|
30
|
-
s = datum
|
|
31
|
-
i++
|
|
32
|
-
break
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (Array.isArray(alpha)) {
|
|
37
|
-
for (; i < length; i++) {
|
|
38
|
-
const datum = data[i]
|
|
39
|
-
if (typeof datum === 'object' && typeof alpha[i] === 'object') {
|
|
40
|
-
s = ret[i] = alpha[i].multipliedBy(datum).plus(alpha[i].minus(1).multipliedBy(s))
|
|
41
|
-
} else {
|
|
42
|
-
ret[i] = ret[i - 1]
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
const o = BigNumber(1).minus(alpha);
|
|
47
|
-
for (; i < length; i++) {
|
|
48
|
-
const datum = data[i]
|
|
49
|
-
s = typeof datum === 'object' ? alpha.multipliedBy(datum).plus(o.multipliedBy(s)) : ret[i - 1]
|
|
50
|
-
ret[i] = s
|
|
51
|
-
}
|
|
52
|
-
}
|
|
12
|
+
export const getEMA = (data, size) => {
|
|
53
13
|
|
|
54
|
-
|
|
55
|
-
|
|
14
|
+
|
|
15
|
+
const output = []
|
|
16
|
+
const instance = new EMA(size)
|
|
17
|
+
|
|
18
|
+
data.forEach(c => {
|
|
19
|
+
|
|
20
|
+
output.push(instance.nextValue(c))
|
|
21
|
+
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return output
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -2,32 +2,31 @@ import { findCrosses } from "../utilities.js";
|
|
|
2
2
|
import { getEMA } from "./ema.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const macd = (main, fastLine = 12, slowLine = 26, signalLine = 9) => {
|
|
6
6
|
const {ohlcv} = main
|
|
7
|
-
const data = ohlcv['close']
|
|
8
|
-
const
|
|
7
|
+
const data = ohlcv['close']
|
|
8
|
+
const col = getMACD(data, fastLine, slowLine, signalLine)
|
|
9
9
|
|
|
10
|
-
for(let k in
|
|
10
|
+
for(let k in col)
|
|
11
11
|
{
|
|
12
|
-
main.addColumn(k,
|
|
12
|
+
main.addColumn(k, col[k]);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const getMACD = (
|
|
16
|
+
export const getMACD = (data, fastLine = 12, slowLine = 26, signalLine = 9) => {
|
|
17
17
|
|
|
18
|
-
const fastEMA = getEMA(
|
|
19
|
-
const slowEMA = getEMA(
|
|
18
|
+
const fastEMA = getEMA(data, fastLine)
|
|
19
|
+
const slowEMA = getEMA(data, slowLine)
|
|
20
20
|
|
|
21
21
|
// Calculate the MACD line (diff)
|
|
22
|
-
const diff = fastEMA.map((o, i) => o
|
|
23
|
-
|
|
22
|
+
const diff = fastEMA.map((o, i) => (isNaN(o) || isNaN(slowEMA[i])) ? null : o - slowEMA[i]);
|
|
24
23
|
|
|
25
24
|
// Calculate the MACD line (dea)
|
|
26
|
-
const dea = getEMA(
|
|
25
|
+
const dea = getEMA(diff, signalLine)
|
|
27
26
|
|
|
28
27
|
// Calculate the MACD line (histogram)
|
|
29
|
-
const histogram = diff.map((d, i) => d
|
|
30
|
-
const x = findCrosses(
|
|
28
|
+
const histogram = diff.map((d, i) => d - dea[i])
|
|
29
|
+
const x = findCrosses(diff, dea)
|
|
31
30
|
|
|
32
31
|
return {
|
|
33
32
|
'macd_diff': diff,
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
const {ohlcv} = main
|
|
4
|
-
const data = ohlcv['close']
|
|
5
|
-
const sma = getSMA(main.BigNumber, data, size)
|
|
6
|
-
main.addColumn(`sma_${size}`, sma)
|
|
7
|
-
}
|
|
2
|
+
import { SMA } from '@debut/indicators';
|
|
8
3
|
|
|
4
|
+
export const sma = (main, size) => {
|
|
5
|
+
const {ohlcv} = main
|
|
6
|
+
const data = ohlcv['close']
|
|
7
|
+
const col = getSMA(data, size)
|
|
8
|
+
main.addColumn(`sma_${size}`, col)
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
export const getSMA = (
|
|
11
|
-
|
|
12
|
-
let result = []
|
|
13
|
-
let sum = BigNumber(0)
|
|
14
|
-
let arr = []
|
|
15
|
-
|
|
16
|
-
for (let i = 0; i < data.length; i++) {
|
|
17
|
-
|
|
18
|
-
arr.push(data[i])
|
|
19
|
-
sum = sum.plus(data[i])
|
|
20
|
-
|
|
21
|
-
if (arr.length > size) {
|
|
22
|
-
sum = sum.minus(arr.shift())
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (i >= size - 1) {
|
|
26
|
-
result.push(sum.dividedBy(size))
|
|
27
|
-
} else {
|
|
11
|
+
export const getSMA = (data, size) => {
|
|
28
12
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
|
|
14
|
+
const output = []
|
|
15
|
+
const instance = new SMA(size)
|
|
16
|
+
|
|
17
|
+
data.forEach(c => {
|
|
18
|
+
|
|
19
|
+
output.push(instance.nextValue(c))
|
|
20
|
+
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return output
|
|
24
|
+
|
|
25
|
+
}
|
package/src/oscillators/rsi.js
CHANGED
|
@@ -1,72 +1,39 @@
|
|
|
1
1
|
import { getSMA } from "../moving-averages/sma.js";
|
|
2
2
|
import { getEMA } from "../moving-averages/ema.js";
|
|
3
3
|
import { findCrosses } from "../utilities.js";
|
|
4
|
+
import { RSI } from "@debut/indicators";
|
|
4
5
|
|
|
5
6
|
const ma = {getSMA, getEMA}
|
|
6
7
|
|
|
7
|
-
export const
|
|
8
|
+
export const rsi = (main, period, movingAverage, movingAveragePeriod) => {
|
|
8
9
|
|
|
9
10
|
const {ohlcv} = main
|
|
10
11
|
const data = ohlcv['close']
|
|
11
|
-
const
|
|
12
|
+
const col = getRSI(data, period, movingAverage, movingAveragePeriod)
|
|
12
13
|
|
|
13
|
-
for(let k in
|
|
14
|
+
for(let k in col)
|
|
14
15
|
{
|
|
15
|
-
main.addColumn(`${k}`.toLowerCase(),
|
|
16
|
+
main.addColumn(`${k}`.toLowerCase(), col[k])
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export const getRSI = (
|
|
20
|
+
export const getRSI = (data, period = 14, movingAverage = 'SMA', movingAveragePeriod = 14) => {
|
|
20
21
|
if (data.length < period) {
|
|
21
22
|
return [];
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let rsi = []
|
|
26
|
+
period = parseInt(period)
|
|
27
|
+
movingAveragePeriod = parseInt(movingAveragePeriod)
|
|
28
|
+
const instance = new RSI(period)
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
let gain = zero;
|
|
30
|
-
let loss = zero;
|
|
30
|
+
data.forEach(c => {
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
for (let i = 1; i <= period; i++) {
|
|
34
|
-
const thisVal = new BigNumber(data[i])
|
|
35
|
-
const prevVal = new BigNumber(data[i - 1])
|
|
36
|
-
const change = thisVal.minus(prevVal)
|
|
32
|
+
rsi.push(instance.nextValue(c))
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
loss = loss.plus(change.abs())
|
|
40
|
-
} else {
|
|
41
|
-
gain = gain.plus(change)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Calculate the first RSI value
|
|
46
|
-
let avgGain = gain.dividedBy(period)
|
|
47
|
-
let avgLoss = loss.dividedBy(period)
|
|
48
|
-
let rs = avgLoss.isEqualTo(zero) ? zero : avgGain.dividedBy(avgLoss)
|
|
49
|
-
rsi.push(hundred.minus(hundred.dividedBy(one.plus(rs))))
|
|
50
|
-
|
|
51
|
-
// Calculate subsequent RSI values
|
|
52
|
-
for (let i = period + 1; i < data.length; i++) {
|
|
53
|
-
const thisVal = new BigNumber(data[i])
|
|
54
|
-
const prevVal = new BigNumber(data[i - 1])
|
|
55
|
-
const change = thisVal.minus(prevVal)
|
|
34
|
+
})
|
|
56
35
|
|
|
57
|
-
|
|
58
|
-
loss = change.abs()
|
|
59
|
-
gain = zero
|
|
60
|
-
} else {
|
|
61
|
-
gain = change
|
|
62
|
-
loss = zero
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
avgGain = avgGain.times(period - 1).plus(gain).dividedBy(period)
|
|
66
|
-
avgLoss = avgLoss.times(period - 1).plus(loss).dividedBy(period)
|
|
67
|
-
rs = avgLoss.isEqualTo(zero) ? zero : avgGain.dividedBy(avgLoss)
|
|
68
|
-
rsi.push(hundred.minus(hundred.dividedBy(one.plus(rs))))
|
|
69
|
-
}
|
|
36
|
+
rsi = rsi.filter(v => v)
|
|
70
37
|
|
|
71
38
|
let output = {[`rsi_${period}`]: rsi}
|
|
72
39
|
|
|
@@ -74,9 +41,9 @@ export const getRSI = (BigNumber, data, period = 14, movingAverage = 'SMA', movi
|
|
|
74
41
|
{
|
|
75
42
|
if(ma.hasOwnProperty(`get${movingAverage}`))
|
|
76
43
|
{
|
|
77
|
-
const rsi_smoothed = ma[`get${movingAverage}`](
|
|
44
|
+
const rsi_smoothed = ma[`get${movingAverage}`](rsi, movingAveragePeriod)
|
|
78
45
|
output[`rsi_${movingAverage}_${movingAveragePeriod}`] = rsi_smoothed
|
|
79
|
-
output[`rsi_${period}_x_rsi_${movingAverage}_${movingAveragePeriod}`] = findCrosses(
|
|
46
|
+
output[`rsi_${period}_x_rsi_${movingAverage}_${movingAveragePeriod}`] = findCrosses(rsi, rsi_smoothed)
|
|
80
47
|
}
|
|
81
48
|
}
|
|
82
49
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export const VolumeProfile = (
|
|
1
|
+
export const VolumeProfile = (ohlcv, numBins = 10) => {
|
|
2
2
|
const { open, high, low, close, volume } = ohlcv;
|
|
3
3
|
|
|
4
4
|
// Determine the range of prices
|
|
5
|
-
const lowPrice =
|
|
6
|
-
const highPrice =
|
|
7
|
-
const binSize = highPrice
|
|
8
|
-
const zero =
|
|
5
|
+
const lowPrice = Math.min(...low);
|
|
6
|
+
const highPrice = Math.max(...high);
|
|
7
|
+
const binSize = (highPrice - lowPrice) / numBins;
|
|
8
|
+
const zero = 0;
|
|
9
9
|
|
|
10
10
|
// Initialize totals
|
|
11
11
|
const totals = {
|
|
@@ -16,14 +16,14 @@ export const VolumeProfile = (BigNumber, ohlcv, numBins = 10, position) => {
|
|
|
16
16
|
|
|
17
17
|
// Initialize bins
|
|
18
18
|
const bins = Array.from({ length: numBins }, (_, i) => ({
|
|
19
|
-
price: lowPrice
|
|
19
|
+
price: lowPrice + binSize * i,
|
|
20
20
|
upVolume: zero,
|
|
21
21
|
downVolume: zero,
|
|
22
22
|
grossVolume: zero,
|
|
23
23
|
}));
|
|
24
24
|
|
|
25
25
|
// Precompute binSize inversely to use multiplication instead of division in the loop
|
|
26
|
-
const inverseBinSize =
|
|
26
|
+
const inverseBinSize = 1 / binSize;
|
|
27
27
|
|
|
28
28
|
// Distribute volume into bins
|
|
29
29
|
for (let i = 0; i < close.length; i++) {
|
|
@@ -33,32 +33,30 @@ export const VolumeProfile = (BigNumber, ohlcv, numBins = 10, position) => {
|
|
|
33
33
|
const currentLow = low[i];
|
|
34
34
|
const currentVolume = volume[i];
|
|
35
35
|
|
|
36
|
-
const upVolume = currentClose
|
|
37
|
-
const downVolume = currentClose
|
|
36
|
+
const upVolume = currentClose >= currentOpen ? currentVolume : zero;
|
|
37
|
+
const downVolume = currentClose < currentOpen ? currentVolume : zero;
|
|
38
38
|
|
|
39
|
-
const lowIndex = Math.max(0,
|
|
40
|
-
const highIndex = Math.min(numBins,
|
|
39
|
+
const lowIndex = Math.max(0, Math.floor((currentLow - lowPrice) * inverseBinSize));
|
|
40
|
+
const highIndex = Math.min(numBins, Math.ceil((currentHigh - lowPrice) * inverseBinSize));
|
|
41
41
|
|
|
42
42
|
for (let j = lowIndex; j < highIndex; j++) {
|
|
43
|
-
bins[j].upVolume
|
|
44
|
-
bins[j].downVolume
|
|
45
|
-
bins[j].grossVolume
|
|
43
|
+
bins[j].upVolume += upVolume;
|
|
44
|
+
bins[j].downVolume += downVolume;
|
|
45
|
+
bins[j].grossVolume += (upVolume + downVolume);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// Sum totals outside the loop
|
|
50
50
|
for (const { upVolume, downVolume, grossVolume } of bins) {
|
|
51
|
-
totals.upVolume
|
|
52
|
-
totals.downVolume
|
|
53
|
-
totals.grossVolume
|
|
51
|
+
totals.upVolume += upVolume;
|
|
52
|
+
totals.downVolume += downVolume;
|
|
53
|
+
totals.grossVolume += grossVolume;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return {bins, nodes};
|
|
56
|
+
const nodes = findVolumeNodes(bins);
|
|
57
|
+
return { bins, nodes };
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
|
|
62
60
|
const findVolumeNodes = bins => {
|
|
63
61
|
if (!bins || bins.length === 0) {
|
|
64
62
|
throw new Error('Bins array is empty or not provided');
|
|
@@ -68,11 +66,11 @@ const findVolumeNodes = bins => {
|
|
|
68
66
|
let lowestVolumeNode = bins[0];
|
|
69
67
|
|
|
70
68
|
bins.forEach(bin => {
|
|
71
|
-
if (bin.grossVolume
|
|
69
|
+
if (bin.grossVolume > highestVolumeNode.grossVolume) {
|
|
72
70
|
highestVolumeNode = bin;
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
if (bin.grossVolume
|
|
73
|
+
if (bin.grossVolume < lowestVolumeNode.grossVolume) {
|
|
76
74
|
lowestVolumeNode = bin;
|
|
77
75
|
}
|
|
78
76
|
});
|
|
@@ -80,5 +78,5 @@ const findVolumeNodes = bins => {
|
|
|
80
78
|
return {
|
|
81
79
|
highestVolumeNode,
|
|
82
80
|
lowestVolumeNode
|
|
83
|
-
}
|
|
84
|
-
}
|
|
81
|
+
};
|
|
82
|
+
}
|
package/src/utilities.js
CHANGED
|
@@ -1,47 +1,55 @@
|
|
|
1
|
-
export const findCrosses = (
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export const findCrosses = (fast, slow) => {
|
|
2
|
+
const states = fast.map((f, i) => {
|
|
3
|
+
if (f > slow[i]) {
|
|
4
|
+
return 'up';
|
|
5
|
+
} else if (f < slow[i]) {
|
|
6
|
+
return 'down';
|
|
7
|
+
} else {
|
|
8
|
+
return 'neutral';
|
|
9
|
+
}
|
|
10
|
+
}).reverse();
|
|
11
|
+
|
|
12
|
+
const groups = groupConsecutiveValues(states);
|
|
13
|
+
|
|
14
|
+
const crosses = groups.map(chunk => {
|
|
15
|
+
const chunkLength = chunk.length;
|
|
16
|
+
return chunk.map((state, index) => {
|
|
17
|
+
let value = chunkLength - index;
|
|
4
18
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
19
|
+
if (state === 'down') {
|
|
20
|
+
return -value;
|
|
21
|
+
} else if (state === 'up') {
|
|
22
|
+
return value;
|
|
23
|
+
} else {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}).flat();
|
|
8
28
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
crosses[0] = 1
|
|
12
|
-
} else if (fast0.isLessThan(slow0)) {
|
|
13
|
-
state = -1
|
|
14
|
-
crosses[0] = -1
|
|
15
|
-
} else {
|
|
16
|
-
state = 0
|
|
17
|
-
crosses[0] = 0
|
|
18
|
-
}
|
|
29
|
+
return crosses.reverse();
|
|
30
|
+
};
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const slowI = new BigNumber(slow[i])
|
|
23
|
-
const fastPrev = new BigNumber(fast[i - 1])
|
|
24
|
-
const slowPrev = new BigNumber(slow[i - 1])
|
|
32
|
+
function groupConsecutiveValues(arr) {
|
|
33
|
+
if (arr.length === 0) return [];
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} else if (fastI.isLessThan(slowI) && fastPrev.isGreaterThanOrEqualTo(slowPrev)) {
|
|
31
|
-
// CrossDown detected
|
|
32
|
-
state = -1
|
|
33
|
-
crosses[i] = -1
|
|
35
|
+
return arr.reduce((acc, currentValue, index, array) => {
|
|
36
|
+
if (index === 0) {
|
|
37
|
+
// Start the first group with the first element
|
|
38
|
+
acc.push([currentValue]);
|
|
34
39
|
} else {
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
// Get the previous value
|
|
41
|
+
const prevValue = array[index - 1];
|
|
42
|
+
const currentGroup = acc[acc.length - 1];
|
|
43
|
+
|
|
44
|
+
// Check the direction of the previous and current values
|
|
45
|
+
if (currentValue !== prevValue) {
|
|
46
|
+
// Start a new group if the direction changes
|
|
47
|
+
acc.push([currentValue]);
|
|
40
48
|
} else {
|
|
41
|
-
|
|
49
|
+
// Otherwise, add to the current group
|
|
50
|
+
currentGroup.push(currentValue);
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return crosses
|
|
53
|
+
return acc;
|
|
54
|
+
}, []);
|
|
47
55
|
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export const IchimokuCloud = (main, tenkan, kijun, senkou) => {
|
|
2
|
-
|
|
3
|
-
const {ohlcv} = main
|
|
4
|
-
const ichi = getIchimokuCloud(main.BigNumber, ohlcv, tenkan, kijun, senkou)
|
|
5
|
-
|
|
6
|
-
for(let k in ichi)
|
|
7
|
-
{
|
|
8
|
-
//console.log(`${k} [length ${ichi[k].length}] [lastValue ${ichi[k][ichi[k].length -1]}]`)
|
|
9
|
-
main.addColumn(`ichimoku_${k}`, ichi[k])
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const getIchimokuCloud = (BigNumber, data, tenkan = 9, kijun = 26, senkou = 52) => {
|
|
15
|
-
const TENKAN_SEN_PERIOD = tenkan
|
|
16
|
-
const KIJUN_SEN_PERIOD = kijun
|
|
17
|
-
const SENKOU_SPAN_A_PERIOD = KIJUN_SEN_PERIOD-TENKAN_SEN_PERIOD
|
|
18
|
-
const SENKOU_SPAN_B_PERIOD = senkou
|
|
19
|
-
const { high, low, close } = data
|
|
20
|
-
const tenkanSen = calculateAverage(BigNumber, high, low, TENKAN_SEN_PERIOD)
|
|
21
|
-
const kijunSen = calculateAverage(BigNumber, high, low, KIJUN_SEN_PERIOD)
|
|
22
|
-
const senkouSpanA = calculateSenkouSpanA(tenkanSen, kijunSen, SENKOU_SPAN_A_PERIOD, KIJUN_SEN_PERIOD)
|
|
23
|
-
const senkouSpanB = calculateSenkouSpanB(BigNumber, high, low, SENKOU_SPAN_B_PERIOD, KIJUN_SEN_PERIOD)
|
|
24
|
-
const chikouSpan = calculateChikouSpan(close, KIJUN_SEN_PERIOD)
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
conversion_line: tenkanSen,
|
|
28
|
-
base_line: kijunSen,
|
|
29
|
-
leading_span_a: senkouSpanA,
|
|
30
|
-
leading_span_b: senkouSpanB,
|
|
31
|
-
lagging_span: chikouSpan
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const calculateAverage = (BigNumber, high, low, period) => {
|
|
36
|
-
|
|
37
|
-
return high.slice(0, high.length - period + 1).map((_, i) => {
|
|
38
|
-
const highSlice = high.slice(i, i + period)
|
|
39
|
-
const lowSlice = low.slice(i, i + period)
|
|
40
|
-
return BigNumber.maximum(...highSlice).plus(BigNumber.minimum(...lowSlice)).dividedBy(2)
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const calculateSenkouSpanA = (tenkanSen, kijunSen, period, slice) => {
|
|
45
|
-
const spanA = tenkanSen.slice(period).map((value, i) =>
|
|
46
|
-
i < kijunSen.length ? value.plus(kijunSen[i]).dividedBy(2) : null
|
|
47
|
-
).filter(val => val !== null)
|
|
48
|
-
|
|
49
|
-
return spanA.slice(0, (spanA.length - slice)+1)
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const calculateSenkouSpanB = (BigNumber, high, low, period, slice) => {
|
|
53
|
-
let spanB = high.slice(period).map((_, i) => { // Adjusted slicing
|
|
54
|
-
const highSlice = high.slice(i, i + period)
|
|
55
|
-
const lowSlice = low.slice(i, i + period)
|
|
56
|
-
return BigNumber.maximum(...highSlice).plus(BigNumber.minimum(...lowSlice)).dividedBy(2)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
return spanB.slice(0, (spanB.length -slice)+2)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const calculateChikouSpan = (close, kijunSenPeriod) => close.slice(0, close.length - kijunSenPeriod + 1)
|
|
64
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { getSMA } from './sma.js'
|
|
2
|
-
|
|
3
|
-
export const RelativeVolume = (main, size) => {
|
|
4
|
-
const {ohlcv} = main
|
|
5
|
-
const data = ohlcv['volume']
|
|
6
|
-
const relVolume = getRelativeVolume(main.BigNumber, data, size)
|
|
7
|
-
main.addColumn(`relative_volume_${size}`, relVolume)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const getRelativeVolume = (BigNumber, data, size = 10) => {
|
|
11
|
-
const sma = getSMA(BigNumber, data, size)
|
|
12
|
-
|
|
13
|
-
return data.map((v, i) => {
|
|
14
|
-
if (i === 0 || !sma[i - 2]) return NaN
|
|
15
|
-
// Avoid division by zero
|
|
16
|
-
if (sma[i - 2].isZero()) return NaN
|
|
17
|
-
return v.dividedBy(sma[i - 2])
|
|
18
|
-
}).filter(v => !Number.isNaN(v))
|
|
19
|
-
}
|
package/src/oscillators/mfi.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export const MFI = (main, period = 14) => {
|
|
2
|
-
const {ohlcv} = main
|
|
3
|
-
const mfi = getMFI(main.BigNumber, ohlcv, period)
|
|
4
|
-
main.addColumn(`mfi_${period}`, mfi)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const getMFI = (BigNumber, ohlcv, period = 14) => {
|
|
8
|
-
const { high, low, close, volume } = ohlcv;
|
|
9
|
-
const zero = BigNumber(0)
|
|
10
|
-
const hundred = BigNumber(100)
|
|
11
|
-
const one = BigNumber(1)
|
|
12
|
-
const typicalPrices = [] // Typical price = (high + low + close) / 3
|
|
13
|
-
const rawMoneyFlows = [] // Raw money flow = typical price * volume
|
|
14
|
-
const positiveMoneyFlows = [] // Positive money flow
|
|
15
|
-
const negativeMoneyFlows = [] // Negative money flow
|
|
16
|
-
const moneyFlowRatios = [] // Money flow ratio = (14-day positive money flow) / (14-day negative money flow)
|
|
17
|
-
const moneyFlowIndexes = [] // Money flow index = 100 - (100 / (1 + money flow ratio))
|
|
18
|
-
|
|
19
|
-
// Calculate typical prices and raw money flows
|
|
20
|
-
for (let i = 0; i < close.length; i++) {
|
|
21
|
-
const typicalPrice = high[i].plus(low[i]).plus(close[i]).dividedBy(3);
|
|
22
|
-
const rawMoneyFlow = typicalPrice.times(volume[i]);
|
|
23
|
-
|
|
24
|
-
typicalPrices.push(typicalPrice)
|
|
25
|
-
rawMoneyFlows.push(rawMoneyFlow)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Calculate positive and negative money flows
|
|
29
|
-
for (let i = 1; i < typicalPrices.length; i++) {
|
|
30
|
-
if (typicalPrices[i].isGreaterThan(typicalPrices[i - 1])) {
|
|
31
|
-
positiveMoneyFlows.push(rawMoneyFlows[i])
|
|
32
|
-
negativeMoneyFlows.push(zero)
|
|
33
|
-
} else if (typicalPrices[i].isLessThan(typicalPrices[i - 1])) {
|
|
34
|
-
positiveMoneyFlows.push(zero)
|
|
35
|
-
negativeMoneyFlows.push(rawMoneyFlows[i])
|
|
36
|
-
} else {
|
|
37
|
-
positiveMoneyFlows.push(zero)
|
|
38
|
-
negativeMoneyFlows.push(zero)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Calculate money flow ratios
|
|
43
|
-
for (let i = period; i <= positiveMoneyFlows.length; i++) {
|
|
44
|
-
const positiveMoneyFlowSlice = positiveMoneyFlows.slice(i - period, i)
|
|
45
|
-
const negativeMoneyFlowSlice = negativeMoneyFlows.slice(i - period, i)
|
|
46
|
-
|
|
47
|
-
const positiveMoneyFlowSum = positiveMoneyFlowSlice.reduce((sum, value) => sum.plus(value), zero)
|
|
48
|
-
const negativeMoneyFlowSum = negativeMoneyFlowSlice.reduce((sum, value) => sum.plus(value), zero)
|
|
49
|
-
|
|
50
|
-
const moneyFlowRatio = positiveMoneyFlowSum.dividedBy(negativeMoneyFlowSum)
|
|
51
|
-
moneyFlowRatios.push(moneyFlowRatio)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Calculate money flow indexes
|
|
55
|
-
for (let i = 0; i < moneyFlowRatios.length; i++) {
|
|
56
|
-
const moneyFlowIndex = hundred.minus(hundred.dividedBy(one.plus(moneyFlowRatios[i])))
|
|
57
|
-
moneyFlowIndexes.push(moneyFlowIndex)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return moneyFlowIndexes
|
|
61
|
-
};
|
|
62
|
-
|
package/test/fetchLiveData.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const apiRoot = 'https://nasdaq.jaimelias.workers.dev/api'
|
|
3
|
-
const convertCurrencyToFloat = str => parseFloat(str.replace(/[,$]/g, ''))
|
|
4
|
-
|
|
5
|
-
export const getOHLCV = async (symbol, limit) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const oneDay = await (getOneDayOHLCV(symbol, limit))
|
|
9
|
-
const latest = await getLatestOHLCV(symbol)
|
|
10
|
-
|
|
11
|
-
return [...oneDay, ...latest]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const getOneDayOHLCV = async (symbol, limit) => {
|
|
15
|
-
|
|
16
|
-
const {fromDate, toDate} = getDateRange(limit)
|
|
17
|
-
const response = await fetch(`${apiRoot}/quote/${symbol}/chart?assetclass=stocks&fromdate=${fromDate}&todate=${toDate}`)
|
|
18
|
-
const data = await response.json()
|
|
19
|
-
const {chart} = data.data
|
|
20
|
-
const ohlcv = chart.map(({z, x})=> ({
|
|
21
|
-
open: convertCurrencyToFloat(z.open),
|
|
22
|
-
high: convertCurrencyToFloat(z.high),
|
|
23
|
-
low: convertCurrencyToFloat(z.low),
|
|
24
|
-
close: convertCurrencyToFloat(z.close),
|
|
25
|
-
volume: convertCurrencyToFloat(z.volume),
|
|
26
|
-
timestamp: x,
|
|
27
|
-
date: new Date(x).toDateString().slice(0, 10)
|
|
28
|
-
}))
|
|
29
|
-
|
|
30
|
-
return ohlcv
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const getLatestOHLCV = async (symbol) => {
|
|
34
|
-
|
|
35
|
-
const response = await fetch(`${apiRoot}/quote/${symbol}/chart?assetClass=stocks`)
|
|
36
|
-
const data = await response.json()
|
|
37
|
-
const {chart, lastSalePrice, volume} = data.data
|
|
38
|
-
const allValues = chart.map(o => convertCurrencyToFloat(o.z.value))
|
|
39
|
-
const timestamp = chart[chart.length -1].x
|
|
40
|
-
|
|
41
|
-
return [{
|
|
42
|
-
open: allValues[0],
|
|
43
|
-
high: Math.max(...allValues),
|
|
44
|
-
low: Math.min(...allValues),
|
|
45
|
-
close: convertCurrencyToFloat(lastSalePrice),
|
|
46
|
-
volume: convertCurrencyToFloat(volume),
|
|
47
|
-
timestamp,
|
|
48
|
-
date: new Date(chart[chart.length -1].x).toDateString().slice(0, 10)
|
|
49
|
-
}]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const getDateRange = limit => {
|
|
53
|
-
const toDate = new Date().toISOString().slice(0, 10) // Get today's date in yyyy-mm-dd format
|
|
54
|
-
|
|
55
|
-
const fromDate = new Date()
|
|
56
|
-
fromDate.setDate(fromDate.getDate() - limit)
|
|
57
|
-
const fromDateFormatted = fromDate.toISOString().slice(0, 10) // Get the date limit number of days ago in yyyy-mm-dd format
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return { fromDate: fromDateFormatted, toDate }
|
|
61
|
-
}
|
package/test/test.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import OHLCV_INDICATORS from '../index.js'
|
|
2
|
-
import { getOHLCV } from './fetchLiveData.js'
|
|
3
|
-
|
|
4
|
-
const indicators = new OHLCV_INDICATORS()
|
|
5
|
-
const {BigNumber, VolumeProfile} = indicators
|
|
6
|
-
|
|
7
|
-
const TEST = async () => {
|
|
8
|
-
|
|
9
|
-
const unparsedOHLCV = await getOHLCV('ADMA', 200)
|
|
10
|
-
|
|
11
|
-
indicators
|
|
12
|
-
.init(unparsedOHLCV)
|
|
13
|
-
.EMA(21)
|
|
14
|
-
.EMA(9, 'ema21')
|
|
15
|
-
.SMA(200)
|
|
16
|
-
.SMA(100, 'sma_200')
|
|
17
|
-
.MACD(12, 26, 9)
|
|
18
|
-
.BollingerBands(20, 2)
|
|
19
|
-
.IchimokuCloud(9, 26, 52)
|
|
20
|
-
.RSI(14)
|
|
21
|
-
.MFI(14)
|
|
22
|
-
.RelativeVolume(10)
|
|
23
|
-
.RelativeVolume(20)
|
|
24
|
-
.crossPairs([{fast: 'ema_9', slow: 'ema_21'}, {fast: 'close', slow: 'sma_200'}, {fast: 'rsi_14', slow: 70}])
|
|
25
|
-
|
|
26
|
-
console.log(indicators.getLastValues())
|
|
27
|
-
//console.log(VolumeProfile(BigNumber, indicators.getData(), 5))
|
|
28
|
-
|
|
29
|
-
const histogram = indicators.getData().macd_histogram
|
|
30
|
-
const macdHistogramUp = isMacdHistogramUp({histogram, slice: 4})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const isMacdHistogramUp = ({histogram, slice=4}) => {
|
|
34
|
-
|
|
35
|
-
histogram = histogram.slice(-slice)
|
|
36
|
-
const histogramDiff = histogram.slice(1).map((value, index) => value - histogram[index])
|
|
37
|
-
const condition1 = histogram[histogram.length -1] > 0
|
|
38
|
-
const condition2 = histogram[histogram.length -1] > histogram[histogram.length -2]
|
|
39
|
-
const condition3 = histogramDiff.filter(diff => diff > 0).length > histogramDiff.filter(diff => diff < 0).length
|
|
40
|
-
|
|
41
|
-
if(condition1 && condition2 && condition3)
|
|
42
|
-
{
|
|
43
|
-
return true
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return false
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
TEST()
|