@guihz/trading-vue-editor-tes 0.0.275 → 0.0.276
Sign up to get free protection for your applications and to get access to all the features.
@@ -73,7 +73,7 @@ ${ko}rows: ${M.rows}
|
|
73
73
|
${ko}columns: ${M.columns}
|
74
74
|
}`}function R6(M,e,t,r,o){const{rows:n,columns:b}=M,z=Math.min(n,e),i=Math.min(b,t),s=[];if(o==="auto"){o=!1;e:for(let a=0;a<z;a++)for(let O=0;O<i;O++)if(M.get(a,O)<0){o=!0;break e}}for(let a=0;a<z;a++){let O=[];for(let u=0;u<i;u++)O.push(L6(M.get(a,u),r,o));s.push(`${O.join(" ")}`)}return i!==b&&(s[s.length-1]+=` ... ${b-t} more columns`),z!==n&&s.push(`... ${n-e} more rows`),s.join(`
|
75
75
|
${d3}`)}function L6(M,e,t){return(M>=0&&t?` ${W3(M,e-1)}`:W3(M,e)).padEnd(e)}function W3(M,e){let t=M.toString();if(t.length<=e)return t;let r=M.toFixed(e);if(r.length>e&&(r=M.toFixed(Math.max(0,e-(r.length-e)))),r.length<=e&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let o=M.toExponential(e);return o.length>e&&(o=M.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function v6(M,e){M.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},M.prototype.addS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)+r);return this},M.prototype.addM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)+r.get(o,n));return this},M.add=function(r,o){return new e(r).add(o)},M.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},M.prototype.subS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)-r);return this},M.prototype.subM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)-r.get(o,n));return this},M.sub=function(r,o){return new e(r).sub(o)},M.prototype.subtract=M.prototype.sub,M.prototype.subtractS=M.prototype.subS,M.prototype.subtractM=M.prototype.subM,M.subtract=M.sub,M.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},M.prototype.mulS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)*r);return this},M.prototype.mulM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)*r.get(o,n));return this},M.mul=function(r,o){return new e(r).mul(o)},M.prototype.multiply=M.prototype.mul,M.prototype.multiplyS=M.prototype.mulS,M.prototype.multiplyM=M.prototype.mulM,M.multiply=M.mul,M.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},M.prototype.divS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)/r);return this},M.prototype.divM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)/r.get(o,n));return this},M.div=function(r,o){return new e(r).div(o)},M.prototype.divide=M.prototype.div,M.prototype.divideS=M.prototype.divS,M.prototype.divideM=M.prototype.divM,M.divide=M.div,M.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},M.prototype.modS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)%r);return this},M.prototype.modM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)%r.get(o,n));return this},M.mod=function(r,o){return new e(r).mod(o)},M.prototype.modulus=M.prototype.mod,M.prototype.modulusS=M.prototype.modS,M.prototype.modulusM=M.prototype.modM,M.modulus=M.mod,M.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},M.prototype.andS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)&r);return this},M.prototype.andM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)&r.get(o,n));return this},M.and=function(r,o){return new e(r).and(o)},M.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},M.prototype.orS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)|r);return this},M.prototype.orM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)|r.get(o,n));return this},M.or=function(r,o){return new e(r).or(o)},M.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},M.prototype.xorS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)^r);return this},M.prototype.xorM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)^r.get(o,n));return this},M.xor=function(r,o){return new e(r).xor(o)},M.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},M.prototype.leftShiftS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)<<r);return this},M.prototype.leftShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)<<r.get(o,n));return this},M.leftShift=function(r,o){return new e(r).leftShift(o)},M.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},M.prototype.signPropagatingRightShiftS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>r);return this},M.prototype.signPropagatingRightShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>r.get(o,n));return this},M.signPropagatingRightShift=function(r,o){return new e(r).signPropagatingRightShift(o)},M.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},M.prototype.rightShiftS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>>r);return this},M.prototype.rightShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>>r.get(o,n));return this},M.rightShift=function(r,o){return new e(r).rightShift(o)},M.prototype.zeroFillRightShift=M.prototype.rightShift,M.prototype.zeroFillRightShiftS=M.prototype.rightShiftS,M.prototype.zeroFillRightShiftM=M.prototype.rightShiftM,M.zeroFillRightShift=M.rightShift,M.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,~this.get(r,o));return this},M.not=function(r){return new e(r).not()},M.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.abs(this.get(r,o)));return this},M.abs=function(r){return new e(r).abs()},M.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.acos(this.get(r,o)));return this},M.acos=function(r){return new e(r).acos()},M.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.acosh(this.get(r,o)));return this},M.acosh=function(r){return new e(r).acosh()},M.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.asin(this.get(r,o)));return this},M.asin=function(r){return new e(r).asin()},M.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.asinh(this.get(r,o)));return this},M.asinh=function(r){return new e(r).asinh()},M.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.atan(this.get(r,o)));return this},M.atan=function(r){return new e(r).atan()},M.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.atanh(this.get(r,o)));return this},M.atanh=function(r){return new e(r).atanh()},M.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.cbrt(this.get(r,o)));return this},M.cbrt=function(r){return new e(r).cbrt()},M.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.ceil(this.get(r,o)));return this},M.ceil=function(r){return new e(r).ceil()},M.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.clz32(this.get(r,o)));return this},M.clz32=function(r){return new e(r).clz32()},M.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.cos(this.get(r,o)));return this},M.cos=function(r){return new e(r).cos()},M.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.cosh(this.get(r,o)));return this},M.cosh=function(r){return new e(r).cosh()},M.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.exp(this.get(r,o)));return this},M.exp=function(r){return new e(r).exp()},M.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.expm1(this.get(r,o)));return this},M.expm1=function(r){return new e(r).expm1()},M.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.floor(this.get(r,o)));return this},M.floor=function(r){return new e(r).floor()},M.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.fround(this.get(r,o)));return this},M.fround=function(r){return new e(r).fround()},M.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log(this.get(r,o)));return this},M.log=function(r){return new e(r).log()},M.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log1p(this.get(r,o)));return this},M.log1p=function(r){return new e(r).log1p()},M.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log10(this.get(r,o)));return this},M.log10=function(r){return new e(r).log10()},M.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log2(this.get(r,o)));return this},M.log2=function(r){return new e(r).log2()},M.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.round(this.get(r,o)));return this},M.round=function(r){return new e(r).round()},M.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sign(this.get(r,o)));return this},M.sign=function(r){return new e(r).sign()},M.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sin(this.get(r,o)));return this},M.sin=function(r){return new e(r).sin()},M.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sinh(this.get(r,o)));return this},M.sinh=function(r){return new e(r).sinh()},M.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sqrt(this.get(r,o)));return this},M.sqrt=function(r){return new e(r).sqrt()},M.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.tan(this.get(r,o)));return this},M.tan=function(r){return new e(r).tan()},M.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.tanh(this.get(r,o)));return this},M.tanh=function(r){return new e(r).tanh()},M.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.trunc(this.get(r,o)));return this},M.trunc=function(r){return new e(r).trunc()},M.pow=function(r,o){return new e(r).pow(o)},M.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},M.prototype.powS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,Math.pow(this.get(o,n),r));return this},M.prototype.powM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,Math.pow(this.get(o,n),r.get(o,n)));return this}}function ne(M,e,t){let r=t?M.rows:M.rows-1;if(e<0||e>r)throw new RangeError("Row index out of range")}function be(M,e,t){let r=t?M.columns:M.columns-1;if(e<0||e>r)throw new RangeError("Column index out of range")}function Br(M,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==M.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function wr(M,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==M.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function cp(M,e){if(!C2.isAnyArray(e))throw new TypeError("row indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=M.rows)throw new RangeError("row indices are out of range")}function sp(M,e){if(!C2.isAnyArray(e))throw new TypeError("column indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=M.columns)throw new RangeError("column indices are out of range")}function Op(M,e,t,r,o){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Uo("startRow",e),Uo("endRow",t),Uo("startColumn",r),Uo("endColumn",o),e>t||r>o||e<0||e>=M.rows||t<0||t>=M.rows||r<0||r>=M.columns||o<0||o>=M.columns)throw new RangeError("Submatrix indices are out of range")}function $o(M,e=0){let t=[];for(let r=0;r<M;r++)t.push(e);return t}function Uo(M,e){if(typeof e!="number")throw new TypeError(`${M} must be a number`)}function Dr(M){if(M.isEmpty())throw new Error("Empty matrix has no elements to index")}function N6(M){let e=$o(M.rows);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[t]+=M.get(t,r);return e}function y6(M){let e=$o(M.columns);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[r]+=M.get(t,r);return e}function B6(M){let e=0;for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)e+=M.get(t,r);return e}function w6(M){let e=$o(M.rows,1);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[t]*=M.get(t,r);return e}function D6(M){let e=$o(M.columns,1);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[r]*=M.get(t,r);return e}function X6(M){let e=1;for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)e*=M.get(t,r);return e}function E6(M,e,t){const r=M.rows,o=M.columns,n=[];for(let b=0;b<r;b++){let z=0,i=0,s=0;for(let a=0;a<o;a++)s=M.get(b,a)-t[b],z+=s,i+=s*s;e?n.push((i-z*z/o)/(o-1)):n.push((i-z*z/o)/o)}return n}function T6(M,e,t){const r=M.rows,o=M.columns,n=[];for(let b=0;b<o;b++){let z=0,i=0,s=0;for(let a=0;a<r;a++)s=M.get(a,b)-t[b],z+=s,i+=s*s;e?n.push((i-z*z/r)/(r-1)):n.push((i-z*z/r)/r)}return n}function C6(M,e,t){const r=M.rows,o=M.columns,n=r*o;let b=0,z=0,i=0;for(let s=0;s<r;s++)for(let a=0;a<o;a++)i=M.get(s,a)-t,b+=i,z+=i*i;return e?(z-b*b/n)/(n-1):(z-b*b/n)/n}function x6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)-e[t])}function S6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)-e[r])}function F6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)-e)}function I6(M){const e=[];for(let t=0;t<M.rows;t++){let r=0;for(let o=0;o<M.columns;o++)r+=Math.pow(M.get(t,o),2)/(M.columns-1);e.push(Math.sqrt(r))}return e}function P6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)/e[t])}function k6(M){const e=[];for(let t=0;t<M.columns;t++){let r=0;for(let o=0;o<M.rows;o++)r+=Math.pow(M.get(o,t),2)/(M.rows-1);e.push(Math.sqrt(r))}return e}function $6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)/e[r])}function U6(M){const e=M.size-1;let t=0;for(let r=0;r<M.columns;r++)for(let o=0;o<M.rows;o++)t+=Math.pow(M.get(o,r),2)/e;return Math.sqrt(t)}function j6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)/e)}class U0{static from1DArray(e,t,r){if(e*t!==r.length)throw new RangeError("data length does not match given dimensions");let n=new l0(e,t);for(let b=0;b<e;b++)for(let z=0;z<t;z++)n.set(b,z,r[b*t+z]);return n}static rowVector(e){let t=new l0(1,e.length);for(let r=0;r<e.length;r++)t.set(0,r,e[r]);return t}static columnVector(e){let t=new l0(e.length,1);for(let r=0;r<e.length;r++)t.set(r,0,e[r]);return t}static zeros(e,t){return new l0(e,t)}static ones(e,t){return new l0(e,t).fill(1)}static rand(e,t,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:o=Math.random}=r;let n=new l0(e,t);for(let b=0;b<e;b++)for(let z=0;z<t;z++)n.set(b,z,o());return n}static randInt(e,t,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:o=0,max:n=1e3,random:b=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(n))throw new TypeError("max must be an integer");if(o>=n)throw new RangeError("min must be smaller than max");let z=n-o,i=new l0(e,t);for(let s=0;s<e;s++)for(let a=0;a<t;a++){let O=o+Math.round(b()*z);i.set(s,a,O)}return i}static eye(e,t,r){t===void 0&&(t=e),r===void 0&&(r=1);let o=Math.min(e,t),n=this.zeros(e,t);for(let b=0;b<o;b++)n.set(b,b,r);return n}static diag(e,t,r){let o=e.length;t===void 0&&(t=o),r===void 0&&(r=t);let n=Math.min(o,t,r),b=this.zeros(t,r);for(let z=0;z<n;z++)b.set(z,z,e[z]);return b}static min(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,o=e.columns,n=new l0(r,o);for(let b=0;b<r;b++)for(let z=0;z<o;z++)n.set(b,z,Math.min(e.get(b,z),t.get(b,z)));return n}static max(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,o=e.columns,n=new this(r,o);for(let b=0;b<r;b++)for(let z=0;z<o;z++)n.set(b,z,Math.max(e.get(b,z),t.get(b,z)));return n}static checkMatrix(e){return U0.isMatrix(e)?e:new l0(e)}static isMatrix(e){return e!=null&&e.klass==="Matrix"}get size(){return this.rows*this.columns}apply(e){if(typeof e!="function")throw new TypeError("callback must be a function");for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.call(this,t,r);return this}to1DArray(){let e=[];for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}to2DArray(){let e=[];for(let t=0;t<this.rows;t++){e.push([]);for(let r=0;r<this.columns;r++)e[t].push(this.get(t,r))}return e}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 e=0;e<this.rows;e++)for(let t=0;t<=e;t++)if(this.get(e,t)!==this.get(t,e))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let e=0;e<this.rows;e++)if(this.get(e,e)!==0)return!1;return!0}isEchelonForm(){let e=0,t=0,r=-1,o=!0,n=!1;for(;e<this.rows&&o;){for(t=0,n=!1;t<this.columns&&n===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(n=!0,r=t):(o=!1,n=!0);e++}return o}isReducedEchelonForm(){let e=0,t=0,r=-1,o=!0,n=!1;for(;e<this.rows&&o;){for(t=0,n=!1;t<this.columns&&n===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(n=!0,r=t):(o=!1,n=!0);for(let b=t+1;b<this.rows;b++)this.get(e,b)!==0&&(o=!1);e++}return o}echelonForm(){let e=this.clone(),t=0,r=0;for(;t<e.rows&&r<e.columns;){let o=t;for(let n=t;n<e.rows;n++)e.get(n,r)>e.get(o,r)&&(o=n);if(e.get(o,r)===0)r++;else{e.swapRows(t,o);let n=e.get(t,r);for(let b=r;b<e.columns;b++)e.set(t,b,e.get(t,b)/n);for(let b=t+1;b<e.rows;b++){let z=e.get(b,r)/e.get(t,r);e.set(b,r,0);for(let i=r+1;i<e.columns;i++)e.set(b,i,e.get(b,i)-e.get(t,i)*z)}t++,r++}}return e}reducedEchelonForm(){let e=this.echelonForm(),t=e.columns,r=e.rows,o=r-1;for(;o>=0;)if(e.maxRow(o)===0)o--;else{let n=0,b=!1;for(;n<r&&b===!1;)e.get(o,n)===1?b=!0:n++;for(let z=0;z<o;z++){let i=e.get(z,n);for(let s=n;s<t;s++){let a=e.get(z,s)-i*e.get(o,s);e.set(z,s,a)}}o--}return e}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{rows:t=1,columns:r=1}=e;if(!Number.isInteger(t)||t<=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 o=new l0(this.rows*t,this.columns*r);for(let n=0;n<t;n++)for(let b=0;b<r;b++)o.setSubMatrix(this,this.rows*n,this.columns*b);return o}fill(e){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,e);return this}neg(){return this.mulS(-1)}getRow(e){ne(this,e);let t=[];for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}getRowVector(e){return l0.rowVector(this.getRow(e))}setRow(e,t){ne(this,e),t=Br(this,t);for(let r=0;r<this.columns;r++)this.set(e,r,t[r]);return this}swapRows(e,t){ne(this,e),ne(this,t);for(let r=0;r<this.columns;r++){let o=this.get(e,r);this.set(e,r,this.get(t,r)),this.set(t,r,o)}return this}getColumn(e){be(this,e);let t=[];for(let r=0;r<this.rows;r++)t.push(this.get(r,e));return t}getColumnVector(e){return l0.columnVector(this.getColumn(e))}setColumn(e,t){be(this,e),t=wr(this,t);for(let r=0;r<this.rows;r++)this.set(r,e,t[r]);return this}swapColumns(e,t){be(this,e),be(this,t);for(let r=0;r<this.rows;r++){let o=this.get(r,e);this.set(r,e,this.get(r,t)),this.set(r,t,o)}return this}addRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[r]);return this}subRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[r]);return this}mulRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[r]);return this}divRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[r]);return this}addColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[t]);return this}subColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[t]);return this}mulColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[t]);return this}divColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[t]);return this}mulRow(e,t){ne(this,e);for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this}mulColumn(e,t){be(this,e);for(let r=0;r<this.rows;r++)this.set(r,e,this.get(r,e)*t);return this}max(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t[r]&&(t[r]=this.get(r,o));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t[o]&&(t[o]=this.get(r,o));return t}case void 0:{let t=this.get(0,0);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o));return t}default:throw new Error(`invalid option: ${e}`)}}maxIndex(){Dr(this);let e=this.get(0,0),t=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>e&&(e=this.get(r,o),t[0]=r,t[1]=o);return t}min(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t[r]&&(t[r]=this.get(r,o));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t[o]&&(t[o]=this.get(r,o));return t}case void 0:{let t=this.get(0,0);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o));return t}default:throw new Error(`invalid option: ${e}`)}}minIndex(){Dr(this);let e=this.get(0,0),t=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<e&&(e=this.get(r,o),t[0]=r,t[1]=o);return t}maxRow(e){if(ne(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxRowIndex(e){ne(this,e),Dr(this);let t=this.get(e,0),r=[e,0];for(let o=1;o<this.columns;o++)this.get(e,o)>t&&(t=this.get(e,o),r[1]=o);return r}minRow(e){if(ne(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minRowIndex(e){ne(this,e),Dr(this);let t=this.get(e,0),r=[e,0];for(let o=1;o<this.columns;o++)this.get(e,o)<t&&(t=this.get(e,o),r[1]=o);return r}maxColumn(e){if(be(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)>t&&(t=this.get(r,e));return t}maxColumnIndex(e){be(this,e),Dr(this);let t=this.get(0,e),r=[0,e];for(let o=1;o<this.rows;o++)this.get(o,e)>t&&(t=this.get(o,e),r[0]=o);return r}minColumn(e){if(be(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)<t&&(t=this.get(r,e));return t}minColumnIndex(e){be(this,e),Dr(this);let t=this.get(0,e),r=[0,e];for(let o=1;o<this.rows;o++)this.get(o,e)<t&&(t=this.get(o,e),r[0]=o);return r}diag(){let e=Math.min(this.rows,this.columns),t=[];for(let r=0;r<e;r++)t.push(this.get(r,r));return t}norm(e="frobenius"){switch(e){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${e}`)}}cumulativeSum(){let e=0;for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r),this.set(t,r,e);return this}dot(e){U0.isMatrix(e)&&(e=e.to1DArray());let t=this.to1DArray();if(t.length!==e.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<t.length;o++)r+=t[o]*e[o];return r}mmul(e){e=l0.checkMatrix(e);let t=this.rows,r=this.columns,o=e.columns,n=new l0(t,o),b=new Float64Array(r);for(let z=0;z<o;z++){for(let i=0;i<r;i++)b[i]=e.get(i,z);for(let i=0;i<t;i++){let s=0;for(let a=0;a<r;a++)s+=this.get(i,a)*b[a];n.set(i,z,s)}}return n}strassen2x2(e){e=l0.checkMatrix(e);let t=new l0(2,2);const r=this.get(0,0),o=e.get(0,0),n=this.get(0,1),b=e.get(0,1),z=this.get(1,0),i=e.get(1,0),s=this.get(1,1),a=e.get(1,1),O=(r+s)*(o+a),u=(z+s)*o,l=r*(b-a),d=s*(i-o),A=(r+n)*a,h=(z-r)*(o+b),q=(n-s)*(i+a),_=O+d-A+q,m=l+A,L=u+d,g=O-u+l+h;return t.set(0,0,_),t.set(0,1,m),t.set(1,0,L),t.set(1,1,g),t}strassen3x3(e){e=l0.checkMatrix(e);let t=new l0(3,3);const r=this.get(0,0),o=this.get(0,1),n=this.get(0,2),b=this.get(1,0),z=this.get(1,1),i=this.get(1,2),s=this.get(2,0),a=this.get(2,1),O=this.get(2,2),u=e.get(0,0),l=e.get(0,1),d=e.get(0,2),A=e.get(1,0),h=e.get(1,1),q=e.get(1,2),_=e.get(2,0),m=e.get(2,1),L=e.get(2,2),g=(r+o+n-b-z-a-O)*h,v=(r-b)*(-l+h),y=z*(-u+l+A-h-q-_+L),X=(-r+b+z)*(u-l+h),T=(b+z)*(-u+l),N=r*u,D=(-r+s+a)*(u-d+q),C=(-r+s)*(d-q),P=(s+a)*(-u+d),H=(r+o+n-z-i-s-a)*q,G=a*(-u+d+A-h-q-_+m),k=(-n+a+O)*(h+_-m),J=(n-O)*(h-m),o0=n*_,z0=(a+O)*(-_+m),a0=(-n+z+i)*(q+_-L),v0=(n-i)*(q-L),w0=(z+i)*(-_+L),u0=o*A,I0=i*m,S0=b*d,F0=s*l,W0=O*L,b1=N+o0+u0,J0=g+X+T+N+k+o0+z0,p1=N+D+P+H+o0+a0+w0,Z1=v+y+X+N+o0+a0+v0,d1=v+X+T+N+I0,F=o0+a0+v0+w0+S0,K=N+D+C+G+k+J+o0,Z=k+J+o0+z0+F0,O0=N+D+C+P+W0;return t.set(0,0,b1),t.set(0,1,J0),t.set(0,2,p1),t.set(1,0,Z1),t.set(1,1,d1),t.set(1,2,F),t.set(2,0,K),t.set(2,1,Z),t.set(2,2,O0),t}mmulStrassen(e){e=l0.checkMatrix(e);let t=this.clone(),r=t.rows,o=t.columns,n=e.rows,b=e.columns;o!==n&&console.warn(`Multiplying ${r} x ${o} and ${n} x ${b} matrix: dimensions do not match.`);function z(O,u,l){let d=O.rows,A=O.columns;if(d===u&&A===l)return O;{let h=U0.zeros(u,l);return h=h.setSubMatrix(O,0,0),h}}let i=Math.max(r,n),s=Math.max(o,b);t=z(t,i,s),e=z(e,i,s);function a(O,u,l,d){if(l<=512||d<=512)return O.mmul(u);l%2===1&&d%2===1?(O=z(O,l+1,d+1),u=z(u,l+1,d+1)):l%2===1?(O=z(O,l+1,d),u=z(u,l+1,d)):d%2===1&&(O=z(O,l,d+1),u=z(u,l,d+1));let A=parseInt(O.rows/2,10),h=parseInt(O.columns/2,10),q=O.subMatrix(0,A-1,0,h-1),_=u.subMatrix(0,A-1,0,h-1),m=O.subMatrix(0,A-1,h,O.columns-1),L=u.subMatrix(0,A-1,h,u.columns-1),g=O.subMatrix(A,O.rows-1,0,h-1),v=u.subMatrix(A,u.rows-1,0,h-1),y=O.subMatrix(A,O.rows-1,h,O.columns-1),X=u.subMatrix(A,u.rows-1,h,u.columns-1),T=a(U0.add(q,y),U0.add(_,X),A,h),N=a(U0.add(g,y),_,A,h),D=a(q,U0.sub(L,X),A,h),C=a(y,U0.sub(v,_),A,h),P=a(U0.add(q,m),X,A,h),H=a(U0.sub(g,q),U0.add(_,L),A,h),G=a(U0.sub(m,y),U0.add(v,X),A,h),k=U0.add(T,C);k.sub(P),k.add(G);let J=U0.add(D,P),o0=U0.add(N,C),z0=U0.sub(T,N);z0.add(D),z0.add(H);let a0=U0.zeros(2*k.rows,2*k.columns);return a0=a0.setSubMatrix(k,0,0),a0=a0.setSubMatrix(J,k.rows,0),a0=a0.setSubMatrix(o0,0,k.columns),a0=a0.setSubMatrix(z0,k.rows,k.columns),a0.subMatrix(0,l-1,0,d-1)}return a(t,e,i,s)}scaleRows(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let o=new l0(this.rows,this.columns);for(let n=0;n<this.rows;n++){const b=this.getRow(n);b.length>0&&q3(b,{min:t,max:r,output:b}),o.setRow(n,b)}return o}scaleColumns(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let o=new l0(this.rows,this.columns);for(let n=0;n<this.columns;n++){const b=this.getColumn(n);b.length&&q3(b,{min:t,max:r,output:b}),o.setColumn(n,b)}return o}flipRows(){const e=Math.ceil(this.columns/2);for(let t=0;t<this.rows;t++)for(let r=0;r<e;r++){let o=this.get(t,r),n=this.get(t,this.columns-1-r);this.set(t,r,n),this.set(t,this.columns-1-r,o)}return this}flipColumns(){const e=Math.ceil(this.rows/2);for(let t=0;t<this.columns;t++)for(let r=0;r<e;r++){let o=this.get(r,t),n=this.get(this.rows-1-r,t);this.set(r,t,n),this.set(this.rows-1-r,t,o)}return this}kroneckerProduct(e){e=l0.checkMatrix(e);let t=this.rows,r=this.columns,o=e.rows,n=e.columns,b=new l0(t*o,r*n);for(let z=0;z<t;z++)for(let i=0;i<r;i++)for(let s=0;s<o;s++)for(let a=0;a<n;a++)b.set(o*z+s,n*i+a,this.get(z,i)*e.get(s,a));return b}kroneckerSum(e){if(e=l0.checkMatrix(e),!this.isSquare()||!e.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let t=this.rows,r=e.rows,o=this.kroneckerProduct(l0.eye(r,r)),n=l0.eye(t,t).kroneckerProduct(e);return o.add(n)}transpose(){let e=new l0(this.columns,this.rows);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.set(r,t,this.get(t,r));return e}sortRows(e=_3){for(let t=0;t<this.rows;t++)this.setRow(t,this.getRow(t).sort(e));return this}sortColumns(e=_3){for(let t=0;t<this.columns;t++)this.setColumn(t,this.getColumn(t).sort(e));return this}subMatrix(e,t,r,o){Op(this,e,t,r,o);let n=new l0(t-e+1,o-r+1);for(let b=e;b<=t;b++)for(let z=r;z<=o;z++)n.set(b-e,z-r,this.get(b,z));return n}subMatrixRow(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.columns-1),t>r||t<0||t>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new l0(e.length,r-t+1);for(let n=0;n<e.length;n++)for(let b=t;b<=r;b++){if(e[n]<0||e[n]>=this.rows)throw new RangeError(`Row index out of range: ${e[n]}`);o.set(n,b-t,this.get(e[n],b))}return o}subMatrixColumn(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.rows-1),t>r||t<0||t>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new l0(r-t+1,e.length);for(let n=0;n<e.length;n++)for(let b=t;b<=r;b++){if(e[n]<0||e[n]>=this.columns)throw new RangeError(`Column index out of range: ${e[n]}`);o.set(b-t,n,this.get(b,e[n]))}return o}setSubMatrix(e,t,r){if(e=l0.checkMatrix(e),e.isEmpty())return this;let o=t+e.rows-1,n=r+e.columns-1;Op(this,t,o,r,n);for(let b=0;b<e.rows;b++)for(let z=0;z<e.columns;z++)this.set(t+b,r+z,e.get(b,z));return this}selection(e,t){cp(this,e),sp(this,t);let r=new l0(e.length,t.length);for(let o=0;o<e.length;o++){let n=e[o];for(let b=0;b<t.length;b++){let z=t[b];r.set(o,b,this.get(n,z))}}return r}trace(){let e=Math.min(this.rows,this.columns),t=0;for(let r=0;r<e;r++)t+=this.get(r,r);return t}clone(){return this.constructor.copy(this,new l0(this.rows,this.columns))}static copy(e,t){for(const[r,o,n]of e.entries())t.set(r,o,n);return t}sum(e){switch(e){case"row":return N6(this);case"column":return y6(this);case void 0:return B6(this);default:throw new Error(`invalid option: ${e}`)}}product(e){switch(e){case"row":return w6(this);case"column":return D6(this);case void 0:return X6(this);default:throw new Error(`invalid option: ${e}`)}}mean(e){const t=this.sum(e);switch(e){case"row":{for(let r=0;r<this.rows;r++)t[r]/=this.columns;return t}case"column":{for(let r=0;r<this.columns;r++)t[r]/=this.rows;return t}case void 0:return t/this.size;default:throw new Error(`invalid option: ${e}`)}}variance(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(e)}=t;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(e){case"row":{if(!C2.isAnyArray(o))throw new TypeError("mean must be an array");return E6(this,r,o)}case"column":{if(!C2.isAnyArray(o))throw new TypeError("mean must be an array");return T6(this,r,o)}case void 0:{if(typeof o!="number")throw new TypeError("mean must be a number");return C6(this,r,o)}default:throw new Error(`invalid option: ${e}`)}}standardDeviation(e,t){typeof e=="object"&&(t=e,e=void 0);const r=this.variance(e,t);if(e===void 0)return Math.sqrt(r);for(let o=0;o<r.length;o++)r[o]=Math.sqrt(r[o]);return r}center(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{center:r=this.mean(e)}=t;switch(e){case"row":{if(!C2.isAnyArray(r))throw new TypeError("center must be an array");return x6(this,r),this}case"column":{if(!C2.isAnyArray(r))throw new TypeError("center must be an array");return S6(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return F6(this,r),this}default:throw new Error(`invalid option: ${e}`)}}scale(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");let r=t.scale;switch(e){case"row":{if(r===void 0)r=I6(this);else if(!C2.isAnyArray(r))throw new TypeError("scale must be an array");return P6(this,r),this}case"column":{if(r===void 0)r=k6(this);else if(!C2.isAnyArray(r))throw new TypeError("scale must be an array");return $6(this,r),this}case void 0:{if(r===void 0)r=U6(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return j6(this,r),this}default:throw new Error(`invalid option: ${e}`)}}toString(e){return h3(this,e)}[Symbol.iterator](){return this.entries()}*entries(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield[e,t,this.get(e,t)]}*values(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield this.get(e,t)}}U0.prototype.klass="Matrix",typeof Symbol<"u"&&(U0.prototype[Symbol.for("nodejs.util.inspect.custom")]=g6);function _3(M,e){return M-e}function H6(M){return M.every(e=>typeof e=="number")}U0.random=U0.rand,U0.randomInt=U0.randInt,U0.diagonal=U0.diag,U0.prototype.diagonal=U0.prototype.diag,U0.identity=U0.eye,U0.prototype.negate=U0.prototype.neg,U0.prototype.tensorProduct=U0.prototype.kroneckerProduct;let l0=(Sr=class extends U0{constructor(t,r){super();ni(this,mM);E(this,"data");if(Sr.isMatrix(t))bi(this,mM,pi).call(this,t.rows,t.columns),Sr.copy(t,this);else if(Number.isInteger(t)&&t>=0)bi(this,mM,pi).call(this,t,r);else if(C2.isAnyArray(t)){const o=t;if(t=o.length,r=t?o[0].length:0,typeof r!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(o[n].length!==r)throw new RangeError("Inconsistent array dimensions");if(!H6(o[n]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(o[n]))}this.rows=t,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(t,r,o){return this.data[t][r]=o,this}get(t,r){return this.data[t][r]}removeRow(t){return ne(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,r){return r===void 0&&(r=t,t=this.rows),ne(this,t,!0),r=Float64Array.from(Br(this,r)),this.data.splice(t,0,r),this.rows+=1,this}removeColumn(t){be(this,t);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns-1);for(let n=0;n<t;n++)o[n]=this.data[r][n];for(let n=t+1;n<this.columns;n++)o[n-1]=this.data[r][n];this.data[r]=o}return this.columns-=1,this}addColumn(t,r){typeof r>"u"&&(r=t,t=this.columns),be(this,t,!0),r=wr(this,r);for(let o=0;o<this.rows;o++){const n=new Float64Array(this.columns+1);let b=0;for(;b<t;b++)n[b]=this.data[o][b];for(n[b++]=r[o];b<this.columns+1;b++)n[b]=this.data[o][b-1];this.data[o]=n}return this.columns+=1,this}},mM=new WeakSet,pi=function(t,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let o=0;o<t;o++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=t,this.columns=r},Sr);v6(U0,l0);const On=class On extends U0{constructor(t){super();ni(this,_2,void 0);if(l0.isMatrix(t)){if(!t.isSymmetric())throw new TypeError("not symmetric data");Mb(this,_2,l0.copy(t,new l0(t.rows,t.rows)))}else if(Number.isInteger(t)&&t>=0)Mb(this,_2,new l0(t,t));else if(Mb(this,_2,new l0(t)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return ye(this,_2).size}get rows(){return ye(this,_2).rows}get columns(){return ye(this,_2).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(t){return l0.isMatrix(t)&&t.klassType==="SymmetricMatrix"}static zeros(t){return new this(t)}static ones(t){return new this(t).fill(1)}clone(){const t=new On(this.diagonalSize);for(const[r,o,n]of this.upperRightEntries())t.set(r,o,n);return t}toMatrix(){return new l0(this)}get(t,r){return ye(this,_2).get(t,r)}set(t,r,o){return ye(this,_2).set(t,r,o),ye(this,_2).set(r,t,o),this}removeCross(t){return ye(this,_2).removeRow(t),ye(this,_2).removeColumn(t),this}addCross(t,r){r===void 0&&(r=t,t=this.diagonalSize);const o=r.slice();return o.splice(t,1),ye(this,_2).addRow(t,o),ye(this,_2).addColumn(t,r),this}applyMask(t){if(t.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[o,n]of t.entries())n||r.push(o);r.reverse();for(const o of r)this.removeCross(o);return this}toCompact(){const{diagonalSize:t}=this,r=new Array(t*(t+1)/2);for(let o=0,n=0,b=0;b<r.length;b++)r[b]=this.get(n,o),++o>=t&&(o=++n);return r}static fromCompact(t){const r=t.length,o=(Math.sqrt(8*r+1)-1)/2;if(!Number.isInteger(o))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(t)}`);const n=new On(o);for(let b=0,z=0,i=0;i<r;i++)n.set(b,z,t[i]),++b>=o&&(b=++z);return n}*upperRightEntries(){for(let t=0,r=0;t<this.diagonalSize;void 0){const o=this.get(t,r);yield[t,r,o],++r>=this.diagonalSize&&(r=++t)}}*upperRightValues(){for(let t=0,r=0;t<this.diagonalSize;void 0)yield this.get(t,r),++r>=this.diagonalSize&&(r=++t)}};_2=new WeakMap;let Yt=On;Yt.prototype.klassType="SymmetricMatrix";class jo extends Yt{static isDistanceMatrix(e){return Yt.isSymmetricMatrix(e)&&e.klassSubType==="DistanceMatrix"}constructor(e){if(super(e),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(e,t,r){return e===t&&(r=0),super.set(e,t,r)}addCross(e,t){return t===void 0&&(t=e,e=this.diagonalSize),t=t.slice(),t[e]=0,super.addCross(e,t)}toSymmetricMatrix(){return new Yt(this)}clone(){const e=new jo(this.diagonalSize);for(const[t,r,o]of this.upperRightEntries())t!==r&&e.set(t,r,o);return e}toCompact(){const{diagonalSize:e}=this,t=(e-1)*e/2,r=new Array(t);for(let o=1,n=0,b=0;b<r.length;b++)r[b]=this.get(n,o),++o>=e&&(o=++n+1);return r}static fromCompact(e){const t=e.length,r=(Math.sqrt(8*t+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(e)}`);const o=new this(r);for(let n=1,b=0,z=0;z<t;z++)o.set(n,b,e[z]),++n>=r&&(n=++b+1);return o}}jo.prototype.klassSubType="DistanceMatrix";class rt extends U0{constructor(e,t,r){super(),this.matrix=e,this.rows=t,this.columns=r}}class Y6 extends rt{constructor(e,t){be(e,t),super(e,e.rows,1),this.column=t}set(e,t,r){return this.matrix.set(e,this.column,r),this}get(e){return this.matrix.get(e,this.column)}}class G6 extends rt{constructor(e,t){sp(e,t),super(e,e.rows,t.length),this.columnIndices=t}set(e,t,r){return this.matrix.set(e,this.columnIndices[t],r),this}get(e,t){return this.matrix.get(e,this.columnIndices[t])}}class V6 extends rt{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(e,this.columns-t-1,r),this}get(e,t){return this.matrix.get(e,this.columns-t-1)}}class K6 extends rt{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(this.rows-e-1,t,r),this}get(e,t){return this.matrix.get(this.rows-e-1,t)}}class J6 extends rt{constructor(e,t){ne(e,t),super(e,1,e.columns),this.row=t}set(e,t,r){return this.matrix.set(this.row,t,r),this}get(e,t){return this.matrix.get(this.row,t)}}class Q6 extends rt{constructor(e,t){cp(e,t),super(e,t.length,e.columns),this.rowIndices=t}set(e,t,r){return this.matrix.set(this.rowIndices[e],t,r),this}get(e,t){return this.matrix.get(this.rowIndices[e],t)}}class Ho extends rt{constructor(e,t,r){cp(e,t),sp(e,r),super(e,t.length,r.length),this.rowIndices=t,this.columnIndices=r}set(e,t,r){return this.matrix.set(this.rowIndices[e],this.columnIndices[t],r),this}get(e,t){return this.matrix.get(this.rowIndices[e],this.columnIndices[t])}}class Z6 extends rt{constructor(e,t,r,o,n){Op(e,t,r,o,n),super(e,r-t+1,n-o+1),this.startRow=t,this.startColumn=o}set(e,t,r){return this.matrix.set(this.startRow+e,this.startColumn+t,r),this}get(e,t){return this.matrix.get(this.startRow+e,this.startColumn+t)}}class e_ extends rt{constructor(e){super(e,e.columns,e.rows)}set(e,t,r){return this.matrix.set(t,e,r),this}get(e,t){return this.matrix.get(t,e)}}class m3 extends U0{constructor(e,t={}){const{rows:r=1}=t;if(e.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=e.length/r,this.data=e}set(e,t,r){let o=this._calculateIndex(e,t);return this.data[o]=r,this}get(e,t){let r=this._calculateIndex(e,t);return this.data[r]}_calculateIndex(e,t){return e*this.columns+t}}class j2 extends U0{constructor(e){super(),this.data=e,this.rows=e.length,this.columns=e[0].length}set(e,t,r){return this.data[e][t]=r,this}get(e,t){return this.data[e][t]}}function t_(M,e){if(C2.isAnyArray(M))return M[0]&&C2.isAnyArray(M[0])?new j2(M):new m3(M,e);throw new Error("the argument is not an array")}class Yo{constructor(e){e=j2.checkMatrix(e);let t=e.clone(),r=t.rows,o=t.columns,n=new Float64Array(r),b=1,z,i,s,a,O,u,l,d,A;for(z=0;z<r;z++)n[z]=z;for(d=new Float64Array(r),i=0;i<o;i++){for(z=0;z<r;z++)d[z]=t.get(z,i);for(z=0;z<r;z++){for(A=Math.min(z,i),O=0,s=0;s<A;s++)O+=t.get(z,s)*d[s];d[z]-=O,t.set(z,i,d[z])}for(a=i,z=i+1;z<r;z++)Math.abs(d[z])>Math.abs(d[a])&&(a=z);if(a!==i){for(s=0;s<o;s++)u=t.get(a,s),t.set(a,s,t.get(i,s)),t.set(i,s,u);l=n[a],n[a]=n[i],n[i]=l,b=-b}if(i<r&&t.get(i,i)!==0)for(z=i+1;z<r;z++)t.set(z,i,t.get(z,i)/t.get(i,i))}this.LU=t,this.pivotVector=n,this.pivotSign=b}isSingular(){let e=this.LU,t=e.columns;for(let r=0;r<t;r++)if(e.get(r,r)===0)return!0;return!1}solve(e){e=l0.checkMatrix(e);let t=this.LU;if(t.rows!==e.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let o=e.columns,n=e.subMatrixRow(this.pivotVector,0,o-1),b=t.columns,z,i,s;for(s=0;s<b;s++)for(z=s+1;z<b;z++)for(i=0;i<o;i++)n.set(z,i,n.get(z,i)-n.get(s,i)*t.get(z,s));for(s=b-1;s>=0;s--){for(i=0;i<o;i++)n.set(s,i,n.get(s,i)/t.get(s,s));for(z=0;z<s;z++)for(i=0;i<o;i++)n.set(z,i,n.get(z,i)-n.get(s,i)*t.get(z,s))}return n}get determinant(){let e=this.LU;if(!e.isSquare())throw new Error("Matrix must be square");let t=this.pivotSign,r=e.columns;for(let o=0;o<r;o++)t*=e.get(o,o);return t}get lowerTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,o=new l0(t,r);for(let n=0;n<t;n++)for(let b=0;b<r;b++)n>b?o.set(n,b,e.get(n,b)):n===b?o.set(n,b,1):o.set(n,b,0);return o}get upperTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,o=new l0(t,r);for(let n=0;n<t;n++)for(let b=0;b<r;b++)n<=b?o.set(n,b,e.get(n,b)):o.set(n,b,0);return o}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function Mt(M,e){let t=0;return Math.abs(M)>Math.abs(e)?(t=e/M,Math.abs(M)*Math.sqrt(1+t*t)):e!==0?(t=M/e,Math.abs(e)*Math.sqrt(1+t*t)):0}class ap{constructor(e){e=j2.checkMatrix(e);let t=e.clone(),r=e.rows,o=e.columns,n=new Float64Array(o),b,z,i,s;for(i=0;i<o;i++){let a=0;for(b=i;b<r;b++)a=Mt(a,t.get(b,i));if(a!==0){for(t.get(i,i)<0&&(a=-a),b=i;b<r;b++)t.set(b,i,t.get(b,i)/a);for(t.set(i,i,t.get(i,i)+1),z=i+1;z<o;z++){for(s=0,b=i;b<r;b++)s+=t.get(b,i)*t.get(b,z);for(s=-s/t.get(i,i),b=i;b<r;b++)t.set(b,z,t.get(b,z)+s*t.get(b,i))}}n[i]=-a}this.QR=t,this.Rdiag=n}solve(e){e=l0.checkMatrix(e);let t=this.QR,r=t.rows;if(e.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let o=e.columns,n=e.clone(),b=t.columns,z,i,s,a;for(s=0;s<b;s++)for(i=0;i<o;i++){for(a=0,z=s;z<r;z++)a+=t.get(z,s)*n.get(z,i);for(a=-a/t.get(s,s),z=s;z<r;z++)n.set(z,i,n.get(z,i)+a*t.get(z,s))}for(s=b-1;s>=0;s--){for(i=0;i<o;i++)n.set(s,i,n.get(s,i)/this.Rdiag[s]);for(z=0;z<s;z++)for(i=0;i<o;i++)n.set(z,i,n.get(z,i)-n.get(s,i)*t.get(z,s))}return n.subMatrix(0,b-1,0,o-1)}isFullRank(){let e=this.QR.columns;for(let t=0;t<e;t++)if(this.Rdiag[t]===0)return!1;return!0}get upperTriangularMatrix(){let e=this.QR,t=e.columns,r=new l0(t,t),o,n;for(o=0;o<t;o++)for(n=0;n<t;n++)o<n?r.set(o,n,e.get(o,n)):o===n?r.set(o,n,this.Rdiag[o]):r.set(o,n,0);return r}get orthogonalMatrix(){let e=this.QR,t=e.rows,r=e.columns,o=new l0(t,r),n,b,z,i;for(z=r-1;z>=0;z--){for(n=0;n<t;n++)o.set(n,z,0);for(o.set(z,z,1),b=z;b<r;b++)if(e.get(z,z)!==0){for(i=0,n=z;n<t;n++)i+=e.get(n,z)*o.get(n,b);for(i=-i/e.get(z,z),n=z;n<t;n++)o.set(n,b,o.get(n,b)+i*e.get(n,z))}}return o}}class Xr{constructor(e,t={}){if(e=j2.checkMatrix(e),e.isEmpty())throw new Error("Matrix must be non-empty");let r=e.rows,o=e.columns;const{computeLeftSingularVectors:n=!0,computeRightSingularVectors:b=!0,autoTranspose:z=!1}=t;let i=!!n,s=!!b,a=!1,O;if(r<o)if(!z)O=e.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{O=e.transpose(),r=O.rows,o=O.columns,a=!0;let N=i;i=s,s=N}else O=e.clone();let u=Math.min(r,o),l=Math.min(r+1,o),d=new Float64Array(l),A=new l0(r,u),h=new l0(o,o),q=new Float64Array(o),_=new Float64Array(r),m=new Float64Array(l);for(let N=0;N<l;N++)m[N]=N;let L=Math.min(r-1,o),g=Math.max(0,Math.min(o-2,r)),v=Math.max(L,g);for(let N=0;N<v;N++){if(N<L){d[N]=0;for(let D=N;D<r;D++)d[N]=Mt(d[N],O.get(D,N));if(d[N]!==0){O.get(N,N)<0&&(d[N]=-d[N]);for(let D=N;D<r;D++)O.set(D,N,O.get(D,N)/d[N]);O.set(N,N,O.get(N,N)+1)}d[N]=-d[N]}for(let D=N+1;D<o;D++){if(N<L&&d[N]!==0){let C=0;for(let P=N;P<r;P++)C+=O.get(P,N)*O.get(P,D);C=-C/O.get(N,N);for(let P=N;P<r;P++)O.set(P,D,O.get(P,D)+C*O.get(P,N))}q[D]=O.get(N,D)}if(i&&N<L)for(let D=N;D<r;D++)A.set(D,N,O.get(D,N));if(N<g){q[N]=0;for(let D=N+1;D<o;D++)q[N]=Mt(q[N],q[D]);if(q[N]!==0){q[N+1]<0&&(q[N]=0-q[N]);for(let D=N+1;D<o;D++)q[D]/=q[N];q[N+1]+=1}if(q[N]=-q[N],N+1<r&&q[N]!==0){for(let D=N+1;D<r;D++)_[D]=0;for(let D=N+1;D<r;D++)for(let C=N+1;C<o;C++)_[D]+=q[C]*O.get(D,C);for(let D=N+1;D<o;D++){let C=-q[D]/q[N+1];for(let P=N+1;P<r;P++)O.set(P,D,O.get(P,D)+C*_[P])}}if(s)for(let D=N+1;D<o;D++)h.set(D,N,q[D])}}let y=Math.min(o,r+1);if(L<o&&(d[L]=O.get(L,L)),r<y&&(d[y-1]=0),g+1<y&&(q[g]=O.get(g,y-1)),q[y-1]=0,i){for(let N=L;N<u;N++){for(let D=0;D<r;D++)A.set(D,N,0);A.set(N,N,1)}for(let N=L-1;N>=0;N--)if(d[N]!==0){for(let D=N+1;D<u;D++){let C=0;for(let P=N;P<r;P++)C+=A.get(P,N)*A.get(P,D);C=-C/A.get(N,N);for(let P=N;P<r;P++)A.set(P,D,A.get(P,D)+C*A.get(P,N))}for(let D=N;D<r;D++)A.set(D,N,-A.get(D,N));A.set(N,N,1+A.get(N,N));for(let D=0;D<N-1;D++)A.set(D,N,0)}else{for(let D=0;D<r;D++)A.set(D,N,0);A.set(N,N,1)}}if(s)for(let N=o-1;N>=0;N--){if(N<g&&q[N]!==0)for(let D=N+1;D<o;D++){let C=0;for(let P=N+1;P<o;P++)C+=h.get(P,N)*h.get(P,D);C=-C/h.get(N+1,N);for(let P=N+1;P<o;P++)h.set(P,D,h.get(P,D)+C*h.get(P,N))}for(let D=0;D<o;D++)h.set(D,N,0);h.set(N,N,1)}let X=y-1,T=Number.EPSILON;for(;y>0;){let N,D;for(N=y-2;N>=-1&&N!==-1;N--){const C=Number.MIN_VALUE+T*Math.abs(d[N]+Math.abs(d[N+1]));if(Math.abs(q[N])<=C||Number.isNaN(q[N])){q[N]=0;break}}if(N===y-2)D=4;else{let C;for(C=y-1;C>=N&&C!==N;C--){let P=(C!==y?Math.abs(q[C]):0)+(C!==N+1?Math.abs(q[C-1]):0);if(Math.abs(d[C])<=T*P){d[C]=0;break}}C===N?D=3:C===y-1?D=1:(D=2,N=C)}switch(N++,D){case 1:{let C=q[y-2];q[y-2]=0;for(let P=y-2;P>=N;P--){let H=Mt(d[P],C),G=d[P]/H,k=C/H;if(d[P]=H,P!==N&&(C=-k*q[P-1],q[P-1]=G*q[P-1]),s)for(let J=0;J<o;J++)H=G*h.get(J,P)+k*h.get(J,y-1),h.set(J,y-1,-k*h.get(J,P)+G*h.get(J,y-1)),h.set(J,P,H)}break}case 2:{let C=q[N-1];q[N-1]=0;for(let P=N;P<y;P++){let H=Mt(d[P],C),G=d[P]/H,k=C/H;if(d[P]=H,C=-k*q[P],q[P]=G*q[P],i)for(let J=0;J<r;J++)H=G*A.get(J,P)+k*A.get(J,N-1),A.set(J,N-1,-k*A.get(J,P)+G*A.get(J,N-1)),A.set(J,P,H)}break}case 3:{const C=Math.max(Math.abs(d[y-1]),Math.abs(d[y-2]),Math.abs(q[y-2]),Math.abs(d[N]),Math.abs(q[N])),P=d[y-1]/C,H=d[y-2]/C,G=q[y-2]/C,k=d[N]/C,J=q[N]/C,o0=((H+P)*(H-P)+G*G)/2,z0=P*G*(P*G);let a0=0;(o0!==0||z0!==0)&&(o0<0?a0=0-Math.sqrt(o0*o0+z0):a0=Math.sqrt(o0*o0+z0),a0=z0/(o0+a0));let v0=(k+P)*(k-P)+a0,w0=k*J;for(let u0=N;u0<y-1;u0++){let I0=Mt(v0,w0);I0===0&&(I0=Number.MIN_VALUE);let S0=v0/I0,F0=w0/I0;if(u0!==N&&(q[u0-1]=I0),v0=S0*d[u0]+F0*q[u0],q[u0]=S0*q[u0]-F0*d[u0],w0=F0*d[u0+1],d[u0+1]=S0*d[u0+1],s)for(let W0=0;W0<o;W0++)I0=S0*h.get(W0,u0)+F0*h.get(W0,u0+1),h.set(W0,u0+1,-F0*h.get(W0,u0)+S0*h.get(W0,u0+1)),h.set(W0,u0,I0);if(I0=Mt(v0,w0),I0===0&&(I0=Number.MIN_VALUE),S0=v0/I0,F0=w0/I0,d[u0]=I0,v0=S0*q[u0]+F0*d[u0+1],d[u0+1]=-F0*q[u0]+S0*d[u0+1],w0=F0*q[u0+1],q[u0+1]=S0*q[u0+1],i&&u0<r-1)for(let W0=0;W0<r;W0++)I0=S0*A.get(W0,u0)+F0*A.get(W0,u0+1),A.set(W0,u0+1,-F0*A.get(W0,u0)+S0*A.get(W0,u0+1)),A.set(W0,u0,I0)}q[y-2]=v0;break}case 4:{if(d[N]<=0&&(d[N]=d[N]<0?-d[N]:0,s))for(let C=0;C<=X;C++)h.set(C,N,-h.get(C,N));for(;N<X&&!(d[N]>=d[N+1]);){let C=d[N];if(d[N]=d[N+1],d[N+1]=C,s&&N<o-1)for(let P=0;P<o;P++)C=h.get(P,N+1),h.set(P,N+1,h.get(P,N)),h.set(P,N,C);if(i&&N<r-1)for(let P=0;P<r;P++)C=A.get(P,N+1),A.set(P,N+1,A.get(P,N)),A.set(P,N,C);N++}y--;break}}}if(a){let N=h;h=A,A=N}this.m=r,this.n=o,this.s=d,this.U=A,this.V=h}solve(e){let t=e,r=this.threshold,o=this.s.length,n=l0.zeros(o,o);for(let u=0;u<o;u++)Math.abs(this.s[u])<=r?n.set(u,u,0):n.set(u,u,1/this.s[u]);let b=this.U,z=this.rightSingularVectors,i=z.mmul(n),s=z.rows,a=b.rows,O=l0.zeros(s,a);for(let u=0;u<s;u++)for(let l=0;l<a;l++){let d=0;for(let A=0;A<o;A++)d+=i.get(u,A)*b.get(l,A);O.set(u,l,d)}return O.mmul(t)}solveForDiagonal(e){return this.solve(l0.diag(e))}inverse(){let e=this.V,t=this.threshold,r=e.rows,o=e.columns,n=new l0(r,this.s.length);for(let a=0;a<r;a++)for(let O=0;O<o;O++)Math.abs(this.s[O])>t&&n.set(a,O,e.get(a,O)/this.s[O]);let b=this.U,z=b.rows,i=b.columns,s=new l0(r,z);for(let a=0;a<r;a++)for(let O=0;O<z;O++){let u=0;for(let l=0;l<i;l++)u+=n.get(a,l)*b.get(O,l);s.set(a,O,u)}return s}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let e=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,t=0,r=this.s;for(let o=0,n=r.length;o<n;o++)r[o]>e&&t++;return t}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 l0.diag(this.s)}}function r_(M,e=!1){return M=j2.checkMatrix(M),e?new Xr(M).inverse():g3(M,l0.eye(M.rows))}function g3(M,e,t=!1){return M=j2.checkMatrix(M),e=j2.checkMatrix(e),t?new Xr(M).solve(e):M.isSquare()?new Yo(M).solve(e):new ap(M).solve(e)}function Go(M){if(M=l0.checkMatrix(M),M.isSquare()){if(M.columns===0)return 1;let e,t,r,o;if(M.columns===2)return e=M.get(0,0),t=M.get(0,1),r=M.get(1,0),o=M.get(1,1),e*o-t*r;if(M.columns===3){let n,b,z;return n=new Ho(M,[1,2],[1,2]),b=new Ho(M,[1,2],[0,2]),z=new Ho(M,[1,2],[0,1]),e=M.get(0,0),t=M.get(0,1),r=M.get(0,2),e*Go(n)-t*Go(b)+r*Go(z)}else return new Yo(M).determinant}else throw Error("determinant can only be calculated for a square matrix")}function M_(M,e){let t=[];for(let r=0;r<M;r++)r!==e&&t.push(r);return t}function o_(M,e,t,r=1e-9,o=1e-9){if(M>o)return new Array(e.rows+1).fill(0);{let n=e.addRow(t,[0]);for(let b=0;b<n.rows;b++)Math.abs(n.get(b,0))<r&&n.set(b,0,0);return n.to1DArray()}}function n_(M,e={}){const{thresholdValue:t=1e-9,thresholdError:r=1e-9}=e;M=l0.checkMatrix(M);let o=M.rows,n=new l0(o,o);for(let b=0;b<o;b++){let z=l0.columnVector(M.getRow(b)),i=M.subMatrixRow(M_(o,b)).transpose(),a=new Xr(i).solve(z),O=l0.sub(z,i.mmul(a)).abs().max();n.setRow(b,o_(O,a,b,t,r))}return n}function b_(M,e=Number.EPSILON){if(M=l0.checkMatrix(M),M.isEmpty())return M.transpose();let t=new Xr(M,{autoTranspose:!0}),r=t.leftSingularVectors,o=t.rightSingularVectors,n=t.diagonal;for(let b=0;b<n.length;b++)Math.abs(n[b])>e?n[b]=1/n[b]:n[b]=0;return o.mmul(l0.diag(n).mmul(r.transpose()))}function p_(M,e=M,t={}){M=new l0(M);let r=!1;if(typeof e=="object"&&!l0.isMatrix(e)&&!C2.isAnyArray(e)?(t=e,e=M,r=!0):e=new l0(e),M.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0}=t;o&&(M=M.center("column"),r||(e=e.center("column")));const n=M.transpose().mmul(e);for(let b=0;b<n.rows;b++)for(let z=0;z<n.columns;z++)n.set(b,z,n.get(b,z)*(1/(M.rows-1)));return n}function z_(M,e=M,t={}){M=new l0(M);let r=!1;if(typeof e=="object"&&!l0.isMatrix(e)&&!C2.isAnyArray(e)?(t=e,e=M,r=!0):e=new l0(e),M.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0,scale:n=!0}=t;o&&(M.center("column"),r||e.center("column")),n&&(M.scale("column"),r||e.scale("column"));const b=M.standardDeviation("column",{unbiased:!0}),z=r?b:e.standardDeviation("column",{unbiased:!0}),i=M.transpose().mmul(e);for(let s=0;s<i.rows;s++)for(let a=0;a<i.columns;a++)i.set(s,a,i.get(s,a)*(1/(b[s]*z[a]))*(1/(M.rows-1)));return i}let R3=class{constructor(e,t={}){const{assumeSymmetric:r=!1}=t;if(e=j2.checkMatrix(e),!e.isSquare())throw new Error("Matrix is not a square matrix");if(e.isEmpty())throw new Error("Matrix must be non-empty");let o=e.columns,n=new l0(o,o),b=new Float64Array(o),z=new Float64Array(o),i=e,s,a,O=!1;if(r?O=!0:O=e.isSymmetric(),O){for(s=0;s<o;s++)for(a=0;a<o;a++)n.set(s,a,i.get(s,a));i_(o,z,b,n),c_(o,z,b,n)}else{let u=new l0(o,o),l=new Float64Array(o);for(a=0;a<o;a++)for(s=0;s<o;s++)u.set(s,a,i.get(s,a));s_(o,u,l,n),O_(o,z,b,n,u)}this.n=o,this.e=z,this.d=b,this.V=n}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let e=this.n,t=this.e,r=this.d,o=new l0(e,e),n,b;for(n=0;n<e;n++){for(b=0;b<e;b++)o.set(n,b,0);o.set(n,n,r[n]),t[n]>0?o.set(n,n+1,t[n]):t[n]<0&&o.set(n,n-1,t[n])}return o}};function i_(M,e,t,r){let o,n,b,z,i,s,a,O;for(i=0;i<M;i++)t[i]=r.get(M-1,i);for(z=M-1;z>0;z--){for(O=0,b=0,s=0;s<z;s++)O=O+Math.abs(t[s]);if(O===0)for(e[z]=t[z-1],i=0;i<z;i++)t[i]=r.get(z-1,i),r.set(z,i,0),r.set(i,z,0);else{for(s=0;s<z;s++)t[s]/=O,b+=t[s]*t[s];for(o=t[z-1],n=Math.sqrt(b),o>0&&(n=-n),e[z]=O*n,b=b-o*n,t[z-1]=o-n,i=0;i<z;i++)e[i]=0;for(i=0;i<z;i++){for(o=t[i],r.set(i,z,o),n=e[i]+r.get(i,i)*o,s=i+1;s<=z-1;s++)n+=r.get(s,i)*t[s],e[s]+=r.get(s,i)*o;e[i]=n}for(o=0,i=0;i<z;i++)e[i]/=b,o+=e[i]*t[i];for(a=o/(b+b),i=0;i<z;i++)e[i]-=a*t[i];for(i=0;i<z;i++){for(o=t[i],n=e[i],s=i;s<=z-1;s++)r.set(s,i,r.get(s,i)-(o*e[s]+n*t[s]));t[i]=r.get(z-1,i),r.set(z,i,0)}}t[z]=b}for(z=0;z<M-1;z++){if(r.set(M-1,z,r.get(z,z)),r.set(z,z,1),b=t[z+1],b!==0){for(s=0;s<=z;s++)t[s]=r.get(s,z+1)/b;for(i=0;i<=z;i++){for(n=0,s=0;s<=z;s++)n+=r.get(s,z+1)*r.get(s,i);for(s=0;s<=z;s++)r.set(s,i,r.get(s,i)-n*t[s])}}for(s=0;s<=z;s++)r.set(s,z+1,0)}for(i=0;i<M;i++)t[i]=r.get(M-1,i),r.set(M-1,i,0);r.set(M-1,M-1,1),e[0]=0}function c_(M,e,t,r){let o,n,b,z,i,s,a,O,u,l,d,A,h,q,_,m;for(b=1;b<M;b++)e[b-1]=e[b];e[M-1]=0;let L=0,g=0,v=Number.EPSILON;for(s=0;s<M;s++){for(g=Math.max(g,Math.abs(t[s])+Math.abs(e[s])),a=s;a<M&&!(Math.abs(e[a])<=v*g);)a++;if(a>s)do{for(o=t[s],O=(t[s+1]-o)/(2*e[s]),u=Mt(O,1),O<0&&(u=-u),t[s]=e[s]/(O+u),t[s+1]=e[s]*(O+u),l=t[s+1],n=o-t[s],b=s+2;b<M;b++)t[b]-=n;for(L=L+n,O=t[a],d=1,A=d,h=d,q=e[s+1],_=0,m=0,b=a-1;b>=s;b--)for(h=A,A=d,m=_,o=d*e[b],n=d*O,u=Mt(O,e[b]),e[b+1]=_*u,_=e[b]/u,d=O/u,O=d*t[b]-_*o,t[b+1]=n+_*(d*o+_*t[b]),i=0;i<M;i++)n=r.get(i,b+1),r.set(i,b+1,_*r.get(i,b)+d*n),r.set(i,b,d*r.get(i,b)-_*n);O=-_*m*h*q*e[s]/l,e[s]=_*O,t[s]=d*O}while(Math.abs(e[s])>v*g);t[s]=t[s]+L,e[s]=0}for(b=0;b<M-1;b++){for(i=b,O=t[b],z=b+1;z<M;z++)t[z]<O&&(i=z,O=t[z]);if(i!==b)for(t[i]=t[b],t[b]=O,z=0;z<M;z++)O=r.get(z,b),r.set(z,b,r.get(z,i)),r.set(z,i,O)}}function s_(M,e,t,r){let o=0,n=M-1,b,z,i,s,a,O,u;for(O=o+1;O<=n-1;O++){for(u=0,s=O;s<=n;s++)u=u+Math.abs(e.get(s,O-1));if(u!==0){for(i=0,s=n;s>=O;s--)t[s]=e.get(s,O-1)/u,i+=t[s]*t[s];for(z=Math.sqrt(i),t[O]>0&&(z=-z),i=i-t[O]*z,t[O]=t[O]-z,a=O;a<M;a++){for(b=0,s=n;s>=O;s--)b+=t[s]*e.get(s,a);for(b=b/i,s=O;s<=n;s++)e.set(s,a,e.get(s,a)-b*t[s])}for(s=0;s<=n;s++){for(b=0,a=n;a>=O;a--)b+=t[a]*e.get(s,a);for(b=b/i,a=O;a<=n;a++)e.set(s,a,e.get(s,a)-b*t[a])}t[O]=u*t[O],e.set(O,O-1,u*z)}}for(s=0;s<M;s++)for(a=0;a<M;a++)r.set(s,a,s===a?1:0);for(O=n-1;O>=o+1;O--)if(e.get(O,O-1)!==0){for(s=O+1;s<=n;s++)t[s]=e.get(s,O-1);for(a=O;a<=n;a++){for(z=0,s=O;s<=n;s++)z+=t[s]*r.get(s,a);for(z=z/t[O]/e.get(O,O-1),s=O;s<=n;s++)r.set(s,a,r.get(s,a)+z*t[s])}}}function O_(M,e,t,r,o){let n=M-1,b=0,z=M-1,i=Number.EPSILON,s=0,a=0,O=0,u=0,l=0,d=0,A=0,h=0,q,_,m,L,g,v,y,X,T,N,D,C,P,H,G;for(q=0;q<M;q++)for((q<b||q>z)&&(t[q]=o.get(q,q),e[q]=0),_=Math.max(q-1,0);_<M;_++)a=a+Math.abs(o.get(q,_));for(;n>=b;){for(L=n;L>b&&(d=Math.abs(o.get(L-1,L-1))+Math.abs(o.get(L,L)),d===0&&(d=a),!(Math.abs(o.get(L,L-1))<i*d));)L--;if(L===n)o.set(n,n,o.get(n,n)+s),t[n]=o.get(n,n),e[n]=0,n--,h=0;else if(L===n-1){if(y=o.get(n,n-1)*o.get(n-1,n),O=(o.get(n-1,n-1)-o.get(n,n))/2,u=O*O+y,A=Math.sqrt(Math.abs(u)),o.set(n,n,o.get(n,n)+s),o.set(n-1,n-1,o.get(n-1,n-1)+s),X=o.get(n,n),u>=0){for(A=O>=0?O+A:O-A,t[n-1]=X+A,t[n]=t[n-1],A!==0&&(t[n]=X-y/A),e[n-1]=0,e[n]=0,X=o.get(n,n-1),d=Math.abs(X)+Math.abs(A),O=X/d,u=A/d,l=Math.sqrt(O*O+u*u),O=O/l,u=u/l,_=n-1;_<M;_++)A=o.get(n-1,_),o.set(n-1,_,u*A+O*o.get(n,_)),o.set(n,_,u*o.get(n,_)-O*A);for(q=0;q<=n;q++)A=o.get(q,n-1),o.set(q,n-1,u*A+O*o.get(q,n)),o.set(q,n,u*o.get(q,n)-O*A);for(q=b;q<=z;q++)A=r.get(q,n-1),r.set(q,n-1,u*A+O*r.get(q,n)),r.set(q,n,u*r.get(q,n)-O*A)}else t[n-1]=X+O,t[n]=X+O,e[n-1]=A,e[n]=-A;n=n-2,h=0}else{if(X=o.get(n,n),T=0,y=0,L<n&&(T=o.get(n-1,n-1),y=o.get(n,n-1)*o.get(n-1,n)),h===10){for(s+=X,q=b;q<=n;q++)o.set(q,q,o.get(q,q)-X);d=Math.abs(o.get(n,n-1))+Math.abs(o.get(n-1,n-2)),X=T=.75*d,y=-.4375*d*d}if(h===30&&(d=(T-X)/2,d=d*d+y,d>0)){for(d=Math.sqrt(d),T<X&&(d=-d),d=X-y/((T-X)/2+d),q=b;q<=n;q++)o.set(q,q,o.get(q,q)-d);s+=d,X=T=y=.964}for(h=h+1,g=n-2;g>=L&&(A=o.get(g,g),l=X-A,d=T-A,O=(l*d-y)/o.get(g+1,g)+o.get(g,g+1),u=o.get(g+1,g+1)-A-l-d,l=o.get(g+2,g+1),d=Math.abs(O)+Math.abs(u)+Math.abs(l),O=O/d,u=u/d,l=l/d,!(g===L||Math.abs(o.get(g,g-1))*(Math.abs(u)+Math.abs(l))<i*(Math.abs(O)*(Math.abs(o.get(g-1,g-1))+Math.abs(A)+Math.abs(o.get(g+1,g+1))))));)g--;for(q=g+2;q<=n;q++)o.set(q,q-2,0),q>g+2&&o.set(q,q-3,0);for(m=g;m<=n-1&&(H=m!==n-1,m!==g&&(O=o.get(m,m-1),u=o.get(m+1,m-1),l=H?o.get(m+2,m-1):0,X=Math.abs(O)+Math.abs(u)+Math.abs(l),X!==0&&(O=O/X,u=u/X,l=l/X)),X!==0);m++)if(d=Math.sqrt(O*O+u*u+l*l),O<0&&(d=-d),d!==0){for(m!==g?o.set(m,m-1,-d*X):L!==g&&o.set(m,m-1,-o.get(m,m-1)),O=O+d,X=O/d,T=u/d,A=l/d,u=u/O,l=l/O,_=m;_<M;_++)O=o.get(m,_)+u*o.get(m+1,_),H&&(O=O+l*o.get(m+2,_),o.set(m+2,_,o.get(m+2,_)-O*A)),o.set(m,_,o.get(m,_)-O*X),o.set(m+1,_,o.get(m+1,_)-O*T);for(q=0;q<=Math.min(n,m+3);q++)O=X*o.get(q,m)+T*o.get(q,m+1),H&&(O=O+A*o.get(q,m+2),o.set(q,m+2,o.get(q,m+2)-O*l)),o.set(q,m,o.get(q,m)-O),o.set(q,m+1,o.get(q,m+1)-O*u);for(q=b;q<=z;q++)O=X*r.get(q,m)+T*r.get(q,m+1),H&&(O=O+A*r.get(q,m+2),r.set(q,m+2,r.get(q,m+2)-O*l)),r.set(q,m,r.get(q,m)-O),r.set(q,m+1,r.get(q,m+1)-O*u)}}}if(a!==0){for(n=M-1;n>=0;n--)if(O=t[n],u=e[n],u===0)for(L=n,o.set(n,n,1),q=n-1;q>=0;q--){for(y=o.get(q,q)-O,l=0,_=L;_<=n;_++)l=l+o.get(q,_)*o.get(_,n);if(e[q]<0)A=y,d=l;else if(L=q,e[q]===0?o.set(q,n,y!==0?-l/y:-l/(i*a)):(X=o.get(q,q+1),T=o.get(q+1,q),u=(t[q]-O)*(t[q]-O)+e[q]*e[q],v=(X*d-A*l)/u,o.set(q,n,v),o.set(q+1,n,Math.abs(X)>Math.abs(A)?(-l-y*v)/X:(-d-T*v)/A)),v=Math.abs(o.get(q,n)),i*v*v>1)for(_=q;_<=n;_++)o.set(_,n,o.get(_,n)/v)}else if(u<0)for(L=n-1,Math.abs(o.get(n,n-1))>Math.abs(o.get(n-1,n))?(o.set(n-1,n-1,u/o.get(n,n-1)),o.set(n-1,n,-(o.get(n,n)-O)/o.get(n,n-1))):(G=Vo(0,-o.get(n-1,n),o.get(n-1,n-1)-O,u),o.set(n-1,n-1,G[0]),o.set(n-1,n,G[1])),o.set(n,n-1,0),o.set(n,n,1),q=n-2;q>=0;q--){for(N=0,D=0,_=L;_<=n;_++)N=N+o.get(q,_)*o.get(_,n-1),D=D+o.get(q,_)*o.get(_,n);if(y=o.get(q,q)-O,e[q]<0)A=y,l=N,d=D;else if(L=q,e[q]===0?(G=Vo(-N,-D,y,u),o.set(q,n-1,G[0]),o.set(q,n,G[1])):(X=o.get(q,q+1),T=o.get(q+1,q),C=(t[q]-O)*(t[q]-O)+e[q]*e[q]-u*u,P=(t[q]-O)*2*u,C===0&&P===0&&(C=i*a*(Math.abs(y)+Math.abs(u)+Math.abs(X)+Math.abs(T)+Math.abs(A))),G=Vo(X*l-A*N+u*D,X*d-A*D-u*N,C,P),o.set(q,n-1,G[0]),o.set(q,n,G[1]),Math.abs(X)>Math.abs(A)+Math.abs(u)?(o.set(q+1,n-1,(-N-y*o.get(q,n-1)+u*o.get(q,n))/X),o.set(q+1,n,(-D-y*o.get(q,n)-u*o.get(q,n-1))/X)):(G=Vo(-l-T*o.get(q,n-1),-d-T*o.get(q,n),A,u),o.set(q+1,n-1,G[0]),o.set(q+1,n,G[1]))),v=Math.max(Math.abs(o.get(q,n-1)),Math.abs(o.get(q,n))),i*v*v>1)for(_=q;_<=n;_++)o.set(_,n-1,o.get(_,n-1)/v),o.set(_,n,o.get(_,n)/v)}for(q=0;q<M;q++)if(q<b||q>z)for(_=q;_<M;_++)r.set(q,_,o.get(q,_));for(_=M-1;_>=b;_--)for(q=b;q<=z;q++){for(A=0,m=b;m<=Math.min(_,z);m++)A=A+r.get(q,m)*o.get(m,_);r.set(q,_,A)}}}function Vo(M,e,t,r){let o,n;return Math.abs(t)>Math.abs(r)?(o=r/t,n=t+o*r,[(M+o*e)/n,(e-o*M)/n]):(o=t/r,n=r+o*t,[(o*M+e)/n,(o*e-M)/n])}class L3{constructor(e){if(e=j2.checkMatrix(e),!e.isSymmetric())throw new Error("Matrix is not symmetric");let t=e,r=t.rows,o=new l0(r,r),n=!0,b,z,i;for(z=0;z<r;z++){let s=0;for(i=0;i<z;i++){let a=0;for(b=0;b<i;b++)a+=o.get(i,b)*o.get(z,b);a=(t.get(z,i)-a)/o.get(i,i),o.set(z,i,a),s=s+a*a}for(s=t.get(z,z)-s,n&=s>0,o.set(z,z,Math.sqrt(Math.max(s,0))),i=z+1;i<r;i++)o.set(z,i,0)}this.L=o,this.positiveDefinite=!!n}isPositiveDefinite(){return this.positiveDefinite}solve(e){e=j2.checkMatrix(e);let t=this.L,r=t.rows;if(e.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let o=e.columns,n=e.clone(),b,z,i;for(i=0;i<r;i++)for(z=0;z<o;z++){for(b=0;b<i;b++)n.set(i,z,n.get(i,z)-n.get(b,z)*t.get(i,b));n.set(i,z,n.get(i,z)/t.get(i,i))}for(i=r-1;i>=0;i--)for(z=0;z<o;z++){for(b=i+1;b<r;b++)n.set(i,z,n.get(i,z)-n.get(b,z)*t.get(b,i));n.set(i,z,n.get(i,z)/t.get(i,i))}return n}get lowerTriangularMatrix(){return this.L}}class v3{constructor(e,t={}){e=j2.checkMatrix(e);let{Y:r}=t;const{scaleScores:o=!1,maxIterations:n=1e3,terminationCriteria:b=1e-10}=t;let z;if(r){if(C2.isAnyArray(r)&&typeof r[0]=="number"?r=l0.columnVector(r):r=j2.checkMatrix(r),r.rows!==e.rows)throw new Error("Y should have the same number of rows as X");z=r.getColumnVector(0)}else z=e.getColumnVector(0);let i=1,s,a,O,u;for(let l=0;l<n&&i>b;l++)O=e.transpose().mmul(z).div(z.transpose().mmul(z).get(0,0)),O=O.div(O.norm()),s=e.mmul(O).div(O.transpose().mmul(O).get(0,0)),l>0&&(i=s.clone().sub(u).pow(2).sum()),u=s.clone(),r?(a=r.transpose().mmul(s).div(s.transpose().mmul(s).get(0,0)),a=a.div(a.norm()),z=r.mmul(a).div(a.transpose().mmul(a).get(0,0))):z=s;if(r){let l=e.transpose().mmul(s).div(s.transpose().mmul(s).get(0,0));l=l.div(l.norm());let d=e.clone().sub(s.clone().mmul(l.transpose())),A=z.transpose().mmul(s).div(s.transpose().mmul(s).get(0,0)),h=r.clone().sub(s.clone().mulS(A.get(0,0)).mmul(a.transpose()));this.t=s,this.p=l.transpose(),this.w=O.transpose(),this.q=a,this.u=z,this.s=s.transpose().mmul(s),this.xResidual=d,this.yResidual=h,this.betas=A}else this.w=O.transpose(),this.s=s.transpose().mmul(s).sqrt(),o?this.t=s.clone().div(this.s.get(0,0)):this.t=s,this.xResidual=e.sub(s.mmul(O.transpose()))}}Z0.AbstractMatrix=U0,Z0.CHO=L3,Z0.CholeskyDecomposition=L3,Z0.DistanceMatrix=jo,Z0.EVD=R3;var a_=Z0.EigenvalueDecomposition=R3;Z0.LU=Yo,Z0.LuDecomposition=Yo;var N3=Z0.Matrix=l0;Z0.MatrixColumnSelectionView=G6,Z0.MatrixColumnView=Y6,Z0.MatrixFlipColumnView=V6,Z0.MatrixFlipRowView=K6,Z0.MatrixRowSelectionView=Q6,Z0.MatrixRowView=J6,Z0.MatrixSelectionView=Ho,Z0.MatrixSubView=Z6,Z0.MatrixTransposeView=e_,Z0.NIPALS=v3,Z0.Nipals=v3,Z0.QR=ap,Z0.QrDecomposition=ap,Z0.SVD=Xr,Z0.SingularValueDecomposition=Xr,Z0.SymmetricMatrix=Yt,Z0.WrapperMatrix1D=m3,Z0.WrapperMatrix2D=j2,Z0.correlation=z_,Z0.covariance=p_;var y3=Z0.default=l0;Z0.determinant=Go,Z0.inverse=r_,Z0.linearDependencies=n_,Z0.pseudoInverse=b_,Z0.solve=g3,Z0.wrap=t_;const B3=a_,w3=N3;y3.Matrix&&y3.Matrix;class u_{constructor(e){E(this,"_errorListener");this._errorListener=e}new({rows:e,columns:t,initial_value:r}={}){return new up(e,t,r,this._errorListener)}avg({id:e}){return e==null?void 0:e.avg()}col({id:e,column:t}){return e==null?void 0:e.col({column:t})}det({id:e}){return e==null?void 0:e.det()}get({id:e,row:t,column:r}){return e==null?void 0:e.get({row:t,column:r})}inv({id:e}){return e==null?void 0:e.inv()}max({id:e}){return e==null?void 0:e.max()}min({id:e}){return e==null?void 0:e.min()}pow({id:e,power:t}){return e==null?void 0:e.pow({power:t})}row({id:e,row:t}){return e==null?void 0:e.row({row:t})}set({id:e,row:t,column:r,value:o}){e==null||e.set({row:t,column:r,value:o})}sum({id1:e,id2:t}){return e==null?void 0:e.sum({id2:t})}copy({id:e}){return e==null?void 0:e.copy()}diff({id1:e,id2:t}){return e==null?void 0:e.diff({id2:t})}rows({id:e}){return e==null?void 0:e.rows()}columns({id:e}){return e==null?void 0:e.columns()}fill({id:e,value:t,from_row:r,to_row:o,from_column:n,to_column:b}){e==null||e.fill({value:t,from_row:r,to_row:o,from_column:n,to_column:b})}kron({id1:e,id2:t}){return e==null?void 0:e.kron({id2:t})}mode({id:e}){return e==null?void 0:e.mode()}mult({id1:e,id2:t}){return e==null?void 0:e.mult({id2:t})}pinv({id:e}){return e==null?void 0:e.pinv()}rank({id:e}){return e==null?void 0:e.rank()}sort({id:e,column:t,order:r}){e==null||e.sort({column:t,order:r})}trace({id:e}){return e==null?void 0:e.trace()}concat({id1:e,id2:t}){return e==null?void 0:e.concat({id2:t})}median({id:e}){return e==null?void 0:e.median()}add_col({id:e,column:t,array_id:r}){e==null||e.add_col({column:t,array_id:r})}add_row({id:e,row:t,array_id:r}){e==null||e.add_row({row:t,array_id:r})}is_zero({id:e}){return e==null?void 0:e.is_zero()}reshape({id:e,rows:t,columns:r},o){return e==null?void 0:e.reshape({rows:t,columns:r},o)}reverse({id:e}){e==null||e.reverse()}is_binary({id:e}){return e==null?void 0:e.is_binary()}is_square({id:e}){return e==null?void 0:e.is_square()}submatrix({id:e,from_row:t,to_row:r,from_column:o,to_column:n}){return e==null?void 0:e.submatrix({from_row:t,to_row:r,from_column:o,to_column:n})}swap_rows({id:e,row1:t,row2:r}){e==null||e.swap_rows({row1:t,row2:r})}transpose({id:e}){return e==null?void 0:e.transpose()}remove_col({id:e,column:t}){return e==null?void 0:e.remove_col({column:t})}remove_row({id:e,row:t}){return e==null?void 0:e.remove_row({row:t})}eigenvalues({id:e}){return e==null?void 0:e.eigenvalues()}is_diagonal({id:e}){return e==null?void 0:e.is_diagonal()}is_identity({id:e}){return e==null?void 0:e.is_identity()}eigenvectors({id:e}){return e==null?void 0:e.eigenvectors()}is_symmetric({id:e}){return e==null?void 0:e.is_symmetric()}swap_columns({id:e,column1:t,column2:r}){e==null||e.swap_columns({column1:t,column2:r})}is_stochastic({id:e}){return e==null?void 0:e.is_stochastic()}is_triangular({id:e}){return e==null?void 0:e.is_triangular()}elements_count({id:e}){return e==null?void 0:e.elements_count()}is_antidiagonal({id:e}){return e==null?void 0:e.is_antidiagonal()}is_antisymmetric({id:e}){return e==null?void 0:e.is_antisymmetric()}}class up{constructor(e=0,t=0,r=void 0,o){E(this,"_matrixInstance");E(this,"_errorListener");this._matrixInstance=this._createMatrix(e,t,r),this._errorListener=o}get _matrixArray(){return this._matrixInstance.map(e=>[...e._value])}get _value(){return this._matrixInstance}set _value(e){this._matrixInstance=e}get isMatrix(){return!0}_createMatrix(e,t,r){return Array.from(new Array(e),()=>new n1(t,r,this._errorListener))}avg(){let e=0,t=0;for(const o of this._matrixInstance)for(const n of o._value)e+=d0(n)?0:n,t+=1;return e/t}col({column:e}){const t=[],r=new n1(0,void 0,this._errorListener);if(d0(e))return r;for(const o of this._matrixInstance)t.push(o._value[e]);return r._value=t,r}det(){return f3(this._matrixArray)}get({row:e,column:t}){var r,o;if(!(d0(e)||d0(t)))return(o=(r=this._matrixInstance[e])==null?void 0:r._value)==null?void 0:o[t]}inv(){const e=Po(this._matrixArray);return this._newMatrix(e)}max(){return i6(this._matrixArray)}min(){return ip(this._matrixArray)}pow({power:e}){const t=d0(e)?this._matrixArray:s6(this._matrixArray,e);return this._newMatrix(t)}row({row:e}){return d0(e)?new n1(0,void 0,this._errorListener):this._matrixInstance[e]}set({row:e,column:t,value:r}){d0(e)||d0(t)||this._matrixInstance[e].set({index:t,value:r})}sum({id2:e}){const t=dM(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:e}){const t=M6(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:e,from_row:t,to_row:r,from_column:o,to_column:n}={}){d0(t)&&(t=0),d0(r)&&(r=this.rows()),d0(o)&&(o=0),d0(n)&&(n=this.columns());let b=t||0;for(;b<(r||0);){let z=this._matrixInstance[b];z||(z=new n1(0,e,this._errorListener),this._matrixInstance[b]=z),z.fill({value:e,index_from:o,index_to:n}),b++}}kron({id2:e}){const t=t6(this._matrixArray,e._matrixArray);return this._newMatrix(t)}mode(){return ip(i3(this._matrixArray))}mult({id2:e}){const t=typeof e=="number"?e:e._matrixArray?e._matrixArray:e._value,r=yr(this._matrixArray,t);return this._newMatrix(r)}pinv(){const e=c6(this._matrixArray);return this._newMatrix(e)}rank(){return this._matrixRank(this._matrixArray)}sort({column:e,order:t=$e.ascending}={}){d0(e)&&(e=0),this._matrixInstance.sort((r,o)=>{const n=r._value[e],b=o._value[e];return t!==$e.descending?n-b:b-n})}trace(){return z6(this._matrixArray)}concat({id2:e}){for(const t of e._value)this._matrixInstance.push(t);return this}median(){return l3(this._matrixArray)}add_col({column:e,array_id:t}={}){d0(e)&&(e=this.columns());for(const[r,o]of this._matrixInstance.entries())o.insert({index:e,value:t?t._value[r]:void 0})}add_row({row:e,array_id:t}){d0(e)&&(e=this.rows()),this._matrixInstance.splice(e,0,t||new n1(this.columns(),void 0,this._errorListener))}is_zero(){return this._matrixArray.every(e=>e.every(t=>t===0))}reshape({rows:e=0,columns:t=0},r){if(e*t!==this.columns()*this.rows()){this._errorListener.addError(l1.matrixRehapeErr,r,$0.Error);return}const o=JW(this._matrixArray,[e,t]);this._matrixInstance=o.map(n=>{const b=new n1(0,void 0,this._errorListener);return b._value=[...n],b})}reverse(){this._matrixInstance.reverse();for(const e of this._matrixInstance)e.reverse()}is_binary(){return this._matrixArray.every(e=>e.every(t=>t===0||t===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:e,to_row:t,from_column:r,to_column:o}={}){d0(e)&&(e=0),d0(t)&&(t=this.rows()),d0(r)&&(r=0),d0(o)&&(o=this.columns());const n=this._matrixArray.splice(e,t),b=[];for(const z of n)b.push(z.splice(r,o));return this._newMatrix(b)}swap_rows({row1:e,row2:t}){if(d0(e)||d0(t))return;const r=this._matrixInstance[e],o=this._matrixInstance[t];this._matrixInstance[e]=o,this._matrixInstance[t]=r}transpose(){const e=s3(this._matrixArray);return this._newMatrix(e)}remove_col({column:e}={}){d0(e)&&(e=this.columns());const t=[];for(const o of this._matrixInstance){const n=o._value.splice(e,1);t.push(n[0])}const r=new n1(0,void 0,this._errorListener);return r._value=t,r}remove_row({row:e}={}){return d0(e)&&(e=this.rows()),this._matrixInstance.splice(e,1)[0]}eigenvalues(){const e=new B3(new w3(this._matrixArray)),t=new n1(0,void 0,this._errorListener);return t._value=e.realEigenvalues,t}is_diagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<t;n++)if(o!==n&&r[o][n]!==0)return!1;return!0}is_identity(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<t;n++)if(o!==n&&r[o][n]!==0||o===n&&r[o][n]!==1)return!1;return!0}eigenvectors(){const e=new B3(new w3(this._matrixArray));return this._newMatrix(e.eigenvectorMatrix.to2DArray())}is_symmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=o+1;n<t;n++)if(r[o][n]!==r[n][o])return!1;return!0}swap_columns({column1:e,column2:t}){if(!(d0(e)||d0(t)))for(const r of this._matrixInstance){const o=r._value[e],n=r._value[t];r.set({index:e,value:n}),r.set({index:t,value:o})}}is_stochastic(){const e=this._matrixArray;for(let t=0;t<e.length;t++){let r=0;for(let o=0;o<e[t].length;o++){if(e[t][o]<0)return!1;r+=e[t][o]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const e=this.rows(),t=this.columns();return e!==t?!1:this._isUpperTriangular(e)||this._isLowerTriangular(e)}elements_count(){return QW(this._matrixArray)}is_antidiagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<e;n++)if(o+n!==e-1&&r[o][n]!==0)return!1;return!0}is_antisymmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<e;n++)if(o!==n&&r[o][n]!==-r[n][o])return!1;return!0}_isUpperTriangular(e){const t=this._matrixArray;for(let r=1;r<e;r++)for(let o=0;o<r;o++)if(t[r][o]!==0)return!1;return!0}_isLowerTriangular(e){const t=this._matrixArray;for(let r=0;r<e-1;r++)for(let o=r+1;o<e;o++)if(t[r][o]!==0)return!1;return!0}_newMatrix(e){const t=new up(0,0,void 0,this._errorListener);return t._value=e.map(r=>{const o=new n1(0,void 0,this._errorListener);return o._value=[...r],o}),t}_matrixRank(e){let t=0;const r=e.length,o=e[0].length,n=[...e].map(b=>[...b]);for(let b=0;b<r&&!(b>=o);b++){let z=b;for(;z<r&&n[z][b]===0;)z++;if(z===r)continue;if(z!==b){const s=n[z];n[z]=n[b],n[b]=s}const i=n[b][b];for(let s=0;s<o;s++)n[b][s]/=i;for(let s=b+1;s<r;s++){const a=n[s][b];n[s]=n[s].map((O,u)=>O-a*n[b][u]),n[s][b]=0}}for(let b=0;b<r;b++)n[b].some(z=>Number(z.toFixed(8))!==0)&&t++;return t}}class A_{constructor(e){E(this,"_variables");E(this,"_cacheData");this._variables=e,this._cacheData={}}change({timeframe:e},t){if(!e)return!0;const{time:r,__period:o}=this._variables,n=N2(e,r),b=N2(o,r);if(n<b)return!0;const z=`change_${t}`,i=this._cacheData[z],s=this._variables.time;if(i){if(i.offset){if(i.currentTime+i.offset<=s)return this._cacheData[z]={currentTime:s,offset:0},!0}else if(i.currentTime+n*1e3<=s)return this._cacheData[z]={currentTime:s,offset:0},!0}else{const a=this._calcTimeOffset(s,e);return this._cacheData[z]={currentTime:s,offset:a},!1}return!1}in_seconds({timeframe:e}={}){const{time:t,__period:r}=this._variables;return N2(e||r,t)}from_seconds({seconds:e=0}){const t=e*1e3,r=D1.duration(t);if(r.years())return"12M";const n=r.asMonths();if(Fo(n))return`${n}M`;const b=r.asWeeks();if(Fo(b))return`${b}M`;const z=r.asDays();if(z>=1)return`${Math.ceil(z)}D`;const i=r.asMinutes();if(i>=1)return`${Math.ceil(i)}`;const s=r.asSeconds();return s<=1?"1S":s<=5?"5S":s<=10?"10S":s<=15?"15S":s<=30?"30S":"1"}_calcTimeOffset(e,t){let r=0;if(t.includes("W")){const z=D1(e).day();t="1D",z!==1&&(r=(8-z)*60*60*24*1e3)}else if(t.includes("M")){const z=D1(e).date();t="1D";const i=D1(e).daysInMonth();z!==1&&(r=(i-z+1)*60*60*24*1e3)}const o=this._variables.getTimeTradingday(e,t),n=N2(t,e)*1e3,b=e-o-Math.floor((e-o)/n)*n;return r?r-b:b}}class f_{constructor(e,t){E(this,"_errorListener");E(this,"_intlNumberFormatter");E(this,"_precision");E(this,"_intlFormat");this._errorListener=e,this._precision=t,this._intlNumberFormatter=new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:3}),this._intlFormat=new Intl.NumberFormat("en-US")}pos({source:e="",str:t=""}){return e==null?void 0:e.indexOf(t)}trim({source:e=""}){return e==null?void 0:e.trim()}lower({source:e=""}){return e==null?void 0:e.toLocaleLowerCase()}match({source:e="",regex:t=""}){const r=e==null?void 0:e.match(new RegExp(t));return r?r[0]:""}split({string:e="",separator:t=""}){const r=e==null?void 0:e.split(t),o=new n1;return o._value=r||[],o}upper({source:e=""}){return e==null?void 0:e.toLocaleUpperCase()}format({formatString:e=""},t){return this._strFormat(e,t)}length({string:e=""}){return e==null?void 0:e.length}repeat({source:e="",repeat:t,separator:r=""},o){if(d0(t)){this._errorListener.addError(l1.arrLenErr,o,$0.Error);return}return Array.from(new Array(t),()=>e).join(r)}replace({source:e="",target:t="",replacement:r="",occurrence:o}){d0(o)&&(o=0);let n=-1;for(let b=0;b<o+1&&(n=e.indexOf(t,n+1),n!==-1);b++);return n!==-1?e.substring(0,n)+r+e.substring(n+t.length):e}contains({source:e="",str:t=""}){return e==null?void 0:e.includes(t)}endswith({source:e="",str:t=""}){return e==null?void 0:e.endsWith(t)}tonumber({string:e=""}){if(/[^\d.]/.test(e))return;const t=parseFloat(e);return isNaN(t)?void 0:t}tostring({value:e,format:t}){if(e===void 0)return"NaN";if(typeof e=="object"){if(e.isArray)return this._arrToStr(e._value,t);if(e.isMatrix){const r=[];for(const o of e._matrixArray)r.push(this._arrToStr(o,t));return r.join(`
|
76
|
-
`)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t==null?void 0:t.replace(/0/g,"#")))}_arrToStr(e,t){return`[${e.map(o=>typeof o=="number"?this._toStringFormat(o,t):o).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return d0(t)&&(t=0),d0(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return d0(e)&&(e=0),$2(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return Number(e==null?void 0:e.toFixed(10));switch(t){case O1.mintick:return e==null?void 0:e.toFixed(this._precision);case O1.percent:return`${Number(e.toFixed(2))}%`;case O1.volume:return this._intlNumberFormatter.format(Math.round(e));default:return this._formatOthers(e,t)}}_formatOthers(e,t){var z;let[r,o]=t.split(".");t.split("%").length===2&&(e=e*100);let[n,b=""]=String(e).split(".");if(r.includes("#")){if(r.includes(",")){const i=r.split(","),s=((z=i[i.length-1])==null?void 0:z.replace(/[^#]/g,"").length)||0;s&&(n=n.replace(new RegExp(`\\B(?=(\\d{${s}})+(?!\\d))`,"g"),",")),r=i.join("")}n=r.replace(/#/,n).replace(/#/g,"")}else n=`${r}${n}`;if(o&&o.includes("#")){const i=o.split("#").length-1,s=+`${n}.${b}`;if(!isNaN(s))return+`${s.toFixed(i)}${o.replace(/#/g,"")}`;b=`${b.substring(0,i)}${o.replace(/#/g,"")}`}else b=o||"";return b?+`${n}.${b}`:n}_formatNumber(e,t){if(!t)return Number(e==null?void 0:e.toFixed(this._precision));switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:return this._formatOthers(e,t)}}strformat({formatString:e=""},t,r){return this._strFormat(e,t,r)}_strFormat(e,t,r){return e.replace(/{[^{}]+}/g,o=>{if(!o)return o;const n=o.replace(/[{}]/g,"").split(","),b=Number(n[0]);if(isNaN(b)||t.length<=b)return o;const z=t[b];if(n.length===1)return typeof z=="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):z===void 0?"":z;if(n.length===2){const i=n[1].trim();return i==="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):i==="date"?D1(z).format("LL"):o}else{const i=n[1].trim(),s=n[2].trim();if(i==="number")return this._formatNumber(z,s);if(i==="date"){let a="YYYY-MM-DD";switch(s){case"long":a="LL";break;case"short":a="L";break;default:s&&(a=s)}return D1(z).format(a)}return o}})}}class l_{constructor(e){E(this,"_errorListener");this._errorListener=e}new(){return new Ap(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class Ap{constructor(e){E(this,"_errorListener");E(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}get _value(){return this._mapInstance}_copyMap(e){const t=new Ap(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class q_{constructor(e){E(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new Er(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new Er(e,r,t)}copy({id:e}){return e==null?void 0:e.copy()}from_index({price:e,index:t}){return new Er(e,t)}from_time({price:e,time:t}){return new Er(e,void 0,t)}}class Er{constructor(e,t,r){E(this,"_index");E(this,"_price");E(this,"_time");this._index=t&&Math.round(t),this._price=e,this._time=r}get index(){return this._index}set index(e){this._index=e&&Math.round(e)}get price(){return this._price}set price(e){this._price=e}get time(){return this._time}set time(e){this._time=e}copy(){return new Er(this._price,this._index,this._time)}}class d_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLabel",{text:"",xloc:P1.bar_index,yloc:le.price,size:L2.normal,style:T1.styleLabelDown,textalign:t1.alignCenter});this._variables=e,this._errorListener=t}new(e,t){B0(this._errorListener,"label.new",this._variables.__requestName,t);const{time:r,high:o,low:n,bar_index:b}=this._variables,z=`label_${t}_${b}`;S1(e,["color","textcolor"]);const i={...this._defaultLabel,...e,id:z,time:r,high:o,low:n,bar_index:b};e.x&&(i.x=e.x&&Math.round(e.x)),e.point&&(i.x=i.xloc===P1.bar_index?e.point.index:e.point.time,i.y=e.point.price),i.yloc===le.abovebar?i.y=o:i.yloc===le.belowbar&&(i.y=n),this._verfiyArgs(e,t);const s=new Ko(z,this._variables,this._errorListener,i);return t.startsWith("export")||this._variables.label.add(z,i,s),s}_verfiyArgs(e,t){const{xloc:r,yloc:o,style:n,size:b,textalign:z,text_font_family:i}=e,s="label.new";this._paramVerfiy(n,t,s,Object.values(T1),"style"),this._paramVerfiy(r,t,s,Object.values(P1),"xloc"),this._paramVerfiy(o,t,s,Object.values(le),"yloc"),this._paramVerfiy(b,t,s,Object.values(L2),"size"),this._paramVerfiy(z,t,s,[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign"),this._paramVerfiy(i,t,s,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}label(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e},t){e==null||e.delete(t)}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Ko{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get type(){return Q0.LABEL}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.label.get(this._id)||this._data}copy(e){B0(this._errorListener,"label.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`label_${e}_${t}`,o=this._getLabel(e),n={...o||{},id:r,bar_index:t},b=new Ko(r,this._variables,this._errorListener,n);return o&&this._variables.label.add(r,n,b),b}get_x(e){var t;return B0(this._errorListener,"label.get_x",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return B0(this._errorListener,"label.get_y",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){B0(this._errorListener,"label.set_x",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=e&&Math.round(e))}set_y({y:e},t){B0(this._errorListener,"label.set_y",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.y=e)}delete(e){B0(this._errorListener,"label.delete",this._variables.__requestName,e),this._variables.label.delete(this._id,this._variables.bar_index,this._data.id)}set_xy({x:e,y:t},r){B0(this._errorListener,"label.set_xy",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.y=t)}get_text(e){var t;return B0(this._errorListener,"label.get_text",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){B0(this._errorListener,"label.set_size",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(L2),"size")}set_text({text:e},t){B0(this._errorListener,"label.set_text",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){B0(this._errorListener,"label.set_xloc",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(P1),"xloc"))}set_yloc({yloc:e},t){B0(this._errorListener,"label.set_yloc",this._variables.__requestName,t);const r=this._getLabel(t),{high:o,low:n}=this._variables;r&&(r.yloc=e,e===le.abovebar?r.y=o:e===le.belowbar&&(r.y=n),this._paramVerfiy(e,t,"label.set_yloc",Object.values(le),"yloc"))}set_color(e,t){B0(this._errorListener,"label.set_color",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["color"]),r&&(r.color=e.color)}set_point({point:e},t){B0(this._errorListener,"label.set_point",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=r.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){B0(this._errorListener,"label.set_style",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(T1),"style")}set_tooltip({tooltip:e},t){B0(this._errorListener,"label.set_tooltip",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){B0(this._errorListener,"label.set_textalign",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign")}set_textcolor(e,t){B0(this._errorListener,"label.set_textcolor",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["textcolor"]),r&&(r.textcolor=e.textcolor)}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"label.set_text_font_family",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLabel(e){const t=this._variables.label.get(this._id)||this._data;return t||console.log(`错误${e}: label 不存在`),t}}const h_={freq_all:Ae.freqAll,freq_once_per_bar:Ae.freqOncePerBar,freq_once_per_bar_close:Ae.freqOncePerBarClose},W_={gaps_off:Pe.gapsOff,gaps_on:Pe.gapsOn,lookahead_off:Pe.lookaheadOff,lookahead_on:Pe.lookaheadOn},Tr={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"},D3={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"},__={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},X3={all:[A2.dataWindow,A2.pane,A2.priceScale,A2.statusLine],data_window:[A2.dataWindow],none:[],pane:[A2.pane],price_scale:[A2.priceScale],status_line:[A2.statusLine]},m_={both:fe.both,left:fe.left,none:fe.none,right:fe.right},g_={inherit:O1.inherit,mintick:O1.mintick,percent:O1.percent,price:O1.price,volume:O1.volume},R_={style_solid:kM.styleSolid,style_dashed:kM.styleDashed,style_dotted:kM.styleDotted},L_={style_arrowdown:T1.styleArrowdown,style_arrowup:T1.styleArrowup,style_circle:T1.styleCircle,style_cross:T1.styleCross,style_diamond:T1.styleDiamond,style_flag:T1.styleFlag,style_label_center:T1.styleLabelCenter,style_label_down:T1.styleLabelDown,style_label_left:T1.styleLabelLeft,style_label_lower_left:T1.styleLabelLowerLeft,style_label_lower_right:T1.styleLabelLowerRight,style_label_right:T1.styleLabelRight,style_label_up:T1.styleLabelUp,style_label_upper_left:T1.styleLabelUpperLeft,style_label_upper_right:T1.styleLabelUpperRight,style_none:T1.styleNone,style_square:T1.styleSquare,style_text_outline:T1.styleTextOutline,style_triangledown:T1.styleTriangledown,style_triangleup:T1.styleTriangleup,style_xcross:T1.styleXcross},v_={style_arrow_both:n2.styleArrowBoth,style_arrow_left:n2.styleArrowLeft,style_arrow_right:n2.styleArrowRight,style_dashed:n2.styleDashed,style_dotted:n2.styleDotted,style_solid:n2.styleSolid},N_={abovebar:ke.abovebar,absolute:ke.absolute,belowbar:ke.belowbar,bottom:ke.bottom,top:ke.top},y_={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},B_={style_area:ee.styleArea,style_areabr:ee.styleAreabr,style_circles:ee.styleCircles,style_columns:ee.styleColumns,style_cross:ee.styleCross,style_histogram:ee.styleHistogram,style_line:ee.styleLine,style_linebr:ee.styleLinebr,style_stepline:ee.styleStepline,style_stepline_diamond:ee.styleSteplineDiamond,style_steplinebr:ee.styleSteplinebr},w_={bottom_center:P2.bottomCenter,bottom_left:P2.bottomLeft,bottom_right:P2.bottomRight,middle_center:P2.middleCenter,middle_left:P2.middleLeft,middle_right:P2.middleRight,top_center:P2.topCenter,top_left:P2.topLeft,top_right:P2.topRight},D_={left:$M.left,none:$M.none,right:$M.right},X_={arrowdown:X2.arrowdown,arrowup:X2.arrowup,circle:X2.circle,cross:X2.cross,diamond:X2.diamond,flag:X2.flag,labeldown:X2.labeldown,labelup:X2.labelup,square:X2.square,triangledown:X2.triangledown,triangleup:X2.triangleup,xcross:X2.xcross},E_={auto:L2.auto,huge:L2.huge,large:L2.large,normal:L2.normal,small:L2.small,tiny:L2.tiny},T_={cash:b2.cash,fixed:b2.fixed,percent_of_equity:b2.percentOfEquity,commission:{cash_per_contract:O2.cashPerContract,cash_per_order:O2.cashPerOrder,percent:O2.percent},direction:{all:i1.all,long:i1.long,short:i1.short},oca:{cancel:Ue.cancel,none:Ue.none,reduce:Ue.reduce}},C_={align_bottom:t1.alignBottom,align_center:t1.alignCenter,align_left:t1.alignLeft,align_right:t1.alignRight,align_top:t1.alignTop,wrap_auto:t1.wrapAuto,wrap_none:t1.wrapNone},x_={bar_index:P1.bar_index,bar_time:P1.bar_time},S_={abovebar:le.abovebar,belowbar:le.belowbar,price:le.price},F_={actual:UM.actual,estimate:UM.estimate,standardized:UM.standardized};class fp{constructor(){E(this,"adjustment",{dividends:PM.dividends,none:PM.none,splits:PM.splits});E(this,"alert",h_);E(this,"barmerge",W_);E(this,"color",Tr);E(this,"currency",D3);E(this,"dayofweek",__);E(this,"earnings",F_);E(this,"display",X3);E(this,"extend",m_);E(this,"font",{family_default:St.familyDefault,family_monospace:St.familyMonospace});E(this,"format",g_);E(this,"hline",R_);E(this,"label",L_);E(this,"line",v_);E(this,"location",N_);E(this,"math",y_);E(this,"order",{ascending:$e.ascending,descending:$e.descending});E(this,"plot",B_);E(this,"position",w_);E(this,"scale",D_);E(this,"session",{extended:ut.extended,regular:ut.regular});E(this,"shape",X_);E(this,"size",E_);E(this,"splits",{denominator:"denominator",numerator:"numerator"});E(this,"strategy",T_);E(this,"text",C_);E(this,"xloc",x_);E(this,"yloc",S_)}updateData(){}}class I_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:P1.bar_index,line_color:Tr.blue,line_style:n2.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var z;B0(this._errorListener,"polyline.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`polyline_${t}_${r}`,n=Object.assign({},this._defaultPolyline,e,{id:o,bar_index:r,points:(z=e.points)==null?void 0:z._value.map(i=>({time:i.time,index:i.index,price:i.price}))});S1(n,["line_color","fill_color"]);const b=new E3(o,this._variables,n);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(o,n,b),b}_verfiyArgs(e,t){const{line_style:r,xloc:o}=e,n="polyline.new";this._paramVerfiy(r,t,n,Object.values(n2),"line_style"),this._paramVerfiy(o,t,n,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}delete({id:e}){e&&e.delete()}}class E3{constructor(e,t,r){E(this,"_id");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=t,this._id=e,this._data=r}get type(){return Q0.POLYLINE}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.polyline.get(this._id)||this._data}delete(){this._variables.polyline.delete(this._id,this._variables.bar_index,this._data.id)}}class P_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLine",{xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},o){B0(this._errorListener,"line.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`line_${o}_${n}`;S1(r,["color"]);const z={...this._defaultLine,...r,id:b,bar_index:n},{x1:i,x2:s}=z;if(i&&(z.x1=i&&Math.round(i)),s&&(z.x2=s&&Math.round(s)),e&&t){const O=z.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,u=z.xloc===P1.bar_index?t==null?void 0:t.index:t==null?void 0:t.time;Object.assign(z,{x1:O,y1:e==null?void 0:e.price,x2:u,y2:t==null?void 0:t.price})}this._verfiyArgs(r,o);const a=new Jo(b,this._variables,this._errorListener,z);return o.startsWith("export")||this._variables.line.add(b,z,a),a}_verfiyArgs(e,t){const{extend:r,xloc:o,style:n}=e,b="line.new";this._paramVerfiy(n,t,b,Object.values(n2),"style"),this._paramVerfiy(r,t,b,Object.values(fe),"extend"),this._paramVerfiy(o,t,b,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}line(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class Jo{constructor(e,t,r,o){E(this,"_variables");E(this,"_id");E(this,"_suffix","");E(this,"_errorListener");E(this,"_fillKeys",[]);E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get id(){return this._id}get __fillKeys(){return this._fillKeys}__setFillKeys(e){this._fillKeys.includes(e)||this._fillKeys.push(e)}__updateFillKeys(e,t){const r=this._fillKeys.findIndex(o=>o===e);r!==-1?this._fillKeys.splice(r,1,t):this._fillKeys.push(t)}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get type(){return Q0.LINE}set data(e){this._data=e}get data(){return this._variables.line.get(this._id)||this._data}get originData(){return this._data}copy(e){const{bar_index:t}=this._variables,r=`line_${e}_${t}`,o=this._getLine(e,"copy"),n={...o,id:r,bar_index:t,isVar:void 0},b=new Jo(r,this._variables,this._errorListener,n);return o&&this._variables.line.add(r,n,b),b}delete(e){B0(this._errorListener,"line.delete",this._variables.__requestName,e);for(const t of this._fillKeys)this._variables.linefill.delete(t,this._variables.bar_index);this._variables.line.delete(this._id,this._variables.bar_index,this._data.id)}get_price({x:e},t){const r=this._getLine(t,"get_price");if(e===void 0)return e;if(r&&r.xloc===P1.bar_index){const{x1:o,y1:n,x2:b,y2:z}=r;return o===void 0||b===void 0||n===void 0||z===void 0?void 0:(z-n)/(b-o)*(e-o)+n}}get_x1(e){var t;return(t=this._getLine(e,"get_x1"))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e,"get_x2"))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e,"get_y1"))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e,"get_y2"))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t,"set_x1");r&&(r.x1=e&&Math.round(e))}set_x2({x:e},t){const r=this._getLine(t,"set_x2");r&&(r.x2=e&&Math.round(e))}set_y1({y:e},t){const r=this._getLine(t,"set_y1");r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t,"set_y2");r&&(r.y2=e)}set_xy1({x:e,y:t},r){const o=this._getLine(r,"set_xy1");o&&(o.x1=e&&Math.round(e),o.y1=t)}set_xy2({x:e,y:t},r){const o=this._getLine(r,"set_xy2");o&&(o.x2=e&&Math.round(e),o.y2=t)}set_xloc({xloc:e,x1:t,x2:r},o){const n=this._getLine(o,"set_xloc");n&&(n.xloc=e,n.x1=t&&Math.round(t),n.x2=r&&Math.round(r),this._paramVerfiy(e,o,"line.set_xloc",Object.values(P1),"xloc"))}set_color(e,t){const r=this._getLine(t,"set_color");r&&(S1(e,["color"]),r.color=e.color)}set_style({style:e},t){const r=this._getLine(t,"set_style");r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(n2),"style"))}set_width({width:e},t){const r=this._getLine(t,"set_width");r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t,"set_extend");r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(fe),"extend"))}set_first_point({point:e},t){const r=this._getLine(t,"set_first_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x1=z),i&&(r.y1=i)}}set_second_point({point:e},t){const r=this._getLine(t,"set_second_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x2=z),i&&(r.y2=i)}}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLine(e,t){B0(this._errorListener,`line.${t}`,this._variables.__requestName,e);const r=this._variables.line.get(this._id)||this._data;return r||console.log(`${e}: line 不存在`),r}}class k_{constructor(e){E(this,"_variables");this._variables=e}new(e,t){const{line1:r,line2:o}=e,{bar_index:n}=this._variables,b=`linefill_${t}_${n}`,z=r==null?void 0:r.data,i=o==null?void 0:o.data;z&&(z.linefills=z.linefills||[],z.linefills.push(b)),i&&(i.linefills=i.linefills||[],i.linefills.push(b)),S1(e,["color"]),r==null||r.__setFillKeys(b),o==null||o.__setFillKeys(b);const s={line1:z,line2:i,color:e.color,id:b,bar_index:n},a=new T3(this._variables,b,s,r,o);return t.startsWith("export")||(z||i)&&this._variables.linefill.add(b,s,a),a}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class T3{constructor(e,t,r,o,n){E(this,"_id");E(this,"_line1");E(this,"_line2");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._line1=o,this._line2=n,this._data=r}get type(){return Q0.LINEFILL}get id(){return this._id}get preId(){return this._preId}updateId(){var o,n;const{bar_index:e,_isRealTimeBar:t}=this._variables,r=this._id;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const b=this._id.split("_");b.pop(),this._id=`${b.join("_")}_${e}`}return(o=this._line1)==null||o.__updateFillKeys(r,this._id),(n=this._line2)==null||n.__updateFillKeys(r,this._id),t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.linefill.get(this._id)||this._data}linefill(e){return e.x}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:o,line2:n}=e;o&&(o.linefills=(t=o.linefills)==null?void 0:t.filter(b=>b!==this._id)),n&&(n.linefills=(r=n.linefills)==null?void 0:r.filter(b=>b!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id,this._variables.bar_index,this._data.id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(e){const t=this._variables.linefill.get(this._id);t&&(S1(e,["color"]),t.color=e.color)}}class $_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultBox",{border_color:Tr.blue,border_width:1,bgcolor:Tr.blue,xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid,text:"",text_size:L2.auto,text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_wrap:t1.wrapNone});this._variables=e,this._errorListener=t}box({x:e}){return e}new({top_left:e,bottom_right:t,...r},o){B0(this._errorListener,"box.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`box_${o}_${n}`,z={...this._defaultBox,...r,id:b,bar_index:n};S1(z,["border_color","bgcolor","text_color"]);const{left:i,right:s}=z;if(i&&(z.left=i&&Math.round(i)),s&&(z.right=s&&Math.round(s)),e){const{price:O,time:u,index:l}=e;z.top=O,z.left=z.xloc===P1.bar_index?l:u}if(t){const{price:O,time:u,index:l}=t;z.bottom=O,z.right=z.xloc===P1.bar_index?l:u}this._verfiyArgs(r,o);const a=new Qo(this._variables,b,this._errorListener,z);return o.startsWith("export")||this._variables.box.add(b,z,a),a}_verfiyArgs(e,t){const{border_style:r,extend:o,xloc:n,text_size:b,text_halign:z,text_valign:i,text_wrap:s,text_font_family:a}=e,O="box.new";this._paramVerfiy(r,t,O,[n2.styleDashed,n2.styleDotted,n2.styleSolid],"border_style"),this._paramVerfiy(o,t,O,Object.values(fe),"extend"),this._paramVerfiy(n,t,O,Object.values(P1),"xloc"),this._paramVerfiy(b,t,O,Object.values(L2),"text_size"),this._paramVerfiy(z,t,O,[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"),this._paramVerfiy(i,t,O,[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"),this._paramVerfiy(s,t,O,[t1.wrapAuto,t1.wrapNone],"text_wrap"),this._paramVerfiy(a,t,O,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_top({id:e},t){return e==null?void 0:e.get_top(t)}get_bottom({id:e},t){return e==null?void 0:e.get_bottom(t)}get_left({id:e},t){return e==null?void 0:e.get_left(t)}get_right({id:e},t){return e==null?void 0:e.get_right(t)}set_top({id:e,...t},r){e==null||e.set_top(t,r)}set_bottom({id:e,...t},r){e==null||e.set_bottom(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_left({id:e,...t},r){e==null||e.set_left(t,r)}set_right({id:e,...t},r){e==null||e.set_right(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({id:e,...t},r){e==null||e.set_border_width(t,r)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t},r){e==null||e.set_lefttop(t,r)}set_rightbottom({id:e,...t},r){e==null||e.set_rightbottom(t,r)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t},r){e==null||e.set_text_color(t,r)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t},r){e==null||e.set_top_left_point(t,r)}set_bottom_right_point({id:e,...t},r){e==null||e.set_bottom_right_point(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Qo{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.BOX}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.box.get(this._id)||this._data}copy(e){B0(this._errorListener,"box.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`box_${e}_${t}`,o=this._getBox(),n={...o,id:r,bar_index:t},b=new Qo(this._variables,r,this._errorListener,n);return o&&this._variables.box.add(r,n,b),b}delete(e){B0(this._errorListener,"box.delete",this._variables.__requestName,e),this._variables.box.delete(this._id,this._variables.bar_index,this._data.id)}get_top(e){B0(this._errorListener,"box.get_top",this._variables.__requestName,e);const t=this._getBox();return t&&t.top}set_top({top:e},t){B0(this._errorListener,"box.set_top",this._variables.__requestName,t);const r=this._getBox();r&&(r.top=e)}get_left(e){B0(this._errorListener,"box.get_left",this._variables.__requestName,e);const t=this._getBox();return t&&t.left}set_left({left:e},t){B0(this._errorListener,"box.set_left",this._variables.__requestName,t);const r=this._getBox();r&&(r.left=e&&Math.round(e))}set_text({text:e},t){B0(this._errorListener,"box.set_text",this._variables.__requestName,t);const r=this._getBox();r&&(r.text=e)}get_right(e){B0(this._errorListener,"box.get_right",this._variables.__requestName,e);const t=this._getBox();return t&&t.right}set_right({right:e},t){B0(this._errorListener,"box.set_right",this._variables.__requestName,t);const r=this._getBox();r&&(r.right=e&&Math.round(e))}get_bottom(e){B0(this._errorListener,"box.get_bottom",this._variables.__requestName,e);const t=this._getBox();return t&&t.bottom}set_bottom({bottom:e},t){B0(this._errorListener,"box.set_bottom",this._variables.__requestName,t);const r=this._getBox();r&&(r.bottom=e)}set_extend({extend:e},t){B0(this._errorListener,"box.set_extend",this._variables.__requestName,t);const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(fe),"extend"))}set_bgcolor({color:e},t){B0(this._errorListener,"box.set_bgcolor",this._variables.__requestName,t);const r=this._getBox();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_lefttop({left:e,top:t},r){B0(this._errorListener,"box.set_lefttop",this._variables.__requestName,r);const o=this._getBox();o&&(o.left=e&&Math.round(e),o.top=t)}set_text_size({text_size:e},t){B0(this._errorListener,"box.set_text_size",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(L2),"text_size"))}set_text_wrap({text_wrap:e},t){B0(this._errorListener,"box.set_text_wrap",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[t1.wrapAuto,t1.wrapNone],"text_wrap"))}set_text_color({text_color:e},t){B0(this._errorListener,"box.set_text_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_color=e,S1(r,["text_color"]))}set_rightbottom({right:e,bottom:t},r){B0(this._errorListener,"box.set_rightbottom",this._variables.__requestName,r);const o=this._getBox();o&&(o.right=e&&Math.round(e),o.bottom=t)}set_text_halign({text_halign:e},t){B0(this._errorListener,"box.set_text_halign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){B0(this._errorListener,"box.set_text_valign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"))}set_top_left_point({point:e},t){B0(this._errorListener,"box.set_top_left_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.top=n,r.left=r.xloc===P1.bar_index?o:b}}set_border_color({color:e},t){B0(this._errorListener,"box.set_border_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_style({style:e},t){B0(this._errorListener,"box.set_border_style",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[n2.styleDashed,n2.styleDotted,n2.styleSolid],"style"))}set_border_width({width:e},t){B0(this._errorListener,"box.set_border_width",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_width=e)}set_bottom_right_point({point:e},t){B0(this._errorListener,"box.set_bottom_right_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.bottom=n,r.right=r.xloc===P1.bar_index?o:b}}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"box.set_text_font_family",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(St),"text_font_family"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getBox(){return this._variables.box.get(this._id)||this._data}}class U_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultTable",{position:P2.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e}){return e}new(e,t){B0(this._errorListener,"table.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`table_${t}_${r}`,{rows:n}=e;S1(e,["text_color","bgcolor","border_color"]);const b=Array.from(Array(n),()=>[]),z=t.split("_"),i=z.pop(),s=z.pop(),a={...this._defaultTable,...e,cell:b,id:o,bar_index:r,line:s,col:i},O=new C3(this._variables,o,this._errorListener,a);return this._paramVerfiy(e.position,t,"table.new",Object.values(P2),"position"),t.startsWith("export")||this._variables.table.add(o,a,O),O}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}cell({table_id:e,...t},r){e==null||e.cell(t,r)}cell_set_bgcolor({table_id:e,...t},r){e==null||e.cell_set_bgcolor(t,r)}cell_set_height({table_id:e,...t},r){e==null||e.cell_set_height(t,r)}cell_set_text({table_id:e,...t},r){e==null||e.cell_set_text(t,r)}cell_set_text_color({table_id:e,...t},r){e==null||e.cell_set_text_color(t,r)}cell_set_text_font_family({table_id:e,...t},r){e==null||e.cell_set_text_font_family(t,r)}cell_set_text_halign({table_id:e,...t},r){e==null||e.cell_set_text_halign(t,r)}cell_set_text_valign({table_id:e,...t},r){e==null||e.cell_set_text_valign(t,r)}cell_set_text_size({table_id:e,...t},r){e==null||e.cell_set_text_size(t,r)}cell_set_tooltip({table_id:e,...t},r){e==null||e.cell_set_tooltip(t,r)}cell_set_width({table_id:e,...t},r){e==null||e.cell_set_width(t,r)}clear({table_id:e,...t},r){e==null||e.clear(t,r)}delete({table_id:e},t){e==null||e.delete(t)}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({table_id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({table_id:e,...t},r){e==null||e.set_border_width(t,r)}set_frame_color({table_id:e,...t},r){e==null||e.set_frame_color(t,r)}set_frame_width({table_id:e,...t},r){e==null||e.set_frame_width(t,r)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class C3{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_defaultCell",{column:0,row:0,text:"",text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_size:L2.normal});E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.TABLE}get id(){return this._id}get preId(){return this._preId}set data(e){this._data=e}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get data(){return this._variables.table.get(this._id)||this._data}cell(e,t){this._verfiyRequestFunc(t,"cell");const r={...this._defaultCell,...e},{column:o=0,row:n=0}=r,b=this._getTable();if(b){const z=b.cell||[],i=z[n]||[];i[o]=r,z[n]=i,b.cell=z}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r},o){this._verfiyRequestFunc(o,"cell_set_bgcolor");const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r},o){this._verfiyRequestFunc(o,"cell_set_height");const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r},o){this._verfiyRequestFunc(o,"cell_set_text");const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r},o){this._verfiyRequestFunc(o,"cell_set_text_color");const n=this._getTableItem(e,t);n&&(n.text_color=r,S1(n,["text_color"]))}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r},o){this._verfiyRequestFunc(o,"cell_set_text_font_family");const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r},o){this._verfiyRequestFunc(o,"cell_set_text_halign");const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r},o){this._verfiyRequestFunc(o,"cell_set_text_valign");const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r},o){this._verfiyRequestFunc(o,"cell_set_text_size");const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r},o){this._verfiyRequestFunc(o,"cell_set_tooltip");const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r},o){this._verfiyRequestFunc(o,"cell_set_width");const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){this._verfiyRequestFunc(n,"clear");const b=this._getTable();if(b){const z=b.cell;if(z)for(let i=t;i<=o;i++)for(let s=e;s<=r;s++){const a=z[i];a&&(a[s]=void 0)}}}delete(e){this._verfiyRequestFunc(e,"delete"),this._variables.table.delete(this._id,this._variables.bar_index,this._data.id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){if(this._verfiyRequestFunc(n,"merge_cells"),e>r||t>o){this._errorListener.addError(l1.mergeCellErr,n,$0.Error);return}const b=this._getTable();if(!b)return;const z=b.merge_cells||[];z.push({start_column:e,start_row:t,end_column:r,end_row:o}),b.merge_cells=z}set_bgcolor({bgcolor:e},t){this._verfiyRequestFunc(t,"set_bgcolor");const r=this._getTable();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_border_color({border_color:e},t){this._verfiyRequestFunc(t,"set_border_color");const r=this._getTable();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_width({border_width:e},t){this._verfiyRequestFunc(t,"set_border_width");const r=this._getTable();r&&(r.border_width=e)}set_frame_color({frame_color:e},t){this._verfiyRequestFunc(t,"set_frame_color");const r=this._getTable();r&&(r.frame_color=e)}set_frame_width({frame_width:e},t){this._verfiyRequestFunc(t,"set_frame_width");const r=this._getTable();r&&(r.frame_width=e)}set_position({position:e},t){this._verfiyRequestFunc(t,"set_position");const r=this._getTable();r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(P2),"position"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getTableItem(e,t){const r=this._getTable();if(r){const o=r.cell;return o?o[t][e]:void 0}}_getTable(){return this._variables.table.get(this._id)||this._data}_verfiyRequestFunc(e,t){B0(this._errorListener,`table.${t}`,this._variables.__requestName,e)}}class j_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){return this._verifyTradeNum(e,t)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.historyOrders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.historyOrders[e];return o||r}exit_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{out_qty:r=0,direction:o}=this._strategy.historyOrders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.closedtrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.historyOrders.length;return!(e>=r)}}class H_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,original_qty:o=0,commission:n=0}=this._strategy.orders[e];return n*r/o}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.orders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.orders[e];return o||r}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,direction:o}=this._strategy.orders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.opentrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.orders.length;return!(e>=r)}}class Y_{constructor(e,t){E(this,"_strategy");E(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(i1),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}}var G_=20,V_=1,Gt=1e6,x3=1e6,K_=-7,J_=21,Q_=!1,WM="[big.js] ",Vt=WM+"Invalid ",Zo=Vt+"decimal places",Z_=Vt+"rounding mode",S3=WM+"Division by zero",m1={},xe=void 0,em=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function F3(){function M(e){var t=this;if(!(t instanceof M))return e===xe?F3():new M(e);if(e instanceof M)t.s=e.s,t.e=e.e,t.c=e.c.slice();else{if(typeof e!="string"){if(M.strict===!0&&typeof e!="bigint")throw TypeError(Vt+"value");e=e===0&&1/e<0?"-0":String(e)}tm(t,e)}t.constructor=M}return M.prototype=m1,M.DP=G_,M.RM=V_,M.NE=K_,M.PE=J_,M.strict=Q_,M.roundDown=0,M.roundHalfUp=1,M.roundHalfEven=2,M.roundUp=3,M}function tm(M,e){var t,r,o;if(!em.test(e))throw Error(Vt+"number");for(M.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1,(t=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(t<0&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):t<0&&(t=e.length),o=e.length,r=0;r<o&&e.charAt(r)=="0";)++r;if(r==o)M.c=[M.e=0];else{for(;o>0&&e.charAt(--o)=="0";);for(M.e=t-r-1,M.c=[],t=0;r<=o;)M.c[t++]=+e.charAt(r++)}return M}function Kt(M,e,t,r){var o=M.c;if(t===xe&&(t=M.constructor.RM),t!==0&&t!==1&&t!==2&&t!==3)throw Error(Z_);if(e<1)r=t===3&&(r||!!o[0])||e===0&&(t===1&&o[0]>=5||t===2&&(o[0]>5||o[0]===5&&(r||o[1]!==xe))),o.length=1,r?(M.e=M.e-e+1,o[0]=1):o[0]=M.e=0;else if(e<o.length){if(r=t===1&&o[e]>=5||t===2&&(o[e]>5||o[e]===5&&(r||o[e+1]!==xe||o[e-1]&1))||t===3&&(r||!!o[0]),o.length=e,r){for(;++o[--e]>9;)if(o[e]=0,e===0){++M.e,o.unshift(1);break}}for(e=o.length;!o[--e];)o.pop()}return M}function Jt(M,e,t){var r=M.e,o=M.c.join(""),n=o.length;if(e)o=o.charAt(0)+(n>1?"."+o.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)o="0"+o;o="0."+o}else if(r>0)if(++r>n)for(r-=n;r--;)o+="0";else r<n&&(o=o.slice(0,r)+"."+o.slice(r));else n>1&&(o=o.charAt(0)+"."+o.slice(1));return M.s<0&&t?"-"+o:o}m1.abs=function(){var M=new this.constructor(this);return M.s=1,M},m1.cmp=function(M){var e,t=this,r=t.c,o=(M=new t.constructor(M)).c,n=t.s,b=M.s,z=t.e,i=M.e;if(!r[0]||!o[0])return r[0]?n:o[0]?-b:0;if(n!=b)return n;if(e=n<0,z!=i)return z>i^e?1:-1;for(b=(z=r.length)<(i=o.length)?z:i,n=-1;++n<b;)if(r[n]!=o[n])return r[n]>o[n]^e?1:-1;return z==i?0:z>i^e?1:-1},m1.div=function(M){var e=this,t=e.constructor,r=e.c,o=(M=new t(M)).c,n=e.s==M.s?1:-1,b=t.DP;if(b!==~~b||b<0||b>Gt)throw Error(Zo);if(!o[0])throw Error(S3);if(!r[0])return M.s=n,M.c=[M.e=0],M;var z,i,s,a,O,u=o.slice(),l=z=o.length,d=r.length,A=r.slice(0,z),h=A.length,q=M,_=q.c=[],m=0,L=b+(q.e=e.e-M.e)+1;for(q.s=n,n=L<0?0:L,u.unshift(0);h++<z;)A.push(0);do{for(s=0;s<10;s++){if(z!=(h=A.length))a=z>h?1:-1;else for(O=-1,a=0;++O<z;)if(o[O]!=A[O]){a=o[O]>A[O]?1:-1;break}if(a<0){for(i=h==z?o:u;h;){if(A[--h]<i[h]){for(O=h;O&&!A[--O];)A[O]=9;--A[O],A[h]+=10}A[h]-=i[h]}for(;!A[0];)A.shift()}else break}_[m++]=a?s:++s,A[0]&&a?A[h]=r[l]||0:A=[r[l]]}while((l++<d||A[0]!==xe)&&n--);return!_[0]&&m!=1&&(_.shift(),q.e--,L--),m>L&&Kt(q,L,t.RM,A[0]!==xe),q},m1.eq=function(M){return this.cmp(M)===0},m1.gt=function(M){return this.cmp(M)>0},m1.gte=function(M){return this.cmp(M)>-1},m1.lt=function(M){return this.cmp(M)<0},m1.lte=function(M){return this.cmp(M)<1},m1.minus=m1.sub=function(M){var e,t,r,o,n=this,b=n.constructor,z=n.s,i=(M=new b(M)).s;if(z!=i)return M.s=-i,n.plus(M);var s=n.c.slice(),a=n.e,O=M.c,u=M.e;if(!s[0]||!O[0])return O[0]?M.s=-i:s[0]?M=new b(n):M.s=1,M;if(z=a-u){for((o=z<0)?(z=-z,r=s):(u=a,r=O),r.reverse(),i=z;i--;)r.push(0);r.reverse()}else for(t=((o=s.length<O.length)?s:O).length,z=i=0;i<t;i++)if(s[i]!=O[i]){o=s[i]<O[i];break}if(o&&(r=s,s=O,O=r,M.s=-M.s),(i=(t=O.length)-(e=s.length))>0)for(;i--;)s[e++]=0;for(i=e;t>z;){if(s[--t]<O[t]){for(e=t;e&&!s[--e];)s[e]=9;--s[e],s[t]+=10}s[t]-=O[t]}for(;s[--i]===0;)s.pop();for(;s[0]===0;)s.shift(),--u;return s[0]||(M.s=1,s=[u=0]),M.c=s,M.e=u,M},m1.mod=function(M){var e,t=this,r=t.constructor,o=t.s,n=(M=new r(M)).s;if(!M.c[0])throw Error(S3);return t.s=M.s=1,e=M.cmp(t)==1,t.s=o,M.s=n,e?new r(t):(o=r.DP,n=r.RM,r.DP=r.RM=0,t=t.div(M),r.DP=o,r.RM=n,this.minus(t.times(M)))},m1.neg=function(){var M=new this.constructor(this);return M.s=-M.s,M},m1.plus=m1.add=function(M){var e,t,r,o=this,n=o.constructor;if(M=new n(M),o.s!=M.s)return M.s=-M.s,o.minus(M);var b=o.e,z=o.c,i=M.e,s=M.c;if(!z[0]||!s[0])return s[0]||(z[0]?M=new n(o):M.s=o.s),M;if(z=z.slice(),e=b-i){for(e>0?(i=b,r=s):(e=-e,r=z),r.reverse();e--;)r.push(0);r.reverse()}for(z.length-s.length<0&&(r=s,s=z,z=r),e=s.length,t=0;e;z[e]%=10)t=(z[--e]=z[e]+s[e]+t)/10|0;for(t&&(z.unshift(t),++i),e=z.length;z[--e]===0;)z.pop();return M.c=z,M.e=i,M},m1.pow=function(M){var e=this,t=new e.constructor("1"),r=t,o=M<0;if(M!==~~M||M<-x3||M>x3)throw Error(Vt+"exponent");for(o&&(M=-M);M&1&&(r=r.times(e)),M>>=1,!!M;)e=e.times(e);return o?t.div(r):r},m1.prec=function(M,e){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");return Kt(new this.constructor(this),M,e)},m1.round=function(M,e){if(M===xe)M=0;else if(M!==~~M||M<-Gt||M>Gt)throw Error(Zo);return Kt(new this.constructor(this),M+this.e+1,e)},m1.sqrt=function(){var M,e,t,r=this,o=r.constructor,n=r.s,b=r.e,z=new o("0.5");if(!r.c[0])return new o(r);if(n<0)throw Error(WM+"No square root");n=Math.sqrt(+Jt(r,!0,!0)),n===0||n===1/0?(e=r.c.join(""),e.length+b&1||(e+="0"),n=Math.sqrt(e),b=((b+1)/2|0)-(b<0||b&1),M=new o((n==1/0?"5e":(n=n.toExponential()).slice(0,n.indexOf("e")+1))+b)):M=new o(n+""),b=M.e+(o.DP+=4);do t=M,M=z.times(t.plus(r.div(t)));while(t.c.slice(0,b).join("")!==M.c.slice(0,b).join(""));return Kt(M,(o.DP-=4)+M.e+1,o.RM)},m1.times=m1.mul=function(M){var e,t=this,r=t.constructor,o=t.c,n=(M=new r(M)).c,b=o.length,z=n.length,i=t.e,s=M.e;if(M.s=t.s==M.s?1:-1,!o[0]||!n[0])return M.c=[M.e=0],M;for(M.e=i+s,b<z&&(e=o,o=n,n=e,s=b,b=z,z=s),e=new Array(s=b+z);s--;)e[s]=0;for(i=z;i--;){for(z=0,s=b+i;s>i;)z=e[s]+n[i]*o[s-i-1]+z,e[s--]=z%10,z=z/10|0;e[s]=z}for(z?++M.e:e.shift(),i=e.length;!e[--i];)e.pop();return M.c=e,M},m1.toExponential=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),++M,e);t.c.length<M;)t.c.push(0)}return Jt(t,!0,!!r)},m1.toFixed=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),M+t.e+1,e),M=M+t.e+1;t.c.length<M;)t.c.push(0)}return Jt(t,!1,!!r)},m1[Symbol.for("nodejs.util.inspect.custom")]=m1.toJSON=m1.toString=function(){var M=this,e=M.constructor;return Jt(M,M.e<=e.NE||M.e>=e.PE,!!M.c[0])},m1.toNumber=function(){var M=+Jt(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(M.toString()))throw Error(WM+"Imprecise conversion");return M},m1.toPrecision=function(M,e){var t=this,r=t.constructor,o=t.c[0];if(M!==xe){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");for(t=Kt(new r(t),M,e);t.c.length<M;)t.c.push(0)}return Jt(t,M<=t.e||t.e<=r.NE||t.e>=r.PE,!!o)},m1.valueOf=function(){var M=this,e=M.constructor;if(e.strict===!0)throw Error(WM+"valueOf disallowed");return Jt(M,M.e<=e.NE||M.e>=e.PE,!0)};var en=F3();function I3(M,e){return en(M).plus(e).toNumber()}function tn(M,e){return en(M).minus(e).toNumber()}function Qt(M,e){return en(M).mul(e).toNumber()}function rn(M,e=5){return Number(M&&en(M).toFixed(e))}let rm=class{constructor(e,t,r,o,n){E(this,"_variables");E(this,"_options");E(this,"_totalChangeCapital");E(this,"_historyOrder");E(this,"_orders");E(this,"_exitOrders");E(this,"_pendingOrders");E(this,"_mintick");E(this,"_funcOptions");E(this,"_pendingCloseOrders");E(this,"_errorListener");E(this,"_risk");E(this,"_opentrades");E(this,"_closedtrades");E(this,"_riskNamespace");E(this,"_updateOptions",{});E(this,"_id");E(this,"_maxDrawdownVerifyIndex",0);E(this,"calcOnOrderFillsData",{index:-1});this._variables=e,this._errorListener=o,this._options={overlay:!1,format:O1.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:b2.fixed,default_qty_value:1,initial_capital:1e6,currency:D3.NONE,slippage:0,commission_type:O2.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=t,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 H_(this),this._closedtrades=new j_(this),this._riskNamespace=new Y_(this,o),this._id=`strategy_${n}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;return this._orders.reduce((t,r)=>t+e*(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(e){this._updateOptions=e||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._ordersHandle(),this._pendingOrderHandle(),this._exitOrdersHandle(),this._maxIntradayFilledOrdersVerify(),this._maxDrawdownVerify();const{open:e,high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,o=this._variables.close;this._variables.strategy.update(this.calcOnOrderFillsData.currentData||{open:e,close:o,high:t,low:r}),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}calcCurrentOrder(){this._ordersHandle(),this._pendingOrderHandle(),this._calcProfitAndLoss()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var l;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{time_tradingday:o,time:n,strategy:{netprofit:b,initial_capital:z}}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables;let{preNetprofit:a=0}=this._risk;n===o&&(a=b,this._risk.preNetprofit=b,this._risk.isTemporaryBan=!1);let O=a-b;O+=this._orders.reduce((d,A)=>{const{in_price:h,direction:q,qty:_=0,commission:m=0,original_qty:L=0}=A,g=q===i1.long?1:-1,v=(i-h)*_,y=(s-h)*_,X=g===1?y:-v;return d+X+_/L*m},0);let u=!1;switch(t){case b2.cash:u=e<O;break;case b2.percentOfEquity:const d=O/(z+b)*100;u=e<d;break}if(u){this._risk.isTemporaryBan=!0;const d=(l=this._orders[0])==null?void 0:l.direction;this._closeOrders(this._orders,d===i1.long?s:i,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:o,time_tradingday:n}=this._variables,{open:b}=this.calcOnOrderFillsData.data||this._variables;o===n&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,b,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:o=0}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:b,strategy:z}=this._variables,{open:i}=this.calcOnOrderFillsData.data||this._variables;let s=t;if(n===b){const a=z.netprofit+z.openprofit;a<o?s=0:s++,Object.assign(this._risk,{lossDays:s,totalProfit:a})}e<=s&&this._riskTouchOff(i,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:o}=this._variables,{open:n}=this.calcOnOrderFillsData.data||this._variables;if(e!==void 0&&t&&this._maxDrawdownVerifyIndex===o){const{initial_capital:b}=this._options,i=this._orders.reduce((a,O)=>{const{in_price:u,commission:l=0,qty:d=0,original_qty:A=0,direction:h}=O,q=h===i1.long?1:-1,_=(n-u)*q*d;return a+_+l*d/A},0)+this._totalChangeCapital;let s=!1;switch(t){case b2.percentOfEquity:s=i/b*100<=-e;break;case b2.cash:s=i<=-e;break}s&&this._riskTouchOff(n,"Close Position (Max Drawdown)")}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,e,t,"close"),this._pendingOrders=[]}strategy(e,t){if(!this._variables.bar_index){this._paramVerfiy(e.format,t,"strategy",[O1.inherit,O1.price,O1.percent,O1.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(b2),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(O2),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),o={...this._updateOptions};if(r)for(const n of Object.keys({...r,...e}))e[n]!==r[n]&&delete o[n];this._variables.max_bars_back=e.max_bars_back||0,self==null||self.workerStorage.set(this._id,e),Object.assign(this._options,e,o),this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:o,scriptType:"strategy"})}}order(e,t){this._verfiyRequestFunc(t,"order"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(Ue),"oca_type"),this._orderHandle(e))}entry(e,t){this._verfiyRequestFunc(t,"entry"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(Ue),"oca_type"),this._entryHandle(e))}close(e,t){if(this._verfiyRequestFunc(t,"close"),!this._getCloseOrders(e.id).length)return;const{immediately:o}=e;if(o||this._options.process_orders_on_close){const n=this._pendingCloseOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingCloseOrders.push({...e,place_order_type:"close"})}else{const n=this._pendingOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingOrders.push({...e,place_order_type:"close"})}}close_all(e,t){if(this._verfiyRequestFunc(t,"close_all"),typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:r}=e;r||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e},t){this._verfiyRequestFunc(t,"cancel"),this._pendingOrders=this._pendingOrders.filter(r=>!(r.id===e&&r.place_order_type!=="close"))}cancel_all(e){this._verfiyRequestFunc(e,"cancel_all"),this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(e,t){this._verfiyRequestFunc(t,"exit"),this._exit(e,t)}convert_to_account({value:e},t){return this._verfiyRequestFunc(t,"convert_to_account"),e}convert_to_symbol({value:e},t){return this._verfiyRequestFunc(t,"convert_to_symbol"),e}default_entry_qty({fill_price:e},t){return this._verfiyRequestFunc(t,"default_entry_qty"),e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=b2.fixed,default_qty_value:r=1,initial_capital:o,commission_value:n}=this._options;let b=r;switch(t){case b2.cash:b=r/e;break;case b2.percentOfEquity:const z=this._getOrderProfit(e),i=o+z+this._totalChangeCapital;n?b=this._getCommQty(i,e):b=i*r/100/e;break}return sc(b,this._getLen())}_calcExitQty(e){if(!String(e).includes("."))return e;const t=this._getLen();return Math.ceil(Qt(e,Math.pow(10,t)))}_getCommQty(e,t){const{commission_type:r,commission_value:o=0,default_qty_value:n=0}=this._options;let b=0;switch(r){case O2.percent:b=e*n/(100*t+o*t);break;case O2.cashPerContract:b=e*n/(100*t+o);break;case O2.cashPerOrder:b=(e-o)*n/100/t}return b}_getLen(){const e=5-(this._variables.precision||5);return e<0?0:e}_getCapital(e,t){const{margin_long:r=0,margin_short:o=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:o<=100&&o>0&&e===-1&&(t=t*100/o),t}_calcProfitAndLoss(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;for(const t of this._orders){const{in_price:r,qty:o=0,direction:n}=t,b=n===i1.long?1:-1,z=(e-r)*b*o,[i,s]=this._calcProfitAndLossHandle(r,o,b);this._calcOrderPercent(t,z,i,s)}}_calcProfitAndLossHandle(e,t,r,o){const{high:n,low:b}=this.calcOnOrderFillsData.data||this._variables,z=((o||n)-e)*t,i=((o||b)-e)*t;let s=r===1?z:-i,a=r===1?i:-z;return[s,a]}_calcOrderPercent(e,t,r,o){const{commission_value:n}=this._options,{close:b}=this.calcOnOrderFillsData.data||this._variables,{original_qty:z=0,qty:i=0,in_price:s,max_profit:a=0,trading_loss:O=0}=e;let{commission:u=0}=e,l=s*i;if(n){const d=this._getCommission(b,i);u=u*i/z,r-=u,o-=u,l+=u,t=t-d-u}r=Math.max(r,a,0),o=Math.min(o,O,0),Object.assign(e,{profit:t,total_profit:this._totalChangeCapital+t,total_profit_percent:t/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:o,profit_percent:t/l*100,max_profit_percent:r/l*100,trading_loss_percent:o/l*100})}_calcLiquidate(){if(!this._orders.length)return;const{time:e}=this._variables,{high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,{initial_capital:o,margin_long:n=0,margin_short:b=0}=this._options,z=this._orders[0].direction===i1.long?1:-1;let i=z===1?r:t;if(z===1&&n===100)return;const s=(z===1?n:b)/100;if(s<=0)return;let a=!1;const[O,u]=this._orders.reduce((h,q)=>{let[_,m]=h;const{in_price:L,qty:g=0,in_time:v}=q;v===e&&(a=!0);const y=L*g,X=i*g;return _+=y,m+=X,[_,m]},[0,0]);let l=0,d=0;const A=o+this._totalChangeCapital;if(a&&(l=A-O*s,l<0&&(i=this._orders[0].in_price,d=Math.abs(Math.trunc(l/s/i)*4),d=Math.max(d,1))),l>=0){const h=z*(u-O);if(l=A+h-u*s,l>=0)return;d=Math.abs(Math.trunc(l/s/i)*4)}d<=0||this._marginCallOrders(i,d,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:o="FIFO"}=this._options;if(o==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r,!0);return}for(const n of this.orders)n.position_close_type=n.place_order_type,n.isTiggerClose=!0,this._processOrder(n,e,t,r,r,!0);this._orders=this._orders.filter(n=>!n.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e),s=e.direction===i1.long?1:-1;if(o<=0)return;let a=o;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"order"});return}this._judgeCapitalEnough(o,b,s)&&this._addPendingOrders(e,b,a,r,z)}_orderOnCloseHandle(e){const t=this._orders.filter(_=>_.direction!==e.direction),{slippage:r=0}=this._options;let{direction:o,qty:n=0,id:b,comment:z,oca_type:i,oca_name:s,in_price:a}=e;const O=o===i1.long?1:-1;if(t.length){const _=this._processOrders(t,a,n,b,z,!1,"order");if(_<=0)return;n=_}const u=a-O*r*this._mintick;if(!this._judgeCapitalEnough(n,u,O))return;this._ocaGroupVerify(n,s,i);const{bar_index:d,time:A}=this._variables,{high:h,low:q}=this.calcOnOrderFillsData.data||this._variables;this._calcCurrentOrder({...e,in_price:u,in_high:h,in_low:q,in_index:d,in_time:A,qty:n,place_order_type:"order"})}_judgeCapitalEnough(e,t,r){let o=this._freezeCapital;if(this._orders.some(a=>(a.direction===i1.long?1:-1)!==r)&&(o=0),e<=0)return!1;const{margin_long:n=0,margin_short:b=0}=this._options;if(n===0&&r===1||b===0&&r===-1)return!0;const z=this._getOrderProfit(t),s=this._getCapital(r,this._options.initial_capital+z+this._totalChangeCapital)-o;return e*t<=s}_getOrderProfit(e){return this._orders.reduce((t,r)=>{const{in_price:o,qty:n=0,direction:b}=r,z=b===i1.long?1:-1;return t+(e-o)*n*z},0)}_ocaGroupVerify(e,t,r){if(!t||!r||r===Ue.none)return!1;let o=!1;switch(r){case Ue.cancel:this._pendingOrders=this._pendingOrders.filter(n=>{if(n.oca_name===t)n.isCancel=!0,o=!0;else return!0});break;case Ue.reduce:this._pendingOrders=this._pendingOrders.filter(n=>{const{qty:b=0,oca_name:z}=n;if(t===z){const i=b-e;return o=!0,i<=0?(n.isCancel=!0,!1):(n.qty=i,!0)}else return!0});break}return o}_processOrders(e,t,r,o,n,b=!1,z,i){if(!e.length)return r;let s=r;for(const a of e)if(a.position_close_type=z||a.place_order_type,a.immediately=i,a.isTiggerClose=b||a.position_close_type==="close",s=this._processOrder(a,t,s,o,n,b),s<=0)break;return this._orders=this._orders.filter(a=>!a.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),s}_addPendingOrders(e,t,r,o,n){const b=this._pendingOrders.find(z=>z.id===e.id&&!z.isMarketPrice);if(b)Object.assign(b,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const z={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"order"};this._pendingOrders.push(z)}}_orderArgsParse(e){var q,_;const{direction:t,qty:r,stop:o}=e;let n=e.limit||0,{close:b}=this.calcOnOrderFillsData.data||this._variables;(_=(q=this.calcOnOrderFillsData)==null?void 0:q.tradeData)!=null&&_.open&&(b=this.calcOnOrderFillsData.tradeData.open);let z=b,i=!1,s;const a=t===i1.long?1:-1,O=o&&(o-b)*a>=0,{backtest_fill_limits_assumption:u=0}=this._options;u>0&&n&&(n-=u*this._mintick*a);const l=n&&(n-b)*a<=0;let d=!1;O&&l?(o!==b&&(s=o),z=n):O?(z=o,d=o===b):l?(z=n,d=n===b):i=!0;const A=r!==void 0?sc(r,this._getLen()):this._calcDefaultQty(z);return{orders:this._orders.filter(m=>m.direction!==t),isMarketPrice:i,activePrice:s,quantities:A,close:b,price:z,isTouch:d}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e);if(o<=0)return;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"entry"});return}this._judgeCapitalEnough(o,n,e.direction===i1.long?1:-1)&&this._addPendingEntry(e,b,o,r,z)}_entryOnCloseHandle(e){const{direction:t,in_price:r,qty:o=0}=e,n=this._orders.filter(b=>b.direction!==t);this._entryOrder(n,r,o,e)}_entryOrder(e,t,r,o){const{time:n,bar_index:b}=this._variables,{high:z,low:i}=this.calcOnOrderFillsData.data||this._variables,{slippage:s=0}=this._options,{oca_name:a,oca_type:O,direction:u,comment:l,id:d}=o,A=u===i1.long?1:-1;if(r=this._getAvailablePositionSize(r,u),r<=0)return;const h=t;if(t=t+s*this._mintick*A,!this._judgeCapitalEnough(r,t,A))return;this._closeOrders(e,h,d,l,"entry",void 0,!0);const _={...o,in_price:t,qty:r,in_index:b,in_high:z,in_low:i,in_time:n,place_order_type:"entry"},{orders:m}=this._getEntryOrders(u),L=m.length;L&&L>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,a,O),this._calcCurrentOrder(_))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:o}=this._risk;if(o&&o!==i1.all&&o!==t)return 0;if(r===void 0)return e;const n=this._orders.reduce((b,z)=>b+(z.qty||0),0);return n?n+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(o=>["entry","order"].includes(o.place_order_type)&&o.direction===e),r=this._orders.filter(o=>o.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,o,n){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:b}=this._getEntryOrders(e.direction),z=b.find(i=>i.id===e.id&&i.place_order_type==="entry");if(z)Object.assign(z,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const i={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"entry"};this._pendingOrders.push(i)}}_closeAllOrders(e,t){const{comment:r,immediately:o}=e,{bar_index:n}=this._variables,b=this._orders.filter(z=>z.in_index!==n);b.length&&(this._closeOrders(b,t,"Close position order",r,"close",o),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,o,n,b,z){if(e.length){for(const i of e)i.position_close_type=n,i.immediately=b,i.isTiggerClose=!0,this._closeOrder(i,t,r,o,z);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}}_closeOrder(e,t,r,o,n){const{time:b,bar_index:z}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables,{slippage:a=0}=this._options,{in_price:O,qty:u=0,direction:l}=e,d=l===i1.long?1:-1;t=t-d*a*this._mintick,e.isDeal=!0;const A=(t-O)*d*u,h={...e,out_price:t,out_id:r,out_index:z,out_high:i,out_low:s,out_time:b,out_comment:o,out_qty:u,profit:A};this._calcPercent(h,n)}_exitOrdersHandle(){if(!this._exitOrders.length)return;let{open:e,low:t,high:r,close:o}=this.calcOnOrderFillsData.data||this._variables;const n=[],b=Math.abs(r-e),z=Math.abs(t-e),i=[],s=this._variables.precision;e=Number(e.toFixed(s)),t=Number(t.toFixed(s)),r=Number(r.toFixed(s)),o=Number(o.toFixed(s));for(const a of this._exitOrders){const{directionNum:O,id:u,comment:l,qty:d,comment_loss:A,comment_profit:h,comment_trailing:q,order:_}=a;if(_.isTiggerClose)continue;let m=b<z||b===z&&O===1;if(_.in_time===this._variables.time&&!this._variables._isRepeated){const{in_price:D}=_;m?D<r&&D>=e?e=D:D<=r&&D>=o?r=D:r=o:D<=e&&D>t?e=D:D<=o&&D>=t?t=D:t=o,e=D}const L=[],[g,v]=this._getLimitPrice(a,e,t,r,m);g&&L.push({order:_,price:g,index:v,isHighFront:m,exitInfo:{id:u,comment:h||l,qty:d}});const[y,X]=this._getStopPrice(a,e,t,r,m);y&&L.push({order:_,price:y,index:X,isHighFront:m,exitInfo:{id:u,comment:A||l,qty:d}});const[T,N]=this._getTrailStopPrice(a,e,t,r,o,m);if(T&&L.push({order:_,price:T,index:N,isHighFront:m,exitInfo:{id:u,comment:q||l,qty:d}}),L.length){this._executesSort(L),n.push(L[0]);continue}i.push(a)}this._exitOrders=i,this._executesSort(n);for(const a of n){const{order:O,price:u,exitInfo:l,isHighFront:d,index:A}=a;d?(r=A===1?u:r,t=A===1?e:u):(r=A===1?e:u,t=A===1?u:t),this._variables.strategy.update({open:u,high:r,low:t,close:o}),this._processExitOnClose(O,u,l)}}_executesSort(e){return e.sort(({price:t,index:r,isHighFront:o},{price:n,index:b})=>r!==b?r-b:o?r===1?t-n:n-t:r===1?n-t:t-n),e}_getLimitPrice(e,t,r,o,n){const{limit:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z>=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getStopPrice(e,t,r,o,n){const{stop:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z<=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getTrailStopPrice(e,t,r,o,n,b){const{trail_stop_price:z,directionNum:i,active_price:s,trail_offset:a=0}=e;let O=z,u,l=1;if(O)if((O-t)*i>=0)u=t,l=1;else{const[d,A,h]=this._calcTrailStopPrice(O,o,r,n,a,i,b);u=A,l=h||1,e.trail_stop_price=d}if(s&&!u&&s<=o&&s>=r)if(a===0)u=s,b&&s>t||!b&&s<t?l=1:l=2;else{O=tn(s,Qt(a*i,this._mintick));let d=o,A=r;b?s>=t&&s<=o?(d=o,l=1):(b=!1,d=n,l=2):s<t&&s>=r?(A=r,l=1):(b=!0,A=n,l=2);const[h,q,_=1]=this._calcTrailStopPrice(O,d,A,n,a,i,b);delete e.active_price,l<_&&(l=_),e.trail_stop_price=h,u=q}return[u,l]}_ordersHandle(e){const t=this._orders.filter(b=>b.isMarketPriceLimit||b.isMarketPriceStop);if(!t.length)return;const{open:r,close:o}=this.calcOnOrderFillsData.data||this._variables,n=e?o:r;for(const b of t){const{out_comment:z,out_qty:i,out_id:s}=b;this._processExitOnClose(b,n,{id:s,comment:z,qty:i})}}_calcTrailStopPrice(e,t,r,o,n,b,z){let i=e,s;const a=tn(b===1?t:r,Qt(n*b,this._mintick));let O=1;return b===1?z?(i<a&&(i=a),i>=r&&(O=2,s=i)):i>=r?(O=1,s=i):a>i&&(i=a,a>=o&&(O=3,s=a)):z?i<=t?(O=1,s=i):a<i&&(i=a,a<=o&&(O=3,s=a)):(a<i&&(i=a),i<=t&&(O=2,s=i)),[i,s,O]}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(z=>z.place_order_type==="exit");let r=[];for(const z of this._pendingOrders){const{isCancel:i,place_order_type:s,isMarketPrice:a}=z;if(i)continue;let O;switch(s){case"entry":if(!a){r.push(z);continue}this._entryOrderHandle(z);break;case"order":if(!a){r.push(z);continue}this._orderOrderHandle(z);break;case"close":O=this._closeOrderHandle(z);break;case"close_all":const{open:u}=this.calcOnOrderFillsData.data||this._variables;this._closeAllOrders(z,u);break}O&&e.push(O)}const o=this._options.pyramiding||1,n=this._orders.filter(z=>z.direction===i1.long).length<o,b=this._orders.filter(z=>z.direction===i1.short).length<o;r=r.filter(z=>z.direction===i1.long&&n||z.direction===i1.short&&b);for(const z of this._pendingOrderSort(r)){const{place_order_type:i}=z;let s;switch(i){case"entry":s=this._entryOrderHandle(z);break;case"order":s=this._orderOrderHandle(z);break}s&&e.push(s)}for(const z of t){const i=this._exitOrderHandle(z);i&&e.push(i)}this._pendingOrders=e}_pendingOrderSort(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,n=Math.abs(o-t)<=Math.abs(r-t);return e.sort(({in_price:b},{in_price:z})=>{let i=0,s=0;return n?(b>=t&&b<=o?i=1:i=2,z>=t&&z<=o?s=1:s=2):(b<=t&&b>=r?i=1:i=2,z<=t&&z>=r?s=1:s=2),i!==s?i-s:n?i===1?b-z:z-b:i===1?z-b:b-z}),e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const{close:e}=this.calcOnOrderFillsData.data||this._variables,t=[];for(const r of this._pendingCloseOrders)switch(r.place_order_type){case"close":const o=this._closeOrderHandle(r,!0);o&&t.push(o);break;case"close_all":this._closeAllOrders(r,e);break;case"entry":this._entryOnCloseHandle(r);break;case"order":this._orderOnCloseHandle(r);break}this._pendingCloseOrders=t,this._ordersHandle(!0)}_entryOrderHandle(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,{isMarketPrice:n,qty:b=0,in_price:z,direction:i,active_price:s}=e;if(s&&o>=s&&r<=s)return delete e.active_price,e;let a=z;if(n)a=t;else{let{stop:O,limit:u}=e;const l=i===i1.long?1:-1,d=O&&(O-t)*l>=0,{backtest_fill_limits_assumption:A=0}=this._options;A>0&&u&&(u-=A*this._mintick*l);const h=u&&(u-t)*l<=0;d&&h||(O&&!d||u&&!h)&&(a=t)}if(a<=o&&a>=r){const O=this._orders.filter(u=>u.direction!==i);this._entryOrder(O,a,b,e)}else return e}_orderOrderHandle(e){const{time:t,bar_index:r}=this._variables,{open:o,low:n,high:b}=this.calcOnOrderFillsData.data||this._variables,{slippage:z=0}=this._options,{isMarketPrice:i,qty:s=0,in_price:a,direction:O,comment:u,oca_name:l,oca_type:d,active_price:A,id:h}=e;if(A&&b>=A&&n<=A)return delete e.active_price,e;let q=a,_=s;if(i&&(q=o),q<=b&&q>=n){const m=this._orders.filter(g=>g.direction!==O);if(m.length&&(_=this._processOrders(m,q,s,h,u,!1,"order"),_<=0))return;const L=O===i1.long?1:-1;this._ocaGroupVerify(_,l,d),this._calcCurrentOrder({...e,in_price:q-L*z*this._mintick,in_index:r,in_time:t,in_high:b,in_low:n,qty:_});return}else return e}_getCloseOrders(e){const{close_entries_rule:t="FIFO"}=this._options;let r=[];return t==="FIFO"?r=this._orders.filter(o=>o.id===e):r=this._orders.filter(o=>o.id===e&&!o.close_qty),r}_closeOrderHandle(e,t){const{id:r,qty:o,qty_percent:n=100,comment:b,immediately:z}=e,{close_entries_rule:i="FIFO"}=this._options,s=this._getCloseOrders(r);if(!s.length)return;let a=0;if(o?a=o:(a=s.reduce((l,d)=>l+(d.qty||0),a),a=n/100*a),a<=0)return;const{open:O,close:u}=this.calcOnOrderFillsData.data||this._variables;if(i==="FIFO")this._processOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,!1,"close",z);else if(this._processCloseOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,z))return e}_processCloseOrders(e,t,r,o,n,b){let z=!1;for(const i of e)i.close_qty=r,(i.qty||0)>r&&(z=!0),i.immediately=b,i.position_close_type="close",i.isTiggerClose=!0,this._processOrder(i,t,r,o,n);return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_exitOrderHandle(e){const{from_entry:t,id:r}=e,o=this._orders.filter(n=>{var b;return(!t||t===n.id)&&!((b=n.exitIds)!=null&&b.includes(r))});if(!(o.length&&!this._ordersToExit(o,e,!0)))return e}_exit(e,t){if(!e.hasOwnProperty("profit")&&!e.hasOwnProperty("loss")&&!e.hasOwnProperty("stop")&&!e.hasOwnProperty("limit")&&(!e.hasOwnProperty("trail_offset")||!e.hasOwnProperty("trail_price")&&!e.hasOwnProperty("trail_points"))){this._errorListener.addError(l1.strategyExitErr,t,$0.Error);return}const{profit:r,loss:o,stop:n,limit:b,trail_offset:z,trail_price:i,trail_points:s,from_entry:a="",id:O}=e;if(this._isNaN(r)&&this._isNaN(o)&&this._isNaN(n)&&this._isNaN(b)&&(this._isNaN(z)||this._isNaN(s)&&this._isNaN(i)))return;const u={...e,place_order_type:"exit"},l=this._orders.filter(q=>{var _;return(!a||a===q.id)&&!((_=q.exitIds)!=null&&_.includes(O))}),d=this._updateExitOrders(u),A=this._pendingOrders.filter(q=>(!a||a===q.id)&&["order","entry"].includes(q.place_order_type||""));if(l.length){if(!this._ordersToExit(l,u,!1))return}else if(!A.length||d)return;const h=this._pendingOrders.find(q=>q.id===O&&q.place_order_type==="exit");h?Object.assign(h,{...e}):this._pendingOrders.push(u)}_updateExitOrders(e){let t=!1;e.qty&&(e.qty=this._calcExitQty(e.qty));const r=this._exitOrders.filter(o=>o.id===e.id&&(o.from_entry===e.from_entry||!e.from_entry));for(const o of r){const{directionNum:n,order:b,qty:z}=o;if(b.isTiggerClose){o.isClose=!0;continue}t=!0;const i={qty:z,...e},s=!0;if(this._stopProfit(b,n,i,s)){o.isClose=!0;continue}if(this._stopLoss(b,n,i,s)){o.isClose=!0;continue}if(this._trailStopLoss(b,n,i,s)){o.isClose=!0;continue}Object.assign(o,i)}return this._exitOrders=this._exitOrders.filter(o=>!o.isClose),t}_ordersToExit(e,t,r){var q;const{qty:o,qty_percent:n=100,id:b,comment:z}=t;let i=o,s=!1;t.comment=z||b;const a=e[0],O={...t},{qty:u=0}=a,l=a.direction===i1.long?1:-1;return i=o?o>=u?u:o:n/100*u,O.qty=this._calcExitQty(i),i<u&&(s=!0),this._stopProfit(a,l,O,r)||this._stopLoss(a,l,O,r)||this._trailStopLoss(a,l,O,r)||(this._exitOrders.push({...O,directionNum:l,order:a}),a.exitIds?(q=a.exitIds)==null||q.push(b):a.exitIds=[b]),s}_addExitPendingCloseOrders(e){const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r,o){var A,h;const{limit:n,profit:b,comment_profit:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=I3(u,Qt(b*t,this._mintick))),r.limit=t===1?ac(O,this._variables.precision):uc(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t<=0)return e.isMarketPriceLimit=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r,o){var A,h;const{stop:n,loss:b,comment_loss:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=tn(u,Qt(b*t,this._mintick))),r.stop=t===1?uc(O,this._variables.precision):ac(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t>=0)return e.isMarketPriceStop=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r,o){var u,l;const{trail_offset:n,trail_price:b,trail_points:z,comment_trailing:i,comment:s,id:a,qty:O}=r;if(!this._isNaN(n)){const{in_price:d}=e,{process_orders_on_close:A}=this._options;let h;if(this._isNaN(b)?this._isNaN(z)||(h=I3(d,Qt(z*t,this._mintick))):h=b,r.active_price=h,o)return;let{close:q}=this.calcOnOrderFillsData.data||this._variables;if((l=(u=this.calcOnOrderFillsData)==null?void 0:u.tradeData)!=null&&l.open&&(q=this.calcOnOrderFillsData.tradeData.open),h!==void 0&&(h-q)*t<=0){const _=tn(q,Qt(n*t,this._mintick));if((_-q)*t>=0)return e.isMarketPriceStop=!0,r.comment=i||s,Object.assign(e,{out_comment:r.comment,out_id:a,out_qty:O}),A&&this._addExitPendingCloseOrders(r),!0;r.trail_stop_price=_}}}_processExitOnClose(e,t,r){const{qty:o=0,comment:n,id:b}=r,{close_entries_rule:z="FIFO"}=this._options;if(o)if(e.isTiggerClose=!0,z==="FIFO")this._processExitOrders(this._orders,t,o,b,n);else{if(e.isDeal)return;this._processOrders([e],t,o,b,n,!1,"exit")}}_processExitOrders(e,t,r,o,n){let b=r,z;for(const i of e)if(z=i,i.position_close_type="exit",b=this._processOrder(i,t,b,o,n),b<=0)break;return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_processOrder(e,t,r,o,n,b=!1){const{time:z,bar_index:i}=this._variables,{low:s,high:a}=this.calcOnOrderFillsData.data||this._variables,{slippage:O=0}=this._options,{in_price:u,qty:l=0,max_profit:d,trading_loss:A,direction:h,commission:q=0,original_qty:_=0}=e,m=h===i1.long?1:-1;if(t=t-m*O*this._mintick,r<l){const L=l-r,g=(t-u)*m*r,v=d!==void 0?d/l*r:void 0,y=A!==void 0?A/l*r:void 0,X=q*L/_;this._calcPercent({...e,out_price:t,last_commission:X,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,profit:g,out_qty:r,max_profit:v,trading_loss:y});const T=(t-u)*m*L-X;Object.assign(e,{qty:L,profit:T,max_profit:d!==void 0?d-(v||0):void 0,trading_loss:A!==void 0?A-(y||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{e.isDeal=!0;const L=(t-u)*m*l;this._calcPercent({...e,out_price:t,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,out_qty:l,profit:L}),r-=l}return b&&(m===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(e,t){const{commission_value:r,process_orders_on_close:o}=this._options,{in_price:n,out_qty:b=0,out_price:z=0,original_qty:i=0,direction:s,last_commission:a=0,immediately:O}=e;let{profit:u=0,max_profit:l,trading_loss:d,commission:A=0}=e,h=n*b,q=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=u,r){const g=this._getCommission(z,b);this._totalChangeCapital-=g;let v=A*b/i;h+=v,v+=g,u=u-v,Object.assign(e,{commission:v});const y=this._orders.reduce((X,T)=>{const{qty:N=0,original_qty:D=0,commission:C=0}=T;return X+C*N/D},0);q+=y-a}const _=s===i1.long?1:-1;let[m,L]=this._calcProfitAndLossHandle(n,b,_,z);if(r){const g=A*b/i;m-=g,L-=g}l=Math.max(m,l||0),d=Math.min(L,d||0),u=parseFloat(String(u)),Object.assign(e,{max_profit:l,profit:u,trading_loss:d,total_profit:this._totalChangeCapital,total_profit_percent:u/q*100,profit_percent:u/h*100,max_profit_percent:l/h*100,trading_loss_percent:d/h*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(o?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(e),!t&&this._calcOrderFillsHandle(z,s,O)}_getCommission(e,t){const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:o=0,max_profit:n=0,trading_loss:b=0,direction:z,immediately:i}=e;let{profit:s=0}=e,a=r*o;const O=this._totalChangeCapital+this._options.initial_capital;if(t){const u=this._getCommission(r,o);this._totalChangeCapital-=u,s=s-u,a+=u,Object.assign(e,{commission:u,total_profit:this._totalChangeCapital})}s=parseFloat(String(s)),Object.assign(e,{original_qty:o,profit:s,total_profit_percent:s/O*100,profit_percent:s/a*100,max_profit_percent:n/a*100,trading_loss_percent:b/a*100,stop:void 0,limit:void 0}),this._risk.intradayOrders+=1,this._orders.push(e),this._variables.strategy.updateOrders(this._orders),t&&this._variables.strategy.updateHistoryOrders(this._historyOrder),this._calcOrderFillsHandle(r,z,i)}_calcOrderFillsHandle(e,t,r=!1){const{calc_on_order_fills:o,process_orders_on_close:n,slippage:b=0}=this._options;if(o){const{open:z,high:i,low:s,close:a}=this._variables,O=t===i1.long?1:-1,u=a-O*b*this._mintick;if((r||n)&&e===u)return;const l=z-O*b*this._mintick;let d={open:z,high:i,low:s,close:a},A={open:z,high:i,low:s,close:a},h=this.calcOnOrderFillsData.index;const q=Math.abs(i-z)<=Math.abs(s-z);switch(h){case-1:e===l?(h=0,A={open:z,high:z,low:z,close:z}):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 0:e===l?(h=1,q?(A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a})):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 1:h=2,q?(A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a});break;case 2:h=-1,d=void 0;break}this.calcOnOrderFillsData={tradeData:d,index:h,currentData:A}}}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_verfiyRequestFunc(e,t){B0(this._errorListener,`strategy.${t}`,this._variables.__requestName,e)}};class lp{constructor(e,t,r){E(this,"array");E(this,"color");E(this,"math");E(this,"str");E(this,"map");E(this,"matrix");E(this,"timeframe");E(this,"ta");E(this,"input");E(this,"_variables");E(this,"_cacheData");E(this,"_options");E(this,"_errorListener");E(this,"_plots");E(this,"_plotshapes");E(this,"_plotbars");E(this,"_plotchars");E(this,"_plotarrows");E(this,"_plotcandles");E(this,"_alerts");E(this,"_bgColors");E(this,"_hlines");E(this,"_fills");E(this,"chart");E(this,"line");E(this,"label");E(this,"polyline");E(this,"box");E(this,"table");E(this,"linefill");E(this,"log");E(this,"runtime");E(this,"strategy");E(this,"request");E(this,"syminfo");E(this,"_count",0);var n;const o=((n=e.toString().split(".")[1])==null?void 0:n.length)||5;this._variables=t,this._errorListener=new pm,this.array=new $4(this._errorListener),this.math=new U4(o),this.color=new A6,this.str=new f_(this._errorListener,o),this.map=new l_(this._errorListener),this.timeframe=new A_(t),this.matrix=new u_(this._errorListener),this.ta=new a6(t,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 u6(t,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 q_(t)},this.line=new P_(t,this._errorListener),this.label=new d_(t,this._errorListener),this.polyline=new I_(t,this._errorListener),this.box=new $_(t,this._errorListener),this.table=new U_(t,this._errorListener),this.linefill=new k_(t),this.log=new nm(t,this.str),this.runtime=new bm(this._errorListener),this.strategy=new rm(this._variables,this._options,e,this._errorListener,r),this.request=new Mm(this._variables,r,this,this._errorListener),this.syminfo=new om}get errors(){return this._errorListener.errors}get scriptType(){return this._options.scriptType}clearErrors(){this._errorListener.clear()}addErrors(e,t){this._errorListener.setErrors(e,t)}options(e,t){if(!t)return e.length?this._getDataOfBarindex(e):this._options;const r=this.input.getInputs(),o=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let b;if(n.length){b={};for(const _ of n)b[_]=[...this._bgColors[_].values()]}const z=this._hlines.size?[...this._hlines.values()]:void 0,i=this._fills.size?[...this._fills.values()]:void 0,s=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 a=this._plots.size>0?[...this._plots.values()]:void 0,O=this._plotbars.size>0?[...this._plotbars.values()]:void 0,u=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,l=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,d=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,A=this._plotchars.size>0?[...this._plotchars.values()]:void 0,h=this._getDraws(),q=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{inputs:r,plots:a,draws:h,alerts:o,colors:b,hlines:z,fills:i,logs:s,plotshapes:u,plotarrows:l,plotcandles:d,plotchars:A,plotbars:O,isUseBgColor:q})}_getDataOfBarindex(e){const t=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let o;if(r.length){o={};for(const q of r)o[q]=[...this._bgColors[q].values()].map(_=>{const m=[];for(const L of e){const g=_.data[L];g&&m.push(g)}return _.data=m,_})}const n=this._hlines.size?[...this._hlines.values()]:void 0,b=this._fills.size?this._getDataFromBarindex(e,[...this._fills.values()]):void 0,z=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 i=this._getDataFromBarindex(e,[...this._plots.values()]),s=this._plotbars.size>0?this._getDataFromBarindex(e,[...this._plotbars.values()]):void 0,a=this._plotarrows.size>0?this._getDataFromBarindex(e,[...this._plotarrows.values()]):void 0,O=this._plotcandles.size>0?this._getDataFromBarindex(e,[...this._plotcandles.values()]):void 0,u=this._plotchars.size>0?this._getDataFromBarindex(e,[...this._plotchars.values()]):void 0,l=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,d=this._getDrawDeletes(e),A=this._getDrawsFromBarindex(e),h=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{plots:i,plotarrows:a,plotcandles:O,plotchars:u,plotbars:s,draws:A,drawDeletes:d,alerts:t,colors:o,hlines:n,fills:b,logs:z,plotshapes:l,isUseBgColor:h})}_getDataFromBarindex(e,t){return t.map(r=>{const o=[];for(const n of e){const b=r.data[n];b&&o.push(b)}return r.data=o,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:o,polyline:n,label:b}=this._variables,z={};return e.size&&(z.lines=e.data),t.size&&(z.linefills=t.data),r.size&&(z.tables=r.data),o.size&&(z.boxes=o.data),n.size&&(z.polylines=n.data),b.size&&(z.labels=b.data),Object.keys(z).length?z:void 0}_getDrawsFromBarindex(e){const{line:t,linefill:r,table:o,box:n,polyline:b,label:z}=this._variables,i={};return t.size&&(i.lines=t.getValOfBarIndex(e)),r.size&&(i.linefills=r.getValOfBarIndex(e)),o.size&&(i.tables=o.getValOfBarIndex(e)),n.size&&(i.boxes=n.getValOfBarIndex(e)),b.size&&(i.polylines=b.getValOfBarIndex(e)),z.size&&(i.labels=z.getValOfBarIndex(e)),Object.keys(i).length?i:void 0}_getDrawDeletes(e){const{line:t,linefill:r,table:o,box:n,polyline:b,label:z}=this._variables,i={},s=t.getDeleteIds(e),a=r.getDeleteIds(e),O=o.getDeleteIds(e),u=n.getDeleteIds(e),l=b.getDeleteIds(e),d=z.getDeleteIds(e);return s.length&&(i.lines=s),a.length&&(i.linefills=a),O.length&&(i.tables=O),u.length&&(i.boxes=u),l.length&&(i.polylines=l),d.length&&(i.labels=d),i}updateOptions(e){var o;const{inputs:t,strategy:r}=e;this.input.update(t),r&&((o=this.strategy)==null||o.updateOptions(r))}update(e){const{barIndex:t}=e;this.strategy.update(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:o}=e;r.test(o)?(Bu.includes(o)||yu.includes(o))&&this._errorListener.addError(r2(l1.libraryTitleIsKeywordErr,{name:o}),t,$0.Error):this._errorListener.addError(l1.libraryTitleErr,t,$0.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r,max_bars_back:o=0}=e;this._variables.max_bars_back=o,this._paramVerfiy(r,t,"indicator",[O1.inherit,O1.percent,O1.price,O1.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,o,n="format"){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_lineWidthVerify(e,t){const{linewidth:r=1}=e;r<1&&(this._errorListener.addError(vu.lineWidthWarning,t,$0.Warning),e.linewidth=1)}plot(e,t){const r=["color"];S1(e,r);const{series:o,color:n,...b}=e,{bar_index:z,time:i}=this._variables,s=`plot_${t}`,a=this._plots.get(s),O=(a==null?void 0:a.data)||[],u=o!==void 0&&isNaN(o)?void 0:o;if(O[z]={value:[i,u],barIndex:z,itemStyle:{color:n}},this._seriesColorHandle(e,r,a),!a){this._count++,this._lineWidthVerify(b,t),this._paramVerfiy(e.format,t,"plot",[O1.percent,O1.price,O1.volume]);const l=n?[n]:void 0;this._plots.set(s,{editable:!0,...b,colors:l,data:O,id:s,zIndex:this._count})}return{type:"plot",offset:e.offset||0,key:s}}plotbar(e,t){const r=["color"];S1(e,r);const{open:o,close:n,low:b,high:z,color:i,...s}=e,{bar_index:a,time:O}=this._variables,u=`plotbar_${t}`,l=this._plotbars.get(u),d=(l==null?void 0:l.data)||[],A=n!==void 0&&isNaN(n)?void 0:n,h=o!==void 0&&isNaN(o)?void 0:o,q=b!==void 0&&isNaN(b)?void 0:b,_=z!==void 0&&isNaN(z)?void 0:z,m=[O,h,A,q,_];if(d[a]={value:m,barIndex:a,itemStyle:{color:i}},this._seriesColorHandle(e,r,l),!l){this._count++,this._paramVerfiy(e.format,t,"plotbar",[O1.percent,O1.price,O1.volume]);const L=i?[i]:void 0;this._plotbars.set(u,{editable:!0,...s,colors:L,data:d,id:u,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:o,format:n,location:b,style:z}=e;this._paramVerfiy(z,r,t,Object.values(X2),"style"),this._paramVerfiy(b,r,t,Object.values(ke),"location"),this._paramVerfiy(o,r,t,Object.values(L2),"size"),this._paramVerfiy(n,r,t,[O1.percent,O1.price,O1.volume],"format")}plotchar(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,high:O,low:u}=this._variables,l=`plotchar_${t}`,d=this._plotchars.get(l),A=(d==null?void 0:d.data)||[],h={value:[a,o],barIndex:s,itemStyle:{color:n,textcolor:b},low:u,high:O};A[s]=h,this._seriesColorHandle(e,r,d),d||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(l,{editable:!0,...i,location:z,data:A,id:l,zIndex:this._count}))}plotarrow(e,t){const r=["colorup","colordown"];S1(e,r);const{series:o,colorup:n,colordown:b,...z}=e,{bar_index:i,time:s,low:a,high:O}=this._variables,u=`plotarrow_${t}`,l=this._plotarrows.get(u),d=(l==null?void 0:l.data)||[];d[i]={value:[s,o!==void 0&&isNaN(o)?void 0:o],barIndex:i,itemStyle:{colorup:n,colordown:b},low:a,high:O},this._seriesColorHandle(e,r,l),l||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[O1.percent,O1.price,O1.volume]),this._plotarrows.set(u,{editable:!0,...z,data:d,id:u,zIndex:this._count}))}plotshape(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,low:O,high:u}=this._variables,l=`plotshape_${t}`,d=this._plotshapes.get(l),A=(d==null?void 0:d.data)||[],h={value:o,barIndex:s,color:n,textcolor:b,time:a,low:O,high:u};if(A[s]=h,this._seriesColorHandle(e,r,d),!d){this._count++;const q=n?[n]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(l,{editable:!0,...i,data:A,location:z,id:l,colors:q,zIndex:this._count})}}plotcandle(e,t){const r=["wickcolor","bordercolor","color"];S1(e,r);const{wickcolor:o,bordercolor:n,color:b,close:z,open:i,low:s,high:a,...O}=e,{bar_index:u,time:l}=this._variables,d=`plotcandle_${t}`,A=this._plotcandles.get(d),h=(A==null?void 0:A.data)||[],q=z!==void 0&&isNaN(z)?void 0:z,_=i!==void 0&&isNaN(i)?void 0:i,m=s!==void 0&&isNaN(s)?void 0:s,L=a!==void 0&&isNaN(a)?void 0:a,g=[l,_,q,m,L];h[u]={value:g,barIndex:u,wickcolor:o,bordercolor:n,color:b},this._seriesColorHandle(e,r,A),A||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[O1.percent,O1.price,O1.volume]),this._plotcandles.set(d,{editable:!0,...O,data:h,id:d,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;S1(e,["color"]),this._verifyDisplay(e.display,"hline",t);const n=e.display&&!e.display.length?A2.none:A2.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(e,t),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:n,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var X,T,N,D,C,P,H,G;const r=["color","top_color","bottom_color"];S1(e,r);const{color:o,top_color:n,bottom_color:b,seriesColors:z,hline1:i,hline2:s,plot1:a,plot2:O,top_value:u,bottom_value:l,...d}=e,{bar_index:A,time:h}=this._variables,q=`fill_${t}`,_=this._fills.get(q),m=(_==null?void 0:_.data)||[];this._verifyDisplay(e.display,"fill",t);const L=e.display&&!e.display.length?A2.none:A2.all;let g,v,y="plot";if(i&&s)g=(X=this._hlines.get(i==null?void 0:i.key))==null?void 0:X.price,v=(T=this._hlines.get(s==null?void 0:s.key))==null?void 0:T.price,y="hline";else{const k=this._plots.get(a==null?void 0:a.key),J=this._plots.get(O==null?void 0:O.key),o0=(k==null?void 0:k.data)||[],z0=(J==null?void 0:J.data)||[];if(g=(D=(N=o0[A])==null?void 0:N.value)==null?void 0:D[1],v=(P=(C=z0[A])==null?void 0:C.value)==null?void 0:P[1],!A){const a0=(k==null?void 0:k.force_overlay)&&(J==null?void 0:J.force_overlay);(k!=null&&k.force_overlay||J!=null&&J.force_overlay)&&!a0?this._errorListener.addError(l1.plotFillForceOverlayErr,t,$0.Error):d.force_overlay=a0}}if(m[A]={time:h,color:o,top_color:n,bottom_color:b,barIndex:A,plot1:g,plot2:v,top_value:u,bottom_value:l},this._seriesColorHandle(e,r,_),!_){this._count++;const k=((H=this._options.indicator)==null?void 0:H.explicit_plot_zorder)||((G=this._options.strategy)==null?void 0:G.explicit_plot_zorder),J=o?[o]:void 0,o0=n?[n]:void 0,z0=b?[b]:void 0;this._fills.set(q,{id:q,colors:J,top_colors:o0,bottom_colors:z0,display:L,data:m,type:y,editable:!0,fillgaps:!1,hline1:i,hline2:s,plot1:a,plot2:O,...d,zIndex:k?this._count:void 0})}}alert({message:e,freq:t=Ae.freqOncePerBar},r){const{bar_index:o,_isRealTimeBar:n,last_bar_index:b}=this._variables,z=`alert_${r}`,i=this._cacheData[z]||{},s=i.barIndex;if(this._paramVerfiy(t,r,"alert",[Ae.freqAll,Ae.freqOncePerBar,Ae.freqOncePerBarClose]),t===Ae.freqOncePerBar&&o===s){this._alerts.delete(z);return}this._cacheData[z]=i;const a={message:e,freq:t,id:z,type:"alert"};if(n){t!==Ae.freqOncePerBarClose&&this._alerts.set(z,a),i.barIndex=o;return}if(!n&&t===Ae.freqOncePerBarClose&&o===s&&b===o-1){this._alerts.set(z,a),i.barIndex=o;return}this._alerts.delete(z)}alertcondition({condition:e,message:t,title:r},o){const{_isRealTimeBar:n}=this._variables,b=`alertcondition_${o}`;n&&e?this._alerts.set(b,{message:t,title:r,id:b,type:"alertcondition"}):this._alerts.delete(b)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=X3.all,t,r){e.length&&e.length<4&&this._errorListener.addError(r2(l1.displayErr,{func:t,values:"[display.none, display.all]"}),r,$0.Error)}_setColors(e,t,r){S1(e,["color"]);const{color:n,...b}=e;this._verifyDisplay(b.display,t,r);const z=e.display&&!e.display.length?A2.none:A2.all,{bar_index:i,time:s}=this._variables,a=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const O=this._bgColors[t].get(a),u=(O==null?void 0:O.data)||[],l=(O==null?void 0:O.setColors)||[];n&&!l.includes(n)&&l.push(n),u[i]={color:n,time:s,barIndex:i},O||this._bgColors[t].set(a,{...b,display:z,data:u,setColors:l,id:a})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return!!(e===void 0||typeof e=="number"&&isNaN(e))}fixnan({source:e},t){return e===void 0||typeof e=="number"&&isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!(typeof e=="number"&&isNaN(e))?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o)}time_close({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o,!0)}timestamp(e){const{dateString:t,timezone:r,year:o,month:n,day:b,hour:z=0,minute:i=0,second:s=0}=e;if(t)return D1(t).utc(!/GMT|UTC/.test(t)).valueOf();let a=n-1,O=o;if(a<0){const u=Math.ceil(Math.abs(a/12));a=12*u+a,O=o-u}return $2({year:O,month:a,day:b,hour:z,minute:i,second:s},r).valueOf()}weekofyear({time:e,timezone:t}){return $2(e,t).week()}year({time:e,timezone:t}){return $2(e,t).year()}second({time:e,timezone:t}){return $2(e,t).second()}month({time:e,timezone:t}){return $2(e,t).month()+1}minute({time:e,timezone:t}){return $2(e,t).minute()}hour({time:e,timezone:t}){return $2(e,t).hour()}dayofweek({time:e,timezone:t}){return $2(e,t).day()+1}dayofmonth({time:e,timezone:t}){return $2(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,this._variables.timeframe.period),o=N2(t,e)*1e3;return e-r-Math.floor((e-r)/o)*o}_timeHandle(e,t,r="",o,n,b=0,z=!1){const i=r||this._variables.__period,s=N2(i,e),a=N2(this._variables.__period,e);let O;if(s<=a)O=e,z&&(O+=a*1e3);else{const u=`time_${t}`,l=this._cacheData[u];if(l)l.currentTime+s*1e3-l.offset<=e?(O=e,this._cacheData[u]={currentTime:e,offset:0}):O=l.currentTime;else{const d=this._calcTimeOffset(e,i);this._cacheData[u]={currentTime:e,offset:d},O=e}z&&(O+=s*1e3)}if(o&&o!==ut.regular&&o!==ut.extended){const{timePeriods:u,weeks:l}=this._parserSession(o,t),d=$2(e,n),A=d.format("YYYY-MM-DD HH:mm"),h=d.format("YYYY-MM-DD"),q=O,_=$2(O,n).format("YYYY-MM-DD HH:mm");O=void 0;for(const L of u){const[g,v]=L;let y;if((g===v||Number(g==null?void 0:g.replace(":",""))>Number(v==null?void 0:v.replace(":","")))&&(y=d.add(1,"day").format("YYYY-MM-DD")),D1(A).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")){D1(_).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")?O=q:O=$2(`${h} ${g}`,n).valueOf();break}}const m=this._variables.dayofweek;O&&!l.includes(m)&&(O=void 0)}return O&&O-b*a*1e3}_seriesColorHandle(e,t,r){var o;if(r&&t!=null&&t.length)for(const n of t){if((o=r.gradientColorKeys)!=null&&o.includes(n))continue;const b=e[n];if(!b)continue;const z=r[`${n}s`]||[];z.includes(b)||(z.push(b),r[`${n}s`]=z,z.length>5&&(r[`${n}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(n)))}}_parserSession(e,t){const r=e.split(":"),o=r[0],b=(r[1]||"1234567").split("").map(i=>{const s=parseInt(i,10);if(s<1||s>7){this._errorListener.addError(`Invalid day of week: ${i}`,t,$0.Error);return}return s});return{timePeriods:o.split(",").map(i=>{i===""||i===ut.regular?i="0930-1500":i===ut.extended&&(i="1500-1830");const s=i.split("-");return s.length!==2?[]:[this._processTime(s[0],t),this._processTime(s[1],t)]}),weeks:b}}_processTime(e,t){const r=e.slice(0,2),o=e.slice(2),n=parseInt(r,10),b=parseInt(o,10);if(!(n>=0&&n<=23)&&b>=0&&b<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",t,$0.Error);return}return`${r}:${o}`}}let Mm=class{constructor(e,t,r,o){E(this,"_variables");E(this,"_scriptId");E(this,"_cacheData");E(this,"_funcs");E(this,"_errorListener");this._variables=e,this._scriptId=t,this._cacheData=new Map,this._funcs=r,this._errorListener=o}security(e,t){var d;const r=self.workerStorage.get(`request_${this._scriptId}`),{__requestName:o,__period:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||n;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${o}${t}_${s}`,O=this._getRequestData(e,a);if(r!=null&&r.has(a))return(d=O==null?void 0:O.result)==null?void 0:d[a];const u=this._parseExprCode(e),l=this._runScriptHandle(u,a,i,O,!0);return r==null||r.set(a,{id:a,isRun:!1,strJs:u,dataId:s,interval:z,symbol:b,paramsExpr:i}),l}security_lower_tf(e,t){const r=self.workerStorage.get(`request_${this._scriptId}`),{__period:o,__requestName:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||o;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${n}${t}_${s}`,O=r==null?void 0:r.get(a),u=this._getRequestLowerTfData(e,t,a,O==null?void 0:O.defaultResult),l=new n1(0,void 0,this._errorListener);if(O!=null&&O.strJs)return O!=null&&O.defaultResult?u!=null&&u.length?u.map(q=>{const _=new n1(0,void 0,this._errorListener);return _._value=q,_}):O==null?void 0:O.defaultResult:u&&(l._value=u,l);const d=this._parseExprCode(e),A={id:a,strJs:d,isRun:!1,dataId:s,interval:z,symbol:b,paramsExpr:i,defaultResult:void 0};r==null||r.set(a,A);const h=this._runScriptHandle(d,a,i,u,!0);return Array.isArray(h)?(A.defaultResult=h.map(()=>new n1(0,void 0,this._errorListener)),A.defaultResult):l}_symbolTransform(e){if(!e)return this._variables.syminfo.tickerid;let[t,r]=e.split(":");return r?t=Du[t]||t:(t="FX",r=t),`${t}:${r}`}_runScriptHandle(e,t,r,o,n){const{result:b,logs:z,errors:i}=this._runScripts(e,t,n,r,o);return this._funcs.log.mergeLogs(z),this._funcs.addErrors(i,t),b}_getCurrentData(e){let{symbol:t,timeframe:r}=e;const{__period:o,syminfo:{ticker:n,tickerid:b}}=this._variables;if(r=hr(r),(o===r||r==="")&&(t===n||t===b||!t)){const{close:z,open:i,high:s,low:a,bar_index:O,last_bar_index:u,last_bar_time:l,_isRealTimeBar:d,volume:A,time:h,time_tradingday:q,mintick:_,nextBarTime:m}=this._variables;return{barIndex:O,c:z,o:i,h:s,l:a,volume:A,lastBarIndex:u,lastBarTime:l/1e3,nextBarTime:m?m/1e3:void 0,isrealtime:d,time_tradingday:q,time:h/1e3,interval:o,mintick:_}}}_parseExprCode(e){let{expression:t,paramsExpr:r=[]}=e,o=[];t=cc(t);const n=JSON.parse(t),b=n.pop();let z=(b==null?void 0:b.memberCodes)||{},i=(b==null?void 0:b.depends)||[];if(!i.length)return`return ${b==null?void 0:b.code}`;let s=[],a=[],O=[];if(this._getDependCodes(i,n,o,s,a,O),this._getStmtFuncs(o,n,O,s,a),a.length){const h=r.length;for(let q=h-1;q>=0;q--){const _=r[q];let m=JSON.parse(cc(_));const L=[];m=m.map(y=>{const{scope:X,code:T,varNames:N,dependSelf:D}=y;return X===2&&!L.includes(N)&&!D&&(y.code=`let ${T}`),N&&L.push(...N.split(", ")),y.memberCodes&&Object.assign(z,{...y.memberCodes}),y});const g=[];let v=a.map(y=>({...y,isArg:!1,isPreArg:!0}));a=[],this._getDependCodes(v,m,o,s,a,g),this._getStmtFuncs(o,m,g,s,a)}}const u=o.filter(h=>!!h).map((h,q)=>{let _=h.join(`
|
76
|
+
`)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t==null?void 0:t.replace(/0/g,"#")))}_arrToStr(e,t){return`[${e.map(o=>typeof o=="number"?this._toStringFormat(o,t):o).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return d0(t)&&(t=0),d0(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return d0(e)&&(e=0),$2(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return Number(e==null?void 0:e.toFixed(10));switch(t){case O1.mintick:return e==null?void 0:e.toFixed(this._precision);case O1.percent:return`${Number(e.toFixed(2))}%`;case O1.volume:return this._intlNumberFormatter.format(Math.round(e));default:return this._formatOthers(e,t)}}_formatOthers(e,t){var z;let[r,o]=t.split(".");t.split("%").length===2&&(e=e*100);let[n,b=""]=String(e).split(".");if(r.includes("#")){if(r.includes(",")){const i=r.split(","),s=((z=i[i.length-1])==null?void 0:z.replace(/[^#]/g,"").length)||0;s&&(n=n.replace(new RegExp(`\\B(?=(\\d{${s}})+(?!\\d))`,"g"),",")),r=i.join("")}n=r.replace(/#/,n).replace(/#/g,"")}else n=`${r}${n}`;if(o&&o.includes("#")){const i=o.split("#").length-1,s=+`${n}.${b}`;if(!isNaN(s))return+`${s.toFixed(i)}${o.replace(/#/g,"")}`;b=`${b.substring(0,i)}${o.replace(/#/g,"")}`}else b=o||"";return b?+`${n}.${b}`:n}_formatNumber(e,t){if(!t)return Number(e==null?void 0:e.toFixed(this._precision));switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:return this._formatOthers(e,t)}}strformat({formatString:e=""},t,r){return this._strFormat(e,t,r)}_strFormat(e,t,r){return e.replace(/{[^{}]+}/g,o=>{if(!o)return o;const n=o.replace(/[{}]/g,"").split(","),b=Number(n[0]);if(isNaN(b)||t.length<=b)return o;const z=t[b];if(n.length===1)return typeof z=="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):z===void 0?"":z;if(n.length===2){const i=n[1].trim();return i==="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):i==="date"?D1(z).format("LL"):o}else{const i=n[1].trim(),s=n[2].trim();if(i==="number")return this._formatNumber(z,s);if(i==="date"){let a="YYYY-MM-DD";switch(s){case"long":a="LL";break;case"short":a="L";break;default:s&&(a=s)}return D1(z).format(a)}return o}})}}class l_{constructor(e){E(this,"_errorListener");this._errorListener=e}new(){return new Ap(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class Ap{constructor(e){E(this,"_errorListener");E(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}get _value(){return this._mapInstance}_copyMap(e){const t=new Ap(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class q_{constructor(e){E(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new Er(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new Er(e,r,t)}copy({id:e}){return e==null?void 0:e.copy()}from_index({price:e,index:t}){return new Er(e,t)}from_time({price:e,time:t}){return new Er(e,void 0,t)}}class Er{constructor(e,t,r){E(this,"_index");E(this,"_price");E(this,"_time");this._index=t&&Math.round(t),this._price=e,this._time=r}get index(){return this._index}set index(e){this._index=e&&Math.round(e)}get price(){return this._price}set price(e){this._price=e}get time(){return this._time}set time(e){this._time=e}copy(){return new Er(this._price,this._index,this._time)}}class d_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLabel",{text:"",xloc:P1.bar_index,yloc:le.price,size:L2.normal,style:T1.styleLabelDown,textalign:t1.alignCenter});this._variables=e,this._errorListener=t}new(e,t){B0(this._errorListener,"label.new",this._variables.__requestName,t);const{time:r,high:o,low:n,bar_index:b}=this._variables,z=`label_${t}_${b}`;S1(e,["color","textcolor"]);const i={...this._defaultLabel,...e,id:z,time:r,high:o,low:n,bar_index:b};e.x&&(i.x=e.x&&Math.round(e.x)),e.point&&(i.x=i.xloc===P1.bar_index?e.point.index:e.point.time,i.y=e.point.price),i.yloc===le.abovebar?i.y=o:i.yloc===le.belowbar&&(i.y=n),this._verfiyArgs(e,t);const s=new Ko(z,this._variables,this._errorListener,i);return t.startsWith("export")||this._variables.label.add(z,i,s),s}_verfiyArgs(e,t){const{xloc:r,yloc:o,style:n,size:b,textalign:z,text_font_family:i}=e,s="label.new";this._paramVerfiy(n,t,s,Object.values(T1),"style"),this._paramVerfiy(r,t,s,Object.values(P1),"xloc"),this._paramVerfiy(o,t,s,Object.values(le),"yloc"),this._paramVerfiy(b,t,s,Object.values(L2),"size"),this._paramVerfiy(z,t,s,[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign"),this._paramVerfiy(i,t,s,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}label(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e},t){e==null||e.delete(t)}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Ko{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get type(){return Q0.LABEL}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.label.get(this._id)||this._data}copy(e){B0(this._errorListener,"label.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`label_${e}_${t}`,o=this._getLabel(e),n={...o||{},id:r,bar_index:t},b=new Ko(r,this._variables,this._errorListener,n);return o&&this._variables.label.add(r,n,b),b}get_x(e){var t;return B0(this._errorListener,"label.get_x",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return B0(this._errorListener,"label.get_y",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){B0(this._errorListener,"label.set_x",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=e&&Math.round(e))}set_y({y:e},t){B0(this._errorListener,"label.set_y",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.y=e)}delete(e){B0(this._errorListener,"label.delete",this._variables.__requestName,e),this._variables.label.delete(this._id,this._variables.bar_index,this._data.id)}set_xy({x:e,y:t},r){B0(this._errorListener,"label.set_xy",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.y=t)}get_text(e){var t;return B0(this._errorListener,"label.get_text",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){B0(this._errorListener,"label.set_size",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(L2),"size")}set_text({text:e},t){B0(this._errorListener,"label.set_text",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){B0(this._errorListener,"label.set_xloc",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(P1),"xloc"))}set_yloc({yloc:e},t){B0(this._errorListener,"label.set_yloc",this._variables.__requestName,t);const r=this._getLabel(t),{high:o,low:n}=this._variables;r&&(r.yloc=e,e===le.abovebar?r.y=o:e===le.belowbar&&(r.y=n),this._paramVerfiy(e,t,"label.set_yloc",Object.values(le),"yloc"))}set_color(e,t){B0(this._errorListener,"label.set_color",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["color"]),r&&(r.color=e.color)}set_point({point:e},t){B0(this._errorListener,"label.set_point",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=r.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){B0(this._errorListener,"label.set_style",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(T1),"style")}set_tooltip({tooltip:e},t){B0(this._errorListener,"label.set_tooltip",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){B0(this._errorListener,"label.set_textalign",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign")}set_textcolor(e,t){B0(this._errorListener,"label.set_textcolor",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["textcolor"]),r&&(r.textcolor=e.textcolor)}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"label.set_text_font_family",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLabel(e){const t=this._variables.label.get(this._id)||this._data;return t||console.log(`错误${e}: label 不存在`),t}}const h_={freq_all:Ae.freqAll,freq_once_per_bar:Ae.freqOncePerBar,freq_once_per_bar_close:Ae.freqOncePerBarClose},W_={gaps_off:Pe.gapsOff,gaps_on:Pe.gapsOn,lookahead_off:Pe.lookaheadOff,lookahead_on:Pe.lookaheadOn},Tr={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"},D3={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"},__={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},X3={all:[A2.dataWindow,A2.pane,A2.priceScale,A2.statusLine],data_window:[A2.dataWindow],none:[],pane:[A2.pane],price_scale:[A2.priceScale],status_line:[A2.statusLine]},m_={both:fe.both,left:fe.left,none:fe.none,right:fe.right},g_={inherit:O1.inherit,mintick:O1.mintick,percent:O1.percent,price:O1.price,volume:O1.volume},R_={style_solid:kM.styleSolid,style_dashed:kM.styleDashed,style_dotted:kM.styleDotted},L_={style_arrowdown:T1.styleArrowdown,style_arrowup:T1.styleArrowup,style_circle:T1.styleCircle,style_cross:T1.styleCross,style_diamond:T1.styleDiamond,style_flag:T1.styleFlag,style_label_center:T1.styleLabelCenter,style_label_down:T1.styleLabelDown,style_label_left:T1.styleLabelLeft,style_label_lower_left:T1.styleLabelLowerLeft,style_label_lower_right:T1.styleLabelLowerRight,style_label_right:T1.styleLabelRight,style_label_up:T1.styleLabelUp,style_label_upper_left:T1.styleLabelUpperLeft,style_label_upper_right:T1.styleLabelUpperRight,style_none:T1.styleNone,style_square:T1.styleSquare,style_text_outline:T1.styleTextOutline,style_triangledown:T1.styleTriangledown,style_triangleup:T1.styleTriangleup,style_xcross:T1.styleXcross},v_={style_arrow_both:n2.styleArrowBoth,style_arrow_left:n2.styleArrowLeft,style_arrow_right:n2.styleArrowRight,style_dashed:n2.styleDashed,style_dotted:n2.styleDotted,style_solid:n2.styleSolid},N_={abovebar:ke.abovebar,absolute:ke.absolute,belowbar:ke.belowbar,bottom:ke.bottom,top:ke.top},y_={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},B_={style_area:ee.styleArea,style_areabr:ee.styleAreabr,style_circles:ee.styleCircles,style_columns:ee.styleColumns,style_cross:ee.styleCross,style_histogram:ee.styleHistogram,style_line:ee.styleLine,style_linebr:ee.styleLinebr,style_stepline:ee.styleStepline,style_stepline_diamond:ee.styleSteplineDiamond,style_steplinebr:ee.styleSteplinebr},w_={bottom_center:P2.bottomCenter,bottom_left:P2.bottomLeft,bottom_right:P2.bottomRight,middle_center:P2.middleCenter,middle_left:P2.middleLeft,middle_right:P2.middleRight,top_center:P2.topCenter,top_left:P2.topLeft,top_right:P2.topRight},D_={left:$M.left,none:$M.none,right:$M.right},X_={arrowdown:X2.arrowdown,arrowup:X2.arrowup,circle:X2.circle,cross:X2.cross,diamond:X2.diamond,flag:X2.flag,labeldown:X2.labeldown,labelup:X2.labelup,square:X2.square,triangledown:X2.triangledown,triangleup:X2.triangleup,xcross:X2.xcross},E_={auto:L2.auto,huge:L2.huge,large:L2.large,normal:L2.normal,small:L2.small,tiny:L2.tiny},T_={cash:b2.cash,fixed:b2.fixed,percent_of_equity:b2.percentOfEquity,commission:{cash_per_contract:O2.cashPerContract,cash_per_order:O2.cashPerOrder,percent:O2.percent},direction:{all:i1.all,long:i1.long,short:i1.short},oca:{cancel:Ue.cancel,none:Ue.none,reduce:Ue.reduce}},C_={align_bottom:t1.alignBottom,align_center:t1.alignCenter,align_left:t1.alignLeft,align_right:t1.alignRight,align_top:t1.alignTop,wrap_auto:t1.wrapAuto,wrap_none:t1.wrapNone},x_={bar_index:P1.bar_index,bar_time:P1.bar_time},S_={abovebar:le.abovebar,belowbar:le.belowbar,price:le.price},F_={actual:UM.actual,estimate:UM.estimate,standardized:UM.standardized};class fp{constructor(){E(this,"adjustment",{dividends:PM.dividends,none:PM.none,splits:PM.splits});E(this,"alert",h_);E(this,"barmerge",W_);E(this,"color",Tr);E(this,"currency",D3);E(this,"dayofweek",__);E(this,"earnings",F_);E(this,"display",X3);E(this,"extend",m_);E(this,"font",{family_default:St.familyDefault,family_monospace:St.familyMonospace});E(this,"format",g_);E(this,"hline",R_);E(this,"label",L_);E(this,"line",v_);E(this,"location",N_);E(this,"math",y_);E(this,"order",{ascending:$e.ascending,descending:$e.descending});E(this,"plot",B_);E(this,"position",w_);E(this,"scale",D_);E(this,"session",{extended:ut.extended,regular:ut.regular});E(this,"shape",X_);E(this,"size",E_);E(this,"splits",{denominator:"denominator",numerator:"numerator"});E(this,"strategy",T_);E(this,"text",C_);E(this,"xloc",x_);E(this,"yloc",S_)}updateData(){}}class I_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:P1.bar_index,line_color:Tr.blue,line_style:n2.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var z;B0(this._errorListener,"polyline.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`polyline_${t}_${r}`,n=Object.assign({},this._defaultPolyline,e,{id:o,bar_index:r,points:(z=e.points)==null?void 0:z._value.map(i=>({time:i.time,index:i.index,price:i.price}))});S1(n,["line_color","fill_color"]);const b=new E3(o,this._variables,n);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(o,n,b),b}_verfiyArgs(e,t){const{line_style:r,xloc:o}=e,n="polyline.new";this._paramVerfiy(r,t,n,Object.values(n2),"line_style"),this._paramVerfiy(o,t,n,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}delete({id:e}){e&&e.delete()}}class E3{constructor(e,t,r){E(this,"_id");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=t,this._id=e,this._data=r}get type(){return Q0.POLYLINE}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.polyline.get(this._id)||this._data}delete(){this._variables.polyline.delete(this._id,this._variables.bar_index,this._data.id)}}class P_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLine",{xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},o){B0(this._errorListener,"line.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`line_${o}_${n}`;S1(r,["color"]);const z={...this._defaultLine,...r,id:b,bar_index:n},{x1:i,x2:s}=z;if(i&&(z.x1=i&&Math.round(i)),s&&(z.x2=s&&Math.round(s)),e&&t){const O=z.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,u=z.xloc===P1.bar_index?t==null?void 0:t.index:t==null?void 0:t.time;Object.assign(z,{x1:O,y1:e==null?void 0:e.price,x2:u,y2:t==null?void 0:t.price})}this._verfiyArgs(r,o);const a=new Jo(b,this._variables,this._errorListener,z);return o.startsWith("export")||this._variables.line.add(b,z,a),a}_verfiyArgs(e,t){const{extend:r,xloc:o,style:n}=e,b="line.new";this._paramVerfiy(n,t,b,Object.values(n2),"style"),this._paramVerfiy(r,t,b,Object.values(fe),"extend"),this._paramVerfiy(o,t,b,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}line(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class Jo{constructor(e,t,r,o){E(this,"_variables");E(this,"_id");E(this,"_suffix","");E(this,"_errorListener");E(this,"_fillKeys",[]);E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get id(){return this._id}get __fillKeys(){return this._fillKeys}__setFillKeys(e){this._fillKeys.includes(e)||this._fillKeys.push(e)}__updateFillKeys(e,t){const r=this._fillKeys.findIndex(o=>o===e);r!==-1?this._fillKeys.splice(r,1,t):this._fillKeys.push(t)}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get type(){return Q0.LINE}set data(e){this._data=e}get data(){return this._variables.line.get(this._id)||this._data}get originData(){return this._data}copy(e){const{bar_index:t}=this._variables,r=`line_${e}_${t}`,o=this._getLine(e,"copy"),n={...o,id:r,bar_index:t,isVar:void 0},b=new Jo(r,this._variables,this._errorListener,n);return o&&this._variables.line.add(r,n,b),b}delete(e){B0(this._errorListener,"line.delete",this._variables.__requestName,e);for(const t of this._fillKeys)this._variables.linefill.delete(t,this._variables.bar_index);this._variables.line.delete(this._id,this._variables.bar_index,this._data.id)}get_price({x:e},t){const r=this._getLine(t,"get_price");if(e===void 0)return e;if(r&&r.xloc===P1.bar_index){const{x1:o,y1:n,x2:b,y2:z}=r;return o===void 0||b===void 0||n===void 0||z===void 0?void 0:(z-n)/(b-o)*(e-o)+n}}get_x1(e){var t;return(t=this._getLine(e,"get_x1"))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e,"get_x2"))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e,"get_y1"))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e,"get_y2"))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t,"set_x1");r&&(r.x1=e&&Math.round(e))}set_x2({x:e},t){const r=this._getLine(t,"set_x2");r&&(r.x2=e&&Math.round(e))}set_y1({y:e},t){const r=this._getLine(t,"set_y1");r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t,"set_y2");r&&(r.y2=e)}set_xy1({x:e,y:t},r){const o=this._getLine(r,"set_xy1");o&&(o.x1=e&&Math.round(e),o.y1=t)}set_xy2({x:e,y:t},r){const o=this._getLine(r,"set_xy2");o&&(o.x2=e&&Math.round(e),o.y2=t)}set_xloc({xloc:e,x1:t,x2:r},o){const n=this._getLine(o,"set_xloc");n&&(n.xloc=e,n.x1=t&&Math.round(t),n.x2=r&&Math.round(r),this._paramVerfiy(e,o,"line.set_xloc",Object.values(P1),"xloc"))}set_color(e,t){const r=this._getLine(t,"set_color");r&&(S1(e,["color"]),r.color=e.color)}set_style({style:e},t){const r=this._getLine(t,"set_style");r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(n2),"style"))}set_width({width:e},t){const r=this._getLine(t,"set_width");r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t,"set_extend");r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(fe),"extend"))}set_first_point({point:e},t){const r=this._getLine(t,"set_first_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x1=z),i&&(r.y1=i)}}set_second_point({point:e},t){const r=this._getLine(t,"set_second_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x2=z),i&&(r.y2=i)}}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLine(e,t){B0(this._errorListener,`line.${t}`,this._variables.__requestName,e);const r=this._variables.line.get(this._id)||this._data;return r||console.log(`${e}: line 不存在`),r}}class k_{constructor(e){E(this,"_variables");this._variables=e}new(e,t){const{line1:r,line2:o}=e,{bar_index:n}=this._variables,b=`linefill_${t}_${n}`,z=r==null?void 0:r.data,i=o==null?void 0:o.data;z&&(z.linefills=z.linefills||[],z.linefills.push(b)),i&&(i.linefills=i.linefills||[],i.linefills.push(b)),S1(e,["color"]),r==null||r.__setFillKeys(b),o==null||o.__setFillKeys(b);const s={line1:z,line2:i,color:e.color,id:b,bar_index:n},a=new T3(this._variables,b,s,r,o);return t.startsWith("export")||(z||i)&&this._variables.linefill.add(b,s,a),a}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class T3{constructor(e,t,r,o,n){E(this,"_id");E(this,"_line1");E(this,"_line2");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._line1=o,this._line2=n,this._data=r}get type(){return Q0.LINEFILL}get id(){return this._id}get preId(){return this._preId}updateId(){var o,n;const{bar_index:e,_isRealTimeBar:t}=this._variables,r=this._id;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const b=this._id.split("_");b.pop(),this._id=`${b.join("_")}_${e}`}return(o=this._line1)==null||o.__updateFillKeys(r,this._id),(n=this._line2)==null||n.__updateFillKeys(r,this._id),t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.linefill.get(this._id)||this._data}linefill(e){return e.x}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:o,line2:n}=e;o&&(o.linefills=(t=o.linefills)==null?void 0:t.filter(b=>b!==this._id)),n&&(n.linefills=(r=n.linefills)==null?void 0:r.filter(b=>b!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id,this._variables.bar_index,this._data.id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(e){const t=this._variables.linefill.get(this._id);t&&(S1(e,["color"]),t.color=e.color)}}class $_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultBox",{border_color:Tr.blue,border_width:1,bgcolor:Tr.blue,xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid,text:"",text_size:L2.auto,text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_wrap:t1.wrapNone});this._variables=e,this._errorListener=t}box({x:e}){return e}new({top_left:e,bottom_right:t,...r},o){B0(this._errorListener,"box.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`box_${o}_${n}`,z={...this._defaultBox,...r,id:b,bar_index:n};S1(z,["border_color","bgcolor","text_color"]);const{left:i,right:s}=z;if(i&&(z.left=i&&Math.round(i)),s&&(z.right=s&&Math.round(s)),e){const{price:O,time:u,index:l}=e;z.top=O,z.left=z.xloc===P1.bar_index?l:u}if(t){const{price:O,time:u,index:l}=t;z.bottom=O,z.right=z.xloc===P1.bar_index?l:u}this._verfiyArgs(r,o);const a=new Qo(this._variables,b,this._errorListener,z);return o.startsWith("export")||this._variables.box.add(b,z,a),a}_verfiyArgs(e,t){const{border_style:r,extend:o,xloc:n,text_size:b,text_halign:z,text_valign:i,text_wrap:s,text_font_family:a}=e,O="box.new";this._paramVerfiy(r,t,O,[n2.styleDashed,n2.styleDotted,n2.styleSolid],"border_style"),this._paramVerfiy(o,t,O,Object.values(fe),"extend"),this._paramVerfiy(n,t,O,Object.values(P1),"xloc"),this._paramVerfiy(b,t,O,Object.values(L2),"text_size"),this._paramVerfiy(z,t,O,[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"),this._paramVerfiy(i,t,O,[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"),this._paramVerfiy(s,t,O,[t1.wrapAuto,t1.wrapNone],"text_wrap"),this._paramVerfiy(a,t,O,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_top({id:e},t){return e==null?void 0:e.get_top(t)}get_bottom({id:e},t){return e==null?void 0:e.get_bottom(t)}get_left({id:e},t){return e==null?void 0:e.get_left(t)}get_right({id:e},t){return e==null?void 0:e.get_right(t)}set_top({id:e,...t},r){e==null||e.set_top(t,r)}set_bottom({id:e,...t},r){e==null||e.set_bottom(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_left({id:e,...t},r){e==null||e.set_left(t,r)}set_right({id:e,...t},r){e==null||e.set_right(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({id:e,...t},r){e==null||e.set_border_width(t,r)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t},r){e==null||e.set_lefttop(t,r)}set_rightbottom({id:e,...t},r){e==null||e.set_rightbottom(t,r)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t},r){e==null||e.set_text_color(t,r)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t},r){e==null||e.set_top_left_point(t,r)}set_bottom_right_point({id:e,...t},r){e==null||e.set_bottom_right_point(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Qo{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.BOX}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.box.get(this._id)||this._data}copy(e){B0(this._errorListener,"box.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`box_${e}_${t}`,o=this._getBox(),n={...o,id:r,bar_index:t},b=new Qo(this._variables,r,this._errorListener,n);return o&&this._variables.box.add(r,n,b),b}delete(e){B0(this._errorListener,"box.delete",this._variables.__requestName,e),this._variables.box.delete(this._id,this._variables.bar_index,this._data.id)}get_top(e){B0(this._errorListener,"box.get_top",this._variables.__requestName,e);const t=this._getBox();return t&&t.top}set_top({top:e},t){B0(this._errorListener,"box.set_top",this._variables.__requestName,t);const r=this._getBox();r&&(r.top=e)}get_left(e){B0(this._errorListener,"box.get_left",this._variables.__requestName,e);const t=this._getBox();return t&&t.left}set_left({left:e},t){B0(this._errorListener,"box.set_left",this._variables.__requestName,t);const r=this._getBox();r&&(r.left=e&&Math.round(e))}set_text({text:e},t){B0(this._errorListener,"box.set_text",this._variables.__requestName,t);const r=this._getBox();r&&(r.text=e)}get_right(e){B0(this._errorListener,"box.get_right",this._variables.__requestName,e);const t=this._getBox();return t&&t.right}set_right({right:e},t){B0(this._errorListener,"box.set_right",this._variables.__requestName,t);const r=this._getBox();r&&(r.right=e&&Math.round(e))}get_bottom(e){B0(this._errorListener,"box.get_bottom",this._variables.__requestName,e);const t=this._getBox();return t&&t.bottom}set_bottom({bottom:e},t){B0(this._errorListener,"box.set_bottom",this._variables.__requestName,t);const r=this._getBox();r&&(r.bottom=e)}set_extend({extend:e},t){B0(this._errorListener,"box.set_extend",this._variables.__requestName,t);const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(fe),"extend"))}set_bgcolor({color:e},t){B0(this._errorListener,"box.set_bgcolor",this._variables.__requestName,t);const r=this._getBox();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_lefttop({left:e,top:t},r){B0(this._errorListener,"box.set_lefttop",this._variables.__requestName,r);const o=this._getBox();o&&(o.left=e&&Math.round(e),o.top=t)}set_text_size({text_size:e},t){B0(this._errorListener,"box.set_text_size",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(L2),"text_size"))}set_text_wrap({text_wrap:e},t){B0(this._errorListener,"box.set_text_wrap",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[t1.wrapAuto,t1.wrapNone],"text_wrap"))}set_text_color({text_color:e},t){B0(this._errorListener,"box.set_text_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_color=e,S1(r,["text_color"]))}set_rightbottom({right:e,bottom:t},r){B0(this._errorListener,"box.set_rightbottom",this._variables.__requestName,r);const o=this._getBox();o&&(o.right=e&&Math.round(e),o.bottom=t)}set_text_halign({text_halign:e},t){B0(this._errorListener,"box.set_text_halign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){B0(this._errorListener,"box.set_text_valign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"))}set_top_left_point({point:e},t){B0(this._errorListener,"box.set_top_left_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.top=n,r.left=r.xloc===P1.bar_index?o:b}}set_border_color({color:e},t){B0(this._errorListener,"box.set_border_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_style({style:e},t){B0(this._errorListener,"box.set_border_style",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[n2.styleDashed,n2.styleDotted,n2.styleSolid],"style"))}set_border_width({width:e},t){B0(this._errorListener,"box.set_border_width",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_width=e)}set_bottom_right_point({point:e},t){B0(this._errorListener,"box.set_bottom_right_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.bottom=n,r.right=r.xloc===P1.bar_index?o:b}}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"box.set_text_font_family",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(St),"text_font_family"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getBox(){return this._variables.box.get(this._id)||this._data}}class U_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultTable",{position:P2.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e}){return e}new(e,t){B0(this._errorListener,"table.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`table_${t}_${r}`,{rows:n}=e;S1(e,["text_color","bgcolor","border_color"]);const b=Array.from(Array(n),()=>[]),z=t.split("_"),i=z.pop(),s=z.pop(),a={...this._defaultTable,...e,cell:b,id:o,bar_index:r,line:s,col:i},O=new C3(this._variables,o,this._errorListener,a);return this._paramVerfiy(e.position,t,"table.new",Object.values(P2),"position"),t.startsWith("export")||this._variables.table.add(o,a,O),O}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}cell({table_id:e,...t},r){e==null||e.cell(t,r)}cell_set_bgcolor({table_id:e,...t},r){e==null||e.cell_set_bgcolor(t,r)}cell_set_height({table_id:e,...t},r){e==null||e.cell_set_height(t,r)}cell_set_text({table_id:e,...t},r){e==null||e.cell_set_text(t,r)}cell_set_text_color({table_id:e,...t},r){e==null||e.cell_set_text_color(t,r)}cell_set_text_font_family({table_id:e,...t},r){e==null||e.cell_set_text_font_family(t,r)}cell_set_text_halign({table_id:e,...t},r){e==null||e.cell_set_text_halign(t,r)}cell_set_text_valign({table_id:e,...t},r){e==null||e.cell_set_text_valign(t,r)}cell_set_text_size({table_id:e,...t},r){e==null||e.cell_set_text_size(t,r)}cell_set_tooltip({table_id:e,...t},r){e==null||e.cell_set_tooltip(t,r)}cell_set_width({table_id:e,...t},r){e==null||e.cell_set_width(t,r)}clear({table_id:e,...t},r){e==null||e.clear(t,r)}delete({table_id:e},t){e==null||e.delete(t)}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({table_id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({table_id:e,...t},r){e==null||e.set_border_width(t,r)}set_frame_color({table_id:e,...t},r){e==null||e.set_frame_color(t,r)}set_frame_width({table_id:e,...t},r){e==null||e.set_frame_width(t,r)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class C3{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_defaultCell",{column:0,row:0,text:"",text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_size:L2.normal});E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.TABLE}get id(){return this._id}get preId(){return this._preId}set data(e){this._data=e}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get data(){return this._variables.table.get(this._id)||this._data}cell(e,t){this._verfiyRequestFunc(t,"cell");const r={...this._defaultCell,...e},{column:o=0,row:n=0}=r,b=this._getTable();if(b){const z=b.cell||[],i=z[n]||[];i[o]=r,z[n]=i,b.cell=z}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r},o){this._verfiyRequestFunc(o,"cell_set_bgcolor");const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r},o){this._verfiyRequestFunc(o,"cell_set_height");const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r},o){this._verfiyRequestFunc(o,"cell_set_text");const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r},o){this._verfiyRequestFunc(o,"cell_set_text_color");const n=this._getTableItem(e,t);n&&(n.text_color=r,S1(n,["text_color"]))}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r},o){this._verfiyRequestFunc(o,"cell_set_text_font_family");const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r},o){this._verfiyRequestFunc(o,"cell_set_text_halign");const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r},o){this._verfiyRequestFunc(o,"cell_set_text_valign");const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r},o){this._verfiyRequestFunc(o,"cell_set_text_size");const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r},o){this._verfiyRequestFunc(o,"cell_set_tooltip");const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r},o){this._verfiyRequestFunc(o,"cell_set_width");const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){this._verfiyRequestFunc(n,"clear");const b=this._getTable();if(b){const z=b.cell;if(z)for(let i=t;i<=o;i++)for(let s=e;s<=r;s++){const a=z[i];a&&(a[s]=void 0)}}}delete(e){this._verfiyRequestFunc(e,"delete"),this._variables.table.delete(this._id,this._variables.bar_index,this._data.id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){if(this._verfiyRequestFunc(n,"merge_cells"),e>r||t>o){this._errorListener.addError(l1.mergeCellErr,n,$0.Error);return}const b=this._getTable();if(!b)return;const z=b.merge_cells||[];z.push({start_column:e,start_row:t,end_column:r,end_row:o}),b.merge_cells=z}set_bgcolor({bgcolor:e},t){this._verfiyRequestFunc(t,"set_bgcolor");const r=this._getTable();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_border_color({border_color:e},t){this._verfiyRequestFunc(t,"set_border_color");const r=this._getTable();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_width({border_width:e},t){this._verfiyRequestFunc(t,"set_border_width");const r=this._getTable();r&&(r.border_width=e)}set_frame_color({frame_color:e},t){this._verfiyRequestFunc(t,"set_frame_color");const r=this._getTable();r&&(r.frame_color=e)}set_frame_width({frame_width:e},t){this._verfiyRequestFunc(t,"set_frame_width");const r=this._getTable();r&&(r.frame_width=e)}set_position({position:e},t){this._verfiyRequestFunc(t,"set_position");const r=this._getTable();r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(P2),"position"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getTableItem(e,t){const r=this._getTable();if(r){const o=r.cell;return o?o[t][e]:void 0}}_getTable(){return this._variables.table.get(this._id)||this._data}_verfiyRequestFunc(e,t){B0(this._errorListener,`table.${t}`,this._variables.__requestName,e)}}class j_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){return this._verifyTradeNum(e,t)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.historyOrders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.historyOrders[e];return o||r}exit_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{out_qty:r=0,direction:o}=this._strategy.historyOrders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.closedtrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.historyOrders.length;return!(e>=r)}}class H_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,original_qty:o=0,commission:n=0}=this._strategy.orders[e];return n*r/o}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.orders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.orders[e];return o||r}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,direction:o}=this._strategy.orders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.opentrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.orders.length;return!(e>=r)}}class Y_{constructor(e,t){E(this,"_strategy");E(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(i1),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}}var G_=20,V_=1,Gt=1e6,x3=1e6,K_=-7,J_=21,Q_=!1,WM="[big.js] ",Vt=WM+"Invalid ",Zo=Vt+"decimal places",Z_=Vt+"rounding mode",S3=WM+"Division by zero",m1={},xe=void 0,em=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function F3(){function M(e){var t=this;if(!(t instanceof M))return e===xe?F3():new M(e);if(e instanceof M)t.s=e.s,t.e=e.e,t.c=e.c.slice();else{if(typeof e!="string"){if(M.strict===!0&&typeof e!="bigint")throw TypeError(Vt+"value");e=e===0&&1/e<0?"-0":String(e)}tm(t,e)}t.constructor=M}return M.prototype=m1,M.DP=G_,M.RM=V_,M.NE=K_,M.PE=J_,M.strict=Q_,M.roundDown=0,M.roundHalfUp=1,M.roundHalfEven=2,M.roundUp=3,M}function tm(M,e){var t,r,o;if(!em.test(e))throw Error(Vt+"number");for(M.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1,(t=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(t<0&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):t<0&&(t=e.length),o=e.length,r=0;r<o&&e.charAt(r)=="0";)++r;if(r==o)M.c=[M.e=0];else{for(;o>0&&e.charAt(--o)=="0";);for(M.e=t-r-1,M.c=[],t=0;r<=o;)M.c[t++]=+e.charAt(r++)}return M}function Kt(M,e,t,r){var o=M.c;if(t===xe&&(t=M.constructor.RM),t!==0&&t!==1&&t!==2&&t!==3)throw Error(Z_);if(e<1)r=t===3&&(r||!!o[0])||e===0&&(t===1&&o[0]>=5||t===2&&(o[0]>5||o[0]===5&&(r||o[1]!==xe))),o.length=1,r?(M.e=M.e-e+1,o[0]=1):o[0]=M.e=0;else if(e<o.length){if(r=t===1&&o[e]>=5||t===2&&(o[e]>5||o[e]===5&&(r||o[e+1]!==xe||o[e-1]&1))||t===3&&(r||!!o[0]),o.length=e,r){for(;++o[--e]>9;)if(o[e]=0,e===0){++M.e,o.unshift(1);break}}for(e=o.length;!o[--e];)o.pop()}return M}function Jt(M,e,t){var r=M.e,o=M.c.join(""),n=o.length;if(e)o=o.charAt(0)+(n>1?"."+o.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)o="0"+o;o="0."+o}else if(r>0)if(++r>n)for(r-=n;r--;)o+="0";else r<n&&(o=o.slice(0,r)+"."+o.slice(r));else n>1&&(o=o.charAt(0)+"."+o.slice(1));return M.s<0&&t?"-"+o:o}m1.abs=function(){var M=new this.constructor(this);return M.s=1,M},m1.cmp=function(M){var e,t=this,r=t.c,o=(M=new t.constructor(M)).c,n=t.s,b=M.s,z=t.e,i=M.e;if(!r[0]||!o[0])return r[0]?n:o[0]?-b:0;if(n!=b)return n;if(e=n<0,z!=i)return z>i^e?1:-1;for(b=(z=r.length)<(i=o.length)?z:i,n=-1;++n<b;)if(r[n]!=o[n])return r[n]>o[n]^e?1:-1;return z==i?0:z>i^e?1:-1},m1.div=function(M){var e=this,t=e.constructor,r=e.c,o=(M=new t(M)).c,n=e.s==M.s?1:-1,b=t.DP;if(b!==~~b||b<0||b>Gt)throw Error(Zo);if(!o[0])throw Error(S3);if(!r[0])return M.s=n,M.c=[M.e=0],M;var z,i,s,a,O,u=o.slice(),l=z=o.length,d=r.length,A=r.slice(0,z),h=A.length,q=M,_=q.c=[],m=0,L=b+(q.e=e.e-M.e)+1;for(q.s=n,n=L<0?0:L,u.unshift(0);h++<z;)A.push(0);do{for(s=0;s<10;s++){if(z!=(h=A.length))a=z>h?1:-1;else for(O=-1,a=0;++O<z;)if(o[O]!=A[O]){a=o[O]>A[O]?1:-1;break}if(a<0){for(i=h==z?o:u;h;){if(A[--h]<i[h]){for(O=h;O&&!A[--O];)A[O]=9;--A[O],A[h]+=10}A[h]-=i[h]}for(;!A[0];)A.shift()}else break}_[m++]=a?s:++s,A[0]&&a?A[h]=r[l]||0:A=[r[l]]}while((l++<d||A[0]!==xe)&&n--);return!_[0]&&m!=1&&(_.shift(),q.e--,L--),m>L&&Kt(q,L,t.RM,A[0]!==xe),q},m1.eq=function(M){return this.cmp(M)===0},m1.gt=function(M){return this.cmp(M)>0},m1.gte=function(M){return this.cmp(M)>-1},m1.lt=function(M){return this.cmp(M)<0},m1.lte=function(M){return this.cmp(M)<1},m1.minus=m1.sub=function(M){var e,t,r,o,n=this,b=n.constructor,z=n.s,i=(M=new b(M)).s;if(z!=i)return M.s=-i,n.plus(M);var s=n.c.slice(),a=n.e,O=M.c,u=M.e;if(!s[0]||!O[0])return O[0]?M.s=-i:s[0]?M=new b(n):M.s=1,M;if(z=a-u){for((o=z<0)?(z=-z,r=s):(u=a,r=O),r.reverse(),i=z;i--;)r.push(0);r.reverse()}else for(t=((o=s.length<O.length)?s:O).length,z=i=0;i<t;i++)if(s[i]!=O[i]){o=s[i]<O[i];break}if(o&&(r=s,s=O,O=r,M.s=-M.s),(i=(t=O.length)-(e=s.length))>0)for(;i--;)s[e++]=0;for(i=e;t>z;){if(s[--t]<O[t]){for(e=t;e&&!s[--e];)s[e]=9;--s[e],s[t]+=10}s[t]-=O[t]}for(;s[--i]===0;)s.pop();for(;s[0]===0;)s.shift(),--u;return s[0]||(M.s=1,s=[u=0]),M.c=s,M.e=u,M},m1.mod=function(M){var e,t=this,r=t.constructor,o=t.s,n=(M=new r(M)).s;if(!M.c[0])throw Error(S3);return t.s=M.s=1,e=M.cmp(t)==1,t.s=o,M.s=n,e?new r(t):(o=r.DP,n=r.RM,r.DP=r.RM=0,t=t.div(M),r.DP=o,r.RM=n,this.minus(t.times(M)))},m1.neg=function(){var M=new this.constructor(this);return M.s=-M.s,M},m1.plus=m1.add=function(M){var e,t,r,o=this,n=o.constructor;if(M=new n(M),o.s!=M.s)return M.s=-M.s,o.minus(M);var b=o.e,z=o.c,i=M.e,s=M.c;if(!z[0]||!s[0])return s[0]||(z[0]?M=new n(o):M.s=o.s),M;if(z=z.slice(),e=b-i){for(e>0?(i=b,r=s):(e=-e,r=z),r.reverse();e--;)r.push(0);r.reverse()}for(z.length-s.length<0&&(r=s,s=z,z=r),e=s.length,t=0;e;z[e]%=10)t=(z[--e]=z[e]+s[e]+t)/10|0;for(t&&(z.unshift(t),++i),e=z.length;z[--e]===0;)z.pop();return M.c=z,M.e=i,M},m1.pow=function(M){var e=this,t=new e.constructor("1"),r=t,o=M<0;if(M!==~~M||M<-x3||M>x3)throw Error(Vt+"exponent");for(o&&(M=-M);M&1&&(r=r.times(e)),M>>=1,!!M;)e=e.times(e);return o?t.div(r):r},m1.prec=function(M,e){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");return Kt(new this.constructor(this),M,e)},m1.round=function(M,e){if(M===xe)M=0;else if(M!==~~M||M<-Gt||M>Gt)throw Error(Zo);return Kt(new this.constructor(this),M+this.e+1,e)},m1.sqrt=function(){var M,e,t,r=this,o=r.constructor,n=r.s,b=r.e,z=new o("0.5");if(!r.c[0])return new o(r);if(n<0)throw Error(WM+"No square root");n=Math.sqrt(+Jt(r,!0,!0)),n===0||n===1/0?(e=r.c.join(""),e.length+b&1||(e+="0"),n=Math.sqrt(e),b=((b+1)/2|0)-(b<0||b&1),M=new o((n==1/0?"5e":(n=n.toExponential()).slice(0,n.indexOf("e")+1))+b)):M=new o(n+""),b=M.e+(o.DP+=4);do t=M,M=z.times(t.plus(r.div(t)));while(t.c.slice(0,b).join("")!==M.c.slice(0,b).join(""));return Kt(M,(o.DP-=4)+M.e+1,o.RM)},m1.times=m1.mul=function(M){var e,t=this,r=t.constructor,o=t.c,n=(M=new r(M)).c,b=o.length,z=n.length,i=t.e,s=M.e;if(M.s=t.s==M.s?1:-1,!o[0]||!n[0])return M.c=[M.e=0],M;for(M.e=i+s,b<z&&(e=o,o=n,n=e,s=b,b=z,z=s),e=new Array(s=b+z);s--;)e[s]=0;for(i=z;i--;){for(z=0,s=b+i;s>i;)z=e[s]+n[i]*o[s-i-1]+z,e[s--]=z%10,z=z/10|0;e[s]=z}for(z?++M.e:e.shift(),i=e.length;!e[--i];)e.pop();return M.c=e,M},m1.toExponential=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),++M,e);t.c.length<M;)t.c.push(0)}return Jt(t,!0,!!r)},m1.toFixed=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),M+t.e+1,e),M=M+t.e+1;t.c.length<M;)t.c.push(0)}return Jt(t,!1,!!r)},m1[Symbol.for("nodejs.util.inspect.custom")]=m1.toJSON=m1.toString=function(){var M=this,e=M.constructor;return Jt(M,M.e<=e.NE||M.e>=e.PE,!!M.c[0])},m1.toNumber=function(){var M=+Jt(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(M.toString()))throw Error(WM+"Imprecise conversion");return M},m1.toPrecision=function(M,e){var t=this,r=t.constructor,o=t.c[0];if(M!==xe){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");for(t=Kt(new r(t),M,e);t.c.length<M;)t.c.push(0)}return Jt(t,M<=t.e||t.e<=r.NE||t.e>=r.PE,!!o)},m1.valueOf=function(){var M=this,e=M.constructor;if(e.strict===!0)throw Error(WM+"valueOf disallowed");return Jt(M,M.e<=e.NE||M.e>=e.PE,!0)};var en=F3();function I3(M,e){return en(M).plus(e).toNumber()}function tn(M,e){return en(M).minus(e).toNumber()}function Qt(M,e){return en(M).mul(e).toNumber()}function rn(M,e=5){return Number(M&&en(M).toFixed(e))}let rm=class{constructor(e,t,r,o,n){E(this,"_variables");E(this,"_options");E(this,"_totalChangeCapital");E(this,"_historyOrder");E(this,"_orders");E(this,"_exitOrders");E(this,"_pendingOrders");E(this,"_mintick");E(this,"_funcOptions");E(this,"_pendingCloseOrders");E(this,"_errorListener");E(this,"_risk");E(this,"_opentrades");E(this,"_closedtrades");E(this,"_riskNamespace");E(this,"_updateOptions",{});E(this,"_id");E(this,"_maxDrawdownVerifyIndex",0);E(this,"calcOnOrderFillsData",{index:-1});this._variables=e,this._errorListener=o,this._options={overlay:!1,format:O1.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:b2.fixed,default_qty_value:1,initial_capital:1e6,currency:D3.NONE,slippage:0,commission_type:O2.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=t,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 H_(this),this._closedtrades=new j_(this),this._riskNamespace=new Y_(this,o),this._id=`strategy_${n}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;return this._orders.reduce((t,r)=>t+e*(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(e){this._updateOptions=e||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._ordersHandle(),this._pendingOrderHandle(),this._exitOrdersHandle(),this._maxIntradayFilledOrdersVerify(),this._maxDrawdownVerify();const{open:e,high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,o=this._variables.close;this._variables.strategy.update(this.calcOnOrderFillsData.currentData||{open:e,close:o,high:t,low:r}),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}calcCurrentOrder(){this._ordersHandle(),this._pendingOrderHandle(),this._calcProfitAndLoss()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var l;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{time_tradingday:o,time:n,strategy:{netprofit:b,initial_capital:z}}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables;let{preNetprofit:a=0}=this._risk;n===o&&(a=b,this._risk.preNetprofit=b,this._risk.isTemporaryBan=!1);let O=a-b;O+=this._orders.reduce((d,A)=>{const{in_price:h,direction:q,qty:_=0,commission:m=0,original_qty:L=0}=A,g=q===i1.long?1:-1,v=(i-h)*_,y=(s-h)*_,X=g===1?y:-v;return d+X+_/L*m},0);let u=!1;switch(t){case b2.cash:u=e<O;break;case b2.percentOfEquity:const d=O/(z+b)*100;u=e<d;break}if(u){this._risk.isTemporaryBan=!0;const d=(l=this._orders[0])==null?void 0:l.direction;this._closeOrders(this._orders,d===i1.long?s:i,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:o,time_tradingday:n}=this._variables,{open:b}=this.calcOnOrderFillsData.data||this._variables;o===n&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,b,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:o=0}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:b,strategy:z}=this._variables,{open:i}=this.calcOnOrderFillsData.data||this._variables;let s=t;if(n===b){const a=z.netprofit+z.openprofit;a<o?s=0:s++,Object.assign(this._risk,{lossDays:s,totalProfit:a})}e<=s&&this._riskTouchOff(i,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:o}=this._variables,{open:n}=this.calcOnOrderFillsData.data||this._variables;if(e!==void 0&&t&&this._maxDrawdownVerifyIndex===o){const{initial_capital:b}=this._options,i=this._orders.reduce((a,O)=>{const{in_price:u,commission:l=0,qty:d=0,original_qty:A=0,direction:h}=O,q=h===i1.long?1:-1,_=(n-u)*q*d;return a+_+l*d/A},0)+this._totalChangeCapital;let s=!1;switch(t){case b2.percentOfEquity:s=i/b*100<=-e;break;case b2.cash:s=i<=-e;break}s&&this._riskTouchOff(n,"Close Position (Max Drawdown)")}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,e,t,"close"),this._pendingOrders=[]}strategy(e,t){if(!this._variables.bar_index){this._paramVerfiy(e.format,t,"strategy",[O1.inherit,O1.price,O1.percent,O1.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(b2),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(O2),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),o={...this._updateOptions};if(r)for(const n of Object.keys({...r,...e}))e[n]!==r[n]&&delete o[n];this._variables.max_bars_back=e.max_bars_back||0,self==null||self.workerStorage.set(this._id,e),Object.assign(this._options,e,o),this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:o,scriptType:"strategy"})}}order(e,t){this._verfiyRequestFunc(t,"order"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(Ue),"oca_type"),this._orderHandle(e))}entry(e,t){this._verfiyRequestFunc(t,"entry"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(Ue),"oca_type"),this._entryHandle(e))}close(e,t){if(this._verfiyRequestFunc(t,"close"),!this._getCloseOrders(e.id).length)return;const{immediately:o}=e;if(o||this._options.process_orders_on_close){const n=this._pendingCloseOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingCloseOrders.push({...e,place_order_type:"close"})}else{const n=this._pendingOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingOrders.push({...e,place_order_type:"close"})}}close_all(e,t){if(this._verfiyRequestFunc(t,"close_all"),typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:r}=e;r||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e},t){this._verfiyRequestFunc(t,"cancel"),this._pendingOrders=this._pendingOrders.filter(r=>!(r.id===e&&r.place_order_type!=="close"))}cancel_all(e){this._verfiyRequestFunc(e,"cancel_all"),this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(e,t){this._verfiyRequestFunc(t,"exit"),this._exit(e,t)}convert_to_account({value:e},t){return this._verfiyRequestFunc(t,"convert_to_account"),e}convert_to_symbol({value:e},t){return this._verfiyRequestFunc(t,"convert_to_symbol"),e}default_entry_qty({fill_price:e},t){return this._verfiyRequestFunc(t,"default_entry_qty"),e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=b2.fixed,default_qty_value:r=1,initial_capital:o,commission_value:n}=this._options;let b=r;switch(t){case b2.cash:b=r/e;break;case b2.percentOfEquity:const z=this._getOrderProfit(e),i=o+z+this._totalChangeCapital;n?b=this._getCommQty(i,e):b=i*r/100/e;break}return sc(b,this._getLen())}_calcExitQty(e){if(!String(e).includes("."))return e;const t=this._getLen();return Math.ceil(Qt(e,Math.pow(10,t)))}_getCommQty(e,t){const{commission_type:r,commission_value:o=0,default_qty_value:n=0}=this._options;let b=0;switch(r){case O2.percent:b=e*n/(100*t+o*t);break;case O2.cashPerContract:b=e*n/(100*t+o);break;case O2.cashPerOrder:b=(e-o)*n/100/t}return b}_getLen(){const e=5-(this._variables.precision||5);return e<0?0:e}_getCapital(e,t){const{margin_long:r=0,margin_short:o=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:o<=100&&o>0&&e===-1&&(t=t*100/o),t}_calcProfitAndLoss(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;for(const t of this._orders){const{in_price:r,qty:o=0,direction:n}=t,b=n===i1.long?1:-1,z=(e-r)*b*o,[i,s]=this._calcProfitAndLossHandle(r,o,b);this._calcOrderPercent(t,z,i,s)}}_calcProfitAndLossHandle(e,t,r,o){const{high:n,low:b}=this.calcOnOrderFillsData.data||this._variables,z=((o||n)-e)*t,i=((o||b)-e)*t;let s=r===1?z:-i,a=r===1?i:-z;return[s,a]}_calcOrderPercent(e,t,r,o){const{commission_value:n}=this._options,{close:b}=this.calcOnOrderFillsData.data||this._variables,{original_qty:z=0,qty:i=0,in_price:s,max_profit:a=0,trading_loss:O=0}=e;let{commission:u=0}=e,l=s*i;if(n){const d=this._getCommission(b,i);u=u*i/z,r-=u,o-=u,l+=u,t=t-d-u}r=Math.max(r,a,0),o=Math.min(o,O,0),Object.assign(e,{profit:t,total_profit:this._totalChangeCapital+t,total_profit_percent:t/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:o,profit_percent:t/l*100,max_profit_percent:r/l*100,trading_loss_percent:o/l*100})}_calcLiquidate(){if(!this._orders.length)return;const{time:e}=this._variables,{high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,{initial_capital:o,margin_long:n=0,margin_short:b=0}=this._options,z=this._orders[0].direction===i1.long?1:-1;let i=z===1?r:t;if(z===1&&n===100)return;const s=(z===1?n:b)/100;if(s<=0)return;let a=!1;const[O,u]=this._orders.reduce((h,q)=>{let[_,m]=h;const{in_price:L,qty:g=0,in_time:v}=q;v===e&&(a=!0);const y=L*g,X=i*g;return _+=y,m+=X,[_,m]},[0,0]);let l=0,d=0;const A=o+this._totalChangeCapital;if(a&&(l=A-O*s,l<0&&(i=this._orders[0].in_price,d=Math.abs(Math.trunc(l/s/i)*4),d=Math.max(d,1))),l>=0){const h=z*(u-O);if(l=A+h-u*s,l>=0)return;d=Math.abs(Math.trunc(l/s/i)*4)}d<=0||this._marginCallOrders(i,d,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:o="FIFO"}=this._options;if(o==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r,!0);return}for(const n of this.orders)n.position_close_type=n.place_order_type,n.isTiggerClose=!0,this._processOrder(n,e,t,r,r,!0);this._orders=this._orders.filter(n=>!n.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e),s=e.direction===i1.long?1:-1;if(o<=0)return;let a=o;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"order"});return}this._judgeCapitalEnough(o,b,s)&&this._addPendingOrders(e,b,a,r,z)}_orderOnCloseHandle(e){const t=this._orders.filter(_=>_.direction!==e.direction),{slippage:r=0}=this._options;let{direction:o,qty:n=0,id:b,comment:z,oca_type:i,oca_name:s,in_price:a}=e;const O=o===i1.long?1:-1;if(t.length){const _=this._processOrders(t,a,n,b,z,!1,"order");if(_<=0)return;n=_}const u=a-O*r*this._mintick;if(!this._judgeCapitalEnough(n,u,O))return;this._ocaGroupVerify(n,s,i);const{bar_index:d,time:A}=this._variables,{high:h,low:q}=this.calcOnOrderFillsData.data||this._variables;this._calcCurrentOrder({...e,in_price:u,in_high:h,in_low:q,in_index:d,in_time:A,qty:n,place_order_type:"order"})}_judgeCapitalEnough(e,t,r){let o=this._freezeCapital;if(this._orders.some(a=>(a.direction===i1.long?1:-1)!==r)&&(o=0),e<=0)return!1;const{margin_long:n=0,margin_short:b=0}=this._options;if(n===0&&r===1||b===0&&r===-1)return!0;const z=this._getOrderProfit(t),s=this._getCapital(r,this._options.initial_capital+z+this._totalChangeCapital)-o;return e*t<=s}_getOrderProfit(e){return this._orders.reduce((t,r)=>{const{in_price:o,qty:n=0,direction:b}=r,z=b===i1.long?1:-1;return t+(e-o)*n*z},0)}_ocaGroupVerify(e,t,r){if(!t||!r||r===Ue.none)return!1;let o=!1;switch(r){case Ue.cancel:this._pendingOrders=this._pendingOrders.filter(n=>{if(n.oca_name===t)n.isCancel=!0,o=!0;else return!0});break;case Ue.reduce:this._pendingOrders=this._pendingOrders.filter(n=>{const{qty:b=0,oca_name:z}=n;if(t===z){const i=b-e;return o=!0,i<=0?(n.isCancel=!0,!1):(n.qty=i,!0)}else return!0});break}return o}_processOrders(e,t,r,o,n,b=!1,z,i){if(!e.length)return r;let s=r;for(const a of e)if(a.position_close_type=z||a.place_order_type,a.immediately=i,a.isTiggerClose=b||a.position_close_type==="close",s=this._processOrder(a,t,s,o,n,b),s<=0)break;return this._orders=this._orders.filter(a=>!a.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),s}_addPendingOrders(e,t,r,o,n){const b=this._pendingOrders.find(z=>z.id===e.id&&!z.isMarketPrice);if(b)Object.assign(b,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const z={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"order"};this._pendingOrders.push(z)}}_orderArgsParse(e){var q,_;const{direction:t,qty:r,stop:o}=e;let n=e.limit||0,{close:b}=this.calcOnOrderFillsData.data||this._variables;(_=(q=this.calcOnOrderFillsData)==null?void 0:q.tradeData)!=null&&_.open&&(b=this.calcOnOrderFillsData.tradeData.open);let z=b,i=!1,s;const a=t===i1.long?1:-1,O=o&&(o-b)*a>=0,{backtest_fill_limits_assumption:u=0}=this._options;u>0&&n&&(n-=u*this._mintick*a);const l=n&&(n-b)*a<=0;let d=!1;O&&l?(o!==b&&(s=o),z=n):O?(z=o,d=o===b):l?(z=n,d=n===b):i=!0;const A=r!==void 0?sc(r,this._getLen()):this._calcDefaultQty(z);return{orders:this._orders.filter(m=>m.direction!==t),isMarketPrice:i,activePrice:s,quantities:A,close:b,price:z,isTouch:d}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e);if(o<=0)return;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"entry"});return}this._judgeCapitalEnough(o,n,e.direction===i1.long?1:-1)&&this._addPendingEntry(e,b,o,r,z)}_entryOnCloseHandle(e){const{direction:t,in_price:r,qty:o=0}=e,n=this._orders.filter(b=>b.direction!==t);this._entryOrder(n,r,o,e)}_entryOrder(e,t,r,o){const{time:n,bar_index:b}=this._variables,{high:z,low:i}=this.calcOnOrderFillsData.data||this._variables,{slippage:s=0}=this._options,{oca_name:a,oca_type:O,direction:u,comment:l,id:d}=o,A=u===i1.long?1:-1;if(r=this._getAvailablePositionSize(r,u),r<=0)return;const h=t;if(t=t+s*this._mintick*A,!this._judgeCapitalEnough(r,t,A))return;this._closeOrders(e,h,d,l,"entry",void 0,!0);const _={...o,in_price:t,qty:r,in_index:b,in_high:z,in_low:i,in_time:n,place_order_type:"entry"},{orders:m}=this._getEntryOrders(u),L=m.length;L&&L>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,a,O),this._calcCurrentOrder(_))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:o}=this._risk;if(o&&o!==i1.all&&o!==t)return 0;if(r===void 0)return e;const n=this._orders.reduce((b,z)=>b+(z.qty||0),0);return n?n+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(o=>["entry","order"].includes(o.place_order_type)&&o.direction===e),r=this._orders.filter(o=>o.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,o,n){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:b}=this._getEntryOrders(e.direction),z=b.find(i=>i.id===e.id&&i.place_order_type==="entry");if(z)Object.assign(z,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const i={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"entry"};this._pendingOrders.push(i)}}_closeAllOrders(e,t){const{comment:r,immediately:o}=e,{bar_index:n}=this._variables,b=this._orders.filter(z=>z.in_index!==n);b.length&&(this._closeOrders(b,t,"Close position order",r,"close",o),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,o,n,b,z){if(e.length){for(const i of e)i.position_close_type=n,i.immediately=b,i.isTiggerClose=!0,this._closeOrder(i,t,r,o,z);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}}_closeOrder(e,t,r,o,n){const{time:b,bar_index:z}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables,{slippage:a=0}=this._options,{in_price:O,qty:u=0,direction:l}=e,d=l===i1.long?1:-1;t=t-d*a*this._mintick,e.isDeal=!0;const A=(t-O)*d*u,h={...e,out_price:t,out_id:r,out_index:z,out_high:i,out_low:s,out_time:b,out_comment:o,out_qty:u,profit:A};this._calcPercent(h,n)}_exitOrdersHandle(){if(!this._exitOrders.length)return;let{open:e,low:t,high:r,close:o}=this.calcOnOrderFillsData.data||this._variables;const n=[],b=Math.abs(r-e),z=Math.abs(t-e),i=[],s=this._variables.precision;e=Number(e.toFixed(s)),t=Number(t.toFixed(s)),r=Number(r.toFixed(s)),o=Number(o.toFixed(s));for(const a of this._exitOrders){const{directionNum:O,id:u,comment:l,qty:d,comment_loss:A,comment_profit:h,comment_trailing:q,order:_}=a;if(_.isTiggerClose)continue;let m=b<z||b===z&&O===1;if(_.in_time===this._variables.time&&!this._variables._isRepeated){const{in_price:D}=_;m?D<r&&D>=e?e=D:D<=r&&D>=o?r=D:r=o:D<=e&&D>t?e=D:D<=o&&D>=t?t=D:t=o,e=D}const L=[],[g,v]=this._getLimitPrice(a,e,t,r,m);g&&L.push({order:_,price:g,index:v,isHighFront:m,exitInfo:{id:u,comment:h||l,qty:d}});const[y,X]=this._getStopPrice(a,e,t,r,m);y&&L.push({order:_,price:y,index:X,isHighFront:m,exitInfo:{id:u,comment:A||l,qty:d}});const[T,N]=this._getTrailStopPrice(a,e,t,r,o,m);if(T&&L.push({order:_,price:T,index:N,isHighFront:m,exitInfo:{id:u,comment:q||l,qty:d}}),L.length){this._executesSort(L),n.push(L[0]);continue}i.push(a)}this._exitOrders=i,this._executesSort(n);for(const a of n){const{order:O,price:u,exitInfo:l,isHighFront:d,index:A}=a;d?(r=A===1?u:r,t=A===1?e:u):(r=A===1?e:u,t=A===1?u:t),this._variables.strategy.update({open:u,high:r,low:t,close:o}),this._processExitOnClose(O,u,l)}}_executesSort(e){return e.sort(({price:t,index:r,isHighFront:o},{price:n,index:b})=>r!==b?r-b:o?r===1?t-n:n-t:r===1?n-t:t-n),e}_getLimitPrice(e,t,r,o,n){const{limit:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z>=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getStopPrice(e,t,r,o,n){const{stop:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z<=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getTrailStopPrice(e,t,r,o,n,b){const{trail_stop_price:z,directionNum:i,active_price:s,trail_offset:a=0}=e;let O=z,u,l=1;if(O)if((O-t)*i>=0)u=t,l=1;else{const[d,A,h]=this._calcTrailStopPrice(O,o,r,n,a,i,b);u=A,l=h||1,e.trail_stop_price=d}if(s&&!u&&s<=o&&s>=r)if(a===0)u=s,b&&s>t||!b&&s<t?l=1:l=2;else{O=tn(s,Qt(a*i,this._mintick));let d=o,A=r;b?s>=t&&s<=o?(d=o,l=1):(b=!1,d=n,l=2):s<t&&s>=r?(A=r,l=1):(b=!0,A=n,l=2);const[h,q,_=1]=this._calcTrailStopPrice(O,d,A,n,a,i,b);delete e.active_price,l<_&&(l=_),e.trail_stop_price=h,u=q}return[u,l]}_ordersHandle(e){const t=this._orders.filter(b=>b.isMarketPriceLimit||b.isMarketPriceStop);if(!t.length)return;const{open:r,close:o}=this.calcOnOrderFillsData.data||this._variables,n=e?o:r;for(const b of t){const{out_comment:z,out_qty:i,out_id:s}=b;this._processExitOnClose(b,n,{id:s,comment:z,qty:i})}}_calcTrailStopPrice(e,t,r,o,n,b,z){let i=e,s;const a=tn(b===1?t:r,Qt(n*b,this._mintick));let O=1;return b===1?z?(i<a&&(i=a),i>=r&&(O=2,s=i)):i>=r?(O=1,s=i):a>i&&(i=a,a>=o&&(O=3,s=a)):z?i<=t?(O=1,s=i):a<i&&(i=a,a<=o&&(O=3,s=a)):(a<i&&(i=a),i<=t&&(O=2,s=i)),[i,s,O]}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(z=>z.place_order_type==="exit");let r=[];for(const z of this._pendingOrders){const{isCancel:i,place_order_type:s,isMarketPrice:a}=z;if(i)continue;let O;switch(s){case"entry":if(!a){r.push(z);continue}this._entryOrderHandle(z);break;case"order":if(!a){r.push(z);continue}this._orderOrderHandle(z);break;case"close":O=this._closeOrderHandle(z);break;case"close_all":const{open:u}=this.calcOnOrderFillsData.data||this._variables;this._closeAllOrders(z,u);break}O&&e.push(O)}const o=this._options.pyramiding||1,n=this._orders.filter(z=>z.direction===i1.long).length<o,b=this._orders.filter(z=>z.direction===i1.short).length<o;r=r.filter(z=>z.direction===i1.long&&n||z.direction===i1.short&&b);for(const z of this._pendingOrderSort(r)){const{place_order_type:i}=z;let s;switch(i){case"entry":s=this._entryOrderHandle(z);break;case"order":s=this._orderOrderHandle(z);break}s&&e.push(s)}for(const z of t){const i=this._exitOrderHandle(z);i&&e.push(i)}this._pendingOrders=e}_pendingOrderSort(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,n=Math.abs(o-t)<=Math.abs(r-t);return e.sort(({in_price:b},{in_price:z})=>{let i=0,s=0;return n?(b>=t&&b<=o?i=1:i=2,z>=t&&z<=o?s=1:s=2):(b<=t&&b>=r?i=1:i=2,z<=t&&z>=r?s=1:s=2),i!==s?i-s:n?i===1?b-z:z-b:i===1?z-b:b-z}),e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const{close:e}=this.calcOnOrderFillsData.data||this._variables,t=[];for(const r of this._pendingCloseOrders)switch(r.place_order_type){case"close":const o=this._closeOrderHandle(r,!0);o&&t.push(o);break;case"close_all":this._closeAllOrders(r,e);break;case"entry":this._entryOnCloseHandle(r);break;case"order":this._orderOnCloseHandle(r);break}this._pendingCloseOrders=t,this._ordersHandle(!0)}_entryOrderHandle(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,{isMarketPrice:n,qty:b=0,in_price:z,direction:i,active_price:s}=e;if(s&&o>=s&&r<=s)return delete e.active_price,e;let a=z;if(n)a=t;else{let{stop:O,limit:u}=e;const l=i===i1.long?1:-1,d=O&&(O-t)*l>=0,{backtest_fill_limits_assumption:A=0}=this._options;A>0&&u&&(u-=A*this._mintick*l);const h=u&&(u-t)*l<=0;d&&h||(O&&!d||u&&!h)&&(a=t)}if(a<=o&&a>=r){const O=this._orders.filter(u=>u.direction!==i);this._entryOrder(O,a,b,e)}else return e}_orderOrderHandle(e){const{time:t,bar_index:r}=this._variables,{open:o,low:n,high:b}=this.calcOnOrderFillsData.data||this._variables,{slippage:z=0}=this._options,{isMarketPrice:i,qty:s=0,in_price:a,direction:O,comment:u,oca_name:l,oca_type:d,active_price:A,id:h}=e;if(A&&b>=A&&n<=A)return delete e.active_price,e;let q=a,_=s;if(i&&(q=o),q<=b&&q>=n){const m=this._orders.filter(g=>g.direction!==O);if(m.length&&(_=this._processOrders(m,q,s,h,u,!1,"order"),_<=0))return;const L=O===i1.long?1:-1;this._ocaGroupVerify(_,l,d),this._calcCurrentOrder({...e,in_price:q-L*z*this._mintick,in_index:r,in_time:t,in_high:b,in_low:n,qty:_});return}else return e}_getCloseOrders(e){const{close_entries_rule:t="FIFO"}=this._options;let r=[];return t==="FIFO"?r=this._orders.filter(o=>o.id===e):r=this._orders.filter(o=>o.id===e&&!o.close_qty),r}_closeOrderHandle(e,t){const{id:r,qty:o,qty_percent:n=100,comment:b,immediately:z}=e,{close_entries_rule:i="FIFO"}=this._options,s=this._getCloseOrders(r);if(!s.length)return;let a=0;if(o?a=o:(a=s.reduce((l,d)=>l+(d.qty||0),a),a=n/100*a),a<=0)return;const{open:O,close:u}=this.calcOnOrderFillsData.data||this._variables;if(i==="FIFO")this._processOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,!1,"close",z);else if(this._processCloseOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,z))return e}_processCloseOrders(e,t,r,o,n,b){let z=!1;for(const i of e)i.close_qty=r,(i.qty||0)>r&&(z=!0),i.immediately=b,i.position_close_type="close",i.isTiggerClose=!0,this._processOrder(i,t,r,o,n);return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_exitOrderHandle(e){const{from_entry:t,id:r}=e,o=this._orders.filter(n=>{var b;return(!t||t===n.id)&&!((b=n.exitIds)!=null&&b.includes(r))});if(!(o.length&&!this._ordersToExit(o,e,!0)))return e}_exit(e,t){if(!e.hasOwnProperty("profit")&&!e.hasOwnProperty("loss")&&!e.hasOwnProperty("stop")&&!e.hasOwnProperty("limit")&&(!e.hasOwnProperty("trail_offset")||!e.hasOwnProperty("trail_price")&&!e.hasOwnProperty("trail_points"))){this._errorListener.addError(l1.strategyExitErr,t,$0.Error);return}const{profit:r,loss:o,stop:n,limit:b,trail_offset:z,trail_price:i,trail_points:s,from_entry:a="",id:O}=e;if(this._isNaN(r)&&this._isNaN(o)&&this._isNaN(n)&&this._isNaN(b)&&(this._isNaN(z)||this._isNaN(s)&&this._isNaN(i)))return;const u={...e,place_order_type:"exit"},l=this._orders.filter(q=>{var _;return(!a||a===q.id)&&!((_=q.exitIds)!=null&&_.includes(O))}),d=this._updateExitOrders(u),A=this._pendingOrders.filter(q=>(!a||a===q.id)&&["order","entry"].includes(q.place_order_type||""));if(l.length){if(!this._ordersToExit(l,u,!1))return}else if(!A.length||d)return;const h=this._pendingOrders.find(q=>q.id===O&&q.place_order_type==="exit");h?Object.assign(h,{...e}):this._pendingOrders.push(u)}_updateExitOrders(e){let t=!1;e.qty&&(e.qty=this._calcExitQty(e.qty));const r=this._exitOrders.filter(o=>o.id===e.id&&(o.from_entry===e.from_entry||!e.from_entry));for(const o of r){const{directionNum:n,order:b,qty:z}=o;if(b.isTiggerClose){o.isClose=!0;continue}t=!0;const i={qty:z,...e},s=!0;if(this._stopProfit(b,n,i,s)){o.isClose=!0;continue}if(this._stopLoss(b,n,i,s)){o.isClose=!0;continue}if(this._trailStopLoss(b,n,i,s)){o.isClose=!0;continue}Object.assign(o,i)}return this._exitOrders=this._exitOrders.filter(o=>!o.isClose),t}_ordersToExit(e,t,r){var q;const{qty:o,qty_percent:n=100,id:b,comment:z}=t;let i=o,s=!1;t.comment=z||b;const a=e[0],O={...t},{qty:u=0}=a,l=a.direction===i1.long?1:-1;return i=o?o>=u?u:o:n/100*u,O.qty=this._calcExitQty(i),i<u&&(s=!0),this._stopProfit(a,l,O,r)||this._stopLoss(a,l,O,r)||this._trailStopLoss(a,l,O,r)||(this._exitOrders.push({...O,directionNum:l,order:a}),a.exitIds?(q=a.exitIds)==null||q.push(b):a.exitIds=[b]),s}_addExitPendingCloseOrders(e){const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r,o){var A,h;const{limit:n,profit:b,comment_profit:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=I3(u,Qt(b*t,this._mintick))),r.limit=t===1?ac(O,this._variables.precision):uc(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t<=0)return e.isMarketPriceLimit=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r,o){var A,h;const{stop:n,loss:b,comment_loss:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=tn(u,Qt(b*t,this._mintick))),r.stop=t===1?uc(O,this._variables.precision):ac(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t>=0)return e.isMarketPriceStop=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r,o){var u,l;const{trail_offset:n,trail_price:b,trail_points:z,comment_trailing:i,comment:s,id:a,qty:O}=r;if(!this._isNaN(n)){const{in_price:d}=e,{process_orders_on_close:A}=this._options;let h;if(this._isNaN(b)?this._isNaN(z)||(h=I3(d,Qt(z*t,this._mintick))):h=b,r.active_price=h,o)return;let{close:q}=this.calcOnOrderFillsData.data||this._variables;if((l=(u=this.calcOnOrderFillsData)==null?void 0:u.tradeData)!=null&&l.open&&(q=this.calcOnOrderFillsData.tradeData.open),h!==void 0&&(h-q)*t<=0){const _=tn(q,Qt(n*t,this._mintick));if((_-q)*t>=0)return e.isMarketPriceStop=!0,r.comment=i||s,Object.assign(e,{out_comment:r.comment,out_id:a,out_qty:O}),A&&this._addExitPendingCloseOrders(r),!0;r.trail_stop_price=_}}}_processExitOnClose(e,t,r){const{qty:o=0,comment:n,id:b}=r,{close_entries_rule:z="FIFO"}=this._options;if(o)if(e.isTiggerClose=!0,z==="FIFO")this._processExitOrders(this._orders,t,o,b,n);else{if(e.isDeal)return;this._processOrders([e],t,o,b,n,!1,"exit")}}_processExitOrders(e,t,r,o,n){let b=r,z;for(const i of e)if(z=i,i.position_close_type="exit",b=this._processOrder(i,t,b,o,n),b<=0)break;return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_processOrder(e,t,r,o,n,b=!1){const{time:z,bar_index:i}=this._variables,{low:s,high:a}=this.calcOnOrderFillsData.data||this._variables,{slippage:O=0}=this._options,{in_price:u,qty:l=0,max_profit:d,trading_loss:A,direction:h,commission:q=0,original_qty:_=0}=e,m=h===i1.long?1:-1;if(t=t-m*O*this._mintick,r<l){const L=l-r,g=(t-u)*m*r,v=d!==void 0?d/l*r:void 0,y=A!==void 0?A/l*r:void 0,X=q*L/_;this._calcPercent({...e,out_price:t,last_commission:X,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,profit:g,out_qty:r,max_profit:v,trading_loss:y});const T=(t-u)*m*L-X;Object.assign(e,{qty:L,profit:T,max_profit:d!==void 0?d-(v||0):void 0,trading_loss:A!==void 0?A-(y||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{e.isDeal=!0;const L=(t-u)*m*l;this._calcPercent({...e,out_price:t,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,out_qty:l,profit:L}),r-=l}return b&&(m===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(e,t){const{commission_value:r,process_orders_on_close:o}=this._options,{in_price:n,out_qty:b=0,out_price:z=0,original_qty:i=0,direction:s,last_commission:a=0,immediately:O}=e;let{profit:u=0,max_profit:l,trading_loss:d,commission:A=0}=e,h=n*b,q=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=u,r){const g=this._getCommission(z,b);this._totalChangeCapital-=g;let v=A*b/i;h+=v,v+=g,u=u-v,Object.assign(e,{commission:v});const y=this._orders.reduce((X,T)=>{const{qty:N=0,original_qty:D=0,commission:C=0}=T;return X+C*N/D},0);q+=y-a}const _=s===i1.long?1:-1;let[m,L]=this._calcProfitAndLossHandle(n,b,_,z);if(r){const g=A*b/i;m-=g,L-=g}l=Math.max(m,l||0),d=Math.min(L,d||0),u=parseFloat(String(u)),Object.assign(e,{max_profit:l,profit:u,trading_loss:d,total_profit:this._totalChangeCapital,total_profit_percent:u/q*100,profit_percent:u/h*100,max_profit_percent:l/h*100,trading_loss_percent:d/h*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(o?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(e),!t&&this._calcOrderFillsHandle(z,s,O)}_getCommission(e,t){const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:o=0,max_profit:n=0,trading_loss:b=0,direction:z,immediately:i}=e;let{profit:s=0}=e,a=r*o;const O=this._totalChangeCapital+this._options.initial_capital;if(t){const u=this._getCommission(r,o);this._totalChangeCapital-=u,s=s-u,a+=u,Object.assign(e,{commission:u,total_profit:this._totalChangeCapital})}s=parseFloat(String(s)),Object.assign(e,{original_qty:o,profit:s,total_profit_percent:s/O*100,profit_percent:s/a*100,max_profit_percent:n/a*100,trading_loss_percent:b/a*100,stop:void 0,limit:void 0}),this._risk.intradayOrders+=1,this._orders.push(e),this._variables.strategy.updateOrders(this._orders),t&&this._variables.strategy.updateHistoryOrders(this._historyOrder),this._calcOrderFillsHandle(r,z,i)}_calcOrderFillsHandle(e,t,r=!1){const{calc_on_order_fills:o,process_orders_on_close:n,slippage:b=0}=this._options;if(o){const{open:z,high:i,low:s,close:a}=this._variables,O=t===i1.long?1:-1,u=a-O*b*this._mintick;if((r||n)&&e===u)return;const l=z-O*b*this._mintick;let d={open:z,high:i,low:s,close:a},A={open:z,high:i,low:s,close:a},h=this.calcOnOrderFillsData.index;const q=Math.abs(i-z)<=Math.abs(s-z);switch(h){case-1:e===l?(h=0,A={open:z,high:z,low:z,close:z}):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 0:e===l?(h=1,q?(A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a})):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 1:h=2,q?(A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a});break;case 2:h=-1,d=void 0;break}this.calcOnOrderFillsData={tradeData:d,index:h,currentData:A}}}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_verfiyRequestFunc(e,t){B0(this._errorListener,`strategy.${t}`,this._variables.__requestName,e)}};class lp{constructor(e,t,r){E(this,"array");E(this,"color");E(this,"math");E(this,"str");E(this,"map");E(this,"matrix");E(this,"timeframe");E(this,"ta");E(this,"input");E(this,"_variables");E(this,"_cacheData");E(this,"_options");E(this,"_errorListener");E(this,"_plots");E(this,"_plotshapes");E(this,"_plotbars");E(this,"_plotchars");E(this,"_plotarrows");E(this,"_plotcandles");E(this,"_alerts");E(this,"_bgColors");E(this,"_hlines");E(this,"_fills");E(this,"chart");E(this,"line");E(this,"label");E(this,"polyline");E(this,"box");E(this,"table");E(this,"linefill");E(this,"log");E(this,"runtime");E(this,"strategy");E(this,"request");E(this,"syminfo");E(this,"_count",0);var n;const o=((n=e.toString().split(".")[1])==null?void 0:n.length)||5;this._variables=t,this._errorListener=new pm,this.array=new $4(this._errorListener),this.math=new U4(o),this.color=new A6,this.str=new f_(this._errorListener,o),this.map=new l_(this._errorListener),this.timeframe=new A_(t),this.matrix=new u_(this._errorListener),this.ta=new a6(t,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 u6(t,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 q_(t)},this.line=new P_(t,this._errorListener),this.label=new d_(t,this._errorListener),this.polyline=new I_(t,this._errorListener),this.box=new $_(t,this._errorListener),this.table=new U_(t,this._errorListener),this.linefill=new k_(t),this.log=new nm(t,this.str),this.runtime=new bm(this._errorListener),this.strategy=new rm(this._variables,this._options,e,this._errorListener,r),this.request=new Mm(this._variables,r,this,this._errorListener),this.syminfo=new om}get errors(){return this._errorListener.errors}get scriptType(){return this._options.scriptType}clearErrors(){this._errorListener.clear()}addErrors(e,t){this._errorListener.setErrors(e,t)}options(e,t){if(!t)return e.length?this._getDataOfBarindex(e):this._options;const r=this.input.getInputs(),o=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let b;if(n.length){b={};for(const _ of n)b[_]=[...this._bgColors[_].values()]}const z=this._hlines.size?[...this._hlines.values()]:void 0,i=this._fills.size?[...this._fills.values()]:void 0,s=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 a=this._plots.size>0?[...this._plots.values()]:void 0,O=this._plotbars.size>0?[...this._plotbars.values()]:void 0,u=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,l=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,d=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,A=this._plotchars.size>0?[...this._plotchars.values()]:void 0,h=this._getDraws(),q=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{inputs:r,plots:a,draws:h,alerts:o,colors:b,hlines:z,fills:i,logs:s,plotshapes:u,plotarrows:l,plotcandles:d,plotchars:A,plotbars:O,isUseBgColor:q})}_getDataOfBarindex(e){const t=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let o;if(r.length){o={};for(const q of r)o[q]=[...this._bgColors[q].values()].map(_=>{const m=[];for(const L of e){const g=_.data[L];g&&m.push(g)}return _.data=m,_})}const n=this._hlines.size?[...this._hlines.values()]:void 0,b=this._fills.size?this._getDataFromBarindex(e,[...this._fills.values()]):void 0,z=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 i=this._getDataFromBarindex(e,[...this._plots.values()]),s=this._plotbars.size>0?this._getDataFromBarindex(e,[...this._plotbars.values()]):void 0,a=this._plotarrows.size>0?this._getDataFromBarindex(e,[...this._plotarrows.values()]):void 0,O=this._plotcandles.size>0?this._getDataFromBarindex(e,[...this._plotcandles.values()]):void 0,u=this._plotchars.size>0?this._getDataFromBarindex(e,[...this._plotchars.values()]):void 0,l=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,d=this._getDrawDeletes(e),A=this._getDrawsFromBarindex(e,d),h=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{plots:i,plotarrows:a,plotcandles:O,plotchars:u,plotbars:s,draws:A,drawDeletes:d,alerts:t,colors:o,hlines:n,fills:b,logs:z,plotshapes:l,isUseBgColor:h})}_getDataFromBarindex(e,t){return t.map(r=>{const o=[];for(const n of e){const b=r.data[n];b&&o.push(b)}return r.data=o,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:o,polyline:n,label:b}=this._variables,z={};return e.size&&(z.lines=e.data),t.size&&(z.linefills=t.data),r.size&&(z.tables=r.data),o.size&&(z.boxes=o.data),n.size&&(z.polylines=n.data),b.size&&(z.labels=b.data),Object.keys(z).length?z:void 0}_getDrawsFromBarindex(e,t){const{line:r,linefill:o,table:n,box:b,polyline:z,label:i}=this._variables,s={};if(r.size){s.lines=r.getValOfBarIndex(e)||[];const a=t.lines;this._filterDelIds(a,s.lines)}if(o.size){s.linefills=o.getValOfBarIndex(e);const a=t.linefills;this._filterDelIds(a,s.linefills)}if(n.size){s.tables=n.getValOfBarIndex(e);const a=t.tables;this._filterDelIds(a,s.tables)}if(b.size){s.boxes=b.getValOfBarIndex(e);const a=t.boxes;this._filterDelIds(a,s.boxes)}if(z.size){s.polylines=z.getValOfBarIndex(e);const a=t.polylines;this._filterDelIds(a,s.polylines)}if(i.size){s.labels=i.getValOfBarIndex(e);const a=t.labels;this._filterDelIds(a,s.labels)}return Object.keys(s).length?s:void 0}_filterDelIds(e,t){if(e)for(const r of t){const o=e.findIndex(n=>n===r.id);o!==-1&&e.splice(o,1)}}_getDrawDeletes(e){const{line:t,linefill:r,table:o,box:n,polyline:b,label:z}=this._variables,i={},s=t.getDeleteIds(e),a=r.getDeleteIds(e),O=o.getDeleteIds(e),u=n.getDeleteIds(e),l=b.getDeleteIds(e),d=z.getDeleteIds(e);return s.length&&(i.lines=s),a.length&&(i.linefills=a),O.length&&(i.tables=O),u.length&&(i.boxes=u),l.length&&(i.polylines=l),d.length&&(i.labels=d),i}updateOptions(e){var o;const{inputs:t,strategy:r}=e;this.input.update(t),r&&((o=this.strategy)==null||o.updateOptions(r))}update(e){const{barIndex:t}=e;this.strategy.update(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:o}=e;r.test(o)?(Bu.includes(o)||yu.includes(o))&&this._errorListener.addError(r2(l1.libraryTitleIsKeywordErr,{name:o}),t,$0.Error):this._errorListener.addError(l1.libraryTitleErr,t,$0.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r,max_bars_back:o=0}=e;this._variables.max_bars_back=o,this._paramVerfiy(r,t,"indicator",[O1.inherit,O1.percent,O1.price,O1.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,o,n="format"){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_lineWidthVerify(e,t){const{linewidth:r=1}=e;r<1&&(this._errorListener.addError(vu.lineWidthWarning,t,$0.Warning),e.linewidth=1)}plot(e,t){const r=["color"];S1(e,r);const{series:o,color:n,...b}=e,{bar_index:z,time:i}=this._variables,s=`plot_${t}`,a=this._plots.get(s),O=(a==null?void 0:a.data)||[],u=o!==void 0&&isNaN(o)?void 0:o;if(O[z]={value:[i,u],barIndex:z,itemStyle:{color:n}},this._seriesColorHandle(e,r,a),!a){this._count++,this._lineWidthVerify(b,t),this._paramVerfiy(e.format,t,"plot",[O1.percent,O1.price,O1.volume]);const l=n?[n]:void 0;this._plots.set(s,{editable:!0,...b,colors:l,data:O,id:s,zIndex:this._count})}return{type:"plot",offset:e.offset||0,key:s}}plotbar(e,t){const r=["color"];S1(e,r);const{open:o,close:n,low:b,high:z,color:i,...s}=e,{bar_index:a,time:O}=this._variables,u=`plotbar_${t}`,l=this._plotbars.get(u),d=(l==null?void 0:l.data)||[],A=n!==void 0&&isNaN(n)?void 0:n,h=o!==void 0&&isNaN(o)?void 0:o,q=b!==void 0&&isNaN(b)?void 0:b,_=z!==void 0&&isNaN(z)?void 0:z,m=[O,h,A,q,_];if(d[a]={value:m,barIndex:a,itemStyle:{color:i}},this._seriesColorHandle(e,r,l),!l){this._count++,this._paramVerfiy(e.format,t,"plotbar",[O1.percent,O1.price,O1.volume]);const L=i?[i]:void 0;this._plotbars.set(u,{editable:!0,...s,colors:L,data:d,id:u,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:o,format:n,location:b,style:z}=e;this._paramVerfiy(z,r,t,Object.values(X2),"style"),this._paramVerfiy(b,r,t,Object.values(ke),"location"),this._paramVerfiy(o,r,t,Object.values(L2),"size"),this._paramVerfiy(n,r,t,[O1.percent,O1.price,O1.volume],"format")}plotchar(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,high:O,low:u}=this._variables,l=`plotchar_${t}`,d=this._plotchars.get(l),A=(d==null?void 0:d.data)||[],h={value:[a,o],barIndex:s,itemStyle:{color:n,textcolor:b},low:u,high:O};A[s]=h,this._seriesColorHandle(e,r,d),d||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(l,{editable:!0,...i,location:z,data:A,id:l,zIndex:this._count}))}plotarrow(e,t){const r=["colorup","colordown"];S1(e,r);const{series:o,colorup:n,colordown:b,...z}=e,{bar_index:i,time:s,low:a,high:O}=this._variables,u=`plotarrow_${t}`,l=this._plotarrows.get(u),d=(l==null?void 0:l.data)||[];d[i]={value:[s,o!==void 0&&isNaN(o)?void 0:o],barIndex:i,itemStyle:{colorup:n,colordown:b},low:a,high:O},this._seriesColorHandle(e,r,l),l||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[O1.percent,O1.price,O1.volume]),this._plotarrows.set(u,{editable:!0,...z,data:d,id:u,zIndex:this._count}))}plotshape(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,low:O,high:u}=this._variables,l=`plotshape_${t}`,d=this._plotshapes.get(l),A=(d==null?void 0:d.data)||[],h={value:o,barIndex:s,color:n,textcolor:b,time:a,low:O,high:u};if(A[s]=h,this._seriesColorHandle(e,r,d),!d){this._count++;const q=n?[n]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(l,{editable:!0,...i,data:A,location:z,id:l,colors:q,zIndex:this._count})}}plotcandle(e,t){const r=["wickcolor","bordercolor","color"];S1(e,r);const{wickcolor:o,bordercolor:n,color:b,close:z,open:i,low:s,high:a,...O}=e,{bar_index:u,time:l}=this._variables,d=`plotcandle_${t}`,A=this._plotcandles.get(d),h=(A==null?void 0:A.data)||[],q=z!==void 0&&isNaN(z)?void 0:z,_=i!==void 0&&isNaN(i)?void 0:i,m=s!==void 0&&isNaN(s)?void 0:s,L=a!==void 0&&isNaN(a)?void 0:a,g=[l,_,q,m,L];h[u]={value:g,barIndex:u,wickcolor:o,bordercolor:n,color:b},this._seriesColorHandle(e,r,A),A||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[O1.percent,O1.price,O1.volume]),this._plotcandles.set(d,{editable:!0,...O,data:h,id:d,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;S1(e,["color"]),this._verifyDisplay(e.display,"hline",t);const n=e.display&&!e.display.length?A2.none:A2.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(e,t),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:n,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var X,T,N,D,C,P,H,G;const r=["color","top_color","bottom_color"];S1(e,r);const{color:o,top_color:n,bottom_color:b,seriesColors:z,hline1:i,hline2:s,plot1:a,plot2:O,top_value:u,bottom_value:l,...d}=e,{bar_index:A,time:h}=this._variables,q=`fill_${t}`,_=this._fills.get(q),m=(_==null?void 0:_.data)||[];this._verifyDisplay(e.display,"fill",t);const L=e.display&&!e.display.length?A2.none:A2.all;let g,v,y="plot";if(i&&s)g=(X=this._hlines.get(i==null?void 0:i.key))==null?void 0:X.price,v=(T=this._hlines.get(s==null?void 0:s.key))==null?void 0:T.price,y="hline";else{const k=this._plots.get(a==null?void 0:a.key),J=this._plots.get(O==null?void 0:O.key),o0=(k==null?void 0:k.data)||[],z0=(J==null?void 0:J.data)||[];if(g=(D=(N=o0[A])==null?void 0:N.value)==null?void 0:D[1],v=(P=(C=z0[A])==null?void 0:C.value)==null?void 0:P[1],!A){const a0=(k==null?void 0:k.force_overlay)&&(J==null?void 0:J.force_overlay);(k!=null&&k.force_overlay||J!=null&&J.force_overlay)&&!a0?this._errorListener.addError(l1.plotFillForceOverlayErr,t,$0.Error):d.force_overlay=a0}}if(m[A]={time:h,color:o,top_color:n,bottom_color:b,barIndex:A,plot1:g,plot2:v,top_value:u,bottom_value:l},this._seriesColorHandle(e,r,_),!_){this._count++;const k=((H=this._options.indicator)==null?void 0:H.explicit_plot_zorder)||((G=this._options.strategy)==null?void 0:G.explicit_plot_zorder),J=o?[o]:void 0,o0=n?[n]:void 0,z0=b?[b]:void 0;this._fills.set(q,{id:q,colors:J,top_colors:o0,bottom_colors:z0,display:L,data:m,type:y,editable:!0,fillgaps:!1,hline1:i,hline2:s,plot1:a,plot2:O,...d,zIndex:k?this._count:void 0})}}alert({message:e,freq:t=Ae.freqOncePerBar},r){const{bar_index:o,_isRealTimeBar:n,last_bar_index:b}=this._variables,z=`alert_${r}`,i=this._cacheData[z]||{},s=i.barIndex;if(this._paramVerfiy(t,r,"alert",[Ae.freqAll,Ae.freqOncePerBar,Ae.freqOncePerBarClose]),t===Ae.freqOncePerBar&&o===s){this._alerts.delete(z);return}this._cacheData[z]=i;const a={message:e,freq:t,id:z,type:"alert"};if(n){t!==Ae.freqOncePerBarClose&&this._alerts.set(z,a),i.barIndex=o;return}if(!n&&t===Ae.freqOncePerBarClose&&o===s&&b===o-1){this._alerts.set(z,a),i.barIndex=o;return}this._alerts.delete(z)}alertcondition({condition:e,message:t,title:r},o){const{_isRealTimeBar:n}=this._variables,b=`alertcondition_${o}`;n&&e?this._alerts.set(b,{message:t,title:r,id:b,type:"alertcondition"}):this._alerts.delete(b)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=X3.all,t,r){e.length&&e.length<4&&this._errorListener.addError(r2(l1.displayErr,{func:t,values:"[display.none, display.all]"}),r,$0.Error)}_setColors(e,t,r){S1(e,["color"]);const{color:n,...b}=e;this._verifyDisplay(b.display,t,r);const z=e.display&&!e.display.length?A2.none:A2.all,{bar_index:i,time:s}=this._variables,a=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const O=this._bgColors[t].get(a),u=(O==null?void 0:O.data)||[],l=(O==null?void 0:O.setColors)||[];n&&!l.includes(n)&&l.push(n),u[i]={color:n,time:s,barIndex:i},O||this._bgColors[t].set(a,{...b,display:z,data:u,setColors:l,id:a})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return!!(e===void 0||typeof e=="number"&&isNaN(e))}fixnan({source:e},t){return e===void 0||typeof e=="number"&&isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!(typeof e=="number"&&isNaN(e))?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o)}time_close({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o,!0)}timestamp(e){const{dateString:t,timezone:r,year:o,month:n,day:b,hour:z=0,minute:i=0,second:s=0}=e;if(t)return D1(t).utc(!/GMT|UTC/.test(t)).valueOf();let a=n-1,O=o;if(a<0){const u=Math.ceil(Math.abs(a/12));a=12*u+a,O=o-u}return $2({year:O,month:a,day:b,hour:z,minute:i,second:s},r).valueOf()}weekofyear({time:e,timezone:t}){return $2(e,t).week()}year({time:e,timezone:t}){return $2(e,t).year()}second({time:e,timezone:t}){return $2(e,t).second()}month({time:e,timezone:t}){return $2(e,t).month()+1}minute({time:e,timezone:t}){return $2(e,t).minute()}hour({time:e,timezone:t}){return $2(e,t).hour()}dayofweek({time:e,timezone:t}){return $2(e,t).day()+1}dayofmonth({time:e,timezone:t}){return $2(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,this._variables.timeframe.period),o=N2(t,e)*1e3;return e-r-Math.floor((e-r)/o)*o}_timeHandle(e,t,r="",o,n,b=0,z=!1){const i=r||this._variables.__period,s=N2(i,e),a=N2(this._variables.__period,e);let O;if(s<=a)O=e,z&&(O+=a*1e3);else{const u=`time_${t}`,l=this._cacheData[u];if(l)l.currentTime+s*1e3-l.offset<=e?(O=e,this._cacheData[u]={currentTime:e,offset:0}):O=l.currentTime;else{const d=this._calcTimeOffset(e,i);this._cacheData[u]={currentTime:e,offset:d},O=e}z&&(O+=s*1e3)}if(o&&o!==ut.regular&&o!==ut.extended){const{timePeriods:u,weeks:l}=this._parserSession(o,t),d=$2(e,n),A=d.format("YYYY-MM-DD HH:mm"),h=d.format("YYYY-MM-DD"),q=O,_=$2(O,n).format("YYYY-MM-DD HH:mm");O=void 0;for(const L of u){const[g,v]=L;let y;if((g===v||Number(g==null?void 0:g.replace(":",""))>Number(v==null?void 0:v.replace(":","")))&&(y=d.add(1,"day").format("YYYY-MM-DD")),D1(A).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")){D1(_).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")?O=q:O=$2(`${h} ${g}`,n).valueOf();break}}const m=this._variables.dayofweek;O&&!l.includes(m)&&(O=void 0)}return O&&O-b*a*1e3}_seriesColorHandle(e,t,r){var o;if(r&&t!=null&&t.length)for(const n of t){if((o=r.gradientColorKeys)!=null&&o.includes(n))continue;const b=e[n];if(!b)continue;const z=r[`${n}s`]||[];z.includes(b)||(z.push(b),r[`${n}s`]=z,z.length>5&&(r[`${n}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(n)))}}_parserSession(e,t){const r=e.split(":"),o=r[0],b=(r[1]||"1234567").split("").map(i=>{const s=parseInt(i,10);if(s<1||s>7){this._errorListener.addError(`Invalid day of week: ${i}`,t,$0.Error);return}return s});return{timePeriods:o.split(",").map(i=>{i===""||i===ut.regular?i="0930-1500":i===ut.extended&&(i="1500-1830");const s=i.split("-");return s.length!==2?[]:[this._processTime(s[0],t),this._processTime(s[1],t)]}),weeks:b}}_processTime(e,t){const r=e.slice(0,2),o=e.slice(2),n=parseInt(r,10),b=parseInt(o,10);if(!(n>=0&&n<=23)&&b>=0&&b<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",t,$0.Error);return}return`${r}:${o}`}}let Mm=class{constructor(e,t,r,o){E(this,"_variables");E(this,"_scriptId");E(this,"_cacheData");E(this,"_funcs");E(this,"_errorListener");this._variables=e,this._scriptId=t,this._cacheData=new Map,this._funcs=r,this._errorListener=o}security(e,t){var d;const r=self.workerStorage.get(`request_${this._scriptId}`),{__requestName:o,__period:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||n;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${o}${t}_${s}`,O=this._getRequestData(e,a);if(r!=null&&r.has(a))return(d=O==null?void 0:O.result)==null?void 0:d[a];const u=this._parseExprCode(e),l=this._runScriptHandle(u,a,i,O,!0);return r==null||r.set(a,{id:a,isRun:!1,strJs:u,dataId:s,interval:z,symbol:b,paramsExpr:i}),l}security_lower_tf(e,t){const r=self.workerStorage.get(`request_${this._scriptId}`),{__period:o,__requestName:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||o;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${n}${t}_${s}`,O=r==null?void 0:r.get(a),u=this._getRequestLowerTfData(e,t,a,O==null?void 0:O.defaultResult),l=new n1(0,void 0,this._errorListener);if(O!=null&&O.strJs)return O!=null&&O.defaultResult?u!=null&&u.length?u.map(q=>{const _=new n1(0,void 0,this._errorListener);return _._value=q,_}):O==null?void 0:O.defaultResult:u&&(l._value=u,l);const d=this._parseExprCode(e),A={id:a,strJs:d,isRun:!1,dataId:s,interval:z,symbol:b,paramsExpr:i,defaultResult:void 0};r==null||r.set(a,A);const h=this._runScriptHandle(d,a,i,u,!0);return Array.isArray(h)?(A.defaultResult=h.map(()=>new n1(0,void 0,this._errorListener)),A.defaultResult):l}_symbolTransform(e){if(!e)return this._variables.syminfo.tickerid;let[t,r]=e.split(":");return r?t=Du[t]||t:(t="FX",r=t),`${t}:${r}`}_runScriptHandle(e,t,r,o,n){const{result:b,logs:z,errors:i}=this._runScripts(e,t,n,r,o);return this._funcs.log.mergeLogs(z),this._funcs.addErrors(i,t),b}_getCurrentData(e){let{symbol:t,timeframe:r}=e;const{__period:o,syminfo:{ticker:n,tickerid:b}}=this._variables;if(r=hr(r),(o===r||r==="")&&(t===n||t===b||!t)){const{close:z,open:i,high:s,low:a,bar_index:O,last_bar_index:u,last_bar_time:l,_isRealTimeBar:d,volume:A,time:h,time_tradingday:q,mintick:_,nextBarTime:m}=this._variables;return{barIndex:O,c:z,o:i,h:s,l:a,volume:A,lastBarIndex:u,lastBarTime:l/1e3,nextBarTime:m?m/1e3:void 0,isrealtime:d,time_tradingday:q,time:h/1e3,interval:o,mintick:_}}}_parseExprCode(e){let{expression:t,paramsExpr:r=[]}=e,o=[];t=cc(t);const n=JSON.parse(t),b=n.pop();let z=(b==null?void 0:b.memberCodes)||{},i=(b==null?void 0:b.depends)||[];if(!i.length)return`return ${b==null?void 0:b.code}`;let s=[],a=[],O=[];if(this._getDependCodes(i,n,o,s,a,O),this._getStmtFuncs(o,n,O,s,a),a.length){const h=r.length;for(let q=h-1;q>=0;q--){const _=r[q];let m=JSON.parse(cc(_));const L=[];m=m.map(y=>{const{scope:X,code:T,varNames:N,dependSelf:D}=y;return X===2&&!L.includes(N)&&!D&&(y.code=`let ${T}`),N&&L.push(...N.split(", ")),y.memberCodes&&Object.assign(z,{...y.memberCodes}),y});const g=[];let v=a.map(y=>({...y,isArg:!1,isPreArg:!0}));a=[],this._getDependCodes(v,m,o,s,a,g),this._getStmtFuncs(o,m,g,s,a)}}const u=o.filter(h=>!!h).map((h,q)=>{let _=h.join(`
|
77
77
|
`);return q===0&&(_=`${_}
|
78
78
|
${s.join(`
|
79
79
|
`)}`),_});let l=u.join(`
|
@@ -82,7 +82,7 @@ ${O.join(`
|
|
82
82
|
`)}
|
83
83
|
return ${b==null?void 0:b.code}`;d>1;)l=`${l}}`,d--;const A=[];for(const h of Object.keys(z))l.includes(`$_var.getCacheData("${h}"`)&&A.push(z[h]);return A.length&&(l=`${A.join(`
|
84
84
|
`)}
|
85
|
-
${l}`),l}_getRequestLowerTfData(e,t,r,o){var L;let{symbol:n,timeframe:b,calc_bars_count:z,ignore_invalid_symbol:i,ignore_invalid_timeframe:s}=e;const{__period:a,time:O,_isRealTimeBar:u}=this._variables;b=hr(b);let l=N2(b,O)*1e3;const d=N2(a,O)*1e3;if(l>d)return!s&&this._errorListener.addError(r2(l1.requestLowerTfPeriodErr,{period:b}),t,$0.Error,25),[];const A=`${n}--${b}`,h=self.workerStorage.get(`request_${this._scriptId}_data`),q=self.workerStorage.get(`request_${this._scriptId}_list`),_=self.workerStorage.get(`request_${this._scriptId}_tmp`),m={id:A,calc_bars_count:z,ignore_invalid_symbol:i,symbol:n,originTimeframe:b,timeframe:ii[b]||ic(b)};if(h!=null&&h.has(A)){_==null||_.delete(A);const{index:g=0,periodStamp:v=d}=this._cacheData.get(r)||{},y=h==null?void 0:h.get(A);if(!y.length)return[];if(y.length-1<0)return[];const T=y.slice(g);let N=O,D=v+N;const C=[];for(const[P,H]of T.entries()){let{time:G}=H;G=G*1e3;let k=g+P;if(G>=D)return!u&&this._cacheData.set(r,{index:k,periodStamp:v}),C;if(N<=G&&G<D){const J=(L=H==null?void 0:H.result)==null?void 0:L[r];if(Array.isArray(J))for(const[o0,z0]of J.entries())C[o0]||(C[o0]=[]),C[o0].push(z0);else o||C.push(J)}}return!u&&this._cacheData.set(r,{index:y.length,periodStamp:v}),C}else(q==null?void 0:q.get(A))||_==null||_.set(A,m);q==null||q.set(A,m)}_getRequestData(e,t){var _,m,L,g,v;let{symbol:r,timeframe:o,calc_bars_count:n,gaps:b,lookahead:z,ignore_invalid_symbol:i}=e;const{__period:s,mintick:a,time:O,nextBarTime:u}=this._variables;o=hr(o),r=r;const l=`${r}--${o}`,d=self.workerStorage.get(`request_${this._scriptId}_data`),A=self.workerStorage.get(`request_${this._scriptId}_list`),h=self.workerStorage.get(`request_${this._scriptId}_tmp`),q={id:l,calc_bars_count:n,ignore_invalid_symbol:i,symbol:r,originTimeframe:o,timeframe:ii[o]||ic(o)};if(d!=null&&d.has(l)){let y=N2(o,O)*1e3;const X=N2(s,O)*1e3;h==null||h.delete(l);const{index:T=0,periodStamp:N=X}=this._cacheData.get(t)||{},D=d==null?void 0:d.get(l);if(!D.length)return;const C=D.slice(T);let P=O,H=N+P;const G=D.length-1;if(G<0)return;const k={lastBarIndex:D[G].barindex||G,lastBarTime:D[G].time,interval:o,mintick:a};if(y>N){let J;if(z===Pe.lookaheadOn?J=this._lookaheadOnHandle(C,o,H,y,k,T,N,t,P,b):J=this._lookaheadOffHandle(C,o,H,y,k,T,N,t,P,u||H,b),J)return J;if(J===null)return}else if(z===Pe.lookaheadOn)for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((_=C[J+1])==null?void 0:_.time)*1e3||z0+y;let w0=T+J;if(z0>=H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<=P&&v0>P){const u0=T+J;return this._cacheData.set(t,{index:u0,periodStamp:N}),{...o0,barIndex:a0||u0,nextBarTime:(m=C[J+1])==null?void 0:m.time,...k}}}else for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((L=C[J+1])==null?void 0:L.time)*1e3||z0+y;let w0=T+J;if(z0>H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<H&&H<=v0)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(g=C[J+1])==null?void 0:g.time,...k};if(z0>=P&&z0<=H&&(a0||w0)===k.lastBarIndex)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(v=C[J+1])==null?void 0:v.time,...k}}this._cacheData.set(t,{index:D.length,periodStamp:N});return}else(A==null?void 0:A.get(l))||h==null||h.set(l,q);A==null||A.set(l,q)}_lookaheadOnHandle(e,t,r,o,n,b,z,i,s,a){var O;for(const[u,l]of e.entries()){let{time:d,barindex:A}=l;d=d*1e3,t.includes("M")&&(o=N2(t,d)*1e3-(D1(d).date()-1)*864e5);const h=d,q=o+h;let _=b+u;if(r<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),null;let m={...l,barIndex:A||_,nextBarTime:(O=e[u+1])==null?void 0:O.time,...n};if(a===Pe.gapsOn){if(r>h&&s<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}else{if(r>q)continue;if(r>h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}}}_lookaheadOffHandle(e,t,r,o,n,b,z,i,s,a,O){var u,l;for(const[d,A]of e.entries()){let{time:h,barindex:q}=A;h=h*1e3,t.includes("M")&&(o=N2(t,h)*1e3-(D1(h).date()-1)*864e5);const _=h,m=o+_,L=b+d;if(r<_)return this._cacheData.set(i,{index:L,periodStamp:z}),null;const g={...A,barIndex:q||L,nextBarTime:(u=e[d+1])==null?void 0:u.time,...n};if(r>=m&&s<m||r<m&&a>=m)return O===Pe.gapsOn?(this._cacheData.set(i,{index:L,periodStamp:z}),g):(this._cacheData.set(i,{index:L,data:g,periodStamp:z}),g);if(!(s>m)&&s>=_){let v=(l=this._cacheData.get(i))==null?void 0:l.data;if(!v){const y=e[L-1];if(!y)return null;v={...y,barIndex:y.barindex||L-1,nextBarTime:g.time,...n},this._cacheData.set(i,{index:L,data:v,periodStamp:z})}return v}}}_getDependCodes(e,t,r,o,n,b){for(const z of e){if(!z.isArg){const i=t.filter(a=>{var O;return(O=a==null?void 0:a.depends)==null?void 0:O.some(u=>u.name===z.name&&u.scope===z.scope&&u.isAgainAssign!==!1)});for(const a of i){const{code:O,depends:u,scope:l,funcName:d}=a;r[l]=r[l]||[];const A=r[l];let h=l===0&&d;if(!A.includes(O)){if(h){if(o.includes(O))continue;o.unshift(O)}else A.unshift(O);if(u!=null&&u.length){for(const q of u)q.memberCode&&!h&&b.push(q.memberCode);this._getDependCodes(u,t,r,o,n,b)}}}const s=t.find(a=>{var O;return((O=a.varNames)==null?void 0:O.split(", ").includes(z.name))&&(!z.isPreArg||z.isPreArg&&a.methodName===z.functionName)||a.funcName===z.name});if(s){const{code:a,depends:O,scope:u}=s;r[u]=r[u]||[];const l=r[u],d=l.findIndex(A=>A===a);if(d!==-1){if(z.isFunc)continue;l.splice(d,1)}if(l.unshift(a),O!=null&&O.length){for(const A of O)A.memberCode&&b.push(A.memberCode);this._getDependCodes(O,t,r,o,n,b)}continue}}n.some(i=>i.name===z.name)||n.push(z)}}_getStmtFuncs(e,t,r,o,n){const b=t.filter(z=>z.isStmtFunc);for(const z of b){const{code:i,depends:s,scope:a=0}=z;e[a]=e[a]||[];const O=e[a];if(!O.includes(i)&&(O.push(i),s!=null&&s.length)){for(const u of s)u.memberCode&&r.push(u.memberCode);this._getDependCodes(s.filter(u=>!(u.isFunc&&i.startsWith(u.name))),t,e,o,n,r)}}}runScripts(e,t,r,o,n,b){var u;const z=`${this._scriptId}_${t}`;let{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O}=self.workerStorage.get(z)||{};if(r&&(i=new qp(z),s=new fp,a=new lp(this._variables.mintick||1e-5,i,this._scriptId),O=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e),i.__requestName=t,self.workerStorage.set(z,{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O})),o&&o.length){const l=o.length-1,{interval:d,symbol:A=""}=n,{mintick:h,syminfo:q}=this._variables,[_,m]=A.split(":");i.updateOptions({interval:d,mintick:h,syminfo:{...q.__syminfo,tickerid:A||q.tickerid,ticker:m||_||q.ticker}});for(const[v,y]of o.entries()){const{barindex:X}=y,T=Object.assign(y,{barIndex:X||v,lastBarIndex:o[l].barindex||l,lastBarTime:o[l].time,nextBarTime:(u=o[v+1])==null?void 0:u.time});if(i.updateData(T),a.update({barIndex:(T==null?void 0:T.barindex)||0}),y.result=Object.assign(y.result||{},{[t]:O(i,s,a,b||[],t)}),a.endExecution(),a.errors.length&&a.errors.some(N=>N.type===$0.Error))return{logs:[],errors:a.errors}}const L=a.log.logs,g=a.errors;return a.log.clearLogs(),a.clearErrors(),{logs:L,errors:g}}}_runScripts(e,t,r,o,n){const b=`${this._scriptId}_${t}`;let{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a}=self.workerStorage.get(b)||{};const{interval:O,...u}=n||{};if(r){z=new qp(b),i=new fp,s=new lp(this._variables.mintick||1e-5,z,this._scriptId),a=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e);const{mintick:h,syminfo:q}=this._variables;z.updateOptions({interval:O,mintick:h||1e-5,syminfo:{...q.__syminfo}}),z.__requestName=t,self.workerStorage.set(b,{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a})}z.updateData(u),s.update({barIndex:(u==null?void 0:u.barindex)||0});const l=a(z,i,s,o||[],t),d=s.log.logs,A=s.errors;return s.log.clearLogs(),s.clearErrors(),s.endExecution(),{result:l,logs:d,errors:A}}},om=class{constructor(){}prefix(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[0])||""}ticker(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[1])||""}};class nm{constructor(e,t){E(this,"_logs");E(this,"_variables");E(this,"_str");E(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=e,this._logs=[],this._str=t}get logs(){return this._logs}clearLogForIndex(e){this._logs=this._logs.filter(t=>t.barIndex!==e)}clearLogs(){this._logs=[]}info(e,t,r){this._addLog(e,t,"info",r)}error(e,t,r){this._addLog(e,t,"error",r)}warning(e,t,r){this._addLog(e,t,"warning",r)}mergeLogs(e){this._logs=this._logs.concat(e)}_addLog(e,t,r,o){if(typeof t=="string"&&(o=t),o.startsWith("export"))return;const{message:n,formatString:b}=e,{time:z,bar_index:i,_isRealTimeBar:s,__isReqRepeated:a}=this._variables;let O=n;b&&Array.isArray(t)&&t.length&&(t=t.map(A=>(typeof A=="object"&&(A.isArray?A=JSON.stringify(A._value):A=A.toString()),A!==void 0?A:"na")),O=this._str.strformat({formatString:b},t,!0));const{isrealtime:u,barIndex:l}=this._preBar;i!==l&&(this._preBar={barIndex:i,isrealtime:s});const d=Date.now();O!==void 0&&this._logs.push({message:`[${D1(u&&!a?d:z).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${O}`,time:z,id:I4(6),barIndex:i,type:r})}}class bm{constructor(e){E(this,"_errorListener");this._errorListener=e}error({message:e},t){t.startsWith("export")||this._errorListener.addError(e,t,$0.Error)}}class pm{constructor(){E(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return D2.flatMap([...this._errors.values()])}setErrors(e,t){this._errors.set(t,e)}addError(e,t,r,o=0){const[n,b]=t.split("_").slice(-2),z=this._errors.get(t),i={message:e,endLineNumber:Number(n),startColumn:Number(b)+1,endColumn:Number(b)+o+1,startLineNumber:Number(n),type:r};z?z.push(i):this._errors.set(t,[i])}}class zm{constructor(){E(this,"_isMarketOpen");E(this,"_currentBarIndex");E(this,"_totalBarIndex");E(this,"_isRealTimeBar");E(this,"_preBarIndex");E(this,"_preIsRealTimeBar");E(this,"_isFirstRun",!1);this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0,this._preIsRealTimeBar=!1}update(e,t,r,o){this._preBarIndex=this._currentBarIndex,this._preIsRealTimeBar=this._isRealTimeBar,this._currentBarIndex=e,this._totalBarIndex=t,this._isRealTimeBar=r,this._isMarketOpen=o}set isFirstRun(e){this._isFirstRun=e}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex||!this._isFirstRun}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar||this._isFirstRun}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1&&!this._preIsRealTimeBar||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class im{constructor(e){E(this,"_variables");this._variables=e}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{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class cm{constructor(e){E(this,"_orders");E(this,"_historyOrders");E(this,"_options");E(this,"_max_contracts_held_all",0);E(this,"_max_contracts_held_long",0);E(this,"_max_contracts_held_short",0);E(this,"_max_drawdown",0);E(this,"_max_runup",0);E(this,"_max_runup_percent",0);E(this,"_max_drawdown_percent",0);E(this,"_variables");E(this,"_netprofit",0);E(this,"_eventrades",0);E(this,"_avg_trade_percent");E(this,"_avg_losing_trade_percent");E(this,"_avg_winning_trade_percent");E(this,"_closedtrades",0);E(this,"_losstrades",0);E(this,"_grossloss",0);E(this,"_grossprofit",0);E(this,"_wintrades",0);E(this,"_opentrades_capital_held",0);E(this,"_position_avg_price",0);E(this,"_position_size",0);E(this,"_openprofit",0);E(this,"_preMaxNetValue",0);E(this,"_preMinNetValue",0);E(this,"marginCallLong",0);E(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=e}update(e){this._calcMaxDrawdownAndMaxRunup(e)}_calcMaxDrawdownAndMaxRunup(e){if(!this._orders.length&&!this._historyOrders.length)return;let t=0,r=0;const{high:o,low:n,close:b}=e;let z=0;for(const[a,O]of this._orders.entries()){const{in_price:u,qty:l=0,direction:d,commission:A,original_qty:h=1}=O,q=d===i1.long?1:-1,_=(o-u)*l,m=(n-u)*l,L=q===1?_:-m,g=q===1?-m:_;z+=(b-u)*q*l,t+=g,a>0&&A&&(r-=A*l/h),r+=L}this._openprofit=z;const i=this.initial_capital,s=i+this._netprofit;this._preMinNetValue=this._preMinNetValue||i,this._preMaxNetValue=this._preMaxNetValue||i,t=this._preMaxNetValue-s+Math.max(t,0),r=s-this._preMinNetValue+r,this._max_drawdown<t&&(this._max_drawdown=t,this._max_drawdown_percent=t/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(e){this._orders=e,this._calcMaxContracts()}_calcMaxContracts(){const e=this._orders.length;if(!e){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[t,r,o,n,b,z,i]=this._orders.reduce(([s,a,O,u,l,d,A],h)=>{const{direction:q,qty:_=0,in_price:m,commission:L=0}=h;return q===i1.long?(s+=_,a+=_,d+=_):(s+=_,O+=_,d-=_),u+=_*m,l+=m,A+=L,[s,a,O,u,l,d,A]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-i,this._grossloss=i),this._position_size=z,this._position_avg_price=b/e,this._opentrades_capital_held=n,this._max_contracts_held_all=Math.max(t,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(o,this._max_contracts_held_short)}updateHistoryOrders(e){this._historyOrders=e;const t=this._historyOrders.length;this._closedtrades=t;const[r,o,n,b,z,i,s,a]=this._historyOrders.reduce((l,d)=>{let[A,h,q,_,m,L,g,v]=l;const{profit:y=0,profit_percent:X=0}=d;return A+=y,h+=X,y<0?(q+=y,_+=X,g+=1):y>0&&(m+=y,L+=X,v+=1),[A,h,q,_,m,L,g,v]},[0,0,0,0,0,0,0,0]),O=this._orders.reduce((l,d)=>{const{commission:A=0,qty:h=0,original_qty:q=0}=d,_=A*h/q;return l+_},0);this._avg_trade_percent=t?o/t:void 0,this._avg_losing_trade_percent=t?Math.abs(b)/s:void 0,this._avg_winning_trade_percent=t?i/a:void 0,this._netprofit=r-O;const u=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,u),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,u),this._grossloss=Math.abs(n-O),this._grossprofit=z,this._eventrades=t-s-a,this._losstrades=s,this._wintrades=a}updateStrategyOptions(e){this._options=e}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 e=this._losstrades;return e?Math.abs(this._grossloss/e):void 0}get avg_losing_trade_percent(){return this._avg_losing_trade_percent}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 e=this._wintrades;return e?Math.abs(this._grossprofit/e):void 0}get avg_winning_trade_percent(){return this._avg_winning_trade_percent}get initial_capital(){var e;return((e=this._options)==null?void 0:e.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:e,margin_long:t=0,margin_short:r=0,commission_type:o,commission_value:n=0}=this._options,b=this._orders[0].direction===i1.long?1:-1,z=(b===1?t:r)/100;if(z<=0)return;const{close:i}=this._variables,[s,a]=this._orders.reduce((O,u)=>{let[l,d]=O;const{in_price:A,qty:h=0,original_qty:q=0}=u,_=A*h;if(l+=_,n){let m=0;switch(o){case O2.percent:m=(_+h*i)*n/100;break;case O2.cashPerContract:m=h*n*2;break;case O2.cashPerOrder:m=h/q*n+n;break}d+=m}return[l,d]},[0,0]);return(s-(e+this._netprofit-a))*b/this._position_size/(1-b*z)}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(e,t){if(!this._options)return 0;const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}}class sm{constructor(e){E(this,"_preAccdist");E(this,"_preNvi");E(this,"_prePvi");E(this,"_preObv");E(this,"_prePvt");E(this,"_preWad");E(this,"_preVwap");E(this,"_preValue");E(this,"_currentData");E(this,"_preData");E(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=e}update(e){this._preValue={},e.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...e}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:e,low:t,high:r,volume:o}=this._currentData;if(r===t)return this._preAccdist;const n=(e-t-(r-e))/(r-t)*o+this._preAccdist;return!this.isRealTime&&(this._preAccdist=n),this._preValue.accdist=n,n}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:e,low:t,high:r,volume:o}=this._currentData,n=(2*e-r-t)/((r-t)*o);return this._preValue.iii=n,n}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:e,low:t,high:r,volume:o,open:n}=this._currentData,b=(e-n)/(r-t)*o;return this._preValue.wvad=b,b}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const o=Math.sign(e-r)*t+this._preObv;return!this.isRealTime&&(this._preObv=o),this._preValue.obv=o,o}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:e,high:t}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const o=Math.max(t-e,Math.abs(t-r),Math.abs(e-r));return this._preValue.tr=o,o}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const o=(e-r)/r*t+this._prePvt;return!this.isRealTime&&(this._prePvt=o),this._preValue.pvt=o,o}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:e,high:t,low:r}=this._currentData,{close:o}=this._preData;if(o===void 0)return this._preWad=0,0;const n=Math.max(t,o),b=Math.min(r,o),z=e-o,s=(z>0?e-b:z<0?e-n:0)+this._preWad;return!this.isRealTime&&(this._preWad=s),this._preValue.wad=s,s}get vwap(){var a,O;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:e,volume:t}=this._currentData;let{sum:r=0,sumV:o=0,isReset:n}=this._preVwap;if(((O=(a=self.workerStorage)==null?void 0:a.get(this._id))==null?void 0:O.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(n=!0,r=o=0),!n)return;const z=e*t+r,i=t+o;!this.isRealTime&&(this._preVwap={sum:z,sumV:i,isReset:n});const s=z/i;return this._preValue.vwap=s,s}_getNvi(){const e=this._preNvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n<r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._preNvi=b),this._preValue.nvi=b,b}_getPvi(){const e=this._prePvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n>r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._prePvi=b),this._preValue.pvi=b,b}}class Om{constructor(){E(this,"_period");E(this,"_multiplier");E(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(e){if(!e)return;this._period=e;const[t,r]=OM(e);this._multiplier=t,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}}class am{constructor(){E(this,"_bgColor");E(this,"_fgColor");E(this,"isUseBgColor",!1)}updateOptions(e){e!=null&&e.bg_color&&(this._bgColor=e.bg_color,this._fgColor=this._contrastColor(e.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(){}get right_visible_bar_time(){}_parseColor(e){let t,r,o,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),o=parseInt(e.substring(5,7),16);const b=e.substring(7);b?n=parseInt(b,16)/255:n=1}else{const b=this._parserRgbColor(e);t=b[0]||0,r=b[1]||0,o=b[2]||0,n=b[3]||1}return{r:t,g:r,b:o,a:n}}_parserRgbColor(e){var t;return((t=e.match(/\d+/g))==null?void 0:t.map(Number))||[]}_contrastColor(e){const{r:t,g:r,b:o}=this._parseColor(e);return(299*t+587*r+114*o)/1e3>128?"#000000":"#ffffff"}}class um{constructor(){E(this,"_syminfo",{})}update(e){this._syminfo=e}get __syminfo(){return this._syminfo}get basecurrency(){return this._syminfo.basecurrency||""}get country(){return this._syminfo.country}get currency(){return this._syminfo.currency||"USD"}get description(){return this._syminfo.description||""}get employees(){return this._syminfo.employees||100}get expiration_date(){return this._syminfo.expiration_date}get industry(){return this._syminfo.industry}get minmove(){return this._syminfo.minmove&&Number(this._syminfo.minmove)}get mintick(){return this._syminfo.mintick}get pointvalue(){return this._syminfo.pointvalue&&Number(this._syminfo.pointvalue)}get prefix(){return this.tickerid.replace(`:${this.ticker}`,"")}get pricescale(){return this._syminfo.pricescale&&Number(this._syminfo.pricescale)}get recommendations_buy(){return this._syminfo.recommendations_buy}get recommendations_buy_strong(){return this._syminfo.recommendations_buy_strong}get recommendations_date(){return this._syminfo.recommendations_date}get recommendations_hold(){return this._syminfo.recommendations_hold}get recommendations_sell(){return this._syminfo.recommendations_sell}get recommendations_sell_strong(){return this._syminfo.recommendations_sell_strong}get recommendations_total(){return this._syminfo.recommendations_total}get root(){return this._syminfo.root||""}get sector(){return this._syminfo.sector}get session(){return this._syminfo.session||ut.regular}get shareholders(){return this._syminfo.shareholders}get shares_outstanding_float(){return this._syminfo.shares_outstanding_float}get shares_outstanding_total(){return this._syminfo.shares_outstanding_total}get target_price_average(){return this._syminfo.target_price_average}get target_price_date(){return this._syminfo.target_price_date}get target_price_estimates(){return this._syminfo.pricescale}get target_price_high(){return this._syminfo.target_price_high}get target_price_low(){return this._syminfo.target_price_low}get target_price_median(){return this._syminfo.target_price_median}get ticker(){return this._syminfo.ticker||""}get tickerid(){return this._syminfo.tickerid||""}get timezone(){return this._syminfo.timezone||"UTC+8"}get type(){return this._syminfo.type||"forex"}get volumetype(){return this._syminfo.volumetype||"n/a"}}class Am{constructor(e){E(this,"_variables");this._variables=e}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class fm{constructor(e){E(this,"_variables");this._variables=e}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}class qp{constructor(e){E(this,"_cacheData");E(this,"_barIndex");E(this,"_isRealTimeBar");E(this,"_barstate");E(this,"_priceVariables");E(this,"_lastBarIndex");E(this,"_currentBarTime");E(this,"_lastBarTime");E(this,"_period");E(this,"_offsetTime");E(this,"_timeframe");E(this,"_ta");E(this,"_polyline");E(this,"_label");E(this,"_line");E(this,"_linefill");E(this,"_box");E(this,"_table");E(this,"_strategy");E(this,"_session");E(this,"syminfo");E(this,"chart");E(this,"earnings");E(this,"dividends");E(this,"_timeTradingday");E(this,"_mintick");E(this,"_cacheSpace");E(this,"_precision");E(this,"_nextBarTime");E(this,"_isRepeated");E(this,"_preCacheData");E(this,"__requestName","");E(this,"__isFirstRun",!1);E(this,"_maxBarsBack",0);E(this,"__isReqRepeated");E(this,"_newCacheData",{});this._cacheData={varData:{},varipData:{}},this._preCacheData={varData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new zm,this._timeframe=new Om,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new sm(e),this._polyline=new Cr(this),this._label=new Cr(this),this._line=new Cr(this,Q0.LINE),this._linefill=new Cr(this,Q0.LINEFILL),this._box=new Cr(this),this._table=new Cr(this),this._strategy=new cm(this),this._session=new im(this),this.syminfo=new um,this.chart=new am,this.earnings=new fm(this),this.dividends=new Am(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:e,open:t,high:r,low:o}=this._priceVariables;return(e+t+r+o)/4}get hl2(){const{high:e,low:t}=this._priceVariables;return(e+t)/2}get hlc3(){const{close:e,high:t,low:r}=this._priceVariables;return(e+t+r)/3}get hlcc4(){const{close:e,high:t,low:r}=this._priceVariables;return(e*2+t+r)/4}get hour(){return D1(this._currentBarTime).hour()}get minute(){return D1(this._currentBarTime).minute()}get second(){return D1(this._currentBarTime).second()}get month(){return D1(this._currentBarTime).month()+1}get year(){return D1(this._currentBarTime).year()}get dayofweek(){return D1(this._currentBarTime).day()}get dayofmonth(){return D1(this._currentBarTime).date()}get weekofyear(){return D1(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[e,t]=OM(this._period);return D1(this._currentBarTime).add(e,t).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}get nextBarTime(){return this._nextBarTime}set max_bars_back(e){this._maxBarsBack=e}updateMaxLength(e){const{max_lines_count:t,max_labels_count:r,max_boxes_count:o,max_polylines_count:n}=e;o&&this._box.setMaxLen(o),r&&this._label.setMaxLen(r),t&&this._line.setMaxLen(t),n&&this._polyline.setMaxLen(n)}getTimeTradingday(e,t){const[r,o]=OM(t),n=D1(e);return["M","w","y","d"].includes(o)?n.valueOf():(n.subtract(this._offsetTime,"h"),n.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(e){var s;const{interval:t="1D",offsetTime:r=5,mintick:o,chart:n,syminfo:b}=e,z=((s=o.toString().split(".")[1])==null?void 0:s.length)||5;this._precision=z;const i=Ac(t);this._period=i,this._mintick=o,this._offsetTime=r,this._timeframe.update(i),this.chart.updateOptions(n),this.syminfo.update(b),this._barstate.isFirstRun=this.__isFirstRun}updateData(e,t){const{barIndex:r,c:o,o:n,h:b,l:z,volume:i,time:s,lastBarIndex:a,lastBarTime:O,isrealtime:u,time_tradingday:l,nextBarTime:d}=e;if(this._priceVariables={close:rn(o,this._precision),open:rn(n,this._precision),high:rn(b,this._precision),low:rn(z,this._precision),volume:Number(i)},this._isRealTimeBar=u,this._newCacheData={},r>this._barIndex){const{varData:A,varipData:h}=this._cacheData;this._preCacheData={varData:{},varipData:{}},u?(this._deepCopy(A,this._preCacheData.varData),this._deepCopy(h,this._preCacheData.varipData)):this._preCacheData={varData:{...A},varipData:{...h}}}this._isRepeated=t,this._timeTradingday=l,this._currentBarTime=s*1e3,this._lastBarIndex=a,this._barIndex=r,this._lastBarTime=O*1e3,this._nextBarTime=d*1e3,this._barstate.update(r,a,u,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(e,t,r){const o=this.setCacheData(e,r),n=this._cacheSpace.get(e)||0;return t=Math.floor(t),n<t&&this._cacheSpace.set(e,t),o[o.length-1-t]}setCacheData(e,t){let r=this._cacheData[e]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=t:r.data.push(t);const o=this._cacheSpace.get(e)||0;return o&&r.data.length>(this._maxBarsBack||o+50)&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[e]=r,r.data}getTypeInstance(e,t){return new Lu(e,t)}verifyVarAndVarip(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`,n=this._isRepeated||this.__isReqRepeated?this._preCacheData:this._cacheData;if(r==="var"&&n.varData.hasOwnProperty(o))return this._upadteChartDraws(n.varData[o]),!0;const b=this.__isReqRepeated?this._preCacheData.varipData:this._cacheData.varipData;return r==="varip"&&b.hasOwnProperty(o)?(this._upadteChartDraws(b[o]),!0):!1}getVarValue(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;(this._isRepeated||this.__isReqRepeated)&&(this._cacheData.varData[o]=this._preCacheData.varData[o],this.__isReqRepeated&&(this._cacheData.varipData[o]=this._preCacheData.varipData[o]));const n=this._cacheData;if(r==="var"){if(this._isRealTimeBar){if(this._newCacheData.hasOwnProperty(o))return this._newCacheData[o];const b=n.varData[o];return typeof b!="object"||b!=null&&b.type?b:b!=null&&b.copy?b.copy():Object.assign({},b)}return n.varData[o]}return this._cacheData.varipData[o]}setVarValue(e,t,r,o){var z;const n=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;let b;switch(typeof r=="object"&&((z=r==null?void 0:r.varipKeys)!=null&&z.length)&&o!=="varip"&&(o="var",b=r.varipKeys),o){case"var":if(this._isRealTimeBar){if(b&&b.length)for(const i of b)this._cacheData.varData[n][i]=r[i];this._newCacheData[n]=r}else this._chartDrawsHandle(r,this._cacheData.varData[n]),this._cacheData.varData[n]=r;break;case"varip":this._chartDrawsHandle(r,this._cacheData.varipData[n]),this._cacheData.varipData[n]=r;break}return r}_upadteChartDraws(e){const t=this._isRealTimeBar?e==null?void 0:e.preId:e==null?void 0:e.id;if(t)switch(e==null?void 0:e.type){case Q0.BOX:this._setChartDraw(t,this._box);break;case Q0.LINE:this._setChartDraw(t,this._line);break;case Q0.POLYLINE:this._setChartDraw(t,this._polyline);break;case Q0.LABEL:this._setChartDraw(t,this._label);break;case Q0.LINEFILL:this._setChartDraw(t,this._linefill);break;case Q0.TABLE:this._setChartDraw(t,this._table);break}}_deepCopy(e,t){for(const r of Object.keys(e)){const o=e[r];typeof o!="object"||o!=null&&o.type?t[r]=o:o!=null&&o.copy?t[r]=o.copy():(t[r]={},this._deepCopy(o,t[r]))}}_setChartDraw(e,t){const r=t.getInstance(e);let o=t.get(e);if(!o||!r)return;const n=r.updateId()||e;n===e&&!this._isRealTimeBar||(o=JSON.parse(JSON.stringify(o)),r.data=o,t.deleteHandle(e,!1),t.set(n,o,r))}_chartDrawsHandle(e,t){const r=t==null?void 0:t.id;let o=e==null?void 0:e.id;o&&e.data&&(e.data.isVar=!0),r!==o&&r&&t.data&&(t.data.isVar=!1)}add(e,t){return Array.isArray(e)&&Array.isArray(t)?D2.uniq([...e,...t]):typeof e=="number"||typeof t=="number"?Number(e)+Number(t):(e||"")+(t||"")}sub(e,t){return Array.isArray(e)&&Array.isArray(t)?e.filter(r=>!t.includes(r)):Number(e)-Number(t)}div(e,t){if(t)return e/t}equal(e,t,r,o){if(e!==void 0&&t!==void 0)return e==t;if(!(r.endsWith(Q0.BOOL)&&e===void 0))return(r.endsWith(Q0.FLOAT)||r.endsWith(Q0.INT)||o.endsWith(Q0.FLOAT)||o.endsWith(Q0.INT))&&e===void 0&&t===void 0?!1:r.endsWith(Q0.STRING)&&e===""&&t===void 0||o.endsWith(Q0.STRING)&&t===""&&e===void 0?!0:r.endsWith(Q0.NA)&&o.endsWith(Q0.NA)?!1:e==t}compareDataHandle(e){if(typeof e!="number"||!e)return e;const t=String(e);if(!t.includes(".")&&!/[eE]/.test(t))return e;const[r,o]=e.toFixed(11).split(".");return+`${r}.${o.slice(0,10)}`}againAssignParse(e,t){var o;if(t)return;const r=(o=e==null?void 0:e.constructor)==null?void 0:o.name;if(r)switch(r){case Ko.name:case E3.name:case Qo.name:case C3.name:case Jo.name:case T3.name:e==null||e.delete();break}}}class Cr{constructor(e,t,r=50){E(this,"_all");E(this,"_allInstance");E(this,"_pseudoArrayAll");E(this,"_maxLength");E(this,"_deleteIds");E(this,"_variables");E(this,"_preDeleteIds");E(this,"_againAddItems");E(this,"_tmpData");E(this,"_tmpInstance");E(this,"_type");E(this,"_tmpIds",[]);this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new n1,this._maxLength=r,this._deleteIds=new Map,this._variables=e,this._preDeleteIds=new Map,this._againAddItems=[],this._tmpData=new Map,this._tmpInstance=new Map,this._type=t}setMaxLen(e){this._maxLength=e}get size(){return this._all.size+this._tmpData.size}get data(){const e=[],t=D2.flatMap([...this._deleteIds.values()]),r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=[];for(const n of r)if(!t.some(b=>b.key===n)){const b=this._tmpData.get(n)||this._all.get(n),z=b==null?void 0:b.id;b&&!o.includes(z)&&(o.push(z),e.push(b))}return this._variables._isRealTimeBar&&this._preDeleteIds.set(this._variables.last_bar_index,this._deleteIds.get(this._variables.last_bar_index)||[]),this._tmpDataHandle(),this._type===Q0.LINEFILL?e:e.slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values(),...this._tmpInstance.values()],this._pseudoArrayAll}add(e,t,r){if(this.set(e,t,r),!this._variables._isRealTimeBar&&this._type!==Q0.LINEFILL&&this._all.size>this._maxLength){const{bar_index:o}=t;for(const[n,b]of this._all){const{isVar:z,id:i,bar_index:s}=b;if(s===o)break;if(z)continue;this.deleteHandle(i);break}}}getValOfBarIndex(e){let t=[];const r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=D2.flatMap([...this._deleteIds.values()]);for(const n of e){const b=r.filter(z=>z.endsWith(`_${n}`));for(const z of b){if(o.some(s=>s.key===z))continue;const i=this._tmpData.get(z)||this._all.get(z);i&&t.push(i)}}return this._againAddItems.length&&(t=this._againAddItems.concat(t),this._againAddItems=[]),this._tmpDataHandle(),t.length?this._type===Q0.LINEFILL?t:t.slice(-this._maxLength):void 0}getDeleteIds(e){let t=[];const{bar_index:r,_isRealTimeBar:o}=this._variables,n=[];for(const b of e){let z=[...this._deleteIds.get(b)||[]];const i=this._preDeleteIds.get(b)||[];if(b===r&&o){let s=[];for(const a of i){const O=z.findIndex(u=>u.id===a.id);if(O===-1){const u=this._all.get(a.key);u&&n.push(u)}else s.push(a),z.splice(O,1)}this._preDeleteIds.set(r,D2.uniqBy([...z,...s],"id"))}else{const s=[],a=[...this._all.values(),...this._tmpData.values()];for(const O of this._tmpIds)a.some(u=>u.id===O.id)||s.push(O);for(const O of z)i.some(u=>u.id===O.id)||s.push(O);z=s,this._preDeleteIds.delete(b)}t=t.concat(z)}return this._againAddItems=n,D2.uniq(t.map(b=>b.id))}set(e,t,r){this._variables._isRealTimeBar?(this._tmpData.set(e,t),this._tmpInstance.set(e,r)):(this._all.set(e,t),this._allInstance.set(e,r))}get(e){const t=this._all.get(e);let r=this._tmpData.get(e);return this._variables._isRealTimeBar?(r||(r=t?{...t}:void 0,r&&this._tmpData.set(e,r)),r):(this._tmpData.clear(),this._tmpInstance.clear(),t)}getInstance(e){return this._allInstance.get(e)}deleteHandle(e,t=!0){var r;if(this._type===Q0.LINE&&t){const o=(r=this._allInstance.get(e))==null?void 0:r.__fillKeys;if(o&&o.length)for(const n of o)this._variables.linefill.deleteHandle(n)}this._variables._isRealTimeBar?(this._tmpData.delete(e),this._tmpInstance.delete(e)):(this._all.delete(e),this._allInstance.delete(e))}delete(e,t,r){const o=this._all.get(e);if(this._variables._isRealTimeBar||this.deleteHandle(e),!(this._variables.__isFirstRun&&!this._variables._isRealTimeBar)&&typeof t=="number"){const n=this._deleteIds.get(t)||[];n.push({key:e,id:(o==null?void 0:o.id)||r}),this._deleteIds.set(t,n)}}_tmpDataHandle(){var e;this._tmpIds=[];for(const[t]of this._tmpInstance){const r=(e=this._tmpData.get(t))==null?void 0:e.id;r&&this._tmpIds.push({id:r,key:t})}this._tmpData.clear(),this._tmpInstance.clear(),this._deleteIds.clear()}}/**
|
85
|
+
${l}`),l}_getRequestLowerTfData(e,t,r,o){var L;let{symbol:n,timeframe:b,calc_bars_count:z,ignore_invalid_symbol:i,ignore_invalid_timeframe:s}=e;const{__period:a,time:O,_isRealTimeBar:u}=this._variables;b=hr(b);let l=N2(b,O)*1e3;const d=N2(a,O)*1e3;if(l>d)return!s&&this._errorListener.addError(r2(l1.requestLowerTfPeriodErr,{period:b}),t,$0.Error,25),[];const A=`${n}--${b}`,h=self.workerStorage.get(`request_${this._scriptId}_data`),q=self.workerStorage.get(`request_${this._scriptId}_list`),_=self.workerStorage.get(`request_${this._scriptId}_tmp`),m={id:A,calc_bars_count:z,ignore_invalid_symbol:i,symbol:n,originTimeframe:b,timeframe:ii[b]||ic(b)};if(h!=null&&h.has(A)){_==null||_.delete(A);const{index:g=0,periodStamp:v=d}=this._cacheData.get(r)||{},y=h==null?void 0:h.get(A);if(!y.length)return[];if(y.length-1<0)return[];const T=y.slice(g);let N=O,D=v+N;const C=[];for(const[P,H]of T.entries()){let{time:G}=H;G=G*1e3;let k=g+P;if(G>=D)return!u&&this._cacheData.set(r,{index:k,periodStamp:v}),C;if(N<=G&&G<D){const J=(L=H==null?void 0:H.result)==null?void 0:L[r];if(Array.isArray(J))for(const[o0,z0]of J.entries())C[o0]||(C[o0]=[]),C[o0].push(z0);else o||C.push(J)}}return!u&&this._cacheData.set(r,{index:y.length,periodStamp:v}),C}else(q==null?void 0:q.get(A))||_==null||_.set(A,m);q==null||q.set(A,m)}_getRequestData(e,t){var _,m,L,g,v;let{symbol:r,timeframe:o,calc_bars_count:n,gaps:b,lookahead:z,ignore_invalid_symbol:i}=e;const{__period:s,mintick:a,time:O,nextBarTime:u}=this._variables;o=hr(o),r=r;const l=`${r}--${o}`,d=self.workerStorage.get(`request_${this._scriptId}_data`),A=self.workerStorage.get(`request_${this._scriptId}_list`),h=self.workerStorage.get(`request_${this._scriptId}_tmp`),q={id:l,calc_bars_count:n,ignore_invalid_symbol:i,symbol:r,originTimeframe:o,timeframe:ii[o]||ic(o)};if(d!=null&&d.has(l)){let y=N2(o,O)*1e3;const X=N2(s,O)*1e3;h==null||h.delete(l);const{index:T=0,periodStamp:N=X}=this._cacheData.get(t)||{},D=d==null?void 0:d.get(l);if(!D.length)return;const C=D.slice(T);let P=O,H=N+P;const G=D.length-1;if(G<0)return;const k={lastBarIndex:D[G].barindex||G,lastBarTime:D[G].time,interval:o,mintick:a};if(y>N){let J;if(z===Pe.lookaheadOn?J=this._lookaheadOnHandle(C,o,H,y,k,T,N,t,P,b):J=this._lookaheadOffHandle(C,o,H,y,k,T,N,t,P,u||H,b),J)return J;if(J===null)return}else if(z===Pe.lookaheadOn)for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((_=C[J+1])==null?void 0:_.time)*1e3||z0+y;let w0=T+J;if(z0>=H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<=P&&v0>P){const u0=T+J;return this._cacheData.set(t,{index:u0,periodStamp:N}),{...o0,barIndex:a0||u0,nextBarTime:(m=C[J+1])==null?void 0:m.time,...k}}}else for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((L=C[J+1])==null?void 0:L.time)*1e3||z0+y;let w0=T+J;if(z0>H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<H&&H<=v0)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(g=C[J+1])==null?void 0:g.time,...k};if(z0>=P&&z0<=H&&(a0||w0)===k.lastBarIndex)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(v=C[J+1])==null?void 0:v.time,...k}}this._cacheData.set(t,{index:D.length,periodStamp:N});return}else(A==null?void 0:A.get(l))||h==null||h.set(l,q);A==null||A.set(l,q)}_lookaheadOnHandle(e,t,r,o,n,b,z,i,s,a){var O;for(const[u,l]of e.entries()){let{time:d,barindex:A}=l;d=d*1e3,t.includes("M")&&(o=N2(t,d)*1e3-(D1(d).date()-1)*864e5);const h=d,q=o+h;let _=b+u;if(r<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),null;let m={...l,barIndex:A||_,nextBarTime:(O=e[u+1])==null?void 0:O.time,...n};if(a===Pe.gapsOn){if(r>h&&s<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}else{if(r>q)continue;if(r>h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}}}_lookaheadOffHandle(e,t,r,o,n,b,z,i,s,a,O){var u,l;for(const[d,A]of e.entries()){let{time:h,barindex:q}=A;h=h*1e3,t.includes("M")&&(o=N2(t,h)*1e3-(D1(h).date()-1)*864e5);const _=h,m=o+_,L=b+d;if(r<_)return this._cacheData.set(i,{index:L,periodStamp:z}),null;const g={...A,barIndex:q||L,nextBarTime:(u=e[d+1])==null?void 0:u.time,...n};if(r>=m&&s<m||r<m&&a>=m)return O===Pe.gapsOn?(this._cacheData.set(i,{index:L,periodStamp:z}),g):(this._cacheData.set(i,{index:L,data:g,periodStamp:z}),g);if(!(s>m)&&s>=_){let v=(l=this._cacheData.get(i))==null?void 0:l.data;if(!v){const y=e[L-1];if(!y)return null;v={...y,barIndex:y.barindex||L-1,nextBarTime:g.time,...n},this._cacheData.set(i,{index:L,data:v,periodStamp:z})}return v}}}_getDependCodes(e,t,r,o,n,b){for(const z of e){if(!z.isArg){const i=t.filter(a=>{var O;return(O=a==null?void 0:a.depends)==null?void 0:O.some(u=>u.name===z.name&&u.scope===z.scope&&u.isAgainAssign!==!1)});for(const a of i){const{code:O,depends:u,scope:l,funcName:d}=a;r[l]=r[l]||[];const A=r[l];let h=l===0&&d;if(!A.includes(O)){if(h){if(o.includes(O))continue;o.unshift(O)}else A.unshift(O);if(u!=null&&u.length){for(const q of u)q.memberCode&&!h&&b.push(q.memberCode);this._getDependCodes(u,t,r,o,n,b)}}}const s=t.find(a=>{var O;return((O=a.varNames)==null?void 0:O.split(", ").includes(z.name))&&(!z.isPreArg||z.isPreArg&&a.methodName===z.functionName)||a.funcName===z.name});if(s){const{code:a,depends:O,scope:u}=s;r[u]=r[u]||[];const l=r[u],d=l.findIndex(A=>A===a);if(d!==-1){if(z.isFunc)continue;l.splice(d,1)}if(l.unshift(a),O!=null&&O.length){for(const A of O)A.memberCode&&b.push(A.memberCode);this._getDependCodes(O,t,r,o,n,b)}continue}}n.some(i=>i.name===z.name)||n.push(z)}}_getStmtFuncs(e,t,r,o,n){const b=t.filter(z=>z.isStmtFunc);for(const z of b){const{code:i,depends:s,scope:a=0}=z;e[a]=e[a]||[];const O=e[a];if(!O.includes(i)&&(O.push(i),s!=null&&s.length)){for(const u of s)u.memberCode&&r.push(u.memberCode);this._getDependCodes(s.filter(u=>!(u.isFunc&&i.startsWith(u.name))),t,e,o,n,r)}}}runScripts(e,t,r,o,n,b){var u;const z=`${this._scriptId}_${t}`;let{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O}=self.workerStorage.get(z)||{};if(r&&(i=new qp(z),s=new fp,a=new lp(this._variables.mintick||1e-5,i,this._scriptId),O=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e),i.__requestName=t,self.workerStorage.set(z,{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O})),o&&o.length){const l=o.length-1,{interval:d,symbol:A=""}=n,{mintick:h,syminfo:q}=this._variables,[_,m]=A.split(":");i.updateOptions({interval:d,mintick:h,syminfo:{...q.__syminfo,tickerid:A||q.tickerid,ticker:m||_||q.ticker}});for(const[v,y]of o.entries()){const{barindex:X}=y,T=Object.assign(y,{barIndex:X||v,lastBarIndex:o[l].barindex||l,lastBarTime:o[l].time,nextBarTime:(u=o[v+1])==null?void 0:u.time});if(i.updateData(T),a.update({barIndex:(T==null?void 0:T.barindex)||0}),y.result=Object.assign(y.result||{},{[t]:O(i,s,a,b||[],t)}),a.endExecution(),a.errors.length&&a.errors.some(N=>N.type===$0.Error))return{logs:[],errors:a.errors}}const L=a.log.logs,g=a.errors;return a.log.clearLogs(),a.clearErrors(),{logs:L,errors:g}}}_runScripts(e,t,r,o,n){const b=`${this._scriptId}_${t}`;let{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a}=self.workerStorage.get(b)||{};const{interval:O,...u}=n||{};if(r){z=new qp(b),i=new fp,s=new lp(this._variables.mintick||1e-5,z,this._scriptId),a=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e);const{mintick:h,syminfo:q}=this._variables;z.updateOptions({interval:O,mintick:h||1e-5,syminfo:{...q.__syminfo}}),z.__requestName=t,self.workerStorage.set(b,{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a})}z.updateData(u),s.update({barIndex:(u==null?void 0:u.barindex)||0});const l=a(z,i,s,o||[],t),d=s.log.logs,A=s.errors;return s.log.clearLogs(),s.clearErrors(),s.endExecution(),{result:l,logs:d,errors:A}}},om=class{constructor(){}prefix(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[0])||""}ticker(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[1])||""}};class nm{constructor(e,t){E(this,"_logs");E(this,"_variables");E(this,"_str");E(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=e,this._logs=[],this._str=t}get logs(){return this._logs}clearLogForIndex(e){this._logs=this._logs.filter(t=>t.barIndex!==e)}clearLogs(){this._logs=[]}info(e,t,r){this._addLog(e,t,"info",r)}error(e,t,r){this._addLog(e,t,"error",r)}warning(e,t,r){this._addLog(e,t,"warning",r)}mergeLogs(e){this._logs=this._logs.concat(e)}_addLog(e,t,r,o){if(typeof t=="string"&&(o=t),o.startsWith("export"))return;const{message:n,formatString:b}=e,{time:z,bar_index:i,_isRealTimeBar:s,__isReqRepeated:a}=this._variables;let O=n;b&&Array.isArray(t)&&t.length&&(t=t.map(A=>(typeof A=="object"&&(A.isArray?A=JSON.stringify(A._value):A=A.toString()),A!==void 0?A:"na")),O=this._str.strformat({formatString:b},t,!0));const{isrealtime:u,barIndex:l}=this._preBar;i!==l&&(this._preBar={barIndex:i,isrealtime:s});const d=Date.now();O!==void 0&&this._logs.push({message:`[${D1(u&&!a?d:z).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${O}`,time:z,id:I4(6),barIndex:i,type:r})}}class bm{constructor(e){E(this,"_errorListener");this._errorListener=e}error({message:e},t){t.startsWith("export")||this._errorListener.addError(e,t,$0.Error)}}class pm{constructor(){E(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return D2.flatMap([...this._errors.values()])}setErrors(e,t){this._errors.set(t,e)}addError(e,t,r,o=0){const[n,b]=t.split("_").slice(-2),z=this._errors.get(t),i={message:e,endLineNumber:Number(n),startColumn:Number(b)+1,endColumn:Number(b)+o+1,startLineNumber:Number(n),type:r};z?z.push(i):this._errors.set(t,[i])}}class zm{constructor(){E(this,"_isMarketOpen");E(this,"_currentBarIndex");E(this,"_totalBarIndex");E(this,"_isRealTimeBar");E(this,"_preBarIndex");E(this,"_preIsRealTimeBar");E(this,"_isFirstRun",!1);this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0,this._preIsRealTimeBar=!1}update(e,t,r,o){this._preBarIndex=this._currentBarIndex,this._preIsRealTimeBar=this._isRealTimeBar,this._currentBarIndex=e,this._totalBarIndex=t,this._isRealTimeBar=r,this._isMarketOpen=o}set isFirstRun(e){this._isFirstRun=e}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex||!this._isFirstRun}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar||this._isFirstRun}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1&&!this._preIsRealTimeBar||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class im{constructor(e){E(this,"_variables");this._variables=e}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{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class cm{constructor(e){E(this,"_orders");E(this,"_historyOrders");E(this,"_options");E(this,"_max_contracts_held_all",0);E(this,"_max_contracts_held_long",0);E(this,"_max_contracts_held_short",0);E(this,"_max_drawdown",0);E(this,"_max_runup",0);E(this,"_max_runup_percent",0);E(this,"_max_drawdown_percent",0);E(this,"_variables");E(this,"_netprofit",0);E(this,"_eventrades",0);E(this,"_avg_trade_percent");E(this,"_avg_losing_trade_percent");E(this,"_avg_winning_trade_percent");E(this,"_closedtrades",0);E(this,"_losstrades",0);E(this,"_grossloss",0);E(this,"_grossprofit",0);E(this,"_wintrades",0);E(this,"_opentrades_capital_held",0);E(this,"_position_avg_price",0);E(this,"_position_size",0);E(this,"_openprofit",0);E(this,"_preMaxNetValue",0);E(this,"_preMinNetValue",0);E(this,"marginCallLong",0);E(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=e}update(e){this._calcMaxDrawdownAndMaxRunup(e)}_calcMaxDrawdownAndMaxRunup(e){if(!this._orders.length&&!this._historyOrders.length)return;let t=0,r=0;const{high:o,low:n,close:b}=e;let z=0;for(const[a,O]of this._orders.entries()){const{in_price:u,qty:l=0,direction:d,commission:A,original_qty:h=1}=O,q=d===i1.long?1:-1,_=(o-u)*l,m=(n-u)*l,L=q===1?_:-m,g=q===1?-m:_;z+=(b-u)*q*l,t+=g,a>0&&A&&(r-=A*l/h),r+=L}this._openprofit=z;const i=this.initial_capital,s=i+this._netprofit;this._preMinNetValue=this._preMinNetValue||i,this._preMaxNetValue=this._preMaxNetValue||i,t=this._preMaxNetValue-s+Math.max(t,0),r=s-this._preMinNetValue+r,this._max_drawdown<t&&(this._max_drawdown=t,this._max_drawdown_percent=t/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(e){this._orders=e,this._calcMaxContracts()}_calcMaxContracts(){const e=this._orders.length;if(!e){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[t,r,o,n,b,z,i]=this._orders.reduce(([s,a,O,u,l,d,A],h)=>{const{direction:q,qty:_=0,in_price:m,commission:L=0}=h;return q===i1.long?(s+=_,a+=_,d+=_):(s+=_,O+=_,d-=_),u+=_*m,l+=m,A+=L,[s,a,O,u,l,d,A]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-i,this._grossloss=i),this._position_size=z,this._position_avg_price=b/e,this._opentrades_capital_held=n,this._max_contracts_held_all=Math.max(t,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(o,this._max_contracts_held_short)}updateHistoryOrders(e){this._historyOrders=e;const t=this._historyOrders.length;this._closedtrades=t;const[r,o,n,b,z,i,s,a]=this._historyOrders.reduce((l,d)=>{let[A,h,q,_,m,L,g,v]=l;const{profit:y=0,profit_percent:X=0}=d;return A+=y,h+=X,y<0?(q+=y,_+=X,g+=1):y>0&&(m+=y,L+=X,v+=1),[A,h,q,_,m,L,g,v]},[0,0,0,0,0,0,0,0]),O=this._orders.reduce((l,d)=>{const{commission:A=0,qty:h=0,original_qty:q=0}=d,_=A*h/q;return l+_},0);this._avg_trade_percent=t?o/t:void 0,this._avg_losing_trade_percent=t?Math.abs(b)/s:void 0,this._avg_winning_trade_percent=t?i/a:void 0,this._netprofit=r-O;const u=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,u),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,u),this._grossloss=Math.abs(n-O),this._grossprofit=z,this._eventrades=t-s-a,this._losstrades=s,this._wintrades=a}updateStrategyOptions(e){this._options=e}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 e=this._losstrades;return e?Math.abs(this._grossloss/e):void 0}get avg_losing_trade_percent(){return this._avg_losing_trade_percent}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 e=this._wintrades;return e?Math.abs(this._grossprofit/e):void 0}get avg_winning_trade_percent(){return this._avg_winning_trade_percent}get initial_capital(){var e;return((e=this._options)==null?void 0:e.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:e,margin_long:t=0,margin_short:r=0,commission_type:o,commission_value:n=0}=this._options,b=this._orders[0].direction===i1.long?1:-1,z=(b===1?t:r)/100;if(z<=0)return;const{close:i}=this._variables,[s,a]=this._orders.reduce((O,u)=>{let[l,d]=O;const{in_price:A,qty:h=0,original_qty:q=0}=u,_=A*h;if(l+=_,n){let m=0;switch(o){case O2.percent:m=(_+h*i)*n/100;break;case O2.cashPerContract:m=h*n*2;break;case O2.cashPerOrder:m=h/q*n+n;break}d+=m}return[l,d]},[0,0]);return(s-(e+this._netprofit-a))*b/this._position_size/(1-b*z)}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(e,t){if(!this._options)return 0;const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}}class sm{constructor(e){E(this,"_preAccdist");E(this,"_preNvi");E(this,"_prePvi");E(this,"_preObv");E(this,"_prePvt");E(this,"_preWad");E(this,"_preVwap");E(this,"_preValue");E(this,"_currentData");E(this,"_preData");E(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=e}update(e){this._preValue={},e.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...e}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:e,low:t,high:r,volume:o}=this._currentData;if(r===t)return this._preAccdist;const n=(e-t-(r-e))/(r-t)*o+this._preAccdist;return!this.isRealTime&&(this._preAccdist=n),this._preValue.accdist=n,n}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:e,low:t,high:r,volume:o}=this._currentData,n=(2*e-r-t)/((r-t)*o);return this._preValue.iii=n,n}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:e,low:t,high:r,volume:o,open:n}=this._currentData,b=(e-n)/(r-t)*o;return this._preValue.wvad=b,b}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const o=Math.sign(e-r)*t+this._preObv;return!this.isRealTime&&(this._preObv=o),this._preValue.obv=o,o}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:e,high:t}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const o=Math.max(t-e,Math.abs(t-r),Math.abs(e-r));return this._preValue.tr=o,o}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const o=(e-r)/r*t+this._prePvt;return!this.isRealTime&&(this._prePvt=o),this._preValue.pvt=o,o}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:e,high:t,low:r}=this._currentData,{close:o}=this._preData;if(o===void 0)return this._preWad=0,0;const n=Math.max(t,o),b=Math.min(r,o),z=e-o,s=(z>0?e-b:z<0?e-n:0)+this._preWad;return!this.isRealTime&&(this._preWad=s),this._preValue.wad=s,s}get vwap(){var a,O;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:e,volume:t}=this._currentData;let{sum:r=0,sumV:o=0,isReset:n}=this._preVwap;if(((O=(a=self.workerStorage)==null?void 0:a.get(this._id))==null?void 0:O.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(n=!0,r=o=0),!n)return;const z=e*t+r,i=t+o;!this.isRealTime&&(this._preVwap={sum:z,sumV:i,isReset:n});const s=z/i;return this._preValue.vwap=s,s}_getNvi(){const e=this._preNvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n<r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._preNvi=b),this._preValue.nvi=b,b}_getPvi(){const e=this._prePvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n>r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._prePvi=b),this._preValue.pvi=b,b}}class Om{constructor(){E(this,"_period");E(this,"_multiplier");E(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(e){if(!e)return;this._period=e;const[t,r]=OM(e);this._multiplier=t,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}}class am{constructor(){E(this,"_bgColor");E(this,"_fgColor");E(this,"isUseBgColor",!1)}updateOptions(e){e!=null&&e.bg_color&&(this._bgColor=e.bg_color,this._fgColor=this._contrastColor(e.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(){}get right_visible_bar_time(){}_parseColor(e){let t,r,o,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),o=parseInt(e.substring(5,7),16);const b=e.substring(7);b?n=parseInt(b,16)/255:n=1}else{const b=this._parserRgbColor(e);t=b[0]||0,r=b[1]||0,o=b[2]||0,n=b[3]||1}return{r:t,g:r,b:o,a:n}}_parserRgbColor(e){var t;return((t=e.match(/\d+/g))==null?void 0:t.map(Number))||[]}_contrastColor(e){const{r:t,g:r,b:o}=this._parseColor(e);return(299*t+587*r+114*o)/1e3>128?"#000000":"#ffffff"}}class um{constructor(){E(this,"_syminfo",{})}update(e){this._syminfo=e}get __syminfo(){return this._syminfo}get basecurrency(){return this._syminfo.basecurrency||""}get country(){return this._syminfo.country}get currency(){return this._syminfo.currency||"USD"}get description(){return this._syminfo.description||""}get employees(){return this._syminfo.employees||100}get expiration_date(){return this._syminfo.expiration_date}get industry(){return this._syminfo.industry}get minmove(){return this._syminfo.minmove&&Number(this._syminfo.minmove)}get mintick(){return this._syminfo.mintick}get pointvalue(){return this._syminfo.pointvalue&&Number(this._syminfo.pointvalue)}get prefix(){return this.tickerid.replace(`:${this.ticker}`,"")}get pricescale(){return this._syminfo.pricescale&&Number(this._syminfo.pricescale)}get recommendations_buy(){return this._syminfo.recommendations_buy}get recommendations_buy_strong(){return this._syminfo.recommendations_buy_strong}get recommendations_date(){return this._syminfo.recommendations_date}get recommendations_hold(){return this._syminfo.recommendations_hold}get recommendations_sell(){return this._syminfo.recommendations_sell}get recommendations_sell_strong(){return this._syminfo.recommendations_sell_strong}get recommendations_total(){return this._syminfo.recommendations_total}get root(){return this._syminfo.root||""}get sector(){return this._syminfo.sector}get session(){return this._syminfo.session||ut.regular}get shareholders(){return this._syminfo.shareholders}get shares_outstanding_float(){return this._syminfo.shares_outstanding_float}get shares_outstanding_total(){return this._syminfo.shares_outstanding_total}get target_price_average(){return this._syminfo.target_price_average}get target_price_date(){return this._syminfo.target_price_date}get target_price_estimates(){return this._syminfo.pricescale}get target_price_high(){return this._syminfo.target_price_high}get target_price_low(){return this._syminfo.target_price_low}get target_price_median(){return this._syminfo.target_price_median}get ticker(){return this._syminfo.ticker||""}get tickerid(){return this._syminfo.tickerid||""}get timezone(){return this._syminfo.timezone||"UTC+8"}get type(){return this._syminfo.type||"forex"}get volumetype(){return this._syminfo.volumetype||"n/a"}}class Am{constructor(e){E(this,"_variables");this._variables=e}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class fm{constructor(e){E(this,"_variables");this._variables=e}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}class qp{constructor(e){E(this,"_cacheData");E(this,"_barIndex");E(this,"_isRealTimeBar");E(this,"_barstate");E(this,"_priceVariables");E(this,"_lastBarIndex");E(this,"_currentBarTime");E(this,"_lastBarTime");E(this,"_period");E(this,"_offsetTime");E(this,"_timeframe");E(this,"_ta");E(this,"_polyline");E(this,"_label");E(this,"_line");E(this,"_linefill");E(this,"_box");E(this,"_table");E(this,"_strategy");E(this,"_session");E(this,"syminfo");E(this,"chart");E(this,"earnings");E(this,"dividends");E(this,"_timeTradingday");E(this,"_mintick");E(this,"_cacheSpace");E(this,"_precision");E(this,"_nextBarTime");E(this,"_isRepeated");E(this,"_preCacheData");E(this,"__requestName","");E(this,"__isFirstRun",!1);E(this,"_maxBarsBack",0);E(this,"__isReqRepeated");E(this,"_newCacheData",{});this._cacheData={varData:{},varipData:{}},this._preCacheData={varData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new zm,this._timeframe=new Om,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new sm(e),this._polyline=new Cr(this),this._label=new Cr(this),this._line=new Cr(this,Q0.LINE),this._linefill=new Cr(this,Q0.LINEFILL),this._box=new Cr(this),this._table=new Cr(this),this._strategy=new cm(this),this._session=new im(this),this.syminfo=new um,this.chart=new am,this.earnings=new fm(this),this.dividends=new Am(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:e,open:t,high:r,low:o}=this._priceVariables;return(e+t+r+o)/4}get hl2(){const{high:e,low:t}=this._priceVariables;return(e+t)/2}get hlc3(){const{close:e,high:t,low:r}=this._priceVariables;return(e+t+r)/3}get hlcc4(){const{close:e,high:t,low:r}=this._priceVariables;return(e*2+t+r)/4}get hour(){return D1(this._currentBarTime).hour()}get minute(){return D1(this._currentBarTime).minute()}get second(){return D1(this._currentBarTime).second()}get month(){return D1(this._currentBarTime).month()+1}get year(){return D1(this._currentBarTime).year()}get dayofweek(){return D1(this._currentBarTime).day()}get dayofmonth(){return D1(this._currentBarTime).date()}get weekofyear(){return D1(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[e,t]=OM(this._period);return D1(this._currentBarTime).add(e,t).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}get nextBarTime(){return this._nextBarTime}set max_bars_back(e){this._maxBarsBack=e}updateMaxLength(e){const{max_lines_count:t,max_labels_count:r,max_boxes_count:o,max_polylines_count:n}=e;o&&this._box.setMaxLen(o),r&&this._label.setMaxLen(r),t&&this._line.setMaxLen(t),n&&this._polyline.setMaxLen(n)}getTimeTradingday(e,t){const[r,o]=OM(t),n=D1(e);return["M","w","y","d"].includes(o)?n.valueOf():(n.subtract(this._offsetTime,"h"),n.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(e){var s;const{interval:t="1D",offsetTime:r=5,mintick:o,chart:n,syminfo:b}=e,z=((s=o.toString().split(".")[1])==null?void 0:s.length)||5;this._precision=z;const i=Ac(t);this._period=i,this._mintick=o,this._offsetTime=r,this._timeframe.update(i),this.chart.updateOptions(n),this.syminfo.update(b),this._barstate.isFirstRun=this.__isFirstRun}updateData(e,t){const{barIndex:r,c:o,o:n,h:b,l:z,volume:i,time:s,lastBarIndex:a,lastBarTime:O,isrealtime:u,time_tradingday:l,nextBarTime:d}=e;if(this._priceVariables={close:rn(o,this._precision),open:rn(n,this._precision),high:rn(b,this._precision),low:rn(z,this._precision),volume:Number(i)},this._isRealTimeBar=u,this._newCacheData={},r>this._barIndex){const{varData:A,varipData:h}=this._cacheData;this._preCacheData={varData:{},varipData:{}},u?(this._deepCopy(A,this._preCacheData.varData),this._deepCopy(h,this._preCacheData.varipData)):this._preCacheData={varData:{...A},varipData:{...h}}}this._isRepeated=t,this._timeTradingday=l,this._currentBarTime=s*1e3,this._lastBarIndex=a,this._barIndex=r,this._lastBarTime=O*1e3,this._nextBarTime=d*1e3,this._barstate.update(r,a,u,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(e,t,r){const o=this.setCacheData(e,r),n=this._cacheSpace.get(e)||0;return t=Math.floor(t),n<t&&this._cacheSpace.set(e,t),o[o.length-1-t]}setCacheData(e,t){let r=this._cacheData[e]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=t:r.data.push(t);const o=this._cacheSpace.get(e)||0;return o&&r.data.length>(this._maxBarsBack||o+50)&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[e]=r,r.data}getTypeInstance(e,t){return new Lu(e,t)}verifyVarAndVarip(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`,n=this._isRepeated||this.__isReqRepeated?this._preCacheData:this._cacheData;if(r==="var"&&n.varData.hasOwnProperty(o))return this._upadteChartDraws(n.varData[o]),!0;const b=this.__isReqRepeated?this._preCacheData.varipData:this._cacheData.varipData;return r==="varip"&&b.hasOwnProperty(o)?(this._upadteChartDraws(b[o]),!0):!1}getVarValue(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;(this._isRepeated||this.__isReqRepeated)&&(this._cacheData.varData[o]=this._preCacheData.varData[o],this.__isReqRepeated&&(this._cacheData.varipData[o]=this._preCacheData.varipData[o]));const n=this._cacheData;if(r==="var"){if(this._isRealTimeBar){if(this._newCacheData.hasOwnProperty(o))return this._newCacheData[o];const b=n.varData[o];return typeof b!="object"||b!=null&&b.type?b:b!=null&&b.copy?b.copy():Object.assign({},b)}return n.varData[o]}return this._cacheData.varipData[o]}setVarValue(e,t,r,o){var z;const n=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;let b;switch(typeof r=="object"&&((z=r==null?void 0:r.varipKeys)!=null&&z.length)&&o!=="varip"&&(o="var",b=r.varipKeys),o){case"var":if(this._isRealTimeBar){if(b&&b.length)for(const i of b)this._cacheData.varData[n][i]=r[i];this._newCacheData[n]=r}else this._chartDrawsHandle(r,this._cacheData.varData[n]),this._cacheData.varData[n]=r;break;case"varip":this._chartDrawsHandle(r,this._cacheData.varipData[n]),this._cacheData.varipData[n]=r;break}return r}_upadteChartDraws(e){const t=this._isRealTimeBar?e==null?void 0:e.preId:e==null?void 0:e.id;if(t)switch(e==null?void 0:e.type){case Q0.BOX:this._setChartDraw(t,this._box);break;case Q0.LINE:this._setChartDraw(t,this._line);break;case Q0.POLYLINE:this._setChartDraw(t,this._polyline);break;case Q0.LABEL:this._setChartDraw(t,this._label);break;case Q0.LINEFILL:this._setChartDraw(t,this._linefill);break;case Q0.TABLE:this._setChartDraw(t,this._table);break}}_deepCopy(e,t){for(const r of Object.keys(e)){const o=e[r];typeof o!="object"||o!=null&&o.type?t[r]=o:o!=null&&o.copy?t[r]=o.copy():(t[r]={},this._deepCopy(o,t[r]))}}_setChartDraw(e,t){const r=t.getInstance(e);let o=t.get(e);if(!o||!r)return;const n=r.updateId()||e;n===e&&!this._isRealTimeBar||(o=JSON.parse(JSON.stringify(o)),r.data=o,t.deleteHandle(e,!1),t.set(n,o,r))}_chartDrawsHandle(e,t){const r=t==null?void 0:t.id;let o=e==null?void 0:e.id;o&&e.data&&(e.data.isVar=!0),r!==o&&r&&t.data&&(t.data.isVar=!1)}add(e,t){return Array.isArray(e)&&Array.isArray(t)?D2.uniq([...e,...t]):typeof e=="number"||typeof t=="number"?Number(e)+Number(t):(e||"")+(t||"")}sub(e,t){return Array.isArray(e)&&Array.isArray(t)?e.filter(r=>!t.includes(r)):Number(e)-Number(t)}div(e,t){if(t)return e/t}equal(e,t,r,o){if(e!==void 0&&t!==void 0)return e==t;if(!(r.endsWith(Q0.BOOL)&&e===void 0))return(r.endsWith(Q0.FLOAT)||r.endsWith(Q0.INT)||o.endsWith(Q0.FLOAT)||o.endsWith(Q0.INT))&&e===void 0&&t===void 0?!1:r.endsWith(Q0.STRING)&&e===""&&t===void 0||o.endsWith(Q0.STRING)&&t===""&&e===void 0?!0:r.endsWith(Q0.NA)&&o.endsWith(Q0.NA)?!1:e==t}compareDataHandle(e){if(typeof e!="number"||!e)return e;const t=String(e);if(!t.includes(".")&&!/[eE]/.test(t))return e;const[r,o]=e.toFixed(11).split(".");return+`${r}.${o.slice(0,10)}`}againAssignParse(e,t){var o;if(t)return;const r=(o=e==null?void 0:e.constructor)==null?void 0:o.name;if(r)switch(r){case Ko.name:case E3.name:case Qo.name:case C3.name:case Jo.name:case T3.name:e==null||e.delete();break}}}class Cr{constructor(e,t,r=50){E(this,"_all");E(this,"_allInstance");E(this,"_pseudoArrayAll");E(this,"_maxLength");E(this,"_deleteIds");E(this,"_variables");E(this,"_preDeleteIds");E(this,"_againAddItems");E(this,"_tmpData");E(this,"_tmpInstance");E(this,"_type");E(this,"_tmpIds",[]);this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new n1,this._maxLength=r,this._deleteIds=new Map,this._variables=e,this._preDeleteIds=new Map,this._againAddItems=[],this._tmpData=new Map,this._tmpInstance=new Map,this._type=t}setMaxLen(e){this._maxLength=e}get size(){return this._all.size+this._tmpData.size}get data(){const e=[],t=D2.flatMap([...this._deleteIds.values()]),r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=[];for(const n of r)if(!t.some(b=>b.key===n)){const b=this._tmpData.get(n)||this._all.get(n),z=b==null?void 0:b.id;b&&!o.includes(z)&&(o.push(z),e.push(b))}return this._variables._isRealTimeBar&&this._preDeleteIds.set(this._variables.last_bar_index,this._deleteIds.get(this._variables.last_bar_index)||[]),this._tmpDataHandle(),this._type===Q0.LINEFILL?e:e.slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values(),...this._tmpInstance.values()],this._pseudoArrayAll}add(e,t,r){if(this.set(e,t,r),!this._variables._isRealTimeBar&&this._type!==Q0.LINEFILL&&this._all.size>this._maxLength){const{bar_index:o}=t;for(const[n,b]of this._all){const{isVar:z,id:i,bar_index:s}=b;if(s===o)break;if(z)continue;this.deleteHandle(i);break}}}getValOfBarIndex(e){let t=[];const r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=D2.flatMap([...this._deleteIds.values()]);for(const n of e){const b=r.filter(z=>z.endsWith(`_${n}`));for(const z of b){if(o.some(s=>s.key===z))continue;const i=this._tmpData.get(z)||this._all.get(z);i&&t.push(i)}}return this._againAddItems.length&&(t=this._againAddItems.concat(t),this._againAddItems=[]),this._tmpDataHandle(),t.length?this._type===Q0.LINEFILL?t:t.slice(-this._maxLength):void 0}getDeleteIds(e){let t=[];const{bar_index:r,_isRealTimeBar:o}=this._variables,n=[];for(const z of e){let i=[...this._deleteIds.get(z)||[]];const s=this._preDeleteIds.get(z)||[];if(z===r&&o){let a=[];for(const O of s){const u=i.findIndex(l=>l.id===O.id);if(u===-1){const l=this._all.get(O.key);l&&n.push(l)}else a.push(O),i.splice(u,1)}this._preDeleteIds.set(r,D2.uniqBy([...i,...a],"id"))}else{const a=[];for(const O of i)s.some(u=>u.id===O.id)||a.push(O);i=a,this._preDeleteIds.delete(z)}t=t.concat(i)}const b=[...this._all.values(),...this._tmpData.values()];for(const z of this._tmpIds)b.some(i=>i.id===z.id)||t.push(z);return this._againAddItems=n,D2.uniq(t.map(z=>z.id))}set(e,t,r){this._variables._isRealTimeBar?(this._tmpData.set(e,t),this._tmpInstance.set(e,r)):(this._all.set(e,t),this._allInstance.set(e,r))}get(e){const t=this._all.get(e);let r=this._tmpData.get(e);return this._variables._isRealTimeBar?(r||(r=t?{...t}:void 0,r&&this._tmpData.set(e,r)),r):(this._tmpData.clear(),this._tmpInstance.clear(),t)}getInstance(e){return this._allInstance.get(e)}deleteHandle(e,t=!0){var r;if(this._type===Q0.LINE&&t){const o=(r=this._allInstance.get(e))==null?void 0:r.__fillKeys;if(o&&o.length)for(const n of o)this._variables.linefill.deleteHandle(n)}this._variables._isRealTimeBar?(this._tmpData.delete(e),this._tmpInstance.delete(e)):(this._all.delete(e),this._allInstance.delete(e))}delete(e,t,r){const o=this._all.get(e);if(this._variables._isRealTimeBar||this.deleteHandle(e),!(this._variables.__isFirstRun&&!this._variables._isRealTimeBar)&&typeof t=="number"){const n=this._deleteIds.get(t)||[];n.push({key:e,id:(o==null?void 0:o.id)||r}),this._deleteIds.set(t,n)}}_tmpDataHandle(){var e;this._tmpIds=[];for(const[t]of this._tmpInstance){const r=(e=this._tmpData.get(t))==null?void 0:e.id;r&&this._tmpIds.push({id:r,key:t})}this._tmpData.clear(),this._tmpInstance.clear(),this._deleteIds.clear()}}/**
|
86
86
|
* @license
|
87
87
|
* Copyright 2019 Google LLC
|
88
88
|
* SPDX-License-Identifier: Apache-2.0
|
@@ -177,6 +177,7 @@ export declare class BuildInFunctions {
|
|
177
177
|
private _getDataFromBarindex;
|
178
178
|
private _getDraws;
|
179
179
|
private _getDrawsFromBarindex;
|
180
|
+
private _filterDelIds;
|
180
181
|
private _getDrawDeletes;
|
181
182
|
updateOptions(options: IKeyObjectValue): void;
|
182
183
|
update(data: IKeyObjectValue): void;
|
@@ -69149,7 +69149,7 @@ function br(a, s, r) {
|
|
69149
69149
|
function Nw() {
|
69150
69150
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
69151
69151
|
}
|
69152
|
-
const Cd = new Worker(new URL("" + new URL("assets/scriptsRunWorker-
|
69152
|
+
const Cd = new Worker(new URL("" + new URL("assets/scriptsRunWorker-CeIoGWzf.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
|
69153
69153
|
Cd.onerror = (a) => {
|
69154
69154
|
console.error(a);
|
69155
69155
|
};
|
@@ -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 tl=Symbol("Comlink.proxy"),Dm=Symbol("Comlink.endpoint"),Im=Symbol("Comlink.releaseProxy"),Bn=Symbol("Comlink.finalizer"),ba=Symbol("Comlink.thrown"),sl=a=>typeof a=="object"&&a!==null||typeof a=="function",Am={canHandle:a=>sl(a)&&a[tl],serialize(a){const{port1:s,port2:r}=new MessageChannel;return al(a,s),[r,[r]]},deserialize(a){return a.start(),Un(a)}},qm={canHandle:a=>sl(a)&&ba in a,serialize({value:a}){let s;return a instanceof Error?s={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:s={isError:!1,value:a},[s,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},rl=new Map([["proxy",Am],["throw",qm]]);function Cm(a,s){for(const r of a)if(s===r||r==="*"||r instanceof RegExp&&r.test(s))return!0;return!1}function al(a,s=globalThis,r=["*"]){s.addEventListener("message",function n(o){if(!o||!o.data)return;if(!Cm(r,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:l,type:c,path:u}=Object.assign({path:[]},o.data),m=(o.data.argumentList||[]).map(Is);let _;try{const g=u.slice(0,-1).reduce((h,D)=>h[D],a),x=u.reduce((h,D)=>h[D],a);switch(c){case"GET":_=x;break;case"SET":g[u.slice(-1)[0]]=Is(o.data.value),_=!0;break;case"APPLY":_=x.apply(g,m);break;case"CONSTRUCT":{const h=new x(...m);_=Kn(h)}break;case"ENDPOINT":{const{port1:h,port2:D}=new MessageChannel;al(a,D),_=Lm(h,[h])}break;case"RELEASE":_=void 0;break;default:return}}catch(g){_={value:g,[ba]:0}}Promise.resolve(_).catch(g=>({value:g,[ba]:0})).then(g=>{const[x,h]=va(g);s.postMessage(Object.assign(Object.assign({},x),{id:l}),h),c==="RELEASE"&&(s.removeEventListener("message",n),nl(s),Bn in a&&typeof a[Bn]=="function"&&a[Bn]())}).catch(g=>{const[x,h]=va({value:new TypeError("Unserializable return value"),[ba]:0});s.postMessage(Object.assign(Object.assign({},x),{id:l}),h)})}),s.start&&s.start()}function Sm(a){return a.constructor.name==="MessagePort"}function nl(a){Sm(a)&&a.close()}function Un(a,s){return $n(a,[],s)}function xa(a){if(a)throw new Error("Proxy has been released and is not useable")}function il(a){return Hs(a,{type:"RELEASE"}).then(()=>{nl(a)})}const ha=new WeakMap,wa="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const s=(ha.get(a)||0)-1;ha.set(a,s),s===0&&il(a)});function zm(a,s){const r=(ha.get(s)||0)+1;ha.set(s,r),wa&&wa.register(a,s,a)}function Nm(a){wa&&wa.unregister(a)}function $n(a,s=[],r=function(){}){let n=!1;const o=new Proxy(r,{get(l,c){if(xa(n),c===Im)return()=>{Nm(o),il(a),n=!0};if(c==="then"){if(s.length===0)return{then:()=>o};const u=Hs(a,{type:"GET",path:s.map(m=>m.toString())}).then(Is);return u.then.bind(u)}return $n(a,[...s,c])},set(l,c,u){xa(n);const[m,_]=va(u);return Hs(a,{type:"SET",path:[...s,c].map(g=>g.toString()),value:m},_).then(Is)},apply(l,c,u){xa(n);const m=s[s.length-1];if(m===Dm)return Hs(a,{type:"ENDPOINT"}).then(Is);if(m==="bind")return $n(a,s.slice(0,-1));const[_,g]=ol(u);return Hs(a,{type:"APPLY",path:s.map(x=>x.toString()),argumentList:_},g).then(Is)},construct(l,c){xa(n);const[u,m]=ol(c);return Hs(a,{type:"CONSTRUCT",path:s.map(_=>_.toString()),argumentList:u},m).then(Is)}});return zm(o,a),o}function Em(a){return Array.prototype.concat.apply([],a)}function ol(a){const s=a.map(va);return[s.map(r=>r[0]),Em(s.map(r=>r[1]))]}const ll=new WeakMap;function Lm(a,s){return ll.set(a,s),a}function Kn(a){return Object.assign(a,{[tl]:!0})}function va(a){for(const[s,r]of rl)if(r.canHandle(a)){const[n,o]=r.serialize(a);return[{type:"HANDLER",name:s,value:n},o]}return[{type:"RAW",value:a},ll.get(a)||[]]}function Is(a){switch(a.type){case"HANDLER":return rl.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Hs(a,s,r){return new Promise(n=>{const o=Mm();a.addEventListener("message",function l(c){!c.data||!c.data.id||c.data.id!==o||(a.removeEventListener("message",l),n(c.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:o},s),r)})}function Mm(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const cl=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-CBj4zTFf.js").href:new URL("assets/scriptsRunWorker-CBj4zTFf.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:ra&&ra.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});cl.onerror=a=>{console.error(a)};async function pl(a){return await _a.setInlayHints(a)}const dl=Un(cl),ul=Un(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-DF7HO8qN.js").href:new URL("assets/parserTccWorker-DF7HO8qN.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:ra&&ra.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function ml(a,s=!1){const{functions:r,types:n,constants:o,variables:l,methods:c}=nt;return await ul.parseTcc(a,s,Kn(pl),{functions:Object.fromEntries(r),methods:Object.fromEntries(c),types:Object.fromEntries(n),constants:Object.fromEntries(o),variables:Object.fromEntries(l)})}async function Om(a,s){const{functions:r,types:n,constants:o,variables:l,methods:c}=nt;return await ul.parseLibraryCode(a,s,Kn(pl),{functions:Object.fromEntries(r),methods:Object.fromEntries(c),types:Object.fromEntries(n),constants:Object.fromEntries(o),variables:Object.fromEntries(l)})}async function Pm(a,s,r=!0){return await dl.runScript(a,s,r)}async function Rm(a){return await dl.removeScript(a)}function Fm(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})}const{slice:Bm,forEach:Um}=[];function $m(a){return Um.call(Bm.call(arguments,1),s=>{if(s)for(const r in s)a[r]===void 0&&(a[r]=s[r])}),a}const yl=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,Km=(a,s,r)=>{const n=r||{};n.path=n.path||"/";const o=encodeURIComponent(s);let l=`${a}=${o}`;if(n.maxAge>0){const c=n.maxAge-0;if(Number.isNaN(c))throw new Error("maxAge should be a Number");l+=`; Max-Age=${Math.floor(c)}`}if(n.domain){if(!yl.test(n.domain))throw new TypeError("option domain is invalid");l+=`; Domain=${n.domain}`}if(n.path){if(!yl.test(n.path))throw new TypeError("option path is invalid");l+=`; Path=${n.path}`}if(n.expires){if(typeof n.expires.toUTCString!="function")throw new TypeError("option expires is invalid");l+=`; Expires=${n.expires.toUTCString()}`}if(n.httpOnly&&(l+="; HttpOnly"),n.secure&&(l+="; Secure"),n.sameSite)switch(typeof n.sameSite=="string"?n.sameSite.toLowerCase():n.sameSite){case!0:l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"strict":l+="; SameSite=Strict";break;case"none":l+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return l},_l={create(a,s,r,n){let o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{path:"/",sameSite:"strict"};r&&(o.expires=new Date,o.expires.setTime(o.expires.getTime()+r*60*1e3)),n&&(o.domain=n),document.cookie=Km(a,encodeURIComponent(s),o)},read(a){const s=`${a}=`,r=document.cookie.split(";");for(let n=0;n<r.length;n++){let o=r[n];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(s)===0)return o.substring(s.length,o.length)}return null},remove(a){this.create(a,"",-1)}};var jm={name:"cookie",lookup(a){let{lookupCookie:s}=a;if(s&&typeof document<"u")return _l.read(s)||void 0},cacheUserLanguage(a,s){let{lookupCookie:r,cookieMinutes:n,cookieDomain:o,cookieOptions:l}=s;r&&typeof document<"u"&&_l.create(r,a,n,o,l)}},Hm={name:"querystring",lookup(a){var n;let{lookupQuerystring:s}=a,r;if(typeof window<"u"){let{search:o}=window.location;!window.location.search&&((n=window.location.hash)==null?void 0:n.indexOf("?"))>-1&&(o=window.location.hash.substring(window.location.hash.indexOf("?")));const c=o.substring(1).split("&");for(let u=0;u<c.length;u++){const m=c[u].indexOf("=");m>0&&c[u].substring(0,m)===s&&(r=c[u].substring(m+1))}}return r}};let Cr=null;const fl=()=>{if(Cr!==null)return Cr;try{Cr=window!=="undefined"&&window.localStorage!==null;const a="i18next.translate.boo";window.localStorage.setItem(a,"foo"),window.localStorage.removeItem(a)}catch{Cr=!1}return Cr};var Wm={name:"localStorage",lookup(a){let{lookupLocalStorage:s}=a;if(s&&fl())return window.localStorage.getItem(s)||void 0},cacheUserLanguage(a,s){let{lookupLocalStorage:r}=s;r&&fl()&&window.localStorage.setItem(r,a)}};let Sr=null;const gl=()=>{if(Sr!==null)return Sr;try{Sr=window!=="undefined"&&window.sessionStorage!==null;const a="i18next.translate.boo";window.sessionStorage.setItem(a,"foo"),window.sessionStorage.removeItem(a)}catch{Sr=!1}return Sr};var Vm={name:"sessionStorage",lookup(a){let{lookupSessionStorage:s}=a;if(s&&gl())return window.sessionStorage.getItem(s)||void 0},cacheUserLanguage(a,s){let{lookupSessionStorage:r}=s;r&&gl()&&window.sessionStorage.setItem(r,a)}},Gm={name:"navigator",lookup(a){const s=[];if(typeof navigator<"u"){const{languages:r,userLanguage:n,language:o}=navigator;if(r)for(let l=0;l<r.length;l++)s.push(r[l]);n&&s.push(n),o&&s.push(o)}return s.length>0?s:void 0}},Xm={name:"htmlTag",lookup(a){let{htmlTag:s}=a,r;const n=s||(typeof document<"u"?document.documentElement:null);return n&&typeof n.getAttribute=="function"&&(r=n.getAttribute("lang")),r}},Ym={name:"path",lookup(a){var o;let{lookupFromPathIndex:s}=a;if(typeof window>"u")return;const r=window.location.pathname.match(/\/([a-zA-Z-]*)/g);return Array.isArray(r)?(o=r[typeof s=="number"?s:0])==null?void 0:o.replace("/",""):void 0}},Qm={name:"subdomain",lookup(a){var o,l;let{lookupFromSubdomainIndex:s}=a;const r=typeof s=="number"?s+1:1,n=typeof window<"u"&&((l=(o=window.location)==null?void 0:o.hostname)==null?void 0:l.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i));if(n)return n[r]}};function Zm(){return{order:["querystring","cookie","localStorage","sessionStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",lookupSessionStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"],convertDetectedLanguage:a=>a}}class bl{constructor(s){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.type="languageDetector",this.detectors={},this.init(s,r)}init(s){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};this.services=s||{languageUtils:{}},this.options=$m(r,this.options||{},Zm()),typeof this.options.convertDetectedLanguage=="string"&&this.options.convertDetectedLanguage.indexOf("15897")>-1&&(this.options.convertDetectedLanguage=o=>o.replace("-","_")),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=n,this.addDetector(jm),this.addDetector(Hm),this.addDetector(Wm),this.addDetector(Vm),this.addDetector(Gm),this.addDetector(Xm),this.addDetector(Ym),this.addDetector(Qm)}addDetector(s){return this.detectors[s.name]=s,this}detect(s){s||(s=this.options.order);let r=[];return s.forEach(n=>{if(this.detectors[n]){let o=this.detectors[n].lookup(this.options);o&&typeof o=="string"&&(o=[o]),o&&(r=r.concat(o))}}),r=r.map(n=>this.options.convertDetectedLanguage(n)),this.services.languageUtils.getBestMatchFromCodes?r:r.length>0?r[0]:null}cacheUserLanguage(s,r){r||(r=this.options.caches),r&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(s)>-1||r.forEach(n=>{this.detectors[n]&&this.detectors[n].cacheUserLanguage(s,this.options)}))}}bl.type="languageDetector";const Jm=(...a)=>{console!=null&&console.warn&&(As(a[0])&&(a[0]=`react-i18next:: ${a[0]}`),console.warn(...a))},xl={},jn=(...a)=>{As(a[0])&&xl[a[0]]||(As(a[0])&&(xl[a[0]]=new Date),Jm(...a))},hl=(a,s)=>()=>{if(a.isInitialized)s();else{const r=()=>{setTimeout(()=>{a.off("initialized",r)},0),s()};a.on("initialized",r)}},Hn=(a,s,r)=>{a.loadNamespaces(s,hl(a,r))},wl=(a,s,r,n)=>{if(As(r)&&(r=[r]),a.options.preload&&a.options.preload.indexOf(s)>-1)return Hn(a,r,n);r.forEach(o=>{a.options.ns.indexOf(o)<0&&a.options.ns.push(o)}),a.loadLanguages(s,hl(a,n))},ey=(a,s,r={})=>!s.languages||!s.languages.length?(jn("i18n.languages were undefined or empty",s.languages),!0):s.hasLoadedNamespace(a,{lng:r.lng,precheck:(n,o)=>{var l;if(((l=r.bindI18n)==null?void 0:l.indexOf("languageChanging"))>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,a))return!1}}),As=a=>typeof a=="string",ty=a=>typeof a=="object"&&a!==null,sy=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,ry={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},ay=a=>ry[a];let Wn={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:a=>a.replace(sy,ay)};const ny=(a={})=>{Wn={...Wn,...a}},iy=()=>Wn;let vl;const oy=a=>{vl=a},ly=()=>vl,cy={type:"3rdParty",init(a){ny(a.options.react),oy(a)}},py=N.createContext();class dy{constructor(){this.usedNamespaces={}}addUsedNamespaces(s){s.forEach(r=>{this.usedNamespaces[r]||(this.usedNamespaces[r]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const uy=(a,s)=>{const r=N.useRef();return N.useEffect(()=>{r.current=s?r.current:a},[a,s]),r.current},Tl=(a,s,r,n)=>a.getFixedT(s,r,n),my=(a,s,r,n)=>N.useCallback(Tl(a,s,r,n),[a,s,r,n]),Ws=(a,s={})=>{var W,Q,C,z;const{i18n:r}=s,{i18n:n,defaultNS:o}=N.useContext(py)||{},l=r||n||ly();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new dy),!l){jn("You will need to pass in an i18next instance by using initReactI18next");const V=(A,L)=>As(L)?L:ty(L)&&As(L.defaultValue)?L.defaultValue:Array.isArray(A)?A[A.length-1]:A,q=[V,{},!1];return q.t=V,q.i18n={},q.ready=!1,q}(W=l.options.react)!=null&&W.wait&&jn("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const c={...iy(),...l.options.react,...s},{useSuspense:u,keyPrefix:m}=c;let _=a||o||((Q=l.options)==null?void 0:Q.defaultNS);_=As(_)?[_]:_||["translation"],(z=(C=l.reportNamespaces).addUsedNamespaces)==null||z.call(C,_);const g=(l.isInitialized||l.initializedStoreOnce)&&_.every(V=>ey(V,l,c)),x=my(l,s.lng||null,c.nsMode==="fallback"?_:_[0],m),h=()=>x,D=()=>Tl(l,s.lng||null,c.nsMode==="fallback"?_:_[0],m),[S,R]=N.useState(h);let U=_.join();s.lng&&(U=`${s.lng}${U}`);const K=uy(U),H=N.useRef(!0);N.useEffect(()=>{const{bindI18n:V,bindI18nStore:q}=c;H.current=!0,!g&&!u&&(s.lng?wl(l,s.lng,_,()=>{H.current&&R(D)}):Hn(l,_,()=>{H.current&&R(D)})),g&&K&&K!==U&&H.current&&R(D);const A=()=>{H.current&&R(D)};return V&&(l==null||l.on(V,A)),q&&(l==null||l.store.on(q,A)),()=>{H.current=!1,l&&(V==null||V.split(" ").forEach(L=>l.off(L,A))),q&&l&&q.split(" ").forEach(L=>l.store.off(L,A))}},[l,U]),N.useEffect(()=>{H.current&&g&&R(h)},[l,m,g]);const re=[S,l,g];if(re.t=S,re.i18n=l,re.ready=g,g||!g&&!u)return re;throw new Promise(V=>{s.lng?wl(l,s.lng,_,()=>V()):Hn(l,_,()=>V())})},yy={type:"type",syntax:"syntax",overloads:"overloads",arguments:"arguments",fields:"fields",example:"example",returns:"returns",remarks:"remarks","see also":"see also","Copy code":"Copy code","Copy link":"Copy link",Copied:"Copied","Link copied":"Link copied",variables:"Variables",constants:"Constants",functions:"Functions",keywords:"Keywords",types:"Types",operators:"Operators",annotations:"Annotations",search:"Search","Mine Script® v1 Reference Manual":"Mine Script® v1 Reference Manual","This script is read-only. It cannot be edited.":"This script is read-only. It cannot be edited.","save script":"Save script","open script":"Open script","find/replace":"Find/Replace","toggle console":"Toggle console","open editor in new tab":"Open editor in new tab","open editor in new window":"Open editor in new window",keyword:"keyword","built-in function":"built-in function","built-in variable":"built-in variable","built-in method":"built-in method","built-in type":"built-in type",annotation:"annotation","built-in constant":"built-in constant",namespace:"namespace","user-defined variable":"user-defined variable","user-defined type":"user-defined type",field:"field",enum:"enum","user-defined method":"user-defined method","user-defined function":"user-defined function",parameter:"parameter","**Namespaces** are immutable terms that act as prefixes for groups of identifiers. A dot and another term always follow a namespace when naming Tcc functions, variables, and methods.":"**Namespaces** are immutable terms that act as prefixes for groups of identifiers. A dot and another term always follow a namespace when naming Mine functions, variables, and methods.","to trigger parameters hint":"to trigger parameters hint",library:"library","enum member":"enum member",Returns:"Returns",Syntax:"Syntax",Remarks:"Remarks",Fields:"Fields",Description:"Description",Example:"Example","Enum members":"Enum members",statement:"statement",loop:"loop","`click` on keyword for more help":"`click` on keyword for more help"},_y={type:"类型",syntax:"语法",overloads:"重载",arguments:"参数",fields:"字段",example:"例子",returns:"返回值",remarks:"备注","see also":"另见","Copy code":"复制代码","Copy link":"复制链接",Copied:"已复制","Link copied":"链接已复制",variables:"内置变量",constants:"常量",functions:"函数",keywords:"关键词",types:"类型",operators:"运算符",annotations:"注释",search:"搜索","Mine Script® v1 Reference Manual":"Mine Script™ v1参考手册","This script is read-only. It cannot be edited.":"该脚本是只读的。它无法被编辑。","save script":"保存脚本","open script":"打开脚本","find/replace":"寻找/替换","toggle console":"切换控制台","open editor in new tab":"在新标签页中打开","open editor in new window":"在新窗口中打开",keyword:"关键词","built-in function":"内置函数","built-in variable":"内置变量","built-in method":"内置方法","built-in type":"内置类型",annotation:"注释","built-in constant":"内置常量",namespace:"命名空间","user-defined variable":"用户自定义变量","user-defined type":"用户自定义类型",field:"字段",enum:"枚举","user-defined method":"用户自定义方法","user-defined function":"用户自定义函数",parameter:"参数","**Namespaces** are immutable terms that act as prefixes for groups of identifiers. A dot and another term always follow a namespace when naming Tcc functions, variables, and methods.":"命名空间是不可变的术语,充当标识符组的前缀。在命名Mine函数、变量和方法时,点和另一个术语始终遵循命名空间。","to trigger parameters hint":"触发参数提示",library:"脚本库","enum member":"枚举成员",Returns:"返回值",Syntax:"语法",Remarks:"备注",Fields:"字段",Description:"描述",Example:"例子","Enum members":"枚举成员",statement:"声明",loop:"循环","`click` on keyword for more help":"“点击”关键词以获得更多帮助"};Me.use(bl).use(cy).init({debug:!1,fallbackLng:"zh",interpolation:{escapeValue:!1},resources:{en:{translation:yy},zh:{translation:_y}}}),self.MonacoEnvironment={getWorker(){return new Fm({name:"Editor Worker"})}},In.config({paths:{vs:"https://my.tradingvue.com/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fy=(a,s)=>{const{height:r,width:n,theme:o,options:l,hasDiff:c,readOnly:u,defaultValue:m,language:_,onChange:g,onLinkOpen:x,onCursorPositionChange:h,onActionTrigger:D,onEditorDidMount:S}=a,{t:R,i18n:U}=Ws(),K=N.useRef(null),H=N.useRef(null),re=N.useRef(!1),W=N.useRef(!1);N.useImperativeHandle(s,()=>({setOriginalScript(A){var L;(L=K.current)==null||L.setOriginalScript(A)},setScript(A){var L;(L=K.current)==null||L.setValue(A)},gotoLine(){var A;(A=K.current)==null||A.gotoLine()},getEditorLayout(){var A;return(A=K.current)==null?void 0:A.getEditorLayout()},setPosition(A,L){var Z;(Z=K.current)==null||Z.setPosition({column:A,lineNumber:L})},setModelMarkers(A){var L;W.current=!0,(L=K.current)==null||L.setModelMarkers(A),setTimeout(()=>{W.current=!1},2e3)},focus(){var A;(A=K.current)==null||A.focus()}})),N.useEffect(()=>{var A,L;c?(L=K.current)==null||L.addDiffDecorations():(A=K.current)==null||A.removeDiffDecorations()},[c]),N.useEffect(()=>{o&&Ne.editor.setTheme(o)},[o]),N.useEffect(()=>{_&&U.changeLanguage(_)},[_]),N.useEffect(()=>{var A;(A=K.current)==null||A.updateActionTrigger(D)},[D]),N.useEffect(()=>{var A;x&&((A=K.current)==null||A.addLinkOpenFunc(x))},[x]);function Q(A,L){var ee,ne;Pt.initBuiltinsTrees(),_a.setEditor(A),K.current=new km(A,L,D),x&&((ee=K.current)==null||ee.addLinkOpenFunc(x)),c&&((ne=K.current)==null||ne.addDiffDecorations()),Gu(A),requestAnimationFrame(q);const Z=A.getValue();K.current.onChangeCursorPosition(h),g&&g(Z),!u&&C(Z),S&&S()}const C=N.useCallback(async A=>{var Rt;re.current=!1;const{errors:L,functions:Z,methods:ee,types:ne,variables:Y,overloadsFuncs:le,imports:xe,enums:pe}=await ml(A),_e=new Map(Object.entries(Z)),Ee=new Map(Object.entries(ee)),te=new Map(Object.entries(ne)),de=new Map(Object.entries(Y)),Oe=new Map(Object.entries(xe)),Ge=new Map(Object.entries(pe));Ds.setUserDefined({functions:_e,methods:Ee,types:te,variables:de,imports:Oe,enums:Ge},le),Pt.setUserDefind(_e,te,de,Ee,Ge);const Qe=L.map(us=>({...us,severity:us.type||Ne.MarkerSeverity.Error}));u||!re.current&&!W.current&&Qe.length&&((Rt=K.current)==null||Rt.setModelMarkers(Qe))},[u]),z=N.useMemo(()=>Qu.debounce(C,1500),[C]);function V(A){var L;if(u){C(A||"");return}re.current=!0,_a.clearInlayHints(),(L=K.current)==null||L.setModelMarkers([]),A!==void 0&&(g&&g(A),z(A))}const q=N.useCallback(()=>{var L,Z;const A=(L=H.current)==null?void 0:L.getBoundingClientRect();(Z=K.current)==null||Z.setEditorLayout((A==null?void 0:A.height)||0,A==null?void 0:A.width)},[]);return N.useEffect(()=>{const A=()=>{window.requestAnimationFrame(q)},L=new ResizeObserver(A);return H.current&&L.observe(H.current),()=>{var Z;H.current&&L.unobserve(H.current),L.disconnect(),(Z=K.current)==null||Z.dispose()}},[]),T.jsx("div",{ref:H,children:T.jsx(mu,{height:r,width:n||"100%",defaultLanguage:Ke,defaultValue:m||`indicator("我的脚本")
|
144
|
+
*/const tl=Symbol("Comlink.proxy"),Dm=Symbol("Comlink.endpoint"),Im=Symbol("Comlink.releaseProxy"),Bn=Symbol("Comlink.finalizer"),ba=Symbol("Comlink.thrown"),sl=a=>typeof a=="object"&&a!==null||typeof a=="function",Am={canHandle:a=>sl(a)&&a[tl],serialize(a){const{port1:s,port2:r}=new MessageChannel;return al(a,s),[r,[r]]},deserialize(a){return a.start(),Un(a)}},qm={canHandle:a=>sl(a)&&ba in a,serialize({value:a}){let s;return a instanceof Error?s={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:s={isError:!1,value:a},[s,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},rl=new Map([["proxy",Am],["throw",qm]]);function Cm(a,s){for(const r of a)if(s===r||r==="*"||r instanceof RegExp&&r.test(s))return!0;return!1}function al(a,s=globalThis,r=["*"]){s.addEventListener("message",function n(o){if(!o||!o.data)return;if(!Cm(r,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:l,type:c,path:u}=Object.assign({path:[]},o.data),m=(o.data.argumentList||[]).map(Is);let _;try{const g=u.slice(0,-1).reduce((h,D)=>h[D],a),x=u.reduce((h,D)=>h[D],a);switch(c){case"GET":_=x;break;case"SET":g[u.slice(-1)[0]]=Is(o.data.value),_=!0;break;case"APPLY":_=x.apply(g,m);break;case"CONSTRUCT":{const h=new x(...m);_=Kn(h)}break;case"ENDPOINT":{const{port1:h,port2:D}=new MessageChannel;al(a,D),_=Lm(h,[h])}break;case"RELEASE":_=void 0;break;default:return}}catch(g){_={value:g,[ba]:0}}Promise.resolve(_).catch(g=>({value:g,[ba]:0})).then(g=>{const[x,h]=va(g);s.postMessage(Object.assign(Object.assign({},x),{id:l}),h),c==="RELEASE"&&(s.removeEventListener("message",n),nl(s),Bn in a&&typeof a[Bn]=="function"&&a[Bn]())}).catch(g=>{const[x,h]=va({value:new TypeError("Unserializable return value"),[ba]:0});s.postMessage(Object.assign(Object.assign({},x),{id:l}),h)})}),s.start&&s.start()}function Sm(a){return a.constructor.name==="MessagePort"}function nl(a){Sm(a)&&a.close()}function Un(a,s){return $n(a,[],s)}function xa(a){if(a)throw new Error("Proxy has been released and is not useable")}function il(a){return Hs(a,{type:"RELEASE"}).then(()=>{nl(a)})}const ha=new WeakMap,wa="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const s=(ha.get(a)||0)-1;ha.set(a,s),s===0&&il(a)});function zm(a,s){const r=(ha.get(s)||0)+1;ha.set(s,r),wa&&wa.register(a,s,a)}function Nm(a){wa&&wa.unregister(a)}function $n(a,s=[],r=function(){}){let n=!1;const o=new Proxy(r,{get(l,c){if(xa(n),c===Im)return()=>{Nm(o),il(a),n=!0};if(c==="then"){if(s.length===0)return{then:()=>o};const u=Hs(a,{type:"GET",path:s.map(m=>m.toString())}).then(Is);return u.then.bind(u)}return $n(a,[...s,c])},set(l,c,u){xa(n);const[m,_]=va(u);return Hs(a,{type:"SET",path:[...s,c].map(g=>g.toString()),value:m},_).then(Is)},apply(l,c,u){xa(n);const m=s[s.length-1];if(m===Dm)return Hs(a,{type:"ENDPOINT"}).then(Is);if(m==="bind")return $n(a,s.slice(0,-1));const[_,g]=ol(u);return Hs(a,{type:"APPLY",path:s.map(x=>x.toString()),argumentList:_},g).then(Is)},construct(l,c){xa(n);const[u,m]=ol(c);return Hs(a,{type:"CONSTRUCT",path:s.map(_=>_.toString()),argumentList:u},m).then(Is)}});return zm(o,a),o}function Em(a){return Array.prototype.concat.apply([],a)}function ol(a){const s=a.map(va);return[s.map(r=>r[0]),Em(s.map(r=>r[1]))]}const ll=new WeakMap;function Lm(a,s){return ll.set(a,s),a}function Kn(a){return Object.assign(a,{[tl]:!0})}function va(a){for(const[s,r]of rl)if(r.canHandle(a)){const[n,o]=r.serialize(a);return[{type:"HANDLER",name:s,value:n},o]}return[{type:"RAW",value:a},ll.get(a)||[]]}function Is(a){switch(a.type){case"HANDLER":return rl.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Hs(a,s,r){return new Promise(n=>{const o=Mm();a.addEventListener("message",function l(c){!c.data||!c.data.id||c.data.id!==o||(a.removeEventListener("message",l),n(c.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:o},s),r)})}function Mm(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const cl=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-CeIoGWzf.js").href:new URL("assets/scriptsRunWorker-CeIoGWzf.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:ra&&ra.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});cl.onerror=a=>{console.error(a)};async function pl(a){return await _a.setInlayHints(a)}const dl=Un(cl),ul=Un(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-DF7HO8qN.js").href:new URL("assets/parserTccWorker-DF7HO8qN.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:ra&&ra.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function ml(a,s=!1){const{functions:r,types:n,constants:o,variables:l,methods:c}=nt;return await ul.parseTcc(a,s,Kn(pl),{functions:Object.fromEntries(r),methods:Object.fromEntries(c),types:Object.fromEntries(n),constants:Object.fromEntries(o),variables:Object.fromEntries(l)})}async function Om(a,s){const{functions:r,types:n,constants:o,variables:l,methods:c}=nt;return await ul.parseLibraryCode(a,s,Kn(pl),{functions:Object.fromEntries(r),methods:Object.fromEntries(c),types:Object.fromEntries(n),constants:Object.fromEntries(o),variables:Object.fromEntries(l)})}async function Pm(a,s,r=!0){return await dl.runScript(a,s,r)}async function Rm(a){return await dl.removeScript(a)}function Fm(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})}const{slice:Bm,forEach:Um}=[];function $m(a){return Um.call(Bm.call(arguments,1),s=>{if(s)for(const r in s)a[r]===void 0&&(a[r]=s[r])}),a}const yl=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,Km=(a,s,r)=>{const n=r||{};n.path=n.path||"/";const o=encodeURIComponent(s);let l=`${a}=${o}`;if(n.maxAge>0){const c=n.maxAge-0;if(Number.isNaN(c))throw new Error("maxAge should be a Number");l+=`; Max-Age=${Math.floor(c)}`}if(n.domain){if(!yl.test(n.domain))throw new TypeError("option domain is invalid");l+=`; Domain=${n.domain}`}if(n.path){if(!yl.test(n.path))throw new TypeError("option path is invalid");l+=`; Path=${n.path}`}if(n.expires){if(typeof n.expires.toUTCString!="function")throw new TypeError("option expires is invalid");l+=`; Expires=${n.expires.toUTCString()}`}if(n.httpOnly&&(l+="; HttpOnly"),n.secure&&(l+="; Secure"),n.sameSite)switch(typeof n.sameSite=="string"?n.sameSite.toLowerCase():n.sameSite){case!0:l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"strict":l+="; SameSite=Strict";break;case"none":l+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return l},_l={create(a,s,r,n){let o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{path:"/",sameSite:"strict"};r&&(o.expires=new Date,o.expires.setTime(o.expires.getTime()+r*60*1e3)),n&&(o.domain=n),document.cookie=Km(a,encodeURIComponent(s),o)},read(a){const s=`${a}=`,r=document.cookie.split(";");for(let n=0;n<r.length;n++){let o=r[n];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(s)===0)return o.substring(s.length,o.length)}return null},remove(a){this.create(a,"",-1)}};var jm={name:"cookie",lookup(a){let{lookupCookie:s}=a;if(s&&typeof document<"u")return _l.read(s)||void 0},cacheUserLanguage(a,s){let{lookupCookie:r,cookieMinutes:n,cookieDomain:o,cookieOptions:l}=s;r&&typeof document<"u"&&_l.create(r,a,n,o,l)}},Hm={name:"querystring",lookup(a){var n;let{lookupQuerystring:s}=a,r;if(typeof window<"u"){let{search:o}=window.location;!window.location.search&&((n=window.location.hash)==null?void 0:n.indexOf("?"))>-1&&(o=window.location.hash.substring(window.location.hash.indexOf("?")));const c=o.substring(1).split("&");for(let u=0;u<c.length;u++){const m=c[u].indexOf("=");m>0&&c[u].substring(0,m)===s&&(r=c[u].substring(m+1))}}return r}};let Cr=null;const fl=()=>{if(Cr!==null)return Cr;try{Cr=window!=="undefined"&&window.localStorage!==null;const a="i18next.translate.boo";window.localStorage.setItem(a,"foo"),window.localStorage.removeItem(a)}catch{Cr=!1}return Cr};var Wm={name:"localStorage",lookup(a){let{lookupLocalStorage:s}=a;if(s&&fl())return window.localStorage.getItem(s)||void 0},cacheUserLanguage(a,s){let{lookupLocalStorage:r}=s;r&&fl()&&window.localStorage.setItem(r,a)}};let Sr=null;const gl=()=>{if(Sr!==null)return Sr;try{Sr=window!=="undefined"&&window.sessionStorage!==null;const a="i18next.translate.boo";window.sessionStorage.setItem(a,"foo"),window.sessionStorage.removeItem(a)}catch{Sr=!1}return Sr};var Vm={name:"sessionStorage",lookup(a){let{lookupSessionStorage:s}=a;if(s&&gl())return window.sessionStorage.getItem(s)||void 0},cacheUserLanguage(a,s){let{lookupSessionStorage:r}=s;r&&gl()&&window.sessionStorage.setItem(r,a)}},Gm={name:"navigator",lookup(a){const s=[];if(typeof navigator<"u"){const{languages:r,userLanguage:n,language:o}=navigator;if(r)for(let l=0;l<r.length;l++)s.push(r[l]);n&&s.push(n),o&&s.push(o)}return s.length>0?s:void 0}},Xm={name:"htmlTag",lookup(a){let{htmlTag:s}=a,r;const n=s||(typeof document<"u"?document.documentElement:null);return n&&typeof n.getAttribute=="function"&&(r=n.getAttribute("lang")),r}},Ym={name:"path",lookup(a){var o;let{lookupFromPathIndex:s}=a;if(typeof window>"u")return;const r=window.location.pathname.match(/\/([a-zA-Z-]*)/g);return Array.isArray(r)?(o=r[typeof s=="number"?s:0])==null?void 0:o.replace("/",""):void 0}},Qm={name:"subdomain",lookup(a){var o,l;let{lookupFromSubdomainIndex:s}=a;const r=typeof s=="number"?s+1:1,n=typeof window<"u"&&((l=(o=window.location)==null?void 0:o.hostname)==null?void 0:l.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i));if(n)return n[r]}};function Zm(){return{order:["querystring","cookie","localStorage","sessionStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",lookupSessionStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"],convertDetectedLanguage:a=>a}}class bl{constructor(s){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.type="languageDetector",this.detectors={},this.init(s,r)}init(s){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};this.services=s||{languageUtils:{}},this.options=$m(r,this.options||{},Zm()),typeof this.options.convertDetectedLanguage=="string"&&this.options.convertDetectedLanguage.indexOf("15897")>-1&&(this.options.convertDetectedLanguage=o=>o.replace("-","_")),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=n,this.addDetector(jm),this.addDetector(Hm),this.addDetector(Wm),this.addDetector(Vm),this.addDetector(Gm),this.addDetector(Xm),this.addDetector(Ym),this.addDetector(Qm)}addDetector(s){return this.detectors[s.name]=s,this}detect(s){s||(s=this.options.order);let r=[];return s.forEach(n=>{if(this.detectors[n]){let o=this.detectors[n].lookup(this.options);o&&typeof o=="string"&&(o=[o]),o&&(r=r.concat(o))}}),r=r.map(n=>this.options.convertDetectedLanguage(n)),this.services.languageUtils.getBestMatchFromCodes?r:r.length>0?r[0]:null}cacheUserLanguage(s,r){r||(r=this.options.caches),r&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(s)>-1||r.forEach(n=>{this.detectors[n]&&this.detectors[n].cacheUserLanguage(s,this.options)}))}}bl.type="languageDetector";const Jm=(...a)=>{console!=null&&console.warn&&(As(a[0])&&(a[0]=`react-i18next:: ${a[0]}`),console.warn(...a))},xl={},jn=(...a)=>{As(a[0])&&xl[a[0]]||(As(a[0])&&(xl[a[0]]=new Date),Jm(...a))},hl=(a,s)=>()=>{if(a.isInitialized)s();else{const r=()=>{setTimeout(()=>{a.off("initialized",r)},0),s()};a.on("initialized",r)}},Hn=(a,s,r)=>{a.loadNamespaces(s,hl(a,r))},wl=(a,s,r,n)=>{if(As(r)&&(r=[r]),a.options.preload&&a.options.preload.indexOf(s)>-1)return Hn(a,r,n);r.forEach(o=>{a.options.ns.indexOf(o)<0&&a.options.ns.push(o)}),a.loadLanguages(s,hl(a,n))},ey=(a,s,r={})=>!s.languages||!s.languages.length?(jn("i18n.languages were undefined or empty",s.languages),!0):s.hasLoadedNamespace(a,{lng:r.lng,precheck:(n,o)=>{var l;if(((l=r.bindI18n)==null?void 0:l.indexOf("languageChanging"))>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,a))return!1}}),As=a=>typeof a=="string",ty=a=>typeof a=="object"&&a!==null,sy=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,ry={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},ay=a=>ry[a];let Wn={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:a=>a.replace(sy,ay)};const ny=(a={})=>{Wn={...Wn,...a}},iy=()=>Wn;let vl;const oy=a=>{vl=a},ly=()=>vl,cy={type:"3rdParty",init(a){ny(a.options.react),oy(a)}},py=N.createContext();class dy{constructor(){this.usedNamespaces={}}addUsedNamespaces(s){s.forEach(r=>{this.usedNamespaces[r]||(this.usedNamespaces[r]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const uy=(a,s)=>{const r=N.useRef();return N.useEffect(()=>{r.current=s?r.current:a},[a,s]),r.current},Tl=(a,s,r,n)=>a.getFixedT(s,r,n),my=(a,s,r,n)=>N.useCallback(Tl(a,s,r,n),[a,s,r,n]),Ws=(a,s={})=>{var W,Q,C,z;const{i18n:r}=s,{i18n:n,defaultNS:o}=N.useContext(py)||{},l=r||n||ly();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new dy),!l){jn("You will need to pass in an i18next instance by using initReactI18next");const V=(A,L)=>As(L)?L:ty(L)&&As(L.defaultValue)?L.defaultValue:Array.isArray(A)?A[A.length-1]:A,q=[V,{},!1];return q.t=V,q.i18n={},q.ready=!1,q}(W=l.options.react)!=null&&W.wait&&jn("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const c={...iy(),...l.options.react,...s},{useSuspense:u,keyPrefix:m}=c;let _=a||o||((Q=l.options)==null?void 0:Q.defaultNS);_=As(_)?[_]:_||["translation"],(z=(C=l.reportNamespaces).addUsedNamespaces)==null||z.call(C,_);const g=(l.isInitialized||l.initializedStoreOnce)&&_.every(V=>ey(V,l,c)),x=my(l,s.lng||null,c.nsMode==="fallback"?_:_[0],m),h=()=>x,D=()=>Tl(l,s.lng||null,c.nsMode==="fallback"?_:_[0],m),[S,R]=N.useState(h);let U=_.join();s.lng&&(U=`${s.lng}${U}`);const K=uy(U),H=N.useRef(!0);N.useEffect(()=>{const{bindI18n:V,bindI18nStore:q}=c;H.current=!0,!g&&!u&&(s.lng?wl(l,s.lng,_,()=>{H.current&&R(D)}):Hn(l,_,()=>{H.current&&R(D)})),g&&K&&K!==U&&H.current&&R(D);const A=()=>{H.current&&R(D)};return V&&(l==null||l.on(V,A)),q&&(l==null||l.store.on(q,A)),()=>{H.current=!1,l&&(V==null||V.split(" ").forEach(L=>l.off(L,A))),q&&l&&q.split(" ").forEach(L=>l.store.off(L,A))}},[l,U]),N.useEffect(()=>{H.current&&g&&R(h)},[l,m,g]);const re=[S,l,g];if(re.t=S,re.i18n=l,re.ready=g,g||!g&&!u)return re;throw new Promise(V=>{s.lng?wl(l,s.lng,_,()=>V()):Hn(l,_,()=>V())})},yy={type:"type",syntax:"syntax",overloads:"overloads",arguments:"arguments",fields:"fields",example:"example",returns:"returns",remarks:"remarks","see also":"see also","Copy code":"Copy code","Copy link":"Copy link",Copied:"Copied","Link copied":"Link copied",variables:"Variables",constants:"Constants",functions:"Functions",keywords:"Keywords",types:"Types",operators:"Operators",annotations:"Annotations",search:"Search","Mine Script® v1 Reference Manual":"Mine Script® v1 Reference Manual","This script is read-only. It cannot be edited.":"This script is read-only. It cannot be edited.","save script":"Save script","open script":"Open script","find/replace":"Find/Replace","toggle console":"Toggle console","open editor in new tab":"Open editor in new tab","open editor in new window":"Open editor in new window",keyword:"keyword","built-in function":"built-in function","built-in variable":"built-in variable","built-in method":"built-in method","built-in type":"built-in type",annotation:"annotation","built-in constant":"built-in constant",namespace:"namespace","user-defined variable":"user-defined variable","user-defined type":"user-defined type",field:"field",enum:"enum","user-defined method":"user-defined method","user-defined function":"user-defined function",parameter:"parameter","**Namespaces** are immutable terms that act as prefixes for groups of identifiers. A dot and another term always follow a namespace when naming Tcc functions, variables, and methods.":"**Namespaces** are immutable terms that act as prefixes for groups of identifiers. A dot and another term always follow a namespace when naming Mine functions, variables, and methods.","to trigger parameters hint":"to trigger parameters hint",library:"library","enum member":"enum member",Returns:"Returns",Syntax:"Syntax",Remarks:"Remarks",Fields:"Fields",Description:"Description",Example:"Example","Enum members":"Enum members",statement:"statement",loop:"loop","`click` on keyword for more help":"`click` on keyword for more help"},_y={type:"类型",syntax:"语法",overloads:"重载",arguments:"参数",fields:"字段",example:"例子",returns:"返回值",remarks:"备注","see also":"另见","Copy code":"复制代码","Copy link":"复制链接",Copied:"已复制","Link copied":"链接已复制",variables:"内置变量",constants:"常量",functions:"函数",keywords:"关键词",types:"类型",operators:"运算符",annotations:"注释",search:"搜索","Mine Script® v1 Reference Manual":"Mine Script™ v1参考手册","This script is read-only. It cannot be edited.":"该脚本是只读的。它无法被编辑。","save script":"保存脚本","open script":"打开脚本","find/replace":"寻找/替换","toggle console":"切换控制台","open editor in new tab":"在新标签页中打开","open editor in new window":"在新窗口中打开",keyword:"关键词","built-in function":"内置函数","built-in variable":"内置变量","built-in method":"内置方法","built-in type":"内置类型",annotation:"注释","built-in constant":"内置常量",namespace:"命名空间","user-defined variable":"用户自定义变量","user-defined type":"用户自定义类型",field:"字段",enum:"枚举","user-defined method":"用户自定义方法","user-defined function":"用户自定义函数",parameter:"参数","**Namespaces** are immutable terms that act as prefixes for groups of identifiers. A dot and another term always follow a namespace when naming Tcc functions, variables, and methods.":"命名空间是不可变的术语,充当标识符组的前缀。在命名Mine函数、变量和方法时,点和另一个术语始终遵循命名空间。","to trigger parameters hint":"触发参数提示",library:"脚本库","enum member":"枚举成员",Returns:"返回值",Syntax:"语法",Remarks:"备注",Fields:"字段",Description:"描述",Example:"例子","Enum members":"枚举成员",statement:"声明",loop:"循环","`click` on keyword for more help":"“点击”关键词以获得更多帮助"};Me.use(bl).use(cy).init({debug:!1,fallbackLng:"zh",interpolation:{escapeValue:!1},resources:{en:{translation:yy},zh:{translation:_y}}}),self.MonacoEnvironment={getWorker(){return new Fm({name:"Editor Worker"})}},In.config({paths:{vs:"https://my.tradingvue.com/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fy=(a,s)=>{const{height:r,width:n,theme:o,options:l,hasDiff:c,readOnly:u,defaultValue:m,language:_,onChange:g,onLinkOpen:x,onCursorPositionChange:h,onActionTrigger:D,onEditorDidMount:S}=a,{t:R,i18n:U}=Ws(),K=N.useRef(null),H=N.useRef(null),re=N.useRef(!1),W=N.useRef(!1);N.useImperativeHandle(s,()=>({setOriginalScript(A){var L;(L=K.current)==null||L.setOriginalScript(A)},setScript(A){var L;(L=K.current)==null||L.setValue(A)},gotoLine(){var A;(A=K.current)==null||A.gotoLine()},getEditorLayout(){var A;return(A=K.current)==null?void 0:A.getEditorLayout()},setPosition(A,L){var Z;(Z=K.current)==null||Z.setPosition({column:A,lineNumber:L})},setModelMarkers(A){var L;W.current=!0,(L=K.current)==null||L.setModelMarkers(A),setTimeout(()=>{W.current=!1},2e3)},focus(){var A;(A=K.current)==null||A.focus()}})),N.useEffect(()=>{var A,L;c?(L=K.current)==null||L.addDiffDecorations():(A=K.current)==null||A.removeDiffDecorations()},[c]),N.useEffect(()=>{o&&Ne.editor.setTheme(o)},[o]),N.useEffect(()=>{_&&U.changeLanguage(_)},[_]),N.useEffect(()=>{var A;(A=K.current)==null||A.updateActionTrigger(D)},[D]),N.useEffect(()=>{var A;x&&((A=K.current)==null||A.addLinkOpenFunc(x))},[x]);function Q(A,L){var ee,ne;Pt.initBuiltinsTrees(),_a.setEditor(A),K.current=new km(A,L,D),x&&((ee=K.current)==null||ee.addLinkOpenFunc(x)),c&&((ne=K.current)==null||ne.addDiffDecorations()),Gu(A),requestAnimationFrame(q);const Z=A.getValue();K.current.onChangeCursorPosition(h),g&&g(Z),!u&&C(Z),S&&S()}const C=N.useCallback(async A=>{var Rt;re.current=!1;const{errors:L,functions:Z,methods:ee,types:ne,variables:Y,overloadsFuncs:le,imports:xe,enums:pe}=await ml(A),_e=new Map(Object.entries(Z)),Ee=new Map(Object.entries(ee)),te=new Map(Object.entries(ne)),de=new Map(Object.entries(Y)),Oe=new Map(Object.entries(xe)),Ge=new Map(Object.entries(pe));Ds.setUserDefined({functions:_e,methods:Ee,types:te,variables:de,imports:Oe,enums:Ge},le),Pt.setUserDefind(_e,te,de,Ee,Ge);const Qe=L.map(us=>({...us,severity:us.type||Ne.MarkerSeverity.Error}));u||!re.current&&!W.current&&Qe.length&&((Rt=K.current)==null||Rt.setModelMarkers(Qe))},[u]),z=N.useMemo(()=>Qu.debounce(C,1500),[C]);function V(A){var L;if(u){C(A||"");return}re.current=!0,_a.clearInlayHints(),(L=K.current)==null||L.setModelMarkers([]),A!==void 0&&(g&&g(A),z(A))}const q=N.useCallback(()=>{var L,Z;const A=(L=H.current)==null?void 0:L.getBoundingClientRect();(Z=K.current)==null||Z.setEditorLayout((A==null?void 0:A.height)||0,A==null?void 0:A.width)},[]);return N.useEffect(()=>{const A=()=>{window.requestAnimationFrame(q)},L=new ResizeObserver(A);return H.current&&L.observe(H.current),()=>{var Z;H.current&&L.unobserve(H.current),L.disconnect(),(Z=K.current)==null||Z.dispose()}},[]),T.jsx("div",{ref:H,children:T.jsx(mu,{height:r,width:n||"100%",defaultLanguage:Ke,defaultValue:m||`indicator("我的脚本")
|
145
145
|
plot(close)
|
146
146
|
`,theme:o||"vs-dark",className:`tvue-script ${o||"vs-dark"}`,options:{colorDecorators:!0,useShadowDOM:!1,matchOnWordStartOnly:!0,automaticLayout:!1,unicodeHighlight:{allowedCharacters:{" ":!0}},suggest:{filterGraceful:!0},fontSize:13,...u?am:{},readOnlyMessage:{value:R("This script is read-only. It cannot be edited.")},...l},onMount:Q,onChange:V})})},gy=N.forwardRef(fy),by=a=>{const{theme:s,modified:r,original:n,height:o,width:l,renderSideBySide:c=!0}=a,u=N.useCallback((m,_)=>{_.languages.register({id:Ke}),_.editor.defineTheme("vs-dark",Mn),_.editor.defineTheme("vs",Ln),_.languages.setMonarchTokensProvider(Ke,js),_.languages.setLanguageConfiguration(Ke,En)},[]);return T.jsx(lu,{height:o||"90vh",width:l||"100%",theme:s||"vs-dark",options:{readOnly:!0,renderSideBySide:c,scrollBeyondLastLine:!1},language:Ke,modified:r,original:n,onMount:u})};M.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"}(M.VMarkerSeverity||(M.VMarkerSeverity={}));var Ta={},xy=function(){var a=document.getSelection();if(!a.rangeCount)return function(){};for(var s=document.activeElement,r=[],n=0;n<a.rangeCount;n++)r.push(a.getRangeAt(n));switch(s.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":s.blur();break;default:s=null;break}return a.removeAllRanges(),function(){a.type==="Caret"&&a.removeAllRanges(),a.rangeCount||r.forEach(function(o){a.addRange(o)}),s&&s.focus()}},hy=xy,kl={"text/plain":"Text","text/html":"Url",default:"Text"},wy="Copy to clipboard: #{key}, Enter";function vy(a){var s=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return a.replace(/#{\s*key\s*}/g,s)}function Ty(a,s){var r,n,o,l,c,u,m=!1;s||(s={}),r=s.debug||!1;try{o=hy(),l=document.createRange(),c=document.getSelection(),u=document.createElement("span"),u.textContent=a,u.ariaHidden="true",u.style.all="unset",u.style.position="fixed",u.style.top=0,u.style.clip="rect(0, 0, 0, 0)",u.style.whiteSpace="pre",u.style.webkitUserSelect="text",u.style.MozUserSelect="text",u.style.msUserSelect="text",u.style.userSelect="text",u.addEventListener("copy",function(g){if(g.stopPropagation(),s.format)if(g.preventDefault(),typeof g.clipboardData>"u"){r&&console.warn("unable to use e.clipboardData"),r&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var x=kl[s.format]||kl.default;window.clipboardData.setData(x,a)}else g.clipboardData.clearData(),g.clipboardData.setData(s.format,a);s.onCopy&&(g.preventDefault(),s.onCopy(g.clipboardData))}),document.body.appendChild(u),l.selectNodeContents(u),c.addRange(l);var _=document.execCommand("copy");if(!_)throw new Error("copy command was unsuccessful");m=!0}catch(g){r&&console.error("unable to copy using execCommand: ",g),r&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(s.format||"text",a),s.onCopy&&s.onCopy(window.clipboardData),m=!0}catch(x){r&&console.error("unable to copy using clipboardData: ",x),r&&console.error("falling back to prompt"),n=vy("message"in s?s.message:wy),window.prompt(n,a)}}finally{c&&(typeof c.removeRange=="function"?c.removeRange(l):c.removeAllRanges()),u&&document.body.removeChild(u),o()}return m}var ky=Ty;function Vn(a){"@babel/helpers - typeof";return Vn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Vn(a)}Object.defineProperty(Ta,"__esModule",{value:!0}),Ta.CopyToClipboard=void 0;var ka=Dl(N),Dy=Dl(ky),Iy=["text","onCopy","options","children"];function Dl(a){return a&&a.__esModule?a:{default:a}}function Il(a,s){var r=Object.keys(a);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);s&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(a,o).enumerable})),r.push.apply(r,n)}return r}function Al(a){for(var s=1;s<arguments.length;s++){var r=arguments[s]!=null?arguments[s]:{};s%2?Il(Object(r),!0).forEach(function(n){Xn(a,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(r)):Il(Object(r)).forEach(function(n){Object.defineProperty(a,n,Object.getOwnPropertyDescriptor(r,n))})}return a}function Ay(a,s){if(a==null)return{};var r=qy(a,s),n,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(a);for(o=0;o<l.length;o++)n=l[o],!(s.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(a,n)&&(r[n]=a[n])}return r}function qy(a,s){if(a==null)return{};var r={},n=Object.keys(a),o,l;for(l=0;l<n.length;l++)o=n[l],!(s.indexOf(o)>=0)&&(r[o]=a[o]);return r}function Cy(a,s){if(!(a instanceof s))throw new TypeError("Cannot call a class as a function")}function ql(a,s){for(var r=0;r<s.length;r++){var n=s[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(a,n.key,n)}}function Sy(a,s,r){return s&&ql(a.prototype,s),r&&ql(a,r),Object.defineProperty(a,"prototype",{writable:!1}),a}function zy(a,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(s&&s.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),s&&Gn(a,s)}function Gn(a,s){return Gn=Object.setPrototypeOf||function(n,o){return n.__proto__=o,n},Gn(a,s)}function Ny(a){var s=Ly();return function(){var n=Da(a),o;if(s){var l=Da(this).constructor;o=Reflect.construct(n,arguments,l)}else o=n.apply(this,arguments);return Ey(this,o)}}function Ey(a,s){if(s&&(Vn(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Cl(a)}function Cl(a){if(a===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function Ly(){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 Da(a){return Da=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},Da(a)}function Xn(a,s,r){return s in a?Object.defineProperty(a,s,{value:r,enumerable:!0,configurable:!0,writable:!0}):a[s]=r,a}var Sl=function(a){zy(r,a);var s=Ny(r);function r(){var n;Cy(this,r);for(var o=arguments.length,l=new Array(o),c=0;c<o;c++)l[c]=arguments[c];return n=s.call.apply(s,[this].concat(l)),Xn(Cl(n),"onClick",function(u){var m=n.props,_=m.text,g=m.onCopy,x=m.children,h=m.options,D=ka.default.Children.only(x),S=(0,Dy.default)(_,h);g&&g(_,S),D&&D.props&&typeof D.props.onClick=="function"&&D.props.onClick(u)}),n}return Sy(r,[{key:"render",value:function(){var o=this.props;o.text,o.onCopy,o.options;var l=o.children,c=Ay(o,Iy),u=ka.default.Children.only(l);return ka.default.cloneElement(u,Al(Al({},c),{},{onClick:this.onClick}))}}]),r}(ka.default.PureComponent);Ta.CopyToClipboard=Sl,Xn(Sl,"defaultProps",{onCopy:void 0,options:void 0});var My=Ta,Yn=My.CopyToClipboard;Yn.CopyToClipboard=Yn;var Oy=Yn;const Vs=nd(Oy);Ne.languages.register({id:Ke}),Ne.editor.defineTheme("vs-dark",Mn),Ne.editor.defineTheme("vs",Ln),Ne.languages.setMonarchTokensProvider(Ke,js),Ne.languages.setLanguageConfiguration(Ke,En);async function zl(a,s){return s&&Ne.editor.setTheme(s.includes("dark")?"vs-dark":"light"),await Ne.editor.colorize(a,Ke,{tabSize:4})}async function Qn(a,s=0){const r=a[s];if(!r)return;const{name:n,args:o,type:l,desc:c,examples:u,remarks:m,seeAlso:_,syntax:g,detailedDesc:x,fields:h,returns:D}=r,S={name:n,orirginalName:n};if(a.length>1&&(S.overloads=`${a.length} ${Me.t("overloads")}`),l&&(S.type=l),o&&(S.name=`${n}()`,S.args=o.map(R=>{const{name:U,desc:K,displayType:H}=R;return{label:`${U} (${H})`,desc:K&&qs(K)}})),c&&(S.desc=c.map(R=>qs(R))),u&&(S.originalExample=u.join(`
|
147
147
|
`),S.examples=await Ne.editor.colorize(S.originalExample,Ke,{tabSize:4})),x){S.detailedDesc=[];for(const R of x){const{desc:U,examples:K}=R;let H=U.map(Q=>qs(Q)),re,W;K&&(W=K.join(`
|