@guihz/trading-vue-editor-tes 0.0.239 → 0.0.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -115,7 +115,7 @@ ${this._prefixNameVar}.setVarValue("${v}", ${y}, ${v}, "${h}")`}n==="-="?L=`${v}
115
115
  })
116
116
  `}return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:d}),d}_parserArrowFunction(e){let n=`$_${e.name}`;this._nameMap.set(e.name,n);const r=[...e.params];n=`${n}${e.index?`$${e.index}`:""}`,this._currentFuncName=n,this._dependsObj[n]=new Map;const s=e.hasRequest?", $paramsExpr":"",c=`const ${n} = (${this._parserParameters(r)}$posStr${s}) => {
117
117
  ${this._parserBlock(e.block,!0,!0)}
118
- }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:c}),c}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
118
+ }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:c}),c}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r==="/")return`${this._prefixNameVar}.div(${s}, ${c})`;if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
119
119
  ${this._prefixNameVar}.setCacheData("m${v}_" + ${S}, ${D})
120
120
  `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,s,c){const h=this._memberIndexList[r]||{};e=c&&r!==0?`"${e}_" + $posStr`:`"${e}"`;const d=`${this._prefixNameVar}.setCacheData(${e}, ${n})`;return h[e]=d,this._memberIndexList[r]=h,this._setDepend({name:n,scope:r,memberCode:d}),`${this._prefixNameVar}.getCacheData(${e}, ${s}, ${n})`}_getUserVarMemberIndexs(e,n,r,s,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,s,c)}_parseLiteral(e){return e.type.endsWith(V.COLOR)?`"${this._colorToRgba(e.value)}"`:e.value}_colorToRgba(e){if(e.startsWith("#")){let n;const r=parseInt(e.substring(1,3),16),s=parseInt(e.substring(3,5),16),c=parseInt(e.substring(5,7),16),h=e.substring(7);return h?n=parseInt(h,16)/255:n=1,`rgba(${Math.round(r)}, ${Math.round(s)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){var S;const{exprs:r,varScope:s,hasMethod:c,arg:h,varPos:d}=e;let v=[];for(const C of r){if(typeof C=="string"){v.push((d==null?void 0:d.reName)||C);continue}let T="";const{column:D,line:L}=((S=C==null?void 0:C.ctx)==null?void 0:S.start)||{},P=`${L}_${D}`;C.selfArg?(T=this._parserMethodElement(C,P,v.join(".")),v=[]):T=this._parserMethodElement(C,P,""),v.push(T)}if(e.expr&&v.unshift(`(${this._parserSingleExpression(e.expr)})`),e.isBuiltIn){const C=v.join(".");C==="strategy.opentrades"?v.push("opentrades"):C==="chart.left_visible_bar_time"?this._hasLeftVisibleBarTime=!0:C==="chart.right_visible_bar_time"&&(this._hasRightVisibleBarTime=!0),v.unshift(e.isConst?this._prefixNameConst:this._prefixNameVar)}else if(wn.includes(v[0])&&(v[0]=`$${v[0]}`),!c){const C={name:v[0],scope:s||(h==null?void 0:h.varScope)||0,isAgainAssign:n,isArg:h==null?void 0:h.isArg,functionName:this._currentFuncName};this._setDepend(C)}return v.join(".")}_setDepend(e){const n=e.name;for(const r of Object.values(this._dependsObj)){const s=r.get(n)||{},c={...e,...s};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:s,line:c}=r.start,h=`${c}_${s}`;let d=this._isInFunc?`$posStr + "__${h}"`:`"${h}"`;d=this._isInLoop?`$$count${this._count} + ${d}`:d;let v=!1,S=[];for(const T of n){T.hasMemberIndex&&(v=!0);let D="";T.selfArg?(D=this._parserMethodElement(T,d,S.join(".")),S=[]):D=this._parserMethodElement(T,d,""),S.push(D)}const C=S.join(".");if(this._isInConditionalStmt&&v){const T=`$$result_${this._preRunMemberFuncsCount}`;this._preRunMemberFuncsCount++;const D=this._preRunMembersFuncs[this._blockCount]||[];return D.push(`const ${T} = ${C}`),this._preRunMembersFuncs[this._blockCount]=D,T}return C}_parserMethodElement(e,n,r){let s="",c="";const h={...e.args};e.expr&&(s=`(${this._parserSingleExpression(e.expr)})`),s=s?`${s}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(s=`${this._prefixNameVar}.${s}`);let d=!1;if(e.isBuiltIn){if(Mp.includes(s))s=`${s}.${s}`;else if(s==="max_bars_back"){const{name:S,varPos:C}=h.var||h.params[0];c=`var_name: "${C?`${S}_${C.lineNumber}_${C.column}`:S}"`}s.startsWith(V.INPUT)?(c=`index: ${this._inputCount}`,this._inputCount++):s.startsWith("request.")&&(d=!0),s=`${this._prefixNameFunc}.${s}`}else{const S=s.split(".");let C=S[0];wn.includes(C)&&(C=`$${C}`,s=S.join("."))}if(e.selfArg){const S=s.split("."),C=S.length,T=S.slice(0,C-1);r&&T.unshift(r),Object.assign(h,{[e.selfArg.name]:{name:T.join(".")}}),s=S[C-1],s=this._nameMap.get(s)||s,this._setDepend({name:S[0],scope:e.varScope||0})}s=`${s}${e.index?`$${e.index}`:""}`;const v=this._parserArguments(h,c,n,d,e.hasRequest,s);if(!e.isBuiltIn){const S=s.split(".");if(S.length>1?this._setDepend({name:S[0],scope:e.varScope||0}):this._setDepend({name:s,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const C=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:C,originName:s,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return s+v}_parserArguments(e,n,r,s=!1,c=!1,h){const d=e.params||[];delete e.params;const v=[],S=[];let C=[],T;const D=(P,b)=>{c&&(this._dependsObj[r]=new Map),s&&b==="expression"&&(this._dependsObj[`$arg_${b}${r}`]=new Map);let y=P.ruleType===le.Brackethesized?this._parserBrackethesized(P):this._parserSingleExpression(P);if(b&&!["arg0, arg1, ...","number0, number1, ..."].includes(b)){P.isSourceType?v.push(`sourceTypeName: "${P.name}"`):b==="defval"&&h===`${this._prefixNameFunc}.input.enum`&&(T=this._enums.get(P.enumName));const g=this._requestParamsHandle(s,b,r,c,y,h);y=(g==null?void 0:g.code)||y,g!=null&&g.paramsExpr&&C.push(g==null?void 0:g.paramsExpr),v.push(`${b}: ${y}`)}else S.push(y)};for(const P of d)D(P,P.originName);for(const P of Object.keys(e))D(e[P],P);s&&this._isInFunc&&v.push("paramsExpr: $paramsExpr"),n&&v.push(n),T&&v.unshift(`options: [${T.join(", ")}]`);const L=C.length?`, [${this._isInFunc?"...$paramsExpr, ":""}${C.join(", ")}]`:"";return S.length?`({${v.join(", ")}}, [${S.join(", ")}], ${r}${L})`:v.length?`({${v.join(", ")}}, ${r}${L})`:`(${r}${L})`}_requestParamsHandle(e,n,r,s,c,h){const d=this._memberIndexList[0],v={};for(const S of Object.keys(d))S.includes("_")||(v[S]=d[S]);if(e&&n==="expression"){const S=this._getDepends(`$arg_${n}${r}`),C=this._getExpressionContext(S);return C.push({scope:1,depends:S.map(T=>(T.isArg&&(T.functionName=this._currentFuncName),T)),code:c,memberCodes:v}),{code:`'${pu(JSON.stringify(C))}'`}}else if(s){const S=this._getDepends(r),C=this._getExpressionContext(S);return C.push({scope:2,varNames:n,methodName:h,depends:S,dependSelf:S.some(T=>T.name===n),code:`${n} = ${c}`,memberCodes:v}),{paramsExpr:`'${pu(JSON.stringify(C))}'`}}}_getExpressionContext(e){const n=[],r=[];return this._getDependsCode(e,n,r),n}_getDependsCode(e,n,r){var s,c;for(const h of e)if(!h.isArg){const d=this._codesCol[h.scope||0],v=d.find(C=>{var T;return((T=C.varNames)==null?void 0:T.includes(h.name))||C.funcName===h.name});v&&(r.includes(v)||(r.push(v),v.depends.length&&this._getDependsCode(v.depends,n,r),n.push({scope:h.scope||0,code:v.code,depends:v.depends,funcName:v.funcName,varNames:(s=v.varNames)==null?void 0:s.join(", ")})));const S=d.filter(C=>C.depends.some(T=>T.name===h.name&&T.scope===h.scope&&T.isAgainAssign));for(const C of S)r.includes(C)||(r.push(C),C.depends.length&&this._getDependsCode(C.depends,n,r),n.push({scope:h.scope||0,code:C.code,depends:C.depends,funcName:C.funcName,varNames:(c=C.varNames)==null?void 0:c.join(", ")}))}}_parserBrackethesized(e){return`[${e.exprs.map(r=>this._parserSingleExpression(r)).join(", ")}]`}_functionalProcess(e,n){return`(function () {
121
121
  let $$_result=${n&&typeof n=="string"&&n.endsWith("string")?'""':"undefined"};
@@ -234,7 +234,7 @@ ${this._prefixNameVar}.againAssignParse(${v}, ${L});
234
234
  `}return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:d}),d}_parserArrowFunction(e){let n=`$_${e.name}`;this._nameMap.set(e.name,n);const r=[...e.params],s=e.index?`$${e.index}`:"";n=`${n}${s}`,e.isExport&&this._exportEles.push({key:`${e.name}${s}`,name:n}),this._currentFuncName=n,this._dependsObj[n]=new Map;const c=e.hasRequest?", $paramsExpr":"",h=`const ${n} = (${this._parserParameters(r)}$posStr${c}) => {
235
235
  if ($posStr.startsWith('export')) return;
236
236
  ${this._parserBlock(e.block,!0,!0)}
237
- }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:h}),h}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + '_' + '${C}'`:`"export_${this._libTitle}_${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
237
+ }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:h}),h}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + '_' + '${C}'`:`"export_${this._libTitle}_${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r==="/")return`${this._prefixNameVar}.div(${s}, ${c})`;if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
238
238
  ${this._prefixNameVar}.setCacheData("m${v}_" + ${S}, ${D})
239
239
  `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,s,c){const h=this._memberIndexList[r]||{};e=c&&r!==0?`"${e}_" + $posStr`:`"${e}"`;const d=`${this._prefixNameVar}.setCacheData(${e}, ${n})`;return h[e]=d,this._memberIndexList[r]=h,this._setDepend({name:n,scope:r,memberCode:d}),`${this._prefixNameVar}.getCacheData(${e}, ${s}, ${n})`}_getUserVarMemberIndexs(e,n,r,s,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,s,c)}_parseLiteral(e){return e.type.endsWith(V.COLOR)?`"${this._colorToRgba(e.value)}"`:e.value}_colorToRgba(e){if(e.startsWith("#")){let n;const r=parseInt(e.substring(1,3),16),s=parseInt(e.substring(3,5),16),c=parseInt(e.substring(5,7),16),h=e.substring(7);return h?n=(255-parseInt(h,16))/255:n=1,`rgba(${Math.round(r)}, ${Math.round(s)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){var S;const{exprs:r,varScope:s,hasMethod:c,arg:h,varPos:d}=e;let v=[];for(const C of r){if(typeof C=="string"){v.push((d==null?void 0:d.reName)||C);continue}let T="";const{column:D,line:L}=((S=C==null?void 0:C.ctx)==null?void 0:S.start)||{},P=`${L}_${D}`;C.selfArg?(T=this._parserMethodElement(C,P,v.join(".")),v=[]):T=this._parserMethodElement(C,P,""),v.push(T)}if(e.expr&&v.unshift(`(${this._parserSingleExpression(e.expr)})`),e.isBuiltIn)v.join(".")==="strategy.opentrades"&&v.push("opentrades"),v.unshift(e.isConst?this._prefixNameConst:this._prefixNameVar);else if(wn.includes(v[0])&&(v[0]=`$${v[0]}`),!c){const C={name:v[0],scope:s||(h==null?void 0:h.varScope)||0,isAgainAssign:n,isArg:h==null?void 0:h.isArg,functionName:this._currentFuncName};this._setDepend(C)}return v.join(".")}_setDepend(e){const n=e.name;for(const r of Object.values(this._dependsObj)){const s=r.get(n)||{},c={...e,...s};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:s,line:c}=r.start,h=`${c}_${s}`;let d=this._isInFunc?`$posStr + "_${h}"`:`"export_${this._libTitle}_${h}"`;d=this._isInLoop?`$$count${this._count} + ${d}`:d;let v=!1,S=[];for(const T of n){T.hasMemberIndex&&(v=!0);let D="";T.selfArg?(D=this._parserMethodElement(T,d,S.join(".")),S=[]):D=this._parserMethodElement(T,d,""),S.push(D)}const C=S.join(".");if(S.length===1&&[...Al,Ii.library].some(T=>S[0].startsWith(`${this._prefixNameFunc}.${T}`)))return"";if(this._isInConditionalStmt&&v){const T=`$$result_${this._preRunMemberFuncsCount}`;this._preRunMemberFuncsCount++;const D=this._preRunMembersFuncs[this._blockCount]||[];return D.push(`const ${T} = ${C}`),this._preRunMembersFuncs[this._blockCount]=D,T}return C}_parserMethodElement(e,n,r){let s="",c="";const h={...e.args};e.expr&&(s=`(${this._parserSingleExpression(e.expr)})`),s=s?`${s}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(s=`${this._prefixNameVar}.${s}`);let d=!1;if(e.isBuiltIn){if(Mp.includes(s))s=`${s}.${s}`;else if(s==="max_bars_back"){const{name:S,varPos:C}=h.var||h.params[0];c=`var_name: "${C?`${S}_${C.lineNumber}_${C.column}`:S}"`}s.startsWith(V.INPUT)?(c=`index: ${this._inputCount}`,this._inputCount++):s.startsWith("request.")&&(d=!0),s=`${this._prefixNameFunc}.${s}`}else{const S=s.split(".");let C=S[0];wn.includes(C)&&(C=`$${C}`,s=S.join("."))}if(e.selfArg){const S=s.split("."),C=S.length,T=S.slice(0,C-1);r&&T.unshift(r),Object.assign(h,{[e.selfArg.name]:{name:T.join(".")}}),s=S[C-1],s=this._nameMap.get(s)||s,this._setDepend({name:S[0],scope:e.varScope||0})}s=`${s}${e.index?`$${e.index}`:""}`;const v=this._parserArguments(h,c,n,d,e.hasRequest,s);if(!e.isBuiltIn){const S=s.split(".");if(S.length>1?this._setDepend({name:S[0],scope:e.varScope||0}):this._setDepend({name:s,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const C=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:C,originName:s,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return s+v}_parserArguments(e,n,r,s=!1,c=!1,h){const d=e.params||[];delete e.params;const v=[],S=[];let C=[],T;const D=(P,b)=>{c&&(this._dependsObj[r]=new Map),s&&b==="expression"&&(this._dependsObj[`$arg_${b}${r}`]=new Map);let y=P.ruleType===le.Brackethesized?this._parserBrackethesized(P):this._parserSingleExpression(P);if(b&&!["arg0, arg1, ...","number0, number1, ..."].includes(b)){P.isSourceType?v.push(`sourceTypeName: "${P.name}"`):b==="defval"&&h===`${this._prefixNameFunc}.input.enum`&&(T=this._enums.get(P.enumName));const g=this._requestParamsHandle(s,b,r,c,y,h);y=(g==null?void 0:g.code)||y,g!=null&&g.paramsExpr&&C.push(g==null?void 0:g.paramsExpr),v.push(`${b}: ${y}`)}else S.push(y)};for(const P of d)D(P,P.originName);for(const P of Object.keys(e))D(e[P],P);s&&this._isInFunc&&v.push("paramsExpr: $paramsExpr"),n&&v.push(n),T&&v.unshift(`options: [${T.join(", ")}]`);const L=C.length?`, [${this._isInFunc?"...$paramsExpr, ":""}${C.join(", ")}]`:"";return S.length?`({${v.join(", ")}}, [${S.join(", ")}], ${r}${L})`:v.length?`({${v.join(", ")}}, ${r}${L})`:`(${r}${L})`}_requestParamsHandle(e,n,r,s,c,h){const d=this._memberIndexList[0],v={};for(const S of Object.keys(d))S.includes("_")||(v[S]=d[S]);if(e&&n==="expression"){const S=this._getDepends(`$arg_${n}${r}`),C=this._getExpressionContext(S);return C.push({scope:1,depends:S.map(T=>(T.isArg&&(T.functionName=this._currentFuncName),T)),code:c,memberCodes:v}),{code:`'${pu(JSON.stringify(C))}'`}}else if(s){const S=this._getDepends(r),C=this._getExpressionContext(S);return C.push({scope:2,varNames:n,methodName:h,depends:S,dependSelf:S.some(T=>T.name===n),code:`${n} = ${c}`,memberCodes:v}),{paramsExpr:`'${pu(JSON.stringify(C))}'`}}}_getExpressionContext(e){const n=[],r=[];return this._getDependsCode(e,n,r),n}_getDependsCode(e,n,r){var s,c;for(const h of e)if(!h.isArg){const d=this._codesCol[h.scope||0],v=d.find(C=>{var T;return((T=C.varNames)==null?void 0:T.includes(h.name))||C.funcName===h.name});v&&(r.includes(v)||(r.push(v),v.depends.length&&this._getDependsCode(v.depends,n,r),n.push({scope:h.scope||0,code:v.code,depends:v.depends,funcName:v.funcName,varNames:(s=v.varNames)==null?void 0:s.join(", ")})));const S=d.filter(C=>C.depends.some(T=>T.name===h.name&&T.scope===h.scope&&T.isAgainAssign));for(const C of S)r.includes(C)||(r.push(C),C.depends.length&&this._getDependsCode(C.depends,n,r),n.push({scope:h.scope||0,code:C.code,depends:C.depends,funcName:C.funcName,varNames:(c=C.varNames)==null?void 0:c.join(", ")}))}}_parserBrackethesized(e){return`[${e.exprs.map(r=>this._parserSingleExpression(r)).join(", ")}]`}_functionalProcess(e,n){return`(function () {
240
240
  let $$_result=${n&&typeof n=="string"&&n.endsWith("string")?'""':"undefined"};
@@ -62,7 +62,7 @@ ${lh}`)}function gy(i,t,e){return(i>=0&&e?` ${fh(i,t-1)}`:fh(i,t)).padEnd(t)}fun
62
62
  `)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return String(this._toStringFormat(t,e==null?void 0:e.replace(/0/g,"#")))}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._toStringFormat(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return mt(e)&&(e=0),mt(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return mt(t)&&(t=0),mr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_toStringFormat(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case Gt.mintick:return t.toFixed(this._precision);case Gt.percent:return`${t}%`;case Gt.volume:return this._intlNumberFormatter.format(Math.round(t));default:return this._formatOthers(t,e)}}_formatOthers(t,e){var u;let[r,n]=e.split(".");e.split("%").length===2&&(t=t*100);let[s,a=""]=String(t).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),f=((u=c[c.length-1])==null?void 0:u.replace(/[^#]/g,"").length)||0;f&&(s=s.replace(new RegExp(`\\B(?=(\\d{${f}})+(?!\\d))`,"g"),",")),r=c.join("")}s=r.replace(/#/,s).replace(/#/g,"")}else s=`${r}${s}`;if(n&&n.includes("#")){const c=n.split("#").length-1,f=+`${s}.${a}`;if(!isNaN(f))return`${f.toFixed(c)}${n.replace(/#/g,"")}`;a=`${a.substring(0,c)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${s}.${a}`:s}_formatNumber(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:return this._formatOthers(t,e)}}strformat({formatString:t=""},e,r){return this._strFormat(t,e,r)}_strFormat(t,e,r){return t.replace(/{[^{}]+}/g,n=>{if(!n)return n;const s=n.replace(/[{}]/g,"").split(","),a=Number(s[0]);if(isNaN(a)||e.length<=a)return n;const u=e[a];if(s.length===1)return typeof u=="number"&&r?this._intlFormat.format(u):u;if(s.length===2){const c=s[1].trim();return c==="number"?r?this._intlFormat.format(u):u:c==="date"?Wt(u).format("LL"):n}else{const c=s[1].trim(),f=s[2].trim();if(c==="number")return this._formatNumber(u,f);if(c==="date"){let d="YYYY-MM-DD";switch(f){case"long":d="LL";break;case"short":d="L";break;default:f&&(d=f)}return Wt(u).format(d)}return n}})}}class cw{constructor(t){$(this,"_errorListener");this._errorListener=t}new(){return new nu(this._errorListener)}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class nu{constructor(t){$(this,"_errorListener");$(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new nu(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new ee(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new ee(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class fw{constructor(t){$(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Bi(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Bi(t,r,e)}copy({id:t}){return t==null?void 0:t.copy()}from_index({price:t,index:e}){return new Bi(t,e)}from_time({price:t,time:e}){return new Bi(t,void 0,e)}}class Bi{constructor(t,e,r){$(this,"_index");$(this,"_price");$(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}set index(t){this._index=t}get price(){return this._price}set price(t){this._price=t}get time(){return this._time}set time(t){this._time=t}copy(){return new Bi(this._price,this._index,this._time)}}class hw{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLabel",{text:"",xloc:be.bar_index,yloc:Vr.price,size:ir.normal,style:ye.styleLabelDown,textalign:jt.alignCenter});this._variables=t,this._errorListener=e}new(t,e){const{time:r,high:n,low:s,bar_index:a}=this._variables,u=`label_${e}_${a}`;ve(t,["color","textcolor"]);const c={...this._defaultLabel,...t,id:u,time:r,high:n,low:s,bar_index:a};t.point&&(c.x=c.xloc===be.bar_index?t.point.index:t.point.time,c.y=t.point.price),c.yloc===Vr.abovebar?c.y=n:c.yloc===Vr.belowbar&&(c.y=s),this._verfiyArgs(t,e);const f=new go(u,this._variables,this._errorListener);return e.startsWith("export")||this._variables.label.add(u,c,f),f}_verfiyArgs(t,e){const{xloc:r,yloc:n,style:s,size:a,textalign:u,text_font_family:c}=t,f="label.new";this._paramVerfiy(s,e,f,Object.values(ye),"style"),this._paramVerfiy(r,e,f,Object.values(be),"xloc"),this._paramVerfiy(n,e,f,Object.values(Vr),"yloc"),this._paramVerfiy(a,e,f,Object.values(ir),"size"),this._paramVerfiy(u,e,f,[jt.alignLeft,jt.alignCenter,jt.alignRight],"textalign"),this._paramVerfiy(c,e,f,Object.values(Jn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}label(t){return t.x}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class go{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");this._id=t,this._variables=e,this._errorListener=r}get type(){return te.LABEL}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.label.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`label_${t}_${e}`,n=this._getLabel(t),s=new go(r,this._variables,this._errorListener);if(n){const a={...n,id:r,bar_index:e};this._variables.label.add(r,a,s)}return s}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id,this._variables._isRealTimeBar?void 0:this._variables.bar_index)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t),this._paramVerfiy(t,e,"label.set_size",Object.values(ir),"size")}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e,this._paramVerfiy(e,r,"label.set_xloc",Object.values(be),"xloc"))}set_yloc({yloc:t},e){const r=this._getLabel(e),{high:n,low:s}=this._variables;r&&(r.yloc=t,t===Vr.abovebar?r.y=n:t===Vr.belowbar&&(r.y=s),this._paramVerfiy(t,e,"label.set_yloc",Object.values(Vr),"yloc"))}set_color(t,e){const r=this._getLabel(e);ve(t,["color"]),r&&(r.color=t.color)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===be.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t),this._paramVerfiy(t,e,"label.set_style",Object.values(ye),"style")}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t),this._paramVerfiy(t,e,"label.set_textalign",[jt.alignLeft,jt.alignCenter,jt.alignRight],"textalign")}set_textcolor(t,e){const r=this._getLabel(e);ve(t,["textcolor"]),r&&(r.textcolor=t.textcolor)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t),this._paramVerfiy(t,e,"label.set_text_font_family",Object.values(Jn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const dw={freq_all:jr.freqAll,freq_once_per_bar:jr.freqOncePerBar,freq_once_per_bar_close:jr.freqOncePerBarClose},_w={gaps_off:ln.gapsOff,gaps_on:ln.gapsOn,lookahead_off:ln.lookaheadOff,lookahead_on:ln.lookaheadOn},Ti={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"},xh={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"},pw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},Eh={all:[Ze.dataWindow,Ze.pane,Ze.priceScale,Ze.statusLine],data_window:[Ze.dataWindow],none:[],pane:[Ze.pane],price_scale:[Ze.priceScale],status_line:[Ze.statusLine]},mw={both:Yr.both,left:Yr.left,none:Yr.none,right:Yr.right},gw={inherit:Gt.inherit,mintick:Gt.mintick,percent:Gt.percent,price:Gt.price,volume:Gt.volume},vw={style_solid:Ss.styleSolid,style_dashed:Ss.styleDashed,style_dotted:Ss.styleDotted},yw={style_arrowdown:ye.styleArrowdown,style_arrowup:ye.styleArrowup,style_circle:ye.styleCircle,style_cross:ye.styleCross,style_diamond:ye.styleDiamond,style_flag:ye.styleFlag,style_label_center:ye.styleLabelCenter,style_label_down:ye.styleLabelDown,style_label_left:ye.styleLabelLeft,style_label_lower_left:ye.styleLabelLowerLeft,style_label_lower_right:ye.styleLabelLowerRight,style_label_right:ye.styleLabelRight,style_label_up:ye.styleLabelUp,style_label_upper_left:ye.styleLabelUpperLeft,style_label_upper_right:ye.styleLabelUpperRight,style_none:ye.styleNone,style_square:ye.styleSquare,style_text_outline:ye.styleTextOutline,style_triangledown:ye.styleTriangledown,style_triangleup:ye.styleTriangleup,style_xcross:ye.styleXcross},ww={style_arrow_both:Re.styleArrowBoth,style_arrow_left:Re.styleArrowLeft,style_arrow_right:Re.styleArrowRight,style_dashed:Re.styleDashed,style_dotted:Re.styleDotted,style_solid:Re.styleSolid},Dw={abovebar:cn.abovebar,absolute:cn.absolute,belowbar:cn.belowbar,bottom:cn.bottom,top:cn.top},bw={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},xw={style_area:Or.styleArea,style_areabr:Or.styleAreabr,style_circles:Or.styleCircles,style_columns:Or.styleColumns,style_cross:Or.styleCross,style_histogram:Or.styleHistogram,style_line:Or.styleLine,style_linebr:Or.styleLinebr,style_stepline:Or.styleStepline,style_stepline_diamond:Or.styleSteplineDiamond,style_steplinebr:Or.styleSteplinebr},Ew={bottom_center:vr.bottomCenter,bottom_left:vr.bottomLeft,bottom_right:vr.bottomRight,middle_center:vr.middleCenter,middle_left:vr.middleLeft,middle_right:vr.middleRight,top_center:vr.topCenter,top_left:vr.topLeft,top_right:vr.topRight},Cw={left:Os.left,none:Os.none,right:Os.right},Aw={arrowdown:lr.arrowdown,arrowup:lr.arrowup,circle:lr.circle,cross:lr.cross,diamond:lr.diamond,flag:lr.flag,labeldown:lr.labeldown,labelup:lr.labelup,square:lr.square,triangledown:lr.triangledown,triangleup:lr.triangleup,xcross:lr.xcross},Mw={auto:ir.auto,huge:ir.huge,large:ir.large,normal:ir.normal,small:ir.small,tiny:ir.tiny},Fw={cash:Pe.cash,fixed:Pe.fixed,percent_of_equity:Pe.percentOfEquity,commission:{cash_per_contract:je.cashPerContract,cash_per_order:je.cashPerOrder,percent:je.percent},direction:{all:fe.all,long:fe.long,short:fe.short},oca:{cancel:fn.cancel,none:fn.none,reduce:fn.reduce}},Nw={align_bottom:jt.alignBottom,align_center:jt.alignCenter,align_left:jt.alignLeft,align_right:jt.alignRight,align_top:jt.alignTop,wrap_auto:jt.wrapAuto,wrap_none:jt.wrapNone},Sw={bar_index:be.bar_index,bar_time:be.bar_time},Ow={abovebar:Vr.abovebar,belowbar:Vr.belowbar,price:Vr.price},Bw={actual:Bs.actual,estimate:Bs.estimate,standardized:Bs.standardized};class Ch{constructor(){$(this,"adjustment",{dividends:Ns.dividends,none:Ns.none,splits:Ns.splits});$(this,"alert",dw);$(this,"barmerge",_w);$(this,"color",Ti);$(this,"currency",xh);$(this,"dayofweek",pw);$(this,"earnings",Bw);$(this,"display",Eh);$(this,"extend",mw);$(this,"font",{family_default:Jn.familyDefault,family_monospace:Jn.familyMonospace});$(this,"format",gw);$(this,"hline",vw);$(this,"label",yw);$(this,"line",ww);$(this,"location",Dw);$(this,"math",bw);$(this,"order",{ascending:Gn.ascending,descending:Gn.descending});$(this,"plot",xw);$(this,"position",Ew);$(this,"scale",Cw);$(this,"session",{extended:Mn.extended,regular:Mn.regular});$(this,"shape",Aw);$(this,"size",Mw);$(this,"splits",{denominator:"denominator",numerator:"numerator"});$(this,"strategy",Fw);$(this,"text",Nw);$(this,"xloc",Sw);$(this,"yloc",Ow)}updateData(){}}class Tw{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:be.bar_index,line_color:Ti.blue,line_style:Re.styleSolid,line_width:1});this._variables=t,this._errorListener=e}new(t,e){var u;const{bar_index:r}=this._variables,n=`polyline_${e}_${r}`,s=Object.assign({},this._defaultPolyline,t,{id:n,bar_index:r,points:(u=t.points)==null?void 0:u._value.map(c=>({time:c.time,index:c.index,price:c.price}))});ve(s,["line_color","fill_color"]);const a=new Ah(n,this._variables);return this._verfiyArgs(t,e),e.startsWith("export")||this._variables.polyline.add(n,s,a),a}_verfiyArgs(t,e){const{line_style:r,xloc:n}=t,s="polyline.new";this._paramVerfiy(r,e,s,Object.values(Re),"line_style"),this._paramVerfiy(n,e,s,Object.values(be),"xloc")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}delete({id:t}){t&&t.delete()}}class Ah{constructor(t,e){$(this,"_id");$(this,"_variables");$(this,"_suffix");this._variables=e,this._id=t}get type(){return te.POLYLINE}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.polyline.get(this._id)}delete(){this._variables.polyline.delete(this._id,this._variables._isRealTimeBar?void 0:this._variables.bar_index)}}class Iw{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLine",{xloc:be.bar_index,extend:Yr.none,style:Re.styleSolid});this._variables=t,this._errorListener=e}new({first_point:t,second_point:e,...r},n){const{bar_index:s}=this._variables,a=`line_${n}_${s}`;ve(r,["color"]);const u={...this._defaultLine,...r,id:a,bar_index:s};if(t&&e){const f=u.xloc===be.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,d=u.xloc===be.bar_index?e==null?void 0:e.index:e==null?void 0:e.time;Object.assign(u,{x1:f,y1:t==null?void 0:t.price,x2:d,y2:e==null?void 0:e.price})}this._verfiyArgs(r,n);const c=new vo(a,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(a,u,c),c}_verfiyArgs(t,e){const{extend:r,xloc:n,style:s}=t,a="line.new";this._paramVerfiy(s,e,a,Object.values(Re),"style"),this._paramVerfiy(r,e,a,Object.values(Yr),"extend"),this._paramVerfiy(n,e,a,Object.values(be),"xloc")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}line(t){return t.x}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class vo{constructor(t,e,r){$(this,"_variables");$(this,"_id");$(this,"_suffix","");$(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get type(){return te.LINE}get data(){return this._variables.line.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`line_${t}_${e}`,n=this._getLine(t),s=new vo(r,this._variables,this._errorListener);return n&&this._variables.line.add(r,{...n,id:r,bar_index:e,isVar:void 0},s),s}delete(){this._variables.line.delete(this._id,this._variables._isRealTimeBar?void 0:this._variables.bar_index)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===be.bar_index){const{x1:n,y1:s,x2:a,y2:u}=r;return n===void 0||a===void 0||s===void 0||u===void 0?void 0:(u-s)/(a-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r,this._paramVerfiy(t,n,"line.set_xloc",Object.values(be),"xloc"))}set_color(t,e){const r=this._getLine(e);r&&(ve(t,["color"]),r.color=t.color)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t,this._paramVerfiy(t,e,"line.set_style",Object.values(Re),"style"))}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t,this._paramVerfiy(t,e,"line.set_extend",Object.values(Yr),"extend"))}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},u=r.xloc===be.bar_index?n:s,c=a;u&&(r.x1=u),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},u=r.xloc===be.bar_index?n:s,c=a;u&&(r.x2=u),c&&(r.y2=c)}}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class $w{constructor(t){$(this,"_variables");this._variables=t}new(t,e){const{line1:r,line2:n}=t,{bar_index:s}=this._variables,a=`linefill_${e}_${s}`,u=r==null?void 0:r.data,c=n==null?void 0:n.data;u&&(u.linefills=u.linefills||[],u.linefills.push(a)),c&&(c.linefills=c.linefills||[],c.linefills.push(a)),ve(t,["color"]);const f=new yo(this._variables,a,r,n);return e.startsWith("export")||(u||c)&&this._variables.linefill.add(a,{line1:u,line2:c,color:t.color,id:a,bar_index:s},f),f}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class yo{constructor(t,e,r,n){$(this,"_id");$(this,"_line1");$(this,"_line2");$(this,"_variables");$(this,"_suffix");this._variables=t,this._id=e,this._line1=r,this._line2=n}get type(){return te.LINEFILL}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.linefill.get(this._id)}linefill(t,e){return t.x?t.x:new yo(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),s&&(s.linefills=(r=s.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id,this._variables._isRealTimeBar?void 0:this._variables.bar_index)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(t){const e=this._variables.linefill.get(this._id);e&&(ve(t,["color"]),e.color=t.color)}}class Lw{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultBox",{border_color:Ti.blue,border_width:1,bgcolor:Ti.blue,xloc:be.bar_index,extend:Yr.none,style:Re.styleSolid,text:"",text_size:ir.auto,text_color:Ti.black,text_halign:jt.alignCenter,text_valign:jt.alignCenter,text_wrap:jt.wrapNone});this._variables=t,this._errorListener=e}box({x:t}){return t}new({top_left:t,bottom_right:e,...r},n){const{bar_index:s}=this._variables,a=`box_${n}_${s}`,u={...this._defaultBox,...r,id:a,bar_index:s};if(ve(u,["border_color","bgcolor","text_color"]),t){const{price:f,time:d,index:h}=t;u.top=f,u.left=u.xloc===be.bar_index?h:d}if(e){const{price:f,time:d,index:h}=e;u.bottom=f,u.right=u.xloc===be.bar_index?h:d}this._verfiyArgs(r,n);const c=new wo(this._variables,a,this._errorListener);return n.startsWith("export")||this._variables.box.add(a,u,c),c}_verfiyArgs(t,e){const{border_style:r,extend:n,xloc:s,text_size:a,text_halign:u,text_valign:c,text_wrap:f,text_font_family:d}=t,h="box.new";this._paramVerfiy(r,e,h,[Re.styleDashed,Re.styleDotted,Re.styleSolid],"border_style"),this._paramVerfiy(n,e,h,Object.values(Yr),"extend"),this._paramVerfiy(s,e,h,Object.values(be),"xloc"),this._paramVerfiy(a,e,h,Object.values(ir),"text_size"),this._paramVerfiy(u,e,h,[jt.alignLeft,jt.alignCenter,jt.alignRight],"text_halign"),this._paramVerfiy(c,e,h,[jt.alignBottom,jt.alignCenter,jt.alignTop],"text_valign"),this._paramVerfiy(f,e,h,[jt.wrapAuto,jt.wrapNone],"text_wrap"),this._paramVerfiy(d,e,h,Object.values(Jn),"text_font_family")}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_text({id:t,...e}){t==null||t.set_text(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e},r){t==null||t.set_border_style(e,r)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e},r){t==null||t.set_text_size(e,r)}set_text_wrap({id:t,...e},r){t==null||t.set_text_wrap(e,r)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e},r){t==null||t.set_text_halign(e,r)}set_text_valign({id:t,...e},r){t==null||t.set_text_valign(e,r)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class wo{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");this._variables=t,this._id=e,this._errorListener=r}get type(){return te.BOX}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.box.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`box_${t}_${e}`,n=this._getBox(),s=new wo(this._variables,r,this._errorListener);return n&&this._variables.box.add(r,{...n,id:r,bar_index:e},s),s}delete(){this._variables.box.delete(this._id,this._variables._isRealTimeBar?void 0:this._variables.bar_index)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t},e){const r=this._getBox();r&&(r.extend=t,this._paramVerfiy(t,e,"box.set_extend",Object.values(Yr),"extend"))}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t,ve(e,["bgcolor"]))}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t},e){const r=this._getBox();r&&(r.text_size=t,this._paramVerfiy(t,e,"box.set_text_size",Object.values(ir),"text_size"))}set_text_wrap({text_wrap:t},e){const r=this._getBox();r&&(r.text_wrap=t,this._paramVerfiy(t,e,"box.set_text_wrap",[jt.wrapAuto,jt.wrapNone],"text_wrap"))}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t,ve(e,["text_color"]))}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t},e){const r=this._getBox();r&&(r.text_halign=t,this._paramVerfiy(t,e,"box.set_text_halign",[jt.alignLeft,jt.alignCenter,jt.alignRight],"text_halign"))}set_text_valign({text_valign:t},e){const r=this._getBox();r&&(r.text_valign=t,this._paramVerfiy(t,e,"box.set_text_valign",[jt.alignBottom,jt.alignCenter,jt.alignTop],"text_valign"))}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===be.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t,ve(e,["border_color"]))}set_border_style({style:t},e){const r=this._getBox();r&&(r.border_style=t,this._paramVerfiy(t,e,"box.set_border_style",[Re.styleDashed,Re.styleDotted,Re.styleSolid],"style"))}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===be.bar_index?r:s}}set_text_font_family({text_font_family:t},e){const r=this._getBox();r&&(r.text_font_family=t,this._paramVerfiy(t,e,"box.set_text_font_family",Object.values(Jn),"text_font_family"))}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}_getBox(){return this._variables.box.get(this._id)}}class Rw{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultTable",{position:vr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t,this._errorListener=e}table({x:t}){return t}new(t,e){const{bar_index:r}=this._variables,n=`table_${e}_${r}`,{rows:s}=t;ve(t,["text_color","bgcolor","border_color"]);const a=Array.from(Array(s),()=>[]),u=e.split("_"),c=u.pop(),f=u.pop(),d={...this._defaultTable,...t,cell:a,id:n,bar_index:r,line:f,col:c},h=new Mh(this._variables,n,this._errorListener);return this._paramVerfiy(t.position,e,"table.new",Object.values(vr),"position"),e.startsWith("export")||this._variables.table.add(n,d,h),h}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e},r){t==null||t.set_position(e,r)}}class Mh{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_suffix","");$(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ti.black,text_halign:jt.alignCenter,text_valign:jt.alignCenter,text_size:ir.normal});this._variables=t,this._id=e,this._errorListener=r}get type(){return te.TABLE}get id(){return this._id}updateId(){const{bar_index:t}=this._variables;if(!this._suffix)this._suffix=`_${t}`,this._id=`${this._id}${this._suffix}`;else{const e=this._id.split("_");e.pop(),this._id=`${e.join("_")}_${t}`}return this._id}get data(){return this._variables.table.get(this._id)}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const a=s.cell||[],u=a[n]||[];u[r]=e,a[n]=u,s.cell=a}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r,ve(n,["text_color"]))}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const a=s.cell;if(a)for(let u=e;u<=n;u++)for(let c=t;c<=r;c++){const f=a[u];f&&(f[c]=void 0)}}}delete(){this._variables.table.delete(this._id,this._variables._isRealTimeBar?void 0:this._variables.bar_index)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){this._errorListener.addError(ie.mergeCellErr,s,Rt.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const u=a.merge_cells||[];u.push({start_column:t,start_row:e,end_column:r,end_row:n}),a.merge_cells=u}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t,ve(e,["bgcolor"]))}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t,ve(e,["border_color"]))}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t},e){const r=this._variables.table.get(this._id);r&&(r.position=t,this._paramVerfiy(t,e,"table.set_position",Object.values(vr),"position"))}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class Pw{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(!this._verifyTradeNum(t))return;const{in_time:e,entry_time:r}=this._strategy.historyOrders[t];return r||e}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===fe.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class kw{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(!this._verifyTradeNum(t))return;const{in_time:e,entry_time:r}=this._strategy.orders[t];return r||e}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===fe.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class zw{constructor(t,e){$(this,"_strategy");$(this,"_errorListener");this._strategy=t,this._errorListener=e}allow_entry_in({value:t},e){this._paramVerfiy(t,e,"strategy.risk.allow_entry_in",Object.values(fe),"value"),this._strategy.updateRisk({allow_entry_in:t})}max_cons_loss_days({count:t}){this._strategy.updateRisk({max_cons_loss_days:t})}max_drawdown({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_drawdown",[Pe.percentOfEquity,Pe.cash],"type"),e===Pe.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_drawdown:t,max_drawdown_type:e})}max_intraday_filled_orders({count:t}){this._strategy.updateRisk({max_intraday_filled_orders:t})}max_intraday_loss({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_intraday_loss",[Pe.percentOfEquity,Pe.cash],"type"),e===Pe.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_intraday_loss:t,max_intraday_loss_type:e})}max_position_size({contracts:t}){this._strategy.updateRisk({max_position_size:t})}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}}var qw=20,Uw=1,ni=1e6,Fh=1e6,Ww=-7,jw=21,Yw=!1,us="[big.js] ",ii=us+"Invalid ",Do=ii+"decimal places",Vw=ii+"rounding mode",Nh=us+"Division by zero",le={},sn=void 0,Hw=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Sh(){function i(t){var e=this;if(!(e instanceof i))return t===sn?Sh():new i(t);if(t instanceof i)e.s=t.s,e.e=t.e,e.c=t.c.slice();else{if(typeof t!="string"){if(i.strict===!0&&typeof t!="bigint")throw TypeError(ii+"value");t=t===0&&1/t<0?"-0":String(t)}Zw(e,t)}e.constructor=i}return i.prototype=le,i.DP=qw,i.RM=Uw,i.NE=Ww,i.PE=jw,i.strict=Yw,i.roundDown=0,i.roundHalfUp=1,i.roundHalfEven=2,i.roundUp=3,i}function Zw(i,t){var e,r,n;if(!Hw.test(t))throw Error(ii+"number");for(i.s=t.charAt(0)=="-"?(t=t.slice(1),-1):1,(e=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(e<0&&(e=r),e+=+t.slice(r+1),t=t.substring(0,r)):e<0&&(e=t.length),n=t.length,r=0;r<n&&t.charAt(r)=="0";)++r;if(r==n)i.c=[i.e=0];else{for(;n>0&&t.charAt(--n)=="0";);for(i.e=e-r-1,i.c=[],e=0;r<=n;)i.c[e++]=+t.charAt(r++)}return i}function si(i,t,e,r){var n=i.c;if(e===sn&&(e=i.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(Vw);if(t<1)r=e===3&&(r||!!n[0])||t===0&&(e===1&&n[0]>=5||e===2&&(n[0]>5||n[0]===5&&(r||n[1]!==sn))),n.length=1,r?(i.e=i.e-t+1,n[0]=1):n[0]=i.e=0;else if(t<n.length){if(r=e===1&&n[t]>=5||e===2&&(n[t]>5||n[t]===5&&(r||n[t+1]!==sn||n[t-1]&1))||e===3&&(r||!!n[0]),n.length=t,r){for(;++n[--t]>9;)if(n[t]=0,t===0){++i.e,n.unshift(1);break}}for(t=n.length;!n[--t];)n.pop()}return i}function oi(i,t,e){var r=i.e,n=i.c.join(""),s=n.length;if(t)n=n.charAt(0)+(s>1?"."+n.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)n="0"+n;n="0."+n}else if(r>0)if(++r>s)for(r-=s;r--;)n+="0";else r<s&&(n=n.slice(0,r)+"."+n.slice(r));else s>1&&(n=n.charAt(0)+"."+n.slice(1));return i.s<0&&e?"-"+n:n}le.abs=function(){var i=new this.constructor(this);return i.s=1,i},le.cmp=function(i){var t,e=this,r=e.c,n=(i=new e.constructor(i)).c,s=e.s,a=i.s,u=e.e,c=i.e;if(!r[0]||!n[0])return r[0]?s:n[0]?-a:0;if(s!=a)return s;if(t=s<0,u!=c)return u>c^t?1:-1;for(a=(u=r.length)<(c=n.length)?u:c,s=-1;++s<a;)if(r[s]!=n[s])return r[s]>n[s]^t?1:-1;return u==c?0:u>c^t?1:-1},le.div=function(i){var t=this,e=t.constructor,r=t.c,n=(i=new e(i)).c,s=t.s==i.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>ni)throw Error(Do);if(!n[0])throw Error(Nh);if(!r[0])return i.s=s,i.c=[i.e=0],i;var u,c,f,d,h,_=n.slice(),g=u=n.length,y=r.length,p=r.slice(0,u),w=p.length,v=i,x=v.c=[],b=0,C=a+(v.e=t.e-i.e)+1;for(v.s=s,s=C<0?0:C,_.unshift(0);w++<u;)p.push(0);do{for(f=0;f<10;f++){if(u!=(w=p.length))d=u>w?1:-1;else for(h=-1,d=0;++h<u;)if(n[h]!=p[h]){d=n[h]>p[h]?1:-1;break}if(d<0){for(c=w==u?n:_;w;){if(p[--w]<c[w]){for(h=w;h&&!p[--h];)p[h]=9;--p[h],p[w]+=10}p[w]-=c[w]}for(;!p[0];)p.shift()}else break}x[b++]=d?f:++f,p[0]&&d?p[w]=r[g]||0:p=[r[g]]}while((g++<y||p[0]!==sn)&&s--);return!x[0]&&b!=1&&(x.shift(),v.e--,C--),b>C&&si(v,C,e.RM,p[0]!==sn),v},le.eq=function(i){return this.cmp(i)===0},le.gt=function(i){return this.cmp(i)>0},le.gte=function(i){return this.cmp(i)>-1},le.lt=function(i){return this.cmp(i)<0},le.lte=function(i){return this.cmp(i)<1},le.minus=le.sub=function(i){var t,e,r,n,s=this,a=s.constructor,u=s.s,c=(i=new a(i)).s;if(u!=c)return i.s=-c,s.plus(i);var f=s.c.slice(),d=s.e,h=i.c,_=i.e;if(!f[0]||!h[0])return h[0]?i.s=-c:f[0]?i=new a(s):i.s=1,i;if(u=d-_){for((n=u<0)?(u=-u,r=f):(_=d,r=h),r.reverse(),c=u;c--;)r.push(0);r.reverse()}else for(e=((n=f.length<h.length)?f:h).length,u=c=0;c<e;c++)if(f[c]!=h[c]){n=f[c]<h[c];break}if(n&&(r=f,f=h,h=r,i.s=-i.s),(c=(e=h.length)-(t=f.length))>0)for(;c--;)f[t++]=0;for(c=t;e>u;){if(f[--e]<h[e]){for(t=e;t&&!f[--t];)f[t]=9;--f[t],f[e]+=10}f[e]-=h[e]}for(;f[--c]===0;)f.pop();for(;f[0]===0;)f.shift(),--_;return f[0]||(i.s=1,f=[_=0]),i.c=f,i.e=_,i},le.mod=function(i){var t,e=this,r=e.constructor,n=e.s,s=(i=new r(i)).s;if(!i.c[0])throw Error(Nh);return e.s=i.s=1,t=i.cmp(e)==1,e.s=n,i.s=s,t?new r(e):(n=r.DP,s=r.RM,r.DP=r.RM=0,e=e.div(i),r.DP=n,r.RM=s,this.minus(e.times(i)))},le.neg=function(){var i=new this.constructor(this);return i.s=-i.s,i},le.plus=le.add=function(i){var t,e,r,n=this,s=n.constructor;if(i=new s(i),n.s!=i.s)return i.s=-i.s,n.minus(i);var a=n.e,u=n.c,c=i.e,f=i.c;if(!u[0]||!f[0])return f[0]||(u[0]?i=new s(n):i.s=n.s),i;if(u=u.slice(),t=a-c){for(t>0?(c=a,r=f):(t=-t,r=u),r.reverse();t--;)r.push(0);r.reverse()}for(u.length-f.length<0&&(r=f,f=u,u=r),t=f.length,e=0;t;u[t]%=10)e=(u[--t]=u[t]+f[t]+e)/10|0;for(e&&(u.unshift(e),++c),t=u.length;u[--t]===0;)u.pop();return i.c=u,i.e=c,i},le.pow=function(i){var t=this,e=new t.constructor("1"),r=e,n=i<0;if(i!==~~i||i<-Fh||i>Fh)throw Error(ii+"exponent");for(n&&(i=-i);i&1&&(r=r.times(t)),i>>=1,!!i;)t=t.times(t);return n?e.div(r):r},le.prec=function(i,t){if(i!==~~i||i<1||i>ni)throw Error(ii+"precision");return si(new this.constructor(this),i,t)},le.round=function(i,t){if(i===sn)i=0;else if(i!==~~i||i<-ni||i>ni)throw Error(Do);return si(new this.constructor(this),i+this.e+1,t)},le.sqrt=function(){var i,t,e,r=this,n=r.constructor,s=r.s,a=r.e,u=new n("0.5");if(!r.c[0])return new n(r);if(s<0)throw Error(us+"No square root");s=Math.sqrt(+oi(r,!0,!0)),s===0||s===1/0?(t=r.c.join(""),t.length+a&1||(t+="0"),s=Math.sqrt(t),a=((a+1)/2|0)-(a<0||a&1),i=new n((s==1/0?"5e":(s=s.toExponential()).slice(0,s.indexOf("e")+1))+a)):i=new n(s+""),a=i.e+(n.DP+=4);do e=i,i=u.times(e.plus(r.div(e)));while(e.c.slice(0,a).join("")!==i.c.slice(0,a).join(""));return si(i,(n.DP-=4)+i.e+1,n.RM)},le.times=le.mul=function(i){var t,e=this,r=e.constructor,n=e.c,s=(i=new r(i)).c,a=n.length,u=s.length,c=e.e,f=i.e;if(i.s=e.s==i.s?1:-1,!n[0]||!s[0])return i.c=[i.e=0],i;for(i.e=c+f,a<u&&(t=n,n=s,s=t,f=a,a=u,u=f),t=new Array(f=a+u);f--;)t[f]=0;for(c=u;c--;){for(u=0,f=a+c;f>c;)u=t[f]+s[c]*n[f-c-1]+u,t[f--]=u%10,u=u/10|0;t[f]=u}for(u?++i.e:t.shift(),c=t.length;!t[--c];)t.pop();return i.c=t,i},le.toExponential=function(i,t){var e=this,r=e.c[0];if(i!==sn){if(i!==~~i||i<0||i>ni)throw Error(Do);for(e=si(new e.constructor(e),++i,t);e.c.length<i;)e.c.push(0)}return oi(e,!0,!!r)},le.toFixed=function(i,t){var e=this,r=e.c[0];if(i!==sn){if(i!==~~i||i<0||i>ni)throw Error(Do);for(e=si(new e.constructor(e),i+e.e+1,t),i=i+e.e+1;e.c.length<i;)e.c.push(0)}return oi(e,!1,!!r)},le[Symbol.for("nodejs.util.inspect.custom")]=le.toJSON=le.toString=function(){var i=this,t=i.constructor;return oi(i,i.e<=t.NE||i.e>=t.PE,!!i.c[0])},le.toNumber=function(){var i=+oi(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(i.toString()))throw Error(us+"Imprecise conversion");return i},le.toPrecision=function(i,t){var e=this,r=e.constructor,n=e.c[0];if(i!==sn){if(i!==~~i||i<1||i>ni)throw Error(ii+"precision");for(e=si(new r(e),i,t);e.c.length<i;)e.c.push(0)}return oi(e,i<=e.e||e.e<=r.NE||e.e>=r.PE,!!n)},le.valueOf=function(){var i=this,t=i.constructor;if(t.strict===!0)throw Error(us+"valueOf disallowed");return oi(i,i.e<=t.NE||i.e>=t.PE,!0)};var iu=Sh();function Oh(i,t){return iu(i).plus(t).toNumber()}function bo(i,t){return iu(i).minus(t).toNumber()}function Ii(i,t){return iu(i).mul(t).toNumber()}let Kw=class{constructor(t,e,r,n,s){$(this,"_variables");$(this,"_options");$(this,"_totalChangeCapital");$(this,"_historyOrder");$(this,"_orders");$(this,"_exitOrders");$(this,"_pendingOrders");$(this,"_mintick");$(this,"_funcOptions");$(this,"_pendingCloseOrders");$(this,"_errorListener");$(this,"_risk");$(this,"_opentrades");$(this,"_closedtrades");$(this,"_riskNamespace");$(this,"_updateOptions",{});$(this,"_id");$(this,"_maxDrawdownVerifyIndex",0);$(this,"calcOnOrderFillsData",{index:-1});this._variables=t,this._errorListener=n,this._options={overlay:!1,format:Gt.inherit,pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Pe.fixed,default_qty_value:1,initial_capital:1e6,currency:xh.NONE,slippage:0,commission_type:je.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=e,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._exitOrders=[],this._pendingCloseOrders=[],this._mintick=r,this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),this._variables.strategy.updateStrategyOptions(this._options),this._risk={intradayOrders:0},this._opentrades=new kw(this),this._closedtrades=new Pw(this),this._riskNamespace=new zw(this,n),this._id=`strategy_${s}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:t}=this.calcOnOrderFillsData.data||this._variables;return this._orders.reduce((e,r)=>e+t*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}get isCalcOnEveryTick(){return this._options.calc_on_every_tick}updateOptions(t){this._updateOptions=t||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._ordersHandle(),this._pendingOrderHandle(),this._exitOrdersHandle(),this._maxIntradayFilledOrdersVerify(),this._maxDrawdownVerify();const{open:t,high:e,low:r}=this.calcOnOrderFillsData.data||this._variables;let n=this._variables.close;this.calcOnOrderFillsData.tradeData&&(n=this.calcOnOrderFillsData.tradeData.open),this._variables.strategy.update({open:t,close:n,high:e,low:r}),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}calcCurrentOrder(){this._ordersHandle(),this._pendingOrderHandle(),this._calcProfitAndLoss()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:t,max_intraday_loss_type:e,isDisabledOpen:r}=this._risk;if(t===void 0||!e||r)return;const{time_tradingday:n,time:s,strategy:{netprofit:a,initial_capital:u}}=this._variables,{high:c,low:f}=this.calcOnOrderFillsData.data||this._variables;let{preNetprofit:d=0}=this._risk;s===n&&(d=a,this._risk.preNetprofit=a,this._risk.isTemporaryBan=!1);let h=d-a;h+=this._orders.reduce((y,p)=>{const{in_price:w,direction:v,qty:x=0,commission:b=0,original_qty:C=0}=p,E=v===fe.long?1:-1,A=(c-w)*x,N=(f-w)*x,S=E===1?N:-A;return y+S+x/C*b},0);let _=!1;switch(e){case Pe.cash:_=t<h;break;case Pe.percentOfEquity:const y=h/(u+a)*100;_=t<y;break}if(_){this._risk.isTemporaryBan=!0;const y=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,y===fe.long?f:c,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:t,intradayOrders:e=0,isDisabledOpen:r}=this._risk;if(t===void 0||r)return;const{time:n,time_tradingday:s}=this._variables,{open:a}=this.calcOnOrderFillsData.data||this._variables;n===s&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),t<=e&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:t,lossDays:e=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(t===void 0||r)return;const{time:s,time_tradingday:a,strategy:u}=this._variables,{open:c}=this.calcOnOrderFillsData.data||this._variables;let f=e;if(s===a){const d=u.netprofit+u.openprofit;d<n?f=0:f++,Object.assign(this._risk,{lossDays:f,totalProfit:d})}t<=f&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:n}=this._variables,{open:s}=this.calcOnOrderFillsData.data||this._variables;if(t!==void 0&&e&&this._maxDrawdownVerifyIndex===n){const{initial_capital:a}=this._options,c=this._orders.reduce((d,h)=>{const{in_price:_,commission:g=0,qty:y=0,original_qty:p=0,direction:w}=h,v=w===fe.long?1:-1,x=(s-_)*v*y;return d+x+g*y/p},0)+this._totalChangeCapital;let f=!1;switch(e){case Pe.percentOfEquity:f=c/a*100<=-t;break;case Pe.cash:f=c<=-t;break}f&&this._riskTouchOff(s,"Close Position (Max Drawdown)")}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,t,e,"close"),this._pendingOrders=[]}strategy(t,e){if(!this._variables.bar_index){this._paramVerfiy(t.format,e,"strategy",[Gt.inherit,Gt.price,Gt.percent,Gt.volume],"format"),this._paramVerfiy(t.default_qty_type,e,"strategy",Object.values(Pe),"default_qty_type"),this._paramVerfiy(t.commission_type,e,"strategy",Object.values(je),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),n={...this._updateOptions};if(r)for(const s of Object.keys({...r,...t}))t[s]!==r[s]&&delete n[s];self==null||self.workerStorage.set(this._id,t),Object.assign(this._options,t,n),this._variables.updateMaxLength(t),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:n,scriptType:"strategy"})}}order(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.order",Object.values(fn),"oca_type"),this._orderHandle(t))}entry(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.entry",Object.values(fn),"oca_type"),this._entryHandle(t))}close(t){if(!this._orders.filter(r=>!this._options.process_orders_on_close||r.in_index!==this._variables.bar_index).length)return;const{immediately:e}=t;if(e||this._options.process_orders_on_close){const r=this._pendingCloseOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingCloseOrders.push({...t,place_order_type:"close"})}else{const r=this._pendingOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingOrders.push({...t,place_order_type:"close"})}}close_all(t){if(typeof t=="string"&&(t={}),!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close_all"}):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>!(e.id===t&&e.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(t,e){this._exit(t,e)}convert_to_account({value:t}){return t}convert_to_symbol({value:t}){return t}default_entry_qty({fill_price:t}){return t?this._calcDefaultQty(t):0}_calcDefaultQty(t){const{default_qty_type:e=Pe.fixed,default_qty_value:r=1,initial_capital:n,commission_value:s}=this._options;let a=r;switch(e){case Pe.cash:a=r/t;break;case Pe.percentOfEquity:const u=this._getOrderProfit(t),c=n+u+this._totalChangeCapital;s?a=this._getCommQty(c,t):a=c*r/100/t;break}return Ql(a,this._getLen(t))}_getCommQty(t,e){const{commission_type:r,commission_value:n=0,default_qty_value:s=0}=this._options;let a=0;switch(r){case je.percent:a=t*s/(100*e+n*e);break;case je.cashPerContract:a=t*s/(100*e+n);break;case je.cashPerOrder:a=(t-n)*s/100/e}return a}_getLen(t){const e=String(Math.floor(t)).length-3;return e<0?0:e}_getCapital(t,e){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&t===1?e=e*100/r:n<=100&&n>0&&t===-1&&(e=e*100/n),e}_calcProfitAndLoss(){const{close:t}=this.calcOnOrderFillsData.data||this._variables;for(const e of this._orders){const{in_price:r,qty:n=0,direction:s}=e,a=s===fe.long?1:-1,u=(t-r)*a*n,[c,f]=this._calcProfitAndLossHandle(r,n,a);this._calcOrderPercent(e,u,c,f)}}_calcProfitAndLossHandle(t,e,r,n){const{high:s,low:a}=this.calcOnOrderFillsData.data||this._variables,u=((n||s)-t)*e,c=((n||a)-t)*e;let f=r===1?u:-c,d=r===1?c:-u;return[f,d]}_calcOrderPercent(t,e,r,n){const{commission_value:s}=this._options,{close:a}=this.calcOnOrderFillsData.data||this._variables,{original_qty:u=0,qty:c=0,in_price:f,max_profit:d=0,trading_loss:h=0}=t;let{commission:_=0}=t,g=f*c;if(s){const y=this._getCommission(a,c);_=_*c/u,r-=_,n-=_,g+=_,e=e-y-_}r=Math.max(r,d,0),n=Math.min(n,h,0),Object.assign(t,{profit:e,total_profit:this._totalChangeCapital+e,total_profit_percent:e/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:n,profit_percent:e/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{time:t}=this._variables,{high:e,low:r}=this.calcOnOrderFillsData.data||this._variables,{initial_capital:n,margin_long:s=0,margin_short:a=0}=this._options,u=this._orders[0].direction===fe.long?1:-1;let c=u===1?r:e;if(u===1&&s===100)return;const f=(u===1?s:a)/100;if(f<=0)return;let d=!1;const[h,_]=this._orders.reduce((w,v)=>{let[x,b]=w;const{in_price:C,qty:E=0,in_time:A}=v;A===t&&(d=!0);const N=C*E,S=c*E;return x+=N,b+=S,[x,b]},[0,0]);let g=0,y=0;const p=n+this._totalChangeCapital;if(d&&(g=p-h*f,g<0&&(c=this._orders[0].in_price,y=Math.abs(Math.trunc(g/f/c)*4),y=Math.max(y,1))),g>=0){const w=u*(_-h);if(g=p+w-_*f,g>=0)return;y=Math.abs(Math.trunc(g/f/c)*4)}y<=0||this._marginCallOrders(c,y,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r,!0);return}for(const s of this.orders)s.position_close_type=s.place_order_type,s.isTiggerClose=!0,this._processOrder(s,t,e,r,r,!0);this._orders=this._orders.filter(s=>!s.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:s,quantities:a,close:u,price:c,activePrice:f,isTouch:d}=this._orderArgsParse(t),h=t.direction===fe.long?1:-1;if(a<=0)return;let _=a;if((s||d)&&e){const y=d?c:u;if(n.length){const E=this._processOrders(n,y,_,t.id,t.comment,!1,"order");if(E<=0)return;_=E}const p=y-h*r*this._mintick;if(!this._judgeCapitalEnough(_,p,h))return;this._ocaGroupVerify(_,t.oca_name,t.oca_type);const{bar_index:v,time:x}=this._variables,{high:b,low:C}=this.calcOnOrderFillsData.data||this._variables;this._calcCurrentOrder({...t,in_price:p,in_high:b,in_low:C,in_index:v,in_time:x,qty:_,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,h)&&this._addPendingOrders(t,c,_,s,f)}_judgeCapitalEnough(t,e,r){let n=this._freezeCapital;if(this._orders.some(d=>(d.direction===fe.long?1:-1)!==r)&&(n=0),t<=0)return!1;const{margin_long:s=0,margin_short:a=0}=this._options;if(s===0&&r===1||a===0&&r===-1)return!0;const u=this._getOrderProfit(e),f=this._getCapital(r,this._options.initial_capital+u+this._totalChangeCapital)-n;return t*e<=f}_getOrderProfit(t){return this._orders.reduce((e,r)=>{const{in_price:n,qty:s=0,direction:a}=r,u=a===fe.long?1:-1;return e+(t-n)*s*u},0)}_ocaGroupVerify(t,e,r){if(!e||!r||r===fn.none)return!1;let n=!1;switch(r){case fn.cancel:this._pendingOrders=this._pendingOrders.filter(s=>{if(s.oca_name===e)s.isCancel=!0,n=!0;else return!0});break;case fn.reduce:this._pendingOrders=this._pendingOrders.filter(s=>{const{qty:a=0,oca_name:u}=s;if(e===u){const c=a-t;return n=!0,c<=0?(s.isCancel=!0,!1):(s.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,s,a=!1,u,c){let f=r;for(const d of t)if(d.position_close_type=u||d.place_order_type,d.immediately=c,d.isTiggerClose=a||d.position_close_type==="close",f=this._processOrder(d,e,f,n,s,a),f<=0)break;return this._orders=this._orders.filter(d=>!d.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),f}_addPendingOrders(t,e,r,n,s){const a=this._pendingOrders.find(u=>u.id===t.id&&!u.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else{const u={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,entry_time:this._variables.time,place_order_type:"order"};this._pendingOrders.push(u)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let s=t.limit||0;const{close:a}=this.calcOnOrderFillsData.data||this._variables;let u=a,c=!1,f;const d=e===fe.long?1:-1,h=n&&(n-a)*d>=0,{backtest_fill_limits_assumption:_=0}=this._options;_>0&&s&&(s-=_*this._mintick*d);const g=s&&(s-a)*d<=0;let y=!1;h&&g?(n!==a&&(f=n),u=s):h?(u=n,y=n===a):g?(u=s,y=s===a):c=!0;const p=r!==void 0?Ql(r,this._getLen(u)):this._calcDefaultQty(u);return{orders:this._orders.filter(v=>v.direction!==e),isMarketPrice:c,activePrice:f,quantities:p,close:a,price:u,isTouch:y}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:s,close:a,price:u,activePrice:c,isTouch:f}=this._orderArgsParse(t);if(s<=0)return;if((n||f)&&e){this._entryOrder(r,f?u:a,s,t);return}this._judgeCapitalEnough(s,a,t.direction===fe.long?1:-1)&&this._addPendingEntry(t,u,s,n,c)}_entryOrder(t,e,r,n){const{time:s,bar_index:a}=this._variables,{high:u,low:c}=this.calcOnOrderFillsData.data||this._variables,{slippage:f=0}=this._options,{oca_name:d,oca_type:h,direction:_,comment:g,id:y}=n,p=_===fe.long?1:-1;if(r=this._getAvailablePositionSize(r,_),r<=0)return;const w=e;if(e=e+f*this._mintick*p,!this._judgeCapitalEnough(r,e,p))return;this._closeOrders(t,w,y,g,"entry",void 0,!0);const x={...n,in_price:e,qty:r,in_index:a,in_high:u,in_low:c,in_time:s,place_order_type:"entry"},{orders:b}=this._getEntryOrders(_),C=b.length;C&&C>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,d,h),this._calcCurrentOrder(x))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==fe.all&&n!==e)return 0;if(r===void 0)return t;const s=this._orders.reduce((a,u)=>a+(u.qty||0),0);return s?s+t>r?0:t:t>r?t-r:0}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===t),r=this._orders.filter(n=>n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,s){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:u}=this._getEntryOrders(t.direction),c=a.find(f=>f.id===t.id&&f.place_order_type==="entry");if(c)Object.assign(c,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s});else{const f={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,entry_time:this._variables.time,place_order_type:"entry"};this._pendingOrders.push(f)}}_closeAllOrders(t,e){const{comment:r,immediately:n}=t,{bar_index:s}=this._variables,a=this._orders.filter(u=>u.in_index!==s);a.length&&(this._closeOrders(a,e,"Close position order",r,"close",n),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n,s,a,u){for(const c of t)c.position_close_type=s,c.immediately=a,c.isTiggerClose=!0,this._closeOrder(c,e,r,n,u);this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_closeOrder(t,e,r,n,s){const{time:a,bar_index:u}=this._variables,{high:c,low:f}=this.calcOnOrderFillsData.data||this._variables,{slippage:d=0}=this._options,{in_price:h,qty:_=0,direction:g}=t,y=g===fe.long?1:-1;e=e-y*d*this._mintick,t.isDeal=!0;const p=(e-h)*y*_,w={...t,out_price:e,out_id:r,out_index:u,out_high:c,out_low:f,out_time:a,out_comment:n,out_qty:_,profit:p};this._calcPercent(w,s)}_exitOrdersHandle(){if(!this._exitOrders.length)return;let{open:t,low:e,high:r,close:n}=this.calcOnOrderFillsData.data||this._variables;const s=[],a=Math.abs(r-t),u=Math.abs(e-t),c=[],f=this._variables.precision;t=Number(t.toFixed(f)),e=Number(e.toFixed(f)),r=Number(r.toFixed(f)),n=Number(n.toFixed(f));for(const d of this._exitOrders){const{directionNum:h,id:_,comment:g,qty:y,comment_loss:p,comment_profit:w,comment_trailing:v,order:x}=d;if(x.isTiggerClose)continue;let b=a<u||a===u&&h===1;const C=[],[E,A]=this._getLimitPrice(d,t,e,r,b);E&&C.push({order:x,price:E,index:A,isHighFront:b,exitInfo:{id:_,comment:w||g,qty:y}});const[N,S]=this._getStopPrice(d,t,e,r,b);N&&C.push({order:x,price:N,index:S,isHighFront:b,exitInfo:{id:_,comment:p||g,qty:y}});const[I,F]=this._getTrailStopPrice(d,t,e,r,n,b);if(I&&C.push({order:x,price:I,index:F,isHighFront:b,exitInfo:{id:_,comment:v||g,qty:y}}),C.length){this._executesSort(C),s.push(C[0]);continue}c.push(d)}this._exitOrders=c,this._executesSort(s);for(const d of s){const{order:h,price:_,exitInfo:g,isHighFront:y,index:p}=d;y?(r=p===1?_:r,e=p===1?t:_):(r=p===1?t:_,e=p===1?_:e),this._variables.strategy.update({open:_,high:r,low:e,close:n}),this._processExitOnClose(h,_,g)}}_executesSort(t){return t.sort(({price:e,index:r,isHighFront:n},{price:s,index:a})=>r!==a?r-a:n?r===1?e-s:s-e:r===1?s-e:e-s),t}_getLimitPrice(t,e,r,n,s){const{limit:a,directionNum:u}=t;let c,f=1;return a&&((e-a)*u>=0?(c=e,f=1):r<=a&&n>=a&&(c=a,s&&a>e||!s&&a<e?f=1:f=2)),[c,f]}_getStopPrice(t,e,r,n,s){const{stop:a,directionNum:u}=t;let c,f=1;return a&&((e-a)*u<=0?(c=e,f=1):r<=a&&n>=a&&(c=a,s&&a>e||!s&&a<e?f=1:f=2)),[c,f]}_getTrailStopPrice(t,e,r,n,s,a){const{trail_stop_price:u,directionNum:c,active_price:f,trail_offset:d=0}=t;let h=u,_,g=1;if(h)if((h-e)*c>=0)_=e,g=1;else{const[y,p,w]=this._calcTrailStopPrice(h,n,r,s,d,c,a);_=p,g=w||1,t.trail_stop_price=y}if(f&&!_&&f<=n&&f>=r)if(d===0)_=f,a&&f>e||!a&&f<e?g=1:g=2;else{h=bo(f,Ii(d*c,this._mintick));let y=n,p=r;a?f>=e&&f<=n?(y=n,g=1):(a=!1,y=s,g=2):f<e&&f>=r?(p=r,g=1):(a=!0,p=s,g=2);const[w,v,x=1]=this._calcTrailStopPrice(h,y,p,s,d,c,a);delete t.active_price,g<x&&(g=x),t.trail_stop_price=w,_=v}return[_,g]}_ordersHandle(t){const e=this._orders.filter(a=>a.isMarketPriceLimit||a.isMarketPriceStop);if(!e.length)return;const{open:r,close:n}=this.calcOnOrderFillsData.data||this._variables,s=t?n:r;for(const a of e){const{out_comment:u,out_qty:c,out_id:f}=a;this._processExitOnClose(a,s,{id:f,comment:u,qty:c})}}_calcTrailStopPrice(t,e,r,n,s,a,u){let c=t,f;const d=bo(a===1?e:r,Ii(s*a,this._mintick));let h=1;return a===1?u?(c<d&&(c=d),c>=r&&(h=2,f=c)):c>=r?(h=1,f=c):d>c&&(c=d,d>=n&&(h=3,f=d)):u?c<=e?(h=1,f=c):d<c&&(c=d,d<=n&&(h=3,f=d)):(d<c&&(c=d),c<=e&&(h=2,f=c)),[c,f,h]}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=this._pendingOrders.filter(r=>r.place_order_type==="exit");for(const r of this._pendingOrders){const{isCancel:n,place_order_type:s}=r;if(n)continue;let a;switch(s){case"entry":a=this._entryOrderHandle(r);break;case"order":a=this._orderOrderHandle(r);break;case"close":a=this._closeOrderHandle(r);break;case"close_all":const{open:u}=this.calcOnOrderFillsData.data||this._variables;this._closeAllOrders(r,u);break}a&&t.push(a)}for(const r of e){const n=this._exitOrderHandle(r);n&&t.push(n)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(r=>["close","close_all"].includes(r.place_order_type||"")),{close:e}=this.calcOnOrderFillsData.data||this._variables;this._pendingCloseOrders=[];for(const r of t)switch(r.place_order_type){case"close":const n=this._closeOrderHandle(r,!0);n&&this._pendingCloseOrders.push(n);break;case"close_all":this._closeAllOrders(r,e);break}this._ordersHandle(!0)}_entryOrderHandle(t){const{open:e,low:r,high:n}=this.calcOnOrderFillsData.data||this._variables,{isMarketPrice:s,qty:a=0,in_price:u,direction:c,active_price:f}=t;if(f&&n>=f&&r<=f)return delete t.active_price,t;let d=u;if(s&&(d=e),d<=n&&d>=r){const h=this._orders.filter(_=>_.direction!==c);this._entryOrder(h,d,a,t)}else return t}_orderOrderHandle(t){const{time:e,bar_index:r}=this._variables,{open:n,low:s,high:a}=this.calcOnOrderFillsData.data||this._variables,{slippage:u=0}=this._options,{isMarketPrice:c,qty:f=0,in_price:d,direction:h,comment:_,oca_name:g,oca_type:y,active_price:p,id:w}=t;if(p&&a>=p&&s<=p)return delete t.active_price,t;let v=d,x=f;if(c&&(v=n),v<=a&&v>=s){const b=this._orders.filter(E=>E.direction!==h);if(b.length&&(x=this._processOrders(b,v,f,w,_,!1,"order"),x<=0))return;const C=h===fe.long?1:-1;this._ocaGroupVerify(x,g,y),this._calcCurrentOrder({...t,in_price:v-C*u*this._mintick,in_index:r,in_time:e,in_high:a,in_low:s,qty:x});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:s=100,comment:a,immediately:u}=t,{close_entries_rule:c="FIFO"}=this._options;let f=[];if(c==="FIFO"?f=this._orders.filter(g=>g.id===r):f=this._orders.filter(g=>g.id===r&&!g.close_qty),!f.length)return;let d=0;if(n?d=n:(d=f.reduce((g,y)=>g+(y.qty||0),d),d=s/100*d),d<=0)return;const{open:h,close:_}=this.calcOnOrderFillsData.data||this._variables;if(c==="FIFO")this._processOrders(f,e?_:h,d,`Close entry(s) order ${r}`,a,!1,"close",u);else if(this._processCloseOrders(f,e?_:h,d,`Close entry(s) order ${r}`,a,u))return t}_processCloseOrders(t,e,r,n,s,a){let u=!1;for(const c of t)c.close_qty=r,(c.qty||0)>r&&(u=!0),c.immediately=a,c.position_close_type="close",c.isTiggerClose=!0,this._processOrder(c,e,r,n,s);return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),u}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,t,!0)))return t}_exit(t,e){if(!t.hasOwnProperty("profit")&&!t.hasOwnProperty("loss")&&!t.hasOwnProperty("stop")&&!t.hasOwnProperty("limit")&&(!t.hasOwnProperty("trail_offset")||!t.hasOwnProperty("trail_price")&&!t.hasOwnProperty("trail_points"))){this._errorListener.addError(ie.strategyExitErr,e,Rt.Error);return}const{profit:r,loss:n,stop:s,limit:a,trail_offset:u,trail_price:c,trail_points:f,from_entry:d="",id:h}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(s)&&this._isNaN(a)&&(this._isNaN(u)||this._isNaN(f)&&this._isNaN(c)))return;const _={...t,place_order_type:"exit"},g=this._orders.filter(v=>(!d||d===v.id)&&!v.hasExit),y=this._updateExitOrders(_),p=this._pendingOrders.filter(v=>(!d||d===v.id)&&["order","entry"].includes(v.place_order_type||""));if(g.length){if(!this._ordersToExit(g,_,!1))return}else if(!p.length||y)return;const w=this._pendingOrders.find(v=>v.id===h&&v.place_order_type==="exit");w?Object.assign(w,{...t}):this._pendingOrders.push(_)}_updateExitOrders(t){let e=!1;const r=this._exitOrders.filter(n=>n.id===t.id&&(n.from_entry===t.from_entry||!t.from_entry));for(const n of r){const{directionNum:s,order:a}=n;if(a.isTiggerClose){n.isClose=!0;continue}e=!0;const u={...t};if(this._stopProfit(a,s,u)){n.isClose=!0;continue}if(this._stopLoss(a,s,u)){n.isClose=!0;continue}if(this._trailStopLoss(a,s,u)){n.isClose=!0;continue}Object.assign(n,u)}return this._exitOrders=this._exitOrders.filter(n=>!n.isClose),e}_ordersToExit(t,e,r){const{qty:n,qty_percent:s=100,id:a,comment:u}=e;let c=n,f=!1;e.comment=u||a;const d=t[0],h={...e},{qty:_=0}=d,g=d.direction===fe.long?1:-1;return c=n?n>=_?_:n:s/100*_,h.qty=c,c<_&&(f=!0),this._stopProfit(d,g,h,r)||this._stopLoss(d,g,h,r)||this._trailStopLoss(d,g,h,r)||(this._exitOrders.push({...h,directionNum:g,order:d}),d.hasExit=!0),f}_addExitPendingCloseOrders(t){const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r,n){const{limit:s,profit:a,comment_profit:u,comment:c,id:f,qty:d}=r;let h=s;const{close:_}=this.calcOnOrderFillsData.data||this._variables,{in_price:g}=t,{process_orders_on_close:y}=this._options;if(!this._isNaN(a)&&this._isNaN(s)&&(h=Oh(g,Ii(a*e,this._mintick))),r.limit=e===1?ec(h,this._variables.precision):rc(h,this._variables.precision),!n&&h!==void 0&&(h-_)*e<=0)return t.isMarketPriceLimit=!0,r.comment=u||c,Object.assign(t,{out_comment:r.comment,out_id:f,out_qty:d}),y&&this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r,n){const{stop:s,loss:a,comment_loss:u,comment:c,id:f,qty:d}=r;let h=s;const{close:_}=this.calcOnOrderFillsData.data||this._variables,{in_price:g}=t,{process_orders_on_close:y}=this._options;if(!this._isNaN(a)&&this._isNaN(s)&&(h=bo(g,Ii(a*e,this._mintick))),r.stop=e===1?rc(h,this._variables.precision):ec(h,this._variables.precision),!n&&h!==void 0&&(h-_)*e>=0)return t.isMarketPriceStop=!0,r.comment=u||c,Object.assign(t,{out_comment:r.comment,out_id:f,out_qty:d}),y&&this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r,n){const{trail_offset:s,trail_price:a,trail_points:u,comment_trailing:c,comment:f,id:d,qty:h}=r;if(!this._isNaN(s)){const{close:_}=this.calcOnOrderFillsData.data||this._variables,{in_price:g}=t,{process_orders_on_close:y}=this._options;let p;if(this._isNaN(a)?this._isNaN(u)||(p=Oh(g,Ii(u*e,this._mintick))):p=a,r.active_price=p,n)return;if(p!==void 0&&(p-_)*e<=0){const w=bo(_,Ii(s*e,this._mintick));if((w-_)*e>=0)return t.isMarketPriceStop=!0,r.comment=c||f,Object.assign(t,{out_comment:r.comment,out_id:d,out_qty:h}),y&&this._addExitPendingCloseOrders(r),!0;r.trail_stop_price=w}}}_processExitOnClose(t,e,r){const{qty:n=0,comment:s,id:a}=r,{close_entries_rule:u="FIFO"}=this._options;if(n)if(t.isTiggerClose=!0,u==="FIFO")this._processExitOrders(this._orders,e,n,a,s);else{if(t.isDeal)return;this._processOrders([t],e,n,a,s,!1,"exit")}}_processExitOrders(t,e,r,n,s){let a=r,u;for(const c of t)if(u=c,c.position_close_type="exit",a=this._processOrder(c,e,a,n,s),a<=0)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),u}_processOrder(t,e,r,n,s,a=!1){const{time:u,bar_index:c}=this._variables,{low:f,high:d}=this.calcOnOrderFillsData.data||this._variables,{slippage:h=0}=this._options,{in_price:_,qty:g=0,max_profit:y,trading_loss:p,direction:w,commission:v=0,original_qty:x=0}=t,b=w===fe.long?1:-1;if(e=e-b*h*this._mintick,r<g){const C=g-r,E=(e-_)*b*r,A=y!==void 0?y/g*r:void 0,N=p!==void 0?p/g*r:void 0,S=v*C/x;this._calcPercent({...t,out_price:e,last_commission:S,out_id:n,out_index:c,out_high:d,out_low:f,out_time:u,out_comment:s,profit:E,out_qty:r,max_profit:A,trading_loss:N});const I=(e-_)*b*C-S;Object.assign(t,{qty:C,profit:I,max_profit:y!==void 0?y-(A||0):void 0,trading_loss:p!==void 0?p-(N||0):void 0,total_profit:this._totalChangeCapital+I}),r=0}else{t.isDeal=!0;const C=(e-_)*b*g;this._calcPercent({...t,out_price:e,out_id:n,out_index:c,out_high:d,out_low:f,out_time:u,out_comment:s,out_qty:g,profit:C}),r-=g}return a&&(b===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(t,e){const{commission_value:r,process_orders_on_close:n}=this._options,{in_price:s,out_qty:a=0,out_price:u=0,original_qty:c=0,direction:f,last_commission:d=0,immediately:h}=t;let{profit:_=0,max_profit:g,trading_loss:y,commission:p=0}=t,w=s*a,v=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=_,r){const E=this._getCommission(u,a);this._totalChangeCapital-=E;let A=p*a/c;w+=A,A+=E,_=_-A,Object.assign(t,{commission:A});const N=this._orders.reduce((S,I)=>{const{qty:F=0,original_qty:O=0,commission:L=0}=I;return S+L*F/O},0);v+=N-d}const x=f===fe.long?1:-1;let[b,C]=this._calcProfitAndLossHandle(s,a,x,u);if(r){const E=p*a/c;b-=E,C-=E}g=Math.max(b,g||0),y=Math.min(C,y||0),_=parseFloat(String(_)),Object.assign(t,{max_profit:g,profit:_,trading_loss:y,total_profit:this._totalChangeCapital,total_profit_percent:_/v*100,profit_percent:_/w*100,max_profit_percent:g/w*100,trading_loss_percent:y/w*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(n?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(t),!e&&this._calcOrderFillsHandle(u,f,h)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case je.percent:a=s*r/100;break;case je.cashPerContract:a=e*r;break;case je.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:s=0,trading_loss:a=0,direction:u,immediately:c}=t;let{profit:f=0}=t,d=r*n;const h=this._totalChangeCapital+this._options.initial_capital;if(e){const _=this._getCommission(r,n);this._totalChangeCapital-=_,f=f-_,d+=_,Object.assign(t,{commission:_,total_profit:this._totalChangeCapital})}f=parseFloat(String(f)),Object.assign(t,{original_qty:n,profit:f,total_profit_percent:f/h*100,profit_percent:f/d*100,max_profit_percent:s/d*100,trading_loss_percent:a/d*100,stop:void 0,limit:void 0}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders),e&&this._variables.strategy.updateHistoryOrders(this._historyOrder),this._calcOrderFillsHandle(r,u,c)}_calcOrderFillsHandle(t,e,r=!1){const{calc_on_order_fills:n,process_orders_on_close:s,slippage:a=0}=this._options;if(n){const{open:u,high:c,low:f,close:d}=this._variables,h=e===fe.long?1:-1,_=d-h*a*this._mintick;if((r||s)&&t===_)return;const g=u-h*a*this._mintick;let y={open:u,high:c,low:f,close:d},p=this.calcOnOrderFillsData.index;const w=Math.abs(c-u)<=Math.abs(f-u);switch(p){case-1:t===g?p=0:t>g?w?(p=1,y={open:c,high:c,low:f,close:d}):(p=2,y={open:c,high:c,low:d,close:d}):w?(p=2,y={open:f,high:d,low:f,close:d}):(p=1,y={open:f,high:c,low:f,close:d});break;case 0:t===g?(p=1,w?y={open:c,high:c,low:f,close:d}:y={open:f,high:c,low:f,close:d}):t>g?w?(p=1,y={open:c,high:c,low:f,close:d}):(p=2,y={open:c,high:c,low:d,close:d}):w?(p=2,y={open:f,high:d,low:f,close:d}):(p=1,y={open:f,high:c,low:f,close:d});break;case 1:p=2,w?y={open:f,high:d,low:f,close:d}:y={open:c,high:c,low:d,close:d};break;case 2:p=-1,y=void 0;break}this.calcOnOrderFillsData={tradeData:y,index:p}}}_isNaN(t){return t===void 0||isNaN(t)}_paramVerfiy(t="",e,r,n,s){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}};var Bh={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){return function(e,r,n){r.prototype.isBetween=function(s,a,u,c){var f=n(s),d=n(a),h=(c=c||"()")[0]==="(",_=c[1]===")";return(h?this.isAfter(f,u):!this.isBefore(f,u))&&(_?this.isBefore(d,u):!this.isAfter(d,u))||(h?this.isBefore(f,u):!this.isAfter(f,u))&&(_?this.isAfter(d,u):!this.isBefore(d,u))}}})})(Bh);var Gw=Bh.exports,Jw=Kt(Gw),Th={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){return function(e,r,n){var s=r.prototype,a=function(_){var g,y=_.date,p=_.utc,w={};if(!((g=y)===null||g instanceof Date||g instanceof Array||s.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(y).length)return new Date;var v=p?n.utc():n();Object.keys(y).forEach(function(I){var F,O;w[F=I,O=s.$utils().p(F),O==="date"?"day":O]=y[I]});var x=w.day||(w.year||w.month>=0?1:v.date()),b=w.year||v.year(),C=w.month>=0?w.month:w.year||w.day?0:v.month(),E=w.hour||0,A=w.minute||0,N=w.second||0,S=w.millisecond||0;return p?new Date(Date.UTC(b,C,x,E,A,N,S)):new Date(b,C,x,E,A,N,S)}return y},u=s.parse;s.parse=function(_){_.date=a.bind(this)(_),u.bind(this)(_)};var c=s.set,f=s.add,d=s.subtract,h=function(_,g,y,p){p===void 0&&(p=1);var w=Object.keys(g),v=this;return w.forEach(function(x){v=_.bind(v)(g[x]*p,x)}),v};s.set=function(_,g){return g=g===void 0?_:g,_.constructor.name==="Object"?h.bind(this)(function(y,p){return c.bind(this)(p,y)},g,_):c.bind(this)(_,g)},s.add=function(_,g){return _.constructor.name==="Object"?h.bind(this)(f,_,g):f.bind(this)(_,g)},s.subtract=function(_,g){return _.constructor.name==="Object"?h.bind(this)(f,_,g,-1):d.bind(this)(_,g)}}})})(Th);var Xw=Th.exports,Qw=Kt(Xw),Ih={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Vt,function(){var e,r,n=1e3,s=6e4,a=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,f=31536e6,d=2628e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,_={years:f,months:d,days:u,hours:a,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},g=function(A){return A instanceof C},y=function(A,N,S){return new C(A,S,N.$l)},p=function(A){return r.p(A)+"s"},w=function(A){return A<0},v=function(A){return w(A)?Math.ceil(A):Math.floor(A)},x=function(A){return Math.abs(A)},b=function(A,N){return A?w(A)?{negative:!0,format:""+x(A)+N}:{negative:!1,format:""+A+N}:{negative:!1,format:""}},C=function(){function A(S,I,F){var O=this;if(this.$d={},this.$l=F,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),I)return y(S*_[p(I)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(q){O.$d[p(q)]=S[q]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(h);if(L){var z=L.slice(2).map(function(q){return q!=null?Number(q):0});return this.$d.years=z[0],this.$d.months=z[1],this.$d.weeks=z[2],this.$d.days=z[3],this.$d.hours=z[4],this.$d.minutes=z[5],this.$d.seconds=z[6],this.calMilliseconds(),this}}return this}var N=A.prototype;return N.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(I,F){return I+(S.$d[F]||0)*_[F]},0)},N.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/f),S%=f,this.$d.months=v(S/d),S%=d,this.$d.days=v(S/u),S%=u,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},N.toISOString=function(){var S=b(this.$d.years,"Y"),I=b(this.$d.months,"M"),F=+this.$d.days||0;this.$d.weeks&&(F+=7*this.$d.weeks);var O=b(F,"D"),L=b(this.$d.hours,"H"),z=b(this.$d.minutes,"M"),q=this.$d.seconds||0;this.$d.milliseconds&&(q+=this.$d.milliseconds/1e3,q=Math.round(1e3*q)/1e3);var W=b(q,"S"),R=S.negative||I.negative||O.negative||L.negative||z.negative||W.negative,Z=L.format||z.format||W.format?"T":"",Y=(R?"-":"")+"P"+S.format+I.format+O.format+Z+L.format+z.format+W.format;return Y==="P"||Y==="-P"?"P0D":Y},N.toJSON=function(){return this.toISOString()},N.format=function(S){var I=S||"YYYY-MM-DDTHH:mm:ss",F={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return I.replace(c,function(O,L){return L||String(F[O])})},N.as=function(S){return this.$ms/_[p(S)]},N.get=function(S){var I=this.$ms,F=p(S);return F==="milliseconds"?I%=1e3:I=F==="weeks"?v(I/_[F]):this.$d[F],I||0},N.add=function(S,I,F){var O;return O=I?S*_[p(I)]:g(S)?S.$ms:y(S,this).$ms,y(this.$ms+O*(F?-1:1),this)},N.subtract=function(S,I){return this.add(S,I,!0)},N.locale=function(S){var I=this.clone();return I.$l=S,I},N.clone=function(){return y(this.$ms,this)},N.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},N.valueOf=function(){return this.asMilliseconds()},N.milliseconds=function(){return this.get("milliseconds")},N.asMilliseconds=function(){return this.as("milliseconds")},N.seconds=function(){return this.get("seconds")},N.asSeconds=function(){return this.as("seconds")},N.minutes=function(){return this.get("minutes")},N.asMinutes=function(){return this.as("minutes")},N.hours=function(){return this.get("hours")},N.asHours=function(){return this.as("hours")},N.days=function(){return this.get("days")},N.asDays=function(){return this.as("days")},N.weeks=function(){return this.get("weeks")},N.asWeeks=function(){return this.as("weeks")},N.months=function(){return this.get("months")},N.asMonths=function(){return this.as("months")},N.years=function(){return this.get("years")},N.asYears=function(){return this.as("years")},A}(),E=function(A,N,S){return A.add(N.years()*S,"y").add(N.months()*S,"M").add(N.days()*S,"d").add(N.hours()*S,"h").add(N.minutes()*S,"m").add(N.seconds()*S,"s").add(N.milliseconds()*S,"ms")};return function(A,N,S){e=S,r=S().$utils(),S.duration=function(O,L){var z=S.locale();return y(O,{$l:z},L)},S.isDuration=g;var I=N.prototype.add,F=N.prototype.subtract;N.prototype.add=function(O,L){return g(O)?E(this,O,1):I.bind(this)(O,L)},N.prototype.subtract=function(O,L){return g(O)?E(this,O,-1):F.bind(this)(O,L)}}})})(Ih);var tD=Ih.exports,eD=Kt(tD);Wt.extend(xa),Wt.extend(Ea),Wt.extend(Jw),Wt.extend(Qw),Wt.extend(eD);class $h{constructor(t,e,r){$(this,"array");$(this,"color");$(this,"math");$(this,"str");$(this,"map");$(this,"matrix");$(this,"timeframe");$(this,"ta");$(this,"input");$(this,"_variables");$(this,"_cacheData");$(this,"_options");$(this,"_errorListener");$(this,"_plots");$(this,"_plotshapes");$(this,"_plotbars");$(this,"_plotchars");$(this,"_plotarrows");$(this,"_plotcandles");$(this,"_alerts");$(this,"_bgColors");$(this,"_hlines");$(this,"_fills");$(this,"chart");$(this,"line");$(this,"label");$(this,"polyline");$(this,"box");$(this,"table");$(this,"linefill");$(this,"log");$(this,"runtime");$(this,"strategy");$(this,"request");$(this,"syminfo");$(this,"_count",0);var s;const n=((s=t.toString().split(".")[1])==null?void 0:s.length)||5;this._variables=e,this._errorListener=new aD,this.array=new I_(this._errorListener),this.math=new $_(n,this._errorListener),this.color=new oy,this.str=new lw(this._errorListener,n),this.map=new cw(this._errorListener),this.timeframe=new ow(e),this.matrix=new sw(this._errorListener),this.ta=new iy(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new sy(e,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new fw(e)},this.line=new Iw(e,this._errorListener),this.label=new hw(e,this._errorListener),this.polyline=new Tw(e,this._errorListener),this.box=new Lw(e,this._errorListener),this.table=new Rw(e,this._errorListener),this.linefill=new $w(e),this.log=new sD(e,this.str),this.runtime=new oD(this._errorListener),this.strategy=new Kw(this._variables,this._options,t,this._errorListener,r),this.request=new nD(this._variables,r),this.syminfo=new iD}get errors(){return this._errorListener.errors}get scriptType(){return this._options.scriptType}options(t){if(t.length)return this._getDataOfBarindex(t);const e=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let s;if(n.length){s={};for(const v of n)s[v]=[...this._bgColors[v].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,u=this._fills.size?[...this._fills.values()]:void 0,c=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders,strategySummary:this._variables.strategy.summaryData});const f=this._plots.size>0?[...this._plots.values()]:void 0,d=this._plotbars.size>0?[...this._plotbars.values()]:void 0,h=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,_=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,g=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,y=this._plotchars.size>0?[...this._plotchars.values()]:void 0,p=this._getDraws(),w=this._variables.chart.isUseBgColor;return Object.assign(this._options,{inputs:e,plots:f,draws:p,alerts:r,colors:s,hlines:a,fills:u,logs:c,plotshapes:h,plotarrows:_,plotcandles:g,plotchars:y,plotbars:d,isUseBgColor:w})}_getDataOfBarindex(t){const e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let n;if(r.length){n={};for(const v of r)n[v]=[...this._bgColors[v].values()].map(x=>{const b=[];for(const C of t){const E=x.data[C];E&&b.push(E)}return x.data=b,x})}const s=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(t,[...this._fills.values()]):void 0,u=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._getDataFromBarindex(t,[...this._plots.values()]),f=this._plotbars.size>0?this._getDataFromBarindex(t,[...this._plotbars.values()]):void 0,d=this._plotarrows.size>0?this._getDataFromBarindex(t,[...this._plotarrows.values()]):void 0,h=this._plotcandles.size>0?this._getDataFromBarindex(t,[...this._plotcandles.values()]):void 0,_=this._plotchars.size>0?this._getDataFromBarindex(t,[...this._plotchars.values()]):void 0,g=this._plotshapes.size>0?this._getDataFromBarindex(t,[...this._plotshapes.values()]):void 0,y=this._getDrawsFromBarindex(t),p=this._getDrawDeletes(t),w=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,plotarrows:d,plotcandles:h,plotchars:_,plotbars:f,draws:y,drawDeletes:p,alerts:e,colors:n,hlines:s,fills:a,logs:u,plotshapes:g,isUseBgColor:w})}_getDataFromBarindex(t,e){return e.map(r=>{const n=[];for(const s of t){const a=r.data[s];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:a}=this._variables,u={};return t.data.length&&(u.lines=t.data),e.data.length&&(u.linefills=e.data),r.data.length&&(u.tables=r.data),n.data.length&&(u.boxes=n.data),s.data.length&&(u.polylines=s.data),a.data.length&&(u.labels=a.data),Object.keys(u).length?u:void 0}_getDrawsFromBarindex(t){const{line:e,linefill:r,table:n,box:s,polyline:a,label:u}=this._variables,c={};return e.data.length&&(c.lines=e.getValOfBarIndex(t)),r.data.length&&(c.linefills=r.getValOfBarIndex(t)),n.data.length&&(c.tables=n.getValOfBarIndex(t)),s.data.length&&(c.boxes=s.getValOfBarIndex(t)),a.data.length&&(c.polylines=a.getValOfBarIndex(t)),u.data.length&&(c.labels=u.getValOfBarIndex(t)),Object.keys(c).length?c:void 0}_getDrawDeletes(t){const{line:e,linefill:r,table:n,box:s,polyline:a,label:u}=this._variables,c={},f=e.getDeleteIds(t),d=r.getDeleteIds(t),h=n.getDeleteIds(t),_=s.getDeleteIds(t),g=a.getDeleteIds(t),y=u.getDeleteIds(t);return f.length&&(c.lines=f),d.length&&(c.linefills=d),h.length&&(c.tables=h),_.length&&(c.boxes=_),g.length&&(c.polylines=g),y.length&&(c.labels=y),c}updateOptions(t){var n;const{inputs:e,strategy:r}=t;this.input.update(e),r&&((n=this.strategy)==null||n.updateOptions(r))}update(t){const{barIndex:e}=t;this.strategy.update(),this.math.update(e)}endExecution(){this.strategy.endExecution()}library(t,e){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=t;r.test(n)?(T_.includes(n)||B_.includes(n))&&this._errorListener.addError(He(ie.libraryTitleIsKeywordErr,{name:n}),e,Rt.Error):this._errorListener.addError(ie.libraryTitleErr,e,Rt.Error),this._options.scriptType="library",this._options.library=t}}indicator(t,e){if(!this._variables.bar_index){const{format:r}=t;this._paramVerfiy(r,e,"indicator",[Gt.inherit,Gt.percent,Gt.price,Gt.volume]),this._variables.updateMaxLength(t),this._options.scriptType="indicator",this._options.indicator=t}}_paramVerfiy(t="",e,r,n,s="format"){t&&!n.includes(t)&&this._errorListener.addError(He(ie.paramsErr,{value:t,func:r,param:s,targetVal:`[${n.join(", ")}]`}),e,Rt.Error)}_lineWidthVerify(t,e){const{linewidth:r=1}=t;r<1&&(this._errorListener.addError(S_.lineWidthWarning,e,Rt.Warning),t.linewidth=1)}plot(t,e){const r=["color"];ve(t,r);const{series:n,color:s,...a}=t,{bar_index:u,time:c}=this._variables,f=`plot_${e}`,d=this._plots.get(f),h=(d==null?void 0:d.data)||[],_=n!==void 0&&isNaN(n)?void 0:n;if(h[u]={value:[c,_],barIndex:u,itemStyle:{color:s}},this._seriesColorHandle(t,r,d),!d){this._count++,this._lineWidthVerify(a,e),this._paramVerfiy(t.format,e,"plot",[Gt.percent,Gt.price,Gt.volume]);const g=s?[s]:void 0;this._plots.set(f,{editable:!0,...a,colors:g,data:h,id:f,zIndex:this._count})}return{type:"plot",offset:t.offset||0,key:f}}plotbar(t,e){const r=["color"];ve(t,r);const{open:n,close:s,low:a,high:u,color:c,...f}=t,{bar_index:d,time:h}=this._variables,_=`plotbar_${e}`,g=this._plotbars.get(_),y=(g==null?void 0:g.data)||[],p=s!==void 0&&isNaN(s)?void 0:s,w=n!==void 0&&isNaN(n)?void 0:n,v=a!==void 0&&isNaN(a)?void 0:a,x=u!==void 0&&isNaN(u)?void 0:u,b=[h,w,p,v,x];if(y[d]={value:b,barIndex:d,itemStyle:{color:c}},this._seriesColorHandle(t,r,g),!g){this._count++,this._paramVerfiy(t.format,e,"plotbar",[Gt.percent,Gt.price,Gt.volume]);const C=c?[c]:void 0;this._plotbars.set(_,{editable:!0,...f,colors:C,data:y,id:_,zIndex:this._count})}}_verfiyArgs(t,e,r){const{size:n,format:s,location:a,style:u}=t;this._paramVerfiy(u,r,e,Object.values(lr),"style"),this._paramVerfiy(a,r,e,Object.values(cn),"location"),this._paramVerfiy(n,r,e,Object.values(ir),"size"),this._paramVerfiy(s,r,e,[Gt.percent,Gt.price,Gt.volume],"format")}plotchar(t,e){const r=["color","textcolor"];ve(t,r);const{series:n,color:s,textcolor:a,location:u=cn.abovebar,...c}=t,{bar_index:f,time:d,high:h,low:_}=this._variables,g=`plotchar_${e}`,y=this._plotchars.get(g),p=(y==null?void 0:y.data)||[],w={value:[d,n],barIndex:f,itemStyle:{color:s,textcolor:a},low:_,high:h};p[f]=w,this._seriesColorHandle(t,r,y),y||(this._count++,this._verfiyArgs(t,"plotchar",e),this._plotchars.set(g,{editable:!0,...c,location:u,data:p,id:g,zIndex:this._count}))}plotarrow(t,e){const r=["colorup","colordown"];ve(t,r);const{series:n,colorup:s,colordown:a,...u}=t,{bar_index:c,time:f,low:d,high:h}=this._variables,_=`plotarrow_${e}`,g=this._plotarrows.get(_),y=(g==null?void 0:g.data)||[];y[c]={value:[f,n!==void 0&&isNaN(n)?void 0:n],barIndex:c,itemStyle:{colorup:s,colordown:a},low:d,high:h},this._seriesColorHandle(t,r,g),g||(this._count++,this._paramVerfiy(t.format,e,"plotarrow",[Gt.percent,Gt.price,Gt.volume]),this._plotarrows.set(_,{editable:!0,...u,data:y,id:_,zIndex:this._count}))}plotshape(t,e){const r=["color","textcolor"];ve(t,r);const{series:n,color:s,textcolor:a,location:u=cn.abovebar,...c}=t,{bar_index:f,time:d,low:h,high:_}=this._variables,g=`plotshape_${e}`,y=this._plotshapes.get(g),p=(y==null?void 0:y.data)||[],w={value:n,barIndex:f,color:s,textcolor:a,time:d,low:h,high:_};if(p[f]=w,this._seriesColorHandle(t,r,y),!y){this._count++;const v=s?[s]:void 0;this._verfiyArgs(t,"plotshape",e),this._plotshapes.set(g,{editable:!0,...c,data:p,location:u,id:g,colors:v,zIndex:this._count})}}plotcandle(t,e){const r=["wickcolor","bordercolor","color"];ve(t,r);const{wickcolor:n,bordercolor:s,color:a,close:u,open:c,low:f,high:d,...h}=t,{bar_index:_,time:g}=this._variables,y=`plotcandle_${e}`,p=this._plotcandles.get(y),w=(p==null?void 0:p.data)||[],v=u!==void 0&&isNaN(u)?void 0:u,x=c!==void 0&&isNaN(c)?void 0:c,b=f!==void 0&&isNaN(f)?void 0:f,C=d!==void 0&&isNaN(d)?void 0:d,E=[g,x,v,b,C];w[_]={value:E,barIndex:_,wickcolor:n,bordercolor:s,color:a},this._seriesColorHandle(t,r,p),p||(this._count++,this._paramVerfiy(t.format,e,"plotcandle",[Gt.percent,Gt.price,Gt.volume]),this._plotcandles.set(y,{editable:!0,...h,data:w,id:y,zIndex:this._count}))}hline(t,e){const r=`hline_${e}`;ve(t,["color"]),this._verifyDisplay(t.display,"hline",e);const s=t.display&&!t.display.length?Ze.none:Ze.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(t,e),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:s,...t,zIndex:this._count})),{type:"hline",key:r}}fill(t,e){var S,I,F,O,L,z,q,W;const r=["color","top_color","bottom_color"];ve(t,r);const{color:n,top_color:s,bottom_color:a,seriesColors:u,hline1:c,hline2:f,plot1:d,plot2:h,top_value:_,bottom_value:g,...y}=t,{bar_index:p,time:w}=this._variables,v=`fill_${e}`,x=this._fills.get(v),b=(x==null?void 0:x.data)||[];this._verifyDisplay(t.display,"fill",e);const C=t.display&&!t.display.length?Ze.none:Ze.all;let E,A,N="plot";if(c&&f)E=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,A=(I=this._hlines.get(f==null?void 0:f.key))==null?void 0:I.price,N="hline";else{const R=this._plots.get(d==null?void 0:d.key),Z=this._plots.get(h==null?void 0:h.key),Y=(R==null?void 0:R.data)||[],G=(Z==null?void 0:Z.data)||[];E=(O=(F=Y[p])==null?void 0:F.value)==null?void 0:O[1],A=(z=(L=G[p])==null?void 0:L.value)==null?void 0:z[1]}if(b[p]={time:w,color:n,top_color:s,bottom_color:a,plot1:E,plot2:A,top_value:_,bottom_value:g},this._seriesColorHandle(t,r,x),!x){this._count++;const R=((q=this._options.indicator)==null?void 0:q.explicit_plot_zorder)||((W=this._options.strategy)==null?void 0:W.explicit_plot_zorder),Z=n?[n]:void 0,Y=s?[s]:void 0,G=a?[a]:void 0;this._fills.set(v,{id:v,colors:Z,top_colors:Y,bottom_colors:G,display:C,data:b,type:N,editable:!0,fillgaps:!1,hline1:c,hline2:f,plot1:d,plot2:h,...y,zIndex:R?this._count:void 0})}}alert({message:t,freq:e=jr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:a}=this._variables,u=`alert_${r}`,c=this._cacheData[u]||{},f=c.barIndex;if(this._paramVerfiy(e,r,"alert",[jr.freqAll,jr.freqOncePerBar,jr.freqOncePerBarClose]),e===jr.freqOncePerBar&&n===f){this._alerts.delete(u);return}this._cacheData[u]=c;const d={message:t,freq:e,id:u,type:"alert"};if(s){e!==jr.freqOncePerBarClose&&this._alerts.set(u,d),c.barIndex=n;return}if(!s&&e===jr.freqOncePerBarClose&&n===f&&a===n-1){this._alerts.set(u,d),c.barIndex=n;return}this._alerts.delete(u)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,a=`alertcondition_${n}`;s&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t,e){this._setColors(t,"barcolor",e)}bgcolor(t,e){this._setColors(t,"bgcolor",e)}_verifyDisplay(t=Eh.all,e,r){t.length&&t.length<4&&this._errorListener.addError(He(ie.displayErr,{func:e,values:"[display.none, display.all]"}),r,Rt.Error)}_setColors(t,e,r){ve(t,["color"]);const{color:s,...a}=t;this._verifyDisplay(a.display,e,r);const u=t.display&&!t.display.length?Ze.none:Ze.all,{bar_index:c,time:f}=this._variables,d=`${e}_${r}`;this._bgColors[e]||(this._bgColors[e]=new Map);const h=this._bgColors[e].get(d),_=(h==null?void 0:h.data)||[],g=(h==null?void 0:h.setColors)||[];s&&!g.includes(s)&&g.push(s),_[c]={color:s,time:f,barIndex:c},h||this._bgColors[e].set(d,{...a,display:u,data:_,setColors:g,id:d})}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return!!(t===void 0||typeof t=="number"&&isNaN(t))}fixnan({source:t},e){return t===void 0||typeof t=="number"&&isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!(typeof t=="number"&&isNaN(t))?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n,!0)}timestamp(t){const{dateString:e,timezone:r,year:n,month:s,day:a,hour:u=0,minute:c=0,second:f=0}=t;if(e)return Wt(e).utc(!/GMT|UTC/.test(e)).valueOf();let d=s-1,h=n;if(d<0){const _=Math.ceil(Math.abs(d/12));d=12*_+d,h=n-_}return mr({year:h,month:d,day:a,hour:u,minute:c,second:f},r).valueOf()}weekofyear({time:t,timezone:e}){return mr(t,e).week()}year({time:t,timezone:e}){return mr(t,e).year()}second({time:t,timezone:e}){return mr(t,e).second()}month({time:t,timezone:e}){return mr(t,e).month()+1}minute({time:t,timezone:e}){return mr(t,e).minute()}hour({time:t,timezone:e}){return mr(t,e).hour()}dayofweek({time:t,timezone:e}){return mr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return mr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,this._variables.timeframe.period),n=gr(e,t)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,a=0,u=!1){const c=r||this._variables.__period,f=gr(c,t),d=gr(this._variables.__period,t);let h;if(f<=d)h=t,u&&(h+=d*1e3);else{const _=`time_${e}`,g=this._cacheData[_];if(g)g.currentTime+f*1e3-g.offset<=t?(h=t,this._cacheData[_]={currentTime:t,offset:0}):h=g.currentTime;else{const y=this._calcTimeOffset(t,c);this._cacheData[_]={currentTime:t,offset:y},h=t}u&&(h+=f*1e3)}if(n&&n!==Mn.regular&&n!==Mn.extended){const{timePeriods:_,weeks:g}=this._parserSession(n,e),y=mr(t,s),p=y.format("YYYY-MM-DD HH:mm"),w=y.format("YYYY-MM-DD"),v=h,x=mr(h,s).format("YYYY-MM-DD HH:mm");h=void 0;for(const C of _){const[E,A]=C;let N;if(E===A&&(N=y.add(1,"day").format("YYYY-MM-DD")),Wt(p).isBetween(`${w} ${E}`,`${N||w} ${A}`,"hour","[)")){Wt(x).isBetween(`${w} ${E}`,`${N||w} ${A}`,"hour","[)")?h=v:h=mr(`${w} ${E}`,s).valueOf();break}}const b=this._variables.dayofweek;h&&!g.includes(b)&&(h=void 0)}return h&&h-a*d*1e3}_seriesColorHandle(t,e,r){var n;if(r&&e!=null&&e.length)for(const s of e){if((n=r.gradientColorKeys)!=null&&n.includes(s))continue;const a=t[s];if(!a)continue;const u=r[`${s}s`]||[];u.includes(a)||(u.push(a),r[`${s}s`]=u,u.length>5&&(r[`${s}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(s)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const f=parseInt(c,10);if(f<1||f>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,Rt.Error);return}return f});return{timePeriods:n.split(",").map(c=>{c===""||c===Mn.regular?c="0930-1500":c===Mn.extended&&(c="1500-1830");const f=c.split("-");return f.length!==2?[]:[this._processTime(f[0],e),this._processTime(f[1],e)]}),weeks:a}}_processTime(t,e){const r=parseInt(t.slice(0,2),10),n=parseInt(t.slice(2),10);if(!(r>=0&&r<=23)&&n>=0&&n<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",e,Rt.Error);return}return`${r}:${n}`}}const rD={1:"1M",3:"3M",5:"5M",15:"15M",30:"30M",45:"45M",60:"1H",120:"2H",180:"3H",240:"4H",D:"1D",W:"1W",M:"1MTH","3M":"3MTH","6M":"6MTH","12M":"12MTH"};let nD=class{constructor(t,e){$(this,"_variables");$(this,"_scriptId");$(this,"_cacheData");this._variables=t,this._scriptId=e,this._cacheData=new Map}security(t,e){const r=self.workerStorage.get(`request_${this._scriptId}`),{paramsExpr:n=[]}=t,s=this._getRequestData(t,e);if(r!=null&&r.has(e)){if(!s)return;const c=r.get(e);return this._runScripts(c,e,!1,n,s)}const a=this._parseExprCode(t),u=this._runScripts(a,e,!0,n,s);return r==null||r.set(e,a),u}_parseExprCode(t){let{expression:e,paramsExpr:r=[]}=t,n=[],s=1;e=Xl(e);const a=JSON.parse(e),u=a.pop();let c=(u==null?void 0:u.memberCodes)||{},f=(u==null?void 0:u.depends)||[];if(!f.length)return`return ${u==null?void 0:u.code}`;let d=[],h=[];const _=[];if(this._getDependCodes(f,a,n,d,h,_),n.push(..._),h.length){const p=r.length;let w=[];for(let v=p-1;v>=0;v--){const x=r[v];let b=JSON.parse(Xl(x));const C=[];s!==0&&h.length&&(w.unshift("{"),s++),b=b.map(S=>{const{scope:I,code:F,varNames:O,dependSelf:L}=S;return I===2&&!C.includes(O)&&!L&&(S.code=`let ${F}`),O&&C.push(...O.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const E=[],A=[];let N=h.map(S=>({...S,isArg:!1,isPreArg:!0}));h=[],this._getDependCodes(N,b,A,d,h,E),w.unshift(...A,...E),n=w.concat(n),w=[]}}for(n.push(`return ${u==null?void 0:u.code}`);s>1;)n.push("}"),s--;n=d.concat(n);let g=n.join(`
63
63
  `);const y=[];for(const p of Object.keys(c))g.includes(`$_var.getCacheData("${p}"`)&&y.push(c[p]);return y.length&&(g=`${y.join(`
64
64
  `)}
65
- ${g}`),g}_getRequestData(t,e){var C,E,A,N,S;let{symbol:r,timeframe:n,calc_bars_count:s,gaps:a,lookahead:u,ignore_invalid_symbol:c}=t;const{__period:f,syminfo:{ticker:d,tickerid:h},mintick:_,time:g,nextBarTime:y}=this._variables;if(n=nc(n),(f===n||n==="")&&(r===d||r===h)){const{close:I,open:F,high:O,low:L,bar_index:z,last_bar_index:q,last_bar_time:W,_isRealTimeBar:R,volume:Z,time:Y,time_tradingday:G}=this._variables;return{barIndex:z,c:I,o:F,h:O,l:L,volume:Z,lastBarIndex:q,lastBarTime:W/1e3,nextBarTime:y,isrealtime:R,time_tradingday:G,time:Y/1e3,interval:f,mintick:_}}const p=`${r}--${n||f}`,w=self.workerStorage.get(`request_${this._scriptId}_data`),v=self.workerStorage.get(`request_${this._scriptId}_list`),x=self.workerStorage.get(`request_${this._scriptId}_tmp`),b={id:p,calc_bars_count:s,ignore_invalid_symbol:c,symbol:r,timeframe:rD[n||f]||n};if(w!=null&&w.has(p)){let I=gr(n,g)*1e3;const F=gr(f,g)*1e3;x==null||x.delete(p),e=`${e}_${p}`;const{index:O=0,periodStamp:L=F}=this._cacheData.get(e)||{},z=w==null?void 0:w.get(p);if(!z.length)return;const q=z.slice(O);let W=g,R=L+W;const Z=z.length-1;if(Z<0)return;const Y={lastBarIndex:z[Z].barindex||Z,lastBarTime:z[Z].time,interval:n,mintick:_};if(I>L){let G;if(u===ln.lookaheadOn?G=this._lookaheadOnHandle(q,n,R,I,Y,O,L,e,W,a):G=this._lookaheadOffHandle(q,n,R,I,Y,O,L,e,W,y||R,a),G)return G;if(G===null)return}else if(u===ln.lookaheadOn)for(const[G,Q]of q.entries()){let{time:ut,barindex:_t}=Q;ut=ut*1e3;const at=((C=q[G+1])==null?void 0:C.time)*1e3||ut+I;let vt=O+G;if(ut>=R){this._cacheData.set(e,{index:vt,periodStamp:L});return}if(ut<=W&&at>W){const wt=O+G;return this._cacheData.set(e,{index:wt,periodStamp:L}),{...Q,barIndex:_t||wt,nextBarTime:(E=q[G+1])==null?void 0:E.time,...Y}}}else for(const[G,Q]of q.entries()){let{time:ut,barindex:_t}=Q;ut=ut*1e3;const at=((A=q[G+1])==null?void 0:A.time)*1e3||ut+I;let vt=O+G;if(ut>R){this._cacheData.set(e,{index:vt,periodStamp:L});return}if(ut<=R&&R<at)return this._cacheData.set(e,{index:vt,periodStamp:L}),{...Q,barIndex:_t||vt,nextBarTime:(N=q[G+1])==null?void 0:N.time,...Y};if(ut>=W&&ut<=R&&(_t||vt)===Y.lastBarIndex)return this._cacheData.set(e,{index:vt,periodStamp:L}),{...Q,barIndex:_t||vt,nextBarTime:(S=q[G+1])==null?void 0:S.time,...Y}}this._cacheData.set(e,{index:z.length,periodStamp:L})}else(v==null?void 0:v.get(p))||x==null||x.set(p,b);v==null||v.set(p,b)}_lookaheadOnHandle(t,e,r,n,s,a,u,c,f,d){var h;for(const[_,g]of t.entries()){let{time:y,barindex:p}=g;y=y*1e3,e.includes("M")&&(n=gr(e,y)*1e3-(Wt(y).date()-1)*864e5);const w=y,v=n+w;let x=a+_;if(r<=w)return this._cacheData.set(c,{index:x,periodStamp:u}),null;let b={...g,barIndex:p||x,nextBarTime:(h=t[_+1])==null?void 0:h.time,...s};if(d===ln.gapsOn){if(r>w&&f<=w)return this._cacheData.set(c,{index:x,periodStamp:u}),b}else{if(r>v)continue;if(r>w)return this._cacheData.set(c,{index:x,periodStamp:u}),b}}}_lookaheadOffHandle(t,e,r,n,s,a,u,c,f,d,h){var _,g;for(const[y,p]of t.entries()){let{time:w,barindex:v}=p;w=w*1e3,e.includes("M")&&(n=gr(e,w)*1e3-(Wt(w).date()-1)*864e5);const x=w,b=n+x,C=a+y;if(r<x)return this._cacheData.set(c,{index:C,periodStamp:u}),null;const E={...p,barIndex:v||C,nextBarTime:(_=t[y+1])==null?void 0:_.time,...s};if(r>=b&&f<b||r<b&&d>=b)return h===ln.gapsOn?(this._cacheData.set(c,{index:C,periodStamp:u}),E):(this._cacheData.set(c,{index:C,data:E,periodStamp:u}),E);if(!(f>b)&&f>=x){let A=(g=this._cacheData.get(c))==null?void 0:g.data;if(!A){const N=t[C-1];if(!N)return null;A={...N,barIndex:N.barindex||C-1,nextBarTime:E.time,...s},this._cacheData.set(c,{index:C,data:A,periodStamp:u})}return A}}}_getDependCodes(t,e,r,n,s,a){for(const u of t){if(!u.isArg){const c=e.filter(d=>{var h;return(h=d==null?void 0:d.depends)==null?void 0:h.some(_=>_.name===u.name&&_.scope===u.scope&&_.isAgainAssign)});for(const d of c){const{code:h,depends:_}=d;if(!r.includes(h)&&(r.unshift(h),_!=null&&_.length)){for(const g of _)g.memberCode&&a.push(g.memberCode);this._getDependCodes(_,e,r,n,s,a)}}const f=e.find(d=>{var h;return((h=d.varNames)==null?void 0:h.split(", ").includes(u.name))&&(!u.isPreArg||u.isPreArg&&d.methodName===u.functionName)||d.funcName===u.name});if(f){const{code:d,depends:h}=f,_=r.findIndex(g=>g===d);if(_!==-1&&r.splice(_,1),r.unshift(d),h!=null&&h.length){for(const g of h)g.memberCode&&a.push(g.memberCode);this._getDependCodes(h,e,r,n,s,a)}continue}}s.some(c=>c.name===u.name)||s.push(u)}}_runScripts(t,e,r,n,s){const a=`${this._scriptId}_${e}`;let{builtInGather:u,buildinConstants:c,buildInFunctions:f,tradingvueFunc:d}=self.workerStorage.get(a)||{};const{interval:h,mintick:_,...g}=s||{};r&&(u=new Lh(a),c=new Ch,f=new $h(this._variables.mintick||1e-5,u,this._scriptId),d=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),u.updateOptions({interval:h,mintick:_||1e-5}),self.workerStorage.set(a,{builtInGather:u,buildinConstants:c,buildInFunctions:f,tradingvueFunc:d})),u.updateData(g),f.update({barIndex:(g==null?void 0:g.barindex)||0});const y=d(u,c,f,n||[],e);return f.endExecution(),y}},iD=class{constructor(){}prefix(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[0])||""}ticker(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[1])||""}};class sD{constructor(t,e){$(this,"_logs");$(this,"_variables");$(this,"_str");$(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=t,this._logs=[],this._str=e}get logs(){return this._logs}clearLogForIndex(t){this._logs=this._logs.filter(e=>e.barIndex!==t)}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:s,formatString:a}=t,{time:u,bar_index:c,_isRealTimeBar:f}=this._variables;let d=s;a&&Array.isArray(e)&&e.length&&(e=e.map(g=>(typeof g=="object"&&(g.isArray?g=JSON.stringify(g._value):g=g.toString()),g!==void 0?g:"na")),d=this._str.strformat({formatString:a},e,!0));const{isrealtime:h}=this._preBar;this._preBar={barIndex:c,isrealtime:f};const _=Date.now();d&&this._logs.push({message:`[${Wt(h||f?_:u).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${d}`,time:u,id:M_(6),barIndex:c,type:r})}}class oD{constructor(t){$(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,Rt.Error)}}class aD{constructor(){$(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Wr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[s,a]=e.split("_").slice(-2),u=this._errors.get(e),c={message:t,endLineNumber:Number(s),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(s),type:r};u?u.push(c):this._errors.set(e,[c])}}class uD{constructor(){$(this,"_isMarketOpen");$(this,"_currentBarIndex");$(this,"_totalBarIndex");$(this,"_isRealTimeBar");$(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class lD{constructor(t){$(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const{time:t,__period:e}=this._variables,r=gr(e,t);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:t,__period:e}=this._variables,r=gr(e,t);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 cD{constructor(t){$(this,"_orders");$(this,"_historyOrders");$(this,"_options");$(this,"_max_contracts_held_all",0);$(this,"_max_contracts_held_long",0);$(this,"_max_contracts_held_short",0);$(this,"_max_drawdown",0);$(this,"_max_runup",0);$(this,"_max_runup_percent",0);$(this,"_max_drawdown_percent",0);$(this,"_variables");$(this,"_netprofit",0);$(this,"_eventrades",0);$(this,"_avg_trade_percent");$(this,"_avg_losing_trade_percent");$(this,"_avg_winning_trade_percent");$(this,"_closedtrades",0);$(this,"_losstrades",0);$(this,"_grossloss",0);$(this,"_grossprofit",0);$(this,"_wintrades",0);$(this,"_opentrades_capital_held",0);$(this,"_position_avg_price",0);$(this,"_position_size",0);$(this,"_openprofit",0);$(this,"_preMaxNetValue",0);$(this,"_preMinNetValue",0);$(this,"marginCallLong",0);$(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=t}update(t){this._calcMaxDrawdownAndMaxRunup(t)}_calcMaxDrawdownAndMaxRunup(t){if(!this._orders.length&&!this._historyOrders.length)return;let e=0,r=0;const{high:n,low:s,close:a}=t;let u=0;for(const[d,h]of this._orders.entries()){const{in_price:_,qty:g=0,direction:y,commission:p,original_qty:w=1}=h,v=y===fe.long?1:-1,x=(n-_)*g,b=(s-_)*g,C=v===1?x:-b,E=v===1?-b:x;u+=(a-_)*v*g,e+=E,d>0&&p&&(r-=p*g/w),r+=C}this._openprofit=u;const c=this.initial_capital,f=c+this._netprofit;this._preMinNetValue=this._preMinNetValue||c,this._preMaxNetValue=this._preMaxNetValue||c,e=this._preMaxNetValue-f+Math.max(e,0),r=f-this._preMinNetValue+r,this._max_drawdown<e&&(this._max_drawdown=e,this._max_drawdown_percent=e/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[e,r,n,s,a,u,c]=this._orders.reduce(([f,d,h,_,g,y,p],w)=>{const{direction:v,qty:x=0,in_price:b,commission:C=0}=w;return v===fe.long?(f+=x,d+=x,y+=x):(f+=x,h+=x,y-=x),_+=x*b,g+=b,p+=C,[f,d,h,_,g,y,p]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-c,this._grossloss=c),this._position_size=u,this._position_avg_price=a/t,this._opentrades_capital_held=s,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,s,a,u,c,f,d]=this._historyOrders.reduce((g,y)=>{let[p,w,v,x,b,C,E,A]=g;const{profit:N=0,profit_percent:S=0}=y;return p+=N,w+=S,N<0?(v+=N,x+=S,E+=1):N>0&&(b+=N,C+=S,A+=1),[p,w,v,x,b,C,E,A]},[0,0,0,0,0,0,0,0]),h=this._orders.reduce((g,y)=>{const{commission:p=0,qty:w=0,original_qty:v=0}=y,x=p*w/v;return g+x},0);this._avg_trade_percent=e?n/e:void 0,this._avg_losing_trade_percent=e?Math.abs(a)/f:void 0,this._avg_winning_trade_percent=e?c/d:void 0,this._netprofit=r-h;const _=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,_),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,_),this._grossloss=Math.abs(s-h),this._grossprofit=u,this._eventrades=e-f-d,this._losstrades=f,this._wintrades=d}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this._losstrades;return t?Math.abs(this._grossloss/t):void 0}get avg_losing_trade_percent(){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 t=this._wintrades;return t?Math.abs(this._grossprofit/t):void 0}get avg_winning_trade_percent(){return this._avg_winning_trade_percent}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:s=0}=this._options,a=this._orders[0].direction===fe.long?1:-1,u=(a===1?e:r)/100;if(u<=0)return;const{close:c}=this._variables,[f,d]=this._orders.reduce((h,_)=>{let[g,y]=h;const{in_price:p,qty:w=0,original_qty:v=0}=_,x=p*w;if(g+=x,s){let b=0;switch(n){case je.percent:b=(x+w*c)*s/100;break;case je.cashPerContract:b=w*s*2;break;case je.cashPerOrder:b=w/v*s+s;break}y+=b}return[g,y]},[0,0]);return(f-(t+this._netprofit-d))*a/this._position_size/(1-a*u)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this._netprofit/this.initial_capital*100}get openprofit_percent(){return this._openprofit/(this.initial_capital+this._netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(t,e){if(!this._options)return 0;const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case je.percent:a=s*r/100;break;case je.cashPerContract:a=e*r;break;case je.cashPerOrder:a=r;break}return a}}class fD{constructor(t){$(this,"_preAccdist");$(this,"_preNvi");$(this,"_prePvi");$(this,"_preObv");$(this,"_prePvt");$(this,"_preWad");$(this,"_preVwap");$(this,"_preValue");$(this,"_currentData");$(this,"_preData");$(this,"_id");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={},this._id=t}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),u=t-n,f=(u>0?t-a:u<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=f),this._preValue.wad=f,f}get vwap(){var d,h;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(((h=(d=self.workerStorage)==null?void 0:d.get(this._id))==null?void 0:h.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(s=!0,r=n=0),!s)return;const u=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:u,sumV:c,isReset:s});const f=u/c;return this._preValue.vwap=f,f}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const u=t||1;return n&&e?a=s<r?u+(n-e)/e*u:u:a=u,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const u=t||1;return n&&e?a=s>r?u+(n-e)/e*u:u:a=u,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class hD{constructor(){$(this,"_period");$(this,"_multiplier");$(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=Fs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}class dD{constructor(t){$(this,"_variables");$(this,"_bgColor");$(this,"_fgColor");$(this,"isUseBgColor",!1);this._variables=t}updateOptions(t){t!=null&&t.bg_color&&(this._bgColor=t.bg_color,this._fgColor=this._contrastColor(t.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){return this._variables.time}get right_visible_bar_time(){return this._variables.time}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?s=parseInt(a,16)/255:s=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,s=a[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}_contrastColor(t){const{r:e,g:r,b:n}=this._parseColor(t);return(299*e+587*r+114*n)/1e3>128?"#000000":"#ffffff"}}class _D{constructor(){$(this,"_syminfo",{})}update(t){this._syminfo=t}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||Mn.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}get volumetype(){return this._syminfo.volumetype||"n/a"}}class pD{constructor(t){$(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class mD{constructor(t){$(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}Wt.extend(A_),Wt.extend(xa),Wt.extend(Ea);class Lh{constructor(t){$(this,"_cacheData");$(this,"_barIndex");$(this,"_isRealTimeBar");$(this,"_barstate");$(this,"_priceVariables");$(this,"_lastBarIndex");$(this,"_currentBarTime");$(this,"_lastBarTime");$(this,"_period");$(this,"_offsetTime");$(this,"_timeframe");$(this,"_ta");$(this,"_polyline");$(this,"_label");$(this,"_line");$(this,"_linefill");$(this,"_box");$(this,"_table");$(this,"_strategy");$(this,"_session");$(this,"syminfo");$(this,"chart");$(this,"earnings");$(this,"dividends");$(this,"_timeTradingday");$(this,"_mintick");$(this,"_cacheSpace");$(this,"_precision");$(this,"_nextBarTime");$(this,"_isRepeated");$(this,"_preCacheData");this._cacheData={varData:{},varNewData:{},varipData:{}},this._preCacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new uD,this._timeframe=new hD,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new fD(t),this._polyline=new $i,this._label=new $i,this._line=new $i,this._linefill=new $i,this._box=new $i,this._table=new $i,this._strategy=new cD(this),this._session=new lD(this),this.syminfo=new _D,this.chart=new dD(this),this.earnings=new mD(this),this.dividends=new pD(this),this._cacheSpace=new Map}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return Wt(this._currentBarTime).hour()}get minute(){return Wt(this._currentBarTime).minute()}get second(){return Wt(this._currentBarTime).second()}get month(){return Wt(this._currentBarTime).month()+1}get year(){return Wt(this._currentBarTime).year()}get dayofweek(){return Wt(this._currentBarTime).day()}get dayofmonth(){return Wt(this._currentBarTime).date()}get weekofyear(){return Wt(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=Fs(this._period);return this._isRealTimeBar?void 0:Wt(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}get precision(){return this._precision}get nextBarTime(){return this._nextBarTime}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:s}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),s&&this._polyline.setMaxLen(s)}getTimeTradingday(t,e){const[r,n]=Fs(e),s=Wt(t);return["M","w","y","d"].includes(n)?s.valueOf():(s.subtract(this._offsetTime,"h"),s.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){var f;const{interval:e="1D",offsetTime:r=5,mintick:n,chart:s,syminfo:a}=t,u=((f=n.toString().split(".")[1])==null?void 0:f.length)||5;this._precision=u;const c=this._transformPeriod(e);this._period=c,this._mintick=n,this._offsetTime=r,this._timeframe.update(c),this.chart.updateOptions(s),this.syminfo.update(a)}updateData(t,e){const{barIndex:r,c:n,o:s,h:a,l:u,volume:c,time:f,lastBarIndex:d,lastBarTime:h,isrealtime:_,time_tradingday:g,nextBarTime:y}=t;if(this._priceVariables={close:Number(n),open:Number(s),high:Number(a),low:Number(u),volume:Number(c)},this._isRealTimeBar=_,r>this._barIndex){const{varData:p,varNewData:w,varipData:v}=this._cacheData;this._preCacheData={varData:{...p},varNewData:{...w},varipData:{...v}},this._isRealTimeBar&&(this._cacheData.varNewData={})}this._isRepeated=e,this._timeTradingday=g,this._currentBarTime=f*1e3,this._lastBarIndex=d,this._barIndex=r,this._lastBarTime=h*1e3,this._nextBarTime=y*1e3,this._barstate.update(r,d,_,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(t,e,r){const n=this.setCacheData(t,r),s=this._cacheSpace.get(t)||0;return e=Math.floor(e),s<e&&this._cacheSpace.set(t,e),n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e);const n=this._cacheSpace.get(t);return n&&r.data.length>n+5&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[t]=r,r.data}getTypeInstance(t,e){return new D_(t,e)}verifyVarAndVarip(t,e,r){const n=`${t}_${e}`;return r==="var"&&this._cacheData.varData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varData[n]),!0):r==="varip"&&this._cacheData.varipData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varipData[n]),!0):!1}getVarValue(t,e,r){const n=`${t}_${e}`,s=this._isRepeated?this._preCacheData:this._cacheData;return r==="var"?this._isRealTimeBar&&s.varNewData.hasOwnProperty(n)?s.varNewData[n]:s.varData[n]:this._cacheData.varipData[n]}setVarValue(t,e,r,n){var u;if(this._isRepeated&&n==="var")return this.getVarValue(t,e,n);const s=`${t}_${e}`;let a;switch(typeof r=="object"&&((u=r==null?void 0:r.varipKeys)!=null&&u.length)&&(n="var",a=r.varipKeys),this._chartDrawsHandle(r,this._cacheData.varData[s]||this._cacheData.varipData[s]),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[s]=r,a&&a.length)for(const c of a)this._cacheData.varData[s][c]=r[c]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}_upadteChartDraws(t){const e=t==null?void 0:t.id;if(e)switch(t==null?void 0:t.type){case te.BOX:this._setChartDraw(e,this._box);break;case te.LINE:this._setChartDraw(e,this._line);break;case te.POLYLINE:this._setChartDraw(e,this._polyline);break;case te.LABEL:this._setChartDraw(e,this._label);break;case te.LINEFILL:this._setChartDraw(e,this._linefill);break;case te.TABLE:this._setChartDraw(e,this._table);break}}_setChartDraw(t,e){const r=e.getInstance(t),n=e.get(t);if(!n||!r)return;const s=(r==null?void 0:r.updateId())||t;e.delete(t),e.set(s,n,r)}_chartDrawsHandle(t,e){const r=e==null?void 0:e.id;let n=t==null?void 0:t.id;r!==n&&(n&&t.data&&(t.data.isVar=!0),r&&e.data&&(e.data.isVar=!1))}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Wr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}equal(t,e,r,n){if(t!==void 0&&e!==void 0)return t==e;if(!(r.endsWith(te.BOOL)&&t===void 0))return(r.endsWith(te.FLOAT)||r.endsWith(te.INT)||n.endsWith(te.FLOAT)||n.endsWith(te.INT))&&t===void 0&&e===void 0?!1:r.endsWith(te.STRING)&&t===""&&e===void 0||n.endsWith(te.STRING)&&e===""&&t===void 0?!0:r.endsWith(te.NA)&&n.endsWith(te.NA)?!1:t==e}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case go.name:case Ah.name:case wo.name:case Mh.name:case vo.name:case yo.name:t==null||t.delete();break}}_transformPeriod(t){return t.includes("MTH")?t=t.replace("MTH","M"):t.includes("M")&&(t=t.replace("M","")),nc(t)}}class $i{constructor(t=50){$(this,"_all");$(this,"_allInstance");$(this,"_pseudoArrayAll");$(this,"_maxLength");$(this,"_deleteIds");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new ee,this._maxLength=t,this._deleteIds=new Map}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){if(this.set(t,e,r),this._all.size>this._maxLength){const{bar_index:n}=e;for(const[s,a]of this._all){const{isVar:u,id:c,bar_index:f}=a;if(f===n)break;if(u)continue;this.delete(c);break}}}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const s=r.filter(a=>a.endsWith(`_${n}`));for(const a of s){const u=this._all.get(a);u&&e.push(u)}}return e.length?e:void 0}getDeleteIds(t){let e=[];for(const r of t)e=e.concat(this._deleteIds.get(r)||[]);return this._deleteIds.clear(),Wr.uniq(e)}set(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t,e){if(this._all.delete(t),this._allInstance.delete(t),typeof e=="number"){const r=this._deleteIds.get(e)||[];r.push(t),this._deleteIds.set(e,r)}}}/**
65
+ ${g}`),g}_getRequestData(t,e){var C,E,A,N,S;let{symbol:r,timeframe:n,calc_bars_count:s,gaps:a,lookahead:u,ignore_invalid_symbol:c}=t;const{__period:f,syminfo:{ticker:d,tickerid:h},mintick:_,time:g,nextBarTime:y}=this._variables;if(n=nc(n),(f===n||n==="")&&(r===d||r===h)){const{close:I,open:F,high:O,low:L,bar_index:z,last_bar_index:q,last_bar_time:W,_isRealTimeBar:R,volume:Z,time:Y,time_tradingday:G}=this._variables;return{barIndex:z,c:I,o:F,h:O,l:L,volume:Z,lastBarIndex:q,lastBarTime:W/1e3,nextBarTime:y,isrealtime:R,time_tradingday:G,time:Y/1e3,interval:f,mintick:_}}const p=`${r}--${n||f}`,w=self.workerStorage.get(`request_${this._scriptId}_data`),v=self.workerStorage.get(`request_${this._scriptId}_list`),x=self.workerStorage.get(`request_${this._scriptId}_tmp`),b={id:p,calc_bars_count:s,ignore_invalid_symbol:c,symbol:r,timeframe:rD[n||f]||n};if(w!=null&&w.has(p)){let I=gr(n,g)*1e3;const F=gr(f,g)*1e3;x==null||x.delete(p),e=`${e}_${p}`;const{index:O=0,periodStamp:L=F}=this._cacheData.get(e)||{},z=w==null?void 0:w.get(p);if(!z.length)return;const q=z.slice(O);let W=g,R=L+W;const Z=z.length-1;if(Z<0)return;const Y={lastBarIndex:z[Z].barindex||Z,lastBarTime:z[Z].time,interval:n,mintick:_};if(I>L){let G;if(u===ln.lookaheadOn?G=this._lookaheadOnHandle(q,n,R,I,Y,O,L,e,W,a):G=this._lookaheadOffHandle(q,n,R,I,Y,O,L,e,W,y||R,a),G)return G;if(G===null)return}else if(u===ln.lookaheadOn)for(const[G,Q]of q.entries()){let{time:ut,barindex:_t}=Q;ut=ut*1e3;const at=((C=q[G+1])==null?void 0:C.time)*1e3||ut+I;let vt=O+G;if(ut>=R){this._cacheData.set(e,{index:vt,periodStamp:L});return}if(ut<=W&&at>W){const wt=O+G;return this._cacheData.set(e,{index:wt,periodStamp:L}),{...Q,barIndex:_t||wt,nextBarTime:(E=q[G+1])==null?void 0:E.time,...Y}}}else for(const[G,Q]of q.entries()){let{time:ut,barindex:_t}=Q;ut=ut*1e3;const at=((A=q[G+1])==null?void 0:A.time)*1e3||ut+I;let vt=O+G;if(ut>R){this._cacheData.set(e,{index:vt,periodStamp:L});return}if(ut<=R&&R<at)return this._cacheData.set(e,{index:vt,periodStamp:L}),{...Q,barIndex:_t||vt,nextBarTime:(N=q[G+1])==null?void 0:N.time,...Y};if(ut>=W&&ut<=R&&(_t||vt)===Y.lastBarIndex)return this._cacheData.set(e,{index:vt,periodStamp:L}),{...Q,barIndex:_t||vt,nextBarTime:(S=q[G+1])==null?void 0:S.time,...Y}}this._cacheData.set(e,{index:z.length,periodStamp:L})}else(v==null?void 0:v.get(p))||x==null||x.set(p,b);v==null||v.set(p,b)}_lookaheadOnHandle(t,e,r,n,s,a,u,c,f,d){var h;for(const[_,g]of t.entries()){let{time:y,barindex:p}=g;y=y*1e3,e.includes("M")&&(n=gr(e,y)*1e3-(Wt(y).date()-1)*864e5);const w=y,v=n+w;let x=a+_;if(r<=w)return this._cacheData.set(c,{index:x,periodStamp:u}),null;let b={...g,barIndex:p||x,nextBarTime:(h=t[_+1])==null?void 0:h.time,...s};if(d===ln.gapsOn){if(r>w&&f<=w)return this._cacheData.set(c,{index:x,periodStamp:u}),b}else{if(r>v)continue;if(r>w)return this._cacheData.set(c,{index:x,periodStamp:u}),b}}}_lookaheadOffHandle(t,e,r,n,s,a,u,c,f,d,h){var _,g;for(const[y,p]of t.entries()){let{time:w,barindex:v}=p;w=w*1e3,e.includes("M")&&(n=gr(e,w)*1e3-(Wt(w).date()-1)*864e5);const x=w,b=n+x,C=a+y;if(r<x)return this._cacheData.set(c,{index:C,periodStamp:u}),null;const E={...p,barIndex:v||C,nextBarTime:(_=t[y+1])==null?void 0:_.time,...s};if(r>=b&&f<b||r<b&&d>=b)return h===ln.gapsOn?(this._cacheData.set(c,{index:C,periodStamp:u}),E):(this._cacheData.set(c,{index:C,data:E,periodStamp:u}),E);if(!(f>b)&&f>=x){let A=(g=this._cacheData.get(c))==null?void 0:g.data;if(!A){const N=t[C-1];if(!N)return null;A={...N,barIndex:N.barindex||C-1,nextBarTime:E.time,...s},this._cacheData.set(c,{index:C,data:A,periodStamp:u})}return A}}}_getDependCodes(t,e,r,n,s,a){for(const u of t){if(!u.isArg){const c=e.filter(d=>{var h;return(h=d==null?void 0:d.depends)==null?void 0:h.some(_=>_.name===u.name&&_.scope===u.scope&&_.isAgainAssign)});for(const d of c){const{code:h,depends:_}=d;if(!r.includes(h)&&(r.unshift(h),_!=null&&_.length)){for(const g of _)g.memberCode&&a.push(g.memberCode);this._getDependCodes(_,e,r,n,s,a)}}const f=e.find(d=>{var h;return((h=d.varNames)==null?void 0:h.split(", ").includes(u.name))&&(!u.isPreArg||u.isPreArg&&d.methodName===u.functionName)||d.funcName===u.name});if(f){const{code:d,depends:h}=f,_=r.findIndex(g=>g===d);if(_!==-1&&r.splice(_,1),r.unshift(d),h!=null&&h.length){for(const g of h)g.memberCode&&a.push(g.memberCode);this._getDependCodes(h,e,r,n,s,a)}continue}}s.some(c=>c.name===u.name)||s.push(u)}}_runScripts(t,e,r,n,s){const a=`${this._scriptId}_${e}`;let{builtInGather:u,buildinConstants:c,buildInFunctions:f,tradingvueFunc:d}=self.workerStorage.get(a)||{};const{interval:h,mintick:_,...g}=s||{};r&&(u=new Lh(a),c=new Ch,f=new $h(this._variables.mintick||1e-5,u,this._scriptId),d=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),u.updateOptions({interval:h,mintick:_||1e-5}),self.workerStorage.set(a,{builtInGather:u,buildinConstants:c,buildInFunctions:f,tradingvueFunc:d})),u.updateData(g),f.update({barIndex:(g==null?void 0:g.barindex)||0});const y=d(u,c,f,n||[],e);return f.endExecution(),y}},iD=class{constructor(){}prefix(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[0])||""}ticker(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[1])||""}};class sD{constructor(t,e){$(this,"_logs");$(this,"_variables");$(this,"_str");$(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=t,this._logs=[],this._str=e}get logs(){return this._logs}clearLogForIndex(t){this._logs=this._logs.filter(e=>e.barIndex!==t)}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:s,formatString:a}=t,{time:u,bar_index:c,_isRealTimeBar:f}=this._variables;let d=s;a&&Array.isArray(e)&&e.length&&(e=e.map(g=>(typeof g=="object"&&(g.isArray?g=JSON.stringify(g._value):g=g.toString()),g!==void 0?g:"na")),d=this._str.strformat({formatString:a},e,!0));const{isrealtime:h}=this._preBar;this._preBar={barIndex:c,isrealtime:f};const _=Date.now();d&&this._logs.push({message:`[${Wt(h||f?_:u).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${d}`,time:u,id:M_(6),barIndex:c,type:r})}}class oD{constructor(t){$(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,Rt.Error)}}class aD{constructor(){$(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Wr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[s,a]=e.split("_").slice(-2),u=this._errors.get(e),c={message:t,endLineNumber:Number(s),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(s),type:r};u?u.push(c):this._errors.set(e,[c])}}class uD{constructor(){$(this,"_isMarketOpen");$(this,"_currentBarIndex");$(this,"_totalBarIndex");$(this,"_isRealTimeBar");$(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class lD{constructor(t){$(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const{time:t,__period:e}=this._variables,r=gr(e,t);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:t,__period:e}=this._variables,r=gr(e,t);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 cD{constructor(t){$(this,"_orders");$(this,"_historyOrders");$(this,"_options");$(this,"_max_contracts_held_all",0);$(this,"_max_contracts_held_long",0);$(this,"_max_contracts_held_short",0);$(this,"_max_drawdown",0);$(this,"_max_runup",0);$(this,"_max_runup_percent",0);$(this,"_max_drawdown_percent",0);$(this,"_variables");$(this,"_netprofit",0);$(this,"_eventrades",0);$(this,"_avg_trade_percent");$(this,"_avg_losing_trade_percent");$(this,"_avg_winning_trade_percent");$(this,"_closedtrades",0);$(this,"_losstrades",0);$(this,"_grossloss",0);$(this,"_grossprofit",0);$(this,"_wintrades",0);$(this,"_opentrades_capital_held",0);$(this,"_position_avg_price",0);$(this,"_position_size",0);$(this,"_openprofit",0);$(this,"_preMaxNetValue",0);$(this,"_preMinNetValue",0);$(this,"marginCallLong",0);$(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=t}update(t){this._calcMaxDrawdownAndMaxRunup(t)}_calcMaxDrawdownAndMaxRunup(t){if(!this._orders.length&&!this._historyOrders.length)return;let e=0,r=0;const{high:n,low:s,close:a}=t;let u=0;for(const[d,h]of this._orders.entries()){const{in_price:_,qty:g=0,direction:y,commission:p,original_qty:w=1}=h,v=y===fe.long?1:-1,x=(n-_)*g,b=(s-_)*g,C=v===1?x:-b,E=v===1?-b:x;u+=(a-_)*v*g,e+=E,d>0&&p&&(r-=p*g/w),r+=C}this._openprofit=u;const c=this.initial_capital,f=c+this._netprofit;this._preMinNetValue=this._preMinNetValue||c,this._preMaxNetValue=this._preMaxNetValue||c,e=this._preMaxNetValue-f+Math.max(e,0),r=f-this._preMinNetValue+r,this._max_drawdown<e&&(this._max_drawdown=e,this._max_drawdown_percent=e/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[e,r,n,s,a,u,c]=this._orders.reduce(([f,d,h,_,g,y,p],w)=>{const{direction:v,qty:x=0,in_price:b,commission:C=0}=w;return v===fe.long?(f+=x,d+=x,y+=x):(f+=x,h+=x,y-=x),_+=x*b,g+=b,p+=C,[f,d,h,_,g,y,p]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-c,this._grossloss=c),this._position_size=u,this._position_avg_price=a/t,this._opentrades_capital_held=s,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,s,a,u,c,f,d]=this._historyOrders.reduce((g,y)=>{let[p,w,v,x,b,C,E,A]=g;const{profit:N=0,profit_percent:S=0}=y;return p+=N,w+=S,N<0?(v+=N,x+=S,E+=1):N>0&&(b+=N,C+=S,A+=1),[p,w,v,x,b,C,E,A]},[0,0,0,0,0,0,0,0]),h=this._orders.reduce((g,y)=>{const{commission:p=0,qty:w=0,original_qty:v=0}=y,x=p*w/v;return g+x},0);this._avg_trade_percent=e?n/e:void 0,this._avg_losing_trade_percent=e?Math.abs(a)/f:void 0,this._avg_winning_trade_percent=e?c/d:void 0,this._netprofit=r-h;const _=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,_),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,_),this._grossloss=Math.abs(s-h),this._grossprofit=u,this._eventrades=e-f-d,this._losstrades=f,this._wintrades=d}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this._losstrades;return t?Math.abs(this._grossloss/t):void 0}get avg_losing_trade_percent(){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 t=this._wintrades;return t?Math.abs(this._grossprofit/t):void 0}get avg_winning_trade_percent(){return this._avg_winning_trade_percent}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:s=0}=this._options,a=this._orders[0].direction===fe.long?1:-1,u=(a===1?e:r)/100;if(u<=0)return;const{close:c}=this._variables,[f,d]=this._orders.reduce((h,_)=>{let[g,y]=h;const{in_price:p,qty:w=0,original_qty:v=0}=_,x=p*w;if(g+=x,s){let b=0;switch(n){case je.percent:b=(x+w*c)*s/100;break;case je.cashPerContract:b=w*s*2;break;case je.cashPerOrder:b=w/v*s+s;break}y+=b}return[g,y]},[0,0]);return(f-(t+this._netprofit-d))*a/this._position_size/(1-a*u)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this._netprofit/this.initial_capital*100}get openprofit_percent(){return this._openprofit/(this.initial_capital+this._netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(t,e){if(!this._options)return 0;const{commission_value:r=0,commission_type:n}=this._options,s=t*e;let a=0;switch(n){case je.percent:a=s*r/100;break;case je.cashPerContract:a=e*r;break;case je.cashPerOrder:a=r;break}return a}}class fD{constructor(t){$(this,"_preAccdist");$(this,"_preNvi");$(this,"_prePvi");$(this,"_preObv");$(this,"_prePvt");$(this,"_preWad");$(this,"_preVwap");$(this,"_preValue");$(this,"_currentData");$(this,"_preData");$(this,"_id");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={},this._id=t}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),u=t-n,f=(u>0?t-a:u<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=f),this._preValue.wad=f,f}get vwap(){var d,h;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(((h=(d=self.workerStorage)==null?void 0:d.get(this._id))==null?void 0:h.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(s=!0,r=n=0),!s)return;const u=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:u,sumV:c,isReset:s});const f=u/c;return this._preValue.vwap=f,f}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const u=t||1;return n&&e?a=s<r?u+(n-e)/e*u:u:a=u,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const u=t||1;return n&&e?a=s>r?u+(n-e)/e*u:u:a=u,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class hD{constructor(){$(this,"_period");$(this,"_multiplier");$(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=Fs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}class dD{constructor(t){$(this,"_variables");$(this,"_bgColor");$(this,"_fgColor");$(this,"isUseBgColor",!1);this._variables=t}updateOptions(t){t!=null&&t.bg_color&&(this._bgColor=t.bg_color,this._fgColor=this._contrastColor(t.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){return this._variables.time}get right_visible_bar_time(){return this._variables.time}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?s=parseInt(a,16)/255:s=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,s=a[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}_contrastColor(t){const{r:e,g:r,b:n}=this._parseColor(t);return(299*e+587*r+114*n)/1e3>128?"#000000":"#ffffff"}}class _D{constructor(){$(this,"_syminfo",{})}update(t){this._syminfo=t}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||Mn.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}get volumetype(){return this._syminfo.volumetype||"n/a"}}class pD{constructor(t){$(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class mD{constructor(t){$(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}Wt.extend(A_),Wt.extend(xa),Wt.extend(Ea);class Lh{constructor(t){$(this,"_cacheData");$(this,"_barIndex");$(this,"_isRealTimeBar");$(this,"_barstate");$(this,"_priceVariables");$(this,"_lastBarIndex");$(this,"_currentBarTime");$(this,"_lastBarTime");$(this,"_period");$(this,"_offsetTime");$(this,"_timeframe");$(this,"_ta");$(this,"_polyline");$(this,"_label");$(this,"_line");$(this,"_linefill");$(this,"_box");$(this,"_table");$(this,"_strategy");$(this,"_session");$(this,"syminfo");$(this,"chart");$(this,"earnings");$(this,"dividends");$(this,"_timeTradingday");$(this,"_mintick");$(this,"_cacheSpace");$(this,"_precision");$(this,"_nextBarTime");$(this,"_isRepeated");$(this,"_preCacheData");this._cacheData={varData:{},varNewData:{},varipData:{}},this._preCacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new uD,this._timeframe=new hD,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new fD(t),this._polyline=new $i,this._label=new $i,this._line=new $i,this._linefill=new $i,this._box=new $i,this._table=new $i,this._strategy=new cD(this),this._session=new lD(this),this.syminfo=new _D,this.chart=new dD(this),this.earnings=new mD(this),this.dividends=new pD(this),this._cacheSpace=new Map}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return Wt(this._currentBarTime).hour()}get minute(){return Wt(this._currentBarTime).minute()}get second(){return Wt(this._currentBarTime).second()}get month(){return Wt(this._currentBarTime).month()+1}get year(){return Wt(this._currentBarTime).year()}get dayofweek(){return Wt(this._currentBarTime).day()}get dayofmonth(){return Wt(this._currentBarTime).date()}get weekofyear(){return Wt(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=Fs(this._period);return this._isRealTimeBar?void 0:Wt(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}get precision(){return this._precision}get nextBarTime(){return this._nextBarTime}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:s}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),s&&this._polyline.setMaxLen(s)}getTimeTradingday(t,e){const[r,n]=Fs(e),s=Wt(t);return["M","w","y","d"].includes(n)?s.valueOf():(s.subtract(this._offsetTime,"h"),s.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){var f;const{interval:e="1D",offsetTime:r=5,mintick:n,chart:s,syminfo:a}=t,u=((f=n.toString().split(".")[1])==null?void 0:f.length)||5;this._precision=u;const c=this._transformPeriod(e);this._period=c,this._mintick=n,this._offsetTime=r,this._timeframe.update(c),this.chart.updateOptions(s),this.syminfo.update(a)}updateData(t,e){const{barIndex:r,c:n,o:s,h:a,l:u,volume:c,time:f,lastBarIndex:d,lastBarTime:h,isrealtime:_,time_tradingday:g,nextBarTime:y}=t;if(this._priceVariables={close:Number(n),open:Number(s),high:Number(a),low:Number(u),volume:Number(c)},this._isRealTimeBar=_,r>this._barIndex){const{varData:p,varNewData:w,varipData:v}=this._cacheData;this._preCacheData={varData:{...p},varNewData:{...w},varipData:{...v}},this._isRealTimeBar&&(this._cacheData.varNewData={})}this._isRepeated=e,this._timeTradingday=g,this._currentBarTime=f*1e3,this._lastBarIndex=d,this._barIndex=r,this._lastBarTime=h*1e3,this._nextBarTime=y*1e3,this._barstate.update(r,d,_,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(t,e,r){const n=this.setCacheData(t,r),s=this._cacheSpace.get(t)||0;return e=Math.floor(e),s<e&&this._cacheSpace.set(t,e),n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e);const n=this._cacheSpace.get(t);return n&&r.data.length>n+5&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[t]=r,r.data}getTypeInstance(t,e){return new D_(t,e)}verifyVarAndVarip(t,e,r){const n=`${t}_${e}`;return r==="var"&&this._cacheData.varData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varData[n]),!0):r==="varip"&&this._cacheData.varipData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varipData[n]),!0):!1}getVarValue(t,e,r){const n=`${t}_${e}`,s=this._isRepeated?this._preCacheData:this._cacheData;return r==="var"?this._isRealTimeBar&&s.varNewData.hasOwnProperty(n)?s.varNewData[n]:s.varData[n]:this._cacheData.varipData[n]}setVarValue(t,e,r,n){var u;if(this._isRepeated&&n==="var")return this.getVarValue(t,e,n);const s=`${t}_${e}`;let a;switch(typeof r=="object"&&((u=r==null?void 0:r.varipKeys)!=null&&u.length)&&(n="var",a=r.varipKeys),this._chartDrawsHandle(r,this._cacheData.varData[s]||this._cacheData.varipData[s]),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[s]=r,a&&a.length)for(const c of a)this._cacheData.varData[s][c]=r[c]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}_upadteChartDraws(t){const e=t==null?void 0:t.id;if(e)switch(t==null?void 0:t.type){case te.BOX:this._setChartDraw(e,this._box);break;case te.LINE:this._setChartDraw(e,this._line);break;case te.POLYLINE:this._setChartDraw(e,this._polyline);break;case te.LABEL:this._setChartDraw(e,this._label);break;case te.LINEFILL:this._setChartDraw(e,this._linefill);break;case te.TABLE:this._setChartDraw(e,this._table);break}}_setChartDraw(t,e){const r=e.getInstance(t),n=e.get(t);if(!n||!r)return;const s=(r==null?void 0:r.updateId())||t;e.delete(t),e.set(s,n,r)}_chartDrawsHandle(t,e){const r=e==null?void 0:e.id;let n=t==null?void 0:t.id;r!==n&&(n&&t.data&&(t.data.isVar=!0),r&&e.data&&(e.data.isVar=!1))}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Wr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}div(t,e){if(e)return t/e}equal(t,e,r,n){if(t!==void 0&&e!==void 0)return t==e;if(!(r.endsWith(te.BOOL)&&t===void 0))return(r.endsWith(te.FLOAT)||r.endsWith(te.INT)||n.endsWith(te.FLOAT)||n.endsWith(te.INT))&&t===void 0&&e===void 0?!1:r.endsWith(te.STRING)&&t===""&&e===void 0||n.endsWith(te.STRING)&&e===""&&t===void 0?!0:r.endsWith(te.NA)&&n.endsWith(te.NA)?!1:t==e}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case go.name:case Ah.name:case wo.name:case Mh.name:case vo.name:case yo.name:t==null||t.delete();break}}_transformPeriod(t){return t.includes("MTH")?t=t.replace("MTH","M"):t.includes("M")&&(t=t.replace("M","")),nc(t)}}class $i{constructor(t=50){$(this,"_all");$(this,"_allInstance");$(this,"_pseudoArrayAll");$(this,"_maxLength");$(this,"_deleteIds");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new ee,this._maxLength=t,this._deleteIds=new Map}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){if(this.set(t,e,r),this._all.size>this._maxLength){const{bar_index:n}=e;for(const[s,a]of this._all){const{isVar:u,id:c,bar_index:f}=a;if(f===n)break;if(u)continue;this.delete(c);break}}}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const s=r.filter(a=>a.endsWith(`_${n}`));for(const a of s){const u=this._all.get(a);u&&e.push(u)}}return e.length?e:void 0}getDeleteIds(t){let e=[];for(const r of t)e=e.concat(this._deleteIds.get(r)||[]);return this._deleteIds.clear(),Wr.uniq(e)}set(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t,e){if(this._all.delete(t),this._allInstance.delete(t),typeof e=="number"){const r=this._deleteIds.get(e)||[];r.push(t),this._deleteIds.set(e,r)}}}/**
66
66
  * @license
67
67
  * Copyright 2019 Google LLC
68
68
  * SPDX-License-Identifier: Apache-2.0
@@ -69138,14 +69138,14 @@ function br(a, s, r) {
69138
69138
  function Nw() {
69139
69139
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
69140
69140
  }
69141
- const Cd = new Worker(new URL("" + new URL("assets/scriptsRunWorker-BJxVCn6K.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
69141
+ const Cd = new Worker(new URL("" + new URL("assets/scriptsRunWorker-BoQwf5xT.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
69142
69142
  Cd.onerror = (a) => {
69143
69143
  console.error(a);
69144
69144
  };
69145
69145
  async function Sd(a) {
69146
69146
  return await wn.setInlayHints(a);
69147
69147
  }
69148
- const Nd = xo(Cd), zd = xo(new Worker(new URL("" + new URL("assets/parserTccWorker-Cj4qsUGd.js", import.meta.url).href, import.meta.url), { type: "module", name: "Parser TccScript Server" }));
69148
+ const Nd = xo(Cd), zd = xo(new Worker(new URL("" + new URL("assets/parserTccWorker-BwaqPCOl.js", import.meta.url).href, import.meta.url), { type: "module", name: "Parser TccScript Server" }));
69149
69149
  async function zw(a, s = !1) {
69150
69150
  const { functions: r, types: n, constants: o, variables: l, methods: c } = dt;
69151
69151
  return await zd.parseTcc(a, s, ho(Sd), { functions: Object.fromEntries(r), methods: Object.fromEntries(c), types: Object.fromEntries(n), constants: Object.fromEntries(o), variables: Object.fromEntries(l) });
@@ -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:d}=Object.assign({path:[]},o.data),m=(o.data.argumentList||[]).map(Is);let _;try{const g=d.slice(0,-1).reduce((h,D)=>h[D],a),x=d.reduce((h,D)=>h[D],a);switch(c){case"GET":_=x;break;case"SET":g[d.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 d=Hs(a,{type:"GET",path:s.map(m=>m.toString())}).then(Is);return d.then.bind(d)}return $n(a,[...s,c])},set(l,c,d){xa(n);const[m,_]=va(d);return Hs(a,{type:"SET",path:[...s,c].map(g=>g.toString()),value:m},_).then(Is)},apply(l,c,d){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(d);return Hs(a,{type:"APPLY",path:s.map(x=>x.toString()),argumentList:_},g).then(Is)},construct(l,c){xa(n);const[d,m]=ol(c);return Hs(a,{type:"CONSTRUCT",path:s.map(_=>_.toString()),argumentList:d},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-BJxVCn6K.js").href:new URL("assets/scriptsRunWorker-BJxVCn6K.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-Cj4qsUGd.js").href:new URL("assets/parserTccWorker-Cj4qsUGd.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 d=0;d<c.length;d++){const m=c[d].indexOf("=");m>0&&c[d].substring(0,m)===s&&(r=c[d].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={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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=S.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=S.useRef();return S.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)=>S.useCallback(Tl(a,s,r,n),[a,s,r,n]),Ws=(a,s={})=>{var V,Q,q,C;const{i18n:r}=s,{i18n:n,defaultNS:o}=S.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 R=(A,O)=>As(O)?O:ty(O)&&As(O.defaultValue)?O.defaultValue:Array.isArray(A)?A[A.length-1]:A,E=[R,{},!1];return E.t=R,E.i18n={},E.ready=!1,E}(V=l.options.react)!=null&&V.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:d,keyPrefix:m}=c;let _=a||o||((Q=l.options)==null?void 0:Q.defaultNS);_=As(_)?[_]:_||["translation"],(C=(q=l.reportNamespaces).addUsedNamespaces)==null||C.call(q,_);const g=(l.isInitialized||l.initializedStoreOnce)&&_.every(R=>ey(R,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),[z,P]=S.useState(h);let $=_.join();s.lng&&($=`${s.lng}${$}`);const j=uy($),W=S.useRef(!0);S.useEffect(()=>{const{bindI18n:R,bindI18nStore:E}=c;W.current=!0,!g&&!d&&(s.lng?wl(l,s.lng,_,()=>{W.current&&P(D)}):Hn(l,_,()=>{W.current&&P(D)})),g&&j&&j!==$&&W.current&&P(D);const A=()=>{W.current&&P(D)};return R&&(l==null||l.on(R,A)),E&&(l==null||l.store.on(E,A)),()=>{W.current=!1,l&&(R==null||R.split(" ").forEach(O=>l.off(O,A))),E&&l&&E.split(" ").forEach(O=>l.store.off(O,A))}},[l,$]),S.useEffect(()=>{W.current&&g&&P(h)},[l,m,g]);const re=[z,l,g];if(re.t=z,re.i18n=l,re.ready=g,g||!g&&!d)return re;throw new Promise(R=>{s.lng?wl(l,s.lng,_,()=>R()):Hn(l,_,()=>R())})},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://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fy=(a,s)=>{const{height:r,width:n,theme:o,options:l,hasDiff:c,readOnly:d,defaultValue:m,language:_,onChange:g,onLinkOpen:x,onCursorPositionChange:h,onActionTrigger:D,onEditorDidMount:z}=a,{t:P,i18n:$}=Ws(),j=S.useRef(null),W=S.useRef(null),re=S.useRef(!1),V=S.useRef(!1);S.useImperativeHandle(s,()=>({setOriginalScript(A){var O;(O=j.current)==null||O.setOriginalScript(A)},setScript(A){var O;(O=j.current)==null||O.setValue(A)},gotoLine(){var A;(A=j.current)==null||A.gotoLine()},getEditorLayout(){var A;return(A=j.current)==null?void 0:A.getEditorLayout()},setPosition(A,O){var J;(J=j.current)==null||J.setPosition({column:A,lineNumber:O})},setModelMarkers(A){var O;V.current=!0,(O=j.current)==null||O.setModelMarkers(A),setTimeout(()=>{V.current=!1},2e3)},focus(){var A;(A=j.current)==null||A.focus()}})),S.useEffect(()=>{var A,O;c?(O=j.current)==null||O.addDiffDecorations():(A=j.current)==null||A.removeDiffDecorations()},[c]),S.useEffect(()=>{o&&Ne.editor.setTheme(o)},[o]),S.useEffect(()=>{_&&$.changeLanguage(_)},[_]),S.useEffect(()=>{var A;(A=j.current)==null||A.updateActionTrigger(D)},[D]),S.useEffect(()=>{var A;x&&((A=j.current)==null||A.addLinkOpenFunc(x))},[x]);function Q(A,O){var se,le;Pt.initBuiltinsTrees(),_a.setEditor(A),j.current=new km(A,O,D),x&&((se=j.current)==null||se.addLinkOpenFunc(x)),c&&((le=j.current)==null||le.addDiffDecorations()),Gu(A),requestAnimationFrame(E);const J=A.getValue();j.current.onChangeCursorPosition(h),g&&g(J),!d&&q(J),z&&z()}const q=S.useCallback(async A=>{var Rt;re.current=!1;const{errors:O,functions:J,methods:se,types:le,variables:Y,overloadsFuncs:oe,imports:xe,enums:pe}=await ml(A),_e=new Map(Object.entries(J)),Ee=new Map(Object.entries(se)),ee=new Map(Object.entries(le)),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:ee,variables:de,imports:Oe,enums:Ge},oe),Pt.setUserDefind(_e,ee,de,Ee,Ge);const Qe=O.map(us=>({...us,severity:us.type||Ne.MarkerSeverity.Error}));d||!re.current&&!V.current&&Qe.length&&((Rt=j.current)==null||Rt.setModelMarkers(Qe))},[d]),C=S.useMemo(()=>Qu.debounce(q,1500),[q]);function R(A){var O;if(d){q(A||"");return}re.current=!0,_a.clearInlayHints(),(O=j.current)==null||O.setModelMarkers([]),A!==void 0&&(g&&g(A),C(A))}const E=S.useCallback(()=>{var O,J;const A=(O=W.current)==null?void 0:O.getBoundingClientRect();(J=j.current)==null||J.setEditorLayout((A==null?void 0:A.height)||0,A==null?void 0:A.width)},[]);return S.useEffect(()=>{const A=()=>{window.requestAnimationFrame(E)},O=new ResizeObserver(A);return W.current&&O.observe(W.current),()=>{var J;W.current&&O.unobserve(W.current),O.disconnect(),(J=j.current)==null||J.dispose()}},[]),T.jsx("div",{ref:W,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:d}=Object.assign({path:[]},o.data),m=(o.data.argumentList||[]).map(Is);let _;try{const g=d.slice(0,-1).reduce((h,D)=>h[D],a),x=d.reduce((h,D)=>h[D],a);switch(c){case"GET":_=x;break;case"SET":g[d.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 d=Hs(a,{type:"GET",path:s.map(m=>m.toString())}).then(Is);return d.then.bind(d)}return $n(a,[...s,c])},set(l,c,d){xa(n);const[m,_]=va(d);return Hs(a,{type:"SET",path:[...s,c].map(g=>g.toString()),value:m},_).then(Is)},apply(l,c,d){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(d);return Hs(a,{type:"APPLY",path:s.map(x=>x.toString()),argumentList:_},g).then(Is)},construct(l,c){xa(n);const[d,m]=ol(c);return Hs(a,{type:"CONSTRUCT",path:s.map(_=>_.toString()),argumentList:d},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-BoQwf5xT.js").href:new URL("assets/scriptsRunWorker-BoQwf5xT.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-BwaqPCOl.js").href:new URL("assets/parserTccWorker-BwaqPCOl.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 d=0;d<c.length;d++){const m=c[d].indexOf("=");m>0&&c[d].substring(0,m)===s&&(r=c[d].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={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},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=S.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=S.useRef();return S.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)=>S.useCallback(Tl(a,s,r,n),[a,s,r,n]),Ws=(a,s={})=>{var V,Q,q,C;const{i18n:r}=s,{i18n:n,defaultNS:o}=S.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 R=(A,O)=>As(O)?O:ty(O)&&As(O.defaultValue)?O.defaultValue:Array.isArray(A)?A[A.length-1]:A,E=[R,{},!1];return E.t=R,E.i18n={},E.ready=!1,E}(V=l.options.react)!=null&&V.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:d,keyPrefix:m}=c;let _=a||o||((Q=l.options)==null?void 0:Q.defaultNS);_=As(_)?[_]:_||["translation"],(C=(q=l.reportNamespaces).addUsedNamespaces)==null||C.call(q,_);const g=(l.isInitialized||l.initializedStoreOnce)&&_.every(R=>ey(R,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),[z,P]=S.useState(h);let $=_.join();s.lng&&($=`${s.lng}${$}`);const j=uy($),W=S.useRef(!0);S.useEffect(()=>{const{bindI18n:R,bindI18nStore:E}=c;W.current=!0,!g&&!d&&(s.lng?wl(l,s.lng,_,()=>{W.current&&P(D)}):Hn(l,_,()=>{W.current&&P(D)})),g&&j&&j!==$&&W.current&&P(D);const A=()=>{W.current&&P(D)};return R&&(l==null||l.on(R,A)),E&&(l==null||l.store.on(E,A)),()=>{W.current=!1,l&&(R==null||R.split(" ").forEach(O=>l.off(O,A))),E&&l&&E.split(" ").forEach(O=>l.store.off(O,A))}},[l,$]),S.useEffect(()=>{W.current&&g&&P(h)},[l,m,g]);const re=[z,l,g];if(re.t=z,re.i18n=l,re.ready=g,g||!g&&!d)return re;throw new Promise(R=>{s.lng?wl(l,s.lng,_,()=>R()):Hn(l,_,()=>R())})},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://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fy=(a,s)=>{const{height:r,width:n,theme:o,options:l,hasDiff:c,readOnly:d,defaultValue:m,language:_,onChange:g,onLinkOpen:x,onCursorPositionChange:h,onActionTrigger:D,onEditorDidMount:z}=a,{t:P,i18n:$}=Ws(),j=S.useRef(null),W=S.useRef(null),re=S.useRef(!1),V=S.useRef(!1);S.useImperativeHandle(s,()=>({setOriginalScript(A){var O;(O=j.current)==null||O.setOriginalScript(A)},setScript(A){var O;(O=j.current)==null||O.setValue(A)},gotoLine(){var A;(A=j.current)==null||A.gotoLine()},getEditorLayout(){var A;return(A=j.current)==null?void 0:A.getEditorLayout()},setPosition(A,O){var J;(J=j.current)==null||J.setPosition({column:A,lineNumber:O})},setModelMarkers(A){var O;V.current=!0,(O=j.current)==null||O.setModelMarkers(A),setTimeout(()=>{V.current=!1},2e3)},focus(){var A;(A=j.current)==null||A.focus()}})),S.useEffect(()=>{var A,O;c?(O=j.current)==null||O.addDiffDecorations():(A=j.current)==null||A.removeDiffDecorations()},[c]),S.useEffect(()=>{o&&Ne.editor.setTheme(o)},[o]),S.useEffect(()=>{_&&$.changeLanguage(_)},[_]),S.useEffect(()=>{var A;(A=j.current)==null||A.updateActionTrigger(D)},[D]),S.useEffect(()=>{var A;x&&((A=j.current)==null||A.addLinkOpenFunc(x))},[x]);function Q(A,O){var se,le;Pt.initBuiltinsTrees(),_a.setEditor(A),j.current=new km(A,O,D),x&&((se=j.current)==null||se.addLinkOpenFunc(x)),c&&((le=j.current)==null||le.addDiffDecorations()),Gu(A),requestAnimationFrame(E);const J=A.getValue();j.current.onChangeCursorPosition(h),g&&g(J),!d&&q(J),z&&z()}const q=S.useCallback(async A=>{var Rt;re.current=!1;const{errors:O,functions:J,methods:se,types:le,variables:Y,overloadsFuncs:oe,imports:xe,enums:pe}=await ml(A),_e=new Map(Object.entries(J)),Ee=new Map(Object.entries(se)),ee=new Map(Object.entries(le)),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:ee,variables:de,imports:Oe,enums:Ge},oe),Pt.setUserDefind(_e,ee,de,Ee,Ge);const Qe=O.map(us=>({...us,severity:us.type||Ne.MarkerSeverity.Error}));d||!re.current&&!V.current&&Qe.length&&((Rt=j.current)==null||Rt.setModelMarkers(Qe))},[d]),C=S.useMemo(()=>Qu.debounce(q,1500),[q]);function R(A){var O;if(d){q(A||"");return}re.current=!0,_a.clearInlayHints(),(O=j.current)==null||O.setModelMarkers([]),A!==void 0&&(g&&g(A),C(A))}const E=S.useCallback(()=>{var O,J;const A=(O=W.current)==null?void 0:O.getBoundingClientRect();(J=j.current)==null||J.setEditorLayout((A==null?void 0:A.height)||0,A==null?void 0:A.width)},[]);return S.useEffect(()=>{const A=()=>{window.requestAnimationFrame(E)},O=new ResizeObserver(A);return W.current&&O.observe(W.current),()=>{var J;W.current&&O.unobserve(W.current),O.disconnect(),(J=j.current)==null||J.dispose()}},[]),T.jsx("div",{ref:W,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,...d?am:{},readOnlyMessage:{value:P("This script is read-only. It cannot be edited.")},...l},onMount:Q,onChange:R})})},gy=S.forwardRef(fy),by=a=>{const{theme:s,modified:r,original:n,height:o,width:l,renderSideBySide:c=!0}=a,d=S.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:d})};L.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"}(L.VMarkerSeverity||(L.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,d,m=!1;s||(s={}),r=s.debug||!1;try{o=hy(),l=document.createRange(),c=document.getSelection(),d=document.createElement("span"),d.textContent=a,d.ariaHidden="true",d.style.all="unset",d.style.position="fixed",d.style.top=0,d.style.clip="rect(0, 0, 0, 0)",d.style.whiteSpace="pre",d.style.webkitUserSelect="text",d.style.MozUserSelect="text",d.style.msUserSelect="text",d.style.userSelect="text",d.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(d),l.selectNodeContents(d),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()),d&&document.body.removeChild(d),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(S),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(d){var m=n.props,_=m.text,g=m.onCopy,x=m.children,h=m.options,D=ka.default.Children.only(x),z=(0,Dy.default)(_,h);g&&g(_,z),D&&D.props&&typeof D.props.onClick=="function"&&D.props.onClick(d)}),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),d=ka.default.Children.only(l);return ka.default.cloneElement(d,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:d,remarks:m,seeAlso:_,syntax:g,detailedDesc:x,fields:h,returns:D}=r,z={name:n,orirginalName:n};if(a.length>1&&(z.overloads=`${a.length} ${Me.t("overloads")}`),l&&(z.type=l),o&&(z.name=`${n}()`,z.args=o.map(P=>{const{name:$,desc:j,displayType:W}=P;return{label:`${$} (${W})`,desc:j&&qs(j)}})),c&&(z.desc=c.map(P=>qs(P))),d&&(z.originalExample=d.join(`
147
147
  `),z.examples=await Ne.editor.colorize(z.originalExample,Ke,{tabSize:4})),x){z.detailedDesc=[];for(const P of x){const{desc:$,examples:j}=P;let W=$.map(Q=>qs(Q)),re,V;j&&(V=j.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guihz/trading-vue-editor-tes",
3
- "version": "0.0.239",
3
+ "version": "0.0.240",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib"