UNPKG

indicatorts

Version:

Stock technical indicators and strategies in TypeScript for browser and server programs.

3 lines (2 loc) 29.1 kB
function b(...e){if(e.length>0){let r=e[0].length;for(let o=1;o<e.length;o++)if(e[o].length!==r)throw new Error(`values length at ${o} not ${r}`)}}function L(e){return e.map(r=>Math.abs(r))}function C(e,r){b(e,r);let o=new Array(e.length);for(let t=0;t<o.length;t++)o[t]=e[t]+r[t];return o}function M(e,r){let o=new Array(r.length);for(let t=0;t<r.length;t++)o[t]=r[t]+e;return o}function l(e,r){b(e,r);let o=new Array(e.length);for(let t=0;t<o.length;t++)o[t]=e[t]/r[t];return o}function R(e,r){let o=new Array(r.length);for(let t=0;t<r.length;t++)o[t]=r[t]/e;return o}function h(e,r){b(e,r);let o=new Array(e.length);for(let t=0;t<o.length;t++)o[t]=e[t]*r[t];return o}function p(e,r){let o=new Array(r.length);for(let t=0;t<o.length;t++)o[t]=r[t]*e;return o}function u(e,r){b(e,r);let o=new Array(e.length);for(let t=0;t<o.length;t++)o[t]=e[t]-r[t];return o}function ur(e,r){let o=new Array(r.length);for(let t=0;t<r.length;t++)o[t]=r[t]-e;return o}function O(e,r,o){let t=new Array(o.length);for(let i=0;i<t.length;i++)i<e?t[i]=r:t[i]=o[i-e];return t}function F(e,r){return O(e,0,r)}function Ct(e,r,o){let t=o.length,i=Array(t).fill(r);for(let n=e;n<t;n++){let m=(n-e+t)%t;i[m]=o[n]}return i}function ge(e,r){return Ct(e,0,r)}function E(e,r){return u(r,F(e,r))}function de(e){return e.map(r=>r>=0?1:-1)}function At(...e){b(...e);let r=new Array(e[0].length);for(let o=0;o<r.length;o++){r[o]=new Array(e.length);for(let t=0;t<r[o].length;t++)r[o][t]=e[t][o]}return r}function V(...e){return At(...e).map(r=>Math.max(...r))}function U(e,r){let o=Math.pow(10,e);return Math.round(r*o)/o}function ar(e,r){return r.map(o=>U(e,o))}function T(e,r,o){let t=new Array((r-e)/o);for(let i=0;i<t.length;i++)t[i]=e+o*i;return t}function be(e,r){return e.map(o=>Math.pow(o,r))}function xe(e){return e.map(r=>Math.sqrt(r))}var x=(t=>(t[t.SELL=-1]="SELL",t[t.HOLD=0]="HOLD",t[t.BUY=1]="BUY",t))(x||{});function lr(e){return e.map(r=>r===1?-1:r===-1?1:0)}function he(e,r){b(e,r);let o=new Array(e.length),t=1,i=t,n=0;for(let m=0;m<o.length;m++)r[m]===1?i>0&&(n=i/e[m],i=0):r[m]===-1&&n>0&&(i=n*e[m],n=0),o[m]=(n*e[m]+i-t)/t;return o}function dr(e,r){let o=new Array(r.length);for(let t=0;t<o.length;t++){let i=r[t].strategy(e),n=he(e.closings,i);o[t]={info:r[t],gain:n[n.length-1],lastAction:i[i.length-1]}}return o.sort((t,i)=>i.gain-t.gain),o}var yt=(n=>(n[n.SYMBOL=0]="SYMBOL",n[n.NAME=1]="NAME",n[n.STRATEGY=2]="STRATEGY",n[n.GAIN=3]="GAIN",n[n.ACTION=4]="ACTION",n))(yt||{});function xr(e,r,o){let t=[];switch(r){case 0:t=e.sort((i,n)=>i.companyInfo.symbol.localeCompare(n.companyInfo.symbol));break;case 1:t=e.sort((i,n)=>i.companyInfo.name.localeCompare(n.companyInfo.name));break;case 2:t=e.sort((i,n)=>i.strategyResults[0].info.name.localeCompare(n.strategyResults[0].info.name));break;case 3:t=e.sort((i,n)=>i.strategyResults[0].gain-n.strategyResults[0].gain);break;case 4:t=e.sort((i,n)=>i.strategyResults[0].lastAction-n.strategyResults[0].lastAction);break}return o||(t=t.reverse()),t}function Ce(e){return Array(e.closings.length).fill(1)}var St={period:2};function d(e,r={}){let{period:o}={...St,...r},t=new Array(e.length),i=0;for(let n=0;n<e.length;n++)i+=e[n],n>=o?(i-=e[n-o],t[n]=i/o):t[n]=i/(n+1);return t}var Y={fast:5,slow:34};function Ae(e,r,o={}){let{fast:t,slow:i}={...Y,...o},n=R(2,C(r,e)),m=d(n,{period:t}),s=d(n,{period:i});return u(m,s)}function ye(e,r={}){let o={...Y,...r};return Ae(e.highs,e.lows,o).map(i=>i>0?1:i<0?-1:0)}var G={short:9,medium:26,long:52,close:26},W=({period:e,highs:r,lows:o,projection:t=0})=>(i,n,m)=>{if(m<e-1)return[...i,0];let s=m+1-e,c=m-t+1,a=Math.max(...r.slice(s,c)),f=Math.min(...o.slice(s,c));return[...i,(a+f)/2]},Rt=({highs:e,lows:r,short:o})=>e.reduce(W({period:o,highs:e,lows:r}),[]),wt=({highs:e,lows:r,medium:o})=>e.reduce(W({period:o,highs:e,lows:r}),[]),Mt=({tenkanSen:e,kijunSen:r,medium:o})=>{let t=new Array(r.length+o).fill(0);return r.forEach((i,n)=>{i&&(t[n+o]=(i+e[n])/2)}),t},Dt=({highs:e,lows:r,long:o,medium:t})=>new Array(e.length+t).fill(0).reduce(W({period:o+t,highs:e,lows:r,projection:t}),[]);function Se(e,r,o,t={}){b(e,r,o);let{short:i,medium:n,long:m,close:s}={...G,...t},c=Rt({highs:e,lows:r,short:i}),a=wt({highs:e,lows:r,medium:n});return{tenkan:c,kijun:a,ssa:Mt({tenkanSen:c,kijunSen:a,medium:n}),ssb:Dt({highs:e,lows:r,medium:n,long:m}),laggingSpan:ge(s,o)}}function Re(e,r={}){let o={...G,...r},t=Se(e.highs,e.lows,e.closings,o),i=new Array(t.kijun.length);for(let n=0;n<i.length;n++)t.ssa[n]>t.ssb[n]?i[n]=1:t.ssa[n]<t.ssb[n]?i[n]=-1:i[n]=0;return i}var Lt={period:4};function j(e,r={}){let{period:o}={...Lt,...r},t=new Array(e.length),i=0;for(let n=0;n<e.length;n++){let m=n+1;n<o?i+=e[n]:(i=t[n-1]*(o-1)+e[n],m=o),t[n]=i/m}return t}var vt={period:14};function we(e,r={}){let{period:o}={...vt,...r},t=new Array(e.length),i=new Array(e.length);t[0]=i[0]=0;for(let a=1;a<e.length;a++){let f=e[a]-e[a-1];f>0?(t[a]=f,i[a]=0):(i[a]=-f,t[a]=0)}let n=j(t,{period:o}),m=j(i,{period:o}),s=new Array(e.length),c=new Array(e.length);s[0]=c[0]=0;for(let a=1;a<e.length;a++)c[a]=n[a]/m[a],s[a]=100-100/(1+c[a]);return s}function Me(e){let r=we(e.closings,{period:2}),o=new Array(r.length);for(let t=0;t<o.length;t++)r[t]<10?o[t]=1:r[t]>90?o[t]=-1:o[t]=0;return o}var P=class e{constructor(){this.root=null}insert(r){let o={value:r,left:null,right:null};if(this.root===null){this.root=o;return}let t=this.root,i=!1;for(;!i;)o.value<=t.value?t.left===null?(t.left=o,i=!0):t=t.left:t.right===null?(t.right=o,i=!0):t=t.right}remove(r){let o={node:this.root,parent:null};for(;o.node!==null;){if(r===o.node.value)return this.removeNode(o),!0;o.parent=o.node,r<o.node.value?o.node=o.node.left:o.node=o.node.right}return!1}min(){let r=e.minNode(this.root);if(r.node===null)throw new Error("Tree empty");return r.node.value}max(){let r=e.maxNode(this.root);if(r.node===null)throw new Error("Tree empty");return r.node?.value}removeNode(r){if(r.node!==null)if(r.node.left!==null&&r.node.right!==null){let o=e.minNode(r.node.right);o.parent===null&&(o.parent=r.node),this.removeNode(o),o.node!==null&&(r.node.value=o.node.value)}else{let o=null;r.node.left!==null?o=r.node.left:o=r.node.right,r.parent===null?this.root=o:r.parent.left===r.node?r.parent.left=o:r.parent.right=o}}static minNode(r){let o={node:null,parent:null};if(r!==null)for(o.node=r;o.node.left!==null;)o.parent=o.node,o.node=o.node.left;return o}static maxNode(r){let o={node:null,parent:null};if(r!==null)for(o.node=r;o.node.right!==null;)o.parent=o.node,o.node=o.node.right;return o}};var It={period:4};function S(e,r={}){let{period:o}={...It,...r},t=new Array(e.length),i=new P;for(let n=0;n<e.length;n++)i.insert(e[n]),n>=o&&i.remove(e[n-o]),t[n]=i.min();return t}var Ot={period:4};function y(e,r={}){let{period:o}={...Ot,...r},t=new Array(e.length),i=new P;for(let n=0;n<e.length;n++)i.insert(e[n]),n>=o&&i.remove(e[n-o]),t[n]=i.max();return t}var K={kPeriod:14,dPeriod:3};function De(e,r,o,t={}){let{kPeriod:i,dPeriod:n}={...K,...t},m=y(e,{period:i}),s=S(r,{period:i}),c=p(100,l(u(o,s),u(m,s))),a=d(c,{period:n});return{k:c,d:a}}function Le(e,r={}){let o={...K,...r},t=De(e.highs,e.lows,e.closings,o),i=new Array(t.k.length);for(let n=0;n<i.length;n++)t.k[n]>=80&&t.d[n]>=80?i[n]=-1:t.k[n]<=20&&t.d[n]<=20?i[n]=1:i[n]=0;return i}var X={period:14};function ve(e,r,o,t={}){let{period:i}={...X,...t},n=y(e,{period:i}),m=S(r,{period:i});return p(-100,l(u(n,o),u(n,m)))}function Ie(e,r={}){let o={...X,...r};return ve(e.highs,e.lows,e.closings,o).map(i=>i<=-80?1:i>=-20?-1:0)}var Bt={period:12};function g(e,r={}){let{period:o}={...Bt,...r},t=new Array(e.length);if(t.length>0){let i=2/(1+o),n=1-i;t[0]=e[0];for(let m=1;m<t.length;m++)t[m]=e[m]*i+t[m-1]*n}return t}var J={fast:14,slow:30};function Oe(e,r={}){let{fast:o,slow:t}={...J,...r},i=g(e,{period:o}),n=g(e,{period:t});return u(i,n)}function Be(e,r={}){let{fast:o,slow:t}={...J,...r},i=Oe(e.closings,{fast:o,slow:t}),n=new Array(i.length);for(let m=0;m<n.length;m++)i[m]>0?n[m]=1:i[m]<0?n[m]=-1:n[m]=0;return n}function _(e){let r=new Array(e.length);if(e.length>0){let o=null,t=0;for(let i=0;i<e.length;i++)o!==e[i]?(o=e[i],t=0):t++,r[i]=t}return r}var Q={period:25};function Ee(e,r,o={}){b(e,r);let{period:t}={...Q,...o},i=_(y(e,{period:t})),n=_(S(r,{period:t})),m=p(100,R(t,M(t,p(-1,i)))),s=p(100,R(t,M(t,p(-1,n))));return{up:m,down:s}}function Pe(e,r={}){let o={...Q,...r},t=Ee(e.highs,e.lows,o),i=new Array(t.up.length);for(let n=0;n<i.length;n++)t.up[n]>t.down[n]?i[n]=1:t.down[n]>t.up[n]?i[n]=-1:i[n]=0;return i}function ke(e,r,o,t){return l(u(t,e),u(r,o))}function Fe(e){return ke(e.openings,e.highs,e.lows,e.closings).map(o=>o>0?1:o<0?-1:0)}function Et(e,r){b(e,r);let o=0,t=0,i=0,n=0;for(let a=0;a<e.length;a++)o+=e[a],t+=e[a]*e[a],i+=r[a],n+=e[a]*r[a];let m=e.length,s=(m*n-o*i)/(m*t-o*o),c=(i-s*o)/m;return{m:s,b:c}}function N(e,r,o){b(r,o);let t=new Array(r.length),i=new Array(r.length),n=0,m=0,s=0,c=0;for(let a=0;a<r.length;a++){n+=r[a],m+=r[a]*r[a],s+=o[a],c+=r[a]*o[a];let f=a+1;a>=e&&(n-=r[a-e],m-=r[a-e]*r[a-e],s-=o[a-e],c-=r[a-e]*o[a-e],f=e),a>0?(t[a]=(f*c-n*s)/(f*m-n*n),i[a]=(s-t[a]*n)/f):(t[a]=0,i[a]=0)}return{m:t,b:i}}function Te(e,r){let o=Et(e,r);return M(o.b,p(o.m,e))}function Ve(e,r,o){let t=N(e,r,o);return C(h(t.m,r),t.b)}var Vo={period:4};function Ne(e){let r=T(0,e.length,1),o=Te(r,e);return p(100,l(u(e,o),e))}var Pt={period:4};function No(e,r={}){let{period:o}={...Pt,...r},t=T(0,e.length,1),i=Ve(o,t,e);return p(100,l(u(e,i),e))}function qe(e){return Ne(e.closings).map(o=>o>0?1:o<0?-1:0)}var $={rPeriod:9,kPeriod:3,dPeriod:3};function He(e,r,o,t={}){let{rPeriod:i,kPeriod:n,dPeriod:m}={...$,...t},s=y(e,{period:i}),c=S(r,{period:i}),a=p(100,l(u(o,c),u(s,c))),f=d(a,{period:n}),w=d(f,{period:m}),I=u(p(3,f),p(2,w));return{k:f,d:w,j:I}}function Ue(e,r={}){let o={...$,...r},t=He(e.highs,e.lows,e.closings,o),i=new Array(t.k.length);for(let n=0;n<i.length;n++)t.k[n]>t.d[n]&&t.k[n]<=20?i[n]=1:t.k[n]<t.d[n]&&t.k[n]>=80?i[n]=-1:i[n]=0;return i}var z={fast:12,slow:26,signal:9};function Ye(e,r={}){let{fast:o,slow:t,signal:i}={...z,...r},n=g(e,{period:o}),m=g(e,{period:t}),s=u(n,m),c=g(s,{period:i});return{macdLine:s,signalLine:c}}function Ge(e,r={}){let o={...z,...r},t=Ye(e.closings,o),i=new Array(t.macdLine.length);for(let n=0;n<i.length;n++)t.macdLine[n]>t.signalLine[n]?i[n]=1:t.macdLine[n]<t.signalLine[n]?i[n]=-1:i[n]=0;return i}var Z=(t=>(t[t.FALLING=-1]="FALLING",t[t.STABLE=0]="STABLE",t[t.RISING=1]="RISING",t))(Z||{});var ee={step:.02,max:.2};function We(e,r,o,t={}){b(e,r,o);let{step:i,max:n}={...ee,...t},m=new Array(e.length),s=new Array(e.length);m[0]=-1,s[0]=e[0];let c=i,a=r[0];for(let f=1;f<s.length;f++){s[f]=s[f-1]-(s[f-1]-a)*c,m[f-1]===-1?(s[f]=Math.max(s[f],e[f-1]),f>1&&(s[f]=Math.max(s[f],e[f-2])),e[f]>=s[f]&&(s[f]=a)):(s[f]=Math.min(s[f],r[f-1]),f>1&&(s[f]=Math.min(s[f],r[f-2])),r[f]<=s[f]&&(s[f]=a));let w=a;s[f]>o[f]?(m[f]=-1,a=Math.min(a,r[f])):(m[f]=1,a=Math.max(a,e[f])),m[f]!==m[f-1]?c=i:w!==a&&c<n&&(c+=i)}return{trends:m,psarResult:s}}function je(e,r={}){let o={...ee,...r};return We(e.highs,e.lows,e.closings,o).trends.map(i=>{switch(i){case-1:return-1;case 1:return 1;case 0:return 0;default:return 0}})}function k(e,r,o){return R(3,C(C(e,r),o))}function Ke(e){let r=k(e.highs,e.lows,e.closings),o=new Array(r.length);o[0]=0;for(let t=1;t<o.length;t++)r[t]>r[t-1]?o[t]=1:r[t]<r[t-1]?o[t]=-1:o[t]=0;return o}var kt={period:4};function A(e,r={}){let{period:o}={...kt,...r},t=new Array(e.length),i=0;for(let n=0;n<e.length;n++)i+=e[n],n>=o&&(i-=e[n-o]),t[n]=i;return t}var te={period:14};function Xe(e,r,o,t={}){b(e,r,o);let{period:i}={...te,...t},n=F(1,o),m=L(u(e,F(1,r))),s=L(u(r,F(1,e))),c=A(m,{period:i}),a=A(s,{period:i}),f=V(u(e,r),L(u(e,n)),L(u(r,n))),w=A(f,{period:i}),I=l(c,w),D=l(a,w);return{plus:I,minus:D}}function Je(e,r={}){let o={...te,...r},t=Xe(e.highs,e.lows,e.closings,o),i=new Array(t.plus.length);for(let n=0;n<i.length;n++)t.plus[n]>t.minus[n]?i[n]=1:t.plus[n]<t.minus[n]?i[n]=-1:i[n]=0;return i}var re={period:20,multiplier:4};function _e(e,r,o,t={}){b(e,r,o);let{period:i,multiplier:n}={...re,...t},m=l(u(e,r),C(e,r)),s=d(h(e,M(1,p(n,m))),{period:i}),c=d(o,{period:i}),a=d(h(r,M(1,p(-1*n,m))),{period:i});return{upper:s,middle:c,lower:a}}function Qe(e,r={}){let o={...re,...r},t=_e(e.highs,e.lows,e.closings,o),i=new Array(t.upper.length);for(let n=0;n<i.length;n++)e.closings[n]>=t.upper[n]?i[n]=1:i[n]=-1;return i}var Ft={period:4};function $e(e,r={}){let{period:o}={...Ft,...r},t=new Array(e.length),i=d(e,{period:o});for(let n=0;n<e.length;n++)if(t[n]=0,n>=o-1){let m=0;for(let s=n-(o-1);s<=n;s++)m+=(e[s]-i[n])*(e[s]-i[n]);t[n]=Math.sqrt(m/o)}return t}var oe={period:20};function ze(e,r={}){let{period:o}={...oe,...r},t=p(2,$e(e,{period:o})),i=d(e,{period:o}),n=C(i,t),m=u(i,t);return{upper:n,middle:i,lower:m}}function Ze(e,r={}){let o={...oe,...r},t=ze(e.closings,o),i=new Array(t.upper.length);for(let n=0;n<i.length;n++)e.closings[n]>t.upper[n]?i[n]=-1:e.closings[n]<t.lower[n]?i[n]=1:i[n]=0;return i}var ne={period:14,smooth:3};function et(e,r,o,t={}){let{period:i,smooth:n}={...ne,...t},m=T(0,o.length,1),s=N(i,m,e),c=N(i,m,r),a=C(e,h(s.m,m)),f=C(r,h(c.m,m)),w=y(a,{period:i}),I=S(f,{period:i}),D=l(p(100,u(o,I)),u(w,I)),ht=g(D,{period:n});return{poResult:D,spoResult:ht}}function tt(e,r={}){let o={...ne,...r},t=et(e.highs,e.lows,e.closings,o),i=new Array(t.poResult.length);for(let n=0;n<i.length;n++)t.poResult[n]>t.spoResult[n]?i[n]=1:t.poResult[n]<t.spoResult[n]?i[n]=-1:i[n]=0;return i}var ie={period:20};function rt(e,r,o,t,i={}){let{period:n}={...ie,...i},m=l(u(u(o,r),u(e,o)),u(e,r)),s=h(m,t);return l(A(s,{period:n}),A(t,{period:n}))}function ot(e,r={}){let o={...ie,...r};return rt(e.highs,e.lows,e.closings,e.volumes,o).map(i=>i<0?1:i>0?-1:0)}var me={period:14};function nt(e,r,o,t={}){let{period:i}={...me,...t},n=E(1,R(2,C(e,r))),m=l(R(1e8,o),u(e,r));return d(l(n,m),{period:i})}function it(e,r={}){let o={...me,...r};return nt(e.highs,e.lows,e.volumes,o).map(i=>i>0?1:i<0?-1:0)}var se={period:13};function mt(e,r,o={}){let{period:t}={...se,...o};return g(h(E(1,e),r),{period:t})}function st(e,r={}){let o={...se,...r};return mt(e.closings,e.volumes,o).map(i=>i>0?1:i<0?-1:0)}var ue={period:14};function ut(e,r,o,t,i={}){let{period:n}={...ue,...i},m=h(k(e,r,o),t),s=de(E(1,m)),c=h(s,m),a=c.map(D=>D>=0?D:0),f=c.map(D=>D<0?D:0),w=l(A(a,{period:n}),A(p(-1,f),{period:n}));return M(100,p(-100,be(M(1,w),-1)))}function at(e,r={}){let o={...ue,...r};return ut(e.highs,e.lows,e.closings,e.volumes,o).map(i=>i>=80?-1:1)}var ae={start:1e3,period:255};function ft(e,r,o={}){b(e,r);let{start:t}={...ae,...o},i=new Array(e.length);for(let n=0;n<i.length;n++)n===0?i[n]=t:r[n-1]<r[n]?i[n]=i[n-1]:i[n]=i[n-1]+(e[n]-e[n-1])/e[n-1]*i[n-1];return i}function ct(e,r={}){let o={...ae,...r},t=ft(e.closings,e.volumes,o),i=g(t,{period:o.period}),n=new Array(t.length);for(let m=0;m<n.length;m++)t[m]<i[m]?n[m]=1:t[m]>i[m]?n[m]=-1:n[m]=0;return n}var fe={period:14};function lt(e,r,o={}){let{period:t}={...fe,...o};return l(A(h(e,r),{period:t}),A(r,{period:t}))}function pt(e,r={}){let o={...fe,...r},t=lt(e.closings,e.volumes,o);return u(t,e.closings).map(n=>n>0?1:n<0?-1:0)}var dm=[{name:"Buy Hold",strategy:Ce},{name:"Awesome Oscillator",strategy:ye},{name:"RSI 2",strategy:Me},{name:"Ichimoku Cloud",strategy:Re},{name:"Stochastic Oscillator",strategy:Le},{name:"Williams R",strategy:Ie},{name:"Absolute Price Oscillator (APO)",strategy:Be},{name:"Aroon Strategy",strategy:Pe},{name:"Balance of Power (BOM)",strategy:Fe},{name:"Chande Forecast Oscillator (CFO)",strategy:qe},{name:"KDJ Strategy",strategy:Ue},{name:"MACD Strategy",strategy:Ge},{name:"Parabolic SAR",strategy:je},{name:"Typical Price",strategy:Ke},{name:"Vortex Strategy",strategy:Je},{name:"Acceleration Bands",strategy:Qe},{name:"Bollinger Bands",strategy:Ze},{name:"Projection Oscillator",strategy:tt},{name:"Chaikin Money Flow (CMF)",strategy:ot},{name:"Ease of Movement (EMV)",strategy:it},{name:"Force Index",strategy:st},{name:"Money Flow Index",strategy:at},{name:"Negative Volume Index (NVI)",strategy:ct},{name:"Volume Weighted Average Price",strategy:pt}];function Tt(e){return{strategyInfo:e.info,score:1,minGain:e.gain,maxGain:e.gain,averageGain:e.gain}}function Vt(e,r){e.score++,e.minGain=Math.min(e.minGain,r.gain),e.maxGain=Math.max(e.maxGain,r.gain),e.averageGain=(e.averageGain+r.gain)/2}function xm(e){let r=new Map;for(let t of e){let i=t.strategyResults[0],n=r.get(i.info.name);n!==void 0?Vt(n,i):r.set(i.info.name,Tt(i))}let o=Array.from(r.values());return o.sort((t,i)=>i.score-t.score),o}var Nt=(n=>(n[n.STRATEGY=0]="STRATEGY",n[n.SCORE=1]="SCORE",n[n.MIN=2]="MIN",n[n.MAX=3]="MAX",n[n.AVERAGE=4]="AVERAGE",n))(Nt||{});function hm(e,r,o){let t=[];switch(r){case 0:t=e.sort((i,n)=>i.strategyInfo.name.localeCompare(n.strategyInfo.name));break;case 1:t=e.sort((i,n)=>i.score-n.score);break;case 2:t=e.sort((i,n)=>i.minGain-n.minGain);break;case 3:t=e.sort((i,n)=>i.maxGain-n.maxGain);break;case 4:t=e.sort((i,n)=>i.averageGain-n.averageGain);break}return o||(t=t.reverse()),t}var v=class e{constructor(r,o){this.min=r,this.max=o}getMin(){return this.min}getMax(){return this.max}span(){return this.max-this.min}static merge(r){return r.reduce((o,t)=>new e(Math.min(o.min,t.min),Math.max(o.max,t.max)))}static from(r){return new e(Math.min(...r),Math.max(...r))}};var B=class{constructor(r,o){this.fromDelta=r.getMin(),this.toDelta=o.getMin(),this.multiplier=o.span()/r.span()}scale(r){return(r-this.fromDelta)*this.multiplier+this.toDelta}descale(r){return(r-this.toDelta)/this.multiplier+this.fromDelta}};var qt="black",Ht=1,Ut="red",Yt=1,Gt=30,ce=4,Wt="14px Arial",le=-1,q=new v(0,1),gt=class{constructor(r){let o=document.getElementById(r);if(o===null)throw new Error("Canvas element not found");if(!(o instanceof HTMLCanvasElement))throw new Error("Not a canvas element");this.canvas=o;let t=this.canvas.getContext("2d");if(t===null)throw new Error("Canvas context is null");this.context=t,this.dataSets=new Map,this.dateSetsChanged=!1,this.xScaler=new B(q,q),this.yScaler=new B(q,q),this.xFocus=le,this.canvas.addEventListener("mousemove",i=>this.onMouseMove(i)),this.canvas.addEventListener("mouseout",()=>this.onMouseOut())}add(r){this.dataSets.set(r.legend,r),this.dateSetsChanged=!0}remove(r){let o=this.dataSets.delete(r);return o&&(this.dateSetsChanged=!0),o}draw(){this.dateSetsChanged&&(this.updateScalers(),this.dateSetsChanged=!1),this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.drawDataSets(),this.drawFocus()}drawDataSets(){let r=this.chartHeight();for(let o of this.dataSets.values()){this.context.lineWidth=o.width??Ht;let t=0,i=0;for(let n=0;n<o.values.length;n++){let m=this.xScaler.scale(n),s=r-this.yScaler.scale(o.values[n]);n>0&&(this.context.strokeStyle=this.styleAtIndex(o,n),this.context.beginPath(),this.context.moveTo(t,i),this.context.lineTo(m,s),this.context.stroke()),t=m,i=s}}}styleAtIndex(r,o){return r.style===void 0?qt:Array.isArray(r.style)?r.style[o]:r.style}drawFocus(){this.xFocus!==le&&(this.drawFocusLine(),this.drawFocusedValues())}drawFocusLine(){this.context.strokeStyle=Ut,this.context.lineWidth=Yt,this.context.beginPath(),this.context.moveTo(this.xFocus,0),this.context.lineTo(this.xFocus,this.chartHeight()),this.context.stroke()}drawFocusedValues(){let r=Math.round(this.xScaler.descale(this.xFocus)),o=ce;this.context.font=Wt,this.context.textBaseline="bottom";for(let t of this.dataSets.values())if(r>=0&&r<t.values.length){let i=t.legend+" "+U(2,t.values[r]).toString();this.context.fillStyle=this.styleAtIndex(t,r),this.context.fillText(i,o,this.canvas.height-ce),o+=this.context.measureText(i).width+ce}}chartHeight(){return this.canvas.height-Gt}updateScalers(){this.dataSets.size!==0&&(this.xScaler=new B(new v(0,Math.max(...Array.from(this.dataSets.values(),r=>r.values.length))),new v(0,this.canvas.width)),this.yScaler=new B(v.merge(Array.from(this.dataSets.values(),r=>v.from(r.values))),new v(0,this.chartHeight())))}onMouseMove(r){let o=this.canvas.getBoundingClientRect();this.xFocus=r.clientX-o.left,this.draw()}onMouseOut(){this.xFocus=le,this.draw()}};function Vm(e){return e.toISOString().substring(0,10)}function Nm(e){let r=new Date;return r.setDate(r.getDate()-e),r}function qm(e,r){let o=new Date(e);return o.setDate(o.getDate()+r),o}function Hm(e){return(e.getMonth()+1).toString()+"/"+e.getDate().toString()}function dt(e,r,o,t){let i=l(u(u(o,r),u(e,o)),u(e,r)),n=h(i,t),m=new Array(n.length);for(let s=0;s<m.length;s++)m[s]=n[s],s>0&&(m[s]+=m[s-1]);return m}var jt={fast:3,slow:10};function zm(e,r,o,t,i={}){let{fast:n,slow:m}={...jt,...i},s=dt(e,r,o,t),c=u(g(s,{period:n}),g(s,{period:m}));return{adResult:s,cmoResult:c}}var Kt={fast:12,slow:26,signal:9};function rs(e,r={}){let{fast:o,slow:t,signal:i}={...Kt,...r},n=g(e,{period:o}),m=g(e,{period:t}),s=p(100,l(u(n,m),m)),c=g(s,{period:i}),a=u(s,c);return{ppoResult:s,signal:c,histogram:a}}var Xt={fast:12,slow:26,signal:9};function ms(e,r={}){let{fast:o,slow:t,signal:i}={...Xt,...r},n=g(e,{period:o}),m=g(e,{period:t}),s=p(100,l(u(n,m),m)),c=g(s,{period:i}),a=u(s,c);return{pvoResult:s,signal:c,histogram:a}}var Jt={period:3};function us(e,r={}){let{period:o}={...Jt,...r},t=new Array(e.length);for(let i=0;i<e.length;i++)i<o?t[i]=0:t[i]=(e[i]/e[i-o]-1)*100;return t}var _t={period:20};function Rs(e,r,o,t={}){let{period:i}={..._t,...t},n=k(e,r,o),m=d(n,{period:i}),s=d(L(u(n,m)),{period:i});return l(u(n,m),p(.015,s))}var Qt={period:12};function Ls(e,r={}){let{period:o}={...Qt,...r},t=g(e,{period:o}),i=g(t,{period:o});return u(p(2,t),i)}var $t={emaPeriod:9,miPeriod:25};function Es(e,r,o={}){let{emaPeriod:t,miPeriod:i}={...$t,...o},n=g(u(e,r),{period:t}),m=g(n,{period:t}),s=l(n,m);return A(s,{period:i})}var zt={period:14};function Ts(e,r,o={}){let{period:t}={...zt,...o};return d(u(r,e),{period:t})}var Zt={period:4};function qs(e,r={}){let{period:o}={...Zt,...r},t=0,i=0;return o%2===0?(t=o/2,i=t+1):(t=(o+1)/2,i=t),d(d(e,{period:i}),{period:t})}var er={period:4};function Gs(e,r={}){let{period:o}={...er,...r},t=g(e,{period:o}),i=g(t,{period:o}),n=g(i,{period:o}),m=O(1,n[0],n);return l(u(n,m),m)}var tr={period:2};function Xs(e,r={}){let{period:o}={...tr,...r},t=g(e,{period:o}),i=g(t,{period:o}),n=g(i,{period:o});return C(u(p(3,t),p(3,i)),n)}var pe={period:20};function bt(e,r,o={}){let{period:t}={...pe,...o};return l(A(h(e,r),{period:t}),A(r,{period:t}))}function xt(e,r,o){b(e,r,o);let t=O(1,o[0],o);return V(u(e,r),L(u(e,t)),L(u(r,t)))}var rr={period:14};function H(e,r,o,t={}){let{period:i}={...rr,...t},n=xt(e,r,o),m=d(n,{period:i});return{trLine:n,atrLine:m}}var or={period:90};function Ou(e,r={}){let{period:o}={...or,...r},t=l(u(e.upper,e.lower),e.middle),i=g(t,{period:o});return{width:t,widthEma:i}}var nr={period:22};function Tu(e,r,o,t={}){let{period:i}={...nr,...t},n=H(e,r,o,{period:i}),m=p(3,n.atrLine),s=y(e,{period:i}),c=S(r,{period:i}),a=u(s,m),f=C(c,m);return{long:a,short:f}}var ir={period:4};function Uu(e,r={}){let{period:o}={...ir,...r},t=y(e,{period:o}),i=S(e,{period:o}),n=R(2,C(t,i));return{upper:t,middle:n,lower:i}}var mr={period:20};function Ku(e,r,o,t={}){let{period:i}={...mr,...t},n=H(e,r,o,{period:i}),m=p(2,n.atrLine),s=g(o,{period:i}),c=C(s,m),a=u(s,m);return{middle:s,upper:c,lower:a}}var sr={period:14};function $u(e,r={}){let{period:o}={...sr,...r},t=y(e,{period:o}),i=p(100,l(u(e,t),t)),n=d(h(i,i),{period:o});return xe(n)}function la(e,r){b(e,r);let o=new Array(e.length);o[0]=0;for(let t=1;t<o.length;t++)o[t]=o[t-1],e[t]>e[t-1]?o[t]+=r[t]:e[t]<e[t-1]&&(o[t]-=r[t]);return o}function ba(e,r){let o=O(1,e[0],e),t=h(r,l(u(e,o),o));return A(t,{period:t.length})}function Wa(e,r={}){let o={...pe,...r},t=d(e.closings,o),i=bt(e.closings,e.volumes,o),n=new Array(i.length);for(let m=0;m<n.length;m++)i[m]>t[m]?n[m]=1:i[m]<t[m]?n[m]=-1:n[m]=0;return n}function df(e){return{dates:new Array(e),openings:new Array(e),closings:new Array(e),highs:new Array(e),lows:new Array(e),volumes:new Array(e)}}function bf(e,r){return{dates:[...e.dates,...r.dates],openings:[...e.openings,...r.openings],closings:[...e.closings,...r.closings],highs:[...e.highs,...r.highs],lows:[...e.lows,...r.lows],volumes:[...e.volumes,...r.volumes]}}export{re as ABDefaultConfig,Y as AODefaultConfig,J as APODefaultConfig,rr as ATRDefaultConfig,x as Action,Q as AroonDefaultConfig,oe as BBDefaultConfig,or as BBWDefaultConfig,P as BinarySearchTree,_t as CCIDefaultConfig,nr as CEDefaultConfig,Vo as CFODefaultConfig,ie as CMFDefaultConfig,jt as CMODefaultConfig,gt as Chart,yt as CompanyResultSortBy,ir as DCDefaultConfig,Qt as DEMADefaultConfig,Bt as EMADefaultConfig,me as EMVDefaultConfig,se as FIDefaultConfig,G as IchimokuCloudDefaultConfig,mr as KCDefaultConfig,$ as KDJDefaultConfig,z as MACDDefaultConfig,Pt as MCFODefaultConfig,ue as MFIDefaultConfig,$t as MIDefaultConfig,Ot as MMaxDefaultConfig,It as MMinDefaultConfig,Ft as MSTDDefaultConfig,kt as MSumDefaultConfig,ae as NVIDefaultConfig,v as NumRange,B as NumScaler,ne as PODefaultConfig,Kt as PPODefaultConfig,ee as PSARDefaultConfig,Xt as PVODefaultConfig,zt as QstickDefaultConfig,Lt as RMADefaultConfig,Jt as ROCDefaultConfig,vt as RSIDefaultConfig,St as SMADefaultConfig,dm as STRATEGY_INFOS,K as StochDefaultConfig,Nt as StrategyStatsSortBy,tr as TEMADefaultConfig,Zt as TRIMADefaultConfig,er as TRIXDefaultConfig,Z as Trend,sr as UIDefaultConfig,fe as VWAPDefaultConfig,pe as VWMADefaultConfig,te as VortexDefaultConfig,X as WillrDefaultConfig,_e as ab,Qe as abStrategy,L as abs,Oe as absolutePriceOscillator,Be as absolutePriceOscillatorStrategy,_e as accelerationBands,Qe as accelerationBandsStrategy,dt as accumulationDistribution,dt as ad,C as add,M as addBy,Ae as ao,ye as aoStrategy,Oe as apo,Be as apoStrategy,he as applyActions,Ee as aroon,Pe as aroonStrategy,H as atr,H as averageTrueRange,Ae as awesomeOscillator,ye as awesomeOscillatorStrategy,dr as backtest,ke as balanceOfPower,Fe as balanceOfPowerStrategy,ze as bb,Ze as bbStrategy,Ou as bbw,ze as bollingerBands,Ze as bollingerBandsStrategy,Ou as bollingerBandsWidth,ke as bop,Fe as bopStrategy,Ce as buyAndHoldStrategy,Rs as cci,Tu as ce,Ne as cfo,qe as cfoStrategy,rt as chaikinMoneyFlow,ot as chaikinMoneyFlowStrategy,zm as chaikinOscillator,Ne as chandeForecastOscillator,qe as chandeForecastOscillatorStrategy,Tu as chandelierExit,E as changes,b as checkSameLength,rt as cmf,ot as cmfStrategy,zm as cmo,Rs as communityChannelIndex,xm as computeStrategyStats,bf as concatAssets,Nm as daysAgo,qm as daysLaterFrom,Uu as dc,Ls as dema,l as divide,R as divideBy,Uu as donchianChannel,Ls as doubleExponentialMovingAverage,nt as easeOfMovement,it as easeOfMovementStrategy,g as ema,nt as emv,it as emvStrategy,g as exponentialMovingAverage,de as extractSigns,mt as fi,st as fiStrategy,mt as forceIndex,st as forceIndexStrategy,T as generateNumbers,Se as ichimokuCloud,Re as ichimokuCloudStrategy,Ku as kc,He as kdj,Ue as kdjStrategy,Ku as keltnerChannel,Et as leastSquare,Te as linearRegressionUsingLeastSquare,Ye as macd,Ge as macdStrategy,Es as massIndex,V as max,No as mcfo,ut as mfi,at as mfiStrategy,Es as mi,y as mmax,S as mmin,ut as moneyFlowIndex,at as moneyFlowIndexStrategy,Ye as movingAverageConvergenceDivergence,Ge as movingAverageConvergenceDivergenceStrategy,No as movingChandeForecastOscillator,N as movingLeastSquare,Ve as movingLinearRegressionUsingLeastSquare,y as movingMax,S as movingMin,$e as movingStandardDeviation,A as movingSum,$e as mstd,A as msum,h as multiply,p as multiplyBy,ft as negativeVolumeIndex,ct as negativeVolumeIndexStrategy,df as newAssetWithLength,ft as nvi,ct as nviStrategy,la as obv,la as onBalanceVolume,We as parabolicSAR,je as parabolicSARStrategy,rs as percentagePriceOscillator,ms as percentageVolumeOscillator,et as po,tt as poStrategy,be as pow,rs as ppo,us as priceRateOfChange,et as projectionOscillator,tt as projectionOscillatorStrategy,We as psar,je as psarStrategy,ms as pvo,Ts as qstick,He as randomIndex,we as relativeStrengthIndex,lr as reverseActions,j as rma,us as roc,j as rollingMovingAverage,U as roundDigits,ar as roundDigitsAll,we as rsi,Me as rsi2Strategy,Ct as shiftLeftAndFillBy,ge as shiftLeftBy,O as shiftRightAndFillBy,F as shiftRightBy,d as simpleMovingAverage,_ as since,d as sma,xr as sortCompanyResults,hm as sortStrategyStats,xe as sqrt,De as stoch,Le as stochStrategy,De as stochasticOscillator,Le as stochasticOscillatorStrategy,u as subtract,ur as subtractBy,Xs as tema,Vm as toISODateString,Hm as toMonthAndDay,xt as tr,At as transpose,qs as triangularMovingAverage,qs as trima,Gs as tripleExponentialAverage,Xs as tripleExponentialMovingAverage,Gs as trix,xt as trueRange,k as typicalPrice,Ke as typicalPriceStrategy,k as typprice,Ke as typpriceStrategy,$u as ui,$u as ulcerIndex,ba as volumePriceTrend,lt as volumeWeightedAveragePrice,pt as volumeWeightedAveragePriceStrategy,bt as volumeWeightedMovingAverage,Wa as volumeWeightedMovingAverageStrategy,Xe as vortex,Je as vortexStrategy,ba as vpt,lt as vwap,pt as vwapStrategy,bt as vwma,Wa as vwmaStrategy,Ie as willRStrategy,ve as williamsR,Ie as williamsRStrategy,ve as willr}; //# sourceMappingURL=index.js.map