UNPKG

indicatorts

Version:

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

3 lines (2 loc) 33.4 kB
"use strict";var ce=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var Zt=Object.prototype.hasOwnProperty;var er=(e,r)=>{for(var o in r)ce(e,o,{get:r[o],enumerable:!0})},tr=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of zt(r))!Zt.call(e,i)&&i!==o&&ce(e,i,{get:()=>r[i],enumerable:!(t=$t(r,i))||t.enumerable});return e};var rr=e=>tr(ce({},"__esModule",{value:!0}),e);var Qr={};er(Qr,{ABDefaultConfig:()=>ee,AODefaultConfig:()=>U,APODefaultConfig:()=>K,ATRDefaultConfig:()=>Wt,Action:()=>x,AroonDefaultConfig:()=>J,BBDefaultConfig:()=>te,BBWDefaultConfig:()=>jt,BinarySearchTree:()=>P,CCIDefaultConfig:()=>Vt,CEDefaultConfig:()=>Kt,CFODefaultConfig:()=>lr,CMFDefaultConfig:()=>oe,CMODefaultConfig:()=>Pt,Chart:()=>dt,CompanyResultSortBy:()=>yt,DCDefaultConfig:()=>Xt,DEMADefaultConfig:()=>Nt,EMADefaultConfig:()=>Lt,EMVDefaultConfig:()=>ne,FIDefaultConfig:()=>ie,IchimokuCloudDefaultConfig:()=>Y,KCDefaultConfig:()=>Jt,KDJDefaultConfig:()=>_,MACDDefaultConfig:()=>Q,MCFODefaultConfig:()=>It,MFIDefaultConfig:()=>me,MIDefaultConfig:()=>qt,MMaxDefaultConfig:()=>Dt,MMinDefaultConfig:()=>Mt,MSTDDefaultConfig:()=>Bt,MSumDefaultConfig:()=>Ot,NVIDefaultConfig:()=>se,NumRange:()=>v,NumScaler:()=>O,PODefaultConfig:()=>re,PPODefaultConfig:()=>kt,PSARDefaultConfig:()=>z,PVODefaultConfig:()=>Ft,QstickDefaultConfig:()=>Ht,RMADefaultConfig:()=>Rt,ROCDefaultConfig:()=>Tt,RSIDefaultConfig:()=>wt,SMADefaultConfig:()=>St,STRATEGY_INFOS:()=>gr,StochDefaultConfig:()=>W,StrategyStatsSortBy:()=>Et,TEMADefaultConfig:()=>Gt,TRIMADefaultConfig:()=>Ut,TRIXDefaultConfig:()=>Yt,Trend:()=>$,UIDefaultConfig:()=>_t,VWAPDefaultConfig:()=>ue,VWMADefaultConfig:()=>fe,VortexDefaultConfig:()=>Z,WillrDefaultConfig:()=>j,ab:()=>Je,abStrategy:()=>_e,abs:()=>D,absolutePriceOscillator:()=>Ie,absolutePriceOscillatorStrategy:()=>Oe,accelerationBands:()=>Je,accelerationBandsStrategy:()=>_e,accumulationDistribution:()=>bt,ad:()=>bt,add:()=>C,addBy:()=>w,ao:()=>he,aoStrategy:()=>Ce,apo:()=>Ie,apoStrategy:()=>Oe,applyActions:()=>be,aroon:()=>Be,aroonStrategy:()=>Ee,atr:()=>q,averageTrueRange:()=>q,awesomeOscillator:()=>he,awesomeOscillatorStrategy:()=>Ce,backtest:()=>mr,balanceOfPower:()=>Pe,balanceOfPowerStrategy:()=>ke,bb:()=>$e,bbStrategy:()=>ze,bbw:()=>Hr,bollingerBands:()=>$e,bollingerBandsStrategy:()=>ze,bollingerBandsWidth:()=>Hr,bop:()=>Pe,bopStrategy:()=>ke,buyAndHoldStrategy:()=>xe,cci:()=>Pr,ce:()=>Ur,cfo:()=>Ve,cfoStrategy:()=>Ne,chaikinMoneyFlow:()=>tt,chaikinMoneyFlowStrategy:()=>rt,chaikinOscillator:()=>Ir,chandeForecastOscillator:()=>Ve,chandeForecastOscillatorStrategy:()=>Ne,chandelierExit:()=>Ur,changes:()=>E,checkSameLength:()=>b,cmf:()=>tt,cmfStrategy:()=>rt,cmo:()=>Ir,communityChannelIndex:()=>Pr,computeStrategyStats:()=>xr,concatAssets:()=>_r,daysAgo:()=>Dr,daysLaterFrom:()=>Lr,dc:()=>Yr,dema:()=>kr,divide:()=>l,divideBy:()=>R,donchianChannel:()=>Yr,doubleExponentialMovingAverage:()=>kr,easeOfMovement:()=>ot,easeOfMovementStrategy:()=>nt,ema:()=>g,emv:()=>ot,emvStrategy:()=>nt,exponentialMovingAverage:()=>g,extractSigns:()=>pe,fi:()=>it,fiStrategy:()=>mt,forceIndex:()=>it,forceIndexStrategy:()=>mt,generateNumbers:()=>T,ichimokuCloud:()=>ye,ichimokuCloudStrategy:()=>Se,kc:()=>Gr,kdj:()=>qe,kdjStrategy:()=>He,keltnerChannel:()=>Gr,leastSquare:()=>vt,linearRegressionUsingLeastSquare:()=>Fe,macd:()=>Ue,macdStrategy:()=>Ye,massIndex:()=>Fr,max:()=>V,mcfo:()=>pr,mfi:()=>st,mfiStrategy:()=>ut,mi:()=>Fr,mmax:()=>y,mmin:()=>S,moneyFlowIndex:()=>st,moneyFlowIndexStrategy:()=>ut,movingAverageConvergenceDivergence:()=>Ue,movingAverageConvergenceDivergenceStrategy:()=>Ye,movingChandeForecastOscillator:()=>pr,movingLeastSquare:()=>N,movingLinearRegressionUsingLeastSquare:()=>Te,movingMax:()=>y,movingMin:()=>S,movingStandardDeviation:()=>Qe,movingSum:()=>A,mstd:()=>Qe,msum:()=>A,multiply:()=>h,multiplyBy:()=>p,negativeVolumeIndex:()=>at,negativeVolumeIndexStrategy:()=>ft,newAssetWithLength:()=>Jr,nvi:()=>at,nviStrategy:()=>ft,obv:()=>jr,onBalanceVolume:()=>jr,parabolicSAR:()=>Ge,parabolicSARStrategy:()=>We,percentagePriceOscillator:()=>Or,percentageVolumeOscillator:()=>Br,po:()=>Ze,poStrategy:()=>et,pow:()=>ge,ppo:()=>Or,priceRateOfChange:()=>Er,projectionOscillator:()=>Ze,projectionOscillatorStrategy:()=>et,psar:()=>Ge,psarStrategy:()=>We,pvo:()=>Br,qstick:()=>Tr,randomIndex:()=>qe,relativeStrengthIndex:()=>Re,reverseActions:()=>ir,rma:()=>G,roc:()=>Er,rollingMovingAverage:()=>G,roundDigits:()=>H,roundDigitsAll:()=>nr,rsi:()=>Re,rsi2Strategy:()=>we,shiftLeftAndFillBy:()=>Ct,shiftLeftBy:()=>le,shiftRightAndFillBy:()=>I,shiftRightBy:()=>F,simpleMovingAverage:()=>d,since:()=>X,sma:()=>d,sortCompanyResults:()=>sr,sortStrategyStats:()=>hr,sqrt:()=>de,stoch:()=>Me,stochStrategy:()=>De,stochasticOscillator:()=>Me,stochasticOscillatorStrategy:()=>De,subtract:()=>u,subtractBy:()=>or,tema:()=>qr,toISODateString:()=>Mr,toMonthAndDay:()=>vr,tr:()=>ht,transpose:()=>At,triangularMovingAverage:()=>Vr,trima:()=>Vr,tripleExponentialAverage:()=>Nr,tripleExponentialMovingAverage:()=>qr,trix:()=>Nr,trueRange:()=>ht,typicalPrice:()=>k,typicalPriceStrategy:()=>je,typprice:()=>k,typpriceStrategy:()=>je,ui:()=>Wr,ulcerIndex:()=>Wr,volumePriceTrend:()=>Kr,volumeWeightedAveragePrice:()=>ct,volumeWeightedAveragePriceStrategy:()=>lt,volumeWeightedMovingAverage:()=>xt,volumeWeightedMovingAverageStrategy:()=>Xr,vortex:()=>Ke,vortexStrategy:()=>Xe,vpt:()=>Kr,vwap:()=>ct,vwapStrategy:()=>lt,vwma:()=>xt,vwmaStrategy:()=>Xr,willRStrategy:()=>ve,williamsR:()=>Le,williamsRStrategy:()=>ve,willr:()=>Le});module.exports=rr(Qr);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 D(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 w(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 or(e,r){let o=new Array(r.length);for(let t=0;t<r.length;t++)o[t]=r[t]-e;return o}function I(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 I(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 le(e,r){return Ct(e,0,r)}function E(e,r){return u(r,F(e,r))}function pe(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 H(e,r){let o=Math.pow(10,e);return Math.round(r*o)/o}function nr(e,r){return r.map(o=>H(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 ge(e,r){return e.map(o=>Math.pow(o,r))}function de(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 ir(e){return e.map(r=>r===1?-1:r===-1?1:0)}function be(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 mr(e,r){let o=new Array(r.length);for(let t=0;t<o.length;t++){let i=r[t].strategy(e),n=be(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 sr(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 xe(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 U={fast:5,slow:34};function he(e,r,o={}){let{fast:t,slow:i}={...U,...o},n=R(2,C(r,e)),m=d(n,{period:t}),s=d(n,{period:i});return u(m,s)}function Ce(e,r={}){let o={...U,...r};return he(e.highs,e.lows,o).map(i=>i>0?1:i<0?-1:0)}var Y={short:9,medium:26,long:52,close:26},Ae=({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]},ur=({highs:e,lows:r,short:o})=>e.reduce(Ae({period:o,highs:e,lows:r}),[]),ar=({highs:e,lows:r,medium:o})=>e.reduce(Ae({period:o,highs:e,lows:r}),[]),fr=({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},cr=({highs:e,lows:r,long:o,medium:t})=>new Array(e.length+t).fill(0).reduce(Ae({period:o+t,highs:e,lows:r,projection:t}),[]);function ye(e,r,o,t={}){b(e,r,o);let{short:i,medium:n,long:m,close:s}={...Y,...t},c=ur({highs:e,lows:r,short:i}),a=ar({highs:e,lows:r,medium:n});return{tenkan:c,kijun:a,ssa:fr({tenkanSen:c,kijunSen:a,medium:n}),ssb:cr({highs:e,lows:r,medium:n,long:m}),laggingSpan:le(s,o)}}function Se(e,r={}){let o={...Y,...r},t=ye(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 Rt={period:4};function G(e,r={}){let{period:o}={...Rt,...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 wt={period:14};function Re(e,r={}){let{period:o}={...wt,...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=G(t,{period:o}),m=G(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 we(e){let r=Re(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 Mt={period:4};function S(e,r={}){let{period:o}={...Mt,...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 Dt={period:4};function y(e,r={}){let{period:o}={...Dt,...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 W={kPeriod:14,dPeriod:3};function Me(e,r,o,t={}){let{kPeriod:i,dPeriod:n}={...W,...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 De(e,r={}){let o={...W,...r},t=Me(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 j={period:14};function Le(e,r,o,t={}){let{period:i}={...j,...t},n=y(e,{period:i}),m=S(r,{period:i});return p(-100,l(u(n,o),u(n,m)))}function ve(e,r={}){let o={...j,...r};return Le(e.highs,e.lows,e.closings,o).map(i=>i<=-80?1:i>=-20?-1:0)}var Lt={period:12};function g(e,r={}){let{period:o}={...Lt,...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 K={fast:14,slow:30};function Ie(e,r={}){let{fast:o,slow:t}={...K,...r},i=g(e,{period:o}),n=g(e,{period:t});return u(i,n)}function Oe(e,r={}){let{fast:o,slow:t}={...K,...r},i=Ie(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 X(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 J={period:25};function Be(e,r,o={}){b(e,r);let{period:t}={...J,...o},i=X(y(e,{period:t})),n=X(S(r,{period:t})),m=p(100,R(t,w(t,p(-1,i)))),s=p(100,R(t,w(t,p(-1,n))));return{up:m,down:s}}function Ee(e,r={}){let o={...J,...r},t=Be(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 Pe(e,r,o,t){return l(u(t,e),u(r,o))}function ke(e){return Pe(e.openings,e.highs,e.lows,e.closings).map(o=>o>0?1:o<0?-1:0)}function vt(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 Fe(e,r){let o=vt(e,r);return w(o.b,p(o.m,e))}function Te(e,r,o){let t=N(e,r,o);return C(h(t.m,r),t.b)}var lr={period:4};function Ve(e){let r=T(0,e.length,1),o=Fe(r,e);return p(100,l(u(e,o),e))}var It={period:4};function pr(e,r={}){let{period:o}={...It,...r},t=T(0,e.length,1),i=Te(o,t,e);return p(100,l(u(e,i),e))}function Ne(e){return Ve(e.closings).map(o=>o>0?1:o<0?-1:0)}var _={rPeriod:9,kPeriod:3,dPeriod:3};function qe(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}),M=d(f,{period:m}),B=u(p(3,f),p(2,M));return{k:f,d:M,j:B}}function He(e,r={}){let o={..._,...r},t=qe(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 Q={fast:12,slow:26,signal:9};function Ue(e,r={}){let{fast:o,slow:t,signal:i}={...Q,...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 Ye(e,r={}){let o={...Q,...r},t=Ue(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 $=(t=>(t[t.FALLING=-1]="FALLING",t[t.STABLE=0]="STABLE",t[t.RISING=1]="RISING",t))($||{});var z={step:.02,max:.2};function Ge(e,r,o,t={}){b(e,r,o);let{step:i,max:n}={...z,...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 M=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:M!==a&&c<n&&(c+=i)}return{trends:m,psarResult:s}}function We(e,r={}){let o={...z,...r};return Ge(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 je(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 Ot={period:4};function A(e,r={}){let{period:o}={...Ot,...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 Z={period:14};function Ke(e,r,o,t={}){b(e,r,o);let{period:i}={...Z,...t},n=F(1,o),m=D(u(e,F(1,r))),s=D(u(r,F(1,e))),c=A(m,{period:i}),a=A(s,{period:i}),f=V(u(e,r),D(u(e,n)),D(u(r,n))),M=A(f,{period:i}),B=l(c,M),L=l(a,M);return{plus:B,minus:L}}function Xe(e,r={}){let o={...Z,...r},t=Ke(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 ee={period:20,multiplier:4};function Je(e,r,o,t={}){b(e,r,o);let{period:i,multiplier:n}={...ee,...t},m=l(u(e,r),C(e,r)),s=d(h(e,w(1,p(n,m))),{period:i}),c=d(o,{period:i}),a=d(h(r,w(1,p(-1*n,m))),{period:i});return{upper:s,middle:c,lower:a}}function _e(e,r={}){let o={...ee,...r},t=Je(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 Bt={period:4};function Qe(e,r={}){let{period:o}={...Bt,...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 te={period:20};function $e(e,r={}){let{period:o}={...te,...r},t=p(2,Qe(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={...te,...r},t=$e(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 re={period:14,smooth:3};function Ze(e,r,o,t={}){let{period:i,smooth:n}={...re,...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)),M=y(a,{period:i}),B=S(f,{period:i}),L=l(p(100,u(o,B)),u(M,B)),Qt=g(L,{period:n});return{poResult:L,spoResult:Qt}}function et(e,r={}){let o={...re,...r},t=Ze(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 oe={period:20};function tt(e,r,o,t,i={}){let{period:n}={...oe,...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 rt(e,r={}){let o={...oe,...r};return tt(e.highs,e.lows,e.closings,e.volumes,o).map(i=>i<0?1:i>0?-1:0)}var ne={period:14};function ot(e,r,o,t={}){let{period:i}={...ne,...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 nt(e,r={}){let o={...ne,...r};return ot(e.highs,e.lows,e.volumes,o).map(i=>i>0?1:i<0?-1:0)}var ie={period:13};function it(e,r,o={}){let{period:t}={...ie,...o};return g(h(E(1,e),r),{period:t})}function mt(e,r={}){let o={...ie,...r};return it(e.closings,e.volumes,o).map(i=>i>0?1:i<0?-1:0)}var me={period:14};function st(e,r,o,t,i={}){let{period:n}={...me,...i},m=h(k(e,r,o),t),s=pe(E(1,m)),c=h(s,m),a=c.map(L=>L>=0?L:0),f=c.map(L=>L<0?L:0),M=l(A(a,{period:n}),A(p(-1,f),{period:n}));return w(100,p(-100,ge(w(1,M),-1)))}function ut(e,r={}){let o={...me,...r};return st(e.highs,e.lows,e.closings,e.volumes,o).map(i=>i>=80?-1:1)}var se={start:1e3,period:255};function at(e,r,o={}){b(e,r);let{start:t}={...se,...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 ft(e,r={}){let o={...se,...r},t=at(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 ue={period:14};function ct(e,r,o={}){let{period:t}={...ue,...o};return l(A(h(e,r),{period:t}),A(r,{period:t}))}function lt(e,r={}){let o={...ue,...r},t=ct(e.closings,e.volumes,o);return u(t,e.closings).map(n=>n>0?1:n<0?-1:0)}var gr=[{name:"Buy Hold",strategy:xe},{name:"Awesome Oscillator",strategy:Ce},{name:"RSI 2",strategy:we},{name:"Ichimoku Cloud",strategy:Se},{name:"Stochastic Oscillator",strategy:De},{name:"Williams R",strategy:ve},{name:"Absolute Price Oscillator (APO)",strategy:Oe},{name:"Aroon Strategy",strategy:Ee},{name:"Balance of Power (BOM)",strategy:ke},{name:"Chande Forecast Oscillator (CFO)",strategy:Ne},{name:"KDJ Strategy",strategy:He},{name:"MACD Strategy",strategy:Ye},{name:"Parabolic SAR",strategy:We},{name:"Typical Price",strategy:je},{name:"Vortex Strategy",strategy:Xe},{name:"Acceleration Bands",strategy:_e},{name:"Bollinger Bands",strategy:ze},{name:"Projection Oscillator",strategy:et},{name:"Chaikin Money Flow (CMF)",strategy:rt},{name:"Ease of Movement (EMV)",strategy:nt},{name:"Force Index",strategy:mt},{name:"Money Flow Index",strategy:ut},{name:"Negative Volume Index (NVI)",strategy:ft},{name:"Volume Weighted Average Price",strategy:lt}];function dr(e){return{strategyInfo:e.info,score:1,minGain:e.gain,maxGain:e.gain,averageGain:e.gain}}function br(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 xr(e){let r=new Map;for(let t of e){let i=t.strategyResults[0],n=r.get(i.info.name);n!==void 0?br(n,i):r.set(i.info.name,dr(i))}let o=Array.from(r.values());return o.sort((t,i)=>i.score-t.score),o}var Et=(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))(Et||{});function hr(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 O=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 Cr="black",Ar=1,yr="red",Sr=1,Rr=30,pt=4,wr="14px Arial",gt=-1,ae=new v(0,1),dt=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 O(ae,ae),this.yScaler=new O(ae,ae),this.xFocus=gt,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??Ar;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?Cr:Array.isArray(r.style)?r.style[o]:r.style}drawFocus(){this.xFocus!==gt&&(this.drawFocusLine(),this.drawFocusedValues())}drawFocusLine(){this.context.strokeStyle=yr,this.context.lineWidth=Sr,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=pt;this.context.font=wr,this.context.textBaseline="bottom";for(let t of this.dataSets.values())if(r>=0&&r<t.values.length){let i=t.legend+" "+H(2,t.values[r]).toString();this.context.fillStyle=this.styleAtIndex(t,r),this.context.fillText(i,o,this.canvas.height-pt),o+=this.context.measureText(i).width+pt}}chartHeight(){return this.canvas.height-Rr}updateScalers(){this.dataSets.size!==0&&(this.xScaler=new O(new v(0,Math.max(...Array.from(this.dataSets.values(),r=>r.values.length))),new v(0,this.canvas.width)),this.yScaler=new O(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=gt,this.draw()}};function Mr(e){return e.toISOString().substring(0,10)}function Dr(e){let r=new Date;return r.setDate(r.getDate()-e),r}function Lr(e,r){let o=new Date(e);return o.setDate(o.getDate()+r),o}function vr(e){return(e.getMonth()+1).toString()+"/"+e.getDate().toString()}function bt(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 Pt={fast:3,slow:10};function Ir(e,r,o,t,i={}){let{fast:n,slow:m}={...Pt,...i},s=bt(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 Or(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 Ft={fast:12,slow:26,signal:9};function Br(e,r={}){let{fast:o,slow:t,signal:i}={...Ft,...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 Tt={period:3};function Er(e,r={}){let{period:o}={...Tt,...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 Vt={period:20};function Pr(e,r,o,t={}){let{period:i}={...Vt,...t},n=k(e,r,o),m=d(n,{period:i}),s=d(D(u(n,m)),{period:i});return l(u(n,m),p(.015,s))}var Nt={period:12};function kr(e,r={}){let{period:o}={...Nt,...r},t=g(e,{period:o}),i=g(t,{period:o});return u(p(2,t),i)}var qt={emaPeriod:9,miPeriod:25};function Fr(e,r,o={}){let{emaPeriod:t,miPeriod:i}={...qt,...o},n=g(u(e,r),{period:t}),m=g(n,{period:t}),s=l(n,m);return A(s,{period:i})}var Ht={period:14};function Tr(e,r,o={}){let{period:t}={...Ht,...o};return d(u(r,e),{period:t})}var Ut={period:4};function Vr(e,r={}){let{period:o}={...Ut,...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 Yt={period:4};function Nr(e,r={}){let{period:o}={...Yt,...r},t=g(e,{period:o}),i=g(t,{period:o}),n=g(i,{period:o}),m=I(1,n[0],n);return l(u(n,m),m)}var Gt={period:2};function qr(e,r={}){let{period:o}={...Gt,...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 fe={period:20};function xt(e,r,o={}){let{period:t}={...fe,...o};return l(A(h(e,r),{period:t}),A(r,{period:t}))}function ht(e,r,o){b(e,r,o);let t=I(1,o[0],o);return V(u(e,r),D(u(e,t)),D(u(r,t)))}var Wt={period:14};function q(e,r,o,t={}){let{period:i}={...Wt,...t},n=ht(e,r,o),m=d(n,{period:i});return{trLine:n,atrLine:m}}var jt={period:90};function Hr(e,r={}){let{period:o}={...jt,...r},t=l(u(e.upper,e.lower),e.middle),i=g(t,{period:o});return{width:t,widthEma:i}}var Kt={period:22};function Ur(e,r,o,t={}){let{period:i}={...Kt,...t},n=q(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 Xt={period:4};function Yr(e,r={}){let{period:o}={...Xt,...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 Jt={period:20};function Gr(e,r,o,t={}){let{period:i}={...Jt,...t},n=q(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 _t={period:14};function Wr(e,r={}){let{period:o}={..._t,...r},t=y(e,{period:o}),i=p(100,l(u(e,t),t)),n=d(h(i,i),{period:o});return de(n)}function jr(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 Kr(e,r){let o=I(1,e[0],e),t=h(r,l(u(e,o),o));return A(t,{period:t.length})}function Xr(e,r={}){let o={...fe,...r},t=d(e.closings,o),i=xt(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 Jr(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 _r(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]}}0&&(module.exports={ABDefaultConfig,AODefaultConfig,APODefaultConfig,ATRDefaultConfig,Action,AroonDefaultConfig,BBDefaultConfig,BBWDefaultConfig,BinarySearchTree,CCIDefaultConfig,CEDefaultConfig,CFODefaultConfig,CMFDefaultConfig,CMODefaultConfig,Chart,CompanyResultSortBy,DCDefaultConfig,DEMADefaultConfig,EMADefaultConfig,EMVDefaultConfig,FIDefaultConfig,IchimokuCloudDefaultConfig,KCDefaultConfig,KDJDefaultConfig,MACDDefaultConfig,MCFODefaultConfig,MFIDefaultConfig,MIDefaultConfig,MMaxDefaultConfig,MMinDefaultConfig,MSTDDefaultConfig,MSumDefaultConfig,NVIDefaultConfig,NumRange,NumScaler,PODefaultConfig,PPODefaultConfig,PSARDefaultConfig,PVODefaultConfig,QstickDefaultConfig,RMADefaultConfig,ROCDefaultConfig,RSIDefaultConfig,SMADefaultConfig,STRATEGY_INFOS,StochDefaultConfig,StrategyStatsSortBy,TEMADefaultConfig,TRIMADefaultConfig,TRIXDefaultConfig,Trend,UIDefaultConfig,VWAPDefaultConfig,VWMADefaultConfig,VortexDefaultConfig,WillrDefaultConfig,ab,abStrategy,abs,absolutePriceOscillator,absolutePriceOscillatorStrategy,accelerationBands,accelerationBandsStrategy,accumulationDistribution,ad,add,addBy,ao,aoStrategy,apo,apoStrategy,applyActions,aroon,aroonStrategy,atr,averageTrueRange,awesomeOscillator,awesomeOscillatorStrategy,backtest,balanceOfPower,balanceOfPowerStrategy,bb,bbStrategy,bbw,bollingerBands,bollingerBandsStrategy,bollingerBandsWidth,bop,bopStrategy,buyAndHoldStrategy,cci,ce,cfo,cfoStrategy,chaikinMoneyFlow,chaikinMoneyFlowStrategy,chaikinOscillator,chandeForecastOscillator,chandeForecastOscillatorStrategy,chandelierExit,changes,checkSameLength,cmf,cmfStrategy,cmo,communityChannelIndex,computeStrategyStats,concatAssets,daysAgo,daysLaterFrom,dc,dema,divide,divideBy,donchianChannel,doubleExponentialMovingAverage,easeOfMovement,easeOfMovementStrategy,ema,emv,emvStrategy,exponentialMovingAverage,extractSigns,fi,fiStrategy,forceIndex,forceIndexStrategy,generateNumbers,ichimokuCloud,ichimokuCloudStrategy,kc,kdj,kdjStrategy,keltnerChannel,leastSquare,linearRegressionUsingLeastSquare,macd,macdStrategy,massIndex,max,mcfo,mfi,mfiStrategy,mi,mmax,mmin,moneyFlowIndex,moneyFlowIndexStrategy,movingAverageConvergenceDivergence,movingAverageConvergenceDivergenceStrategy,movingChandeForecastOscillator,movingLeastSquare,movingLinearRegressionUsingLeastSquare,movingMax,movingMin,movingStandardDeviation,movingSum,mstd,msum,multiply,multiplyBy,negativeVolumeIndex,negativeVolumeIndexStrategy,newAssetWithLength,nvi,nviStrategy,obv,onBalanceVolume,parabolicSAR,parabolicSARStrategy,percentagePriceOscillator,percentageVolumeOscillator,po,poStrategy,pow,ppo,priceRateOfChange,projectionOscillator,projectionOscillatorStrategy,psar,psarStrategy,pvo,qstick,randomIndex,relativeStrengthIndex,reverseActions,rma,roc,rollingMovingAverage,roundDigits,roundDigitsAll,rsi,rsi2Strategy,shiftLeftAndFillBy,shiftLeftBy,shiftRightAndFillBy,shiftRightBy,simpleMovingAverage,since,sma,sortCompanyResults,sortStrategyStats,sqrt,stoch,stochStrategy,stochasticOscillator,stochasticOscillatorStrategy,subtract,subtractBy,tema,toISODateString,toMonthAndDay,tr,transpose,triangularMovingAverage,trima,tripleExponentialAverage,tripleExponentialMovingAverage,trix,trueRange,typicalPrice,typicalPriceStrategy,typprice,typpriceStrategy,ui,ulcerIndex,volumePriceTrend,volumeWeightedAveragePrice,volumeWeightedAveragePriceStrategy,volumeWeightedMovingAverage,volumeWeightedMovingAverageStrategy,vortex,vortexStrategy,vpt,vwap,vwapStrategy,vwma,vwmaStrategy,willRStrategy,williamsR,williamsRStrategy,willr}); //# sourceMappingURL=index.js.map