@guihz/trading-vue-editor-tes 0.0.212 → 0.0.213

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,10 +59,10 @@ ${ao}rows: ${i.rows}
59
59
  ${ao}columns: ${i.columns}
60
60
  }`}function H1(i,t,e,r,n){const{rows:s,columns:a}=i,l=Math.min(s,t),c=Math.min(a,e),h=[];if(n==="auto"){n=!1;t:for(let d=0;d<l;d++)for(let f=0;f<c;f++)if(i.get(d,f)<0){n=!0;break t}}for(let d=0;d<l;d++){let f=[];for(let p=0;p<c;p++)f.push(J1(i.get(d,p),r,n));h.push(`${f.join(" ")}`)}return c!==a&&(h[h.length-1]+=` ... ${a-e} more columns`),l!==s&&h.push(`... ${s-t} more rows`),h.join(`
61
61
  ${th}`)}function J1(i,t,e){return(i>=0&&e?` ${rh(i,t-1)}`:rh(i,t)).padEnd(t)}function rh(i,t){let e=i.toString();if(e.length<=t)return e;let r=i.toFixed(t);if(r.length>t&&(r=i.toFixed(Math.max(0,t-(r.length-t)))),r.length<=t&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=i.toExponential(t);return n.length>t&&(n=i.toExponential(Math.max(0,t-(n.length-t)))),n.slice(0)}function X1(i,t){i.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},i.prototype.addS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r);return this},i.prototype.addM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r.get(n,s));return this},i.add=function(r,n){return new t(r).add(n)},i.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},i.prototype.subS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r);return this},i.prototype.subM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r.get(n,s));return this},i.sub=function(r,n){return new t(r).sub(n)},i.prototype.subtract=i.prototype.sub,i.prototype.subtractS=i.prototype.subS,i.prototype.subtractM=i.prototype.subM,i.subtract=i.sub,i.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},i.prototype.mulS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r);return this},i.prototype.mulM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r.get(n,s));return this},i.mul=function(r,n){return new t(r).mul(n)},i.prototype.multiply=i.prototype.mul,i.prototype.multiplyS=i.prototype.mulS,i.prototype.multiplyM=i.prototype.mulM,i.multiply=i.mul,i.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},i.prototype.divS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r);return this},i.prototype.divM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r.get(n,s));return this},i.div=function(r,n){return new t(r).div(n)},i.prototype.divide=i.prototype.div,i.prototype.divideS=i.prototype.divS,i.prototype.divideM=i.prototype.divM,i.divide=i.div,i.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},i.prototype.modS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r);return this},i.prototype.modM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r.get(n,s));return this},i.mod=function(r,n){return new t(r).mod(n)},i.prototype.modulus=i.prototype.mod,i.prototype.modulusS=i.prototype.modS,i.prototype.modulusM=i.prototype.modM,i.modulus=i.mod,i.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},i.prototype.andS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r);return this},i.prototype.andM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r.get(n,s));return this},i.and=function(r,n){return new t(r).and(n)},i.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},i.prototype.orS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r);return this},i.prototype.orM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r.get(n,s));return this},i.or=function(r,n){return new t(r).or(n)},i.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},i.prototype.xorS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r);return this},i.prototype.xorM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r.get(n,s));return this},i.xor=function(r,n){return new t(r).xor(n)},i.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},i.prototype.leftShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r);return this},i.prototype.leftShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r.get(n,s));return this},i.leftShift=function(r,n){return new t(r).leftShift(n)},i.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},i.prototype.signPropagatingRightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r);return this},i.prototype.signPropagatingRightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r.get(n,s));return this},i.signPropagatingRightShift=function(r,n){return new t(r).signPropagatingRightShift(n)},i.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},i.prototype.rightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r);return this},i.prototype.rightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r.get(n,s));return this},i.rightShift=function(r,n){return new t(r).rightShift(n)},i.prototype.zeroFillRightShift=i.prototype.rightShift,i.prototype.zeroFillRightShiftS=i.prototype.rightShiftS,i.prototype.zeroFillRightShiftM=i.prototype.rightShiftM,i.zeroFillRightShift=i.rightShift,i.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,~this.get(r,n));return this},i.not=function(r){return new t(r).not()},i.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.abs(this.get(r,n)));return this},i.abs=function(r){return new t(r).abs()},i.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acos(this.get(r,n)));return this},i.acos=function(r){return new t(r).acos()},i.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acosh(this.get(r,n)));return this},i.acosh=function(r){return new t(r).acosh()},i.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asin(this.get(r,n)));return this},i.asin=function(r){return new t(r).asin()},i.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asinh(this.get(r,n)));return this},i.asinh=function(r){return new t(r).asinh()},i.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atan(this.get(r,n)));return this},i.atan=function(r){return new t(r).atan()},i.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atanh(this.get(r,n)));return this},i.atanh=function(r){return new t(r).atanh()},i.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cbrt(this.get(r,n)));return this},i.cbrt=function(r){return new t(r).cbrt()},i.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.ceil(this.get(r,n)));return this},i.ceil=function(r){return new t(r).ceil()},i.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.clz32(this.get(r,n)));return this},i.clz32=function(r){return new t(r).clz32()},i.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cos(this.get(r,n)));return this},i.cos=function(r){return new t(r).cos()},i.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cosh(this.get(r,n)));return this},i.cosh=function(r){return new t(r).cosh()},i.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.exp(this.get(r,n)));return this},i.exp=function(r){return new t(r).exp()},i.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.expm1(this.get(r,n)));return this},i.expm1=function(r){return new t(r).expm1()},i.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.floor(this.get(r,n)));return this},i.floor=function(r){return new t(r).floor()},i.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.fround(this.get(r,n)));return this},i.fround=function(r){return new t(r).fround()},i.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log(this.get(r,n)));return this},i.log=function(r){return new t(r).log()},i.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log1p(this.get(r,n)));return this},i.log1p=function(r){return new t(r).log1p()},i.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log10(this.get(r,n)));return this},i.log10=function(r){return new t(r).log10()},i.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log2(this.get(r,n)));return this},i.log2=function(r){return new t(r).log2()},i.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.round(this.get(r,n)));return this},i.round=function(r){return new t(r).round()},i.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sign(this.get(r,n)));return this},i.sign=function(r){return new t(r).sign()},i.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sin(this.get(r,n)));return this},i.sin=function(r){return new t(r).sin()},i.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sinh(this.get(r,n)));return this},i.sinh=function(r){return new t(r).sinh()},i.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sqrt(this.get(r,n)));return this},i.sqrt=function(r){return new t(r).sqrt()},i.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tan(this.get(r,n)));return this},i.tan=function(r){return new t(r).tan()},i.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tanh(this.get(r,n)));return this},i.tanh=function(r){return new t(r).tanh()},i.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.trunc(this.get(r,n)));return this},i.trunc=function(r){return new t(r).trunc()},i.pow=function(r,n){return new t(r).pow(n)},i.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},i.prototype.powS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r));return this},i.prototype.powM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r.get(n,s)));return this}}function Br(i,t,e){let r=e?i.rows:i.rows-1;if(t<0||t>r)throw new RangeError("Row index out of range")}function Ir(i,t,e){let r=e?i.columns:i.columns-1;if(t<0||t>r)throw new RangeError("Column index out of range")}function Fi(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.columns)throw new RangeError("vector size must be the same as the number of columns");return t}function Mi(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.rows)throw new RangeError("vector size must be the same as the number of rows");return t}function Ka(i,t){if(!fr.isAnyArray(t))throw new TypeError("row indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.rows)throw new RangeError("row indices are out of range")}function Ga(i,t){if(!fr.isAnyArray(t))throw new TypeError("column indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.columns)throw new RangeError("column indices are out of range")}function Ha(i,t,e,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(lo("startRow",t),lo("endRow",e),lo("startColumn",r),lo("endColumn",n),t>e||r>n||t<0||t>=i.rows||e<0||e>=i.rows||r<0||r>=i.columns||n<0||n>=i.columns)throw new RangeError("Submatrix indices are out of range")}function uo(i,t=0){let e=[];for(let r=0;r<i;r++)e.push(t);return e}function lo(i,t){if(typeof t!="number")throw new TypeError(`${i} must be a number`)}function Ni(i){if(i.isEmpty())throw new Error("Empty matrix has no elements to index")}function Q1(i){let t=uo(i.rows);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]+=i.get(e,r);return t}function tw(i){let t=uo(i.columns);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]+=i.get(e,r);return t}function ew(i){let t=0;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t+=i.get(e,r);return t}function rw(i){let t=uo(i.rows,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]*=i.get(e,r);return t}function nw(i){let t=uo(i.columns,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]*=i.get(e,r);return t}function iw(i){let t=1;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t*=i.get(e,r);return t}function sw(i,t,e){const r=i.rows,n=i.columns,s=[];for(let a=0;a<r;a++){let l=0,c=0,h=0;for(let d=0;d<n;d++)h=i.get(a,d)-e[a],l+=h,c+=h*h;t?s.push((c-l*l/n)/(n-1)):s.push((c-l*l/n)/n)}return s}function ow(i,t,e){const r=i.rows,n=i.columns,s=[];for(let a=0;a<n;a++){let l=0,c=0,h=0;for(let d=0;d<r;d++)h=i.get(d,a)-e[a],l+=h,c+=h*h;t?s.push((c-l*l/r)/(r-1)):s.push((c-l*l/r)/r)}return s}function aw(i,t,e){const r=i.rows,n=i.columns,s=r*n;let a=0,l=0,c=0;for(let h=0;h<r;h++)for(let d=0;d<n;d++)c=i.get(h,d)-e,a+=c,l+=c*c;return t?(l-a*a/s)/(s-1):(l-a*a/s)/s}function uw(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[e])}function lw(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[r])}function cw(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t)}function fw(i){const t=[];for(let e=0;e<i.rows;e++){let r=0;for(let n=0;n<i.columns;n++)r+=Math.pow(i.get(e,n),2)/(i.columns-1);t.push(Math.sqrt(r))}return t}function hw(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[e])}function dw(i){const t=[];for(let e=0;e<i.columns;e++){let r=0;for(let n=0;n<i.rows;n++)r+=Math.pow(i.get(n,e),2)/(i.rows-1);t.push(Math.sqrt(r))}return t}function pw(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[r])}function _w(i){const t=i.size-1;let e=0;for(let r=0;r<i.columns;r++)for(let n=0;n<i.rows;n++)e+=Math.pow(i.get(n,r),2)/t;return Math.sqrt(e)}function mw(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t)}class $t{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new dt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)s.set(a,l,r[a*e+l]);return s}static rowVector(t){let e=new dt(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new dt(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new dt(t,e)}static ones(t,e){return new dt(t,e).fill(1)}static rand(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=r;let s=new dt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)s.set(a,l,n());return s}static randInt(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:a=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let l=s-n,c=new dt(t,e);for(let h=0;h<t;h++)for(let d=0;d<e;d++){let f=n+Math.round(a()*l);c.set(h,d,f)}return c}static eye(t,e,r){e===void 0&&(e=t),r===void 0&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let a=0;a<n;a++)s.set(a,a,r);return s}static diag(t,e,r){let n=t.length;e===void 0&&(e=n),r===void 0&&(r=e);let s=Math.min(n,e,r),a=this.zeros(e,r);for(let l=0;l<s;l++)a.set(l,l,t[l]);return a}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new dt(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)s.set(a,l,Math.min(t.get(a,l),e.get(a,l)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)s.set(a,l,Math.max(t.get(a,l),e.get(a,l)));return s}static checkMatrix(t){return $t.isMatrix(t)?t:new dt(t)}static isMatrix(t){return t!=null&&t.klass==="Matrix"}get size(){return this.rows*this.columns}apply(t){if(typeof t!="function")throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(this.get(t,t)!==0)return!1;return!0}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let a=e+1;a<this.rows;a++)this.get(t,a)!==0&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(t.get(n,r)===0)r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let a=r;a<t.columns;a++)t.set(e,a,t.get(e,a)/s);for(let a=e+1;a<t.rows;a++){let l=t.get(a,r)/t.get(e,r);t.set(a,r,0);for(let c=r+1;c<t.columns;c++)t.set(a,c,t.get(a,c)-t.get(e,c)*l)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(t.maxRow(n)===0)n--;else{let s=0,a=!1;for(;s<r&&a===!1;)t.get(n,s)===1?a=!0:s++;for(let l=0;l<n;l++){let c=t.get(l,s);for(let h=s;h<e;h++){let d=t.get(l,h)-c*t.get(n,h);t.set(l,h,d)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new dt(this.rows*e,this.columns*r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)n.setSubMatrix(this,this.rows*s,this.columns*a);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){Br(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return dt.rowVector(this.getRow(t))}setRow(t,e){Br(this,t),e=Fi(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Br(this,t),Br(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){Ir(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return dt.columnVector(this.getColumn(t))}setColumn(t,e){Ir(this,t),e=Mi(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){Ir(this,t),Ir(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=Fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=Fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=Fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=Fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=Mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=Mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=Mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=Mi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){Br(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){Ir(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){Ni(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}minIndex(){Ni(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(Br(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){Br(this,t),Ni(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(Br(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){Br(this,t),Ni(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(Ir(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){Ir(this,t),Ni(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(Ir(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){Ir(this,t),Ni(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${t}`)}}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){$t.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=dt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new dt(e,n),a=new Float64Array(r);for(let l=0;l<n;l++){for(let c=0;c<r;c++)a[c]=t.get(c,l);for(let c=0;c<e;c++){let h=0;for(let d=0;d<r;d++)h+=this.get(c,d)*a[d];s.set(c,l,h)}}return s}strassen2x2(t){t=dt.checkMatrix(t);let e=new dt(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),a=t.get(0,1),l=this.get(1,0),c=t.get(1,0),h=this.get(1,1),d=t.get(1,1),f=(r+h)*(n+d),p=(l+h)*n,g=r*(a-d),w=h*(c-n),m=(r+s)*d,y=(l-r)*(n+a),v=(s-h)*(c+d),x=f+w-m+v,b=g+m,M=p+w,E=f-p+g+y;return e.set(0,0,x),e.set(0,1,b),e.set(1,0,M),e.set(1,1,E),e}strassen3x3(t){t=dt.checkMatrix(t);let e=new dt(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),a=this.get(1,0),l=this.get(1,1),c=this.get(1,2),h=this.get(2,0),d=this.get(2,1),f=this.get(2,2),p=t.get(0,0),g=t.get(0,1),w=t.get(0,2),m=t.get(1,0),y=t.get(1,1),v=t.get(1,2),x=t.get(2,0),b=t.get(2,1),M=t.get(2,2),E=(r+n+s-a-l-d-f)*y,C=(r-a)*(-g+y),N=l*(-p+g+m-y-v-x+M),S=(-r+a+l)*(p-g+y),T=(a+l)*(-p+g),A=r*p,O=(-r+h+d)*(p-w+v),L=(-r+h)*(w-v),q=(h+d)*(-p+w),U=(r+n+s-l-c-h-d)*v,W=d*(-p+w+m-y-v-x+b),z=(-s+d+f)*(y+x-b),K=(s-f)*(y-b),Z=s*x,X=(d+f)*(-x+b),Q=(-s+l+c)*(v+x-M),ct=(s-c)*(v-M),vt=(l+c)*(-x+M),lt=n*m,yt=c*b,bt=a*w,Ot=h*g,xt=f*M,ue=A+Z+lt,It=E+S+T+A+z+Z+X,Nt=A+O+q+U+Z+Q+vt,fe=C+N+S+A+Z+Q+ct,re=C+S+T+A+yt,qt=Z+Q+ct+vt+bt,Jt=A+O+L+W+z+K+Z,Le=z+K+Z+X+Ot,yr=A+O+L+q+xt;return e.set(0,0,ue),e.set(0,1,It),e.set(0,2,Nt),e.set(1,0,fe),e.set(1,1,re),e.set(1,2,qt),e.set(2,0,Jt),e.set(2,1,Le),e.set(2,2,yr),e}mmulStrassen(t){t=dt.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,a=t.columns;n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${a} matrix: dimensions do not match.`);function l(f,p,g){let w=f.rows,m=f.columns;if(w===p&&m===g)return f;{let y=$t.zeros(p,g);return y=y.setSubMatrix(f,0,0),y}}let c=Math.max(r,s),h=Math.max(n,a);e=l(e,c,h),t=l(t,c,h);function d(f,p,g,w){if(g<=512||w<=512)return f.mmul(p);g%2===1&&w%2===1?(f=l(f,g+1,w+1),p=l(p,g+1,w+1)):g%2===1?(f=l(f,g+1,w),p=l(p,g+1,w)):w%2===1&&(f=l(f,g,w+1),p=l(p,g,w+1));let m=parseInt(f.rows/2,10),y=parseInt(f.columns/2,10),v=f.subMatrix(0,m-1,0,y-1),x=p.subMatrix(0,m-1,0,y-1),b=f.subMatrix(0,m-1,y,f.columns-1),M=p.subMatrix(0,m-1,y,p.columns-1),E=f.subMatrix(m,f.rows-1,0,y-1),C=p.subMatrix(m,p.rows-1,0,y-1),N=f.subMatrix(m,f.rows-1,y,f.columns-1),S=p.subMatrix(m,p.rows-1,y,p.columns-1),T=d($t.add(v,N),$t.add(x,S),m,y),A=d($t.add(E,N),x,m,y),O=d(v,$t.sub(M,S),m,y),L=d(N,$t.sub(C,x),m,y),q=d($t.add(v,b),S,m,y),U=d($t.sub(E,v),$t.add(x,M),m,y),W=d($t.sub(b,N),$t.add(C,S),m,y),z=$t.add(T,L);z.sub(q),z.add(W);let K=$t.add(O,q),Z=$t.add(A,L),X=$t.sub(T,A);X.add(O),X.add(U);let Q=$t.zeros(2*z.rows,2*z.columns);return Q=Q.setSubMatrix(z,0,0),Q=Q.setSubMatrix(K,z.rows,0),Q=Q.setSubMatrix(Z,0,z.columns),Q=Q.setSubMatrix(X,z.rows,z.columns),Q.subMatrix(0,g-1,0,w-1)}return d(e,t,c,h)}scaleRows(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new dt(this.rows,this.columns);for(let s=0;s<this.rows;s++){const a=this.getRow(s);a.length>0&&Qf(a,{min:e,max:r,output:a}),n.setRow(s,a)}return n}scaleColumns(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new dt(this.rows,this.columns);for(let s=0;s<this.columns;s++){const a=this.getColumn(s);a.length&&Qf(a,{min:e,max:r,output:a}),n.setColumn(s,a)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let n=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,n)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let n=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,n)}return this}kroneckerProduct(t){t=dt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,a=new dt(e*n,r*s);for(let l=0;l<e;l++)for(let c=0;c<r;c++)for(let h=0;h<n;h++)for(let d=0;d<s;d++)a.set(n*l+h,s*c+d,this.get(l,c)*t.get(h,d));return a}kroneckerSum(t){if(t=dt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(dt.eye(r,r)),s=dt.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new dt(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=nh){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=nh){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Ha(this,t,e,r,n);let s=new dt(e-t+1,n-r+1);for(let a=t;a<=e;a++)for(let l=r;l<=n;l++)s.set(a-t,l-r,this.get(a,l));return s}subMatrixRow(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new dt(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let a=e;a<=r;a++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,a-e,this.get(t[s],a))}return n}subMatrixColumn(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new dt(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let a=e;a<=r;a++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(a-e,s,this.get(a,t[s]))}return n}setSubMatrix(t,e,r){if(t=dt.checkMatrix(t),t.isEmpty())return this;let n=e+t.rows-1,s=r+t.columns-1;Ha(this,e,n,r,s);for(let a=0;a<t.rows;a++)for(let l=0;l<t.columns;l++)this.set(e+a,r+l,t.get(a,l));return this}selection(t,e){Ka(this,t),Ga(this,e);let r=new dt(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let a=0;a<e.length;a++){let l=e[a];r.set(n,a,this.get(s,l))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){return this.constructor.copy(this,new dt(this.rows,this.columns))}static copy(t,e){for(const[r,n,s]of t.entries())e.set(r,n,s);return e}sum(t){switch(t){case"row":return Q1(this);case"column":return tw(this);case void 0:return ew(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return rw(this);case"column":return nw(this);case void 0:return iw(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":{for(let r=0;r<this.rows;r++)e[r]/=this.columns;return e}case"column":{for(let r=0;r<this.columns;r++)e[r]/=this.rows;return e}case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(t){case"row":{if(!fr.isAnyArray(n))throw new TypeError("mean must be an array");return sw(this,r,n)}case"column":{if(!fr.isAnyArray(n))throw new TypeError("mean must be an array");return ow(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return aw(this,r,n)}default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){typeof t=="object"&&(e=t,t=void 0);const r=this.variance(t,e);if(t===void 0)return Math.sqrt(r);for(let n=0;n<r.length;n++)r[n]=Math.sqrt(r[n]);return r}center(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":{if(!fr.isAnyArray(r))throw new TypeError("center must be an array");return uw(this,r),this}case"column":{if(!fr.isAnyArray(r))throw new TypeError("center must be an array");return lw(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return cw(this,r),this}default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":{if(r===void 0)r=fw(this);else if(!fr.isAnyArray(r))throw new TypeError("scale must be an array");return hw(this,r),this}case"column":{if(r===void 0)r=dw(this);else if(!fr.isAnyArray(r))throw new TypeError("scale must be an array");return pw(this,r),this}case void 0:{if(r===void 0)r=_w(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return mw(this,r),this}default:throw new Error(`invalid option: ${t}`)}}toString(t){return eh(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}$t.prototype.klass="Matrix",typeof Symbol<"u"&&($t.prototype[Symbol.for("nodejs.util.inspect.custom")]=G1);function nh(i,t){return i-t}function gw(i){return i.every(t=>typeof t=="number")}$t.random=$t.rand,$t.randomInt=$t.randInt,$t.diagonal=$t.diag,$t.prototype.diagonal=$t.prototype.diag,$t.identity=$t.eye,$t.prototype.negate=$t.prototype.neg,$t.prototype.tensorProduct=$t.prototype.kroneckerProduct;let dt=(Li=class extends $t{constructor(e,r){super();Pl(this,ls);$(this,"data");if(Li.isMatrix(e))zl(this,ls,kl).call(this,e.rows,e.columns),Li.copy(e,this);else if(Number.isInteger(e)&&e>=0)zl(this,ls,kl).call(this,e,r);else if(fr.isAnyArray(e)){const n=e;if(e=n.length,r=e?n[0].length:0,typeof r!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let s=0;s<e;s++){if(n[s].length!==r)throw new RangeError("Inconsistent array dimensions");if(!gw(n[s]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[s]))}this.rows=e,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(e,r,n){return this.data[e][r]=n,this}get(e,r){return this.data[e][r]}removeRow(e){return Br(this,e),this.data.splice(e,1),this.rows-=1,this}addRow(e,r){return r===void 0&&(r=e,e=this.rows),Br(this,e,!0),r=Float64Array.from(Fi(this,r)),this.data.splice(e,0,r),this.rows+=1,this}removeColumn(e){Ir(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let s=0;s<e;s++)n[s]=this.data[r][s];for(let s=e+1;s<this.columns;s++)n[s-1]=this.data[r][s];this.data[r]=n}return this.columns-=1,this}addColumn(e,r){typeof r>"u"&&(r=e,e=this.columns),Ir(this,e,!0),r=Mi(this,r);for(let n=0;n<this.rows;n++){const s=new Float64Array(this.columns+1);let a=0;for(;a<e;a++)s[a]=this.data[n][a];for(s[a++]=r[n];a<this.columns+1;a++)s[a]=this.data[n][a-1];this.data[n]=s}return this.columns+=1,this}},ls=new WeakSet,kl=function(e,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let n=0;n<e;n++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=e,this.columns=r},Li);X1($t,dt);const Fo=class Fo extends $t{constructor(e){super();Pl(this,tr,void 0);if(dt.isMatrix(e)){if(!e.isSymmetric())throw new TypeError("not symmetric data");va(this,tr,dt.copy(e,new dt(e.rows,e.rows)))}else if(Number.isInteger(e)&&e>=0)va(this,tr,new dt(e,e));else if(va(this,tr,new dt(e)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return Xr(this,tr).size}get rows(){return Xr(this,tr).rows}get columns(){return Xr(this,tr).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(e){return dt.isMatrix(e)&&e.klassType==="SymmetricMatrix"}static zeros(e){return new this(e)}static ones(e){return new this(e).fill(1)}clone(){const e=new Fo(this.diagonalSize);for(const[r,n,s]of this.upperRightEntries())e.set(r,n,s);return e}toMatrix(){return new dt(this)}get(e,r){return Xr(this,tr).get(e,r)}set(e,r,n){return Xr(this,tr).set(e,r,n),Xr(this,tr).set(r,e,n),this}removeCross(e){return Xr(this,tr).removeRow(e),Xr(this,tr).removeColumn(e),this}addCross(e,r){r===void 0&&(r=e,e=this.diagonalSize);const n=r.slice();return n.splice(e,1),Xr(this,tr).addRow(e,n),Xr(this,tr).addColumn(e,r),this}applyMask(e){if(e.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[n,s]of e.entries())s||r.push(n);r.reverse();for(const n of r)this.removeCross(n);return this}toCompact(){const{diagonalSize:e}=this,r=new Array(e*(e+1)/2);for(let n=0,s=0,a=0;a<r.length;a++)r[a]=this.get(s,n),++n>=e&&(n=++s);return r}static fromCompact(e){const r=e.length,n=(Math.sqrt(8*r+1)-1)/2;if(!Number.isInteger(n))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(e)}`);const s=new Fo(n);for(let a=0,l=0,c=0;c<r;c++)s.set(a,l,e[c]),++a>=n&&(a=++l);return s}*upperRightEntries(){for(let e=0,r=0;e<this.diagonalSize;void 0){const n=this.get(e,r);yield[e,r,n],++r>=this.diagonalSize&&(r=++e)}}*upperRightValues(){for(let e=0,r=0;e<this.diagonalSize;void 0)yield this.get(e,r),++r>=this.diagonalSize&&(r=++e)}};tr=new WeakMap;let ti=Fo;ti.prototype.klassType="SymmetricMatrix";class co extends ti{static isDistanceMatrix(t){return ti.isSymmetricMatrix(t)&&t.klassSubType==="DistanceMatrix"}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return e===void 0&&(e=t,t=this.diagonalSize),e=e.slice(),e[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new ti(this)}clone(){const t=new co(this.diagonalSize);for(const[e,r,n]of this.upperRightEntries())e!==r&&t.set(e,r,n);return t}toCompact(){const{diagonalSize:t}=this,e=(t-1)*t/2,r=new Array(e);for(let n=1,s=0,a=0;a<r.length;a++)r[a]=this.get(s,n),++n>=t&&(n=++s+1);return r}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const n=new this(r);for(let s=1,a=0,l=0;l<e;l++)n.set(s,a,t[l]),++s>=r&&(s=++a+1);return n}}co.prototype.klassSubType="DistanceMatrix";class dn extends $t{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class vw extends dn{constructor(t,e){Ir(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class ww extends dn{constructor(t,e){Ga(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class yw extends dn{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}class Dw extends dn{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class bw extends dn{constructor(t,e){Br(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class xw extends dn{constructor(t,e){Ka(t,e),super(t,e.length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class fo extends dn{constructor(t,e,r){Ka(t,e),Ga(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class Ew extends dn{constructor(t,e,r,n,s){Ha(t,e,r,n,s),super(t,r-e+1,s-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class Aw extends dn{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class ih extends $t{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class wr extends $t{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function Cw(i,t){if(fr.isAnyArray(i))return i[0]&&fr.isAnyArray(i[0])?new wr(i):new ih(i,t);throw new Error("the argument is not an array")}class ho{constructor(t){t=wr.checkMatrix(t);let e=t.clone(),r=e.rows,n=e.columns,s=new Float64Array(r),a=1,l,c,h,d,f,p,g,w,m;for(l=0;l<r;l++)s[l]=l;for(w=new Float64Array(r),c=0;c<n;c++){for(l=0;l<r;l++)w[l]=e.get(l,c);for(l=0;l<r;l++){for(m=Math.min(l,c),f=0,h=0;h<m;h++)f+=e.get(l,h)*w[h];w[l]-=f,e.set(l,c,w[l])}for(d=c,l=c+1;l<r;l++)Math.abs(w[l])>Math.abs(w[d])&&(d=l);if(d!==c){for(h=0;h<n;h++)p=e.get(d,h),e.set(d,h,e.get(c,h)),e.set(c,h,p);g=s[d],s[d]=s[c],s[c]=g,a=-a}if(c<r&&e.get(c,c)!==0)for(l=c+1;l<r;l++)e.set(l,c,e.get(l,c)/e.get(c,c))}this.LU=e,this.pivotVector=s,this.pivotSign=a}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(t.get(r,r)===0)return!0;return!1}solve(t){t=dt.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=t.columns,s=t.subMatrixRow(this.pivotVector,0,n-1),a=e.columns,l,c,h;for(h=0;h<a;h++)for(l=h+1;l<a;l++)for(c=0;c<n;c++)s.set(l,c,s.get(l,c)-s.get(h,c)*e.get(l,h));for(h=a-1;h>=0;h--){for(c=0;c<n;c++)s.set(h,c,s.get(h,c)/e.get(h,h));for(l=0;l<h;l++)for(c=0;c<n;c++)s.set(l,c,s.get(l,c)-s.get(h,c)*e.get(l,h))}return s}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new dt(e,r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)s>a?n.set(s,a,t.get(s,a)):s===a?n.set(s,a,1):n.set(s,a,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new dt(e,r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)s<=a?n.set(s,a,t.get(s,a)):n.set(s,a,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function pn(i,t){let e=0;return Math.abs(i)>Math.abs(t)?(e=t/i,Math.abs(i)*Math.sqrt(1+e*e)):t!==0?(e=i/t,Math.abs(t)*Math.sqrt(1+e*e)):0}class Ja{constructor(t){t=wr.checkMatrix(t);let e=t.clone(),r=t.rows,n=t.columns,s=new Float64Array(n),a,l,c,h;for(c=0;c<n;c++){let d=0;for(a=c;a<r;a++)d=pn(d,e.get(a,c));if(d!==0){for(e.get(c,c)<0&&(d=-d),a=c;a<r;a++)e.set(a,c,e.get(a,c)/d);for(e.set(c,c,e.get(c,c)+1),l=c+1;l<n;l++){for(h=0,a=c;a<r;a++)h+=e.get(a,c)*e.get(a,l);for(h=-h/e.get(c,c),a=c;a<r;a++)e.set(a,l,e.get(a,l)+h*e.get(a,c))}}s[c]=-d}this.QR=e,this.Rdiag=s}solve(t){t=dt.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=t.columns,s=t.clone(),a=e.columns,l,c,h,d;for(h=0;h<a;h++)for(c=0;c<n;c++){for(d=0,l=h;l<r;l++)d+=e.get(l,h)*s.get(l,c);for(d=-d/e.get(h,h),l=h;l<r;l++)s.set(l,c,s.get(l,c)+d*e.get(l,h))}for(h=a-1;h>=0;h--){for(c=0;c<n;c++)s.set(h,c,s.get(h,c)/this.Rdiag[h]);for(l=0;l<h;l++)for(c=0;c<n;c++)s.set(l,c,s.get(l,c)-s.get(h,c)*e.get(l,h))}return s.subMatrix(0,a-1,0,n-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(this.Rdiag[e]===0)return!1;return!0}get upperTriangularMatrix(){let t=this.QR,e=t.columns,r=new dt(e,e),n,s;for(n=0;n<e;n++)for(s=0;s<e;s++)n<s?r.set(n,s,t.get(n,s)):n===s?r.set(n,s,this.Rdiag[n]):r.set(n,s,0);return r}get orthogonalMatrix(){let t=this.QR,e=t.rows,r=t.columns,n=new dt(e,r),s,a,l,c;for(l=r-1;l>=0;l--){for(s=0;s<e;s++)n.set(s,l,0);for(n.set(l,l,1),a=l;a<r;a++)if(t.get(l,l)!==0){for(c=0,s=l;s<e;s++)c+=t.get(s,l)*n.get(s,a);for(c=-c/t.get(l,l),s=l;s<e;s++)n.set(s,a,n.get(s,a)+c*t.get(s,l))}}return n}}class Si{constructor(t,e={}){if(t=wr.checkMatrix(t),t.isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:a=!0,autoTranspose:l=!1}=e;let c=!!s,h=!!a,d=!1,f;if(r<n)if(!l)f=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{f=t.transpose(),r=f.rows,n=f.columns,d=!0;let A=c;c=h,h=A}else f=t.clone();let p=Math.min(r,n),g=Math.min(r+1,n),w=new Float64Array(g),m=new dt(r,p),y=new dt(n,n),v=new Float64Array(n),x=new Float64Array(r),b=new Float64Array(g);for(let A=0;A<g;A++)b[A]=A;let M=Math.min(r-1,n),E=Math.max(0,Math.min(n-2,r)),C=Math.max(M,E);for(let A=0;A<C;A++){if(A<M){w[A]=0;for(let O=A;O<r;O++)w[A]=pn(w[A],f.get(O,A));if(w[A]!==0){f.get(A,A)<0&&(w[A]=-w[A]);for(let O=A;O<r;O++)f.set(O,A,f.get(O,A)/w[A]);f.set(A,A,f.get(A,A)+1)}w[A]=-w[A]}for(let O=A+1;O<n;O++){if(A<M&&w[A]!==0){let L=0;for(let q=A;q<r;q++)L+=f.get(q,A)*f.get(q,O);L=-L/f.get(A,A);for(let q=A;q<r;q++)f.set(q,O,f.get(q,O)+L*f.get(q,A))}v[O]=f.get(A,O)}if(c&&A<M)for(let O=A;O<r;O++)m.set(O,A,f.get(O,A));if(A<E){v[A]=0;for(let O=A+1;O<n;O++)v[A]=pn(v[A],v[O]);if(v[A]!==0){v[A+1]<0&&(v[A]=0-v[A]);for(let O=A+1;O<n;O++)v[O]/=v[A];v[A+1]+=1}if(v[A]=-v[A],A+1<r&&v[A]!==0){for(let O=A+1;O<r;O++)x[O]=0;for(let O=A+1;O<r;O++)for(let L=A+1;L<n;L++)x[O]+=v[L]*f.get(O,L);for(let O=A+1;O<n;O++){let L=-v[O]/v[A+1];for(let q=A+1;q<r;q++)f.set(q,O,f.get(q,O)+L*x[q])}}if(h)for(let O=A+1;O<n;O++)y.set(O,A,v[O])}}let N=Math.min(n,r+1);if(M<n&&(w[M]=f.get(M,M)),r<N&&(w[N-1]=0),E+1<N&&(v[E]=f.get(E,N-1)),v[N-1]=0,c){for(let A=M;A<p;A++){for(let O=0;O<r;O++)m.set(O,A,0);m.set(A,A,1)}for(let A=M-1;A>=0;A--)if(w[A]!==0){for(let O=A+1;O<p;O++){let L=0;for(let q=A;q<r;q++)L+=m.get(q,A)*m.get(q,O);L=-L/m.get(A,A);for(let q=A;q<r;q++)m.set(q,O,m.get(q,O)+L*m.get(q,A))}for(let O=A;O<r;O++)m.set(O,A,-m.get(O,A));m.set(A,A,1+m.get(A,A));for(let O=0;O<A-1;O++)m.set(O,A,0)}else{for(let O=0;O<r;O++)m.set(O,A,0);m.set(A,A,1)}}if(h)for(let A=n-1;A>=0;A--){if(A<E&&v[A]!==0)for(let O=A+1;O<n;O++){let L=0;for(let q=A+1;q<n;q++)L+=y.get(q,A)*y.get(q,O);L=-L/y.get(A+1,A);for(let q=A+1;q<n;q++)y.set(q,O,y.get(q,O)+L*y.get(q,A))}for(let O=0;O<n;O++)y.set(O,A,0);y.set(A,A,1)}let S=N-1,T=Number.EPSILON;for(;N>0;){let A,O;for(A=N-2;A>=-1&&A!==-1;A--){const L=Number.MIN_VALUE+T*Math.abs(w[A]+Math.abs(w[A+1]));if(Math.abs(v[A])<=L||Number.isNaN(v[A])){v[A]=0;break}}if(A===N-2)O=4;else{let L;for(L=N-1;L>=A&&L!==A;L--){let q=(L!==N?Math.abs(v[L]):0)+(L!==A+1?Math.abs(v[L-1]):0);if(Math.abs(w[L])<=T*q){w[L]=0;break}}L===A?O=3:L===N-1?O=1:(O=2,A=L)}switch(A++,O){case 1:{let L=v[N-2];v[N-2]=0;for(let q=N-2;q>=A;q--){let U=pn(w[q],L),W=w[q]/U,z=L/U;if(w[q]=U,q!==A&&(L=-z*v[q-1],v[q-1]=W*v[q-1]),h)for(let K=0;K<n;K++)U=W*y.get(K,q)+z*y.get(K,N-1),y.set(K,N-1,-z*y.get(K,q)+W*y.get(K,N-1)),y.set(K,q,U)}break}case 2:{let L=v[A-1];v[A-1]=0;for(let q=A;q<N;q++){let U=pn(w[q],L),W=w[q]/U,z=L/U;if(w[q]=U,L=-z*v[q],v[q]=W*v[q],c)for(let K=0;K<r;K++)U=W*m.get(K,q)+z*m.get(K,A-1),m.set(K,A-1,-z*m.get(K,q)+W*m.get(K,A-1)),m.set(K,q,U)}break}case 3:{const L=Math.max(Math.abs(w[N-1]),Math.abs(w[N-2]),Math.abs(v[N-2]),Math.abs(w[A]),Math.abs(v[A])),q=w[N-1]/L,U=w[N-2]/L,W=v[N-2]/L,z=w[A]/L,K=v[A]/L,Z=((U+q)*(U-q)+W*W)/2,X=q*W*(q*W);let Q=0;(Z!==0||X!==0)&&(Z<0?Q=0-Math.sqrt(Z*Z+X):Q=Math.sqrt(Z*Z+X),Q=X/(Z+Q));let ct=(z+q)*(z-q)+Q,vt=z*K;for(let lt=A;lt<N-1;lt++){let yt=pn(ct,vt);yt===0&&(yt=Number.MIN_VALUE);let bt=ct/yt,Ot=vt/yt;if(lt!==A&&(v[lt-1]=yt),ct=bt*w[lt]+Ot*v[lt],v[lt]=bt*v[lt]-Ot*w[lt],vt=Ot*w[lt+1],w[lt+1]=bt*w[lt+1],h)for(let xt=0;xt<n;xt++)yt=bt*y.get(xt,lt)+Ot*y.get(xt,lt+1),y.set(xt,lt+1,-Ot*y.get(xt,lt)+bt*y.get(xt,lt+1)),y.set(xt,lt,yt);if(yt=pn(ct,vt),yt===0&&(yt=Number.MIN_VALUE),bt=ct/yt,Ot=vt/yt,w[lt]=yt,ct=bt*v[lt]+Ot*w[lt+1],w[lt+1]=-Ot*v[lt]+bt*w[lt+1],vt=Ot*v[lt+1],v[lt+1]=bt*v[lt+1],c&&lt<r-1)for(let xt=0;xt<r;xt++)yt=bt*m.get(xt,lt)+Ot*m.get(xt,lt+1),m.set(xt,lt+1,-Ot*m.get(xt,lt)+bt*m.get(xt,lt+1)),m.set(xt,lt,yt)}v[N-2]=ct;break}case 4:{if(w[A]<=0&&(w[A]=w[A]<0?-w[A]:0,h))for(let L=0;L<=S;L++)y.set(L,A,-y.get(L,A));for(;A<S&&!(w[A]>=w[A+1]);){let L=w[A];if(w[A]=w[A+1],w[A+1]=L,h&&A<n-1)for(let q=0;q<n;q++)L=y.get(q,A+1),y.set(q,A+1,y.get(q,A)),y.set(q,A,L);if(c&&A<r-1)for(let q=0;q<r;q++)L=m.get(q,A+1),m.set(q,A+1,m.get(q,A)),m.set(q,A,L);A++}N--;break}}}if(d){let A=y;y=m,m=A}this.m=r,this.n=n,this.s=w,this.U=m,this.V=y}solve(t){let e=t,r=this.threshold,n=this.s.length,s=dt.zeros(n,n);for(let p=0;p<n;p++)Math.abs(this.s[p])<=r?s.set(p,p,0):s.set(p,p,1/this.s[p]);let a=this.U,l=this.rightSingularVectors,c=l.mmul(s),h=l.rows,d=a.rows,f=dt.zeros(h,d);for(let p=0;p<h;p++)for(let g=0;g<d;g++){let w=0;for(let m=0;m<n;m++)w+=c.get(p,m)*a.get(g,m);f.set(p,g,w)}return f.mmul(e)}solveForDiagonal(t){return this.solve(dt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new dt(r,this.s.length);for(let d=0;d<r;d++)for(let f=0;f<n;f++)Math.abs(this.s[f])>e&&s.set(d,f,t.get(d,f)/this.s[f]);let a=this.U,l=a.rows,c=a.columns,h=new dt(r,l);for(let d=0;d<r;d++)for(let f=0;f<l;f++){let p=0;for(let g=0;g<c;g++)p+=s.get(d,g)*a.get(f,g);h.set(d,f,p)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return dt.diag(this.s)}}function Fw(i,t=!1){return i=wr.checkMatrix(i),t?new Si(i).inverse():sh(i,dt.eye(i.rows))}function sh(i,t,e=!1){return i=wr.checkMatrix(i),t=wr.checkMatrix(t),e?new Si(i).solve(t):i.isSquare()?new ho(i).solve(t):new Ja(i).solve(t)}function po(i){if(i=dt.checkMatrix(i),i.isSquare()){if(i.columns===0)return 1;let t,e,r,n;if(i.columns===2)return t=i.get(0,0),e=i.get(0,1),r=i.get(1,0),n=i.get(1,1),t*n-e*r;if(i.columns===3){let s,a,l;return s=new fo(i,[1,2],[1,2]),a=new fo(i,[1,2],[0,2]),l=new fo(i,[1,2],[0,1]),t=i.get(0,0),e=i.get(0,1),r=i.get(0,2),t*po(s)-e*po(a)+r*po(l)}else return new ho(i).determinant}else throw Error("determinant can only be calculated for a square matrix")}function Mw(i,t){let e=[];for(let r=0;r<i;r++)r!==t&&e.push(r);return e}function Nw(i,t,e,r=1e-9,n=1e-9){if(i>n)return new Array(t.rows+1).fill(0);{let s=t.addRow(e,[0]);for(let a=0;a<s.rows;a++)Math.abs(s.get(a,0))<r&&s.set(a,0,0);return s.to1DArray()}}function Sw(i,t={}){const{thresholdValue:e=1e-9,thresholdError:r=1e-9}=t;i=dt.checkMatrix(i);let n=i.rows,s=new dt(n,n);for(let a=0;a<n;a++){let l=dt.columnVector(i.getRow(a)),c=i.subMatrixRow(Mw(n,a)).transpose(),d=new Si(c).solve(l),f=dt.sub(l,c.mmul(d)).abs().max();s.setRow(a,Nw(f,d,a,e,r))}return s}function Ow(i,t=Number.EPSILON){if(i=dt.checkMatrix(i),i.isEmpty())return i.transpose();let e=new Si(i,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,s=e.diagonal;for(let a=0;a<s.length;a++)Math.abs(s[a])>t?s[a]=1/s[a]:s[a]=0;return n.mmul(dt.diag(s).mmul(r.transpose()))}function Bw(i,t=i,e={}){i=new dt(i);let r=!1;if(typeof t=="object"&&!dt.isMatrix(t)&&!fr.isAnyArray(t)?(e=t,t=i,r=!0):t=new dt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=e;n&&(i=i.center("column"),r||(t=t.center("column")));const s=i.transpose().mmul(t);for(let a=0;a<s.rows;a++)for(let l=0;l<s.columns;l++)s.set(a,l,s.get(a,l)*(1/(i.rows-1)));return s}function Iw(i,t=i,e={}){i=new dt(i);let r=!1;if(typeof t=="object"&&!dt.isMatrix(t)&&!fr.isAnyArray(t)?(e=t,t=i,r=!0):t=new dt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:s=!0}=e;n&&(i.center("column"),r||t.center("column")),s&&(i.scale("column"),r||t.scale("column"));const a=i.standardDeviation("column",{unbiased:!0}),l=r?a:t.standardDeviation("column",{unbiased:!0}),c=i.transpose().mmul(t);for(let h=0;h<c.rows;h++)for(let d=0;d<c.columns;d++)c.set(h,d,c.get(h,d)*(1/(a[h]*l[d]))*(1/(i.rows-1)));return c}let oh=class{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(t=wr.checkMatrix(t),!t.isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let n=t.columns,s=new dt(n,n),a=new Float64Array(n),l=new Float64Array(n),c=t,h,d,f=!1;if(r?f=!0:f=t.isSymmetric(),f){for(h=0;h<n;h++)for(d=0;d<n;d++)s.set(h,d,c.get(h,d));Tw(n,l,a,s),$w(n,l,a,s)}else{let p=new dt(n,n),g=new Float64Array(n);for(d=0;d<n;d++)for(h=0;h<n;h++)p.set(h,d,c.get(h,d));Lw(n,p,g,s),Rw(n,l,a,s,p)}this.n=n,this.e=l,this.d=a,this.V=s}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t=this.n,e=this.e,r=this.d,n=new dt(t,t),s,a;for(s=0;s<t;s++){for(a=0;a<t;a++)n.set(s,a,0);n.set(s,s,r[s]),e[s]>0?n.set(s,s+1,e[s]):e[s]<0&&n.set(s,s-1,e[s])}return n}};function Tw(i,t,e,r){let n,s,a,l,c,h,d,f;for(c=0;c<i;c++)e[c]=r.get(i-1,c);for(l=i-1;l>0;l--){for(f=0,a=0,h=0;h<l;h++)f=f+Math.abs(e[h]);if(f===0)for(t[l]=e[l-1],c=0;c<l;c++)e[c]=r.get(l-1,c),r.set(l,c,0),r.set(c,l,0);else{for(h=0;h<l;h++)e[h]/=f,a+=e[h]*e[h];for(n=e[l-1],s=Math.sqrt(a),n>0&&(s=-s),t[l]=f*s,a=a-n*s,e[l-1]=n-s,c=0;c<l;c++)t[c]=0;for(c=0;c<l;c++){for(n=e[c],r.set(c,l,n),s=t[c]+r.get(c,c)*n,h=c+1;h<=l-1;h++)s+=r.get(h,c)*e[h],t[h]+=r.get(h,c)*n;t[c]=s}for(n=0,c=0;c<l;c++)t[c]/=a,n+=t[c]*e[c];for(d=n/(a+a),c=0;c<l;c++)t[c]-=d*e[c];for(c=0;c<l;c++){for(n=e[c],s=t[c],h=c;h<=l-1;h++)r.set(h,c,r.get(h,c)-(n*t[h]+s*e[h]));e[c]=r.get(l-1,c),r.set(l,c,0)}}e[l]=a}for(l=0;l<i-1;l++){if(r.set(i-1,l,r.get(l,l)),r.set(l,l,1),a=e[l+1],a!==0){for(h=0;h<=l;h++)e[h]=r.get(h,l+1)/a;for(c=0;c<=l;c++){for(s=0,h=0;h<=l;h++)s+=r.get(h,l+1)*r.get(h,c);for(h=0;h<=l;h++)r.set(h,c,r.get(h,c)-s*e[h])}}for(h=0;h<=l;h++)r.set(h,l+1,0)}for(c=0;c<i;c++)e[c]=r.get(i-1,c),r.set(i-1,c,0);r.set(i-1,i-1,1),t[0]=0}function $w(i,t,e,r){let n,s,a,l,c,h,d,f,p,g,w,m,y,v,x,b;for(a=1;a<i;a++)t[a-1]=t[a];t[i-1]=0;let M=0,E=0,C=Number.EPSILON;for(h=0;h<i;h++){for(E=Math.max(E,Math.abs(e[h])+Math.abs(t[h])),d=h;d<i&&!(Math.abs(t[d])<=C*E);)d++;if(d>h)do{for(n=e[h],f=(e[h+1]-n)/(2*t[h]),p=pn(f,1),f<0&&(p=-p),e[h]=t[h]/(f+p),e[h+1]=t[h]*(f+p),g=e[h+1],s=n-e[h],a=h+2;a<i;a++)e[a]-=s;for(M=M+s,f=e[d],w=1,m=w,y=w,v=t[h+1],x=0,b=0,a=d-1;a>=h;a--)for(y=m,m=w,b=x,n=w*t[a],s=w*f,p=pn(f,t[a]),t[a+1]=x*p,x=t[a]/p,w=f/p,f=w*e[a]-x*n,e[a+1]=s+x*(w*n+x*e[a]),c=0;c<i;c++)s=r.get(c,a+1),r.set(c,a+1,x*r.get(c,a)+w*s),r.set(c,a,w*r.get(c,a)-x*s);f=-x*b*y*v*t[h]/g,t[h]=x*f,e[h]=w*f}while(Math.abs(t[h])>C*E);e[h]=e[h]+M,t[h]=0}for(a=0;a<i-1;a++){for(c=a,f=e[a],l=a+1;l<i;l++)e[l]<f&&(c=l,f=e[l]);if(c!==a)for(e[c]=e[a],e[a]=f,l=0;l<i;l++)f=r.get(l,a),r.set(l,a,r.get(l,c)),r.set(l,c,f)}}function Lw(i,t,e,r){let n=0,s=i-1,a,l,c,h,d,f,p;for(f=n+1;f<=s-1;f++){for(p=0,h=f;h<=s;h++)p=p+Math.abs(t.get(h,f-1));if(p!==0){for(c=0,h=s;h>=f;h--)e[h]=t.get(h,f-1)/p,c+=e[h]*e[h];for(l=Math.sqrt(c),e[f]>0&&(l=-l),c=c-e[f]*l,e[f]=e[f]-l,d=f;d<i;d++){for(a=0,h=s;h>=f;h--)a+=e[h]*t.get(h,d);for(a=a/c,h=f;h<=s;h++)t.set(h,d,t.get(h,d)-a*e[h])}for(h=0;h<=s;h++){for(a=0,d=s;d>=f;d--)a+=e[d]*t.get(h,d);for(a=a/c,d=f;d<=s;d++)t.set(h,d,t.get(h,d)-a*e[d])}e[f]=p*e[f],t.set(f,f-1,p*l)}}for(h=0;h<i;h++)for(d=0;d<i;d++)r.set(h,d,h===d?1:0);for(f=s-1;f>=n+1;f--)if(t.get(f,f-1)!==0){for(h=f+1;h<=s;h++)e[h]=t.get(h,f-1);for(d=f;d<=s;d++){for(l=0,h=f;h<=s;h++)l+=e[h]*r.get(h,d);for(l=l/e[f]/t.get(f,f-1),h=f;h<=s;h++)r.set(h,d,r.get(h,d)+l*e[h])}}}function Rw(i,t,e,r,n){let s=i-1,a=0,l=i-1,c=Number.EPSILON,h=0,d=0,f=0,p=0,g=0,w=0,m=0,y=0,v,x,b,M,E,C,N,S,T,A,O,L,q,U,W;for(v=0;v<i;v++)for((v<a||v>l)&&(e[v]=n.get(v,v),t[v]=0),x=Math.max(v-1,0);x<i;x++)d=d+Math.abs(n.get(v,x));for(;s>=a;){for(M=s;M>a&&(w=Math.abs(n.get(M-1,M-1))+Math.abs(n.get(M,M)),w===0&&(w=d),!(Math.abs(n.get(M,M-1))<c*w));)M--;if(M===s)n.set(s,s,n.get(s,s)+h),e[s]=n.get(s,s),t[s]=0,s--,y=0;else if(M===s-1){if(N=n.get(s,s-1)*n.get(s-1,s),f=(n.get(s-1,s-1)-n.get(s,s))/2,p=f*f+N,m=Math.sqrt(Math.abs(p)),n.set(s,s,n.get(s,s)+h),n.set(s-1,s-1,n.get(s-1,s-1)+h),S=n.get(s,s),p>=0){for(m=f>=0?f+m:f-m,e[s-1]=S+m,e[s]=e[s-1],m!==0&&(e[s]=S-N/m),t[s-1]=0,t[s]=0,S=n.get(s,s-1),w=Math.abs(S)+Math.abs(m),f=S/w,p=m/w,g=Math.sqrt(f*f+p*p),f=f/g,p=p/g,x=s-1;x<i;x++)m=n.get(s-1,x),n.set(s-1,x,p*m+f*n.get(s,x)),n.set(s,x,p*n.get(s,x)-f*m);for(v=0;v<=s;v++)m=n.get(v,s-1),n.set(v,s-1,p*m+f*n.get(v,s)),n.set(v,s,p*n.get(v,s)-f*m);for(v=a;v<=l;v++)m=r.get(v,s-1),r.set(v,s-1,p*m+f*r.get(v,s)),r.set(v,s,p*r.get(v,s)-f*m)}else e[s-1]=S+f,e[s]=S+f,t[s-1]=m,t[s]=-m;s=s-2,y=0}else{if(S=n.get(s,s),T=0,N=0,M<s&&(T=n.get(s-1,s-1),N=n.get(s,s-1)*n.get(s-1,s)),y===10){for(h+=S,v=a;v<=s;v++)n.set(v,v,n.get(v,v)-S);w=Math.abs(n.get(s,s-1))+Math.abs(n.get(s-1,s-2)),S=T=.75*w,N=-.4375*w*w}if(y===30&&(w=(T-S)/2,w=w*w+N,w>0)){for(w=Math.sqrt(w),T<S&&(w=-w),w=S-N/((T-S)/2+w),v=a;v<=s;v++)n.set(v,v,n.get(v,v)-w);h+=w,S=T=N=.964}for(y=y+1,E=s-2;E>=M&&(m=n.get(E,E),g=S-m,w=T-m,f=(g*w-N)/n.get(E+1,E)+n.get(E,E+1),p=n.get(E+1,E+1)-m-g-w,g=n.get(E+2,E+1),w=Math.abs(f)+Math.abs(p)+Math.abs(g),f=f/w,p=p/w,g=g/w,!(E===M||Math.abs(n.get(E,E-1))*(Math.abs(p)+Math.abs(g))<c*(Math.abs(f)*(Math.abs(n.get(E-1,E-1))+Math.abs(m)+Math.abs(n.get(E+1,E+1))))));)E--;for(v=E+2;v<=s;v++)n.set(v,v-2,0),v>E+2&&n.set(v,v-3,0);for(b=E;b<=s-1&&(U=b!==s-1,b!==E&&(f=n.get(b,b-1),p=n.get(b+1,b-1),g=U?n.get(b+2,b-1):0,S=Math.abs(f)+Math.abs(p)+Math.abs(g),S!==0&&(f=f/S,p=p/S,g=g/S)),S!==0);b++)if(w=Math.sqrt(f*f+p*p+g*g),f<0&&(w=-w),w!==0){for(b!==E?n.set(b,b-1,-w*S):M!==E&&n.set(b,b-1,-n.get(b,b-1)),f=f+w,S=f/w,T=p/w,m=g/w,p=p/f,g=g/f,x=b;x<i;x++)f=n.get(b,x)+p*n.get(b+1,x),U&&(f=f+g*n.get(b+2,x),n.set(b+2,x,n.get(b+2,x)-f*m)),n.set(b,x,n.get(b,x)-f*S),n.set(b+1,x,n.get(b+1,x)-f*T);for(v=0;v<=Math.min(s,b+3);v++)f=S*n.get(v,b)+T*n.get(v,b+1),U&&(f=f+m*n.get(v,b+2),n.set(v,b+2,n.get(v,b+2)-f*g)),n.set(v,b,n.get(v,b)-f),n.set(v,b+1,n.get(v,b+1)-f*p);for(v=a;v<=l;v++)f=S*r.get(v,b)+T*r.get(v,b+1),U&&(f=f+m*r.get(v,b+2),r.set(v,b+2,r.get(v,b+2)-f*g)),r.set(v,b,r.get(v,b)-f),r.set(v,b+1,r.get(v,b+1)-f*p)}}}if(d!==0){for(s=i-1;s>=0;s--)if(f=e[s],p=t[s],p===0)for(M=s,n.set(s,s,1),v=s-1;v>=0;v--){for(N=n.get(v,v)-f,g=0,x=M;x<=s;x++)g=g+n.get(v,x)*n.get(x,s);if(t[v]<0)m=N,w=g;else if(M=v,t[v]===0?n.set(v,s,N!==0?-g/N:-g/(c*d)):(S=n.get(v,v+1),T=n.get(v+1,v),p=(e[v]-f)*(e[v]-f)+t[v]*t[v],C=(S*w-m*g)/p,n.set(v,s,C),n.set(v+1,s,Math.abs(S)>Math.abs(m)?(-g-N*C)/S:(-w-T*C)/m)),C=Math.abs(n.get(v,s)),c*C*C>1)for(x=v;x<=s;x++)n.set(x,s,n.get(x,s)/C)}else if(p<0)for(M=s-1,Math.abs(n.get(s,s-1))>Math.abs(n.get(s-1,s))?(n.set(s-1,s-1,p/n.get(s,s-1)),n.set(s-1,s,-(n.get(s,s)-f)/n.get(s,s-1))):(W=_o(0,-n.get(s-1,s),n.get(s-1,s-1)-f,p),n.set(s-1,s-1,W[0]),n.set(s-1,s,W[1])),n.set(s,s-1,0),n.set(s,s,1),v=s-2;v>=0;v--){for(A=0,O=0,x=M;x<=s;x++)A=A+n.get(v,x)*n.get(x,s-1),O=O+n.get(v,x)*n.get(x,s);if(N=n.get(v,v)-f,t[v]<0)m=N,g=A,w=O;else if(M=v,t[v]===0?(W=_o(-A,-O,N,p),n.set(v,s-1,W[0]),n.set(v,s,W[1])):(S=n.get(v,v+1),T=n.get(v+1,v),L=(e[v]-f)*(e[v]-f)+t[v]*t[v]-p*p,q=(e[v]-f)*2*p,L===0&&q===0&&(L=c*d*(Math.abs(N)+Math.abs(p)+Math.abs(S)+Math.abs(T)+Math.abs(m))),W=_o(S*g-m*A+p*O,S*w-m*O-p*A,L,q),n.set(v,s-1,W[0]),n.set(v,s,W[1]),Math.abs(S)>Math.abs(m)+Math.abs(p)?(n.set(v+1,s-1,(-A-N*n.get(v,s-1)+p*n.get(v,s))/S),n.set(v+1,s,(-O-N*n.get(v,s)-p*n.get(v,s-1))/S)):(W=_o(-g-T*n.get(v,s-1),-w-T*n.get(v,s),m,p),n.set(v+1,s-1,W[0]),n.set(v+1,s,W[1]))),C=Math.max(Math.abs(n.get(v,s-1)),Math.abs(n.get(v,s))),c*C*C>1)for(x=v;x<=s;x++)n.set(x,s-1,n.get(x,s-1)/C),n.set(x,s,n.get(x,s)/C)}for(v=0;v<i;v++)if(v<a||v>l)for(x=v;x<i;x++)r.set(v,x,n.get(v,x));for(x=i-1;x>=a;x--)for(v=a;v<=l;v++){for(m=0,b=a;b<=Math.min(x,l);b++)m=m+r.get(v,b)*n.get(b,x);r.set(v,x,m)}}}function _o(i,t,e,r){let n,s;return Math.abs(e)>Math.abs(r)?(n=r/e,s=e+n*r,[(i+n*t)/s,(t-n*i)/s]):(n=e/r,s=r+n*e,[(n*i+t)/s,(n*t-i)/s])}class ah{constructor(t){if(t=wr.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");let e=t,r=e.rows,n=new dt(r,r),s=!0,a,l,c;for(l=0;l<r;l++){let h=0;for(c=0;c<l;c++){let d=0;for(a=0;a<c;a++)d+=n.get(c,a)*n.get(l,a);d=(e.get(l,c)-d)/n.get(c,c),n.set(l,c,d),h=h+d*d}for(h=e.get(l,l)-h,s&=h>0,n.set(l,l,Math.sqrt(Math.max(h,0))),c=l+1;c<r;c++)n.set(l,c,0)}this.L=n,this.positiveDefinite=!!s}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=wr.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=t.columns,s=t.clone(),a,l,c;for(c=0;c<r;c++)for(l=0;l<n;l++){for(a=0;a<c;a++)s.set(c,l,s.get(c,l)-s.get(a,l)*e.get(c,a));s.set(c,l,s.get(c,l)/e.get(c,c))}for(c=r-1;c>=0;c--)for(l=0;l<n;l++){for(a=c+1;a<r;a++)s.set(c,l,s.get(c,l)-s.get(a,l)*e.get(a,c));s.set(c,l,s.get(c,l)/e.get(c,c))}return s}get lowerTriangularMatrix(){return this.L}}class uh{constructor(t,e={}){t=wr.checkMatrix(t);let{Y:r}=e;const{scaleScores:n=!1,maxIterations:s=1e3,terminationCriteria:a=1e-10}=e;let l;if(r){if(fr.isAnyArray(r)&&typeof r[0]=="number"?r=dt.columnVector(r):r=wr.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");l=r.getColumnVector(0)}else l=t.getColumnVector(0);let c=1,h,d,f,p;for(let g=0;g<s&&c>a;g++)f=t.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),f=f.div(f.norm()),h=t.mmul(f).div(f.transpose().mmul(f).get(0,0)),g>0&&(c=h.clone().sub(p).pow(2).sum()),p=h.clone(),r?(d=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),d=d.div(d.norm()),l=r.mmul(d).div(d.transpose().mmul(d).get(0,0))):l=h;if(r){let g=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));g=g.div(g.norm());let w=t.clone().sub(h.clone().mmul(g.transpose())),m=l.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),y=r.clone().sub(h.clone().mulS(m.get(0,0)).mmul(d.transpose()));this.t=h,this.p=g.transpose(),this.w=f.transpose(),this.q=d,this.u=l,this.s=h.transpose().mmul(h),this.xResidual=w,this.yResidual=y,this.betas=m}else this.w=f.transpose(),this.s=h.transpose().mmul(h).sqrt(),n?this.t=h.clone().div(this.s.get(0,0)):this.t=h,this.xResidual=t.sub(h.mmul(f.transpose()))}}kt.AbstractMatrix=$t,kt.CHO=ah,kt.CholeskyDecomposition=ah,kt.DistanceMatrix=co,kt.EVD=oh;var Pw=kt.EigenvalueDecomposition=oh;kt.LU=ho,kt.LuDecomposition=ho;var lh=kt.Matrix=dt;kt.MatrixColumnSelectionView=ww,kt.MatrixColumnView=vw,kt.MatrixFlipColumnView=yw,kt.MatrixFlipRowView=Dw,kt.MatrixRowSelectionView=xw,kt.MatrixRowView=bw,kt.MatrixSelectionView=fo,kt.MatrixSubView=Ew,kt.MatrixTransposeView=Aw,kt.NIPALS=uh,kt.Nipals=uh,kt.QR=Ja,kt.QrDecomposition=Ja,kt.SVD=Si,kt.SingularValueDecomposition=Si,kt.SymmetricMatrix=ti,kt.WrapperMatrix1D=ih,kt.WrapperMatrix2D=wr,kt.correlation=Iw,kt.covariance=Bw;var ch=kt.default=dt;kt.determinant=po,kt.inverse=Fw,kt.linearDependencies=Sw,kt.pseudoInverse=Ow,kt.solve=sh,kt.wrap=Cw;const fh=Pw,hh=lh;ch.Matrix&&ch.Matrix;class zw{constructor(t){$(this,"_errorListener");this._errorListener=t}new({rows:t,columns:e,initial_value:r}={}){return new Xa(t,e,r,this._errorListener)}avg({id:t}){return t==null?void 0:t.avg()}col({id:t,column:e}){return t==null?void 0:t.col({column:e})}det({id:t}){return t==null?void 0:t.det()}get({id:t,row:e,column:r}){return t==null?void 0:t.get({row:e,column:r})}inv({id:t}){return t==null?void 0:t.inv()}max({id:t}){return t==null?void 0:t.max()}min({id:t}){return t==null?void 0:t.min()}pow({id:t,power:e}){return t==null?void 0:t.pow({power:e})}row({id:t,row:e}){return t==null?void 0:t.row({row:e})}set({id:t,row:e,column:r,value:n}){t==null||t.set({row:e,column:r,value:n})}sum({id1:t,id2:e}){return t==null?void 0:t.sum({id2:e})}copy({id:t}){return t==null?void 0:t.copy()}diff({id1:t,id2:e}){return t==null?void 0:t.diff({id2:e})}rows({id:t}){return t==null?void 0:t.rows()}columns({id:t}){return t==null?void 0:t.columns()}fill({id:t,value:e,from_row:r,to_row:n,from_column:s,to_column:a}){t==null||t.fill({value:e,from_row:r,to_row:n,from_column:s,to_column:a})}kron({id1:t,id2:e}){return t==null?void 0:t.kron({id2:e})}mode({id:t}){return t==null?void 0:t.mode()}mult({id1:t,id2:e}){return t==null?void 0:t.mult({id2:e})}pinv({id:t}){return t==null?void 0:t.pinv()}rank({id:t}){return t==null?void 0:t.rank()}sort({id:t,column:e,order:r}){t==null||t.sort({column:e,order:r})}trace({id:t}){return t==null?void 0:t.trace()}concat({id1:t,id2:e}){return t==null?void 0:t.concat({id2:e})}median({id:t}){return t==null?void 0:t.median()}add_col({id:t,column:e,array_id:r}){t==null||t.add_col({column:e,array_id:r})}add_row({id:t,row:e,array_id:r}){t==null||t.add_row({row:e,array_id:r})}is_zero({id:t}){return t==null?void 0:t.is_zero()}reshape({id:t,rows:e,columns:r},n){return t==null?void 0:t.reshape({rows:e,columns:r},n)}reverse({id:t}){t==null||t.reverse()}is_binary({id:t}){return t==null?void 0:t.is_binary()}is_square({id:t}){return t==null?void 0:t.is_square()}submatrix({id:t,from_row:e,to_row:r,from_column:n,to_column:s}){return t==null?void 0:t.submatrix({from_row:e,to_row:r,from_column:n,to_column:s})}swap_rows({id:t,row1:e,row2:r}){t==null||t.swap_rows({row1:e,row2:r})}transpose({id:t}){return t==null?void 0:t.transpose()}remove_col({id:t,column:e}){return t==null?void 0:t.remove_col({column:e})}remove_row({id:t,row:e}){return t==null?void 0:t.remove_row({row:e})}eigenvalues({id:t}){return t==null?void 0:t.eigenvalues()}is_diagonal({id:t}){return t==null?void 0:t.is_diagonal()}is_identity({id:t}){return t==null?void 0:t.is_identity()}eigenvectors({id:t}){return t==null?void 0:t.eigenvectors()}is_symmetric({id:t}){return t==null?void 0:t.is_symmetric()}swap_columns({id:t,column1:e,column2:r}){t==null||t.swap_columns({column1:e,column2:r})}is_stochastic({id:t}){return t==null?void 0:t.is_stochastic()}is_triangular({id:t}){return t==null?void 0:t.is_triangular()}elements_count({id:t}){return t==null?void 0:t.elements_count()}is_antidiagonal({id:t}){return t==null?void 0:t.is_antidiagonal()}is_antisymmetric({id:t}){return t==null?void 0:t.is_antisymmetric()}}class Xa{constructor(t=0,e=0,r=void 0,n){$(this,"_matrixInstance");$(this,"_errorListener");this._matrixInstance=this._createMatrix(t,e,r),this._errorListener=n}get _matrixArray(){return this._matrixInstance.map(t=>[...t._value])}get _value(){return this._matrixInstance}set _value(t){this._matrixInstance=t}get isMatrix(){return!0}_createMatrix(t,e,r){return Array.from(new Array(t),()=>new Qt(e,r,this._errorListener))}avg(){let t=0,e=0;for(const n of this._matrixInstance)for(const s of n._value)t+=_t(s)?0:s,e+=1;return t/e}col({column:t}){const e=[],r=new Qt(0,void 0,this._errorListener);if(_t(t))return r;for(const n of this._matrixInstance)e.push(n._value[t]);return r._value=e,r}det(){return Jf(this._matrixArray)}get({row:t,column:e}){var r,n;if(!(_t(t)||_t(e)))return(n=(r=this._matrixInstance[t])==null?void 0:r._value)==null?void 0:n[e]}inv(){const t=oo(this._matrixArray);return this._newMatrix(t)}max(){return T1(this._matrixArray)}min(){return Za(this._matrixArray)}pow({power:t}){const e=_t(t)?this._matrixArray:L1(this._matrixArray,t);return this._newMatrix(e)}row({row:t}){return _t(t)?new Qt(0,void 0,this._errorListener):this._matrixInstance[t]}set({row:t,column:e,value:r}){_t(t)||_t(e)||this._matrixInstance[t].set({index:e,value:r})}sum({id2:t}){const e=os(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:t}){const e=M1(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:t,from_row:e,to_row:r,from_column:n,to_column:s}={}){_t(e)&&(e=0),_t(r)&&(r=this.rows()),_t(n)&&(n=0),_t(s)&&(s=this.columns());for(const[a,l]of this._matrixInstance.entries())for(const[c]of l._value.entries())a<r&&a>=e&&c>=n&&c<s&&l.set({index:c,value:t})}kron({id2:t}){const e=C1(this._matrixArray,t._matrixArray);return this._newMatrix(e)}mode(){return Za(jf(this._matrixArray))}mult({id2:t}){const e=typeof t=="number"?t:t._matrixArray?t._matrixArray:t._value,r=Ci(this._matrixArray,e);return this._newMatrix(r)}pinv(){const t=$1(this._matrixArray);return this._newMatrix(t)}rank(){return this._matrixRank(this._matrixArray)}sort({column:t,order:e=Kn.ascending}={}){_t(t)&&(t=0),this._matrixInstance.sort((r,n)=>{const s=r._value[t],a=n._value[t];return e!==Kn.descending?s-a:a-s})}trace(){return I1(this._matrixArray)}concat({id2:t}){for(const e of t._value)this._matrixInstance.push(e);return this}median(){return Xf(this._matrixArray)}add_col({column:t,array_id:e}={}){_t(t)&&(t=this.columns());for(const[r,n]of this._matrixInstance.entries())n.insert({index:t,value:e?e._value[r]:void 0})}add_row({row:t,array_id:e}){_t(t)&&(t=this.rows()),this._matrixInstance.splice(t,0,e||new Qt(this.columns(),void 0,this._errorListener))}is_zero(){return this._matrixArray.every(t=>t.every(e=>e===0))}reshape({rows:t=0,columns:e=0},r){if(t*e!==this.columns()*this.rows()){this._errorListener.addError(se.matrixRehapeErr,r,Pt.Error);return}const n=b1(this._matrixArray,[t,e]);this._matrixInstance=n.map(s=>{const a=new Qt(0,void 0,this._errorListener);return a._value=[...s],a})}reverse(){this._matrixInstance.reverse();for(const t of this._matrixInstance)t.reverse()}is_binary(){return this._matrixArray.every(t=>t.every(e=>e===0||e===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:t,to_row:e,from_column:r,to_column:n}={}){_t(t)&&(t=0),_t(e)&&(e=this.rows()),_t(r)&&(r=0),_t(n)&&(n=this.columns());const s=this._matrixArray.splice(t,e),a=[];for(const l of s)a.push(l.splice(r,n));return this._newMatrix(a)}swap_rows({row1:t,row2:e}){if(_t(t)||_t(e))return;const r=this._matrixInstance[t],n=this._matrixInstance[e];this._matrixInstance[t]=n,this._matrixInstance[e]=r}transpose(){const t=Vf(this._matrixArray);return this._newMatrix(t)}remove_col({column:t}={}){_t(t)&&(t=this.columns());const e=[];for(const n of this._matrixInstance){const s=n._value.splice(t,1);e.push(s[0])}const r=new Qt(0,void 0,this._errorListener);return r._value=e,r}remove_row({row:t}={}){return _t(t)&&(t=this.rows()),this._matrixInstance.splice(t,1)[0]}eigenvalues(){const t=new fh(new hh(this._matrixArray)),e=new Qt(0,void 0,this._errorListener);return e._value=t.realEigenvalues,e}is_diagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0)return!1;return!0}is_identity(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0||n===s&&r[n][s]!==1)return!1;return!0}eigenvectors(){const t=new fh(new hh(this._matrixArray));return this._newMatrix(t.eigenvectorMatrix.to2DArray())}is_symmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=n+1;s<e;s++)if(r[n][s]!==r[s][n])return!1;return!0}swap_columns({column1:t,column2:e}){if(!(_t(t)||_t(e)))for(const r of this._matrixInstance){const n=r._value[t],s=r._value[e];r.set({index:t,value:s}),r.set({index:e,value:n})}}is_stochastic(){const t=this._matrixArray;for(let e=0;e<t.length;e++){let r=0;for(let n=0;n<t[e].length;n++){if(t[e][n]<0)return!1;r+=t[e][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const t=this.rows(),e=this.columns();return t!==e?!1:this._isUpperTriangular(t)||this._isLowerTriangular(t)}elements_count(){return x1(this._matrixArray)}is_antidiagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n+s!==t-1&&r[n][s]!==0)return!1;return!0}is_antisymmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n!==s&&r[n][s]!==-r[s][n])return!1;return!0}_isUpperTriangular(t){const e=this._matrixArray;for(let r=1;r<t;r++)for(let n=0;n<r;n++)if(e[r][n]!==0)return!1;return!0}_isLowerTriangular(t){const e=this._matrixArray;for(let r=0;r<t-1;r++)for(let n=r+1;n<t;n++)if(e[r][n]!==0)return!1;return!0}_newMatrix(t){const e=new Xa(0,0,void 0,this._errorListener);return e._value=t.map(r=>{const n=new Qt(0,void 0,this._errorListener);return n._value=[...r],n}),e}_matrixRank(t){let e=0;const r=t.length,n=t[0].length,s=[...t].map(a=>[...a]);for(let a=0;a<r&&!(a>=n);a++){let l=a;for(;l<r&&s[l][a]===0;)l++;if(l===r)continue;if(l!==a){const h=s[l];s[l]=s[a],s[a]=h}const c=s[a][a];for(let h=0;h<n;h++)s[a][h]/=c;for(let h=a+1;h<r;h++){const d=s[h][a];s[h]=s[h].map((f,p)=>f-d*s[a][p]),s[h][a]=0}}for(let a=0;a<r;a++)s[a].some(l=>Number(l.toFixed(8))!==0)&&e++;return e}}class kw{constructor(t){$(this,"_variables");$(this,"_cacheData");this._variables=t,this._cacheData={}}change({timeframe:t},e){if(!t)return!0;const r=tn(t),n=tn(this._variables.timeframe.period);if(r<n)return!0;const s=`change_${e}`,a=this._cacheData[s],l=this._variables.time;if(a){if(a.offset){if(a.currentTime+a.offset<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else if(a.currentTime+r*1e3<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else{const c=this._calcTimeOffset(l,t);return this._cacheData[s]={currentTime:l,offset:c},!1}return!1}in_seconds({timeframe:t}={}){return tn(t||this._variables.timeframe.period)}from_seconds({seconds:t=0}){const e=t*1e3,r=ee.duration(e);if(r.years())return"12M";const s=r.asMonths();if(io(s))return`${s}M`;const a=r.asWeeks();if(io(a))return`${a}M`;const l=r.asDays();if(l>=1)return`${Math.ceil(l)}D`;const c=r.asMinutes();if(c>=1)return`${Math.ceil(c)}`;const h=r.asSeconds();return h<=1?"1S":h<=5?"5S":h<=10?"10S":h<=15?"15S":h<=30?"30S":"1"}_calcTimeOffset(t,e){let r=0;if(e.includes("W")){const l=ee(t).day();e="1D",l!==1&&(r=(8-l)*60*60*24*1e3)}else if(e.includes("M")){const l=ee(t).date();e="1D";const c=ee(t).daysInMonth();l!==1&&(r=(c-l+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(t,e),s=tn(e)*1e3,a=t-n-Math.floor((t-n)/s)*s;return r?r-a:a}}class qw{constructor(t,e){$(this,"_errorListener");$(this,"_intlNumberFormatter");$(this,"_precision");this._errorListener=t,this._precision=e,this._intlNumberFormatter=new Intl.NumberFormat("en",{notation:"compact"})}pos({source:t="",str:e=""}){return t==null?void 0:t.indexOf(e)}trim({source:t=""}){return t==null?void 0:t.trim()}lower({source:t=""}){return t==null?void 0:t.toLocaleLowerCase()}match({source:t="",regex:e=""}){const r=t==null?void 0:t.match(new RegExp(e));return r?r[0]:""}split({string:t="",separator:e=""}){const r=t==null?void 0:t.split(e),n=new Qt;return n._value=r||[],n}upper({source:t=""}){return t==null?void 0:t.toLocaleUpperCase()}format({formatString:t=""},e){return this._strFormat(t,e)}length({string:t=""}){return t==null?void 0:t.length}repeat({source:t="",repeat:e,separator:r=""},n){if(_t(e)){this._errorListener.addError(se.arrLenErr,n,Pt.Error);return}return Array.from(new Array(e),()=>t).join(r)}replace({source:t="",target:e="",replacement:r="",occurrence:n}){_t(n)&&(n=0);let s=-1;for(let a=0;a<n+1&&(s=t.indexOf(e,s+1),s!==-1);a++);return s!==-1?t.substring(0,s)+r+t.substring(s+e.length):t}contains({source:t="",str:e=""}){return t==null?void 0:t.includes(e)}endswith({source:t="",str:e=""}){return t==null?void 0:t.endsWith(e)}tonumber({string:t=""}){if(/[^\d.]/.test(t))return;const e=parseFloat(t);return isNaN(e)?void 0:e}tostring({value:t,format:e}){if(t===void 0)return"NaN";if(typeof t=="object"){if(t.isArray)return this._arrToStr(t._value,e);if(t.isMatrix){const r=[];for(const n of t._matrixArray)r.push(this._arrToStr(n,e));return r.join(`
62
- `)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return String(this._toStringFormat(t,e==null?void 0:e.replace(/0/g,"#")))}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._toStringFormat(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return _t(e)&&(e=0),_t(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _t(t)&&(t=0),mr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_toStringFormat(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case Kt.mintick:return t.toFixed(this._precision);case Kt.percent:return`${t}%`;case Kt.volume:return this._intlNumberFormatter.format(Math.round(t));default:return this._formatOthers(t,e)}}_formatOthers(t,e){var l;let[r,n]=e.split(".");e.split("%").length===2&&(t=t*100);let[s,a=""]=String(t).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),h=((l=c[c.length-1])==null?void 0:l.replace(/[^#]/g,"").length)||0;h&&(s=s.replace(new RegExp(`\\B(?=(\\d{${h}})+(?!\\d))`,"g"),",")),r=c.join("")}s=r.replace(/#/,s).replace(/#/g,"")}else s=`${r}${s}`;if(n&&n.includes("#")){const c=n.split("#").length-1,h=+`${s}.${a}`;if(!isNaN(h))return`${h.toFixed(c)}${n.replace(/#/g,"")}`;a=`${a.substring(0,c)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${s}.${a}`:s}_formatNumber(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:return this._formatOthers(t,e)}}_strFormat(t,e){let r=t;for(const[n,s]of e.entries()){if(s===void 0||typeof s=="number"&&isNaN(s)){r="NaN";continue}if(typeof s=="number"){const a=`\\{\\s*${n}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const c=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(s,c)))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),String(s))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),s)}return r}}class Uw{constructor(t){$(this,"_errorListener");this._errorListener=t}new(){return new Qa(this._errorListener)}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class Qa{constructor(t){$(this,"_errorListener");$(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new Qa(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class Ww{constructor(t){$(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Oi(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Oi(t,r,e)}copy({id:t}){return t==null?void 0:t.copy()}from_index({price:t,index:e}){return new Oi(t,e)}from_time({price:t,time:e}){return new Oi(t,void 0,e)}}class Oi{constructor(t,e,r){$(this,"_index");$(this,"_price");$(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}set index(t){this._index=t}get price(){return this._price}set price(t){this._price=t}get time(){return this._time}set time(t){this._time=t}copy(){return new Oi(this._price,this._index,this._time)}}class jw{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLabel",{text:"",xloc:De.bar_index,yloc:jr.price,size:ir.normal,style:ve.styleLabelDown,textalign:Wt.alignCenter});this._variables=t,this._errorListener=e}new(t,e){const{time:r,high:n,low:s,bar_index:a}=this._variables,l=`label_${e}_${a}`;ge(t,["color","textcolor"]);const c={...this._defaultLabel,...t,id:l,time:r,high:n,low:s,bar_index:a};t.point&&(c.x=c.xloc===De.bar_index?t.point.index:t.point.time,c.y=t.point.price),c.yloc===jr.abovebar?c.y=n:c.yloc===jr.belowbar&&(c.y=s),this._verfiyArgs(t,e);const h=new mo(l,this._variables,this._errorListener);return e.startsWith("export")||this._variables.label.add(l,c,h),h}_verfiyArgs(t,e){const{xloc:r,yloc:n,style:s,size:a,textalign:l,text_font_family:c}=t,h="label.new";this._paramVerfiy(s,e,h,Object.values(ve),"style"),this._paramVerfiy(r,e,h,Object.values(De),"xloc"),this._paramVerfiy(n,e,h,Object.values(jr),"yloc"),this._paramVerfiy(a,e,h,Object.values(ir),"size"),this._paramVerfiy(l,e,h,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign"),this._paramVerfiy(c,e,h,Object.values(Gn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}label(t){return t.x}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class mo{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");this._id=t,this._variables=e,this._errorListener=r}get type(){return Me.LABEL}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.label.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`label_${t}_${e}`,n=this._getLabel(t),s=new mo(r,this._variables,this._errorListener);if(n){const a={...n,id:r,bar_index:e};this._variables.label.add(r,a,s)}return s}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t),this._paramVerfiy(t,e,"label.set_size",Object.values(ir),"size")}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e,this._paramVerfiy(e,r,"label.set_xloc",Object.values(De),"xloc"))}set_yloc({yloc:t},e){const r=this._getLabel(e),{high:n,low:s}=this._variables;r&&(r.yloc=t,t===jr.abovebar?r.y=n:t===jr.belowbar&&(r.y=s),this._paramVerfiy(t,e,"label.set_yloc",Object.values(jr),"yloc"))}set_color(t,e){const r=this._getLabel(e);ge(t,["color"]),r&&(r.color=t.color)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===De.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t),this._paramVerfiy(t,e,"label.set_style",Object.values(ve),"style")}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t),this._paramVerfiy(t,e,"label.set_textalign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign")}set_textcolor(t,e){const r=this._getLabel(e);ge(t,["textcolor"]),r&&(r.textcolor=t.textcolor)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t),this._paramVerfiy(t,e,"label.set_text_font_family",Object.values(Gn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const Yw={freq_all:Ur.freqAll,freq_once_per_bar:Ur.freqOncePerBar,freq_once_per_bar_close:Ur.freqOncePerBarClose},Vw={gaps_off:Qi.gapsOff,gaps_on:Qi.gapsOn,lookahead_off:Qi.lookaheadOff,lookahead_on:Qi.lookaheadOn},Bi={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#FF5252",silver:"#B2B5BE",teal:"#00897B",white:"#FFFFFF",yellow:"#FFEB3B"},dh={AUD:"AUD",BTC:"BTC",CAD:"CAD",CHF:"CHF",ETH:"ETH",EUR:"EUR",GBP:"GBP",HKD:"HKD",INR:"INR",JPY:"JPY",KRW:"KRW",MYR:"MYR",NOK:"NOK",NONE:"NONE",NZD:"NZD",RUB:"RUB",SEK:"SEK",SGD:"SGD",TRY:"TRY",USD:"USD",USDT:"USDT",ZAR:"ZAR"},Zw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},ph={all:[Ke.dataWindow,Ke.pane,Ke.priceScale,Ke.statusLine],data_window:[Ke.dataWindow],none:[],pane:[Ke.pane],price_scale:[Ke.priceScale],status_line:[Ke.statusLine]},Kw={both:Wr.both,left:Wr.left,none:Wr.none,right:Wr.right},Gw={inherit:Kt.inherit,mintick:Kt.mintick,percent:Kt.percent,price:Kt.price,volume:Kt.volume},Hw={style_solid:Ns.styleSolid,style_dashed:Ns.styleDashed,style_dotted:Ns.styleDotted},Jw={style_arrowdown:ve.styleArrowdown,style_arrowup:ve.styleArrowup,style_circle:ve.styleCircle,style_cross:ve.styleCross,style_diamond:ve.styleDiamond,style_flag:ve.styleFlag,style_label_center:ve.styleLabelCenter,style_label_down:ve.styleLabelDown,style_label_left:ve.styleLabelLeft,style_label_lower_left:ve.styleLabelLowerLeft,style_label_lower_right:ve.styleLabelLowerRight,style_label_right:ve.styleLabelRight,style_label_up:ve.styleLabelUp,style_label_upper_left:ve.styleLabelUpperLeft,style_label_upper_right:ve.styleLabelUpperRight,style_none:ve.styleNone,style_square:ve.styleSquare,style_text_outline:ve.styleTextOutline,style_triangledown:ve.styleTriangledown,style_triangleup:ve.styleTriangleup,style_xcross:ve.styleXcross},Xw={style_arrow_both:Re.styleArrowBoth,style_arrow_left:Re.styleArrowLeft,style_arrow_right:Re.styleArrowRight,style_dashed:Re.styleDashed,style_dotted:Re.styleDotted,style_solid:Re.styleSolid},Qw={abovebar:ln.abovebar,absolute:ln.absolute,belowbar:ln.belowbar,bottom:ln.bottom,top:ln.top},ty={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},ey={style_area:Sr.styleArea,style_areabr:Sr.styleAreabr,style_circles:Sr.styleCircles,style_columns:Sr.styleColumns,style_cross:Sr.styleCross,style_histogram:Sr.styleHistogram,style_line:Sr.styleLine,style_linebr:Sr.styleLinebr,style_stepline:Sr.styleStepline,style_stepline_diamond:Sr.styleSteplineDiamond,style_steplinebr:Sr.styleSteplinebr},ry={bottom_center:gr.bottomCenter,bottom_left:gr.bottomLeft,bottom_right:gr.bottomRight,middle_center:gr.middleCenter,middle_left:gr.middleLeft,middle_right:gr.middleRight,top_center:gr.topCenter,top_left:gr.topLeft,top_right:gr.topRight},ny={left:Ss.left,none:Ss.none,right:Ss.right},iy={arrowdown:lr.arrowdown,arrowup:lr.arrowup,circle:lr.circle,cross:lr.cross,diamond:lr.diamond,flag:lr.flag,labeldown:lr.labeldown,labelup:lr.labelup,square:lr.square,triangledown:lr.triangledown,triangleup:lr.triangleup,xcross:lr.xcross},sy={auto:ir.auto,huge:ir.huge,large:ir.large,normal:ir.normal,small:ir.small,tiny:ir.tiny},oy={cash:Pe.cash,fixed:Pe.fixed,percent_of_equity:Pe.percentOfEquity,commission:{cash_per_contract:je.cashPerContract,cash_per_order:je.cashPerOrder,percent:je.percent},direction:{all:ce.all,long:ce.long,short:ce.short},oca:{cancel:cn.cancel,none:cn.none,reduce:cn.reduce}},ay={align_bottom:Wt.alignBottom,align_center:Wt.alignCenter,align_left:Wt.alignLeft,align_right:Wt.alignRight,align_top:Wt.alignTop,wrap_auto:Wt.wrapAuto,wrap_none:Wt.wrapNone},uy={bar_index:De.bar_index,bar_time:De.bar_time},ly={abovebar:jr.abovebar,belowbar:jr.belowbar,price:jr.price},cy={actual:Os.actual,estimate:Os.estimate,standardized:Os.standardized};class _h{constructor(){$(this,"adjustment",{dividends:Ms.dividends,none:Ms.none,splits:Ms.splits});$(this,"alert",Yw);$(this,"barmerge",Vw);$(this,"color",Bi);$(this,"currency",dh);$(this,"dayofweek",Zw);$(this,"earnings",cy);$(this,"display",ph);$(this,"extend",Kw);$(this,"font",{family_default:Gn.familyDefault,family_monospace:Gn.familyMonospace});$(this,"format",Gw);$(this,"hline",Hw);$(this,"label",Jw);$(this,"line",Xw);$(this,"location",Qw);$(this,"math",ty);$(this,"order",{ascending:Kn.ascending,descending:Kn.descending});$(this,"plot",ey);$(this,"position",ry);$(this,"scale",ny);$(this,"session",{extended:gi.extended,regular:gi.regular});$(this,"shape",iy);$(this,"size",sy);$(this,"splits",{denominator:"denominator",numerator:"numerator"});$(this,"strategy",oy);$(this,"text",ay);$(this,"xloc",uy);$(this,"yloc",ly)}updateData(){}}class fy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:De.bar_index,line_color:Bi.blue,line_style:Re.styleSolid,line_width:1});this._variables=t,this._errorListener=e}new(t,e){var l;const{bar_index:r}=this._variables,n=`polyline_${e}_${r}`,s=Object.assign({},this._defaultPolyline,t,{id:n,bar_index:r,points:(l=t.points)==null?void 0:l._value.map(c=>({time:c.time,index:c.index,price:c.price}))});ge(s,["line_color","fill_color"]);const a=new mh(n,this._variables);return this._verfiyArgs(t,e),e.startsWith("export")||this._variables.polyline.add(n,s,a),a}_verfiyArgs(t,e){const{line_style:r,xloc:n}=t,s="polyline.new";this._paramVerfiy(r,e,s,Object.values(Re),"line_style"),this._paramVerfiy(n,e,s,Object.values(De),"xloc")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}delete({id:t}){t&&t.delete()}}class mh{constructor(t,e){$(this,"_id");$(this,"_variables");$(this,"_suffix");this._variables=e,this._id=t}get type(){return Me.POLYLINE}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.polyline.get(this._id)}delete(){this._variables.polyline.delete(this._id)}}class hy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLine",{xloc:De.bar_index,extend:Wr.none,style:Re.styleSolid});this._variables=t,this._errorListener=e}new({first_point:t,second_point:e,...r},n){const{bar_index:s}=this._variables,a=`line_${n}_${s}`;ge(r,["color"]);const l={...this._defaultLine,...r,id:a,bar_index:s};if(t&&e){const h=l.xloc===De.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,d=l.xloc===De.bar_index?e==null?void 0:e.index:e==null?void 0:e.time;Object.assign(l,{x1:h,y1:t==null?void 0:t.price,x2:d,y2:e==null?void 0:e.price})}this._verfiyArgs(r,n);const c=new go(a,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(a,l,c),c}_verfiyArgs(t,e){const{extend:r,xloc:n,style:s}=t,a="line.new";this._paramVerfiy(s,e,a,Object.values(Re),"style"),this._paramVerfiy(r,e,a,Object.values(Wr),"extend"),this._paramVerfiy(n,e,a,Object.values(De),"xloc")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}line(t){return t.x}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class go{constructor(t,e,r){$(this,"_variables");$(this,"_id");$(this,"_suffix","");$(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get type(){return Me.LINE}get data(){return this._variables.line.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`line_${t}_${e}`,n=this._getLine(t),s=new go(r,this._variables,this._errorListener);return n&&this._variables.line.add(r,{...n,id:r,bar_index:e,isVar:void 0},s),s}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===De.bar_index){const{x1:n,y1:s,x2:a,y2:l}=r;return n===void 0||a===void 0||s===void 0||l===void 0?void 0:(l-s)/(a-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r,this._paramVerfiy(t,n,"line.set_xloc",Object.values(De),"xloc"))}set_color(t,e){const r=this._getLine(e);r&&(ge(t,["color"]),r.color=t.color)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t,this._paramVerfiy(t,e,"line.set_style",Object.values(Re),"style"))}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t,this._paramVerfiy(t,e,"line.set_extend",Object.values(Wr),"extend"))}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===De.bar_index?n:s,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===De.bar_index?n:s,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class dy{constructor(t){$(this,"_variables");this._variables=t}new(t,e){const{line1:r,line2:n}=t,{bar_index:s}=this._variables,a=`linefill_${e}_${s}`,l=r==null?void 0:r.data,c=n==null?void 0:n.data;l&&(l.linefills=l.linefills||[],l.linefills.push(a)),c&&(c.linefills=c.linefills||[],c.linefills.push(a)),ge(t,["color"]);const h=new vo(this._variables,a,r,n);return e.startsWith("export")||(l||c)&&this._variables.linefill.add(a,{line1:l,line2:c,color:t.color,id:a,bar_index:s},h),h}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class vo{constructor(t,e,r,n){$(this,"_id");$(this,"_line1");$(this,"_line2");$(this,"_variables");$(this,"_suffix");this._variables=t,this._id=e,this._line1=r,this._line2=n}get type(){return Me.LINEFILL}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.linefill.get(this._id)}linefill(t,e){return t.x?t.x:new vo(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),s&&(s.linefills=(r=s.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(t){const e=this._variables.linefill.get(this._id);e&&(ge(t,["color"]),e.color=t.color)}}class py{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultBox",{border_color:Bi.blue,border_width:1,bgcolor:Bi.blue,xloc:De.bar_index,extend:Wr.none,style:Re.styleSolid,text:"",text_size:ir.auto,text_color:Bi.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_wrap:Wt.wrapNone});this._variables=t,this._errorListener=e}box({x:t}){return t}new({top_left:t,bottom_right:e,...r},n){const{bar_index:s}=this._variables,a=`box_${n}_${s}`,l={...this._defaultBox,...r,id:a,bar_index:s};if(ge(l,["border_color","bgcolor","text_color"]),t){const{price:h,time:d,index:f}=t;l.top=h,l.left=l.xloc===De.bar_index?f:d}if(e){const{price:h,time:d,index:f}=e;l.bottom=h,l.right=l.xloc===De.bar_index?f:d}this._verfiyArgs(r,n);const c=new wo(this._variables,a,this._errorListener);return n.startsWith("export")||this._variables.box.add(a,l,c),c}_verfiyArgs(t,e){const{border_style:r,extend:n,xloc:s,text_size:a,text_halign:l,text_valign:c,text_wrap:h,text_font_family:d}=t,f="box.new";this._paramVerfiy(r,e,f,[Re.styleDashed,Re.styleDotted,Re.styleSolid],"border_style"),this._paramVerfiy(n,e,f,Object.values(Wr),"extend"),this._paramVerfiy(s,e,f,Object.values(De),"xloc"),this._paramVerfiy(a,e,f,Object.values(ir),"text_size"),this._paramVerfiy(l,e,f,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"),this._paramVerfiy(c,e,f,[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"),this._paramVerfiy(h,e,f,[Wt.wrapAuto,Wt.wrapNone],"text_wrap"),this._paramVerfiy(d,e,f,Object.values(Gn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_text({id:t,...e}){t==null||t.set_text(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e},r){t==null||t.set_border_style(e,r)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e},r){t==null||t.set_text_size(e,r)}set_text_wrap({id:t,...e},r){t==null||t.set_text_wrap(e,r)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e},r){t==null||t.set_text_halign(e,r)}set_text_valign({id:t,...e},r){t==null||t.set_text_valign(e,r)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class wo{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");this._variables=t,this._id=e,this._errorListener=r}get type(){return Me.BOX}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.box.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`box_${t}_${e}`,n=this._getBox(),s=new wo(this._variables,r,this._errorListener);return n&&this._variables.box.add(r,{...n,id:r,bar_index:e},s),s}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t},e){const r=this._getBox();r&&(r.extend=t,this._paramVerfiy(t,e,"box.set_extend",Object.values(Wr),"extend"))}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t,ge(e,["bgcolor"]))}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t},e){const r=this._getBox();r&&(r.text_size=t,this._paramVerfiy(t,e,"box.set_text_size",Object.values(ir),"text_size"))}set_text_wrap({text_wrap:t},e){const r=this._getBox();r&&(r.text_wrap=t,this._paramVerfiy(t,e,"box.set_text_wrap",[Wt.wrapAuto,Wt.wrapNone],"text_wrap"))}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t,ge(e,["text_color"]))}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t},e){const r=this._getBox();r&&(r.text_halign=t,this._paramVerfiy(t,e,"box.set_text_halign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"))}set_text_valign({text_valign:t},e){const r=this._getBox();r&&(r.text_valign=t,this._paramVerfiy(t,e,"box.set_text_valign",[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"))}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===De.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t,ge(e,["border_color"]))}set_border_style({style:t},e){const r=this._getBox();r&&(r.border_style=t,this._paramVerfiy(t,e,"box.set_border_style",[Re.styleDashed,Re.styleDotted,Re.styleSolid],"style"))}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===De.bar_index?r:s}}set_text_font_family({text_font_family:t},e){const r=this._getBox();r&&(r.text_font_family=t,this._paramVerfiy(t,e,"box.set_text_font_family",Object.values(Gn),"text_font_family"))}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getBox(){return this._variables.box.get(this._id)}}class _y{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultTable",{position:gr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t,this._errorListener=e}table({x:t}){return t}new(t,e){const{bar_index:r}=this._variables,n=`table_${e}_${r}`,{rows:s}=t;ge(t,["text_color","bgcolor","border_color"]);const a=Array.from(Array(s),()=>[]),l=e.split("_"),c=l.pop(),h=l.pop(),d={...this._defaultTable,...t,cell:a,id:n,bar_index:r,line:h,col:c},f=new gh(this._variables,n,this._errorListener);return this._paramVerfiy(t.position,e,"table.new",Object.values(gr),"position"),e.startsWith("export")||this._variables.table.add(n,d,f),f}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e},r){t==null||t.set_position(e,r)}}class gh{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");$(this,"_defaultCell",{column:0,row:0,text:"",text_color:Bi.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_size:ir.normal});this._variables=t,this._id=e,this._errorListener=r}get type(){return Me.TABLE}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.table.get(this._id)}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const a=s.cell||[],l=a[n]||[];l[r]=e,a[n]=l,s.cell=a}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r,ge(n,["text_color"]))}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const a=s.cell;if(a)for(let l=e;l<=n;l++)for(let c=t;c<=r;c++){const h=a[l];h&&(h[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){this._errorListener.addError(se.mergeCellErr,s,Pt.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const l=a.merge_cells||[];l.push({start_column:t,start_row:e,end_column:r,end_row:n}),a.merge_cells=l}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t,ge(e,["bgcolor"]))}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t,ge(e,["border_color"]))}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t},e){const r=this._variables.table.get(this._id);r&&(r.position=t,this._paramVerfiy(t,e,"table.set_position",Object.values(gr),"position"))}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class my{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_time}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===ce.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class gy{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===ce.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class vy{constructor(t,e){$(this,"_strategy");$(this,"_errorListener");this._strategy=t,this._errorListener=e}allow_entry_in({value:t},e){this._paramVerfiy(t,e,"strategy.risk.allow_entry_in",Object.values(ce),"value"),this._strategy.updateRisk({allow_entry_in:t})}max_cons_loss_days({count:t}){this._strategy.updateRisk({max_cons_loss_days:t})}max_drawdown({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_drawdown",[Pe.percentOfEquity,Pe.cash],"type"),e===Pe.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_drawdown:t,max_drawdown_type:e})}max_intraday_filled_orders({count:t}){this._strategy.updateRisk({max_intraday_filled_orders:t})}max_intraday_loss({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_intraday_loss",[Pe.percentOfEquity,Pe.cash],"type"),e===Pe.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_intraday_loss:t,max_intraday_loss_type:e})}max_position_size({contracts:t}){this._strategy.updateRisk({max_position_size:t})}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}}var wy=20,yy=1,ei=1e6,vh=1e6,Dy=-7,by=21,xy=!1,us="[big.js] ",ri=us+"Invalid ",yo=ri+"decimal places",Ey=ri+"rounding mode",wh=us+"Division by zero",ae={},sn=void 0,Ay=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function yh(){function i(t){var e=this;if(!(e instanceof i))return t===sn?yh():new i(t);if(t instanceof i)e.s=t.s,e.e=t.e,e.c=t.c.slice();else{if(typeof t!="string"){if(i.strict===!0&&typeof t!="bigint")throw TypeError(ri+"value");t=t===0&&1/t<0?"-0":String(t)}Cy(e,t)}e.constructor=i}return i.prototype=ae,i.DP=wy,i.RM=yy,i.NE=Dy,i.PE=by,i.strict=xy,i.roundDown=0,i.roundHalfUp=1,i.roundHalfEven=2,i.roundUp=3,i}function Cy(i,t){var e,r,n;if(!Ay.test(t))throw Error(ri+"number");for(i.s=t.charAt(0)=="-"?(t=t.slice(1),-1):1,(e=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(e<0&&(e=r),e+=+t.slice(r+1),t=t.substring(0,r)):e<0&&(e=t.length),n=t.length,r=0;r<n&&t.charAt(r)=="0";)++r;if(r==n)i.c=[i.e=0];else{for(;n>0&&t.charAt(--n)=="0";);for(i.e=e-r-1,i.c=[],e=0;r<=n;)i.c[e++]=+t.charAt(r++)}return i}function ni(i,t,e,r){var n=i.c;if(e===sn&&(e=i.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(Ey);if(t<1)r=e===3&&(r||!!n[0])||t===0&&(e===1&&n[0]>=5||e===2&&(n[0]>5||n[0]===5&&(r||n[1]!==sn))),n.length=1,r?(i.e=i.e-t+1,n[0]=1):n[0]=i.e=0;else if(t<n.length){if(r=e===1&&n[t]>=5||e===2&&(n[t]>5||n[t]===5&&(r||n[t+1]!==sn||n[t-1]&1))||e===3&&(r||!!n[0]),n.length=t,r){for(;++n[--t]>9;)if(n[t]=0,t===0){++i.e,n.unshift(1);break}}for(t=n.length;!n[--t];)n.pop()}return i}function ii(i,t,e){var r=i.e,n=i.c.join(""),s=n.length;if(t)n=n.charAt(0)+(s>1?"."+n.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)n="0"+n;n="0."+n}else if(r>0)if(++r>s)for(r-=s;r--;)n+="0";else r<s&&(n=n.slice(0,r)+"."+n.slice(r));else s>1&&(n=n.charAt(0)+"."+n.slice(1));return i.s<0&&e?"-"+n:n}ae.abs=function(){var i=new this.constructor(this);return i.s=1,i},ae.cmp=function(i){var t,e=this,r=e.c,n=(i=new e.constructor(i)).c,s=e.s,a=i.s,l=e.e,c=i.e;if(!r[0]||!n[0])return r[0]?s:n[0]?-a:0;if(s!=a)return s;if(t=s<0,l!=c)return l>c^t?1:-1;for(a=(l=r.length)<(c=n.length)?l:c,s=-1;++s<a;)if(r[s]!=n[s])return r[s]>n[s]^t?1:-1;return l==c?0:l>c^t?1:-1},ae.div=function(i){var t=this,e=t.constructor,r=t.c,n=(i=new e(i)).c,s=t.s==i.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>ei)throw Error(yo);if(!n[0])throw Error(wh);if(!r[0])return i.s=s,i.c=[i.e=0],i;var l,c,h,d,f,p=n.slice(),g=l=n.length,w=r.length,m=r.slice(0,l),y=m.length,v=i,x=v.c=[],b=0,M=a+(v.e=t.e-i.e)+1;for(v.s=s,s=M<0?0:M,p.unshift(0);y++<l;)m.push(0);do{for(h=0;h<10;h++){if(l!=(y=m.length))d=l>y?1:-1;else for(f=-1,d=0;++f<l;)if(n[f]!=m[f]){d=n[f]>m[f]?1:-1;break}if(d<0){for(c=y==l?n:p;y;){if(m[--y]<c[y]){for(f=y;f&&!m[--f];)m[f]=9;--m[f],m[y]+=10}m[y]-=c[y]}for(;!m[0];)m.shift()}else break}x[b++]=d?h:++h,m[0]&&d?m[y]=r[g]||0:m=[r[g]]}while((g++<w||m[0]!==sn)&&s--);return!x[0]&&b!=1&&(x.shift(),v.e--,M--),b>M&&ni(v,M,e.RM,m[0]!==sn),v},ae.eq=function(i){return this.cmp(i)===0},ae.gt=function(i){return this.cmp(i)>0},ae.gte=function(i){return this.cmp(i)>-1},ae.lt=function(i){return this.cmp(i)<0},ae.lte=function(i){return this.cmp(i)<1},ae.minus=ae.sub=function(i){var t,e,r,n,s=this,a=s.constructor,l=s.s,c=(i=new a(i)).s;if(l!=c)return i.s=-c,s.plus(i);var h=s.c.slice(),d=s.e,f=i.c,p=i.e;if(!h[0]||!f[0])return f[0]?i.s=-c:h[0]?i=new a(s):i.s=1,i;if(l=d-p){for((n=l<0)?(l=-l,r=h):(p=d,r=f),r.reverse(),c=l;c--;)r.push(0);r.reverse()}else for(e=((n=h.length<f.length)?h:f).length,l=c=0;c<e;c++)if(h[c]!=f[c]){n=h[c]<f[c];break}if(n&&(r=h,h=f,f=r,i.s=-i.s),(c=(e=f.length)-(t=h.length))>0)for(;c--;)h[t++]=0;for(c=t;e>l;){if(h[--e]<f[e]){for(t=e;t&&!h[--t];)h[t]=9;--h[t],h[e]+=10}h[e]-=f[e]}for(;h[--c]===0;)h.pop();for(;h[0]===0;)h.shift(),--p;return h[0]||(i.s=1,h=[p=0]),i.c=h,i.e=p,i},ae.mod=function(i){var t,e=this,r=e.constructor,n=e.s,s=(i=new r(i)).s;if(!i.c[0])throw Error(wh);return e.s=i.s=1,t=i.cmp(e)==1,e.s=n,i.s=s,t?new r(e):(n=r.DP,s=r.RM,r.DP=r.RM=0,e=e.div(i),r.DP=n,r.RM=s,this.minus(e.times(i)))},ae.neg=function(){var i=new this.constructor(this);return i.s=-i.s,i},ae.plus=ae.add=function(i){var t,e,r,n=this,s=n.constructor;if(i=new s(i),n.s!=i.s)return i.s=-i.s,n.minus(i);var a=n.e,l=n.c,c=i.e,h=i.c;if(!l[0]||!h[0])return h[0]||(l[0]?i=new s(n):i.s=n.s),i;if(l=l.slice(),t=a-c){for(t>0?(c=a,r=h):(t=-t,r=l),r.reverse();t--;)r.push(0);r.reverse()}for(l.length-h.length<0&&(r=h,h=l,l=r),t=h.length,e=0;t;l[t]%=10)e=(l[--t]=l[t]+h[t]+e)/10|0;for(e&&(l.unshift(e),++c),t=l.length;l[--t]===0;)l.pop();return i.c=l,i.e=c,i},ae.pow=function(i){var t=this,e=new t.constructor("1"),r=e,n=i<0;if(i!==~~i||i<-vh||i>vh)throw Error(ri+"exponent");for(n&&(i=-i);i&1&&(r=r.times(t)),i>>=1,!!i;)t=t.times(t);return n?e.div(r):r},ae.prec=function(i,t){if(i!==~~i||i<1||i>ei)throw Error(ri+"precision");return ni(new this.constructor(this),i,t)},ae.round=function(i,t){if(i===sn)i=0;else if(i!==~~i||i<-ei||i>ei)throw Error(yo);return ni(new this.constructor(this),i+this.e+1,t)},ae.sqrt=function(){var i,t,e,r=this,n=r.constructor,s=r.s,a=r.e,l=new n("0.5");if(!r.c[0])return new n(r);if(s<0)throw Error(us+"No square root");s=Math.sqrt(+ii(r,!0,!0)),s===0||s===1/0?(t=r.c.join(""),t.length+a&1||(t+="0"),s=Math.sqrt(t),a=((a+1)/2|0)-(a<0||a&1),i=new n((s==1/0?"5e":(s=s.toExponential()).slice(0,s.indexOf("e")+1))+a)):i=new n(s+""),a=i.e+(n.DP+=4);do e=i,i=l.times(e.plus(r.div(e)));while(e.c.slice(0,a).join("")!==i.c.slice(0,a).join(""));return ni(i,(n.DP-=4)+i.e+1,n.RM)},ae.times=ae.mul=function(i){var t,e=this,r=e.constructor,n=e.c,s=(i=new r(i)).c,a=n.length,l=s.length,c=e.e,h=i.e;if(i.s=e.s==i.s?1:-1,!n[0]||!s[0])return i.c=[i.e=0],i;for(i.e=c+h,a<l&&(t=n,n=s,s=t,h=a,a=l,l=h),t=new Array(h=a+l);h--;)t[h]=0;for(c=l;c--;){for(l=0,h=a+c;h>c;)l=t[h]+s[c]*n[h-c-1]+l,t[h--]=l%10,l=l/10|0;t[h]=l}for(l?++i.e:t.shift(),c=t.length;!t[--c];)t.pop();return i.c=t,i},ae.toExponential=function(i,t){var e=this,r=e.c[0];if(i!==sn){if(i!==~~i||i<0||i>ei)throw Error(yo);for(e=ni(new e.constructor(e),++i,t);e.c.length<i;)e.c.push(0)}return ii(e,!0,!!r)},ae.toFixed=function(i,t){var e=this,r=e.c[0];if(i!==sn){if(i!==~~i||i<0||i>ei)throw Error(yo);for(e=ni(new e.constructor(e),i+e.e+1,t),i=i+e.e+1;e.c.length<i;)e.c.push(0)}return ii(e,!1,!!r)},ae[Symbol.for("nodejs.util.inspect.custom")]=ae.toJSON=ae.toString=function(){var i=this,t=i.constructor;return ii(i,i.e<=t.NE||i.e>=t.PE,!!i.c[0])},ae.toNumber=function(){var i=+ii(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(i.toString()))throw Error(us+"Imprecise conversion");return i},ae.toPrecision=function(i,t){var e=this,r=e.constructor,n=e.c[0];if(i!==sn){if(i!==~~i||i<1||i>ei)throw Error(ri+"precision");for(e=ni(new r(e),i,t);e.c.length<i;)e.c.push(0)}return ii(e,i<=e.e||e.e<=r.NE||e.e>=r.PE,!!n)},ae.valueOf=function(){var i=this,t=i.constructor;if(t.strict===!0)throw Error(us+"valueOf disallowed");return ii(i,i.e<=t.NE||i.e>=t.PE,!0)};var tu=yh();function Dh(i,t){return tu(i).plus(t).toNumber()}function Do(i,t){return tu(i).minus(t).toNumber()}function Ii(i,t){return tu(i).mul(t).toNumber()}let Fy=class{constructor(t,e,r,n,s){$(this,"_variables");$(this,"_options");$(this,"_totalChangeCapital");$(this,"_historyOrder");$(this,"_orders");$(this,"_exitOrders");$(this,"_pendingOrders");$(this,"_mintick");$(this,"_funcOptions");$(this,"_pendingCloseOrders");$(this,"_errorListener");$(this,"_risk");$(this,"_opentrades");$(this,"_closedtrades");$(this,"_riskNamespace");$(this,"_updateOptions",{});$(this,"_id");$(this,"_maxDrawdownVerifyIndex",0);$(this,"calcOnOrderFillsData",{index:-1});this._variables=t,this._errorListener=n,this._options={overlay:!1,format:Kt.inherit,pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Pe.fixed,default_qty_value:1,initial_capital:1e6,currency:dh.NONE,slippage:0,commission_type:je.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=e,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._exitOrders=[],this._pendingCloseOrders=[],this._mintick=r,this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),this._variables.strategy.updateStrategyOptions(this._options),this._risk={intradayOrders:0},this._opentrades=new gy(this),this._closedtrades=new my(this),this._riskNamespace=new vy(this,n),this._id=`strategy_${s}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:t}=this.calcOnOrderFillsData.data||this._variables;return this._orders.reduce((e,r)=>e+t*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}get isCalcOnEveryTick(){return this._options.calc_on_every_tick}updateOptions(t){this._updateOptions=t||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),this._exitOrdersHandle(),this._maxDrawdownVerify();const{open:t,close:e,high:r,low:n}=this.calcOnOrderFillsData.data||this._variables;this._variables.strategy.update({open:t,close:e,high:r,low:n}),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}calcCurrentOrder(){this._calcProfitAndLoss()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:t,max_intraday_loss_type:e,isDisabledOpen:r}=this._risk;if(t===void 0||!e||r)return;const{time_tradingday:n,time:s,strategy:{netprofit:a,initial_capital:l}}=this._variables,{high:c,low:h}=this.calcOnOrderFillsData.data||this._variables;let{preNetprofit:d=0}=this._risk;s===n&&(d=a,this._risk.preNetprofit=a,this._risk.isTemporaryBan=!1);let f=d-a;f+=this._orders.reduce((w,m)=>{const{in_price:y,direction:v,qty:x=0,commission:b=0,original_qty:M=0}=m,E=v===ce.long?1:-1,C=(c-y)*x,N=(h-y)*x,S=E===1?N:-C;return w+S+x/M*b},0);let p=!1;switch(e){case Pe.cash:p=t<f;break;case Pe.percentOfEquity:const w=f/(l+a)*100;p=t<w;break}if(p){this._risk.isTemporaryBan=!0;const w=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,w===ce.long?h:c,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:t,intradayOrders:e=0,isDisabledOpen:r}=this._risk;if(t===void 0||r)return;const{time:n,time_tradingday:s}=this._variables,{open:a}=this.calcOnOrderFillsData.data||this._variables;n===s&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),t<=e&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:t,lossDays:e=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(t===void 0||r)return;const{time:s,time_tradingday:a,strategy:l}=this._variables,{open:c}=this.calcOnOrderFillsData.data||this._variables;let h=e;if(s===a){const d=l.netprofit+l.openprofit;d<n?h=0:h++,Object.assign(this._risk,{lossDays:h,totalProfit:d})}t<=h&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:n}=this._variables,{open:s}=this.calcOnOrderFillsData.data||this._variables;if(t!==void 0&&e&&this._maxDrawdownVerifyIndex===n){const{initial_capital:a}=this._options,c=this._orders.reduce((d,f)=>{const{in_price:p,commission:g=0,qty:w=0,original_qty:m=0,direction:y}=f,v=y===ce.long?1:-1,x=(s-p)*v*w;return d+x+g*w/m},0)+this._totalChangeCapital;let h=!1;switch(e){case Pe.percentOfEquity:h=c/a*100<=-t;break;case Pe.cash:h=c<=-t;break}h&&this._riskTouchOff(s,"Close Position (Max Drawdown)")}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,t,e,"close"),this._pendingOrders=[]}strategy(t,e){if(!this._variables.bar_index){this._paramVerfiy(t.format,e,"strategy",[Kt.inherit,Kt.price,Kt.percent,Kt.volume],"format"),this._paramVerfiy(t.default_qty_type,e,"strategy",Object.values(Pe),"default_qty_type"),this._paramVerfiy(t.commission_type,e,"strategy",Object.values(je),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),n={...this._updateOptions};if(r)for(const s of Object.keys({...r,...t}))t[s]!==r[s]&&delete n[s];self==null||self.workerStorage.set(this._id,t),Object.assign(this._options,t,n),this._variables.updateMaxLength(t),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:n,scriptType:"strategy"})}}order(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.order",Object.values(cn),"oca_type"),this._orderHandle(t))}entry(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.entry",Object.values(cn),"oca_type"),this._entryHandle(t))}close(t){if(!this._orders.filter(r=>!this._options.process_orders_on_close||r.in_index!==this._variables.bar_index).length)return;const{immediately:e}=t;if(e||this._options.process_orders_on_close){const r=this._pendingCloseOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingCloseOrders.push({...t,place_order_type:"close"})}else{const r=this._pendingOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingOrders.push({...t,place_order_type:"close"})}}close_all(t){if(typeof t=="string"&&(t={}),!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close_all"}):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>!(e.id===t&&e.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(t,e){this._exit(t,e)}convert_to_account({value:t}){return t}convert_to_symbol({value:t}){return t}default_entry_qty({fill_price:t}){return t?this._calcDefaultQty(t):0}_calcDefaultQty(t){const{default_qty_type:e=Pe.fixed,default_qty_value:r=1,initial_capital:n,commission_value:s}=this._options;let a=r;switch(e){case Pe.cash:a=r/t;break;case Pe.percentOfEquity:const l=this._getOrderProfit(t),c=n+l+this._totalChangeCapital;s?a=this._getCommQty(c,t):a=c*r/100/t;break}return Vl(a,this._getLen(t))}_getCommQty(t,e){const{commission_type:r,commission_value:n=0,default_qty_value:s=0}=this._options;let a=0;switch(r){case je.percent:a=t*s/(100*e+n*e);break;case je.cashPerContract:a=t*s/(100*e+n);break;case je.cashPerOrder:a=(t-n)*s/100/e}return a}_getLen(t){const e=String(Math.floor(t)).length-2;return e<0?0:e}_getCapital(t,e){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&t===1?e=e*100/r:n<=100&&n>0&&t===-1&&(e=e*100/n),e}_calcProfitAndLoss(){const{close:t}=this.calcOnOrderFillsData.data||this._variables;for(const e of this._orders){const{in_price:r,qty:n=0,direction:s}=e,a=s===ce.long?1:-1,l=(t-r)*a*n,[c,h]=this._calcProfitAndLossHandle(r,n,a);this._calcOrderPercent(e,l,c,h)}}_calcProfitAndLossHandle(t,e,r){const{high:n,low:s}=this.calcOnOrderFillsData.data||this._variables,a=(n-t)*e,l=(s-t)*e;let c=r===1?a:-l,h=r===1?l:-a;return[c,h]}_calcOrderPercent(t,e,r,n){const{commission_value:s}=this._options,{close:a}=this.calcOnOrderFillsData.data||this._variables,{original_qty:l=0,qty:c=0,in_price:h,max_profit:d=0,trading_loss:f=0}=t;let{commission:p=0}=t,g=h*c;if(s){const w=this._getCommission(a,c);p=p*c/l,r-=p,n-=p,g+=p,e=e-w-p}r=Math.max(r,d,0),n=Math.min(n,f,0),Object.assign(t,{profit:e,total_profit:this._totalChangeCapital+e,total_profit_percent:e/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:n,profit_percent:e/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{time:t}=this._variables,{high:e,low:r}=this.calcOnOrderFillsData.data||this._variables,{initial_capital:n,margin_long:s=0,margin_short:a=0}=this._options,l=this._orders[0].direction===ce.long?1:-1;let c=l===1?r:e;if(l===1&&s===100)return;const h=(l===1?s:a)/100;if(h<=0)return;let d=!1;const[f,p]=this._orders.reduce((y,v)=>{let[x,b]=y;const{in_price:M,qty:E=0,in_time:C}=v;C===t&&(d=!0);const N=M*E,S=c*E;return x+=N,b+=S,[x,b]},[0,0]);let g=0,w=0;const m=n+this._totalChangeCapital;if(d&&(g=m-f*h,g<0&&(c=this._orders[0].in_price,w=Math.abs(Math.trunc(g/h/c)*4),w=Math.max(w,1))),g>=0){const y=l*(p-f);if(g=m+y-p*h,g>=0)return;w=Math.abs(Math.trunc(g/h/c)*4)}w<=0||this._marginCallOrders(c,w,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r,!0);return}for(const s of this.orders)s.position_close_type=s.place_order_type,this._processOrder(s,t,e,r,r,!0);this._orders=this._orders.filter(s=>!s.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:s,quantities:a,close:l,price:c,activePrice:h,isTouch:d}=this._orderArgsParse(t),f=t.direction===ce.long?1:-1;if(a<=0)return;let p=a;if((s||d)&&e){const w=d?c:l;if(n.length){const E=this._processOrders(n,w,p,t.id,t.comment,!1,"order");if(E<=0)return;p=E}const m=w+f*r*this._mintick;if(!this._judgeCapitalEnough(p,m,f))return;this._ocaGroupVerify(p,t.oca_name,t.oca_type);const{bar_index:v,time:x}=this._variables,{high:b,low:M}=this.calcOnOrderFillsData.data||this._variables;this._calcCurrentOrder({...t,in_price:m,in_high:b,in_low:M,in_index:v,in_time:x,qty:p,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,f)&&this._addPendingOrders(t,c,p,s,h)}_judgeCapitalEnough(t,e,r){let n=this._freezeCapital;if(this._orders.some(d=>(d.direction===ce.long?1:-1)!==r)&&(n=0),t<=0)return!1;const{margin_long:s=0,margin_short:a=0}=this._options;if(s===0&&r===1||a===0&&r===-1)return!0;const l=this._getOrderProfit(e),h=this._getCapital(r,this._options.initial_capital+l+this._totalChangeCapital)-n;return t*e<=h}_getOrderProfit(t){return this._orders.reduce((e,r)=>{const{in_price:n,qty:s=0,direction:a}=r,l=a===ce.long?1:-1;return e+(t-n)*s*l},0)}_ocaGroupVerify(t,e,r){if(!e||!r||r===cn.none)return!1;let n=!1;switch(r){case cn.cancel:this._pendingOrders=this._pendingOrders.filter(s=>{if(s.oca_name===e)s.isCancel=!0,n=!0;else return!0});break;case cn.reduce:this._pendingOrders=this._pendingOrders.filter(s=>{const{qty:a=0,oca_name:l}=s;if(e===l){const c=a-t;return n=!0,c<=0?(s.isCancel=!0,!1):(s.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,s,a=!1,l,c){let h=r;for(const d of t)if(d.position_close_type=l||d.place_order_type,d.immediately=c,h=this._processOrder(d,e,h,n,s,a),h<=0)break;return this._orders=this._orders.filter(d=>!d.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),h}_addPendingOrders(t,e,r,n,s){const a=this._pendingOrders.find(l=>l.id===t.id&&!l.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else{const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let s=t.limit||0;const{close:a}=this.calcOnOrderFillsData.data||this._variables;let l=a,c=!1,h;const d=e===ce.long?1:-1,f=n&&(n-a)*d>=0,{backtest_fill_limits_assumption:p=0}=this._options;p>0&&s&&(s-=p*this._mintick*d);const g=s&&(s-a)*d<=0;let w=!1;f&&g?(n!==a&&(h=n),l=s):f?(l=n,w=n===a):g?(l=s,w=s===a):c=!0;const m=r!==void 0?Vl(r,this._getLen(l)):this._calcDefaultQty(l);return{orders:this._orders.filter(v=>v.direction!==e),isMarketPrice:c,activePrice:h,quantities:m,close:a,price:l,isTouch:w}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:s,close:a,price:l,activePrice:c,isTouch:h}=this._orderArgsParse(t);if(s<=0)return;if((n||h)&&e){this._entryOrder(r,h?l:a,s,t);return}this._judgeCapitalEnough(s,a,t.direction===ce.long?1:-1)&&this._addPendingEntry(t,l,s,n,c)}_entryOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{high:l,low:c}=this.calcOnOrderFillsData.data||this._variables,{slippage:h=0}=this._options,{oca_name:d,oca_type:f,direction:p,comment:g,id:w}=n,m=p===ce.long?1:-1;if(r=this._getAvailablePositionSize(r,p),r<=0||(e=e+h*this._mintick*m,!this._judgeCapitalEnough(r,e,m)))return;this._closeOrders(t,e,w,g,"entry");const v={...n,in_price:e,qty:r,in_index:a,in_high:l,in_low:c,in_time:s,place_order_type:"entry"},{orders:x}=this._getEntryOrders(p),b=x.length;b&&b>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,d,f),this._calcCurrentOrder(v))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==ce.all&&n!==e)return 0;if(r===void 0)return t;const s=this._orders.reduce((a,l)=>a+(l.qty||0),0);return s?s+t>r?0:t:t>r?t-r:0}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===t),r=this._orders.filter(n=>n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,s){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(t.direction),c=a.length+l.length,h=a.find(d=>d.id===t.id&&d.place_order_type==="entry");if(h)Object.assign(h,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else if(!c||c<(this._options.pyramiding||1)){const d={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"entry"};this._pendingOrders.push(d)}}_closeAllOrders(t,e){const{comment:r,immediately:n}=t,{bar_index:s}=this._variables,a=this._orders.filter(l=>l.in_index!==s);a.length&&(this._closeOrders(a,e,"Close position order",r,"close",n),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n,s,a){for(const l of t)l.position_close_type=s,l.immediately=a,this._closeOrder(l,e,r,n);this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_closeOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{high:l,low:c}=this.calcOnOrderFillsData.data||this._variables,{slippage:h=0}=this._options,{in_price:d,qty:f=0,direction:p}=t,g=p===ce.long?1:-1;e=e-g*h*this._mintick,t.isDeal=!0;const w=(e-d)*g*f,m={...t,out_price:e,out_id:r,out_index:a,out_high:l,out_low:c,out_time:s,out_comment:n,out_qty:f,profit:w};this._calcPercent(m)}_exitOrdersHandle(){if(!this._exitOrders.length)return;const{open:t,low:e,high:r,close:n}=this.calcOnOrderFillsData.data||this._variables,s=[],a=Math.abs(r-t),l=Math.abs(e-t),c=[];for(const h of this._exitOrders){const{stop:d,limit:f,trail_stop_price:p,directionNum:g,id:w,comment:m,active_price:y,trail_offset:v=0,qty:x,comment_loss:b,comment_profit:M,comment_trailing:E,order:C}=h;let N=p,S=a<l||a===l&&g===1,T,A=1,O=m;if(f&&((t-f)*g>=0?(T=t,A=1):e<=f&&r>=f&&(T=f,S&&f>t||!S&&f<t?A=1:A=2),O=M||m),d&&!(N&&(d-N)*g<0)&&((t-d)*g<=0?(T=t,A=1):e<=d&&r>=d&&(T=d,S&&d>t||!S&&d<t?A=1:A=2),O=b||m),T){s.push({order:C,price:T,index:A,isHighFront:S,exitInfo:{id:w,comment:O,qty:x}});continue}if(T=void 0,N)if((N-t)*g>=0)T=t,A=1;else{const[L,q,U]=this._calcTrailStopPrice(N,r,e,n,v,g,S);T=q,A=U||1,h.trail_stop_price=L}if(y&&!T&&y<=r&&y>=e)if(v===0)T=y,S&&y>t||!S&&y<t?A=1:A=2;else{N=Do(y,Ii(v*g,this._mintick));let L=r,q=e;S?y>=t&&y<=r?(L=r,A=1):(S=!1,L=n,A=2):y<t&&y>=e?(q=e,A=1):(S=!0,q=n,A=2);const[U,W,z=1]=this._calcTrailStopPrice(N,L,q,n,v,g,S);delete h.active_price,A<z&&(A=z),h.trail_stop_price=U,T=W}if(T){s.push({order:C,price:T,index:A,isHighFront:S,exitInfo:{id:w,comment:E||m,qty:x}});continue}c.push(h)}this._exitOrders=c,s.sort(({price:h,index:d,isHighFront:f},{price:p,index:g})=>d!==g?d-g:f?d===1?h-p:p-h:d===1?p-h:h-p);for(const h of s){const{order:d,price:f,exitInfo:p}=h;this._processExitOnClose(d,f,p)}}_ordersHandle(){const t=this._orders.filter(r=>r.isMarketPriceLimit||r.isMarketPriceStop);if(!t.length)return;const{open:e}=this.calcOnOrderFillsData.data||this._variables;for(const r of t){const{out_comment:n,out_qty:s,out_id:a}=r;this._processExitOnClose(r,e,{id:a,comment:n,qty:s})}}_calcTrailStopPrice(t,e,r,n,s,a,l){let c=t,h;const d=Do(a===1?e:r,Ii(s*a,this._mintick));let f=1;return a===1?l?(c<d&&(c=d),c>=r&&(f=2,h=c)):c>=r?(f=1,h=c):d>c&&(c=d,d>=n&&(f=3,h=d)):l?c<=e?(f=1,h=c):d<c&&(c=d,d<=n&&(f=3,h=d)):(d<c&&(c=d),c<=e&&(f=2,h=c)),[c,h,f]}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of this._pendingOrders){const{isCancel:s,place_order_type:a}=n;if(s)continue;let l;switch(a){case"entry":l=this._entryOrderHandle(n);break;case"order":l=this._orderOrderHandle(n);break}l&&t.push(l)}for(const n of r)switch(n.place_order_type){case"close":const s=this._closeOrderHandle(n);s&&t.push(s);break;case"close_all":const{open:a}=this.calcOnOrderFillsData.data||this._variables;this._closeAllOrders(n,a);break}for(const n of e){const s=this._exitOrderHandle(n);s&&t.push(s)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(r=>["close","close_all"].includes(r.place_order_type||"")),{close:e}=this.calcOnOrderFillsData.data||this._variables;this._pendingCloseOrders=[];for(const r of t)switch(r.place_order_type){case"close":const n=this._closeOrderHandle(r,!0);n&&this._pendingCloseOrders.push(n);break;case"close_all":this._closeAllOrders(r,e);break}this._ordersHandle()}_entryOrderHandle(t){const{open:e,low:r,high:n}=this.calcOnOrderFillsData.data||this._variables,{isMarketPrice:s,qty:a=0,in_price:l,direction:c,active_price:h}=t;if(h&&n>=h&&r<=h)return delete t.active_price,t;let d=l;if(s&&(d=e),d<=n&&d>=r){const f=this._orders.filter(p=>p.direction!==c);this._entryOrder(f,d,a,t)}else return t}_orderOrderHandle(t){const{time:e,bar_index:r}=this._variables,{open:n,low:s,high:a}=this.calcOnOrderFillsData.data||this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:h=0,in_price:d,direction:f,comment:p,oca_name:g,oca_type:w,active_price:m,id:y}=t;if(m&&a>=m&&s<=m)return delete t.active_price,t;let v=d,x=h;if(c&&(v=n),v<=a&&v>=s){const b=this._orders.filter(E=>E.direction!==f);if(b.length&&(x=this._processOrders(b,v,h,y,p,!1,"order"),x<=0))return;const M=f===ce.long?1:-1;this._ocaGroupVerify(x,g,w),this._calcCurrentOrder({...t,in_price:v+M*l*this._mintick,in_index:r,in_time:e,in_high:a,in_low:s,qty:x});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:s=100,comment:a,immediately:l}=t,{close_entries_rule:c="FIFO"}=this._options;let h=[];if(c==="FIFO"?h=this._orders.filter(g=>g.id===r):h=this._orders.filter(g=>g.id===r&&!g.close_qty),!h.length)return t;let d=0;if(n?d=n:(d=h.reduce((g,w)=>g+(w.qty||0),d),d=s/100*d),d<=0)return;const{open:f,close:p}=this.calcOnOrderFillsData.data||this._variables;if(c==="FIFO")this._processOrders(h,e?p:f,d,`Close entry(s) order ${r}`,a,!1,"close",l);else if(this._processCloseOrders(h,e?p:f,d,`Close entry(s) order ${r}`,a,l))return t}_processCloseOrders(t,e,r,n,s,a){let l=!1;for(const c of t)c.close_qty=r,(c.qty||0)>r&&(l=!0),c.immediately=a,c.position_close_type="close",this._processOrder(c,e,r,n,s);return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),l}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,t,!0)))return t}_exit(t,e){if(!t.hasOwnProperty("profit")&&!t.hasOwnProperty("loss")&&!t.hasOwnProperty("stop")&&!t.hasOwnProperty("limit")&&(!t.hasOwnProperty("trail_offset")||!t.hasOwnProperty("trail_price")&&!t.hasOwnProperty("trail_points"))){this._errorListener.addError(se.strategyExitErr,e,Pt.Error);return}const{profit:r,loss:n,stop:s,limit:a,trail_offset:l,trail_price:c,trail_points:h,from_entry:d="",id:f}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(s)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(h)&&this._isNaN(c)))return;const p={...t,place_order_type:"exit"},g=this._orders.filter(y=>(!d||d===y.id)&&!y.hasExit);this._updateExitOrders(p);const w=this._pendingOrders.filter(y=>!d||d===y.id);if(g.length){if(!this._ordersToExit(g,p,!1))return}else if(!w.length)return;const m=this._pendingOrders.find(y=>y.id===f&&y.place_order_type==="exit");m?Object.assign(m,{...t}):this._pendingOrders.push(p)}_updateExitOrders(t){const e=this._exitOrders.filter(r=>r.id===t.id&&(r.from_entry===t.from_entry||!t.from_entry));for(const r of e){const{directionNum:n,order:s}=r,a={...t};if(this._stopProfit(s,n,a)){r.isClose=!0;continue}if(this._stopLoss(s,n,a)){r.isClose=!0;continue}if(this._trailStopLoss(s,n,a)){r.isClose=!0;continue}Object.assign(r,a)}this._exitOrders=this._exitOrders.filter(r=>!r.isClose)}_ordersToExit(t,e,r){const{qty:n,qty_percent:s=100,id:a,comment:l}=e;let c=n,h=!1;e.comment=l||a;const d=t[0],f={...e},{qty:p=0}=d,g=d.direction===ce.long?1:-1;return c=n?n>=p?p:n:s/100*p,f.qty=c,c<p&&(h=!0),this._stopProfit(d,g,f,r)||this._stopLoss(d,g,f,r)||this._trailStopLoss(d,g,f,r)||(this._exitOrders.push({...f,directionNum:g,order:d}),d.hasExit=!0),h}_addExitPendingCloseOrders(t){const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r,n){const{limit:s,profit:a,comment_profit:l,comment:c,id:h}=r;let d=s;const{close:f}=this.calcOnOrderFillsData.data||this._variables,{in_price:p}=t,{process_orders_on_close:g}=this._options;if(!this._isNaN(a)&&this._isNaN(s)&&(d=Dh(p,Ii(a*e,this._mintick))),r.limit=e===1?Zl(d,this._variables.precision):Kl(d,this._variables.precision),!n&&d!==void 0&&(d-f)*e<=0)return t.isMarketPriceLimit=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment,out_id:h}),g&&this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r,n){const{stop:s,loss:a,comment_loss:l,comment:c,id:h}=r;let d=s;const{close:f}=this.calcOnOrderFillsData.data||this._variables,{in_price:p}=t,{process_orders_on_close:g}=this._options;if(!this._isNaN(a)&&this._isNaN(s)&&(d=Do(p,Ii(a*e,this._mintick))),r.stop=e===1?Kl(d,this._variables.precision):Zl(d,this._variables.precision),!n&&d!==void 0&&(d-f)*e>=0)return t.isMarketPriceStop=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment,out_id:h}),g&&this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r,n){const{trail_offset:s,trail_price:a,trail_points:l,comment_trailing:c,comment:h,id:d}=r;if(!this._isNaN(s)){const{close:f}=this.calcOnOrderFillsData.data||this._variables,{in_price:p}=t,{process_orders_on_close:g}=this._options;let w;if(this._isNaN(a)?this._isNaN(l)||(w=Dh(p,Ii(l*e,this._mintick))):w=a,r.active_price=w,n)return;if(w!==void 0&&(w-f)*e<=0){const m=Do(f,Ii(s*e,this._mintick));if((m-f)*e>=0)return t.isMarketPriceStop=!0,r.comment=c||h,Object.assign(t,{out_comment:r.comment,out_id:d}),g&&this._addExitPendingCloseOrders(r),!0;r.trail_stop_price=m}}}_processExitOnClose(t,e,r){const{qty:n=0,comment:s,id:a}=r,{close_entries_rule:l="FIFO"}=this._options;if(l==="FIFO")this._processExitOrders(this._orders,e,n,a,s);else{if(t.isDeal)return;this._processOrders([t],e,n,a,s,!1,"exit")}}_processExitOrders(t,e,r,n,s){let a=r,l;for(const c of t)if(l=c,c.position_close_type="exit",a=this._processOrder(c,e,a,n,s),a<=0)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),l}_processOrder(t,e,r,n,s,a=!1){const{time:l,bar_index:c}=this._variables,{low:h,high:d}=this.calcOnOrderFillsData.data||this._variables,{slippage:f=0}=this._options,{in_price:p,qty:g=0,max_profit:w,trading_loss:m,direction:y,commission:v=0,original_qty:x=0}=t,b=y===ce.long?1:-1;if(e=e-b*f*this._mintick,r<g){const M=g-r,E=(e-p)*b*r,C=w!==void 0?w/g*r:void 0,N=m!==void 0?m/g*r:void 0,S=v*M/x;this._calcPercent({...t,out_price:e,last_commission:S,out_id:n,out_index:c,out_high:d,out_low:h,out_time:l,out_comment:s,profit:E,out_qty:r,max_profit:C,trading_loss:N});const T=(e-p)*b*M-S;Object.assign(t,{qty:M,profit:T,max_profit:w!==void 0?w-(C||0):void 0,trading_loss:m!==void 0?m-(N||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{t.isDeal=!0;const M=(e-p)*b*g;this._calcPercent({...t,out_price:e,out_id:n,out_index:c,out_high:d,out_low:h,out_time:l,out_comment:s,out_qty:g,profit:M}),r-=g}return a&&(b===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(t){const{commission_value:e,process_orders_on_close:r}=this._options,{in_price:n,out_qty:s=0,out_price:a=0,original_qty:l=0,direction:c,last_commission:h=0,immediately:d}=t;let{profit:f=0,max_profit:p,trading_loss:g,commission:w=0}=t,m=n*s,y=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=f,e){const v=this._getCommission(a,s);this._totalChangeCapital-=v;let x=w*s/l;m+=x,x+=v,f=f-x,Object.assign(t,{commission:x,profit:f});const b=this._orders.reduce((M,E)=>{const{qty:C=0,original_qty:N=0,commission:S=0}=E;return M+S*C/N},0);y+=b-h}if(p===void 0||g===void 0){const v=c===ce.long?1:-1,x=this._calcProfitAndLossHandle(n,s,v);if(p=x[0],g=x[1],e){const b=w*s/l;p-=b,g-=b}p=Math.max(0,p),g=Math.min(0,g)}Object.assign(t,{max_profit:p,trading_loss:g,total_profit:this._totalChangeCapital,total_profit_percent:f/y*100,profit_percent:f/m*100,max_profit_percent:p/m*100,trading_loss_percent:g/m*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(r?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(t),this._calcOrderFillsHandle(n,c,d)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case je.percent:a=s*r/100;break;case je.cashPerContract:a=e*r;break;case je.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:s=0,trading_loss:a=0,direction:l,immediately:c}=t;let{profit:h=0}=t,d=r*n;const f=this._totalChangeCapital+this._options.initial_capital;if(e){const p=this._getCommission(r,n);this._totalChangeCapital-=p,h=h-p,d+=p,Object.assign(t,{commission:p,profit:h,total_profit:this._totalChangeCapital})}Object.assign(t,{original_qty:n,total_profit_percent:h/f*100,profit_percent:h/d*100,max_profit_percent:s/d*100,trading_loss_percent:a/d*100,stop:void 0,limit:void 0}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders),e&&this._variables.strategy.updateHistoryOrders(this._historyOrder),this._calcOrderFillsHandle(r,l,c)}_calcOrderFillsHandle(t,e,r=!1){const{calc_on_order_fills:n,process_orders_on_close:s,slippage:a=0}=this._options;if(n){const{open:l,high:c,low:h,close:d}=this._variables,f=e===ce.long?1:-1,p=d-f*a*this._mintick;if((r||s)&&t===p)return;const g=l-f*a*this._mintick;let w={open:l,high:c,low:h,close:d},m=this.calcOnOrderFillsData.index;const y=Math.abs(c-l)<=Math.abs(h-l);switch(m){case-1:t===g?m=0:t>g?y?(m=1,w={open:c,high:c,low:h,close:d}):(m=2,w={open:c,high:c,low:d,close:d}):y?(m=2,w={open:h,high:d,low:h,close:d}):(m=1,w={open:h,high:c,low:h,close:d});break;case 0:t===g?(m=1,y?w={open:c,high:c,low:h,close:d}:w={open:h,high:c,low:h,close:d}):t>g?y?(m=1,w={open:c,high:c,low:h,close:d}):(m=2,w={open:c,high:c,low:d,close:d}):y?(m=2,w={open:h,high:d,low:h,close:d}):(m=1,w={open:h,high:c,low:h,close:d});break;case 1:m=2,y?w={open:h,high:d,low:h,close:d}:w={open:c,high:c,low:d,close:d};break;case 2:m=-1,w=void 0;break}this.calcOnOrderFillsData={tradeData:w,index:m}}}_isNaN(t){return t===void 0||isNaN(t)}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}};var bh={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){return function(e,r,n){r.prototype.isBetween=function(s,a,l,c){var h=n(s),d=n(a),f=(c=c||"()")[0]==="(",p=c[1]===")";return(f?this.isAfter(h,l):!this.isBefore(h,l))&&(p?this.isBefore(d,l):!this.isAfter(d,l))||(f?this.isBefore(h,l):!this.isAfter(h,l))&&(p?this.isAfter(d,l):!this.isBefore(d,l))}}})})(bh);var My=bh.exports,Ny=Gt(My),xh={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){return function(e,r,n){var s=r.prototype,a=function(p){var g,w=p.date,m=p.utc,y={};if(!((g=w)===null||g instanceof Date||g instanceof Array||s.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var v=m?n.utc():n();Object.keys(w).forEach(function(T){var A,O;y[A=T,O=s.$utils().p(A),O==="date"?"day":O]=w[T]});var x=y.day||(y.year||y.month>=0?1:v.date()),b=y.year||v.year(),M=y.month>=0?y.month:y.year||y.day?0:v.month(),E=y.hour||0,C=y.minute||0,N=y.second||0,S=y.millisecond||0;return m?new Date(Date.UTC(b,M,x,E,C,N,S)):new Date(b,M,x,E,C,N,S)}return w},l=s.parse;s.parse=function(p){p.date=a.bind(this)(p),l.bind(this)(p)};var c=s.set,h=s.add,d=s.subtract,f=function(p,g,w,m){m===void 0&&(m=1);var y=Object.keys(g),v=this;return y.forEach(function(x){v=p.bind(v)(g[x]*m,x)}),v};s.set=function(p,g){return g=g===void 0?p:g,p.constructor.name==="Object"?f.bind(this)(function(w,m){return c.bind(this)(m,w)},g,p):c.bind(this)(p,g)},s.add=function(p,g){return p.constructor.name==="Object"?f.bind(this)(h,p,g):h.bind(this)(p,g)},s.subtract=function(p,g){return p.constructor.name==="Object"?f.bind(this)(h,p,g,-1):d.bind(this)(p,g)}}})})(xh);var Sy=xh.exports,Oy=Gt(Sy),Eh={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){var e,r,n=1e3,s=6e4,a=36e5,l=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,h=31536e6,d=2628e6,f=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,p={years:h,months:d,days:l,hours:a,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},g=function(C){return C instanceof M},w=function(C,N,S){return new M(C,S,N.$l)},m=function(C){return r.p(C)+"s"},y=function(C){return C<0},v=function(C){return y(C)?Math.ceil(C):Math.floor(C)},x=function(C){return Math.abs(C)},b=function(C,N){return C?y(C)?{negative:!0,format:""+x(C)+N}:{negative:!1,format:""+C+N}:{negative:!1,format:""}},M=function(){function C(S,T,A){var O=this;if(this.$d={},this.$l=A,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),T)return w(S*p[m(T)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(U){O.$d[m(U)]=S[U]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(f);if(L){var q=L.slice(2).map(function(U){return U!=null?Number(U):0});return this.$d.years=q[0],this.$d.months=q[1],this.$d.weeks=q[2],this.$d.days=q[3],this.$d.hours=q[4],this.$d.minutes=q[5],this.$d.seconds=q[6],this.calMilliseconds(),this}}return this}var N=C.prototype;return N.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(T,A){return T+(S.$d[A]||0)*p[A]},0)},N.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/h),S%=h,this.$d.months=v(S/d),S%=d,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},N.toISOString=function(){var S=b(this.$d.years,"Y"),T=b(this.$d.months,"M"),A=+this.$d.days||0;this.$d.weeks&&(A+=7*this.$d.weeks);var O=b(A,"D"),L=b(this.$d.hours,"H"),q=b(this.$d.minutes,"M"),U=this.$d.seconds||0;this.$d.milliseconds&&(U+=this.$d.milliseconds/1e3,U=Math.round(1e3*U)/1e3);var W=b(U,"S"),z=S.negative||T.negative||O.negative||L.negative||q.negative||W.negative,K=L.format||q.format||W.format?"T":"",Z=(z?"-":"")+"P"+S.format+T.format+O.format+K+L.format+q.format+W.format;return Z==="P"||Z==="-P"?"P0D":Z},N.toJSON=function(){return this.toISOString()},N.format=function(S){var T=S||"YYYY-MM-DDTHH:mm:ss",A={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return T.replace(c,function(O,L){return L||String(A[O])})},N.as=function(S){return this.$ms/p[m(S)]},N.get=function(S){var T=this.$ms,A=m(S);return A==="milliseconds"?T%=1e3:T=A==="weeks"?v(T/p[A]):this.$d[A],T||0},N.add=function(S,T,A){var O;return O=T?S*p[m(T)]:g(S)?S.$ms:w(S,this).$ms,w(this.$ms+O*(A?-1:1),this)},N.subtract=function(S,T){return this.add(S,T,!0)},N.locale=function(S){var T=this.clone();return T.$l=S,T},N.clone=function(){return w(this.$ms,this)},N.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},N.valueOf=function(){return this.asMilliseconds()},N.milliseconds=function(){return this.get("milliseconds")},N.asMilliseconds=function(){return this.as("milliseconds")},N.seconds=function(){return this.get("seconds")},N.asSeconds=function(){return this.as("seconds")},N.minutes=function(){return this.get("minutes")},N.asMinutes=function(){return this.as("minutes")},N.hours=function(){return this.get("hours")},N.asHours=function(){return this.as("hours")},N.days=function(){return this.get("days")},N.asDays=function(){return this.as("days")},N.weeks=function(){return this.get("weeks")},N.asWeeks=function(){return this.as("weeks")},N.months=function(){return this.get("months")},N.asMonths=function(){return this.as("months")},N.years=function(){return this.get("years")},N.asYears=function(){return this.as("years")},C}(),E=function(C,N,S){return C.add(N.years()*S,"y").add(N.months()*S,"M").add(N.days()*S,"d").add(N.hours()*S,"h").add(N.minutes()*S,"m").add(N.seconds()*S,"s").add(N.milliseconds()*S,"ms")};return function(C,N,S){e=S,r=S().$utils(),S.duration=function(O,L){var q=S.locale();return w(O,{$l:q},L)},S.isDuration=g;var T=N.prototype.add,A=N.prototype.subtract;N.prototype.add=function(O,L){return g(O)?E(this,O,1):T.bind(this)(O,L)},N.prototype.subtract=function(O,L){return g(O)?E(this,O,-1):A.bind(this)(O,L)}}})})(Eh);var By=Eh.exports,Iy=Gt(By);ee.extend(wa),ee.extend(ya),ee.extend(Ny),ee.extend(Oy),ee.extend(Iy);class Ah{constructor(t,e,r){$(this,"array");$(this,"color");$(this,"math");$(this,"str");$(this,"map");$(this,"matrix");$(this,"timeframe");$(this,"ta");$(this,"input");$(this,"_variables");$(this,"_cacheData");$(this,"_options");$(this,"_errorListener");$(this,"_plots");$(this,"_plotshapes");$(this,"_plotbars");$(this,"_plotchars");$(this,"_plotarrows");$(this,"_plotcandles");$(this,"_alerts");$(this,"_bgColors");$(this,"_hlines");$(this,"_fills");$(this,"chart");$(this,"line");$(this,"label");$(this,"polyline");$(this,"box");$(this,"table");$(this,"linefill");$(this,"log");$(this,"runtime");$(this,"strategy");$(this,"request");$(this,"syminfo");$(this,"_count",0);var s;const n=((s=t.toString().split(".")[1])==null?void 0:s.length)||5;this._variables=e,this._errorListener=new Py,this.array=new pp(this._errorListener),this.math=new _p(n,this._errorListener),this.color=new k1,this.str=new qw(this._errorListener,n),this.map=new Uw(this._errorListener),this.timeframe=new kw(e),this.matrix=new zw(this._errorListener),this.ta=new P1(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new z1(e,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new Ww(e)},this.line=new hy(e,this._errorListener),this.label=new jw(e,this._errorListener),this.polyline=new fy(e,this._errorListener),this.box=new py(e,this._errorListener),this.table=new _y(e,this._errorListener),this.linefill=new dy(e),this.log=new Ly(e),this.runtime=new Ry(this._errorListener),this.strategy=new Fy(this._variables,this._options,t,this._errorListener,r),this.request=new Ty(this._variables,r),this.syminfo=new $y}get errors(){return this._errorListener.errors}options(t){if(t.length)return this._getDataOfBarindex(t);const e=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let s;if(n.length){s={};for(const v of n)s[v]=[...this._bgColors[v].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,l=this._fills.size?[...this._fills.values()]:void 0,c=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders,strategySummary:this._variables.strategy.summaryData});const h=this._plots.size>0?[...this._plots.values()]:void 0,d=this._plotbars.size>0?[...this._plotbars.values()]:void 0,f=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,p=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,g=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,w=this._plotchars.size>0?[...this._plotchars.values()]:void 0,m=this._getDraws(),y=this._variables.chart.isUseBgColor;return Object.assign(this._options,{inputs:e,plots:h,draws:m,alerts:r,colors:s,hlines:a,fills:l,logs:c,plotshapes:f,plotarrows:p,plotcandles:g,plotchars:w,plotbars:d,isUseBgColor:y})}_getDataOfBarindex(t){const e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let n;if(r.length){n={};for(const y of r)n[y]=[...this._bgColors[y].values()].map(v=>{const x=[];for(const b of t){const M=v.data[b];M&&x.push(M)}return v.data=x,v})}const s=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(t,[...this._fills.values()]):void 0,l=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._getDataFromBarindex(t,[...this._plots.values()]),h=this._plotbars.size>0?this._getDataFromBarindex(t,[...this._plotbars.values()]):void 0,d=this._plotarrows.size>0?this._getDataFromBarindex(t,[...this._plotarrows.values()]):void 0,f=this._plotcandles.size>0?this._getDataFromBarindex(t,[...this._plotcandles.values()]):void 0,p=this._plotchars.size>0?this._getDataFromBarindex(t,[...this._plotchars.values()]):void 0,g=this._plotshapes.size>0?this._getDataFromBarindex(t,[...this._plotshapes.values()]):void 0,w=this._getDrawsFromBarindex(t),m=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,plotarrows:d,plotcandles:f,plotchars:p,plotbars:h,draws:w,alerts:e,colors:n,hlines:s,fills:a,logs:l,plotshapes:g,isUseBgColor:m})}_getDataFromBarindex(t,e){return e.map(r=>{const n=[];for(const s of t){const a=r.data[s];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:a}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),s.data.length&&(l.polylines=s.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}_getDrawsFromBarindex(t){const{line:e,linefill:r,table:n,box:s,polyline:a,label:l}=this._variables,c={};return e.data.length&&(c.lines=e.getValOfBarIndex(t)),r.data.length&&(c.linefills=r.getValOfBarIndex(t)),n.data.length&&(c.tables=n.getValOfBarIndex(t)),s.data.length&&(c.boxes=s.getValOfBarIndex(t)),a.data.length&&(c.polylines=a.getValOfBarIndex(t)),l.data.length&&(c.labels=l.getValOfBarIndex(t)),Object.keys(c).length?c:void 0}updateOptions(t){const{inputs:e,strategy:r}=t;this.input.update(e),r&&this.strategy.updateOptions(r)}update(t){const{barIndex:e}=t;this.strategy.update(),this.math.update(e)}endExecution(){this.strategy.endExecution()}library(t,e){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=t;r.test(n)?(dp.includes(n)||hp.includes(n))&&this._errorListener.addError(Ze(se.libraryTitleIsKeywordErr,{name:n}),e,Pt.Error):this._errorListener.addError(se.libraryTitleErr,e,Pt.Error),this._options.scriptType="library",this._options.library=t}}indicator(t,e){if(!this._variables.bar_index){const{format:r}=t;this._paramVerfiy(r,e,"indicator",[Kt.inherit,Kt.percent,Kt.price,Kt.volume]),this._variables.updateMaxLength(t),this._options.scriptType="indicator",this._options.indicator=t}}_paramVerfiy(t="",e,r,n,s="format"){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_lineWidthVerify(t,e){const{linewidth:r=1}=t;r<1&&(this._errorListener.addError(cp.lineWidthWarning,e,Pt.Warning),t.linewidth=1)}plot(t,e){const r=["color"];ge(t,r);const{series:n,color:s,...a}=t,{bar_index:l,time:c}=this._variables,h=`plot_${e}`,d=this._plots.get(h),f=(d==null?void 0:d.data)||[],p=n!==void 0&&isNaN(n)?void 0:n;if(f[l]={value:[c,p],itemStyle:{color:s}},this._seriesColorHandle(t,r,d),!d){this._count++,this._lineWidthVerify(a,e),this._paramVerfiy(t.format,e,"plot",[Kt.percent,Kt.price,Kt.volume]);const g=s?[s]:void 0;this._plots.set(h,{editable:!0,...a,colors:g,data:f,id:h,zIndex:this._count})}return{type:"plot",key:h}}plotbar(t,e){const r=["color"];ge(t,r);const{open:n,close:s,low:a,high:l,color:c,...h}=t,{bar_index:d,time:f}=this._variables,p=`plotbar_${e}`,g=this._plotbars.get(p),w=(g==null?void 0:g.data)||[],m=s!==void 0&&isNaN(s)?void 0:s,y=n!==void 0&&isNaN(n)?void 0:n,v=a!==void 0&&isNaN(a)?void 0:a,x=l!==void 0&&isNaN(l)?void 0:l,b=[f,y,m,v,x];if(w[d]={value:b,itemStyle:{color:c}},this._seriesColorHandle(t,r,g),!g){this._count++,this._paramVerfiy(t.format,e,"plotbar",[Kt.percent,Kt.price,Kt.volume]);const M=c?[c]:void 0;this._plotbars.set(p,{editable:!0,...h,colors:M,data:w,id:p,zIndex:this._count})}}_verfiyArgs(t,e,r){const{size:n,format:s,location:a,style:l}=t;this._paramVerfiy(l,r,e,Object.values(lr),"style"),this._paramVerfiy(a,r,e,Object.values(ln),"location"),this._paramVerfiy(n,r,e,Object.values(ir),"size"),this._paramVerfiy(s,r,e,[Kt.percent,Kt.price,Kt.volume],"format")}plotchar(t,e){const r=["color","textcolor"];ge(t,r);const{series:n,color:s,textcolor:a,location:l=ln.abovebar,...c}=t,{bar_index:h,time:d,high:f,low:p}=this._variables,g=`plotchar_${e}`,w=this._plotchars.get(g),m=(w==null?void 0:w.data)||[],y={value:[d,n],itemStyle:{color:s,textcolor:a},low:p,high:f};m[h]=y,this._seriesColorHandle(t,r,w),w||(this._count++,this._verfiyArgs(t,"plotchar",e),this._plotchars.set(g,{editable:!0,...c,location:l,data:m,id:g,zIndex:this._count}))}plotarrow(t,e){const r=["colorup","colordown"];ge(t,r);const{series:n,colorup:s,colordown:a,...l}=t,{bar_index:c,time:h,low:d,high:f}=this._variables,p=`plotarrow_${e}`,g=this._plotarrows.get(p),w=(g==null?void 0:g.data)||[];w[c]={value:[h,n!==void 0&&isNaN(n)?void 0:n],itemStyle:{colorup:s,colordown:a},low:d,high:f},this._seriesColorHandle(t,r,g),g||(this._count++,this._paramVerfiy(t.format,e,"plotarrow",[Kt.percent,Kt.price,Kt.volume]),this._plotarrows.set(p,{editable:!0,...l,data:w,id:p,zIndex:this._count}))}plotshape(t,e){const r=["color","textcolor"];ge(t,r);const{series:n,color:s,textcolor:a,location:l=ln.abovebar,...c}=t,{bar_index:h,time:d,low:f,high:p}=this._variables,g=`plotshape_${e}`,w=this._plotshapes.get(g),m=(w==null?void 0:w.data)||[],y={value:n,color:s,textcolor:a,time:d,low:f,high:p};if(m[h]=y,this._seriesColorHandle(t,r,w),!w){this._count++;const v=s?[s]:void 0;this._verfiyArgs(t,"plotshape",e),this._plotshapes.set(g,{editable:!0,...c,data:m,location:l,id:g,colors:v,zIndex:this._count})}}plotcandle(t,e){const r=["wickcolor","bordercolor","color"];ge(t,r);const{wickcolor:n,bordercolor:s,color:a,close:l,open:c,low:h,high:d,...f}=t,{bar_index:p,time:g}=this._variables,w=`plotcandle_${e}`,m=this._plotcandles.get(w),y=(m==null?void 0:m.data)||[],v=l!==void 0&&isNaN(l)?void 0:l,x=c!==void 0&&isNaN(c)?void 0:c,b=h!==void 0&&isNaN(h)?void 0:h,M=d!==void 0&&isNaN(d)?void 0:d,E=[g,x,v,b,M];y[p]={value:E,wickcolor:n,bordercolor:s,color:a},this._seriesColorHandle(t,r,m),m||(this._count++,this._paramVerfiy(t.format,e,"plotcandle",[Kt.percent,Kt.price,Kt.volume]),this._plotcandles.set(w,{editable:!0,...f,data:y,id:w,zIndex:this._count}))}hline(t,e){const r=`hline_${e}`;ge(t,["color"]),this._verifyDisplay(t.display,"hline",e);const s=t.display&&!t.display.length?Ke.none:Ke.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(t,e),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:s,...t,zIndex:this._count})),{type:"hline",key:r}}fill(t,e){var S,T,A,O,L,q,U,W,z,K;const r=["color","top_color","bottom_color"];ge(t,r);const{color:n,top_color:s,bottom_color:a,seriesColors:l,hline1:c,hline2:h,plot1:d,plot2:f,top_value:p,bottom_value:g,...w}=t,{bar_index:m,time:y}=this._variables,v=`fill_${e}`,x=this._fills.get(v),b=(x==null?void 0:x.data)||[];this._verifyDisplay(t.display,"fill",e);const M=t.display&&!t.display.length?Ke.none:Ke.all;let E,C,N="plot";if(c&&h)E=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,C=(T=this._hlines.get(h==null?void 0:h.key))==null?void 0:T.price,N="hline";else{const Z=((A=this._plots.get(d==null?void 0:d.key))==null?void 0:A.data)||[],X=((O=this._plots.get(f==null?void 0:f.key))==null?void 0:O.data)||[];E=(q=(L=Z[m])==null?void 0:L.value)==null?void 0:q[1],C=(W=(U=X[m])==null?void 0:U.value)==null?void 0:W[1]}if(b[m]={time:y,color:n,top_color:s,bottom_color:a,plot1:E,plot2:C,top_value:p,bottom_value:g},this._seriesColorHandle(t,r,x),!x){this._count++;const Z=((z=this._options.indicator)==null?void 0:z.explicit_plot_zorder)||((K=this._options.strategy)==null?void 0:K.explicit_plot_zorder),X=n?[n]:void 0,Q=s?[s]:void 0,ct=a?[a]:void 0;this._fills.set(v,{id:v,colors:X,top_colors:Q,bottom_colors:ct,display:M,data:b,type:N,editable:!0,fillgaps:!1,hline1:c,hline2:h,plot1:d,plot2:f,...w,zIndex:Z?this._count:void 0})}}alert({message:t,freq:e=Ur.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l]||{},h=c.barIndex;if(this._paramVerfiy(e,r,"alert",[Ur.freqAll,Ur.freqOncePerBar,Ur.freqOncePerBarClose]),e===Ur.freqOncePerBar&&n===h){this._alerts.delete(l);return}this._cacheData[l]=c;const d={message:t,freq:e,id:l,type:"alert"};if(s){e!==Ur.freqOncePerBarClose&&this._alerts.set(l,d),c.barIndex=n;return}if(!s&&e===Ur.freqOncePerBarClose&&n===h&&a===n-1){this._alerts.set(l,d),c.barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,a=`alertcondition_${n}`;s&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t,e){this._setColors(t,"barcolor",e)}bgcolor(t,e){this._setColors(t,"bgcolor",e)}_verifyDisplay(t=ph.all,e,r){t.length&&t.length<4&&this._errorListener.addError(Ze(se.displayErr,{func:e,values:"[display.none, display.all]"}),r,Pt.Error)}_setColors(t,e,r){ge(t,["color"]);const{color:s,...a}=t;this._verifyDisplay(a.display,e,r);const l=t.display&&!t.display.length?Ke.none:Ke.all,{bar_index:c,time:h}=this._variables,d=`${e}_${r}`;this._bgColors[e]||(this._bgColors[e]=new Map);const f=this._bgColors[e].get(d),p=(f==null?void 0:f.data)||[],g=(f==null?void 0:f.setColors)||[];s&&!g.includes(s)&&g.push(s),p[c]={color:s,time:h},f||this._bgColors[e].set(d,{...a,display:l,data:p,setColors:g,id:d})}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return!!(t===void 0||typeof t=="number"&&isNaN(t))}fixnan({source:t},e){return t===void 0||typeof t=="number"&&isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!(typeof t=="number"&&isNaN(t))?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n,!0)}timestamp(t){const{dateString:e,timezone:r,year:n,month:s,day:a,hour:l=0,minute:c=0,second:h=0}=t;if(e)return ee(e).utc(!/GMT|UTC/.test(e)).valueOf();let d=s-1,f=n;if(d<0){const p=Math.ceil(Math.abs(d/12));d=12*p+d,f=n-p}return mr({year:f,month:d,day:a,hour:l,minute:c,second:h},r).valueOf()}weekofyear({time:t,timezone:e}){return mr(t,e).week()}year({time:t,timezone:e}){return mr(t,e).year()}second({time:t,timezone:e}){return mr(t,e).second()}month({time:t,timezone:e}){return mr(t,e).month()+1}minute({time:t,timezone:e}){return mr(t,e).minute()}hour({time:t,timezone:e}){return mr(t,e).hour()}dayofweek({time:t,timezone:e}){return mr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return mr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,this._variables.timeframe.period),n=tn(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,a=0,l=!1){const c=r||this._variables.timeframe.period,h=tn(c),d=tn(this._variables.timeframe.period);let f;if(h<=d)f=t,l&&(f+=d*1e3);else{const p=`time_${e}`,g=this._cacheData[p];if(g)g.currentTime+h*1e3-g.offset<=t?(f=t,this._cacheData[p]={currentTime:t,offset:0}):f=g.currentTime;else{const w=this._calcTimeOffset(t,c);this._cacheData[p]={currentTime:t,offset:w},f=t}l&&(f+=h*1e3)}if(n){const{timePeriods:p,weeks:g}=this._parserSession(n,e),w=mr(t,s),m=w.format("YYYY-MM-DD HH:mm"),y=w.format("YYYY-MM-DD"),v=f,x=mr(f,s).format("YYYY-MM-DD HH:mm");f=void 0;for(const M of p){const[E,C]=M;let N;if(E===C&&(N=w.add(1,"day").format("YYYY-MM-DD")),ee(m).isBetween(`${y} ${E}`,`${N||y} ${C}`,"hour","[)")){ee(x).isBetween(`${y} ${E}`,`${N||y} ${C}`,"hour","[)")?f=v:f=mr(`${y} ${E}`,s).valueOf();break}}const b=this._variables.dayofweek;f&&!g.includes(b)&&(f=void 0)}return f&&f-a*d*1e3}_seriesColorHandle(t,e,r){var n;if(r&&e!=null&&e.length)for(const s of e){if((n=r.gradientColorKeys)!=null&&n.includes(s))continue;const a=t[s];if(!a)continue;const l=r[`${s}s`]||[];l.includes(a)||(l.push(a),r[`${s}s`]=l,l.length>5&&(r[`${s}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(s)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const h=parseInt(c,10);if(h<1||h>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,Pt.Error);return}return h});return{timePeriods:n.split(",").map(c=>{c===""||c===gi.regular?c="0930-1500":c===gi.extended&&(c="1500-1830");const h=c.split("-");return h.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,e,Pt.Error),[]):[this._processTime(h[0],e),this._processTime(h[1],e)]}),weeks:a}}_processTime(t,e){const r=parseInt(t.slice(0,2),10),n=parseInt(t.slice(2),10);if(!(r>=0&&r<=23)&&n>=0&&n<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",e,Pt.Error);return}return`${r}:${n}`}}class Ty{constructor(t,e){$(this,"_variables");$(this,"_scriptId");$(this,"_cacheData");this._variables=t,this._scriptId=e,this._cacheData=new Map}security(t,e){const r=self.workerStorage.get(`request_${this._scriptId}`),{paramsExpr:n=[]}=t,s=this._getRequestData(t,e);if(r!=null&&r.has(e)){const c=r.get(e);return this._runScripts(c,e,!1,n,s)}const a=this._parseExprCode(t),l=this._runScripts(a,e,!0,n,s);return r==null||r.set(e,a),l}_parseExprCode(t){let{expression:e,paramsExpr:r=[]}=t,n=[],s=1;e=Yl(e);const a=JSON.parse(e),l=a.pop();let c=(l==null?void 0:l.memberCodes)||{},h=(l==null?void 0:l.depends)||[];if(!h.length)return`return ${l==null?void 0:l.code}`;let d=[],f=[];const p=[];if(this._getDependCodes(h,a,n,d,f,p),n.push(...p),f.length){const m=r.length;let y=[];for(let v=m-1;v>=0;v--){const x=r[v];let b=JSON.parse(Yl(x));const M=[];s!==0&&f.length&&(y.unshift("{"),s++),b=b.map(S=>{const{scope:T,code:A,varNames:O,dependSelf:L}=S;return T===2&&!M.includes(O)&&!L&&(S.code=`let ${A}`),O&&M.push(...O.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const E=[],C=[];let N=f.map(S=>({...S,isArg:!1,isPreArg:!0}));f=[],this._getDependCodes(N,b,C,d,f,E),y.unshift(...C,...E),n=y.concat(n),y=[]}}for(n.push(`return ${l==null?void 0:l.code}`);s>1;)n.push("}"),s--;n=d.concat(n);let g=n.join(`
62
+ `)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return String(this._toStringFormat(t,e==null?void 0:e.replace(/0/g,"#")))}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._toStringFormat(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return _t(e)&&(e=0),_t(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _t(t)&&(t=0),mr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_toStringFormat(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case Kt.mintick:return t.toFixed(this._precision);case Kt.percent:return`${t}%`;case Kt.volume:return this._intlNumberFormatter.format(Math.round(t));default:return this._formatOthers(t,e)}}_formatOthers(t,e){var l;let[r,n]=e.split(".");e.split("%").length===2&&(t=t*100);let[s,a=""]=String(t).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),h=((l=c[c.length-1])==null?void 0:l.replace(/[^#]/g,"").length)||0;h&&(s=s.replace(new RegExp(`\\B(?=(\\d{${h}})+(?!\\d))`,"g"),",")),r=c.join("")}s=r.replace(/#/,s).replace(/#/g,"")}else s=`${r}${s}`;if(n&&n.includes("#")){const c=n.split("#").length-1,h=+`${s}.${a}`;if(!isNaN(h))return`${h.toFixed(c)}${n.replace(/#/g,"")}`;a=`${a.substring(0,c)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${s}.${a}`:s}_formatNumber(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:return this._formatOthers(t,e)}}_strFormat(t,e){let r=t;for(const[n,s]of e.entries()){if(s===void 0||typeof s=="number"&&isNaN(s)){r="NaN";continue}if(typeof s=="number"){const a=`\\{\\s*${n}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const c=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(s,c)))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),String(s))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),s)}return r}}class Uw{constructor(t){$(this,"_errorListener");this._errorListener=t}new(){return new Qa(this._errorListener)}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class Qa{constructor(t){$(this,"_errorListener");$(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new Qa(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class Ww{constructor(t){$(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Oi(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Oi(t,r,e)}copy({id:t}){return t==null?void 0:t.copy()}from_index({price:t,index:e}){return new Oi(t,e)}from_time({price:t,time:e}){return new Oi(t,void 0,e)}}class Oi{constructor(t,e,r){$(this,"_index");$(this,"_price");$(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}set index(t){this._index=t}get price(){return this._price}set price(t){this._price=t}get time(){return this._time}set time(t){this._time=t}copy(){return new Oi(this._price,this._index,this._time)}}class jw{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLabel",{text:"",xloc:De.bar_index,yloc:jr.price,size:ir.normal,style:ve.styleLabelDown,textalign:Wt.alignCenter});this._variables=t,this._errorListener=e}new(t,e){const{time:r,high:n,low:s,bar_index:a}=this._variables,l=`label_${e}_${a}`;ge(t,["color","textcolor"]);const c={...this._defaultLabel,...t,id:l,time:r,high:n,low:s,bar_index:a};t.point&&(c.x=c.xloc===De.bar_index?t.point.index:t.point.time,c.y=t.point.price),c.yloc===jr.abovebar?c.y=n:c.yloc===jr.belowbar&&(c.y=s),this._verfiyArgs(t,e);const h=new mo(l,this._variables,this._errorListener);return e.startsWith("export")||this._variables.label.add(l,c,h),h}_verfiyArgs(t,e){const{xloc:r,yloc:n,style:s,size:a,textalign:l,text_font_family:c}=t,h="label.new";this._paramVerfiy(s,e,h,Object.values(ve),"style"),this._paramVerfiy(r,e,h,Object.values(De),"xloc"),this._paramVerfiy(n,e,h,Object.values(jr),"yloc"),this._paramVerfiy(a,e,h,Object.values(ir),"size"),this._paramVerfiy(l,e,h,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign"),this._paramVerfiy(c,e,h,Object.values(Gn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}label(t){return t.x}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class mo{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");this._id=t,this._variables=e,this._errorListener=r}get type(){return Me.LABEL}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.label.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`label_${t}_${e}`,n=this._getLabel(t),s=new mo(r,this._variables,this._errorListener);if(n){const a={...n,id:r,bar_index:e};this._variables.label.add(r,a,s)}return s}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t),this._paramVerfiy(t,e,"label.set_size",Object.values(ir),"size")}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e,this._paramVerfiy(e,r,"label.set_xloc",Object.values(De),"xloc"))}set_yloc({yloc:t},e){const r=this._getLabel(e),{high:n,low:s}=this._variables;r&&(r.yloc=t,t===jr.abovebar?r.y=n:t===jr.belowbar&&(r.y=s),this._paramVerfiy(t,e,"label.set_yloc",Object.values(jr),"yloc"))}set_color(t,e){const r=this._getLabel(e);ge(t,["color"]),r&&(r.color=t.color)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===De.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t),this._paramVerfiy(t,e,"label.set_style",Object.values(ve),"style")}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t),this._paramVerfiy(t,e,"label.set_textalign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign")}set_textcolor(t,e){const r=this._getLabel(e);ge(t,["textcolor"]),r&&(r.textcolor=t.textcolor)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t),this._paramVerfiy(t,e,"label.set_text_font_family",Object.values(Gn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const Yw={freq_all:Ur.freqAll,freq_once_per_bar:Ur.freqOncePerBar,freq_once_per_bar_close:Ur.freqOncePerBarClose},Vw={gaps_off:Qi.gapsOff,gaps_on:Qi.gapsOn,lookahead_off:Qi.lookaheadOff,lookahead_on:Qi.lookaheadOn},Bi={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#FF5252",silver:"#B2B5BE",teal:"#00897B",white:"#FFFFFF",yellow:"#FFEB3B"},dh={AUD:"AUD",BTC:"BTC",CAD:"CAD",CHF:"CHF",ETH:"ETH",EUR:"EUR",GBP:"GBP",HKD:"HKD",INR:"INR",JPY:"JPY",KRW:"KRW",MYR:"MYR",NOK:"NOK",NONE:"NONE",NZD:"NZD",RUB:"RUB",SEK:"SEK",SGD:"SGD",TRY:"TRY",USD:"USD",USDT:"USDT",ZAR:"ZAR"},Zw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},ph={all:[Ke.dataWindow,Ke.pane,Ke.priceScale,Ke.statusLine],data_window:[Ke.dataWindow],none:[],pane:[Ke.pane],price_scale:[Ke.priceScale],status_line:[Ke.statusLine]},Kw={both:Wr.both,left:Wr.left,none:Wr.none,right:Wr.right},Gw={inherit:Kt.inherit,mintick:Kt.mintick,percent:Kt.percent,price:Kt.price,volume:Kt.volume},Hw={style_solid:Ns.styleSolid,style_dashed:Ns.styleDashed,style_dotted:Ns.styleDotted},Jw={style_arrowdown:ve.styleArrowdown,style_arrowup:ve.styleArrowup,style_circle:ve.styleCircle,style_cross:ve.styleCross,style_diamond:ve.styleDiamond,style_flag:ve.styleFlag,style_label_center:ve.styleLabelCenter,style_label_down:ve.styleLabelDown,style_label_left:ve.styleLabelLeft,style_label_lower_left:ve.styleLabelLowerLeft,style_label_lower_right:ve.styleLabelLowerRight,style_label_right:ve.styleLabelRight,style_label_up:ve.styleLabelUp,style_label_upper_left:ve.styleLabelUpperLeft,style_label_upper_right:ve.styleLabelUpperRight,style_none:ve.styleNone,style_square:ve.styleSquare,style_text_outline:ve.styleTextOutline,style_triangledown:ve.styleTriangledown,style_triangleup:ve.styleTriangleup,style_xcross:ve.styleXcross},Xw={style_arrow_both:Re.styleArrowBoth,style_arrow_left:Re.styleArrowLeft,style_arrow_right:Re.styleArrowRight,style_dashed:Re.styleDashed,style_dotted:Re.styleDotted,style_solid:Re.styleSolid},Qw={abovebar:ln.abovebar,absolute:ln.absolute,belowbar:ln.belowbar,bottom:ln.bottom,top:ln.top},ty={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},ey={style_area:Sr.styleArea,style_areabr:Sr.styleAreabr,style_circles:Sr.styleCircles,style_columns:Sr.styleColumns,style_cross:Sr.styleCross,style_histogram:Sr.styleHistogram,style_line:Sr.styleLine,style_linebr:Sr.styleLinebr,style_stepline:Sr.styleStepline,style_stepline_diamond:Sr.styleSteplineDiamond,style_steplinebr:Sr.styleSteplinebr},ry={bottom_center:gr.bottomCenter,bottom_left:gr.bottomLeft,bottom_right:gr.bottomRight,middle_center:gr.middleCenter,middle_left:gr.middleLeft,middle_right:gr.middleRight,top_center:gr.topCenter,top_left:gr.topLeft,top_right:gr.topRight},ny={left:Ss.left,none:Ss.none,right:Ss.right},iy={arrowdown:lr.arrowdown,arrowup:lr.arrowup,circle:lr.circle,cross:lr.cross,diamond:lr.diamond,flag:lr.flag,labeldown:lr.labeldown,labelup:lr.labelup,square:lr.square,triangledown:lr.triangledown,triangleup:lr.triangleup,xcross:lr.xcross},sy={auto:ir.auto,huge:ir.huge,large:ir.large,normal:ir.normal,small:ir.small,tiny:ir.tiny},oy={cash:Pe.cash,fixed:Pe.fixed,percent_of_equity:Pe.percentOfEquity,commission:{cash_per_contract:je.cashPerContract,cash_per_order:je.cashPerOrder,percent:je.percent},direction:{all:ce.all,long:ce.long,short:ce.short},oca:{cancel:cn.cancel,none:cn.none,reduce:cn.reduce}},ay={align_bottom:Wt.alignBottom,align_center:Wt.alignCenter,align_left:Wt.alignLeft,align_right:Wt.alignRight,align_top:Wt.alignTop,wrap_auto:Wt.wrapAuto,wrap_none:Wt.wrapNone},uy={bar_index:De.bar_index,bar_time:De.bar_time},ly={abovebar:jr.abovebar,belowbar:jr.belowbar,price:jr.price},cy={actual:Os.actual,estimate:Os.estimate,standardized:Os.standardized};class _h{constructor(){$(this,"adjustment",{dividends:Ms.dividends,none:Ms.none,splits:Ms.splits});$(this,"alert",Yw);$(this,"barmerge",Vw);$(this,"color",Bi);$(this,"currency",dh);$(this,"dayofweek",Zw);$(this,"earnings",cy);$(this,"display",ph);$(this,"extend",Kw);$(this,"font",{family_default:Gn.familyDefault,family_monospace:Gn.familyMonospace});$(this,"format",Gw);$(this,"hline",Hw);$(this,"label",Jw);$(this,"line",Xw);$(this,"location",Qw);$(this,"math",ty);$(this,"order",{ascending:Kn.ascending,descending:Kn.descending});$(this,"plot",ey);$(this,"position",ry);$(this,"scale",ny);$(this,"session",{extended:gi.extended,regular:gi.regular});$(this,"shape",iy);$(this,"size",sy);$(this,"splits",{denominator:"denominator",numerator:"numerator"});$(this,"strategy",oy);$(this,"text",ay);$(this,"xloc",uy);$(this,"yloc",ly)}updateData(){}}class fy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:De.bar_index,line_color:Bi.blue,line_style:Re.styleSolid,line_width:1});this._variables=t,this._errorListener=e}new(t,e){var l;const{bar_index:r}=this._variables,n=`polyline_${e}_${r}`,s=Object.assign({},this._defaultPolyline,t,{id:n,bar_index:r,points:(l=t.points)==null?void 0:l._value.map(c=>({time:c.time,index:c.index,price:c.price}))});ge(s,["line_color","fill_color"]);const a=new mh(n,this._variables);return this._verfiyArgs(t,e),e.startsWith("export")||this._variables.polyline.add(n,s,a),a}_verfiyArgs(t,e){const{line_style:r,xloc:n}=t,s="polyline.new";this._paramVerfiy(r,e,s,Object.values(Re),"line_style"),this._paramVerfiy(n,e,s,Object.values(De),"xloc")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}delete({id:t}){t&&t.delete()}}class mh{constructor(t,e){$(this,"_id");$(this,"_variables");$(this,"_suffix");this._variables=e,this._id=t}get type(){return Me.POLYLINE}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.polyline.get(this._id)}delete(){this._variables.polyline.delete(this._id)}}class hy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLine",{xloc:De.bar_index,extend:Wr.none,style:Re.styleSolid});this._variables=t,this._errorListener=e}new({first_point:t,second_point:e,...r},n){const{bar_index:s}=this._variables,a=`line_${n}_${s}`;ge(r,["color"]);const l={...this._defaultLine,...r,id:a,bar_index:s};if(t&&e){const h=l.xloc===De.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,d=l.xloc===De.bar_index?e==null?void 0:e.index:e==null?void 0:e.time;Object.assign(l,{x1:h,y1:t==null?void 0:t.price,x2:d,y2:e==null?void 0:e.price})}this._verfiyArgs(r,n);const c=new go(a,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(a,l,c),c}_verfiyArgs(t,e){const{extend:r,xloc:n,style:s}=t,a="line.new";this._paramVerfiy(s,e,a,Object.values(Re),"style"),this._paramVerfiy(r,e,a,Object.values(Wr),"extend"),this._paramVerfiy(n,e,a,Object.values(De),"xloc")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}line(t){return t.x}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class go{constructor(t,e,r){$(this,"_variables");$(this,"_id");$(this,"_suffix","");$(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get type(){return Me.LINE}get data(){return this._variables.line.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`line_${t}_${e}`,n=this._getLine(t),s=new go(r,this._variables,this._errorListener);return n&&this._variables.line.add(r,{...n,id:r,bar_index:e,isVar:void 0},s),s}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===De.bar_index){const{x1:n,y1:s,x2:a,y2:l}=r;return n===void 0||a===void 0||s===void 0||l===void 0?void 0:(l-s)/(a-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r,this._paramVerfiy(t,n,"line.set_xloc",Object.values(De),"xloc"))}set_color(t,e){const r=this._getLine(e);r&&(ge(t,["color"]),r.color=t.color)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t,this._paramVerfiy(t,e,"line.set_style",Object.values(Re),"style"))}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t,this._paramVerfiy(t,e,"line.set_extend",Object.values(Wr),"extend"))}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===De.bar_index?n:s,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===De.bar_index?n:s,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class dy{constructor(t){$(this,"_variables");this._variables=t}new(t,e){const{line1:r,line2:n}=t,{bar_index:s}=this._variables,a=`linefill_${e}_${s}`,l=r==null?void 0:r.data,c=n==null?void 0:n.data;l&&(l.linefills=l.linefills||[],l.linefills.push(a)),c&&(c.linefills=c.linefills||[],c.linefills.push(a)),ge(t,["color"]);const h=new vo(this._variables,a,r,n);return e.startsWith("export")||(l||c)&&this._variables.linefill.add(a,{line1:l,line2:c,color:t.color,id:a,bar_index:s},h),h}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class vo{constructor(t,e,r,n){$(this,"_id");$(this,"_line1");$(this,"_line2");$(this,"_variables");$(this,"_suffix");this._variables=t,this._id=e,this._line1=r,this._line2=n}get type(){return Me.LINEFILL}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.linefill.get(this._id)}linefill(t,e){return t.x?t.x:new vo(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),s&&(s.linefills=(r=s.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(t){const e=this._variables.linefill.get(this._id);e&&(ge(t,["color"]),e.color=t.color)}}class py{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultBox",{border_color:Bi.blue,border_width:1,bgcolor:Bi.blue,xloc:De.bar_index,extend:Wr.none,style:Re.styleSolid,text:"",text_size:ir.auto,text_color:Bi.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_wrap:Wt.wrapNone});this._variables=t,this._errorListener=e}box({x:t}){return t}new({top_left:t,bottom_right:e,...r},n){const{bar_index:s}=this._variables,a=`box_${n}_${s}`,l={...this._defaultBox,...r,id:a,bar_index:s};if(ge(l,["border_color","bgcolor","text_color"]),t){const{price:h,time:d,index:f}=t;l.top=h,l.left=l.xloc===De.bar_index?f:d}if(e){const{price:h,time:d,index:f}=e;l.bottom=h,l.right=l.xloc===De.bar_index?f:d}this._verfiyArgs(r,n);const c=new wo(this._variables,a,this._errorListener);return n.startsWith("export")||this._variables.box.add(a,l,c),c}_verfiyArgs(t,e){const{border_style:r,extend:n,xloc:s,text_size:a,text_halign:l,text_valign:c,text_wrap:h,text_font_family:d}=t,f="box.new";this._paramVerfiy(r,e,f,[Re.styleDashed,Re.styleDotted,Re.styleSolid],"border_style"),this._paramVerfiy(n,e,f,Object.values(Wr),"extend"),this._paramVerfiy(s,e,f,Object.values(De),"xloc"),this._paramVerfiy(a,e,f,Object.values(ir),"text_size"),this._paramVerfiy(l,e,f,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"),this._paramVerfiy(c,e,f,[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"),this._paramVerfiy(h,e,f,[Wt.wrapAuto,Wt.wrapNone],"text_wrap"),this._paramVerfiy(d,e,f,Object.values(Gn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_text({id:t,...e}){t==null||t.set_text(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e},r){t==null||t.set_border_style(e,r)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e},r){t==null||t.set_text_size(e,r)}set_text_wrap({id:t,...e},r){t==null||t.set_text_wrap(e,r)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e},r){t==null||t.set_text_halign(e,r)}set_text_valign({id:t,...e},r){t==null||t.set_text_valign(e,r)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class wo{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");this._variables=t,this._id=e,this._errorListener=r}get type(){return Me.BOX}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.box.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`box_${t}_${e}`,n=this._getBox(),s=new wo(this._variables,r,this._errorListener);return n&&this._variables.box.add(r,{...n,id:r,bar_index:e},s),s}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t},e){const r=this._getBox();r&&(r.extend=t,this._paramVerfiy(t,e,"box.set_extend",Object.values(Wr),"extend"))}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t,ge(e,["bgcolor"]))}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t},e){const r=this._getBox();r&&(r.text_size=t,this._paramVerfiy(t,e,"box.set_text_size",Object.values(ir),"text_size"))}set_text_wrap({text_wrap:t},e){const r=this._getBox();r&&(r.text_wrap=t,this._paramVerfiy(t,e,"box.set_text_wrap",[Wt.wrapAuto,Wt.wrapNone],"text_wrap"))}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t,ge(e,["text_color"]))}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t},e){const r=this._getBox();r&&(r.text_halign=t,this._paramVerfiy(t,e,"box.set_text_halign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"))}set_text_valign({text_valign:t},e){const r=this._getBox();r&&(r.text_valign=t,this._paramVerfiy(t,e,"box.set_text_valign",[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"))}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===De.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t,ge(e,["border_color"]))}set_border_style({style:t},e){const r=this._getBox();r&&(r.border_style=t,this._paramVerfiy(t,e,"box.set_border_style",[Re.styleDashed,Re.styleDotted,Re.styleSolid],"style"))}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===De.bar_index?r:s}}set_text_font_family({text_font_family:t},e){const r=this._getBox();r&&(r.text_font_family=t,this._paramVerfiy(t,e,"box.set_text_font_family",Object.values(Gn),"text_font_family"))}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getBox(){return this._variables.box.get(this._id)}}class _y{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultTable",{position:gr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t,this._errorListener=e}table({x:t}){return t}new(t,e){const{bar_index:r}=this._variables,n=`table_${e}_${r}`,{rows:s}=t;ge(t,["text_color","bgcolor","border_color"]);const a=Array.from(Array(s),()=>[]),l=e.split("_"),c=l.pop(),h=l.pop(),d={...this._defaultTable,...t,cell:a,id:n,bar_index:r,line:h,col:c},f=new gh(this._variables,n,this._errorListener);return this._paramVerfiy(t.position,e,"table.new",Object.values(gr),"position"),e.startsWith("export")||this._variables.table.add(n,d,f),f}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e},r){t==null||t.set_position(e,r)}}class gh{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");$(this,"_defaultCell",{column:0,row:0,text:"",text_color:Bi.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_size:ir.normal});this._variables=t,this._id=e,this._errorListener=r}get type(){return Me.TABLE}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.table.get(this._id)}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const a=s.cell||[],l=a[n]||[];l[r]=e,a[n]=l,s.cell=a}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r,ge(n,["text_color"]))}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const a=s.cell;if(a)for(let l=e;l<=n;l++)for(let c=t;c<=r;c++){const h=a[l];h&&(h[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){this._errorListener.addError(se.mergeCellErr,s,Pt.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const l=a.merge_cells||[];l.push({start_column:t,start_row:e,end_column:r,end_row:n}),a.merge_cells=l}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t,ge(e,["bgcolor"]))}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t,ge(e,["border_color"]))}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t},e){const r=this._variables.table.get(this._id);r&&(r.position=t,this._paramVerfiy(t,e,"table.set_position",Object.values(gr),"position"))}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class my{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_time}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===ce.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class gy{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===ce.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class vy{constructor(t,e){$(this,"_strategy");$(this,"_errorListener");this._strategy=t,this._errorListener=e}allow_entry_in({value:t},e){this._paramVerfiy(t,e,"strategy.risk.allow_entry_in",Object.values(ce),"value"),this._strategy.updateRisk({allow_entry_in:t})}max_cons_loss_days({count:t}){this._strategy.updateRisk({max_cons_loss_days:t})}max_drawdown({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_drawdown",[Pe.percentOfEquity,Pe.cash],"type"),e===Pe.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_drawdown:t,max_drawdown_type:e})}max_intraday_filled_orders({count:t}){this._strategy.updateRisk({max_intraday_filled_orders:t})}max_intraday_loss({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_intraday_loss",[Pe.percentOfEquity,Pe.cash],"type"),e===Pe.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_intraday_loss:t,max_intraday_loss_type:e})}max_position_size({contracts:t}){this._strategy.updateRisk({max_position_size:t})}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}}var wy=20,yy=1,ei=1e6,vh=1e6,Dy=-7,by=21,xy=!1,us="[big.js] ",ri=us+"Invalid ",yo=ri+"decimal places",Ey=ri+"rounding mode",wh=us+"Division by zero",ae={},sn=void 0,Ay=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function yh(){function i(t){var e=this;if(!(e instanceof i))return t===sn?yh():new i(t);if(t instanceof i)e.s=t.s,e.e=t.e,e.c=t.c.slice();else{if(typeof t!="string"){if(i.strict===!0&&typeof t!="bigint")throw TypeError(ri+"value");t=t===0&&1/t<0?"-0":String(t)}Cy(e,t)}e.constructor=i}return i.prototype=ae,i.DP=wy,i.RM=yy,i.NE=Dy,i.PE=by,i.strict=xy,i.roundDown=0,i.roundHalfUp=1,i.roundHalfEven=2,i.roundUp=3,i}function Cy(i,t){var e,r,n;if(!Ay.test(t))throw Error(ri+"number");for(i.s=t.charAt(0)=="-"?(t=t.slice(1),-1):1,(e=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(e<0&&(e=r),e+=+t.slice(r+1),t=t.substring(0,r)):e<0&&(e=t.length),n=t.length,r=0;r<n&&t.charAt(r)=="0";)++r;if(r==n)i.c=[i.e=0];else{for(;n>0&&t.charAt(--n)=="0";);for(i.e=e-r-1,i.c=[],e=0;r<=n;)i.c[e++]=+t.charAt(r++)}return i}function ni(i,t,e,r){var n=i.c;if(e===sn&&(e=i.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(Ey);if(t<1)r=e===3&&(r||!!n[0])||t===0&&(e===1&&n[0]>=5||e===2&&(n[0]>5||n[0]===5&&(r||n[1]!==sn))),n.length=1,r?(i.e=i.e-t+1,n[0]=1):n[0]=i.e=0;else if(t<n.length){if(r=e===1&&n[t]>=5||e===2&&(n[t]>5||n[t]===5&&(r||n[t+1]!==sn||n[t-1]&1))||e===3&&(r||!!n[0]),n.length=t,r){for(;++n[--t]>9;)if(n[t]=0,t===0){++i.e,n.unshift(1);break}}for(t=n.length;!n[--t];)n.pop()}return i}function ii(i,t,e){var r=i.e,n=i.c.join(""),s=n.length;if(t)n=n.charAt(0)+(s>1?"."+n.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)n="0"+n;n="0."+n}else if(r>0)if(++r>s)for(r-=s;r--;)n+="0";else r<s&&(n=n.slice(0,r)+"."+n.slice(r));else s>1&&(n=n.charAt(0)+"."+n.slice(1));return i.s<0&&e?"-"+n:n}ae.abs=function(){var i=new this.constructor(this);return i.s=1,i},ae.cmp=function(i){var t,e=this,r=e.c,n=(i=new e.constructor(i)).c,s=e.s,a=i.s,l=e.e,c=i.e;if(!r[0]||!n[0])return r[0]?s:n[0]?-a:0;if(s!=a)return s;if(t=s<0,l!=c)return l>c^t?1:-1;for(a=(l=r.length)<(c=n.length)?l:c,s=-1;++s<a;)if(r[s]!=n[s])return r[s]>n[s]^t?1:-1;return l==c?0:l>c^t?1:-1},ae.div=function(i){var t=this,e=t.constructor,r=t.c,n=(i=new e(i)).c,s=t.s==i.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>ei)throw Error(yo);if(!n[0])throw Error(wh);if(!r[0])return i.s=s,i.c=[i.e=0],i;var l,c,h,d,f,p=n.slice(),g=l=n.length,w=r.length,m=r.slice(0,l),y=m.length,v=i,x=v.c=[],b=0,M=a+(v.e=t.e-i.e)+1;for(v.s=s,s=M<0?0:M,p.unshift(0);y++<l;)m.push(0);do{for(h=0;h<10;h++){if(l!=(y=m.length))d=l>y?1:-1;else for(f=-1,d=0;++f<l;)if(n[f]!=m[f]){d=n[f]>m[f]?1:-1;break}if(d<0){for(c=y==l?n:p;y;){if(m[--y]<c[y]){for(f=y;f&&!m[--f];)m[f]=9;--m[f],m[y]+=10}m[y]-=c[y]}for(;!m[0];)m.shift()}else break}x[b++]=d?h:++h,m[0]&&d?m[y]=r[g]||0:m=[r[g]]}while((g++<w||m[0]!==sn)&&s--);return!x[0]&&b!=1&&(x.shift(),v.e--,M--),b>M&&ni(v,M,e.RM,m[0]!==sn),v},ae.eq=function(i){return this.cmp(i)===0},ae.gt=function(i){return this.cmp(i)>0},ae.gte=function(i){return this.cmp(i)>-1},ae.lt=function(i){return this.cmp(i)<0},ae.lte=function(i){return this.cmp(i)<1},ae.minus=ae.sub=function(i){var t,e,r,n,s=this,a=s.constructor,l=s.s,c=(i=new a(i)).s;if(l!=c)return i.s=-c,s.plus(i);var h=s.c.slice(),d=s.e,f=i.c,p=i.e;if(!h[0]||!f[0])return f[0]?i.s=-c:h[0]?i=new a(s):i.s=1,i;if(l=d-p){for((n=l<0)?(l=-l,r=h):(p=d,r=f),r.reverse(),c=l;c--;)r.push(0);r.reverse()}else for(e=((n=h.length<f.length)?h:f).length,l=c=0;c<e;c++)if(h[c]!=f[c]){n=h[c]<f[c];break}if(n&&(r=h,h=f,f=r,i.s=-i.s),(c=(e=f.length)-(t=h.length))>0)for(;c--;)h[t++]=0;for(c=t;e>l;){if(h[--e]<f[e]){for(t=e;t&&!h[--t];)h[t]=9;--h[t],h[e]+=10}h[e]-=f[e]}for(;h[--c]===0;)h.pop();for(;h[0]===0;)h.shift(),--p;return h[0]||(i.s=1,h=[p=0]),i.c=h,i.e=p,i},ae.mod=function(i){var t,e=this,r=e.constructor,n=e.s,s=(i=new r(i)).s;if(!i.c[0])throw Error(wh);return e.s=i.s=1,t=i.cmp(e)==1,e.s=n,i.s=s,t?new r(e):(n=r.DP,s=r.RM,r.DP=r.RM=0,e=e.div(i),r.DP=n,r.RM=s,this.minus(e.times(i)))},ae.neg=function(){var i=new this.constructor(this);return i.s=-i.s,i},ae.plus=ae.add=function(i){var t,e,r,n=this,s=n.constructor;if(i=new s(i),n.s!=i.s)return i.s=-i.s,n.minus(i);var a=n.e,l=n.c,c=i.e,h=i.c;if(!l[0]||!h[0])return h[0]||(l[0]?i=new s(n):i.s=n.s),i;if(l=l.slice(),t=a-c){for(t>0?(c=a,r=h):(t=-t,r=l),r.reverse();t--;)r.push(0);r.reverse()}for(l.length-h.length<0&&(r=h,h=l,l=r),t=h.length,e=0;t;l[t]%=10)e=(l[--t]=l[t]+h[t]+e)/10|0;for(e&&(l.unshift(e),++c),t=l.length;l[--t]===0;)l.pop();return i.c=l,i.e=c,i},ae.pow=function(i){var t=this,e=new t.constructor("1"),r=e,n=i<0;if(i!==~~i||i<-vh||i>vh)throw Error(ri+"exponent");for(n&&(i=-i);i&1&&(r=r.times(t)),i>>=1,!!i;)t=t.times(t);return n?e.div(r):r},ae.prec=function(i,t){if(i!==~~i||i<1||i>ei)throw Error(ri+"precision");return ni(new this.constructor(this),i,t)},ae.round=function(i,t){if(i===sn)i=0;else if(i!==~~i||i<-ei||i>ei)throw Error(yo);return ni(new this.constructor(this),i+this.e+1,t)},ae.sqrt=function(){var i,t,e,r=this,n=r.constructor,s=r.s,a=r.e,l=new n("0.5");if(!r.c[0])return new n(r);if(s<0)throw Error(us+"No square root");s=Math.sqrt(+ii(r,!0,!0)),s===0||s===1/0?(t=r.c.join(""),t.length+a&1||(t+="0"),s=Math.sqrt(t),a=((a+1)/2|0)-(a<0||a&1),i=new n((s==1/0?"5e":(s=s.toExponential()).slice(0,s.indexOf("e")+1))+a)):i=new n(s+""),a=i.e+(n.DP+=4);do e=i,i=l.times(e.plus(r.div(e)));while(e.c.slice(0,a).join("")!==i.c.slice(0,a).join(""));return ni(i,(n.DP-=4)+i.e+1,n.RM)},ae.times=ae.mul=function(i){var t,e=this,r=e.constructor,n=e.c,s=(i=new r(i)).c,a=n.length,l=s.length,c=e.e,h=i.e;if(i.s=e.s==i.s?1:-1,!n[0]||!s[0])return i.c=[i.e=0],i;for(i.e=c+h,a<l&&(t=n,n=s,s=t,h=a,a=l,l=h),t=new Array(h=a+l);h--;)t[h]=0;for(c=l;c--;){for(l=0,h=a+c;h>c;)l=t[h]+s[c]*n[h-c-1]+l,t[h--]=l%10,l=l/10|0;t[h]=l}for(l?++i.e:t.shift(),c=t.length;!t[--c];)t.pop();return i.c=t,i},ae.toExponential=function(i,t){var e=this,r=e.c[0];if(i!==sn){if(i!==~~i||i<0||i>ei)throw Error(yo);for(e=ni(new e.constructor(e),++i,t);e.c.length<i;)e.c.push(0)}return ii(e,!0,!!r)},ae.toFixed=function(i,t){var e=this,r=e.c[0];if(i!==sn){if(i!==~~i||i<0||i>ei)throw Error(yo);for(e=ni(new e.constructor(e),i+e.e+1,t),i=i+e.e+1;e.c.length<i;)e.c.push(0)}return ii(e,!1,!!r)},ae[Symbol.for("nodejs.util.inspect.custom")]=ae.toJSON=ae.toString=function(){var i=this,t=i.constructor;return ii(i,i.e<=t.NE||i.e>=t.PE,!!i.c[0])},ae.toNumber=function(){var i=+ii(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(i.toString()))throw Error(us+"Imprecise conversion");return i},ae.toPrecision=function(i,t){var e=this,r=e.constructor,n=e.c[0];if(i!==sn){if(i!==~~i||i<1||i>ei)throw Error(ri+"precision");for(e=ni(new r(e),i,t);e.c.length<i;)e.c.push(0)}return ii(e,i<=e.e||e.e<=r.NE||e.e>=r.PE,!!n)},ae.valueOf=function(){var i=this,t=i.constructor;if(t.strict===!0)throw Error(us+"valueOf disallowed");return ii(i,i.e<=t.NE||i.e>=t.PE,!0)};var tu=yh();function Dh(i,t){return tu(i).plus(t).toNumber()}function Do(i,t){return tu(i).minus(t).toNumber()}function Ii(i,t){return tu(i).mul(t).toNumber()}let Fy=class{constructor(t,e,r,n,s){$(this,"_variables");$(this,"_options");$(this,"_totalChangeCapital");$(this,"_historyOrder");$(this,"_orders");$(this,"_exitOrders");$(this,"_pendingOrders");$(this,"_mintick");$(this,"_funcOptions");$(this,"_pendingCloseOrders");$(this,"_errorListener");$(this,"_risk");$(this,"_opentrades");$(this,"_closedtrades");$(this,"_riskNamespace");$(this,"_updateOptions",{});$(this,"_id");$(this,"_maxDrawdownVerifyIndex",0);$(this,"calcOnOrderFillsData",{index:-1});this._variables=t,this._errorListener=n,this._options={overlay:!1,format:Kt.inherit,pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Pe.fixed,default_qty_value:1,initial_capital:1e6,currency:dh.NONE,slippage:0,commission_type:je.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=e,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._exitOrders=[],this._pendingCloseOrders=[],this._mintick=r,this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),this._variables.strategy.updateStrategyOptions(this._options),this._risk={intradayOrders:0},this._opentrades=new gy(this),this._closedtrades=new my(this),this._riskNamespace=new vy(this,n),this._id=`strategy_${s}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:t}=this.calcOnOrderFillsData.data||this._variables;return this._orders.reduce((e,r)=>e+t*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}get isCalcOnEveryTick(){return this._options.calc_on_every_tick}updateOptions(t){this._updateOptions=t||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),this._exitOrdersHandle(),this._maxDrawdownVerify();const{open:t,close:e,high:r,low:n}=this.calcOnOrderFillsData.data||this._variables;this._variables.strategy.update({open:t,close:e,high:r,low:n}),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}calcCurrentOrder(){this._calcProfitAndLoss()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:t,max_intraday_loss_type:e,isDisabledOpen:r}=this._risk;if(t===void 0||!e||r)return;const{time_tradingday:n,time:s,strategy:{netprofit:a,initial_capital:l}}=this._variables,{high:c,low:h}=this.calcOnOrderFillsData.data||this._variables;let{preNetprofit:d=0}=this._risk;s===n&&(d=a,this._risk.preNetprofit=a,this._risk.isTemporaryBan=!1);let f=d-a;f+=this._orders.reduce((w,m)=>{const{in_price:y,direction:v,qty:x=0,commission:b=0,original_qty:M=0}=m,E=v===ce.long?1:-1,C=(c-y)*x,N=(h-y)*x,S=E===1?N:-C;return w+S+x/M*b},0);let p=!1;switch(e){case Pe.cash:p=t<f;break;case Pe.percentOfEquity:const w=f/(l+a)*100;p=t<w;break}if(p){this._risk.isTemporaryBan=!0;const w=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,w===ce.long?h:c,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:t,intradayOrders:e=0,isDisabledOpen:r}=this._risk;if(t===void 0||r)return;const{time:n,time_tradingday:s}=this._variables,{open:a}=this.calcOnOrderFillsData.data||this._variables;n===s&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),t<=e&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:t,lossDays:e=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(t===void 0||r)return;const{time:s,time_tradingday:a,strategy:l}=this._variables,{open:c}=this.calcOnOrderFillsData.data||this._variables;let h=e;if(s===a){const d=l.netprofit+l.openprofit;d<n?h=0:h++,Object.assign(this._risk,{lossDays:h,totalProfit:d})}t<=h&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:n}=this._variables,{open:s}=this.calcOnOrderFillsData.data||this._variables;if(t!==void 0&&e&&this._maxDrawdownVerifyIndex===n){const{initial_capital:a}=this._options,c=this._orders.reduce((d,f)=>{const{in_price:p,commission:g=0,qty:w=0,original_qty:m=0,direction:y}=f,v=y===ce.long?1:-1,x=(s-p)*v*w;return d+x+g*w/m},0)+this._totalChangeCapital;let h=!1;switch(e){case Pe.percentOfEquity:h=c/a*100<=-t;break;case Pe.cash:h=c<=-t;break}h&&this._riskTouchOff(s,"Close Position (Max Drawdown)")}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,t,e,"close"),this._pendingOrders=[]}strategy(t,e){if(!this._variables.bar_index){this._paramVerfiy(t.format,e,"strategy",[Kt.inherit,Kt.price,Kt.percent,Kt.volume],"format"),this._paramVerfiy(t.default_qty_type,e,"strategy",Object.values(Pe),"default_qty_type"),this._paramVerfiy(t.commission_type,e,"strategy",Object.values(je),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),n={...this._updateOptions};if(r)for(const s of Object.keys({...r,...t}))t[s]!==r[s]&&delete n[s];self==null||self.workerStorage.set(this._id,t),Object.assign(this._options,t,n),this._variables.updateMaxLength(t),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:n,scriptType:"strategy"})}}order(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.order",Object.values(cn),"oca_type"),this._orderHandle(t))}entry(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.entry",Object.values(cn),"oca_type"),this._entryHandle(t))}close(t){if(!this._orders.filter(r=>!this._options.process_orders_on_close||r.in_index!==this._variables.bar_index).length)return;const{immediately:e}=t;if(e||this._options.process_orders_on_close){const r=this._pendingCloseOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingCloseOrders.push({...t,place_order_type:"close"})}else{const r=this._pendingOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingOrders.push({...t,place_order_type:"close"})}}close_all(t){if(typeof t=="string"&&(t={}),!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close_all"}):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>!(e.id===t&&e.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(t,e){this._exit(t,e)}convert_to_account({value:t}){return t}convert_to_symbol({value:t}){return t}default_entry_qty({fill_price:t}){return t?this._calcDefaultQty(t):0}_calcDefaultQty(t){const{default_qty_type:e=Pe.fixed,default_qty_value:r=1,initial_capital:n,commission_value:s}=this._options;let a=r;switch(e){case Pe.cash:a=r/t;break;case Pe.percentOfEquity:const l=this._getOrderProfit(t),c=n+l+this._totalChangeCapital;s?a=this._getCommQty(c,t):a=c*r/100/t;break}return Vl(a,this._getLen(t))}_getCommQty(t,e){const{commission_type:r,commission_value:n=0,default_qty_value:s=0}=this._options;let a=0;switch(r){case je.percent:a=t*s/(100*e+n*e);break;case je.cashPerContract:a=t*s/(100*e+n);break;case je.cashPerOrder:a=(t-n)*s/100/e}return a}_getLen(t){const e=String(Math.floor(t)).length-2;return e<0?0:e}_getCapital(t,e){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&t===1?e=e*100/r:n<=100&&n>0&&t===-1&&(e=e*100/n),e}_calcProfitAndLoss(){const{close:t}=this.calcOnOrderFillsData.data||this._variables;for(const e of this._orders){const{in_price:r,qty:n=0,direction:s}=e,a=s===ce.long?1:-1,l=(t-r)*a*n,[c,h]=this._calcProfitAndLossHandle(r,n,a);this._calcOrderPercent(e,l,c,h)}}_calcProfitAndLossHandle(t,e,r){const{high:n,low:s}=this.calcOnOrderFillsData.data||this._variables,a=(n-t)*e,l=(s-t)*e;let c=r===1?a:-l,h=r===1?l:-a;return[c,h]}_calcOrderPercent(t,e,r,n){const{commission_value:s}=this._options,{close:a}=this.calcOnOrderFillsData.data||this._variables,{original_qty:l=0,qty:c=0,in_price:h,max_profit:d=0,trading_loss:f=0}=t;let{commission:p=0}=t,g=h*c;if(s){const w=this._getCommission(a,c);p=p*c/l,r-=p,n-=p,g+=p,e=e-w-p}r=Math.max(r,d,0),n=Math.min(n,f,0),Object.assign(t,{profit:e,total_profit:this._totalChangeCapital+e,total_profit_percent:e/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:n,profit_percent:e/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{time:t}=this._variables,{high:e,low:r}=this.calcOnOrderFillsData.data||this._variables,{initial_capital:n,margin_long:s=0,margin_short:a=0}=this._options,l=this._orders[0].direction===ce.long?1:-1;let c=l===1?r:e;if(l===1&&s===100)return;const h=(l===1?s:a)/100;if(h<=0)return;let d=!1;const[f,p]=this._orders.reduce((y,v)=>{let[x,b]=y;const{in_price:M,qty:E=0,in_time:C}=v;C===t&&(d=!0);const N=M*E,S=c*E;return x+=N,b+=S,[x,b]},[0,0]);let g=0,w=0;const m=n+this._totalChangeCapital;if(d&&(g=m-f*h,g<0&&(c=this._orders[0].in_price,w=Math.abs(Math.trunc(g/h/c)*4),w=Math.max(w,1))),g>=0){const y=l*(p-f);if(g=m+y-p*h,g>=0)return;w=Math.abs(Math.trunc(g/h/c)*4)}w<=0||this._marginCallOrders(c,w,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r,!0);return}for(const s of this.orders)s.position_close_type=s.place_order_type,this._processOrder(s,t,e,r,r,!0);this._orders=this._orders.filter(s=>!s.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:s,quantities:a,close:l,price:c,activePrice:h,isTouch:d}=this._orderArgsParse(t),f=t.direction===ce.long?1:-1;if(a<=0)return;let p=a;if((s||d)&&e){const w=d?c:l;if(n.length){const E=this._processOrders(n,w,p,t.id,t.comment,!1,"order");if(E<=0)return;p=E}const m=w+f*r*this._mintick;if(!this._judgeCapitalEnough(p,m,f))return;this._ocaGroupVerify(p,t.oca_name,t.oca_type);const{bar_index:v,time:x}=this._variables,{high:b,low:M}=this.calcOnOrderFillsData.data||this._variables;this._calcCurrentOrder({...t,in_price:m,in_high:b,in_low:M,in_index:v,in_time:x,qty:p,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,f)&&this._addPendingOrders(t,c,p,s,h)}_judgeCapitalEnough(t,e,r){let n=this._freezeCapital;if(this._orders.some(d=>(d.direction===ce.long?1:-1)!==r)&&(n=0),t<=0)return!1;const{margin_long:s=0,margin_short:a=0}=this._options;if(s===0&&r===1||a===0&&r===-1)return!0;const l=this._getOrderProfit(e),h=this._getCapital(r,this._options.initial_capital+l+this._totalChangeCapital)-n;return t*e<=h}_getOrderProfit(t){return this._orders.reduce((e,r)=>{const{in_price:n,qty:s=0,direction:a}=r,l=a===ce.long?1:-1;return e+(t-n)*s*l},0)}_ocaGroupVerify(t,e,r){if(!e||!r||r===cn.none)return!1;let n=!1;switch(r){case cn.cancel:this._pendingOrders=this._pendingOrders.filter(s=>{if(s.oca_name===e)s.isCancel=!0,n=!0;else return!0});break;case cn.reduce:this._pendingOrders=this._pendingOrders.filter(s=>{const{qty:a=0,oca_name:l}=s;if(e===l){const c=a-t;return n=!0,c<=0?(s.isCancel=!0,!1):(s.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,s,a=!1,l,c){let h=r;for(const d of t)if(d.position_close_type=l||d.place_order_type,d.immediately=c,h=this._processOrder(d,e,h,n,s,a),h<=0)break;return this._orders=this._orders.filter(d=>!d.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),h}_addPendingOrders(t,e,r,n,s){const a=this._pendingOrders.find(l=>l.id===t.id&&!l.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else{const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let s=t.limit||0;const{close:a}=this.calcOnOrderFillsData.data||this._variables;let l=a,c=!1,h;const d=e===ce.long?1:-1,f=n&&(n-a)*d>=0,{backtest_fill_limits_assumption:p=0}=this._options;p>0&&s&&(s-=p*this._mintick*d);const g=s&&(s-a)*d<=0;let w=!1;f&&g?(n!==a&&(h=n),l=s):f?(l=n,w=n===a):g?(l=s,w=s===a):c=!0;const m=r!==void 0?Vl(r,this._getLen(l)):this._calcDefaultQty(l);return{orders:this._orders.filter(v=>v.direction!==e),isMarketPrice:c,activePrice:h,quantities:m,close:a,price:l,isTouch:w}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:s,close:a,price:l,activePrice:c,isTouch:h}=this._orderArgsParse(t);if(s<=0)return;if((n||h)&&e){this._entryOrder(r,h?l:a,s,t);return}this._judgeCapitalEnough(s,a,t.direction===ce.long?1:-1)&&this._addPendingEntry(t,l,s,n,c)}_entryOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{high:l,low:c}=this.calcOnOrderFillsData.data||this._variables,{slippage:h=0}=this._options,{oca_name:d,oca_type:f,direction:p,comment:g,id:w}=n,m=p===ce.long?1:-1;if(r=this._getAvailablePositionSize(r,p),r<=0||(e=e+h*this._mintick*m,!this._judgeCapitalEnough(r,e,m)))return;this._closeOrders(t,e,w,g,"entry");const v={...n,in_price:e,qty:r,in_index:a,in_high:l,in_low:c,in_time:s,place_order_type:"entry"},{orders:x}=this._getEntryOrders(p),b=x.length;b&&b>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,d,f),this._calcCurrentOrder(v))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==ce.all&&n!==e)return 0;if(r===void 0)return t;const s=this._orders.reduce((a,l)=>a+(l.qty||0),0);return s?s+t>r?0:t:t>r?t-r:0}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===t),r=this._orders.filter(n=>n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,s){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(t.direction),c=a.length+l.length,h=a.find(d=>d.id===t.id&&d.place_order_type==="entry");if(h)Object.assign(h,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else if(!c||c<(this._options.pyramiding||1)){const d={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"entry"};this._pendingOrders.push(d)}}_closeAllOrders(t,e){const{comment:r,immediately:n}=t,{bar_index:s}=this._variables,a=this._orders.filter(l=>l.in_index!==s);a.length&&(this._closeOrders(a,e,"Close position order",r,"close",n),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n,s,a){for(const l of t)l.position_close_type=s,l.immediately=a,this._closeOrder(l,e,r,n);this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_closeOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{high:l,low:c}=this.calcOnOrderFillsData.data||this._variables,{slippage:h=0}=this._options,{in_price:d,qty:f=0,direction:p}=t,g=p===ce.long?1:-1;e=e-g*h*this._mintick,t.isDeal=!0;const w=(e-d)*g*f,m={...t,out_price:e,out_id:r,out_index:a,out_high:l,out_low:c,out_time:s,out_comment:n,out_qty:f,profit:w};this._calcPercent(m)}_exitOrdersHandle(){if(!this._exitOrders.length)return;const{open:t,low:e,high:r,close:n}=this.calcOnOrderFillsData.data||this._variables,s=[],a=Math.abs(r-t),l=Math.abs(e-t),c=[];for(const h of this._exitOrders){const{stop:d,limit:f,trail_stop_price:p,directionNum:g,id:w,comment:m,active_price:y,trail_offset:v=0,qty:x,comment_loss:b,comment_profit:M,comment_trailing:E,order:C}=h;let N=p,S=a<l||a===l&&g===1,T,A=1,O=m;if(f&&((t-f)*g>=0?(T=t,A=1):e<=f&&r>=f&&(T=f,S&&f>t||!S&&f<t?A=1:A=2),O=M||m),d&&!(N&&(d-N)*g<0)&&((t-d)*g<=0?(T=t,A=1):e<=d&&r>=d&&(T=d,S&&d>t||!S&&d<t?A=1:A=2),O=b||m),T){s.push({order:C,price:T,index:A,isHighFront:S,exitInfo:{id:w,comment:O,qty:x}});continue}if(T=void 0,N)if((N-t)*g>=0)T=t,A=1;else{const[L,q,U]=this._calcTrailStopPrice(N,r,e,n,v,g,S);T=q,A=U||1,h.trail_stop_price=L}if(y&&!T&&y<=r&&y>=e)if(v===0)T=y,S&&y>t||!S&&y<t?A=1:A=2;else{N=Do(y,Ii(v*g,this._mintick));let L=r,q=e;S?y>=t&&y<=r?(L=r,A=1):(S=!1,L=n,A=2):y<t&&y>=e?(q=e,A=1):(S=!0,q=n,A=2);const[U,W,z=1]=this._calcTrailStopPrice(N,L,q,n,v,g,S);delete h.active_price,A<z&&(A=z),h.trail_stop_price=U,T=W}if(T){s.push({order:C,price:T,index:A,isHighFront:S,exitInfo:{id:w,comment:E||m,qty:x}});continue}c.push(h)}this._exitOrders=c,s.sort(({price:h,index:d,isHighFront:f},{price:p,index:g})=>d!==g?d-g:f?d===1?h-p:p-h:d===1?p-h:h-p);for(const h of s){const{order:d,price:f,exitInfo:p}=h;this._processExitOnClose(d,f,p)}}_ordersHandle(){const t=this._orders.filter(r=>r.isMarketPriceLimit||r.isMarketPriceStop);if(!t.length)return;const{open:e}=this.calcOnOrderFillsData.data||this._variables;for(const r of t){const{out_comment:n,out_qty:s,out_id:a}=r;this._processExitOnClose(r,e,{id:a,comment:n,qty:s})}}_calcTrailStopPrice(t,e,r,n,s,a,l){let c=t,h;const d=Do(a===1?e:r,Ii(s*a,this._mintick));let f=1;return a===1?l?(c<d&&(c=d),c>=r&&(f=2,h=c)):c>=r?(f=1,h=c):d>c&&(c=d,d>=n&&(f=3,h=d)):l?c<=e?(f=1,h=c):d<c&&(c=d,d<=n&&(f=3,h=d)):(d<c&&(c=d),c<=e&&(f=2,h=c)),[c,h,f]}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=this._pendingOrders.filter(r=>r.place_order_type==="exit");for(const r of this._pendingOrders){const{isCancel:n,place_order_type:s}=r;if(n)continue;let a;switch(s){case"entry":a=this._entryOrderHandle(r);break;case"order":a=this._orderOrderHandle(r);break;case"close":a=this._closeOrderHandle(r);break;case"close_all":const{open:l}=this.calcOnOrderFillsData.data||this._variables;this._closeAllOrders(r,l);break}a&&t.push(a)}for(const r of e){const n=this._exitOrderHandle(r);n&&t.push(n)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(r=>["close","close_all"].includes(r.place_order_type||"")),{close:e}=this.calcOnOrderFillsData.data||this._variables;this._pendingCloseOrders=[];for(const r of t)switch(r.place_order_type){case"close":const n=this._closeOrderHandle(r,!0);n&&this._pendingCloseOrders.push(n);break;case"close_all":this._closeAllOrders(r,e);break}this._ordersHandle()}_entryOrderHandle(t){const{open:e,low:r,high:n}=this.calcOnOrderFillsData.data||this._variables,{isMarketPrice:s,qty:a=0,in_price:l,direction:c,active_price:h}=t;if(h&&n>=h&&r<=h)return delete t.active_price,t;let d=l;if(s&&(d=e),d<=n&&d>=r){const f=this._orders.filter(p=>p.direction!==c);this._entryOrder(f,d,a,t)}else return t}_orderOrderHandle(t){const{time:e,bar_index:r}=this._variables,{open:n,low:s,high:a}=this.calcOnOrderFillsData.data||this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:h=0,in_price:d,direction:f,comment:p,oca_name:g,oca_type:w,active_price:m,id:y}=t;if(m&&a>=m&&s<=m)return delete t.active_price,t;let v=d,x=h;if(c&&(v=n),v<=a&&v>=s){const b=this._orders.filter(E=>E.direction!==f);if(b.length&&(x=this._processOrders(b,v,h,y,p,!1,"order"),x<=0))return;const M=f===ce.long?1:-1;this._ocaGroupVerify(x,g,w),this._calcCurrentOrder({...t,in_price:v+M*l*this._mintick,in_index:r,in_time:e,in_high:a,in_low:s,qty:x});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:s=100,comment:a,immediately:l}=t,{close_entries_rule:c="FIFO"}=this._options;let h=[];if(c==="FIFO"?h=this._orders.filter(g=>g.id===r):h=this._orders.filter(g=>g.id===r&&!g.close_qty),!h.length)return;let d=0;if(n?d=n:(d=h.reduce((g,w)=>g+(w.qty||0),d),d=s/100*d),d<=0)return;const{open:f,close:p}=this.calcOnOrderFillsData.data||this._variables;if(c==="FIFO")this._processOrders(h,e?p:f,d,`Close entry(s) order ${r}`,a,!1,"close",l);else if(this._processCloseOrders(h,e?p:f,d,`Close entry(s) order ${r}`,a,l))return t}_processCloseOrders(t,e,r,n,s,a){let l=!1;for(const c of t)c.close_qty=r,(c.qty||0)>r&&(l=!0),c.immediately=a,c.position_close_type="close",this._processOrder(c,e,r,n,s);return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),l}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,t,!0)))return t}_exit(t,e){if(!t.hasOwnProperty("profit")&&!t.hasOwnProperty("loss")&&!t.hasOwnProperty("stop")&&!t.hasOwnProperty("limit")&&(!t.hasOwnProperty("trail_offset")||!t.hasOwnProperty("trail_price")&&!t.hasOwnProperty("trail_points"))){this._errorListener.addError(se.strategyExitErr,e,Pt.Error);return}const{profit:r,loss:n,stop:s,limit:a,trail_offset:l,trail_price:c,trail_points:h,from_entry:d="",id:f}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(s)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(h)&&this._isNaN(c)))return;const p={...t,place_order_type:"exit"},g=this._orders.filter(y=>(!d||d===y.id)&&!y.hasExit);this._updateExitOrders(p);const w=this._pendingOrders.filter(y=>!d||d===y.id);if(g.length){if(!this._ordersToExit(g,p,!1))return}else if(!w.length)return;const m=this._pendingOrders.find(y=>y.id===f&&y.place_order_type==="exit");m?Object.assign(m,{...t}):this._pendingOrders.push(p)}_updateExitOrders(t){const e=this._exitOrders.filter(r=>r.id===t.id&&(r.from_entry===t.from_entry||!t.from_entry));for(const r of e){const{directionNum:n,order:s}=r,a={...t};if(this._stopProfit(s,n,a)){r.isClose=!0;continue}if(this._stopLoss(s,n,a)){r.isClose=!0;continue}if(this._trailStopLoss(s,n,a)){r.isClose=!0;continue}Object.assign(r,a)}this._exitOrders=this._exitOrders.filter(r=>!r.isClose)}_ordersToExit(t,e,r){const{qty:n,qty_percent:s=100,id:a,comment:l}=e;let c=n,h=!1;e.comment=l||a;const d=t[0],f={...e},{qty:p=0}=d,g=d.direction===ce.long?1:-1;return c=n?n>=p?p:n:s/100*p,f.qty=c,c<p&&(h=!0),this._stopProfit(d,g,f,r)||this._stopLoss(d,g,f,r)||this._trailStopLoss(d,g,f,r)||(this._exitOrders.push({...f,directionNum:g,order:d}),d.hasExit=!0),h}_addExitPendingCloseOrders(t){const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r,n){const{limit:s,profit:a,comment_profit:l,comment:c,id:h}=r;let d=s;const{close:f}=this.calcOnOrderFillsData.data||this._variables,{in_price:p}=t,{process_orders_on_close:g}=this._options;if(!this._isNaN(a)&&this._isNaN(s)&&(d=Dh(p,Ii(a*e,this._mintick))),r.limit=e===1?Zl(d,this._variables.precision):Kl(d,this._variables.precision),!n&&d!==void 0&&(d-f)*e<=0)return t.isMarketPriceLimit=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment,out_id:h}),g&&this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r,n){const{stop:s,loss:a,comment_loss:l,comment:c,id:h}=r;let d=s;const{close:f}=this.calcOnOrderFillsData.data||this._variables,{in_price:p}=t,{process_orders_on_close:g}=this._options;if(!this._isNaN(a)&&this._isNaN(s)&&(d=Do(p,Ii(a*e,this._mintick))),r.stop=e===1?Kl(d,this._variables.precision):Zl(d,this._variables.precision),!n&&d!==void 0&&(d-f)*e>=0)return t.isMarketPriceStop=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment,out_id:h}),g&&this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r,n){const{trail_offset:s,trail_price:a,trail_points:l,comment_trailing:c,comment:h,id:d}=r;if(!this._isNaN(s)){const{close:f}=this.calcOnOrderFillsData.data||this._variables,{in_price:p}=t,{process_orders_on_close:g}=this._options;let w;if(this._isNaN(a)?this._isNaN(l)||(w=Dh(p,Ii(l*e,this._mintick))):w=a,r.active_price=w,n)return;if(w!==void 0&&(w-f)*e<=0){const m=Do(f,Ii(s*e,this._mintick));if((m-f)*e>=0)return t.isMarketPriceStop=!0,r.comment=c||h,Object.assign(t,{out_comment:r.comment,out_id:d}),g&&this._addExitPendingCloseOrders(r),!0;r.trail_stop_price=m}}}_processExitOnClose(t,e,r){const{qty:n=0,comment:s,id:a}=r,{close_entries_rule:l="FIFO"}=this._options;if(l==="FIFO")this._processExitOrders(this._orders,e,n,a,s);else{if(t.isDeal)return;this._processOrders([t],e,n,a,s,!1,"exit")}}_processExitOrders(t,e,r,n,s){let a=r,l;for(const c of t)if(l=c,c.position_close_type="exit",a=this._processOrder(c,e,a,n,s),a<=0)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),l}_processOrder(t,e,r,n,s,a=!1){const{time:l,bar_index:c}=this._variables,{low:h,high:d}=this.calcOnOrderFillsData.data||this._variables,{slippage:f=0}=this._options,{in_price:p,qty:g=0,max_profit:w,trading_loss:m,direction:y,commission:v=0,original_qty:x=0}=t,b=y===ce.long?1:-1;if(e=e-b*f*this._mintick,r<g){const M=g-r,E=(e-p)*b*r,C=w!==void 0?w/g*r:void 0,N=m!==void 0?m/g*r:void 0,S=v*M/x;this._calcPercent({...t,out_price:e,last_commission:S,out_id:n,out_index:c,out_high:d,out_low:h,out_time:l,out_comment:s,profit:E,out_qty:r,max_profit:C,trading_loss:N});const T=(e-p)*b*M-S;Object.assign(t,{qty:M,profit:T,max_profit:w!==void 0?w-(C||0):void 0,trading_loss:m!==void 0?m-(N||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{t.isDeal=!0;const M=(e-p)*b*g;this._calcPercent({...t,out_price:e,out_id:n,out_index:c,out_high:d,out_low:h,out_time:l,out_comment:s,out_qty:g,profit:M}),r-=g}return a&&(b===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(t){const{commission_value:e,process_orders_on_close:r}=this._options,{in_price:n,out_qty:s=0,out_price:a=0,original_qty:l=0,direction:c,last_commission:h=0,immediately:d}=t;let{profit:f=0,max_profit:p,trading_loss:g,commission:w=0}=t,m=n*s,y=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=f,e){const v=this._getCommission(a,s);this._totalChangeCapital-=v;let x=w*s/l;m+=x,x+=v,f=f-x,Object.assign(t,{commission:x,profit:f});const b=this._orders.reduce((M,E)=>{const{qty:C=0,original_qty:N=0,commission:S=0}=E;return M+S*C/N},0);y+=b-h}if(p===void 0||g===void 0){const v=c===ce.long?1:-1,x=this._calcProfitAndLossHandle(n,s,v);if(p=x[0],g=x[1],e){const b=w*s/l;p-=b,g-=b}p=Math.max(0,p),g=Math.min(0,g)}Object.assign(t,{max_profit:p,trading_loss:g,total_profit:this._totalChangeCapital,total_profit_percent:f/y*100,profit_percent:f/m*100,max_profit_percent:p/m*100,trading_loss_percent:g/m*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(r?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(t),this._calcOrderFillsHandle(n,c,d)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case je.percent:a=s*r/100;break;case je.cashPerContract:a=e*r;break;case je.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:s=0,trading_loss:a=0,direction:l,immediately:c}=t;let{profit:h=0}=t,d=r*n;const f=this._totalChangeCapital+this._options.initial_capital;if(e){const p=this._getCommission(r,n);this._totalChangeCapital-=p,h=h-p,d+=p,Object.assign(t,{commission:p,profit:h,total_profit:this._totalChangeCapital})}Object.assign(t,{original_qty:n,total_profit_percent:h/f*100,profit_percent:h/d*100,max_profit_percent:s/d*100,trading_loss_percent:a/d*100,stop:void 0,limit:void 0}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders),e&&this._variables.strategy.updateHistoryOrders(this._historyOrder),this._calcOrderFillsHandle(r,l,c)}_calcOrderFillsHandle(t,e,r=!1){const{calc_on_order_fills:n,process_orders_on_close:s,slippage:a=0}=this._options;if(n){const{open:l,high:c,low:h,close:d}=this._variables,f=e===ce.long?1:-1,p=d-f*a*this._mintick;if((r||s)&&t===p)return;const g=l-f*a*this._mintick;let w={open:l,high:c,low:h,close:d},m=this.calcOnOrderFillsData.index;const y=Math.abs(c-l)<=Math.abs(h-l);switch(m){case-1:t===g?m=0:t>g?y?(m=1,w={open:c,high:c,low:h,close:d}):(m=2,w={open:c,high:c,low:d,close:d}):y?(m=2,w={open:h,high:d,low:h,close:d}):(m=1,w={open:h,high:c,low:h,close:d});break;case 0:t===g?(m=1,y?w={open:c,high:c,low:h,close:d}:w={open:h,high:c,low:h,close:d}):t>g?y?(m=1,w={open:c,high:c,low:h,close:d}):(m=2,w={open:c,high:c,low:d,close:d}):y?(m=2,w={open:h,high:d,low:h,close:d}):(m=1,w={open:h,high:c,low:h,close:d});break;case 1:m=2,y?w={open:h,high:d,low:h,close:d}:w={open:c,high:c,low:d,close:d};break;case 2:m=-1,w=void 0;break}this.calcOnOrderFillsData={tradeData:w,index:m}}}_isNaN(t){return t===void 0||isNaN(t)}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}};var bh={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){return function(e,r,n){r.prototype.isBetween=function(s,a,l,c){var h=n(s),d=n(a),f=(c=c||"()")[0]==="(",p=c[1]===")";return(f?this.isAfter(h,l):!this.isBefore(h,l))&&(p?this.isBefore(d,l):!this.isAfter(d,l))||(f?this.isBefore(h,l):!this.isAfter(h,l))&&(p?this.isAfter(d,l):!this.isBefore(d,l))}}})})(bh);var My=bh.exports,Ny=Gt(My),xh={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){return function(e,r,n){var s=r.prototype,a=function(p){var g,w=p.date,m=p.utc,y={};if(!((g=w)===null||g instanceof Date||g instanceof Array||s.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var v=m?n.utc():n();Object.keys(w).forEach(function(T){var A,O;y[A=T,O=s.$utils().p(A),O==="date"?"day":O]=w[T]});var x=y.day||(y.year||y.month>=0?1:v.date()),b=y.year||v.year(),M=y.month>=0?y.month:y.year||y.day?0:v.month(),E=y.hour||0,C=y.minute||0,N=y.second||0,S=y.millisecond||0;return m?new Date(Date.UTC(b,M,x,E,C,N,S)):new Date(b,M,x,E,C,N,S)}return w},l=s.parse;s.parse=function(p){p.date=a.bind(this)(p),l.bind(this)(p)};var c=s.set,h=s.add,d=s.subtract,f=function(p,g,w,m){m===void 0&&(m=1);var y=Object.keys(g),v=this;return y.forEach(function(x){v=p.bind(v)(g[x]*m,x)}),v};s.set=function(p,g){return g=g===void 0?p:g,p.constructor.name==="Object"?f.bind(this)(function(w,m){return c.bind(this)(m,w)},g,p):c.bind(this)(p,g)},s.add=function(p,g){return p.constructor.name==="Object"?f.bind(this)(h,p,g):h.bind(this)(p,g)},s.subtract=function(p,g){return p.constructor.name==="Object"?f.bind(this)(h,p,g,-1):d.bind(this)(p,g)}}})})(xh);var Sy=xh.exports,Oy=Gt(Sy),Eh={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){var e,r,n=1e3,s=6e4,a=36e5,l=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,h=31536e6,d=2628e6,f=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,p={years:h,months:d,days:l,hours:a,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},g=function(C){return C instanceof M},w=function(C,N,S){return new M(C,S,N.$l)},m=function(C){return r.p(C)+"s"},y=function(C){return C<0},v=function(C){return y(C)?Math.ceil(C):Math.floor(C)},x=function(C){return Math.abs(C)},b=function(C,N){return C?y(C)?{negative:!0,format:""+x(C)+N}:{negative:!1,format:""+C+N}:{negative:!1,format:""}},M=function(){function C(S,T,A){var O=this;if(this.$d={},this.$l=A,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),T)return w(S*p[m(T)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(U){O.$d[m(U)]=S[U]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(f);if(L){var q=L.slice(2).map(function(U){return U!=null?Number(U):0});return this.$d.years=q[0],this.$d.months=q[1],this.$d.weeks=q[2],this.$d.days=q[3],this.$d.hours=q[4],this.$d.minutes=q[5],this.$d.seconds=q[6],this.calMilliseconds(),this}}return this}var N=C.prototype;return N.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(T,A){return T+(S.$d[A]||0)*p[A]},0)},N.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/h),S%=h,this.$d.months=v(S/d),S%=d,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},N.toISOString=function(){var S=b(this.$d.years,"Y"),T=b(this.$d.months,"M"),A=+this.$d.days||0;this.$d.weeks&&(A+=7*this.$d.weeks);var O=b(A,"D"),L=b(this.$d.hours,"H"),q=b(this.$d.minutes,"M"),U=this.$d.seconds||0;this.$d.milliseconds&&(U+=this.$d.milliseconds/1e3,U=Math.round(1e3*U)/1e3);var W=b(U,"S"),z=S.negative||T.negative||O.negative||L.negative||q.negative||W.negative,K=L.format||q.format||W.format?"T":"",Z=(z?"-":"")+"P"+S.format+T.format+O.format+K+L.format+q.format+W.format;return Z==="P"||Z==="-P"?"P0D":Z},N.toJSON=function(){return this.toISOString()},N.format=function(S){var T=S||"YYYY-MM-DDTHH:mm:ss",A={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return T.replace(c,function(O,L){return L||String(A[O])})},N.as=function(S){return this.$ms/p[m(S)]},N.get=function(S){var T=this.$ms,A=m(S);return A==="milliseconds"?T%=1e3:T=A==="weeks"?v(T/p[A]):this.$d[A],T||0},N.add=function(S,T,A){var O;return O=T?S*p[m(T)]:g(S)?S.$ms:w(S,this).$ms,w(this.$ms+O*(A?-1:1),this)},N.subtract=function(S,T){return this.add(S,T,!0)},N.locale=function(S){var T=this.clone();return T.$l=S,T},N.clone=function(){return w(this.$ms,this)},N.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},N.valueOf=function(){return this.asMilliseconds()},N.milliseconds=function(){return this.get("milliseconds")},N.asMilliseconds=function(){return this.as("milliseconds")},N.seconds=function(){return this.get("seconds")},N.asSeconds=function(){return this.as("seconds")},N.minutes=function(){return this.get("minutes")},N.asMinutes=function(){return this.as("minutes")},N.hours=function(){return this.get("hours")},N.asHours=function(){return this.as("hours")},N.days=function(){return this.get("days")},N.asDays=function(){return this.as("days")},N.weeks=function(){return this.get("weeks")},N.asWeeks=function(){return this.as("weeks")},N.months=function(){return this.get("months")},N.asMonths=function(){return this.as("months")},N.years=function(){return this.get("years")},N.asYears=function(){return this.as("years")},C}(),E=function(C,N,S){return C.add(N.years()*S,"y").add(N.months()*S,"M").add(N.days()*S,"d").add(N.hours()*S,"h").add(N.minutes()*S,"m").add(N.seconds()*S,"s").add(N.milliseconds()*S,"ms")};return function(C,N,S){e=S,r=S().$utils(),S.duration=function(O,L){var q=S.locale();return w(O,{$l:q},L)},S.isDuration=g;var T=N.prototype.add,A=N.prototype.subtract;N.prototype.add=function(O,L){return g(O)?E(this,O,1):T.bind(this)(O,L)},N.prototype.subtract=function(O,L){return g(O)?E(this,O,-1):A.bind(this)(O,L)}}})})(Eh);var By=Eh.exports,Iy=Gt(By);ee.extend(wa),ee.extend(ya),ee.extend(Ny),ee.extend(Oy),ee.extend(Iy);class Ah{constructor(t,e,r){$(this,"array");$(this,"color");$(this,"math");$(this,"str");$(this,"map");$(this,"matrix");$(this,"timeframe");$(this,"ta");$(this,"input");$(this,"_variables");$(this,"_cacheData");$(this,"_options");$(this,"_errorListener");$(this,"_plots");$(this,"_plotshapes");$(this,"_plotbars");$(this,"_plotchars");$(this,"_plotarrows");$(this,"_plotcandles");$(this,"_alerts");$(this,"_bgColors");$(this,"_hlines");$(this,"_fills");$(this,"chart");$(this,"line");$(this,"label");$(this,"polyline");$(this,"box");$(this,"table");$(this,"linefill");$(this,"log");$(this,"runtime");$(this,"strategy");$(this,"request");$(this,"syminfo");$(this,"_count",0);var s;const n=((s=t.toString().split(".")[1])==null?void 0:s.length)||5;this._variables=e,this._errorListener=new Py,this.array=new pp(this._errorListener),this.math=new _p(n,this._errorListener),this.color=new k1,this.str=new qw(this._errorListener,n),this.map=new Uw(this._errorListener),this.timeframe=new kw(e),this.matrix=new zw(this._errorListener),this.ta=new P1(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new z1(e,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new Ww(e)},this.line=new hy(e,this._errorListener),this.label=new jw(e,this._errorListener),this.polyline=new fy(e,this._errorListener),this.box=new py(e,this._errorListener),this.table=new _y(e,this._errorListener),this.linefill=new dy(e),this.log=new Ly(e),this.runtime=new Ry(this._errorListener),this.strategy=new Fy(this._variables,this._options,t,this._errorListener,r),this.request=new Ty(this._variables,r),this.syminfo=new $y}get errors(){return this._errorListener.errors}options(t){if(t.length)return this._getDataOfBarindex(t);const e=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let s;if(n.length){s={};for(const v of n)s[v]=[...this._bgColors[v].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,l=this._fills.size?[...this._fills.values()]:void 0,c=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders,strategySummary:this._variables.strategy.summaryData});const h=this._plots.size>0?[...this._plots.values()]:void 0,d=this._plotbars.size>0?[...this._plotbars.values()]:void 0,f=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,p=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,g=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,w=this._plotchars.size>0?[...this._plotchars.values()]:void 0,m=this._getDraws(),y=this._variables.chart.isUseBgColor;return Object.assign(this._options,{inputs:e,plots:h,draws:m,alerts:r,colors:s,hlines:a,fills:l,logs:c,plotshapes:f,plotarrows:p,plotcandles:g,plotchars:w,plotbars:d,isUseBgColor:y})}_getDataOfBarindex(t){const e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let n;if(r.length){n={};for(const y of r)n[y]=[...this._bgColors[y].values()].map(v=>{const x=[];for(const b of t){const M=v.data[b];M&&x.push(M)}return v.data=x,v})}const s=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(t,[...this._fills.values()]):void 0,l=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._getDataFromBarindex(t,[...this._plots.values()]),h=this._plotbars.size>0?this._getDataFromBarindex(t,[...this._plotbars.values()]):void 0,d=this._plotarrows.size>0?this._getDataFromBarindex(t,[...this._plotarrows.values()]):void 0,f=this._plotcandles.size>0?this._getDataFromBarindex(t,[...this._plotcandles.values()]):void 0,p=this._plotchars.size>0?this._getDataFromBarindex(t,[...this._plotchars.values()]):void 0,g=this._plotshapes.size>0?this._getDataFromBarindex(t,[...this._plotshapes.values()]):void 0,w=this._getDrawsFromBarindex(t),m=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,plotarrows:d,plotcandles:f,plotchars:p,plotbars:h,draws:w,alerts:e,colors:n,hlines:s,fills:a,logs:l,plotshapes:g,isUseBgColor:m})}_getDataFromBarindex(t,e){return e.map(r=>{const n=[];for(const s of t){const a=r.data[s];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:a}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),s.data.length&&(l.polylines=s.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}_getDrawsFromBarindex(t){const{line:e,linefill:r,table:n,box:s,polyline:a,label:l}=this._variables,c={};return e.data.length&&(c.lines=e.getValOfBarIndex(t)),r.data.length&&(c.linefills=r.getValOfBarIndex(t)),n.data.length&&(c.tables=n.getValOfBarIndex(t)),s.data.length&&(c.boxes=s.getValOfBarIndex(t)),a.data.length&&(c.polylines=a.getValOfBarIndex(t)),l.data.length&&(c.labels=l.getValOfBarIndex(t)),Object.keys(c).length?c:void 0}updateOptions(t){const{inputs:e,strategy:r}=t;this.input.update(e),r&&this.strategy.updateOptions(r)}update(t){const{barIndex:e}=t;this.strategy.update(),this.math.update(e)}endExecution(){this.strategy.endExecution()}library(t,e){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=t;r.test(n)?(dp.includes(n)||hp.includes(n))&&this._errorListener.addError(Ze(se.libraryTitleIsKeywordErr,{name:n}),e,Pt.Error):this._errorListener.addError(se.libraryTitleErr,e,Pt.Error),this._options.scriptType="library",this._options.library=t}}indicator(t,e){if(!this._variables.bar_index){const{format:r}=t;this._paramVerfiy(r,e,"indicator",[Kt.inherit,Kt.percent,Kt.price,Kt.volume]),this._variables.updateMaxLength(t),this._options.scriptType="indicator",this._options.indicator=t}}_paramVerfiy(t="",e,r,n,s="format"){t&&!n.includes(t)&&this._errorListener.addError(Ze(se.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Pt.Error)}_lineWidthVerify(t,e){const{linewidth:r=1}=t;r<1&&(this._errorListener.addError(cp.lineWidthWarning,e,Pt.Warning),t.linewidth=1)}plot(t,e){const r=["color"];ge(t,r);const{series:n,color:s,...a}=t,{bar_index:l,time:c}=this._variables,h=`plot_${e}`,d=this._plots.get(h),f=(d==null?void 0:d.data)||[],p=n!==void 0&&isNaN(n)?void 0:n;if(f[l]={value:[c,p],itemStyle:{color:s}},this._seriesColorHandle(t,r,d),!d){this._count++,this._lineWidthVerify(a,e),this._paramVerfiy(t.format,e,"plot",[Kt.percent,Kt.price,Kt.volume]);const g=s?[s]:void 0;this._plots.set(h,{editable:!0,...a,colors:g,data:f,id:h,zIndex:this._count})}return{type:"plot",key:h}}plotbar(t,e){const r=["color"];ge(t,r);const{open:n,close:s,low:a,high:l,color:c,...h}=t,{bar_index:d,time:f}=this._variables,p=`plotbar_${e}`,g=this._plotbars.get(p),w=(g==null?void 0:g.data)||[],m=s!==void 0&&isNaN(s)?void 0:s,y=n!==void 0&&isNaN(n)?void 0:n,v=a!==void 0&&isNaN(a)?void 0:a,x=l!==void 0&&isNaN(l)?void 0:l,b=[f,y,m,v,x];if(w[d]={value:b,itemStyle:{color:c}},this._seriesColorHandle(t,r,g),!g){this._count++,this._paramVerfiy(t.format,e,"plotbar",[Kt.percent,Kt.price,Kt.volume]);const M=c?[c]:void 0;this._plotbars.set(p,{editable:!0,...h,colors:M,data:w,id:p,zIndex:this._count})}}_verfiyArgs(t,e,r){const{size:n,format:s,location:a,style:l}=t;this._paramVerfiy(l,r,e,Object.values(lr),"style"),this._paramVerfiy(a,r,e,Object.values(ln),"location"),this._paramVerfiy(n,r,e,Object.values(ir),"size"),this._paramVerfiy(s,r,e,[Kt.percent,Kt.price,Kt.volume],"format")}plotchar(t,e){const r=["color","textcolor"];ge(t,r);const{series:n,color:s,textcolor:a,location:l=ln.abovebar,...c}=t,{bar_index:h,time:d,high:f,low:p}=this._variables,g=`plotchar_${e}`,w=this._plotchars.get(g),m=(w==null?void 0:w.data)||[],y={value:[d,n],itemStyle:{color:s,textcolor:a},low:p,high:f};m[h]=y,this._seriesColorHandle(t,r,w),w||(this._count++,this._verfiyArgs(t,"plotchar",e),this._plotchars.set(g,{editable:!0,...c,location:l,data:m,id:g,zIndex:this._count}))}plotarrow(t,e){const r=["colorup","colordown"];ge(t,r);const{series:n,colorup:s,colordown:a,...l}=t,{bar_index:c,time:h,low:d,high:f}=this._variables,p=`plotarrow_${e}`,g=this._plotarrows.get(p),w=(g==null?void 0:g.data)||[];w[c]={value:[h,n!==void 0&&isNaN(n)?void 0:n],itemStyle:{colorup:s,colordown:a},low:d,high:f},this._seriesColorHandle(t,r,g),g||(this._count++,this._paramVerfiy(t.format,e,"plotarrow",[Kt.percent,Kt.price,Kt.volume]),this._plotarrows.set(p,{editable:!0,...l,data:w,id:p,zIndex:this._count}))}plotshape(t,e){const r=["color","textcolor"];ge(t,r);const{series:n,color:s,textcolor:a,location:l=ln.abovebar,...c}=t,{bar_index:h,time:d,low:f,high:p}=this._variables,g=`plotshape_${e}`,w=this._plotshapes.get(g),m=(w==null?void 0:w.data)||[],y={value:n,color:s,textcolor:a,time:d,low:f,high:p};if(m[h]=y,this._seriesColorHandle(t,r,w),!w){this._count++;const v=s?[s]:void 0;this._verfiyArgs(t,"plotshape",e),this._plotshapes.set(g,{editable:!0,...c,data:m,location:l,id:g,colors:v,zIndex:this._count})}}plotcandle(t,e){const r=["wickcolor","bordercolor","color"];ge(t,r);const{wickcolor:n,bordercolor:s,color:a,close:l,open:c,low:h,high:d,...f}=t,{bar_index:p,time:g}=this._variables,w=`plotcandle_${e}`,m=this._plotcandles.get(w),y=(m==null?void 0:m.data)||[],v=l!==void 0&&isNaN(l)?void 0:l,x=c!==void 0&&isNaN(c)?void 0:c,b=h!==void 0&&isNaN(h)?void 0:h,M=d!==void 0&&isNaN(d)?void 0:d,E=[g,x,v,b,M];y[p]={value:E,wickcolor:n,bordercolor:s,color:a},this._seriesColorHandle(t,r,m),m||(this._count++,this._paramVerfiy(t.format,e,"plotcandle",[Kt.percent,Kt.price,Kt.volume]),this._plotcandles.set(w,{editable:!0,...f,data:y,id:w,zIndex:this._count}))}hline(t,e){const r=`hline_${e}`;ge(t,["color"]),this._verifyDisplay(t.display,"hline",e);const s=t.display&&!t.display.length?Ke.none:Ke.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(t,e),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:s,...t,zIndex:this._count})),{type:"hline",key:r}}fill(t,e){var S,T,A,O,L,q,U,W,z,K;const r=["color","top_color","bottom_color"];ge(t,r);const{color:n,top_color:s,bottom_color:a,seriesColors:l,hline1:c,hline2:h,plot1:d,plot2:f,top_value:p,bottom_value:g,...w}=t,{bar_index:m,time:y}=this._variables,v=`fill_${e}`,x=this._fills.get(v),b=(x==null?void 0:x.data)||[];this._verifyDisplay(t.display,"fill",e);const M=t.display&&!t.display.length?Ke.none:Ke.all;let E,C,N="plot";if(c&&h)E=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,C=(T=this._hlines.get(h==null?void 0:h.key))==null?void 0:T.price,N="hline";else{const Z=((A=this._plots.get(d==null?void 0:d.key))==null?void 0:A.data)||[],X=((O=this._plots.get(f==null?void 0:f.key))==null?void 0:O.data)||[];E=(q=(L=Z[m])==null?void 0:L.value)==null?void 0:q[1],C=(W=(U=X[m])==null?void 0:U.value)==null?void 0:W[1]}if(b[m]={time:y,color:n,top_color:s,bottom_color:a,plot1:E,plot2:C,top_value:p,bottom_value:g},this._seriesColorHandle(t,r,x),!x){this._count++;const Z=((z=this._options.indicator)==null?void 0:z.explicit_plot_zorder)||((K=this._options.strategy)==null?void 0:K.explicit_plot_zorder),X=n?[n]:void 0,Q=s?[s]:void 0,ct=a?[a]:void 0;this._fills.set(v,{id:v,colors:X,top_colors:Q,bottom_colors:ct,display:M,data:b,type:N,editable:!0,fillgaps:!1,hline1:c,hline2:h,plot1:d,plot2:f,...w,zIndex:Z?this._count:void 0})}}alert({message:t,freq:e=Ur.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l]||{},h=c.barIndex;if(this._paramVerfiy(e,r,"alert",[Ur.freqAll,Ur.freqOncePerBar,Ur.freqOncePerBarClose]),e===Ur.freqOncePerBar&&n===h){this._alerts.delete(l);return}this._cacheData[l]=c;const d={message:t,freq:e,id:l,type:"alert"};if(s){e!==Ur.freqOncePerBarClose&&this._alerts.set(l,d),c.barIndex=n;return}if(!s&&e===Ur.freqOncePerBarClose&&n===h&&a===n-1){this._alerts.set(l,d),c.barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,a=`alertcondition_${n}`;s&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t,e){this._setColors(t,"barcolor",e)}bgcolor(t,e){this._setColors(t,"bgcolor",e)}_verifyDisplay(t=ph.all,e,r){t.length&&t.length<4&&this._errorListener.addError(Ze(se.displayErr,{func:e,values:"[display.none, display.all]"}),r,Pt.Error)}_setColors(t,e,r){ge(t,["color"]);const{color:s,...a}=t;this._verifyDisplay(a.display,e,r);const l=t.display&&!t.display.length?Ke.none:Ke.all,{bar_index:c,time:h}=this._variables,d=`${e}_${r}`;this._bgColors[e]||(this._bgColors[e]=new Map);const f=this._bgColors[e].get(d),p=(f==null?void 0:f.data)||[],g=(f==null?void 0:f.setColors)||[];s&&!g.includes(s)&&g.push(s),p[c]={color:s,time:h},f||this._bgColors[e].set(d,{...a,display:l,data:p,setColors:g,id:d})}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return!!(t===void 0||typeof t=="number"&&isNaN(t))}fixnan({source:t},e){return t===void 0||typeof t=="number"&&isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!(typeof t=="number"&&isNaN(t))?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n,!0)}timestamp(t){const{dateString:e,timezone:r,year:n,month:s,day:a,hour:l=0,minute:c=0,second:h=0}=t;if(e)return ee(e).utc(!/GMT|UTC/.test(e)).valueOf();let d=s-1,f=n;if(d<0){const p=Math.ceil(Math.abs(d/12));d=12*p+d,f=n-p}return mr({year:f,month:d,day:a,hour:l,minute:c,second:h},r).valueOf()}weekofyear({time:t,timezone:e}){return mr(t,e).week()}year({time:t,timezone:e}){return mr(t,e).year()}second({time:t,timezone:e}){return mr(t,e).second()}month({time:t,timezone:e}){return mr(t,e).month()+1}minute({time:t,timezone:e}){return mr(t,e).minute()}hour({time:t,timezone:e}){return mr(t,e).hour()}dayofweek({time:t,timezone:e}){return mr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return mr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,this._variables.timeframe.period),n=tn(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,a=0,l=!1){const c=r||this._variables.timeframe.period,h=tn(c),d=tn(this._variables.timeframe.period);let f;if(h<=d)f=t,l&&(f+=d*1e3);else{const p=`time_${e}`,g=this._cacheData[p];if(g)g.currentTime+h*1e3-g.offset<=t?(f=t,this._cacheData[p]={currentTime:t,offset:0}):f=g.currentTime;else{const w=this._calcTimeOffset(t,c);this._cacheData[p]={currentTime:t,offset:w},f=t}l&&(f+=h*1e3)}if(n){const{timePeriods:p,weeks:g}=this._parserSession(n,e),w=mr(t,s),m=w.format("YYYY-MM-DD HH:mm"),y=w.format("YYYY-MM-DD"),v=f,x=mr(f,s).format("YYYY-MM-DD HH:mm");f=void 0;for(const M of p){const[E,C]=M;let N;if(E===C&&(N=w.add(1,"day").format("YYYY-MM-DD")),ee(m).isBetween(`${y} ${E}`,`${N||y} ${C}`,"hour","[)")){ee(x).isBetween(`${y} ${E}`,`${N||y} ${C}`,"hour","[)")?f=v:f=mr(`${y} ${E}`,s).valueOf();break}}const b=this._variables.dayofweek;f&&!g.includes(b)&&(f=void 0)}return f&&f-a*d*1e3}_seriesColorHandle(t,e,r){var n;if(r&&e!=null&&e.length)for(const s of e){if((n=r.gradientColorKeys)!=null&&n.includes(s))continue;const a=t[s];if(!a)continue;const l=r[`${s}s`]||[];l.includes(a)||(l.push(a),r[`${s}s`]=l,l.length>5&&(r[`${s}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(s)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const h=parseInt(c,10);if(h<1||h>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,Pt.Error);return}return h});return{timePeriods:n.split(",").map(c=>{c===""||c===gi.regular?c="0930-1500":c===gi.extended&&(c="1500-1830");const h=c.split("-");return h.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,e,Pt.Error),[]):[this._processTime(h[0],e),this._processTime(h[1],e)]}),weeks:a}}_processTime(t,e){const r=parseInt(t.slice(0,2),10),n=parseInt(t.slice(2),10);if(!(r>=0&&r<=23)&&n>=0&&n<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",e,Pt.Error);return}return`${r}:${n}`}}class Ty{constructor(t,e){$(this,"_variables");$(this,"_scriptId");$(this,"_cacheData");this._variables=t,this._scriptId=e,this._cacheData=new Map}security(t,e){const r=self.workerStorage.get(`request_${this._scriptId}`),{paramsExpr:n=[]}=t,s=this._getRequestData(t,e);if(r!=null&&r.has(e)){const c=r.get(e);return this._runScripts(c,e,!1,n,s)}const a=this._parseExprCode(t),l=this._runScripts(a,e,!0,n,s);return r==null||r.set(e,a),l}_parseExprCode(t){let{expression:e,paramsExpr:r=[]}=t,n=[],s=1;e=Yl(e);const a=JSON.parse(e),l=a.pop();let c=(l==null?void 0:l.memberCodes)||{},h=(l==null?void 0:l.depends)||[];if(!h.length)return`return ${l==null?void 0:l.code}`;let d=[],f=[];const p=[];if(this._getDependCodes(h,a,n,d,f,p),n.push(...p),f.length){const m=r.length;let y=[];for(let v=m-1;v>=0;v--){const x=r[v];let b=JSON.parse(Yl(x));const M=[];s!==0&&f.length&&(y.unshift("{"),s++),b=b.map(S=>{const{scope:T,code:A,varNames:O,dependSelf:L}=S;return T===2&&!M.includes(O)&&!L&&(S.code=`let ${A}`),O&&M.push(...O.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const E=[],C=[];let N=f.map(S=>({...S,isArg:!1,isPreArg:!0}));f=[],this._getDependCodes(N,b,C,d,f,E),y.unshift(...C,...E),n=y.concat(n),y=[]}}for(n.push(`return ${l==null?void 0:l.code}`);s>1;)n.push("}"),s--;n=d.concat(n);let g=n.join(`
63
63
  `);const w=[];for(const m of Object.keys(c))g.includes(`$_var.getCacheData("${m}"`)&&w.push(c[m]);return w.length&&(g=`${w.join(`
64
64
  `)}
65
- ${g}`),g}_getRequestData(t,e){let{symbol:r,timeframe:n,calc_bars_count:s}=t;const{__period:a,syminfo:{ticker:l,tickerid:c},mintick:h}=this._variables;if((n===a||n==="")&&(r===l||r===c)){const{close:g,open:w,high:m,low:y,bar_index:v,last_bar_index:x,last_bar_time:b,_isRealTimeBar:M,volume:E,time:C,time_tradingday:N}=this._variables;return{barIndex:v,c:g,o:w,h:m,l:y,volume:E,lastBarIndex:x,lastBarTime:b/1e3,isrealtime:M,time_tradingday:N,time:C/1e3,interval:a,mintick:h}}const d=`${r}--${n||a}`,f=self.workerStorage.get(`request_${this._scriptId}_data`),p=self.workerStorage.get(`request_${this._scriptId}_list`);if(f!=null&&f.has(d)){p==null||p.delete(d);const{index:g=0,periodStamp:w=tn(this._variables.__period)*1e3}=this._cacheData.get(e)||{},m=(f.get(d)||[]).slice(g),y=this._variables.time,v=w+y,x=m.length-1,b={lastBarIndex:m[x].barindex||x,lastBarTime:m[x].time,interval:a,mintick:h};for(const[M,E]of m.entries()){let{time:C,barindex:N}=E;if(C=C*1e3,C>=v){this._cacheData.set(e,{index:M,periodStamp:w});return}if(C>=y)return this._cacheData.set(e,{index:M+1,periodStamp:w}),{...E,barIndex:N||M,...b}}this._cacheData.set(e,{index:m.length,periodStamp:w})}else(p==null?void 0:p.get(d))||p==null||p.set(d,{id:d,calc_bars_count:s,symbol:r,timeframe:n||a})}_getDependCodes(t,e,r,n,s,a){for(const l of t){if(!l.isArg){const c=e.filter(d=>{var f;return(f=d==null?void 0:d.depends)==null?void 0:f.some(p=>p.name===l.name&&p.scope===l.scope&&p.isAgainAssign)});for(const d of c){const{code:f,depends:p}=d;if(!r.includes(f)&&(r.unshift(f),p!=null&&p.length)){for(const g of p)g.memberCode&&a.push(g.memberCode);this._getDependCodes(p,e,r,n,s,a)}}const h=e.find(d=>{var f;return((f=d.varNames)==null?void 0:f.split(", ").includes(l.name))&&(!l.isPreArg||l.isPreArg&&d.methodName===l.functionName)||d.funcName===l.name});if(h){const{code:d,depends:f}=h,p=r.findIndex(g=>g===d);if(p!==-1&&r.splice(p,1),r.unshift(d),f!=null&&f.length){for(const g of f)g.memberCode&&a.push(g.memberCode);this._getDependCodes(f,e,r,n,s,a)}continue}}s.some(c=>c.name===l.name)||s.push(l)}}_runScripts(t,e,r,n,s){const a=`${this._scriptId}_${e}`;let{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:d}=self.workerStorage.get(a)||{};const{interval:f,mintick:p,...g}=s||{};r&&(l=new Ch(a),c=new _h,h=new Ah(this._variables.mintick||1e-5,l,this._scriptId),d=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),l.updateOptions({interval:f,mintick:p||1e-5}),self.workerStorage.set(a,{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:d})),l.updateData(g),h.update({barIndex:(g==null?void 0:g.barindex)||0});const w=d(l,c,h,n||[],e);return h.endExecution(),w}}let $y=class{constructor(){}prefix(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[0])||""}ticker(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[1])||""}};class Ly{constructor(t){$(this,"_logs");$(this,"_variables");$(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:s,formatString:a}=t,{time:l,bar_index:c}=this._variables;let h=s;a&&Array.isArray(e)&&e.length&&(h=a.replace(/{(\d+)}/g,(d,f)=>{if(e.length<=Number(f))return d;let p=e[f];return typeof p=="number"&&(p=this._intlFormat.format(parseFloat(p.toFixed(3)))),typeof p=="object"&&(p.isArray?p=JSON.stringify(p._value):p=p.toString()),p!==void 0?p:"na"})),h&&this._logs.push({message:`[${ee(l).format()}]: ${h}`,time:l,barIndex:c,type:r})}}class Ry{constructor(t){$(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,Pt.Error)}}class Py{constructor(){$(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Qr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[s,a]=e.split("_").slice(-2),l=this._errors.get(e),c={message:t,endLineNumber:Number(s),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(s),type:r};l?l.push(c):this._errors.set(e,[c])}}class zy{constructor(){$(this,"_isMarketOpen");$(this,"_currentBarIndex");$(this,"_totalBarIndex");$(this,"_isRealTimeBar");$(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class ky{constructor(t){$(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=tn(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=tn(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class qy{constructor(t){$(this,"_orders");$(this,"_historyOrders");$(this,"_options");$(this,"_max_contracts_held_all",0);$(this,"_max_contracts_held_long",0);$(this,"_max_contracts_held_short",0);$(this,"_max_drawdown",0);$(this,"_max_runup",0);$(this,"_max_runup_percent",0);$(this,"_max_drawdown_percent",0);$(this,"_variables");$(this,"_netprofit",0);$(this,"_eventrades",0);$(this,"_avg_trade_percent");$(this,"_closedtrades",0);$(this,"_losstrades",0);$(this,"_grossloss",0);$(this,"_grossloss_percent",0);$(this,"_grossprofit",0);$(this,"_grossprofit_percent",0);$(this,"_wintrades",0);$(this,"_opentrades_capital_held",0);$(this,"_position_avg_price",0);$(this,"_position_size",0);$(this,"_openprofit",0);$(this,"_preMaxNetValue",0);$(this,"_preMinNetValue",0);$(this,"marginCallLong",0);$(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=t}update(t){this._calcMaxDrawdownAndMaxRunup(t)}_calcMaxDrawdownAndMaxRunup(t){if(!this._orders.length&&!this._historyOrders.length)return;let e=0,r=0;const{high:n,low:s,close:a}=t;let l=0;for(const d of this._orders){const{in_price:f,qty:p=0,direction:g}=d,w=g===ce.long?1:-1,m=(n-f)*p,y=(s-f)*p,v=w===1?m:-y,x=w===1?-y:m;l+=(a-f)*w*p,e+=x,r+=v}this._openprofit=l;const c=this.initial_capital,h=c+this._netprofit;this._preMinNetValue=this._preMinNetValue||c,this._preMaxNetValue=this._preMaxNetValue||c,e=this._preMaxNetValue-h+Math.max(e,0),r=h-this._preMinNetValue+r,this._max_drawdown<e&&(this._max_drawdown=e,this._max_drawdown_percent=e/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[e,r,n,s,a,l,c]=this._orders.reduce(([h,d,f,p,g,w,m],y)=>{const{direction:v,qty:x=0,in_price:b,commission:M=0}=y;return v===ce.long?(h+=x,d+=x,w+=x):(h+=x,f+=x,w-=x),p+=x*b,g+=b,m+=M,[h,d,f,p,g,w,m]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-c,this._grossloss=-c),this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=s,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,s,a]=this._historyOrders.reduce((h,d)=>{let[f,p,g,w]=h;const{profit:m=0,profit_percent:y=0}=d;return f+=m,p+=y,m<0?g+=m:w+=m,[f,p,g,w]},[0,0,0,0]),l=this._orders.reduce((h,d)=>{const{commission:f=0,qty:p=0,original_qty:g=0}=d,w=f*p/g;return h+w},0);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r-l;const c=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,c),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,c),this._grossloss=s-l,this._grossprofit=a,this._eventrades=this._historyOrders.filter(h=>h.profit===0).length,this._losstrades=this._historyOrders.filter(h=>(h.profit||0)<0).length,this._wintrades=this._historyOrders.filter(h=>(h.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this._losstrades;return t?Math.abs(this._grossloss/t):void 0}get avg_losing_trade_percent(){const t=this._losstrades;return t?Math.abs(this._grossloss_percent/t):void 0}get avg_trade(){if(this._closedtrades)return this._netprofit/this._closedtrades}get equity(){return this.initial_capital+this._netprofit+this._openprofit}get netprofit(){return this._netprofit}get eventrades(){return this._eventrades}get openprofit(){return this._openprofit}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this._wintrades;return t?Math.abs(this._grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this._wintrades;return t?Math.abs(this._grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:s=0}=this._options,a=this._orders[0].direction===ce.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[h,d]=this._orders.reduce((f,p)=>{let[g,w]=f;const{in_price:m,qty:y=0,original_qty:v=0}=p,x=m*y;if(g+=x,s){let b=0;switch(n){case je.percent:b=(x+y*c)*s/100;break;case je.cashPerContract:b=y*s*2;break;case je.cashPerOrder:b=y/v*s+s;break}w+=b}return[g,w]},[0,0]);return(h-(t+this._netprofit-d))*a/this._position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this._netprofit/this.initial_capital*100}get openprofit_percent(){return this._openprofit/(this.initial_capital+this._netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(t,e){if(!this._options)return 0;const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case je.percent:a=s*r/100;break;case je.cashPerContract:a=e*r;break;case je.cashPerOrder:a=r;break}return a}}class Uy{constructor(t){$(this,"_preAccdist");$(this,"_preNvi");$(this,"_prePvi");$(this,"_preObv");$(this,"_prePvt");$(this,"_preWad");$(this,"_preVwap");$(this,"_preValue");$(this,"_currentData");$(this,"_preData");$(this,"_id");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={},this._id=t}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){var d,f;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(((f=(d=self.workerStorage)==null?void 0:d.get(this._id))==null?void 0:f.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(s=!0,r=n=0),!s)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:s});const h=l/c;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class Wy{constructor(){$(this,"_period");$(this,"_multiplier");$(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=this._transformPeriod(t);const[e,r]=Fs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}_transformPeriod(t){const e=parseInt(t);return t.length>1&&e===1?t.replace("1",""):t}}class jy{constructor(t){$(this,"_variables");$(this,"_bgColor");$(this,"_fgColor");$(this,"isUseBgColor",!1);this._variables=t}updateOptions(t){t!=null&&t.bg_color&&(this._bgColor=t.bg_color,this._fgColor=this._contrastColor(t.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){return this._variables.time}get right_visible_bar_time(){return this._variables.time}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?s=parseInt(a,16)/255:s=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,s=a[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}_contrastColor(t){const{r:e,g:r,b:n}=this._parseColor(t);return(299*e+587*r+114*n)/1e3>128?"#000000":"#ffffff"}}class Yy{constructor(t){$(this,"_variables");this._variables=t}get basecurrency(){return""}get country(){}get currency(){return"CNY"}get description(){return""}get employees(){return 100}get expiration_date(){}get industry(){}get minmove(){}get mintick(){return this._variables.mintick}get pointvalue(){}get prefix(){}get pricescale(){}get recommendations_buy(){}get recommendations_buy_strong(){}get recommendations_date(){}get recommendations_hold(){}get recommendations_sell(){}get recommendations_sell_strong(){}get recommendations_total(){}get root(){return""}get sector(){}get session(){return gi.regular}get shareholders(){}get shares_outstanding_float(){}get shares_outstanding_total(){}get target_price_average(){}get target_price_date(){}get target_price_estimates(){}get target_price_high(){}get target_price_low(){}get target_price_median(){}get ticker(){return""}get tickerid(){return""}get timezone(){}get type(){}get volumetype(){return"n/a"}}class Vy{constructor(t){$(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class Zy{constructor(t){$(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}ee.extend(up),ee.extend(wa),ee.extend(ya);class Ch{constructor(t){$(this,"_cacheData");$(this,"_barIndex");$(this,"_isRealTimeBar");$(this,"_barstate");$(this,"_priceVariables");$(this,"_lastBarIndex");$(this,"_currentBarTime");$(this,"_lastBarTime");$(this,"_period");$(this,"_offsetTime");$(this,"_timeframe");$(this,"_ta");$(this,"_polyline");$(this,"_label");$(this,"_line");$(this,"_linefill");$(this,"_box");$(this,"_table");$(this,"_strategy");$(this,"_session");$(this,"syminfo");$(this,"chart");$(this,"earnings");$(this,"dividends");$(this,"_timeTradingday");$(this,"_mintick");$(this,"_cacheSpace");$(this,"_precision");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new zy,this._timeframe=new Wy,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Uy(t),this._polyline=new Ti,this._label=new Ti,this._line=new Ti,this._linefill=new Ti,this._box=new Ti,this._table=new Ti,this._strategy=new qy(this),this._session=new ky(this),this.syminfo=new Yy(this),this.chart=new jy(this),this.earnings=new Zy(this),this.dividends=new Vy(this),this._cacheSpace=new Map}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return ee(this._currentBarTime).hour()}get minute(){return ee(this._currentBarTime).minute()}get second(){return ee(this._currentBarTime).second()}get month(){return ee(this._currentBarTime).month()+1}get year(){return ee(this._currentBarTime).year()}get dayofweek(){return ee(this._currentBarTime).day()}get dayofmonth(){return ee(this._currentBarTime).date()}get weekofyear(){return ee(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=Fs(this._period);return this._isRealTimeBar?void 0:ee(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}get precision(){return this._precision}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:s}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),s&&this._polyline.setMaxLen(s)}getTimeTradingday(t,e){const[r,n]=Fs(e),s=ee(t);return["M","w","y","d"].includes(n)?s.valueOf():(s.subtract(this._offsetTime,"h"),s.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){var l;const{interval:e="1D",offsetTime:r=5,mintick:n,chart:s}=t,a=((l=n.toString().split(".")[1])==null?void 0:l.length)||5;this._precision=a,this._period=e,this._mintick=n,this._offsetTime=r,this._timeframe.update(e),this.chart.updateOptions(s)}updateData(t){const{barIndex:e,c:r,o:n,h:s,l:a,volume:l,time:c,lastBarIndex:h,lastBarTime:d,isrealtime:f,time_tradingday:p}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(s),low:Number(a),volume:Number(l)},this._isRealTimeBar=f,e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varNewData={}),this._timeTradingday=p,this._currentBarTime=c*1e3,this._lastBarIndex=h,this._barIndex=e,this._lastBarTime=d*1e3,this._barstate.update(e,h,f,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){const n=this.setCacheData(t,r);return(this._cacheSpace.get(t)||0)<e&&this._cacheSpace.set(t,e),n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e);const n=this._cacheSpace.get(t);return n&&r.data.length>n+5&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[t]=r,r.data}getTypeInstance(t,e){return new np(t,e)}verifyVarAndVarip(t,e,r){const n=`${t}_${e}`;return r==="var"&&this._cacheData.varData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varData[n]),!0):r==="varip"&&this._cacheData.varipData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varipData[n]),!0):!1}getVarValue(t,e,r){const n=`${t}_${e}`;return r==="var"?this._isRealTimeBar&&this._cacheData.varNewData.hasOwnProperty(n)?this._cacheData.varNewData[n]:this._cacheData.varData[n]:this._cacheData.varipData[n]}setVarValue(t,e,r,n){var l;const s=`${t}_${e}`;let a;switch(typeof r=="object"&&((l=r==null?void 0:r.varipKeys)!=null&&l.length)&&(n="var",a=r.varipKeys),this._chartDrawsHandle(r,this._cacheData.varData[s]||this._cacheData.varipData[s]),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[s]=r,a&&a.length)for(const c of a)this._cacheData.varData[s][c]=r[c]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}_upadteChartDraws(t){const e=t==null?void 0:t.id;if(e)switch(t==null?void 0:t.type){case Me.BOX:this._setChartDraw(e,this._box);break;case Me.LINE:this._setChartDraw(e,this._line);break;case Me.POLYLINE:this._setChartDraw(e,this._polyline);break;case Me.LABEL:this._setChartDraw(e,this._label);break;case Me.LINEFILL:this._setChartDraw(e,this._linefill);break;case Me.TABLE:this._setChartDraw(e,this._table);break}}_setChartDraw(t,e){const r=e.getInstance(t),n=e.get(t),s=(r==null?void 0:r.updateId())||t;e.delete(t),e.set(s,n,r)}_chartDrawsHandle(t,e){const r=e==null?void 0:e.id;let n=t==null?void 0:t.id;r!==n&&(n&&t.data&&(t.data.isVar=!0),r&&e.data&&(e.data.isVar=!1))}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Qr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case mo.name:case mh.name:case wo.name:case gh.name:case go.name:case vo.name:t==null||t.delete();break}}}class Ti{constructor(t=50){$(this,"_all");$(this,"_allInstance");$(this,"_pseudoArrayAll");$(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Qt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){if(this.set(t,e,r),this._all.size>this._maxLength){const{bar_index:n}=e;for(const[s,a]of this._all){const{isVar:l,id:c,bar_index:h}=a;if(h===n)break;if(l)continue;this.delete(c);break}}}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const s=r.filter(a=>a.endsWith(`_${n}`));for(const a of s){const l=this._all.get(a);l&&e.push(l)}}return e.length?e:void 0}set(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}/**
65
+ ${g}`),g}_getRequestData(t,e){let{symbol:r,timeframe:n,calc_bars_count:s}=t;const{__period:a,syminfo:{ticker:l,tickerid:c},mintick:h}=this._variables;if((n===a||n==="")&&(r===l||r===c)){const{close:g,open:w,high:m,low:y,bar_index:v,last_bar_index:x,last_bar_time:b,_isRealTimeBar:M,volume:E,time:C,time_tradingday:N}=this._variables;return{barIndex:v,c:g,o:w,h:m,l:y,volume:E,lastBarIndex:x,lastBarTime:b/1e3,isrealtime:M,time_tradingday:N,time:C/1e3,interval:a,mintick:h}}const d=`${r}--${n||a}`,f=self.workerStorage.get(`request_${this._scriptId}_data`),p=self.workerStorage.get(`request_${this._scriptId}_list`);if(f!=null&&f.has(d)){p==null||p.delete(d);const{index:g=0,periodStamp:w=tn(this._variables.__period)*1e3}=this._cacheData.get(e)||{},m=(f.get(d)||[]).slice(g),y=this._variables.time,v=w+y,x=m.length-1,b={lastBarIndex:m[x].barindex||x,lastBarTime:m[x].time,interval:a,mintick:h};for(const[M,E]of m.entries()){let{time:C,barindex:N}=E;if(C=C*1e3,C>=v){this._cacheData.set(e,{index:M,periodStamp:w});return}if(C>=y)return this._cacheData.set(e,{index:M+1,periodStamp:w}),{...E,barIndex:N||M,...b}}this._cacheData.set(e,{index:m.length,periodStamp:w})}else(p==null?void 0:p.get(d))||p==null||p.set(d,{id:d,calc_bars_count:s,symbol:r,timeframe:n||a})}_getDependCodes(t,e,r,n,s,a){for(const l of t){if(!l.isArg){const c=e.filter(d=>{var f;return(f=d==null?void 0:d.depends)==null?void 0:f.some(p=>p.name===l.name&&p.scope===l.scope&&p.isAgainAssign)});for(const d of c){const{code:f,depends:p}=d;if(!r.includes(f)&&(r.unshift(f),p!=null&&p.length)){for(const g of p)g.memberCode&&a.push(g.memberCode);this._getDependCodes(p,e,r,n,s,a)}}const h=e.find(d=>{var f;return((f=d.varNames)==null?void 0:f.split(", ").includes(l.name))&&(!l.isPreArg||l.isPreArg&&d.methodName===l.functionName)||d.funcName===l.name});if(h){const{code:d,depends:f}=h,p=r.findIndex(g=>g===d);if(p!==-1&&r.splice(p,1),r.unshift(d),f!=null&&f.length){for(const g of f)g.memberCode&&a.push(g.memberCode);this._getDependCodes(f,e,r,n,s,a)}continue}}s.some(c=>c.name===l.name)||s.push(l)}}_runScripts(t,e,r,n,s){const a=`${this._scriptId}_${e}`;let{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:d}=self.workerStorage.get(a)||{};const{interval:f,mintick:p,...g}=s||{};r&&(l=new Ch(a),c=new _h,h=new Ah(this._variables.mintick||1e-5,l,this._scriptId),d=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),l.updateOptions({interval:f,mintick:p||1e-5}),self.workerStorage.set(a,{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:d})),l.updateData(g),h.update({barIndex:(g==null?void 0:g.barindex)||0});const w=d(l,c,h,n||[],e);return h.endExecution(),w}}let $y=class{constructor(){}prefix(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[0])||""}ticker(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[1])||""}};class Ly{constructor(t){$(this,"_logs");$(this,"_variables");$(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:s,formatString:a}=t,{time:l,bar_index:c}=this._variables;let h=s;a&&Array.isArray(e)&&e.length&&(h=a.replace(/{(\d+)}/g,(d,f)=>{if(e.length<=Number(f))return d;let p=e[f];return typeof p=="number"&&(p=this._intlFormat.format(parseFloat(p.toFixed(3)))),typeof p=="object"&&(p.isArray?p=JSON.stringify(p._value):p=p.toString()),p!==void 0?p:"na"})),h&&this._logs.push({message:`[${ee(l).format()}]: ${h}`,time:l,barIndex:c,type:r})}}class Ry{constructor(t){$(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,Pt.Error)}}class Py{constructor(){$(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Qr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[s,a]=e.split("_").slice(-2),l=this._errors.get(e),c={message:t,endLineNumber:Number(s),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(s),type:r};l?l.push(c):this._errors.set(e,[c])}}class zy{constructor(){$(this,"_isMarketOpen");$(this,"_currentBarIndex");$(this,"_totalBarIndex");$(this,"_isRealTimeBar");$(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class ky{constructor(t){$(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=tn(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=tn(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class qy{constructor(t){$(this,"_orders");$(this,"_historyOrders");$(this,"_options");$(this,"_max_contracts_held_all",0);$(this,"_max_contracts_held_long",0);$(this,"_max_contracts_held_short",0);$(this,"_max_drawdown",0);$(this,"_max_runup",0);$(this,"_max_runup_percent",0);$(this,"_max_drawdown_percent",0);$(this,"_variables");$(this,"_netprofit",0);$(this,"_eventrades",0);$(this,"_avg_trade_percent");$(this,"_closedtrades",0);$(this,"_losstrades",0);$(this,"_grossloss",0);$(this,"_grossloss_percent",0);$(this,"_grossprofit",0);$(this,"_grossprofit_percent",0);$(this,"_wintrades",0);$(this,"_opentrades_capital_held",0);$(this,"_position_avg_price",0);$(this,"_position_size",0);$(this,"_openprofit",0);$(this,"_preMaxNetValue",0);$(this,"_preMinNetValue",0);$(this,"marginCallLong",0);$(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=t}update(t){this._calcMaxDrawdownAndMaxRunup(t)}_calcMaxDrawdownAndMaxRunup(t){if(!this._orders.length&&!this._historyOrders.length)return;let e=0,r=0;const{high:n,low:s,close:a}=t;let l=0;for(const d of this._orders){const{in_price:f,qty:p=0,direction:g}=d,w=g===ce.long?1:-1,m=(n-f)*p,y=(s-f)*p,v=w===1?m:-y,x=w===1?-y:m;l+=(a-f)*w*p,e+=x,r+=v}this._openprofit=l;const c=this.initial_capital,h=c+this._netprofit;this._preMinNetValue=this._preMinNetValue||c,this._preMaxNetValue=this._preMaxNetValue||c,e=this._preMaxNetValue-h+Math.max(e,0),r=h-this._preMinNetValue+r,this._max_drawdown<e&&(this._max_drawdown=e,this._max_drawdown_percent=e/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[e,r,n,s,a,l,c]=this._orders.reduce(([h,d,f,p,g,w,m],y)=>{const{direction:v,qty:x=0,in_price:b,commission:M=0}=y;return v===ce.long?(h+=x,d+=x,w+=x):(h+=x,f+=x,w-=x),p+=x*b,g+=b,m+=M,[h,d,f,p,g,w,m]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-c,this._grossloss=-c),this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=s,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,s,a]=this._historyOrders.reduce((h,d)=>{let[f,p,g,w]=h;const{profit:m=0,profit_percent:y=0}=d;return f+=m,p+=y,m<0?g+=m:w+=m,[f,p,g,w]},[0,0,0,0]),l=this._orders.reduce((h,d)=>{const{commission:f=0,qty:p=0,original_qty:g=0}=d,w=f*p/g;return h+w},0);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r-l;const c=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,c),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,c),this._grossloss=s-l,this._grossprofit=a,this._eventrades=this._historyOrders.filter(h=>h.profit===0).length,this._losstrades=this._historyOrders.filter(h=>(h.profit||0)<0).length,this._wintrades=this._historyOrders.filter(h=>(h.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this._losstrades;return t?Math.abs(this._grossloss/t):void 0}get avg_losing_trade_percent(){const t=this._losstrades;return t?Math.abs(this._grossloss_percent/t):void 0}get avg_trade(){if(this._closedtrades)return this._netprofit/this._closedtrades}get equity(){return this.initial_capital+this._netprofit+this._openprofit}get netprofit(){return this._netprofit}get eventrades(){return this._eventrades}get openprofit(){return this._openprofit}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this._wintrades;return t?Math.abs(this._grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this._wintrades;return t?Math.abs(this._grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:s=0}=this._options,a=this._orders[0].direction===ce.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[h,d]=this._orders.reduce((f,p)=>{let[g,w]=f;const{in_price:m,qty:y=0,original_qty:v=0}=p,x=m*y;if(g+=x,s){let b=0;switch(n){case je.percent:b=(x+y*c)*s/100;break;case je.cashPerContract:b=y*s*2;break;case je.cashPerOrder:b=y/v*s+s;break}w+=b}return[g,w]},[0,0]);return(h-(t+this._netprofit-d))*a/this._position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this._netprofit/this.initial_capital*100}get openprofit_percent(){return this._openprofit/(this.initial_capital+this._netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(t,e){if(!this._options)return 0;const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case je.percent:a=s*r/100;break;case je.cashPerContract:a=e*r;break;case je.cashPerOrder:a=r;break}return a}}class Uy{constructor(t){$(this,"_preAccdist");$(this,"_preNvi");$(this,"_prePvi");$(this,"_preObv");$(this,"_prePvt");$(this,"_preWad");$(this,"_preVwap");$(this,"_preValue");$(this,"_currentData");$(this,"_preData");$(this,"_id");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={},this._id=t}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){var d,f;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(((f=(d=self.workerStorage)==null?void 0:d.get(this._id))==null?void 0:f.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(s=!0,r=n=0),!s)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:s});const h=l/c;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class Wy{constructor(){$(this,"_period");$(this,"_multiplier");$(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=this._transformPeriod(t);const[e,r]=Fs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}_transformPeriod(t){const e=parseInt(t);return t.length>1&&e===1?t.replace("1",""):t}}class jy{constructor(t){$(this,"_variables");$(this,"_bgColor");$(this,"_fgColor");$(this,"isUseBgColor",!1);this._variables=t}updateOptions(t){t!=null&&t.bg_color&&(this._bgColor=t.bg_color,this._fgColor=this._contrastColor(t.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){return this._variables.time}get right_visible_bar_time(){return this._variables.time}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?s=parseInt(a,16)/255:s=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,s=a[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}_contrastColor(t){const{r:e,g:r,b:n}=this._parseColor(t);return(299*e+587*r+114*n)/1e3>128?"#000000":"#ffffff"}}class Yy{constructor(t){$(this,"_variables");this._variables=t}get basecurrency(){return""}get country(){}get currency(){return"CNY"}get description(){return""}get employees(){return 100}get expiration_date(){}get industry(){}get minmove(){}get mintick(){return this._variables.mintick}get pointvalue(){}get prefix(){}get pricescale(){}get recommendations_buy(){}get recommendations_buy_strong(){}get recommendations_date(){}get recommendations_hold(){}get recommendations_sell(){}get recommendations_sell_strong(){}get recommendations_total(){}get root(){return""}get sector(){}get session(){return gi.regular}get shareholders(){}get shares_outstanding_float(){}get shares_outstanding_total(){}get target_price_average(){}get target_price_date(){}get target_price_estimates(){}get target_price_high(){}get target_price_low(){}get target_price_median(){}get ticker(){return""}get tickerid(){return""}get timezone(){}get type(){}get volumetype(){return"n/a"}}class Vy{constructor(t){$(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class Zy{constructor(t){$(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}ee.extend(up),ee.extend(wa),ee.extend(ya);class Ch{constructor(t){$(this,"_cacheData");$(this,"_barIndex");$(this,"_isRealTimeBar");$(this,"_barstate");$(this,"_priceVariables");$(this,"_lastBarIndex");$(this,"_currentBarTime");$(this,"_lastBarTime");$(this,"_period");$(this,"_offsetTime");$(this,"_timeframe");$(this,"_ta");$(this,"_polyline");$(this,"_label");$(this,"_line");$(this,"_linefill");$(this,"_box");$(this,"_table");$(this,"_strategy");$(this,"_session");$(this,"syminfo");$(this,"chart");$(this,"earnings");$(this,"dividends");$(this,"_timeTradingday");$(this,"_mintick");$(this,"_cacheSpace");$(this,"_precision");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new zy,this._timeframe=new Wy,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Uy(t),this._polyline=new Ti,this._label=new Ti,this._line=new Ti,this._linefill=new Ti,this._box=new Ti,this._table=new Ti,this._strategy=new qy(this),this._session=new ky(this),this.syminfo=new Yy(this),this.chart=new jy(this),this.earnings=new Zy(this),this.dividends=new Vy(this),this._cacheSpace=new Map}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return ee(this._currentBarTime).hour()}get minute(){return ee(this._currentBarTime).minute()}get second(){return ee(this._currentBarTime).second()}get month(){return ee(this._currentBarTime).month()+1}get year(){return ee(this._currentBarTime).year()}get dayofweek(){return ee(this._currentBarTime).day()}get dayofmonth(){return ee(this._currentBarTime).date()}get weekofyear(){return ee(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=Fs(this._period);return this._isRealTimeBar?void 0:ee(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}get precision(){return this._precision}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:s}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),s&&this._polyline.setMaxLen(s)}getTimeTradingday(t,e){const[r,n]=Fs(e),s=ee(t);return["M","w","y","d"].includes(n)?s.valueOf():(s.subtract(this._offsetTime,"h"),s.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){var l;const{interval:e="1D",offsetTime:r=5,mintick:n,chart:s}=t,a=((l=n.toString().split(".")[1])==null?void 0:l.length)||5;this._precision=a,this._period=e,this._mintick=n,this._offsetTime=r,this._timeframe.update(e),this.chart.updateOptions(s)}updateData(t){const{barIndex:e,c:r,o:n,h:s,l:a,volume:l,time:c,lastBarIndex:h,lastBarTime:d,isrealtime:f,time_tradingday:p}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(s),low:Number(a),volume:Number(l)},this._isRealTimeBar=f,e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varNewData={}),this._timeTradingday=p,this._currentBarTime=c*1e3,this._lastBarIndex=h,this._barIndex=e,this._lastBarTime=d*1e3,this._barstate.update(e,h,f,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){const n=this.setCacheData(t,r);return(this._cacheSpace.get(t)||0)<e&&this._cacheSpace.set(t,e),n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e);const n=this._cacheSpace.get(t);return n&&r.data.length>n+5&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[t]=r,r.data}getTypeInstance(t,e){return new np(t,e)}verifyVarAndVarip(t,e,r){const n=`${t}_${e}`;return r==="var"&&this._cacheData.varData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varData[n]),!0):r==="varip"&&this._cacheData.varipData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varipData[n]),!0):!1}getVarValue(t,e,r){const n=`${t}_${e}`;return r==="var"?this._isRealTimeBar&&this._cacheData.varNewData.hasOwnProperty(n)?this._cacheData.varNewData[n]:this._cacheData.varData[n]:this._cacheData.varipData[n]}setVarValue(t,e,r,n){var l;const s=`${t}_${e}`;let a;switch(typeof r=="object"&&((l=r==null?void 0:r.varipKeys)!=null&&l.length)&&(n="var",a=r.varipKeys),this._chartDrawsHandle(r,this._cacheData.varData[s]||this._cacheData.varipData[s]),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[s]=r,a&&a.length)for(const c of a)this._cacheData.varData[s][c]=r[c]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}_upadteChartDraws(t){const e=t==null?void 0:t.id;if(e)switch(t==null?void 0:t.type){case Me.BOX:this._setChartDraw(e,this._box);break;case Me.LINE:this._setChartDraw(e,this._line);break;case Me.POLYLINE:this._setChartDraw(e,this._polyline);break;case Me.LABEL:this._setChartDraw(e,this._label);break;case Me.LINEFILL:this._setChartDraw(e,this._linefill);break;case Me.TABLE:this._setChartDraw(e,this._table);break}}_setChartDraw(t,e){const r=e.getInstance(t),n=e.get(t);if(!n||!r)return;const s=(r==null?void 0:r.updateId())||t;e.delete(t),e.set(s,n,r)}_chartDrawsHandle(t,e){const r=e==null?void 0:e.id;let n=t==null?void 0:t.id;r!==n&&(n&&t.data&&(t.data.isVar=!0),r&&e.data&&(e.data.isVar=!1))}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Qr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case mo.name:case mh.name:case wo.name:case gh.name:case go.name:case vo.name:t==null||t.delete();break}}}class Ti{constructor(t=50){$(this,"_all");$(this,"_allInstance");$(this,"_pseudoArrayAll");$(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Qt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){if(this.set(t,e,r),this._all.size>this._maxLength){const{bar_index:n}=e;for(const[s,a]of this._all){const{isVar:l,id:c,bar_index:h}=a;if(h===n)break;if(l)continue;this.delete(c);break}}}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const s=r.filter(a=>a.endsWith(`_${n}`));for(const a of s){const l=this._all.get(a);l&&e.push(l)}}return e.length?e:void 0}set(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}/**
66
66
  * @license
67
67
  * Copyright 2019 Google LLC
68
68
  * SPDX-License-Identifier: Apache-2.0
@@ -67600,7 +67600,7 @@ function nr(a, n, r) {
67600
67600
  function ih() {
67601
67601
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
67602
67602
  }
67603
- const Pp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-DvdFfBYN.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
67603
+ const Pp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-BQfEmIBN.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
67604
67604
  Pp.onerror = (a) => {
67605
67605
  console.error(a);
67606
67606
  };
@@ -141,7 +141,7 @@ function print() { __p += __j.call(arguments, '') }
141
141
  * @license
142
142
  * Copyright 2019 Google LLC
143
143
  * SPDX-License-Identifier: Apache-2.0
144
- */const yo=Symbol("Comlink.proxy"),tm=Symbol("Comlink.endpoint"),rm=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),_o=a=>typeof a=="object"&&a!==null||typeof a=="function",sm={canHandle:a=>_o(a)&&a[yo],serialize(a){const{port1:n,port2:s}=new MessageChannel;return go(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},am={canHandle:a=>_o(a)&&Ys in a,serialize({value:a}){let n;return a instanceof Error?n={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:n={isError:!1,value:a},[n,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},fo=new Map([["proxy",sm],["throw",am]]);function nm(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function go(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!nm(s,c.origin)){console.warn(`Invalid origin '${c.origin}' for comlink proxy`);return}const{id:l,type:m,path:y}=Object.assign({path:[]},c.data),f=(c.data.argumentList||[]).map(br);let b;try{const h=y.slice(0,-1).reduce((N,F)=>N[F],a),T=y.reduce((N,F)=>N[F],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=br(c.data.value),b=!0;break;case"APPLY":b=T.apply(h,f);break;case"CONSTRUCT":{const N=new T(...f);b=gn(N)}break;case"ENDPOINT":{const{port1:N,port2:F}=new MessageChannel;go(a,F),b=pm(N,[N])}break;case"RELEASE":b=void 0;break;default:return}}catch(h){b={value:h,[Ys]:0}}Promise.resolve(b).catch(h=>({value:h,[Ys]:0})).then(h=>{const[T,N]=ea(h);n.postMessage(Object.assign(Object.assign({},T),{id:l}),N),m==="RELEASE"&&(n.removeEventListener("message",o),bo(n),yn in a&&typeof a[yn]=="function"&&a[yn]())}).catch(h=>{const[T,N]=ea({value:new TypeError("Unserializable return value"),[Ys]:0});n.postMessage(Object.assign(Object.assign({},T),{id:l}),N)})}),n.start&&n.start()}function im(a){return a.constructor.name==="MessagePort"}function bo(a){im(a)&&a.close()}function _n(a,n){return fn(a,[],n)}function Qs(a){if(a)throw new Error("Proxy has been released and is not useable")}function xo(a){return Lr(a,{type:"RELEASE"}).then(()=>{bo(a)})}const Zs=new WeakMap,Js="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const n=(Zs.get(a)||0)-1;Zs.set(a,n),n===0&&xo(a)});function om(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function lm(a){Js&&Js.unregister(a)}function fn(a,n=[],s=function(){}){let o=!1;const c=new Proxy(s,{get(l,m){if(Qs(o),m===rm)return()=>{lm(c),xo(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Lr(a,{type:"GET",path:n.map(f=>f.toString())}).then(br);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Lr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(br)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===tm)return Lr(a,{type:"ENDPOINT"}).then(br);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=ho(y);return Lr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(br)},construct(l,m){Qs(o);const[y,f]=ho(m);return Lr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(br)}});return om(c,a),c}function cm(a){return Array.prototype.concat.apply([],a)}function ho(a){const n=a.map(ea);return[n.map(s=>s[0]),cm(n.map(s=>s[1]))]}const wo=new WeakMap;function pm(a,n){return wo.set(a,n),a}function gn(a){return Object.assign(a,{[yo]:!0})}function ea(a){for(const[n,s]of fo)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},wo.get(a)||[]]}function br(a){switch(a.type){case"HANDLER":return fo.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Lr(a,n,s){return new Promise(o=>{const c=dm();a.addEventListener("message",function l(m){!m.data||!m.data.id||m.data.id!==c||(a.removeEventListener("message",l),o(m.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:c},n),s)})}function dm(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const vo=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-DvdFfBYN.js").href:new URL("assets/scriptsRunWorker-DvdFfBYN.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});vo.onerror=a=>{console.error(a)};async function To(a){return await Gs.setInlayHints(a)}const Do=_n(vo),ko=_n(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-BwTU0Mcr.js").href:new URL("assets/parserTccWorker-BwTU0Mcr.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function Io(a,n=!1){const{functions:s,types:o,constants:c,variables:l,methods:m}=ct;return await ko.parseTcc(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function mm(a,n){const{functions:s,types:o,constants:c,variables:l,methods:m}=ct;return await ko.parseLibraryCode(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function um(a,n,s=!0){return await Do.runScript(a,n,s)}async function ym(a){return await Do.removeScript(a)}function _m(a){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/editor.worker-CT5Cb1wO.js").href:new URL("assets/editor.worker-CT5Cb1wO.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),{name:a==null?void 0:a.name})}self.MonacoEnvironment={getWorker(){return new _m({name:"Editor Worker"})}},sn.config({paths:{vs:"https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fm=(a,n)=>{const{height:s,width:o,theme:c,options:l,hasDiff:m,readOnly:y,defaultValue:f,onChange:b,onLinkOpen:h,onCursorPositionChange:T,onActionTrigger:N,onEditorDidMount:F}=a,S=O.useRef(null),R=O.useRef(null),W=O.useRef(!1),V=O.useRef(!1);O.useImperativeHandle(n,()=>({setOriginalScript(E){var H;(H=S.current)==null||H.setOriginalScript(E)},setScript(E){var H;(H=S.current)==null||H.setValue(E)},gotoLine(){var E;(E=S.current)==null||E.gotoLine()},getEditorLayout(){var E;return(E=S.current)==null?void 0:E.getEditorLayout()},setPosition(E,H){var Q;(Q=S.current)==null||Q.setPosition({column:E,lineNumber:H})},setModelMarkers(E){var H;V.current=!0,(H=S.current)==null||H.setModelMarkers(E),setTimeout(()=>{V.current=!1},2e3)},focus(){var E;(E=S.current)==null||E.focus()}})),O.useEffect(()=>{var E,H;m?(H=S.current)==null||H.addDiffDecorations():(E=S.current)==null||E.removeDiffDecorations()},[m]),O.useEffect(()=>{c&&ke.editor.setTheme(c)},[c]),O.useEffect(()=>{var E;(E=S.current)==null||E.updateActionTrigger(N)},[N]),O.useEffect(()=>{var E;h&&((E=S.current)==null||E.addLinkOpenFunc(h))},[h]);function Y(E,H){var ie,Qe;zt.initBuiltinsTrees(),Gs.setEditor(E),S.current=new em(E,H,N),h&&((ie=S.current)==null||ie.addLinkOpenFunc(h)),m&&((Qe=S.current)==null||Qe.addDiffDecorations()),kd(E),requestAnimationFrame(B);const Q=E.getValue();S.current.onChangeCursorPosition(T),b&&b(Q),!y&&U(Q),F&&F()}const U=O.useCallback(async E=>{var $e;const H=Date.now();W.current=!1;const{errors:Q,functions:ie,methods:Qe,types:St,variables:Ue,overloadsFuncs:Ke,imports:J,enums:be}=await Io(E),Ee=new Map(Object.entries(ie)),Me=new Map(Object.entries(Qe)),pt=new Map(Object.entries(St)),ht=new Map(Object.entries(Ue)),se=new Map(Object.entries(J)),xe=new Map(Object.entries(be));gr.setUserDefined({functions:Ee,methods:Me,types:pt,variables:ht,imports:se,enums:xe},Ke),zt.setUserDefind(Ee,pt,ht,Me,xe);const Pe=Q.map(Nt=>({...Nt,severity:Nt.type||ke.MarkerSeverity.Error}));if(y)return;!W.current&&!V.current&&Pe.length&&(($e=S.current)==null||$e.setModelMarkers(Pe));const Et=Date.now();console.log((Et-H)/1e3)},[y]),K=O.useMemo(()=>qd.debounce(U,1500),[U]);function A(E){var H;if(y){U(E||"");return}W.current=!0,Gs.clearInlayHints(),(H=S.current)==null||H.setModelMarkers([]),E!==void 0&&(b&&b(E),K(E))}const B=O.useCallback(()=>{var H,Q;const E=(H=R.current)==null?void 0:H.getBoundingClientRect();(Q=S.current)==null||Q.setEditorLayout((E==null?void 0:E.height)||0,E==null?void 0:E.width)},[]);return O.useEffect(()=>{const E=()=>{window.requestAnimationFrame(B)},H=new ResizeObserver(E);return R.current&&H.observe(R.current),()=>{var Q;R.current&&H.unobserve(R.current),H.disconnect(),(Q=S.current)==null||Q.dispose()}},[]),M.jsx("div",{ref:R,children:M.jsx(yd,{height:s,width:o||"100%",defaultLanguage:Se,defaultValue:f||`indicator("我的脚本")
144
+ */const yo=Symbol("Comlink.proxy"),tm=Symbol("Comlink.endpoint"),rm=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),_o=a=>typeof a=="object"&&a!==null||typeof a=="function",sm={canHandle:a=>_o(a)&&a[yo],serialize(a){const{port1:n,port2:s}=new MessageChannel;return go(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},am={canHandle:a=>_o(a)&&Ys in a,serialize({value:a}){let n;return a instanceof Error?n={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:n={isError:!1,value:a},[n,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},fo=new Map([["proxy",sm],["throw",am]]);function nm(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function go(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!nm(s,c.origin)){console.warn(`Invalid origin '${c.origin}' for comlink proxy`);return}const{id:l,type:m,path:y}=Object.assign({path:[]},c.data),f=(c.data.argumentList||[]).map(br);let b;try{const h=y.slice(0,-1).reduce((N,F)=>N[F],a),T=y.reduce((N,F)=>N[F],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=br(c.data.value),b=!0;break;case"APPLY":b=T.apply(h,f);break;case"CONSTRUCT":{const N=new T(...f);b=gn(N)}break;case"ENDPOINT":{const{port1:N,port2:F}=new MessageChannel;go(a,F),b=pm(N,[N])}break;case"RELEASE":b=void 0;break;default:return}}catch(h){b={value:h,[Ys]:0}}Promise.resolve(b).catch(h=>({value:h,[Ys]:0})).then(h=>{const[T,N]=ea(h);n.postMessage(Object.assign(Object.assign({},T),{id:l}),N),m==="RELEASE"&&(n.removeEventListener("message",o),bo(n),yn in a&&typeof a[yn]=="function"&&a[yn]())}).catch(h=>{const[T,N]=ea({value:new TypeError("Unserializable return value"),[Ys]:0});n.postMessage(Object.assign(Object.assign({},T),{id:l}),N)})}),n.start&&n.start()}function im(a){return a.constructor.name==="MessagePort"}function bo(a){im(a)&&a.close()}function _n(a,n){return fn(a,[],n)}function Qs(a){if(a)throw new Error("Proxy has been released and is not useable")}function xo(a){return Lr(a,{type:"RELEASE"}).then(()=>{bo(a)})}const Zs=new WeakMap,Js="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const n=(Zs.get(a)||0)-1;Zs.set(a,n),n===0&&xo(a)});function om(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function lm(a){Js&&Js.unregister(a)}function fn(a,n=[],s=function(){}){let o=!1;const c=new Proxy(s,{get(l,m){if(Qs(o),m===rm)return()=>{lm(c),xo(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Lr(a,{type:"GET",path:n.map(f=>f.toString())}).then(br);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Lr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(br)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===tm)return Lr(a,{type:"ENDPOINT"}).then(br);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=ho(y);return Lr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(br)},construct(l,m){Qs(o);const[y,f]=ho(m);return Lr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(br)}});return om(c,a),c}function cm(a){return Array.prototype.concat.apply([],a)}function ho(a){const n=a.map(ea);return[n.map(s=>s[0]),cm(n.map(s=>s[1]))]}const wo=new WeakMap;function pm(a,n){return wo.set(a,n),a}function gn(a){return Object.assign(a,{[yo]:!0})}function ea(a){for(const[n,s]of fo)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},wo.get(a)||[]]}function br(a){switch(a.type){case"HANDLER":return fo.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Lr(a,n,s){return new Promise(o=>{const c=dm();a.addEventListener("message",function l(m){!m.data||!m.data.id||m.data.id!==c||(a.removeEventListener("message",l),o(m.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:c},n),s)})}function dm(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const vo=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-BQfEmIBN.js").href:new URL("assets/scriptsRunWorker-BQfEmIBN.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});vo.onerror=a=>{console.error(a)};async function To(a){return await Gs.setInlayHints(a)}const Do=_n(vo),ko=_n(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-BwTU0Mcr.js").href:new URL("assets/parserTccWorker-BwTU0Mcr.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function Io(a,n=!1){const{functions:s,types:o,constants:c,variables:l,methods:m}=ct;return await ko.parseTcc(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function mm(a,n){const{functions:s,types:o,constants:c,variables:l,methods:m}=ct;return await ko.parseLibraryCode(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function um(a,n,s=!0){return await Do.runScript(a,n,s)}async function ym(a){return await Do.removeScript(a)}function _m(a){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/editor.worker-CT5Cb1wO.js").href:new URL("assets/editor.worker-CT5Cb1wO.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),{name:a==null?void 0:a.name})}self.MonacoEnvironment={getWorker(){return new _m({name:"Editor Worker"})}},sn.config({paths:{vs:"https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fm=(a,n)=>{const{height:s,width:o,theme:c,options:l,hasDiff:m,readOnly:y,defaultValue:f,onChange:b,onLinkOpen:h,onCursorPositionChange:T,onActionTrigger:N,onEditorDidMount:F}=a,S=O.useRef(null),R=O.useRef(null),W=O.useRef(!1),V=O.useRef(!1);O.useImperativeHandle(n,()=>({setOriginalScript(E){var H;(H=S.current)==null||H.setOriginalScript(E)},setScript(E){var H;(H=S.current)==null||H.setValue(E)},gotoLine(){var E;(E=S.current)==null||E.gotoLine()},getEditorLayout(){var E;return(E=S.current)==null?void 0:E.getEditorLayout()},setPosition(E,H){var Q;(Q=S.current)==null||Q.setPosition({column:E,lineNumber:H})},setModelMarkers(E){var H;V.current=!0,(H=S.current)==null||H.setModelMarkers(E),setTimeout(()=>{V.current=!1},2e3)},focus(){var E;(E=S.current)==null||E.focus()}})),O.useEffect(()=>{var E,H;m?(H=S.current)==null||H.addDiffDecorations():(E=S.current)==null||E.removeDiffDecorations()},[m]),O.useEffect(()=>{c&&ke.editor.setTheme(c)},[c]),O.useEffect(()=>{var E;(E=S.current)==null||E.updateActionTrigger(N)},[N]),O.useEffect(()=>{var E;h&&((E=S.current)==null||E.addLinkOpenFunc(h))},[h]);function Y(E,H){var ie,Qe;zt.initBuiltinsTrees(),Gs.setEditor(E),S.current=new em(E,H,N),h&&((ie=S.current)==null||ie.addLinkOpenFunc(h)),m&&((Qe=S.current)==null||Qe.addDiffDecorations()),kd(E),requestAnimationFrame(B);const Q=E.getValue();S.current.onChangeCursorPosition(T),b&&b(Q),!y&&U(Q),F&&F()}const U=O.useCallback(async E=>{var $e;const H=Date.now();W.current=!1;const{errors:Q,functions:ie,methods:Qe,types:St,variables:Ue,overloadsFuncs:Ke,imports:J,enums:be}=await Io(E),Ee=new Map(Object.entries(ie)),Me=new Map(Object.entries(Qe)),pt=new Map(Object.entries(St)),ht=new Map(Object.entries(Ue)),se=new Map(Object.entries(J)),xe=new Map(Object.entries(be));gr.setUserDefined({functions:Ee,methods:Me,types:pt,variables:ht,imports:se,enums:xe},Ke),zt.setUserDefind(Ee,pt,ht,Me,xe);const Pe=Q.map(Nt=>({...Nt,severity:Nt.type||ke.MarkerSeverity.Error}));if(y)return;!W.current&&!V.current&&Pe.length&&(($e=S.current)==null||$e.setModelMarkers(Pe));const Et=Date.now();console.log((Et-H)/1e3)},[y]),K=O.useMemo(()=>qd.debounce(U,1500),[U]);function A(E){var H;if(y){U(E||"");return}W.current=!0,Gs.clearInlayHints(),(H=S.current)==null||H.setModelMarkers([]),E!==void 0&&(b&&b(E),K(E))}const B=O.useCallback(()=>{var H,Q;const E=(H=R.current)==null?void 0:H.getBoundingClientRect();(Q=S.current)==null||Q.setEditorLayout((E==null?void 0:E.height)||0,E==null?void 0:E.width)},[]);return O.useEffect(()=>{const E=()=>{window.requestAnimationFrame(B)},H=new ResizeObserver(E);return R.current&&H.observe(R.current),()=>{var Q;R.current&&H.unobserve(R.current),H.disconnect(),(Q=S.current)==null||Q.dispose()}},[]),M.jsx("div",{ref:R,children:M.jsx(yd,{height:s,width:o||"100%",defaultLanguage:Se,defaultValue:f||`indicator("我的脚本")
145
145
  plot(close)
146
146
  `,theme:c||"vs-dark",className:`tvue-script ${c||"vs-dark"}`,options:{colorDecorators:!0,useShadowDOM:!1,matchOnWordStartOnly:!0,automaticLayout:!1,unicodeHighlight:{allowedCharacters:{" ":!0}},suggest:{filterGraceful:!0},fontSize:13,...y?Ld:{},readOnlyMessage:{value:"该脚本是只读的。它无法被编辑。"},...l},onMount:Y,onChange:A})})},gm=O.forwardRef(fm),bm=a=>{const{theme:n,modified:s,original:o,height:c,width:l,renderSideBySide:m=!0}=a,y=O.useCallback((f,b)=>{b.languages.register({id:Se}),b.editor.defineTheme("vs-dark",cn),b.editor.defineTheme("vs",ln),b.languages.setMonarchTokensProvider(Se,Nr),b.languages.setLanguageConfiguration(Se,on)},[]);return M.jsx(cd,{height:c||"90vh",width:l||"100%",theme:n||"vs-dark",options:{readOnly:!0,renderSideBySide:m,scrollBeyondLastLine:!1},language:Se,modified:s,original:o,onMount:y})};I.VMarkerSeverity=void 0,function(a){a[a.Hint=1]="Hint",a[a.Info=2]="Info",a[a.Warning=4]="Warning",a[a.Error=8]="Error"}(I.VMarkerSeverity||(I.VMarkerSeverity={}));var ta={},xm=function(){var a=document.getSelection();if(!a.rangeCount)return function(){};for(var n=document.activeElement,s=[],o=0;o<a.rangeCount;o++)s.push(a.getRangeAt(o));switch(n.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":n.blur();break;default:n=null;break}return a.removeAllRanges(),function(){a.type==="Caret"&&a.removeAllRanges(),a.rangeCount||s.forEach(function(c){a.addRange(c)}),n&&n.focus()}},hm=xm,Ao={"text/plain":"Text","text/html":"Url",default:"Text"},wm="Copy to clipboard: #{key}, Enter";function vm(a){var n=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return a.replace(/#{\s*key\s*}/g,n)}function Tm(a,n){var s,o,c,l,m,y,f=!1;n||(n={}),s=n.debug||!1;try{c=hm(),l=document.createRange(),m=document.getSelection(),y=document.createElement("span"),y.textContent=a,y.ariaHidden="true",y.style.all="unset",y.style.position="fixed",y.style.top=0,y.style.clip="rect(0, 0, 0, 0)",y.style.whiteSpace="pre",y.style.webkitUserSelect="text",y.style.MozUserSelect="text",y.style.msUserSelect="text",y.style.userSelect="text",y.addEventListener("copy",function(h){if(h.stopPropagation(),n.format)if(h.preventDefault(),typeof h.clipboardData>"u"){s&&console.warn("unable to use e.clipboardData"),s&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var T=Ao[n.format]||Ao.default;window.clipboardData.setData(T,a)}else h.clipboardData.clearData(),h.clipboardData.setData(n.format,a);n.onCopy&&(h.preventDefault(),n.onCopy(h.clipboardData))}),document.body.appendChild(y),l.selectNodeContents(y),m.addRange(l);var b=document.execCommand("copy");if(!b)throw new Error("copy command was unsuccessful");f=!0}catch(h){s&&console.error("unable to copy using execCommand: ",h),s&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(n.format||"text",a),n.onCopy&&n.onCopy(window.clipboardData),f=!0}catch(T){s&&console.error("unable to copy using clipboardData: ",T),s&&console.error("falling back to prompt"),o=vm("message"in n?n.message:wm),window.prompt(o,a)}}finally{m&&(typeof m.removeRange=="function"?m.removeRange(l):m.removeAllRanges()),y&&document.body.removeChild(y),c()}return f}var Dm=Tm;function bn(a){"@babel/helpers - typeof";return bn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},bn(a)}Object.defineProperty(ta,"__esModule",{value:!0}),ta.CopyToClipboard=void 0;var ra=qo(O),km=qo(Dm),Im=["text","onCopy","options","children"];function qo(a){return a&&a.__esModule?a:{default:a}}function Co(a,n){var s=Object.keys(a);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(a);n&&(o=o.filter(function(c){return Object.getOwnPropertyDescriptor(a,c).enumerable})),s.push.apply(s,o)}return s}function zo(a){for(var n=1;n<arguments.length;n++){var s=arguments[n]!=null?arguments[n]:{};n%2?Co(Object(s),!0).forEach(function(o){hn(a,o,s[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(s)):Co(Object(s)).forEach(function(o){Object.defineProperty(a,o,Object.getOwnPropertyDescriptor(s,o))})}return a}function Am(a,n){if(a==null)return{};var s=qm(a,n),o,c;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(a);for(c=0;c<l.length;c++)o=l[c],!(n.indexOf(o)>=0)&&Object.prototype.propertyIsEnumerable.call(a,o)&&(s[o]=a[o])}return s}function qm(a,n){if(a==null)return{};var s={},o=Object.keys(a),c,l;for(l=0;l<o.length;l++)c=o[l],!(n.indexOf(c)>=0)&&(s[c]=a[c]);return s}function Cm(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function So(a,n){for(var s=0;s<n.length;s++){var o=n[s];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(a,o.key,o)}}function zm(a,n,s){return n&&So(a.prototype,n),s&&So(a,s),Object.defineProperty(a,"prototype",{writable:!1}),a}function Sm(a,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(n&&n.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),n&&xn(a,n)}function xn(a,n){return xn=Object.setPrototypeOf||function(o,c){return o.__proto__=c,o},xn(a,n)}function Em(a){var n=Lm();return function(){var o=sa(a),c;if(n){var l=sa(this).constructor;c=Reflect.construct(o,arguments,l)}else c=o.apply(this,arguments);return Nm(this,c)}}function Nm(a,n){if(n&&(bn(n)==="object"||typeof n=="function"))return n;if(n!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Eo(a)}function Eo(a){if(a===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function Lm(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function sa(a){return sa=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},sa(a)}function hn(a,n,s){return n in a?Object.defineProperty(a,n,{value:s,enumerable:!0,configurable:!0,writable:!0}):a[n]=s,a}var No=function(a){Sm(s,a);var n=Em(s);function s(){var o;Cm(this,s);for(var c=arguments.length,l=new Array(c),m=0;m<c;m++)l[m]=arguments[m];return o=n.call.apply(n,[this].concat(l)),hn(Eo(o),"onClick",function(y){var f=o.props,b=f.text,h=f.onCopy,T=f.children,N=f.options,F=ra.default.Children.only(T),S=(0,km.default)(b,N);h&&h(b,S),F&&F.props&&typeof F.props.onClick=="function"&&F.props.onClick(y)}),o}return zm(s,[{key:"render",value:function(){var c=this.props;c.text,c.onCopy,c.options;var l=c.children,m=Am(c,Im),y=ra.default.Children.only(l);return ra.default.cloneElement(y,zo(zo({},m),{},{onClick:this.onClick}))}}]),s}(ra.default.PureComponent);ta.CopyToClipboard=No,hn(No,"defaultProps",{onCopy:void 0,options:void 0});var Mm=ta,wn=Mm.CopyToClipboard;wn.CopyToClipboard=wn;var Pm=wn;const vn=ip(Pm);async function Om(a,n=0){const s=a[n];if(!s)return;const{name:o,args:c,type:l,desc:m,examples:y,remarks:f,seeAlso:b,syntax:h,detailedDesc:T,fields:N,returns:F}=s,S={name:o};if(a.length>1&&(S.overloads=`${a.length} overloads`),l&&(S.type=l),c&&(S.name=`${o}()`,S.args=c.map(R=>{const{name:W,desc:V,displayType:Y}=R;return{label:`${W} (${Y})`,desc:V&&xr(V)}})),m&&(S.desc=m.map(R=>xr(R))),y&&(S.originalExample=y.join(`
147
147
  `),S.examples=await ke.editor.colorize(S.originalExample,Se,{tabSize:4})),T){S.detailedDesc=[];for(const R of T){const{desc:W,examples:V}=R;let Y=W.map(A=>xr(A)),U,K;V&&(K=V.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guihz/trading-vue-editor-tes",
3
- "version": "0.0.212",
3
+ "version": "0.0.213",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib"