@guihz/trading-vue-editor-tes 0.0.182 → 0.0.184
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.
@@ -116,7 +116,7 @@ ${this._prefixNameVar}.againAssignParse(${v}, ${B});
|
|
116
116
|
})
|
117
117
|
`}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":"",l=`const ${n} = (${this._parserParameters(r)}$posStr${s}) => {
|
118
118
|
${this._parserBlock(e.block,!0,!0)}
|
119
|
-
}`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:l}),l}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let l=r;if(s){const h=this._parserSingleExpression(s);l=`${l} = ${h}`}return l}).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 l=e.posList;for(const[h,d]of e.names.entries()){const v=((r=l[h])==null?void 0:r.reName)||d;n[v]=l[h]}}else{const l=((s=e.pos)==null?void 0:s.reName)||e.name;n[l]=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 l={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}`,A=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${s} = ${this._prefixNameVar}.getVarValue("${s}", ${A}, ${d}, "${n.declare}")`}return l.code=v,l.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(l),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((l,h)=>{var d,v;return l==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:Rn.includes(l)?`$${l}`:l}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:Rn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",l=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._parserSingleExpression(n[0])} ${r} ${this._parserSingleExpression(n[1])}`;case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=l,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=l,s;case le.TernaryExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,this._isInConditionalStmt=l,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||""}}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),l=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${l})`:`${this._prefixNameVar}.add(${s}, ${l})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,l=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(l);const v=s.start.tokenIndex,S=r?"$posStr":v;if(l.ruleType===le.Name&&!l.hasMethod){let A=this._blockCount;const R=((C=l.varPos)==null?void 0:C.reName)||l.name;for(;A>=0;){const B=this._varlist[A]||{},M=B[R];if(M)return this._getUserVarMemberIndexs(M,R,A,h,r);if(l.isBuiltIn){const b=this._memberIndexList[0]||{};return b[R]=`${this._prefixNameVar}.setCacheData("${R}", ${d})`,`${this._prefixNameVar}.getCacheData("${R}", ${h}, ${d})`}if(R.includes(".")){const b=R.split(".")[0],y=B[b];if(y)return this._getUserVarMemberIndexs(y,R,A,h,r)}A--}return this._getOtherVarMemberIndexs(`${R}_${l.varScope||l.scope}`,R,l.varScope||l.scope,h,r)}else{const A=this._preRunMembers[this._blockCount]||[],R=`$$m${v}_${S}`;A.push(`const ${R} = ${d};
|
119
|
+
}`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:l}),l}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let l=r;if(s){const h=this._parserSingleExpression(s);l=`${l} = ${h}`}return l}).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 l=e.posList;for(const[h,d]of e.names.entries()){const v=((r=l[h])==null?void 0:r.reName)||d;n[v]=l[h]}}else{const l=((s=e.pos)==null?void 0:s.reName)||e.name;n[l]=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 l={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}`,A=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${A}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${A}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${A}, ${d}, "${n.declare}")`}return l.code=v,l.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(l),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((l,h)=>{var d,v;return l==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:Rn.includes(l)?`$${l}`:l}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:Rn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",l=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._parserSingleExpression(n[0])} ${r} ${this._parserSingleExpression(n[1])}`;case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=l,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=l,s;case le.TernaryExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,this._isInConditionalStmt=l,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||""}}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),l=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${l})`:`${this._prefixNameVar}.add(${s}, ${l})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,l=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(l);const v=s.start.tokenIndex,S=r?"$posStr":v;if(l.ruleType===le.Name&&!l.hasMethod){let A=this._blockCount;const R=((C=l.varPos)==null?void 0:C.reName)||l.name;for(;A>=0;){const B=this._varlist[A]||{},M=B[R];if(M)return this._getUserVarMemberIndexs(M,R,A,h,r);if(l.isBuiltIn){const b=this._memberIndexList[0]||{};return b[R]=`${this._prefixNameVar}.setCacheData("${R}", ${d})`,`${this._prefixNameVar}.getCacheData("${R}", ${h}, ${d})`}if(R.includes(".")){const b=R.split(".")[0],y=B[b];if(y)return this._getUserVarMemberIndexs(y,R,A,h,r)}A--}return this._getOtherVarMemberIndexs(`${R}_${l.varScope||l.scope}`,R,l.varScope||l.scope,h,r)}else{const A=this._preRunMembers[this._blockCount]||[],R=`$$m${v}_${S}`;A.push(`const ${R} = ${d};
|
120
120
|
${this._prefixNameVar}.setCacheData("m${v}_" + ${S}, ${R})`),this._preRunMembers[this._blockCount]=A}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,s,l){const h=this._memberIndexList[r]||{};e=l&&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,l){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,s,l)}_parseLiteral(e){return e.type.endsWith(U.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),l=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(l)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){const{exprs:r,varScope:s,hasMethod:l,arg:h,varPos:d}=e,v=r.map(S=>{var B;if(typeof S=="string")return(d==null?void 0:d.reName)||S;const{column:C,line:A}=((B=S==null?void 0:S.ctx)==null?void 0:B.start)||{},R=`${A}_${C}`;return this._parserMethodElement(S,R)});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(Rn.includes(v[0])&&(v[0]=`$${v[0]}`),!l){const S={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(S)}return v.join(".")}_setDepend(e){const n=e.name;for(const r of Object.values(this._dependsObj)){const s=r.get(n)||{},l={...e,...s};r.set(n,l)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:s,line:l}=r.start,h=`${l}_${s}`;let d=this._isInFunc?`$posStr + "__${h}"`:`"${h}"`;d=this._isInLoop?`$$count${this._count} + ${d}`:d;let v=!1;const C=n.map(A=>(A.hasMemberIndex&&(v=!0),this._parserMethodElement(A,d))).join(".");if(this._isInConditionalStmt&&v){const A=`$$result_${this._preRunMemberFuncsCount}`;this._preRunMemberFuncsCount++;const R=this._preRunMembersFuncs[this._blockCount]||[];return R.push(`const ${A} = ${C}`),this._preRunMembersFuncs[this._blockCount]=R,A}return C}_parserMethodElement(e,n){let r="",s="";const l={...e.args};e.expr&&(r=`(${this._parserSingleExpression(e.expr)})`),r=r?`${r}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(r=`${this._prefixNameVar}.${r}`);let h=!1;if(e.isBuiltIn){if(Ip.includes(r))r=`${r}.${r}`;else if(r==="max_bars_back"){const{name:v,varPos:S}=l.var||l.params[0];s=`var_name: "${S?`${v}_${S.lineNumber}_${S.column}`:v}"`}r.startsWith(U.INPUT)?(s=`index: ${this._inputCount}`,this._inputCount++):r.startsWith("request.")&&(h=!0),r=`${this._prefixNameFunc}.${r}`}else{const v=r.split(".");let S=v[0];Rn.includes(S)&&(S=`$${S}`,r=v.join("."))}if(e.selfArg){const v=r.split("."),S=v.length;Object.assign(l,{[e.selfArg.name]:{name:v.slice(0,S-1).join(".")}}),r=v[S-1],r=this._nameMap.get(r)||r,this._setDepend({name:v[0],scope:e.varScope||0})}r=`${r}${e.index?`$${e.index}`:""}`;const d=this._parserArguments(l,s,n,h,e.hasRequest,r);if(!e.isBuiltIn){const v=r.split(".");if(v.length>1?this._setDepend({name:v[0],scope:e.varScope||0}):this._setDepend({name:r,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const S=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:S,originName:r,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return r+d}_parserArguments(e,n,r,s=!1,l=!1,h){const d=e.params||[];delete e.params;const v=[],S=[];let C=[],A;const R=(M,b)=>{l&&(this._dependsObj[r]=new Map),s&&b==="expression"&&(this._dependsObj[`$arg_${b}${r}`]=new Map);let y=M.ruleType===le.Brackethesized?this._parserBrackethesized(M):this._parserSingleExpression(M);if(b&&!["arg0, arg1, ...","number0, number1, ..."].includes(b)){M.isSourceType?v.push(`sourceTypeName: "${M.name}"`):b==="defval"&&h===`${this._prefixNameFunc}.input.enum`&&(A=this._enums.get(M.enumName));const g=this._requestParamsHandle(s,b,r,l,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 M of d)R(M,M.originName);for(const M of Object.keys(e))R(e[M],M);s&&this._isInFunc&&v.push("paramsExpr: $paramsExpr"),n&&v.push(n),A&&v.unshift(`options: [${A.join(", ")}]`);const B=C.length?`, [${this._isInFunc?"...$paramsExpr, ":""}${C.join(", ")}]`:"";return S.length?`({${v.join(", ")}}, [${S.join(", ")}], ${r}${B})`:v.length?`({${v.join(", ")}}, ${r}${B})`:`(${r}${B})`}_requestParamsHandle(e,n,r,s,l,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(A=>(A.isArg&&(A.functionName=this._currentFuncName),A)),code:l,memberCodes:v}),{code:`'${Lp(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(A=>A.name===n),code:`${n} = ${l}`,memberCodes:v}),{paramsExpr:`'${Lp(JSON.stringify(C))}'`}}}_getExpressionContext(e){const n=[],r=[];return this._getDependsCode(e,n,r),n}_getDependsCode(e,n,r){var s,l;for(const h of e)if(!h.isArg){const d=this._codesCol[h.scope||0],v=d.find(C=>{var A;return((A=C.varNames)==null?void 0:A.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(A=>A.name===h.name&&A.scope===h.scope&&A.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:(l=C.varNames)==null?void 0:l.join(", ")}))}}_parserBrackethesized(e){return`[${e.exprs.map(r=>this._parserSingleExpression(r)).join(", ")}]`}_functionalProcess(e){return`(function () {
|
121
121
|
let $$_result=undefined;
|
122
122
|
${e}
|
@@ -62,7 +62,7 @@ ${Pf}`)}function O1(s,t,e){return(s>=0&&e?` ${qf(s,t-1)}`:qf(s,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))}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._toStringFormat(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return _t(e)&&(e=0),_t(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _t(t)&&(t=0),zr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_toStringFormat(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case Kt.mintick:return t.toFixed(this._precision);case Kt.percent:return`${t}%`;case Kt.volume:return this._intlNumberFormatter.format(Math.round(t));default:return this._formatOthers(t,e)}}_formatOthers(t,e){var l;let[r,n]=e.split(".");e.split("%").length===2&&(t=t*100);let[i,a=""]=String(t).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),p=((l=c[c.length-1])==null?void 0:l.replace(/[^#]/g,"").length)||0;p&&(i=i.replace(new RegExp(`\\B(?=(\\d{${p}})+(?!\\d))`,"g"),",")),r=c.join("")}i=r.replace(/#/,i).replace(/#/g,"")}else i=`${r}${i}`;if(n&&n.includes("#")){const c=n.split("#").length-1;a=`${a.substring(0,c)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${i}.${a}`:i}_formatNumber(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:return this._formatOthers(t,e)}}_strFormat(t,e){let r=t;for(const[n,i]of e.entries()){if(i===void 0||typeof i=="number"&&isNaN(i)){r="NaN";continue}if(typeof i=="number"){const a=`\\{\\s*${n}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const c=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(i,c)))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),String(i))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),i)}return r}}class Ey{constructor(t){R(this,"_errorListener");this._errorListener=t}new(){return new ka(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 ka{constructor(t){R(this,"_errorListener");R(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new ka(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class xy{constructor(t){R(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Ai(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Ai(t,r,e)}copy({id:t}){return t==null?void 0:t.copy()}from_index({price:t,index:e}){return new Ai(t,e)}from_time({price:t,time:e}){return new Ai(t,void 0,e)}}class Ai{constructor(t,e,r){R(this,"_index");R(this,"_price");R(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new Ai(this._price,this._index,this._time)}}class Ay{constructor(t,e){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultLabel",{text:"",xloc:we.bar_index,yloc:Ur.price,size:er.normal,style:me.styleLabelDown,textalign:Wt.alignCenter});this._variables=t,this._errorListener=e}new(t,e){const{time:r,high:n,low:i,bar_index:a}=this._variables,l=`label_${e}_${a}`;_e(t,["color","textcolor"]);const c={...this._defaultLabel,...t,id:l,time:r,high:n,low:i};t.point&&(c.x=c.xloc===we.bar_index?t.point.index:t.point.time,c.y=t.point.price),c.yloc===Ur.abovebar?c.y=n:c.yloc===Ur.belowbar&&(c.y=i),this._verfiyArgs(t,e);const p=new ao(l,this._variables,this._errorListener);return e.startsWith("export")||this._variables.label.add(l,c,p),p}_verfiyArgs(t,e){const{xloc:r,yloc:n,style:i,size:a,textalign:l,text_font_family:c}=t,p="label.new";this._paramVerfiy(i,e,p,Object.values(me),"style"),this._paramVerfiy(r,e,p,Object.values(we),"xloc"),this._paramVerfiy(n,e,p,Object.values(Ur),"yloc"),this._paramVerfiy(a,e,p,Object.values(er),"size"),this._paramVerfiy(l,e,p,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign"),this._paramVerfiy(c,e,p,Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.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 ao{constructor(t,e,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}copy(t){const e=`label_${t}_${this._variables.bar_index}`,r=this._getLabel(t),n=new ao(e,this._variables,this._errorListener);if(r){const i={...r,id:e};this._variables.label.add(e,i,n)}return n}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t),this._paramVerfiy(t,e,"label.set_size",Object.values(er),"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(we),"xloc"))}set_yloc({yloc:t},e){const r=this._getLabel(e),{high:n,low:i}=this._variables;r&&(r.yloc=t,t===Ur.abovebar?r.y=n:t===Ur.belowbar&&(r.y=i),this._paramVerfiy(t,e,"label.set_yloc",Object.values(Ur),"yloc"))}set_color(t,e){const r=this._getLabel(e);_e(t,["color"]),r&&(r.color=t.color)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===we.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(me),"style")}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t),this._paramVerfiy(t,e,"label.set_textalign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign")}set_textcolor(t,e){const r=this._getLabel(e);_e(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(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const Cy={freq_all:qr.freqAll,freq_once_per_bar:qr.freqOncePerBar,freq_once_per_bar_close:qr.freqOncePerBarClose},Fy={gaps_off:Vi.gapsOff,gaps_on:Vi.gapsOn,lookahead_off:Vi.lookaheadOff,lookahead_on:Vi.lookaheadOn},Ci={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"},Jf={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"},My={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},Xf={all:[Ye.dataWindow,Ye.pane,Ye.priceScale,Ye.statusLine],data_window:[Ye.dataWindow],none:[],pane:[Ye.pane],price_scale:[Ye.priceScale],status_line:[Ye.statusLine]},Ny={both:kr.both,left:kr.left,none:kr.none,right:kr.right},Sy={inherit:Kt.inherit,mintick:Kt.mintick,percent:Kt.percent,price:Kt.price,volume:Kt.volume},By={style_solid:Ds.styleSolid,style_dashed:Ds.styleDashed,style_dotted:Ds.styleDotted},Oy={style_arrowdown:me.styleArrowdown,style_arrowup:me.styleArrowup,style_circle:me.styleCircle,style_cross:me.styleCross,style_diamond:me.styleDiamond,style_flag:me.styleFlag,style_label_center:me.styleLabelCenter,style_label_down:me.styleLabelDown,style_label_left:me.styleLabelLeft,style_label_lower_left:me.styleLabelLowerLeft,style_label_lower_right:me.styleLabelLowerRight,style_label_right:me.styleLabelRight,style_label_up:me.styleLabelUp,style_label_upper_left:me.styleLabelUpperLeft,style_label_upper_right:me.styleLabelUpperRight,style_none:me.styleNone,style_square:me.styleSquare,style_text_outline:me.styleTextOutline,style_triangledown:me.styleTriangledown,style_triangleup:me.styleTriangleup,style_xcross:me.styleXcross},Ty={style_arrow_both:Le.styleArrowBoth,style_arrow_left:Le.styleArrowLeft,style_arrow_right:Le.styleArrowRight,style_dashed:Le.styleDashed,style_dotted:Le.styleDotted,style_solid:Le.styleSolid},Iy={abovebar:an.abovebar,absolute:an.absolute,belowbar:an.belowbar,bottom:an.bottom,top:an.top},$y={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},Ly={style_area:Cr.styleArea,style_areabr:Cr.styleAreabr,style_circles:Cr.styleCircles,style_columns:Cr.styleColumns,style_cross:Cr.styleCross,style_histogram:Cr.styleHistogram,style_line:Cr.styleLine,style_linebr:Cr.styleLinebr,style_stepline:Cr.styleStepline,style_stepline_diamond:Cr.styleSteplineDiamond,style_steplinebr:Cr.styleSteplinebr},Ry={bottom_center:pr.bottomCenter,bottom_left:pr.bottomLeft,bottom_right:pr.bottomRight,middle_center:pr.middleCenter,middle_left:pr.middleLeft,middle_right:pr.middleRight,top_center:pr.topCenter,top_left:pr.topLeft,top_right:pr.topRight},Py={left:bs.left,none:bs.none,right:bs.right},zy={arrowdown:or.arrowdown,arrowup:or.arrowup,circle:or.circle,cross:or.cross,diamond:or.diamond,flag:or.flag,labeldown:or.labeldown,labelup:or.labelup,square:or.square,triangledown:or.triangledown,triangleup:or.triangleup,xcross:or.xcross},qy={auto:er.auto,huge:er.huge,large:er.large,normal:er.normal,small:er.small,tiny:er.tiny},ky={cash:Oe.cash,fixed:Oe.fixed,percent_of_equity:Oe.percentOfEquity,commission:{cash_per_contract:Fr.cashPerContract,cash_per_order:Fr.cashPerOrder,percent:Fr.percent},direction:{all:ge.all,long:ge.long,short:ge.short},oca:{cancel:un.cancel,none:un.none,reduce:un.reduce}},Uy={align_bottom:Wt.alignBottom,align_center:Wt.alignCenter,align_left:Wt.alignLeft,align_right:Wt.alignRight,align_top:Wt.alignTop,wrap_auto:Wt.wrapAuto,wrap_none:Wt.wrapNone},Wy={bar_index:we.bar_index,bar_time:we.bar_time},jy={abovebar:Ur.abovebar,belowbar:Ur.belowbar,price:Ur.price},Yy={actual:Es.actual,estimate:Es.estimate,standardized:Es.standardized};class Qf{constructor(){R(this,"adjustment",{dividends:ws.dividends,none:ws.none,splits:ws.splits});R(this,"alert",Cy);R(this,"barmerge",Fy);R(this,"color",Ci);R(this,"currency",Jf);R(this,"dayofweek",My);R(this,"earnings",Yy);R(this,"display",Xf);R(this,"extend",Ny);R(this,"font",{family_default:Zn.familyDefault,family_monospace:Zn.familyMonospace});R(this,"format",Sy);R(this,"hline",By);R(this,"label",Oy);R(this,"line",Ty);R(this,"location",Iy);R(this,"math",$y);R(this,"order",{ascending:Vn.ascending,descending:Vn.descending});R(this,"plot",Ly);R(this,"position",Ry);R(this,"scale",Py);R(this,"session",{extended:fi.extended,regular:fi.regular});R(this,"shape",zy);R(this,"size",qy);R(this,"splits",{denominator:"denominator",numerator:"numerator"});R(this,"strategy",ky);R(this,"text",Uy);R(this,"xloc",Wy);R(this,"yloc",jy)}updateData(){}}class Vy{constructor(t,e){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:we.bar_index,line_color:Ci.blue,line_style:Le.styleSolid,line_width:1});this._variables=t,this._errorListener=e}new(t,e){var a;const r=`polyline_${e}_${this._variables.bar_index}`,n=Object.assign({},this._defaultPolyline,t,{id:r,points:(a=t.points)==null?void 0:a._value.map(l=>({time:l.time,index:l.index,price:l.price}))});_e(n,["line_color","fill_color"]);const i=new th(r,this._variables);return this._verfiyArgs(t,e),e.startsWith("export")||this._variables.polyline.add(r,n,i),i}_verfiyArgs(t,e){const{line_style:r,xloc:n}=t,i="polyline.new";this._paramVerfiy(r,e,i,Object.values(Le),"line_style"),this._paramVerfiy(n,e,i,Object.values(we),"xloc")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}delete({id:t}){t&&t.delete()}}class th{constructor(t,e){R(this,"_id");R(this,"_variables");this._variables=e,this._id=t}delete(){this._variables.polyline.delete(this._id)}}class Zy{constructor(t,e){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultLine",{xloc:we.bar_index,extend:kr.none,style:Le.styleSolid});this._variables=t,this._errorListener=e}new({first_point:t,second_point:e,...r},n){const i=`line_${n}_${this._variables.bar_index}`;_e(r,["color"]);const a={...this._defaultLine,...r,id:i};if(t&&e){const c=a.xloc===we.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,p=a.xloc===we.bar_index?e==null?void 0:e.index:e==null?void 0:e.time;Object.assign(a,{x1:c,y1:t==null?void 0:t.price,x2:p,y2:e==null?void 0:e.price})}this._verfiyArgs(r,n);const l=new uo(i,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(i,a,l),l}_verfiyArgs(t,e){const{extend:r,xloc:n,style:i}=t,a="line.new";this._paramVerfiy(i,e,a,Object.values(Le),"style"),this._paramVerfiy(r,e,a,Object.values(kr),"extend"),this._paramVerfiy(n,e,a,Object.values(we),"xloc")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.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 uo{constructor(t,e,r){R(this,"_variables");R(this,"_id");R(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get data(){return this._variables.line.get(this._id)}copy(t){const e=`line_${t}_${this._variables.bar_index}`,r=this._getLine(t),n=new uo(e,this._variables,this._errorListener);return r&&this._variables.line.add(e,{...r,id:e},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===we.bar_index){const{x1:n,y1:i,x2:a,y2:l}=r;return n===void 0||a===void 0||i===void 0||l===void 0?void 0:(l-i)/(a-n)*(t-n)+i}}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 i=this._getLine(n);i&&(i.xloc=t,i.x1=e,i.x2=r,this._paramVerfiy(t,n,"line.set_xloc",Object.values(we),"xloc"))}set_color(t,e){const r=this._getLine(e);r&&(_e(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(Le),"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(kr),"extend"))}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:i,price:a}=t||{},l=r.xloc===we.bar_index?n:i,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:i,price:a}=t||{},l=r.xloc===we.bar_index?n:i,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class Ky{constructor(t){R(this,"_variables");this._variables=t}new(t,e){const{line1:r,line2:n}=t,i=`linefill_${e}_${this._variables.bar_index}`,a=r==null?void 0:r.data,l=n==null?void 0:n.data;a&&(a.linefills=a.linefills||[],a.linefills.push(i)),l&&(l.linefills=l.linefills||[],l.linefills.push(i)),_e(t,["color"]);const c=new lo(this._variables,i,r,n);return e.startsWith("export")||(a||l)&&this._variables.linefill.add(i,{line1:a,line2:l,color:t.color,id:i},c),c}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 lo{constructor(t,e,r,n){R(this,"_id");R(this,"_line1");R(this,"_line2");R(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}linefill(t,e){return t.x?t.x:new lo(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:i}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),i&&(i.linefills=(r=i.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(t){const e=this._variables.linefill.get(this._id);e&&(_e(t,["color"]),e.color=t.color)}}class Gy{constructor(t,e){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultBox",{border_color:Ci.blue,border_width:1,bgcolor:Ci.blue,xloc:we.bar_index,extend:kr.none,style:Le.styleSolid,text:"",text_size:er.auto,text_color:Ci.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_wrap:Wt.wrapNone});this._variables=t,this._errorListener=e}box({x:t}){return t}new({top_left:t,bottom_right:e,...r},n){const i=`box_${n}_${this._variables.bar_index}`,a={...this._defaultBox,...r,id:i};if(_e(a,["border_color","bgcolor","text_color"]),t){const{price:c,time:p,index:h}=t;a.top=c,a.left=a.xloc===we.bar_index?h:p}if(e){const{price:c,time:p,index:h}=e;a.bottom=c,a.right=a.xloc===we.bar_index?h:p}this._verfiyArgs(r,n);const l=new co(this._variables,i,this._errorListener);return n.startsWith("export")||this._variables.box.add(i,a,l),l}_verfiyArgs(t,e){const{border_style:r,extend:n,xloc:i,text_size:a,text_halign:l,text_valign:c,text_wrap:p,text_font_family:h}=t,f="box.new";this._paramVerfiy(r,e,f,[Le.styleDashed,Le.styleDotted,Le.styleSolid],"border_style"),this._paramVerfiy(n,e,f,Object.values(kr),"extend"),this._paramVerfiy(i,e,f,Object.values(we),"xloc"),this._paramVerfiy(a,e,f,Object.values(er),"text_size"),this._paramVerfiy(l,e,f,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"),this._paramVerfiy(c,e,f,[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"),this._paramVerfiy(p,e,f,[Wt.wrapAuto,Wt.wrapNone],"text_wrap"),this._paramVerfiy(h,e,f,Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.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_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 co{constructor(t,e,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");this._variables=t,this._id=e,this._errorListener=r}copy(t){const e=`box_${t}_${this._variables.bar_index}`,r=this._getBox(),n=new co(this._variables,e,this._errorListener);return r&&this._variables.box.add(e,{...r,id:e},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t},e){const r=this._getBox();r&&(r.extend=t,this._paramVerfiy(t,e,"box.set_extend",Object.values(kr),"extend"))}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t,_e(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(er),"text_size"))}set_text_wrap({text_wrap:t},e){const r=this._getBox();r&&(r.text_wrap=t,this._paramVerfiy(t,e,"box.set_text_wrap",[Wt.wrapAuto,Wt.wrapNone],"text_wrap"))}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t,_e(e,["text_color"]))}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t},e){const r=this._getBox();r&&(r.text_halign=t,this._paramVerfiy(t,e,"box.set_text_halign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"))}set_text_valign({text_valign:t},e){const r=this._getBox();r&&(r.text_valign=t,this._paramVerfiy(t,e,"box.set_text_valign",[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"))}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:i}=t||{};e.top=n,e.left=e.xloc===we.bar_index?r:i}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t,_e(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",[Le.styleDashed,Le.styleDotted,Le.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:i}=t||{};e.bottom=n,e.right=e.xloc===we.bar_index?r:i}}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(Zn),"text_font_family"))}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getBox(){return this._variables.box.get(this._id)}}class Hy{constructor(t,e){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultTable",{position:pr.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 r=`table_${e}_${this._variables.bar_index}`,{columns:n,rows:i}=t;_e(t,["text_color","bgcolor","border_color"]);const a=Array.from(Array(i),()=>Array.from(Array(n),()=>{})),l={...this._defaultTable,...t,cell:a,id:r},c=new eh(this._variables,r,this._errorListener);return this._paramVerfiy(t.position,e,"table.new",Object.values(pr),"position"),e.startsWith("export")||this._variables.table.add(r,l,c),c}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.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 eh{constructor(t,e,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");R(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ci.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_size:er.normal});this._variables=t,this._id=e,this._errorListener=r}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,i=this._variables.table.get(this._id);if(i){const a=i.cell||[],l=a[n]||[];l[r]=e,a[n]=l,i.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,_e(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 i=this._variables.table.get(this._id);if(i){const a=i.cell;if(a)for(let l=e;l<=n;l++)for(let c=t;c<=r;c++){const p=a[l];p&&(p[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},i){if(t>r||e>n){this._errorListener.addError(ue.mergeCellErr,i,zt.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const l=a.merge_cells||[];l.push({start_column:t,start_row:e,end_column:r,end_row:n}),a.merge_cells=l}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t,_e(e,["bgcolor"]))}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t,_e(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(pr),"position"))}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.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 Jy{constructor(t){R(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_time}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===ge.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class Xy{constructor(t){R(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===ge.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class Qy{constructor(t,e){R(this,"_strategy");R(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(ge),"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",[Oe.percentOfEquity,Oe.cash],"type"),e===Oe.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",[Oe.percentOfEquity,Oe.cash],"type"),e===Oe.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,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}}let tw=class{constructor(t,e,r,n){R(this,"_variables");R(this,"_options");R(this,"_totalChangeCapital");R(this,"_historyOrder");R(this,"_orders");R(this,"_pendingOrders");R(this,"_mintick");R(this,"_funcOptions");R(this,"_pendingCloseOrders");R(this,"_errorListener");R(this,"_risk");R(this,"_opentrades");R(this,"_closedtrades");R(this,"_riskNamespace");this._variables=t,this._errorListener=n,this._options={overlay:!1,format:Kt.inherit,pyramiding:0,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Oe.fixed,default_qty_value:1,initial_capital:1e6,currency:Jf.NONE,slippage:0,commission_type:Fr.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._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 Xy(this),this._closedtrades=new Jy(this),this._riskNamespace=new Qy(this,n)}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _orderProfit(){return this._orders.reduce((t,e)=>t+(e.profit||0),0)}get _freezeCapital(){const{close:t}=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}updateOptions(t){Object.assign(this._options,t),this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._calcProfitAndLoss(),this._variables.strategy.update(),this._maxDrawdownVerify(),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{high:n,low:i,time_tradingday:a,time:l,strategy:{netprofit:c,initial_capital:p}}=this._variables;let{preNetprofit:h=0}=this._risk;l===a&&(h=c,this._risk.preNetprofit=c,this._risk.isTemporaryBan=!1);let f=h-c;f+=this._orders.reduce((y,m)=>{const{in_price:w,direction:v,qty:E=0,commission:b=0,original_qty:N=0}=m,x=v===ge.long?1:-1,F=(n-w)*E,M=(i-w)*E,S=x===1?-M:F;return y+S+E/N*b},0);let d=!1;switch(e){case Oe.cash:d=t<f;break;case Oe.percentOfEquity:const y=f/(p+c)*100;d=t<y;break}if(d){this._risk.isTemporaryBan=!0;const y=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,y===ge.long?i:n,"Close Position (Max intraday Loss)"),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:i,open:a}=this._variables;n===i&&(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)"),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:i,time_tradingday:a,strategy:l,open:c}=this._variables;let p=e;if(i===a){const h=l.netprofit+l.openprofit;h<n?p=0:p++,Object.assign(this._risk,{lossDays:p,totalProfit:h})}t<=p&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){var n;const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(!r&&t!==void 0&&e){const{max_drawdown:i,max_drawdown_percent:a}=this._variables.strategy;let l=!1;switch(e){case Oe.percentOfEquity:l=a<i;break;case Oe.cash:l=t<i;break}if(l){const{high:c,low:p}=this._variables,h=(n=this._orders[0])==null?void 0:n.direction;this._riskTouchOff(h===ge.long?c:p,"Close Position (Max Drawdown)")}}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._closeOrders(this._orders,t,e),this._pendingOrders=[]}strategy(t,e){this._variables.bar_index||(this._paramVerfiy(t.format,e,"strategy",[Kt.inherit,Kt.price,Kt.percent,Kt.volume],"format"),this._paramVerfiy(t.default_qty_type,e,"strategy",Object.values(Oe),"default_qty_type"),this._paramVerfiy(t.commission_type,e,"strategy",Object.values(Fr),"commission_type"),Object.assign(this._options,t),this._variables.updateMaxLength(t),Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"}))}order(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.order",Object.values(un),"oca_type"),this._orderHandle(t))}entry(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.entry",Object.values(un),"oca_type"),this._entryHandle(t))}close(t){if(!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close"}):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=Oe.fixed,default_qty_value:r=1,initial_capital:n}=this._options;switch(e){case Oe.fixed:return r;case Oe.cash:return r/t;case Oe.percentOfEquity:return(n+this._orderProfit+this._totalChangeCapital)*r/100/t}}_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{high:t,low:e,close:r}=this._variables;for(const n of this._orders){const{in_price:i,qty:a=0,direction:l}=n,c=l===ge.long?1:-1,p=(r-i)*c*a,h=(t-i)*a,f=(e-i)*a,d=c===1?h:-f,g=c===1?-f:h;this._calcOrderPercent(n,p,d,g)}}_calcOrderPercent(t,e,r,n){const{commission_value:i}=this._options,{close:a}=this._variables,{original_qty:l=0,qty:c=0,in_price:p,max_profit:h=0,trading_loss:f=0}=t;let{commission:d=0}=t;const g=p*c;if(i){const y=this._getCommission(a,c);e=e-y,d=d*c/l,r-=d,n+=d}r=Math.max(r,h),n=Math.min(n,f),e=e-d,Object.assign(t,{profit:e,total_profit:this._totalChangeCapital+e,total_profit_percent:e/this._options.initial_capital*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{high:t,low:e}=this._variables,{initial_capital:r,margin_long:n=0,margin_short:i=0,commission_value:a=0}=this._options,l=this._orders[0].direction===ge.long?1:-1,c=l===1?e:t,p=(l===1?n:i)/100;if(p<=0)return;const[h,f,d]=this._orders.reduce((v,E)=>{let[b,N,x]=v;const{in_price:F,qty:M=0,original_qty:S=0,commission:I=0}=E,C=F*M,B=c*M;if(b+=C,N+=B,a){const L=this._getCommission(c,M);x+=L+M/S*I}return[b,N,x]},[0,0,0]),g=l*(f-h),m=r+this._totalChangeCapital+g-d-f*p;if(m>=0)return;const w=Math.trunc(m/p/c)*4;this._marginCallOrders(c,w,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r);return}for(const i of this.orders)this._processOrder(i,t,e,r,r);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:i,quantities:a,close:l,price:c,activePrice:p}=this._orderArgsParse(t),h=t.direction===ge.long?1:-1;if(a<=0)return;let f=a;if(i&&e){if(n.length){const m=this._processOrders(n,l,f,t.id,t.comment);if(m<=0)return;f=m}const g=l+h*r*this._mintick;if(!this._judgeCapitalEnough(f,g,h))return;this._ocaGroupVerify(f,t.oca_name,t.oca_type),this._calcCurrentOrder({...t,in_price:g,in_index:this._variables.bar_index,in_time:this._variables.time,qty:f,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,h)&&this._addPendingOrders(t,c,f,i,p)}_judgeCapitalEnough(t,e,r){if(t<=0)return!1;const{margin_long:n=0,margin_short:i=0}=this._options;if((n===0||n===100)&&r===1||i===0&&r===-1)return!0;const l=this._getCapital(r,this._options.initial_capital+this._orderProfit+this._totalChangeCapital)-this._freezeCapital;return t*e<=l}_ocaGroupVerify(t,e,r){if(!e||!r||r===un.none)return!1;let n=!1;switch(r){case un.cancel:this._pendingOrders=this._pendingOrders.filter(i=>{if(i.oca_name===e)i.isCancel=!0,n=!0;else return!0});break;case un.reduce:this._pendingOrders=this._pendingOrders.filter(i=>{const{qty:a=0,oca_name:l}=i;if(e===l){const c=a-t;return n=!0,c<=0?(i.isCancel=!0,!1):(i.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,i){let a=r;for(const l of t)if(a=this._processOrder(l,e,a,n,i),a<=0)break;return this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),a}_addPendingOrders(t,e,r,n,i){const a=this._pendingOrders.find(l=>l.id===t.id&&!l.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:i});else{const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:i,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let i=t.limit||0;const{close:a}=this._variables;let l=a,c=!1,p;const h=e===ge.long?1:-1,f=n&&(n-a)*h>0,{backtest_fill_limits_assumption:d=0}=this._options;d>0&&i&&(i-=d*this._mintick*h);const g=i&&(i-a)*h<0;f&&g?(p=n,l=i):f?l=n:g?l=i:c=!0;const y=r||this._calcDefaultQty(l)||1;return{orders:this._orders.filter(w=>w.direction!==e),isMarketPrice:c,activePrice:p,quantities:y,close:a,price:l}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:i,close:a,price:l,activePrice:c}=this._orderArgsParse(t);if(i<=0)return;if(r.length&&n&&e){this._entryOrder(r,a,i,t);return}this._judgeCapitalEnough(i,a,t.direction===ge.long?1:-1)&&this._addPendingEntry(t,l,i,n,c)}_entryOrder(t,e,r,n){const{time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{oca_name:c,oca_type:p,direction:h,comment:f,isMarketPrice:d,id:g}=n,y=h===ge.long?1:-1;if(this._closeOrders(t,e,g,f),r=this._getAvailablePositionSize(r,h),r<=0)return;e=e+l*this._mintick*y;const m={...n,in_price:e,original_qty:r,qty:r,in_index:a,in_time:i,place_order_type:"entry"};if(d){this._calcCurrentOrder(m);return}const{pendingOrders:w,orders:v}=this._getEntryOrders(h),E=w.length+v.length;E&&E>=(this._options.pyramiding||0)||!this._judgeCapitalEnough(r,e,y)||(this._ocaGroupVerify(r,c,p),this._calcCurrentOrder(m))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==ge.all&&n!==e)return 0;if(r===void 0)return t;const i=this._orders.reduce((a,l)=>a+(l.qty||0),0);return i?i+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,i){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(t.direction),c=a.length+l.length,p=a.find(h=>h.id===t.id&&h.place_order_type==="entry");if(p)Object.assign(p,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:i});else if(!c||c<(this._options.pyramiding||1)){const h={...t,in_price:e,isMarketPrice:n,qty:r,active_price:i,place_order_type:"entry"};this._pendingOrders.push(h)}}_closeAllOrders(t,e){const{comment:r}=t,{bar_index:n}=this._variables,i=this._orders.filter(a=>a.in_index!==n);i.length&&(this._closeOrders(i,e,"Close position order",r),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n){for(const i of t)this._closeOrder(i,e,r,n);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_closeOrder(t,e,r,n){const{time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{in_price:c,qty:p=0,direction:h}=t,f=h===ge.long?1:-1;e=e-f*l*this._mintick,t.isDeal=!0;const d=(e-c)*f*p,g={...t,out_price:e,out_id:r,out_index:a,out_time:i,out_comment:n,out_qty:p,profit:d};this._calcPercent(g),this._risk.intradayOrders+=1,this._historyOrder.push(g),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_ordersHandle(){const t=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!t.length)return;const{open:e,low:r,high:n,close:i}=this._variables;for(const a of t){const{stop:l,limit:c,trail_stop_price:p,isMarketPriceLimit:h,isMarketPriceStop:f,direction:d,id:g,out_comment:y,active_price:m,trail_offset:w=0,out_qty:v,comment_loss:E,comment_profit:b,comment_trailing:N}=a;let x=p;const F=d===ge.long?1:-1;let M,S=y;if(h||f?M=e:(c&&r<=c&&n>=c&&(S=b||y,M=c),l&&r<=l&&n>=l&&(M=x?(l-x)*F>0?l:x:l,S=(x===M?N:E)||y)),M)this._processExitOnClose(a,M,{from_entry:g,comment:S,qty:v});else{let I=!1;if(m&&m<=n&&m>=r&&(x=m-w*F*this._mintick,(x-i)*F>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(M=x)),I=!0,a.trail_stop_price=x),x)if((x-e)*F>=0&&!I)M=x;else{const C=(F===1?n:r)-w*F*this._mintick;F===1?x<e&&x>=r&&C>x&&C<i?M=x:C>x?(x=C,C>=i&&(M=C)):x<=n&&r<=x&&(M=x):x>e&&x<=n&&C<x&&C>i?M=x:C<x?(x=C,C<=i&&(M=C)):x<=n&&r<=x&&(M=x),a.trail_stop_price=x}M&&this._processExitOnClose(a,M,{from_entry:g,comment:N||y,qty:v})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of r)switch(n.place_order_type){case"close":this._closeOrderHandle(n);break;case"close_all":this._closeAllOrders(n,this._variables.open);break}for(const n of this._pendingOrders){const{isCancel:i,place_order_type:a}=n;if(i)continue;let l;switch(a){case"entry":l=this._entryOrderHandle(n);break;case"order":l=this._orderOrderHandle(n);break}l&&t.push(l)}for(const n of e){const i=this._exitOrderHandle(n);i&&t.push(i)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),e=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;for(const n of e)switch(n.place_order_type){case"close":this._closeOrderHandle(n,!0);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of t){const{from_entry:i}=n,a=this._orders.filter(l=>!i||l.id===i&&(l.isMarketPriceLimit||l.isMarketPriceStop));for(const l of a)this._processExitOnClose(l,l.limit||l.stop||l.trail_stop_price||r,n)}this._pendingCloseOrders=[]}_entryOrderHandle(t){const{open:e,low:r,high:n}=this._variables,{isMarketPrice:i,qty:a=0,in_price:l,direction:c,active_price:p}=t;if(p&&n>=p&&r<=p)return delete t.active_price,t;let h=l;if(i&&(h=e),h<=n&&h>=r){const f=this._orders.filter(d=>d.direction!==c);this._entryOrder(f,h,a,t)}else return t}_orderOrderHandle(t){const{open:e,low:r,high:n,time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:p=0,in_price:h,direction:f,comment:d,oca_name:g,oca_type:y,active_price:m,id:w}=t;if(m&&n>=m&&r<=m)return delete t.active_price,t;let v=h,E=p;if(c&&(v=e),v<=n&&v>=r){const b=this._orders.filter(x=>x.direction!==f);if(b.length&&(E=this._processOrders(b,v,p,w,d),E<=0))return;const N=f===ge.long?1:-1;this._ocaGroupVerify(E,g,y),this._calcCurrentOrder({...t,in_price:v+N*l*this._mintick,in_index:a,in_time:i,qty:E});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:i=100,comment:a}=t,{bar_index:l}=this._variables,c=this._orders.filter(g=>g.id===r&&g.in_index!==l&&(!g.close_qty||g.close_qty<(g.qty||0)));if(!c.length)return;let p=0;if(n?p=n:(p=c.reduce((g,y)=>g+(y.qty||0),p),p=i/100*p),p<=0)return;const{open:h,close:f}=this._variables;let d=p;for(const g of c){const{qty:y=0}=g;d<y?g.close_qty=d:(g.close_qty=y,d-=y)}this._processOrders(this._options.close_entries_rule==="ANY"?c:this._orders,e?f:h,p,`Close entry(s) order ${r}`,a)}_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)))return t}_exit(t,e){const{profit:r,loss:n,stop:i,limit:a,trail_offset:l,trail_price:c,trail_points:p,from_entry:h="",id:f}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(i)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(p)&&this._isNaN(c))){this._errorListener.addError(ue.strategyExitErr,e,zt.Error);return}const d={...t,place_order_type:"exit"},g=this._orders.filter(w=>(!h||h===w.id)&&!w.hasExit),y=this._pendingOrders.filter(w=>!h||h===w.id);if(g.length){if(!this._ordersToExit(g,d))return}else if(!y.length)return;const m=this._pendingOrders.find(w=>w.id===f);m?Object.assign(m,{...t}):this._pendingOrders.push(d)}_ordersToExit(t,e){const{qty:r,qty_percent:n=100,id:i,comment:a,comment_loss:l,comment_profit:c,comment_trailing:p}=e;let h=r,f=!1;e.comment=a||i;for(const d of t){const{qty:g=0}=d,y=d.direction===ge.long?1:-1;h=r?r>=g?g:r:n/100*g,d.out_qty=h,h<g&&(f=!0),Object.assign(d,{out_comment:a||i,comment_loss:l,comment_profit:c,comment_trailing:p}),!(this._stopProfit(d,y,{...e,qty:h})||this._stopLoss(d,y,{...e,qty:h})||this._trailStopLoss(d,y,{...e,qty:h}))&&(d.place_order_type="exit")}return f}_addExitPendingCloseOrders(t){t.place_order_type="exit";const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r){const{limit:n,profit:i,comment_profit:a,comment:l}=r;let c=n;const{close:p}=this._variables,{in_price:h}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=h+e*i*this._mintick),t.limit=c,c&&(c-p)*e<=0&&(t.isMarketPriceLimit=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=p,f))return this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r){const{stop:n,loss:i,comment_loss:a,comment:l}=r;let c=n;const{close:p}=this._variables,{in_price:h}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=h-e*i*this._mintick),t.stop=c,c&&(c-p)*e>=0&&(t.isMarketPriceStop=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=p,f))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r){const{trail_offset:n,trail_price:i,trail_points:a,comment_trailing:l,comment:c}=r;if(!this._isNaN(n)){const{close:p}=this._variables,{in_price:h}=t,{process_orders_on_close:f}=this._options;let d;if(this._isNaN(i)?this._isNaN(a)||(d=h+a*e*this._mintick):d=i,t.trail_offset=n,d&&(d-p)*e<=0){const g=p-n*e*this._mintick;if((g-p)*e>=0&&(t.trail_stop_price=p,t.isMarketPriceStop=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment}),f))return this._addExitPendingCloseOrders(r),!0;t.trail_stop_price=g}t.active_price=d}}_processExitOnClose(t,e,r){const{qty:n=0,comment:i,id:a}=r,{close_entries_rule:l="FIFO"}=this._options;if(l==="FIFO"){const c=this._processExitOrders(this._orders,e,n,a,i);c&&!c.hasExit?(c.hasExit=!0,Object.assign(t,{trail_stop_price:c.trail_stop_price,stop:c.stop,limit:c.limit,trail_offset:c.trail_offset,active_price:c.active_price})):c&&(t.hasExit=!0)}else t.hasExit=!0,this._processOrders([t],e,n,a,i)}_processExitOrders(t,e,r,n,i){let a=r,l;for(const c of t)if(l=c,a=this._processOrder(c,e,a,n,i),a<=0||!c.hasExit)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),l}_processOrder(t,e,r,n,i){const{time:a,bar_index:l}=this._variables,{slippage:c=0}=this._options,{in_price:p,qty:h=0,max_profit:f=0,trading_loss:d=0,direction:g,commission:y=0,original_qty:m=0}=t,w=g===ge.long?1:-1;if(e=e-w*c*this._mintick,r<h){const v=h-r,E=(e-p)*w*r,b=f/h*r,N=d/h*r;this._calcPercent({...t,out_price:e,out_id:n,out_index:l,out_time:a,out_comment:i,profit:E,out_qty:r,max_profit:b,trading_loss:N});const x=(e-p)*w*v-y*v/m;Object.assign(t,{qty:v,profit:x,max_profit:f-b,trading_loss:d-N,total_profit:this._totalChangeCapital+x}),r=0}else{t.isDeal=!0;const v=(e-p)*w*h;this._calcPercent({...t,out_price:e,out_id:n,out_index:l,out_time:a,out_comment:i,out_qty:h,profit:v}),r-=h}return r}_calcPercent(t){const{commission_value:e}=this._options,{in_price:r,out_qty:n=0,out_price:i=0,original_qty:a=0}=t;let{profit:l=0,max_profit:c=0,trading_loss:p=0,commission:h=0}=t;c=c<0?0:c;const f=r*n;if(this._totalChangeCapital+=l,e){const d=this._getCommission(i,n);this._totalChangeCapital-=d,h=h*n/a+d,l=l-h,Object.assign(t,{commission:h,profit:l,max_profit:c})}Object.assign(t,{total_profit:this._totalChangeCapital,total_profit_percent:l/this._options.initial_capital*100,profit_percent:l/f*100,max_profit_percent:c/f*100,trading_loss_percent:p/f*100}),this._risk.intradayOrders+=1,this._historyOrder.push(t),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,i=t*e;let a=0;switch(n){case Fr.percent:a=i*r/100;break;case Fr.cashPerContract:a=e*r;break;case Fr.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:i=0,trading_loss:a=0}=t;let{profit:l=0}=t;const c=r*n;if(e){const p=this._getCommission(r,n);this._totalChangeCapital-=p,l=l-p,Object.assign(t,{commission:p,profit:l,total_profit:this._totalChangeCapital})}Object.assign(t,{original_qty:n,total_profit_percent:l/this._options.initial_capital*100,profit_percent:l/c*100,max_profit_percent:i/c*100,trading_loss_percent:a/c*100}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders)}_isNaN(t){return t===void 0||isNaN(t)}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}};var rh={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Vt,function(){return function(e,r,n){r.prototype.isBetween=function(i,a,l,c){var p=n(i),h=n(a),f=(c=c||"()")[0]==="(",d=c[1]===")";return(f?this.isAfter(p,l):!this.isBefore(p,l))&&(d?this.isBefore(h,l):!this.isAfter(h,l))||(f?this.isBefore(p,l):!this.isAfter(p,l))&&(d?this.isAfter(h,l):!this.isBefore(h,l))}}})})(rh);var ew=rh.exports,rw=Gt(ew),nh={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Vt,function(){return function(e,r,n){var i=r.prototype,a=function(d){var g,y=d.date,m=d.utc,w={};if(!((g=y)===null||g instanceof Date||g instanceof Array||i.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(y).length)return new Date;var v=m?n.utc():n();Object.keys(y).forEach(function(I){var C,B;w[C=I,B=i.$utils().p(C),B==="date"?"day":B]=y[I]});var E=w.day||(w.year||w.month>=0?1:v.date()),b=w.year||v.year(),N=w.month>=0?w.month:w.year||w.day?0:v.month(),x=w.hour||0,F=w.minute||0,M=w.second||0,S=w.millisecond||0;return m?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return y},l=i.parse;i.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var c=i.set,p=i.add,h=i.subtract,f=function(d,g,y,m){m===void 0&&(m=1);var w=Object.keys(g),v=this;return w.forEach(function(E){v=d.bind(v)(g[E]*m,E)}),v};i.set=function(d,g){return g=g===void 0?d:g,d.constructor.name==="Object"?f.bind(this)(function(y,m){return c.bind(this)(m,y)},g,d):c.bind(this)(d,g)},i.add=function(d,g){return d.constructor.name==="Object"?f.bind(this)(p,d,g):p.bind(this)(d,g)},i.subtract=function(d,g){return d.constructor.name==="Object"?f.bind(this)(p,d,g,-1):h.bind(this)(d,g)}}})})(nh);var nw=nh.exports,iw=Gt(nw),ih={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Vt,function(){var e,r,n=1e3,i=6e4,a=36e5,l=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,p=31536e6,h=2628e6,f=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,d={years:p,months:h,days:l,hours:a,minutes:i,seconds:n,milliseconds:1,weeks:6048e5},g=function(F){return F instanceof N},y=function(F,M,S){return new N(F,S,M.$l)},m=function(F){return r.p(F)+"s"},w=function(F){return F<0},v=function(F){return w(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?w(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,I,C){var B=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),I)return y(S*d[m(I)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(k){B.$d[m(k)]=S[k]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(f);if(L){var U=L.slice(2).map(function(k){return k!=null?Number(k):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(I,C){return I+(S.$d[C]||0)*d[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/p),S%=p,this.$d.months=v(S/h),S%=h,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/i),S%=i,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),I=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var B=b(C,"D"),L=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),k=this.$d.seconds||0;this.$d.milliseconds&&(k+=this.$d.milliseconds/1e3,k=Math.round(1e3*k)/1e3);var W=b(k,"S"),z=S.negative||I.negative||B.negative||L.negative||U.negative||W.negative,K=L.format||U.format||W.format?"T":"",Z=(z?"-":"")+"P"+S.format+I.format+B.format+K+L.format+U.format+W.format;return Z==="P"||Z==="-P"?"P0D":Z},M.toJSON=function(){return this.toISOString()},M.format=function(S){var I=S||"YYYY-MM-DDTHH:mm:ss",C={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(B,L){return L||String(C[B])})},M.as=function(S){return this.$ms/d[m(S)]},M.get=function(S){var I=this.$ms,C=m(S);return C==="milliseconds"?I%=1e3:I=C==="weeks"?v(I/d[C]):this.$d[C],I||0},M.add=function(S,I,C){var B;return B=I?S*d[m(I)]:g(S)?S.$ms:y(S,this).$ms,y(this.$ms+B*(C?-1:1),this)},M.subtract=function(S,I){return this.add(S,I,!0)},M.locale=function(S){var I=this.clone();return I.$l=S,I},M.clone=function(){return y(this.$ms,this)},M.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){e=S,r=S().$utils(),S.duration=function(B,L){var U=S.locale();return y(B,{$l:U},L)},S.isDuration=g;var I=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(B,L){return g(B)?x(this,B,1):I.bind(this)(B,L)},M.prototype.subtract=function(B,L){return g(B)?x(this,B,-1):C.bind(this)(B,L)}}})})(ih);var sw=ih.exports,ow=Gt(sw);ee.extend(Sl),ee.extend(rw),ee.extend(iw),ee.extend(ow);class sh{constructor(t,e,r){R(this,"array");R(this,"color");R(this,"math");R(this,"str");R(this,"map");R(this,"matrix");R(this,"timeframe");R(this,"ta");R(this,"input");R(this,"_variables");R(this,"_cacheData");R(this,"_options");R(this,"_errorListener");R(this,"_plots");R(this,"_plotshapes");R(this,"_plotbars");R(this,"_plotchars");R(this,"_plotarrows");R(this,"_plotcandles");R(this,"_alerts");R(this,"_bgColors");R(this,"_hlines");R(this,"_fills");R(this,"chart");R(this,"line");R(this,"label");R(this,"polyline");R(this,"box");R(this,"table");R(this,"linefill");R(this,"log");R(this,"runtime");R(this,"strategy");R(this,"request");R(this,"syminfo");R(this,"_count",0);var i;const n=((i=t.toString().split(".")[1])==null?void 0:i.length)||5;this._variables=e,this._errorListener=new fw,this.array=new Gp(this._errorListener),this.math=new Hp(n,this._errorListener),this.color=new D1,this.str=new by(this._errorListener,n),this.map=new Ey(this._errorListener),this.timeframe=new Dy(e),this.matrix=new wy(this._errorListener),this.ta=new y1(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 w1(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 xy(e)},this.line=new Zy(e,this._errorListener),this.label=new Ay(e,this._errorListener),this.polyline=new Vy(e,this._errorListener),this.box=new Gy(e,this._errorListener),this.table=new Hy(e,this._errorListener),this.linefill=new Ky(e),this.log=new lw(e),this.runtime=new cw(this._errorListener),this.strategy=new tw(this._variables,this._options,t,this._errorListener),this.request=new aw(this._variables,r),this.syminfo=new uw}get errors(){return this._errorListener.errors}options(t){if(t.length)return this._getDataOfBarindex(t);const e=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let i;if(n.length){i={};for(const v of n)i[v]=[...this._bgColors[v].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,l=this._fills.size?[...this._fills.values()]:void 0,c=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const p=this._plots.size>0?[...this._plots.values()]:void 0,h=this._plotbars.size>0?[...this._plotbars.values()]:void 0,f=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,d=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,m=this._getDraws(),w=this._variables.chart.isUseBgColor;return Object.assign(this._options,{inputs:e,plots:p,draws:m,alerts:r,colors:i,hlines:a,fills:l,logs:c,plotshapes:f,plotarrows:d,plotcandles:g,plotchars:y,plotbars:h,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 d of r)n[d]=[...this._bgColors[d].values()].map(g=>{const y=[];for(const m of t){const w=g.colors[m];w&&y.push(w)}return g.colors=y,g})}const i=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(t,[...this._fills.values()]):void 0,l=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._getDataFromBarindex(t,[...this._plots.values()]),p=this._plotshapes.size>0?this._getDataFromBarindex(t,[...this._plotshapes.values()]):void 0,h=this._getDrawsFromBarindex(t),f=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,draws:h,alerts:e,colors:n,hlines:i,fills:a,logs:l,plotshapes:p,isUseBgColor:f})}_getDataFromBarindex(t,e){return e.map(r=>{const n=[];for(const i of t){const a=r.data[i];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:i,label:a}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),i.data.length&&(l.polylines=i.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}_getDrawsFromBarindex(t){const{line:e,linefill:r,table:n,box:i,polyline:a,label:l}=this._variables,c={};return e.data.length&&(c.lines=e.getValOfBarIndex(t)),r.data.length&&(c.linefills=r.getValOfBarIndex(t)),n.data.length&&(c.tables=n.getValOfBarIndex(t)),i.data.length&&(c.boxes=i.getValOfBarIndex(t)),a.data.length&&(c.polylines=a.getValOfBarIndex(t)),l.data.length&&(c.labels=l.getValOfBarIndex(t)),Object.keys(c).length?c:void 0}updateOptions(t){const{inputs:e}=t;this.input.update(e)}update(t){const{barIndex:e}=t;this.strategy.updateOptions(),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)?(Kp.includes(n)||Zp.includes(n))&&this._errorListener.addError(je(ue.libraryTitleIsKeywordErr,{name:n}),e,zt.Error):this._errorListener.addError(ue.libraryTitleErr,e,zt.Error),this._options.scriptType="library",this._options.library=t}}indicator(t,e){if(!this._variables.bar_index){const{format:r}=t;this._paramVerfiy(r,e,"indicator",[Kt.inherit,Kt.percent,Kt.price,Kt.volume]),this._variables.updateMaxLength(t),this._options.scriptType="indicator",this._options.indicator=t}}_paramVerfiy(t="",e,r,n,i="format"){t&&!n.includes(t)&&this._errorListener.addError(je(ue.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_lineWidthVerify(t,e){const{linewidth:r=1}=t;r<1&&(this._errorListener.addError(Yp.lineWidthWarning,e,zt.Warning),t.linewidth=1)}plot(t,e){const r=["color"];_e(t,r);const{series:n,color:i,...a}=t,{bar_index:l,time:c}=this._variables,p=`plot_${e}`,h=this._plots.get(p),f=(h==null?void 0:h.data)||[],d=n!==void 0&&isNaN(n)?void 0:n;if(f[l]={value:[c,d],itemStyle:{color:i}},this._seriesColorHandle(t,r,h),!h){this._count++,this._lineWidthVerify(a,e),this._paramVerfiy(t.format,e,"plot",[Kt.percent,Kt.price,Kt.volume]);const g=i?[i]:void 0;this._plots.set(p,{editable:!0,...a,colors:g,data:f,id:p,zIndex:this._count})}return{type:"plot",key:p}}plotbar(t,e){const r=["color"];_e(t,r);const{open:n,close:i,low:a,high:l,color:c,...p}=t,{bar_index:h,time:f}=this._variables,d=`plotbar_${e}`,g=this._plotbars.get(d),y=(g==null?void 0:g.data)||[],m=i!==void 0&&isNaN(i)?void 0:i,w=n!==void 0&&isNaN(n)?void 0:n,v=a!==void 0&&isNaN(a)?void 0:a,E=l!==void 0&&isNaN(l)?void 0:l,b=[f,w,m,v,E];if(y[h]={value:b,itemStyle:{color:c}},this._seriesColorHandle(t,r,g),!g){this._count++,this._paramVerfiy(t.format,e,"plotbar",[Kt.percent,Kt.price,Kt.volume]);const N=c?[c]:void 0;this._plotbars.set(d,{editable:!0,...p,colors:N,data:y,id:d,zIndex:this._count})}}_verfiyArgs(t,e,r){const{size:n,format:i,location:a,style:l}=t;this._paramVerfiy(l,r,e,Object.values(or),"style"),this._paramVerfiy(a,r,e,Object.values(an),"location"),this._paramVerfiy(n,r,e,Object.values(er),"size"),this._paramVerfiy(i,r,e,[Kt.percent,Kt.price,Kt.volume],"format")}plotchar(t,e){const r=["color","textcolor"];_e(t,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=t,{bar_index:p,time:h,high:f,low:d}=this._variables,g=`plotchar_${e}`,y=this._plotchars.get(g),m=(y==null?void 0:y.data)||[],w={value:[h,n],itemStyle:{color:i,textcolor:a},low:d,high:f};m[p]=w,this._seriesColorHandle(t,r,y),y||(this._count++,this._verfiyArgs(t,"plotchar",e),this._plotchars.set(g,{editable:!0,...c,location:l,data:m,id:g,zIndex:this._count}))}plotarrow(t,e){const r=["colorup","colordown"];_e(t,r);const{series:n,colorup:i,colordown:a,...l}=t,{bar_index:c,time:p}=this._variables,h=`plotarrow_${e}`,f=this._plotarrows.get(h),d=(f==null?void 0:f.data)||[];d[c]={value:[p,n!==void 0&&isNaN(n)?void 0:n],itemStyle:{colorup:i,colordown:a}},this._seriesColorHandle(t,r,f),f||(this._count++,this._paramVerfiy(t.format,e,"plotarrow",[Kt.percent,Kt.price,Kt.volume]),this._plotarrows.set(h,{editable:!0,...l,data:d,id:h,zIndex:this._count}))}plotshape(t,e){const r=["color","textcolor"];_e(t,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=t,{bar_index:p,time:h,low:f,high:d}=this._variables,g=`plotshape_${e}`,y=this._plotshapes.get(g),m=(y==null?void 0:y.data)||[],w={value:n,color:i,textcolor:a,time:h,low:f,high:d};if(m[p]=w,this._seriesColorHandle(t,r,y),!y){this._count++;const v=i?[i]:void 0;this._verfiyArgs(t,"plotshape",e),this._plotshapes.set(g,{editable:!0,...c,data:m,location:l,id:g,colors:v,zIndex:this._count})}}plotcandle(t,e){const r=["wickcolor","bordercolor","color"];_e(t,r);const{wickcolor:n,bordercolor:i,color:a,close:l,open:c,low:p,high:h,...f}=t,{bar_index:d,time:g}=this._variables,y=`plotcandle_${e}`,m=this._plotcandles.get(y),w=(m==null?void 0:m.data)||[],v=l!==void 0&&isNaN(l)?void 0:l,E=c!==void 0&&isNaN(c)?void 0:c,b=p!==void 0&&isNaN(p)?void 0:p,N=h!==void 0&&isNaN(h)?void 0:h,x=[g,E,v,b,N];w[d]={value:x,wickcolor:n,bordercolor:i,color:a},this._seriesColorHandle(t,r,m),m||(this._count++,this._paramVerfiy(t.format,e,"plotcandle",[Kt.percent,Kt.price,Kt.volume]),this._plotcandles.set(y,{editable:!0,...f,data:w,id:y,zIndex:this._count}))}hline(t,e){const r=`hline_${e}`;_e(t,["color"]),this._verifyDisplay(t.display,"hline",e);const i=t.display&&!t.display.length?Ye.none:Ye.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(t,e),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:i,...t,zIndex:this._count})),{type:"hline",key:r}}fill(t,e){var S,I,C,B,L,U,k,W,z,K;const r=["color","top_color","bottom_color"];_e(t,r);const{color:n,top_color:i,bottom_color:a,seriesColors:l,hline1:c,hline2:p,plot1:h,plot2:f,top_value:d,bottom_value:g,...y}=t,{bar_index:m,time:w}=this._variables,v=`fill_${e}`,E=this._fills.get(v),b=(E==null?void 0:E.data)||[];this._verifyDisplay(t.display,"fill",e);const N=t.display&&!t.display.length?Ye.none:Ye.all;let x,F,M="plot";if(c&&p)x=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,F=(I=this._hlines.get(p==null?void 0:p.key))==null?void 0:I.price,M="hline";else{const Z=((C=this._plots.get(h==null?void 0:h.key))==null?void 0:C.data)||[],X=((B=this._plots.get(f==null?void 0:f.key))==null?void 0:B.data)||[];x=(U=(L=Z[m])==null?void 0:L.value)==null?void 0:U[1],F=(W=(k=X[m])==null?void 0:k.value)==null?void 0:W[1]}if(b[m]={time:w,color:n,top_color:i,bottom_color:a,plot1:x,plot2:F,top_value:d,bottom_value:g},this._seriesColorHandle(t,r,E),!E){this._count++;const Z=((z=this._options.indicator)==null?void 0:z.explicit_plot_zorder)||((K=this._options.strategy)==null?void 0:K.explicit_plot_zorder),X=n?[n]:void 0,Q=i?[i]:void 0,ct=a?[a]:void 0;this._fills.set(v,{id:v,colors:X,top_colors:Q,bottom_colors:ct,display:N,data:b,type:M,editable:!0,fillgaps:!1,hline1:c,hline2:p,plot1:h,plot2:f,...y,zIndex:Z?this._count:void 0})}}alert({message:t,freq:e=qr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:i,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l]||{},p=c.barIndex;if(this._paramVerfiy(e,r,"alert",[qr.freqAll,qr.freqOncePerBar,qr.freqOncePerBarClose]),e===qr.freqOncePerBar&&n===p){this._alerts.delete(l);return}this._cacheData[l]=c;const h={message:t,freq:e,id:l,type:"alert"};if(i){e!==qr.freqOncePerBarClose&&this._alerts.set(l,h),c.barIndex=n;return}if(!i&&e===qr.freqOncePerBarClose&&n===p&&a===n-1){this._alerts.set(l,h),c.barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:i}=this._variables,a=`alertcondition_${n}`;i&&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=Xf.all,e,r){t.length&&t.length<4&&this._errorListener.addError(je(ue.displayErr,{func:e,values:"[display.none, display.all]"}),r,zt.Error)}_setColors(t,e,r){_e(t,["color"]);const{color:i,...a}=t;this._verifyDisplay(a.display,e,r);const l=t.display&&!t.display.length?Ye.none:Ye.all,{bar_index:c,time:p}=this._variables,h=`${e}_${r}`;this._bgColors[e]||(this._bgColors[e]=new Map);const f=this._bgColors[e].get(h),d=(f==null?void 0:f.colors)||[],g=(f==null?void 0:f.setColors)||[];i&&!g.includes(i)&&g.push(i),d[c]={color:i,time:p},f||this._bgColors[e].set(h,{...a,display:l,colors:d,setColors:g,id:h})}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},i){return this._timeHandle(this._variables.time,i,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},i){return this._variables.time_close&&this._timeHandle(this._variables.time_close,i,t,e,r,n)}timestamp(t){const{dateString:e,timezone:r,year:n,month:i,day:a,hour:l=0,minute:c=0,second:p=0}=t;if(e)return ee(e).utc(!/GMT|UTC/.test(e)).valueOf();let h=i-1,f=n;if(h<0){const g=Math.ceil(Math.abs(h/12));h=12*g+h,f=n-g}let d=ee({year:f,month:h,day:a,hour:l,minute:c,second:p});return r&&(d=zr(d.utc(!0).valueOf(),r)),d.utc(!0).valueOf()}weekofyear({time:t,timezone:e}){return zr(t,e).week()}year({time:t,timezone:e}){return zr(t,e).year()}second({time:t,timezone:e}){return zr(t,e).second()}month({time:t,timezone:e}){return zr(t,e).month()+1}minute({time:t,timezone:e}){return zr(t,e).minute()}hour({time:t,timezone:e}){return zr(t,e).hour()}dayofweek({time:t,timezone:e}){return zr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return zr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Xr(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,i,a=0){const l=r||this._variables.timeframe.period,c=Xr(l),p=Xr(this._variables.timeframe.period);let h;if(c<=p)h=t;else{const f=`time_${e}`,d=this._cacheData[f];if(d)d.currentTime+c*1e3-d.offset<=t?(h=t,this._cacheData[f]={currentTime:t,offset:0}):h=d;else{const g=this._calcTimeOffset(t,l);this._cacheData[f]={currentTime:t,offset:g},h=t}}if(n){const{timePeriods:f,weeks:d}=this._parserSession(n,e),g=ee(t).format("YYYY-MM-DD"),y=h;h=void 0;for(const w of f){const[v,E]=w;if(ee(t).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")){ee(y).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")?h=y:h=ee(`${g} ${v}`).valueOf();break}}const m=this._variables.dayofweek;h&&!d.includes(m)&&(h=void 0)}return i&&(h=h&&zr(h,i).valueOf()),h&&h-a*p*1e3}_seriesColorHandle(t,e,r){var n;if(r&&e!=null&&e.length)for(const i of e){if((n=r.gradientColorKeys)!=null&&n.includes(i))continue;const a=t[i];if(!a)continue;const l=r[`${i}s`]||[];l.includes(a)||(l.push(a),r[`${i}s`]=l,l.length>5&&(r[`${i}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(i)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const p=parseInt(c,10);if(p<1||p>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,zt.Error);return}return p});return{timePeriods:n.split(",").map(c=>{c===""||c===fi.regular?c="0930-1500":c===fi.extended&&(c="1500-1830");const p=c.split("-");return p.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,e,zt.Error),[]):[this._processTime(p[0],e),this._processTime(p[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,zt.Error);return}return`${r}:${n}`}}class aw{constructor(t,e){R(this,"_variables");R(this,"_scriptId");R(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,i=this._getRequestData(t,e);if(r!=null&&r.has(e)){const c=r.get(e);return this._runScripts(c,e,!1,n,i)}const a=this._parseExprCode(t),l=this._runScripts(a,e,!0,n,i);return r==null||r.set(e,a),l}_parseExprCode(t){let{expression:e,paramsExpr:r=[]}=t,n=[],i=1;e=Tl(e);const a=JSON.parse(e),l=a.pop();let c=(l==null?void 0:l.memberCodes)||{},p=(l==null?void 0:l.depends)||[];if(!p.length)return`return ${l==null?void 0:l.code}`;let h=[],f=[];const d=[];if(this._getDependCodes(p,a,n,h,f,d),f.length){const m=r.length;let w=[];for(let v=m-1;v>=0;v--){const E=r[v];let b=JSON.parse(Tl(E));const N=[];i!==0&&f.length&&(w.unshift("{"),i++),b=b.map(S=>{const{scope:I,code:C,varNames:B,dependSelf:L}=S;return I===2&&!N.includes(B)&&!L&&(S.code=`let ${C}`),B&&N.push(...B.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const x=[],F=[];let M=f.map(S=>({...S,isArg:!1,isPreArg:!0}));f=[],this._getDependCodes(M,b,F,h,f,x),w.unshift(...F,...x),n=w.concat(n),w=[]}}for(n.push(`return ${l==null?void 0:l.code}`);i>1;)n.push("}"),i--;n=h.concat(n),n.push(...d);let g=n.join(`
|
63
63
|
`);const y=[];for(const m of Object.keys(c))g.includes(`$_var.getCacheData("${m}"`)&&y.push(c[m]);return y.length&&(g=`${y.join(`
|
64
64
|
`)}
|
65
|
-
${g}`),g}_getRequestData(t,e){let{symbol:r,timeframe:n,calc_bars_count:i}=t;const a=self.workerStorage.get(`request_${this._scriptId}_data`),l=`${r}--${n}`;if(a!=null&&a.has(l)){const{index:c=0,periodStamp:p=Xr(this._variables.__period)*1e3}=this._cacheData.get(e)||{},h=(a.get(l)||[]).slice(c),f=this._variables.time,d=p+f;for(const[g,y]of h.entries()){const{timestamp:m,close:w,open:v,high:E,low:b,volume:N}=y;let x=m*1e3;if(x>=d){this._cacheData.set(e,{index:g,periodStamp:p});return}if(x>=f)return this._cacheData.set(e,{index:g+1,periodStamp:p}),{close:Number(w),open:Number(v),high:Number(E),low:Number(b),timestamp:m,volume:N}}this._cacheData.set(e,{index:h.length,periodStamp:p})}else{const c=self.workerStorage.get(`request_${this._scriptId}_list`);(c==null?void 0:c.get(l))||c==null||c.set(l,{id:l,calc_bars_count:i,symbol:r,timeframe:n})}}_getDependCodes(t,e,r,n,i,a){for(const l of t){if(!l.isArg){const c=e.filter(h=>{var f;return(f=h==null?void 0:h.depends)==null?void 0:f.some(d=>d.name===l.name&&d.scope===l.scope&&d.isAgainAssign)});for(const h of c){const{code:f,depends:d}=h;if(!r.includes(f)&&(r.unshift(f),d!=null&&d.length)){for(const g of d)g.memberCode&&a.push(g.memberCode);this._getDependCodes(d,e,r,n,i,a)}}const p=e.find(h=>{var f;return((f=h.varNames)==null?void 0:f.split(", ").includes(l.name))&&(!l.isPreArg||l.isPreArg&&h.methodName===l.functionName)||h.funcName===l.name});if(p){const{code:h,depends:f}=p,d=r.findIndex(g=>g===h);if(d!==-1&&r.splice(d,1),r.unshift(h),f!=null&&f.length){for(const g of f)g.memberCode&&a.push(g.memberCode);this._getDependCodes(f,e,r,n,i,a)}continue}}i.some(c=>c.name===l.name)||i.push(l)}}_runScripts(t,e,r,n,i){const a=`${this._scriptId}_${e}`;let{builtInGather:l,buildinConstants:c,buildInFunctions:p,tradingvueFunc:h}=self.workerStorage.get(a)||{};return r&&(l=new oh(a),c=new Qf,p=new sh(this._variables.mintick||1e-5,l,this._scriptId),h=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),self.workerStorage.set(a,{builtInGather:l,buildinConstants:c,buildInFunctions:p,tradingvueFunc:h})),h(l,c,p,n||[],e)}}let uw=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 lw{constructor(t){R(this,"_logs");R(this,"_variables");R(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:i,formatString:a}=t,{time:l,bar_index:c}=this._variables;let p=i;a&&Array.isArray(e)&&e.length&&(p=a.replace(/{(\d+)}/g,(h,f)=>{let d=e[f];return typeof d=="number"&&(d=this._intlFormat.format(parseFloat(d.toFixed(3)))),typeof d=="object"&&(d.isArray?d=JSON.stringify(d._value):d=d.toString()),d!==void 0?d:h})),p&&this._logs.push({message:`[${ee(l).format()}]: ${p}`,time:l,barIndex:c,type:r})}}class cw{constructor(t){R(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,zt.Error)}}class fw{constructor(){R(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Jr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[i,a]=e.split("_").slice(-2),l=this._errors.get(e),c={message:t,endLineNumber:Number(i),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(i),type:r};l?l.push(c):this._errors.set(e,[c])}}class hw{constructor(){R(this,"_isMarketOpen");R(this,"_currentBarIndex");R(this,"_totalBarIndex");R(this,"_isRealTimeBar");R(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}}class pw{constructor(t){R(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=Xr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=Xr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class dw{constructor(t){R(this,"_orders");R(this,"_historyOrders");R(this,"_options");R(this,"_max_contracts_held_all",0);R(this,"_max_contracts_held_long",0);R(this,"_max_contracts_held_short",0);R(this,"_max_drawdown",0);R(this,"_max_runup",0);R(this,"_max_runup_percent",0);R(this,"_max_drawdown_percent",0);R(this,"_variables");R(this,"_netprofit",0);R(this,"_eventrades",0);R(this,"_avg_trade_percent");R(this,"_closedtrades",0);R(this,"_losstrades",0);R(this,"_grossloss",0);R(this,"_grossloss_percent",0);R(this,"_grossprofit",0);R(this,"_grossprofit_percent",0);R(this,"_wintrades",0);R(this,"_opentrades_capital_held",0);R(this,"_position_avg_price",0);R(this,"_position_size",0);this._orders=[],this._historyOrders=[],this._variables=t}update(){this._calcMaxDrawdownAndMaxRunup()}_calcMaxDrawdownAndMaxRunup(){let t=0,e=0;const{high:r,low:n}=this._variables;for(const p of this._orders){const{in_price:h,qty:f=0,commission:d=0,original_qty:g=0,direction:y}=p,m=y===ge.long?1:-1,w=(r-h)*f,v=(n-h)*f,E=m===1?w:-v,b=m===1?-v:w;t+=b+d*f/g,e+=E+d*f/g}const[i,a]=this._historyOrders.reduce((p,h)=>{let[f,d]=p;const{profit:g=0,commission:y=0}=h;return f+=g,d+=g-y,[f,d]},[0,0]);t-=i,e+=a;const l=t/(this.initial_capital+this.netprofit)*100;this._max_drawdown<t&&(this._max_drawdown=t),l>this._max_drawdown_percent&&(this._max_drawdown_percent=l);const c=e/(this.initial_capital+this.netprofit)*100;e>this._max_runup&&(this._max_runup=e),c>this._max_runup_percent&&(this._max_runup_percent=c)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t)return;const[e,r,n,i,a,l]=this._orders.reduce(([c,p,h,f,d,g],y)=>{const{direction:m,qty:w=0,in_price:v}=y;return m===ge.long?(c+=w,p+=w,g+=w):(c+=w,h+=w,g-=w),f+=w*v,d+=v,[c,p,h,f,d,g]},[0,0,0,0,0,0]);this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=i,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,i,a,l,c]=this._historyOrders.reduce((p,h)=>{let[f,d,g,y,m,w]=p;const{profit:v=0,profit_percent:E=0}=h;return f+=v,d+=E,v<0?(g+=v,y+=E):(m+=v,w+=E),[f,d,g,y,m,w]},[0,0,0,0,0,0]);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r,this._grossloss=i,this._grossloss_percent=a,this._grossprofit=l,this._grossprofit_percent=c,this._eventrades=this._historyOrders.filter(p=>p.profit===0).length,this._losstrades=this._historyOrders.filter(p=>(p.profit||0)<0).length,this._wintrades=this._historyOrders.filter(p=>(p.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this.losstrades;return t?Math.abs(this.grossloss/t):void 0}get avg_losing_trade_percent(){const t=this.losstrades;return t?Math.abs(this.grossloss_percent/t):void 0}get avg_trade(){if(this.closedtrades)return Math.abs(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._orders.reduce((t,e)=>{const{profit:r=0}=e;return t+r},0)}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this.wintrades;return t?Math.abs(this.grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this.wintrades;return t?Math.abs(this.grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss_percent}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit_percent}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:i=0}=this._options,a=this._orders[0].direction===ge.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[p,h]=this._orders.reduce((f,d)=>{let[g,y]=f;const{in_price:m,qty:w=0,original_qty:v=0}=d,E=m*w;if(g+=E,i){let b=0;switch(n){case Fr.percent:b=(E+w*c)*i/100;break;case Fr.cashPerContract:b=w*i*2;break;case Fr.cashPerOrder:b=w/v*i+i;break}y+=b}return[g,y]},[0,0]);return(p-(t+this.netprofit-h))*a/this.position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this.netprofit/this.initial_capital*100}get openprofit_percent(){return this.openprofit/(this.initial_capital+this.netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}}class _w{constructor(t){R(this,"_preAccdist");R(this,"_preNvi");R(this,"_prePvi");R(this,"_preObv");R(this,"_prePvt");R(this,"_preWad");R(this,"_preVwap");R(this,"_preValue");R(this,"_currentData");R(this,"_preData");R(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 i=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=i),this._preValue.accdist=i,i}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,i=(2*t-r-e)/((r-e)*n);return this._preValue.iii=i,i}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:i}=this._currentData,a=(t-i)/(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 i=Math.max(e,n),a=Math.min(r,n),l=t-n,p=(l>0?t-a:l<0?t-i:0)+this._preWad;return!this.isRealTime&&(this._preWad=p),this._preValue.wad=p,p}get vwap(){var h,f;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:i}=this._preVwap;if(((f=(h=self.workerStorage)==null?void 0:h.get(this._id))==null?void 0:f.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(i=!0,r=n=0),!i)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:i});const p=l/c;return this._preValue.vwap=p,p}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class mw{constructor(){R(this,"_period");R(this,"_multiplier");R(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=ys(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 gw{constructor(t){R(this,"_variables");R(this,"_bgColor");R(this,"_fgColor");R(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,i;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?i=parseInt(a,16)/255:i=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,i=a[3]||1}return{r:e,g:r,b:n,a:i}}_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 vw{constructor(t){R(this,"_variables");this._variables=t}get basecurrency(){return""}get country(){}get currency(){return"CNY"}get description(){return""}get employees(){return 100}get expiration_date(){}get industry(){}get minmove(){}get mintick(){return this._variables.mintick}get pointvalue(){}get prefix(){}get pricescale(){}get recommendations_buy(){}get recommendations_buy_strong(){}get recommendations_date(){}get recommendations_hold(){}get recommendations_sell(){}get recommendations_sell_strong(){}get recommendations_total(){}get root(){return""}get sector(){}get session(){return fi.regular}get shareholders(){}get shares_outstanding_float(){}get shares_outstanding_total(){}get target_price_average(){}get target_price_date(){}get target_price_estimates(){}get target_price_high(){}get target_price_low(){}get target_price_median(){}get ticker(){}get tickerid(){}get timezone(){}get type(){}get volumetype(){return"n/a"}}class yw{constructor(t){R(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class ww{constructor(t){R(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}ee.extend(Wp),ee.extend(Sl),ee.extend(kp);class oh{constructor(t){R(this,"_cacheData");R(this,"_barIndex");R(this,"_isRealTimeBar");R(this,"_barstate");R(this,"_priceVariables");R(this,"_lastBarIndex");R(this,"_currentBarTime");R(this,"_lastBarTime");R(this,"_period");R(this,"_offsetTime");R(this,"_timeframe");R(this,"_ta");R(this,"_polyline");R(this,"_label");R(this,"_line");R(this,"_linefill");R(this,"_box");R(this,"_table");R(this,"_strategy");R(this,"_session");R(this,"syminfo");R(this,"chart");R(this,"earnings");R(this,"dividends");R(this,"_timeTradingday");R(this,"_mintick");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new hw,this._timeframe=new mw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new _w(t),this._polyline=new Fi,this._label=new Fi,this._line=new Fi,this._linefill=new Fi,this._box=new Fi,this._table=new Fi(1),this._strategy=new dw(this),this._session=new pw(this),this.syminfo=new vw(this),this.chart=new gw(this),this.earnings=new ww(this),this.dividends=new yw(this)}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return ee(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return ee(this._currentBarTime).minute()}get second(){return ee(this._currentBarTime).second()}get month(){return ee(this._currentBarTime).month()+1}get year(){return ee(this._currentBarTime).year()}get dayofweek(){return ee(this._currentBarTime).day()+1}get dayofmonth(){return ee(this._currentBarTime).date()}get weekofyear(){return ee(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=ys(this._period);return this._isRealTimeBar?void 0:ee(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:i}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),i&&this._polyline.setMaxLen(i)}getTimeTradingday(t,e){const[r,n]=ys(e),i=ee(t);return["M","w","y","d"].includes(n)?i.valueOf():(i.subtract(this._offsetTime,"h"),i.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){const{interval:e="1D",offsetTime:r=5,mintick:n,chart:i}=t;this._period=e,this._mintick=n,this._offsetTime=r,this._timeframe.update(e),this.chart.updateOptions(i)}updateData(t){const{barIndex:e,c:r,o:n,h:i,l:a,volume:l,time:c,lastBarIndex:p,lastBarTime:h,complete:f,time_tradingday:d}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(i),low:Number(a),volume:Number(l)},this._isRealTimeBar=f,e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._timeTradingday=d,this._currentBarTime=c*1e3,this._lastBarIndex=p,this._barIndex=e,this._lastBarTime=h*1e3,this._barstate.update(e,p,f,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){const n=this.setCacheData(t,r);return n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};return r.barIndex>this._barIndex||(r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e),r.barIndex=this._barIndex,this._cacheData[t]=r),r.data}getTypeInstance(t,e){return new Rp(t,e)}getVarValue(t,e,r,n){const i=`${t}_${e}`;if(n==="var"&&this._cacheData.varData.hasOwnProperty(i))return this._cacheData.varData[i];if(n==="varip"&&this._cacheData.varipData.hasOwnProperty(i))return this._cacheData.varipData[i];if(!(arguments.length<=3))return this.setVarValue(t,e,r,n)}setVarValue(t,e,r,n){const i=`${t}_${e}`;let a;switch(typeof r=="object"&&r&&(n="var",a=r.varipKeys),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[i]=r,a&&a.length)for(const l of a)this._cacheData.varData[i][l]=r[l]}else this._cacheData.varData[i]=r;break;case"varip":this._cacheData.varipData[i]=r;break}return r}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Jr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case ao.name:case th.name:case co.name:case eh.name:case uo.name:case lo.name:t==null||t.delete();break}}}class Fi{constructor(t=50){R(this,"_all");R(this,"_allInstance");R(this,"_pseudoArrayAll");R(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Qt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const i=r.filter(a=>a.endsWith(`_${n}`));for(const a of i){const l=this._all.get(a);l&&e.push(l)}}return e.length?e:void 0}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}/**
|
65
|
+
${g}`),g}_getRequestData(t,e){let{symbol:r,timeframe:n,calc_bars_count:i}=t;const a=self.workerStorage.get(`request_${this._scriptId}_data`),l=`${r}--${n}`;if(a!=null&&a.has(l)){const{index:c=0,periodStamp:p=Xr(this._variables.__period)*1e3}=this._cacheData.get(e)||{},h=(a.get(l)||[]).slice(c),f=this._variables.time,d=p+f;for(const[g,y]of h.entries()){const{timestamp:m,close:w,open:v,high:E,low:b,volume:N}=y;let x=m*1e3;if(x>=d){this._cacheData.set(e,{index:g,periodStamp:p});return}if(x>=f)return this._cacheData.set(e,{index:g+1,periodStamp:p}),{close:Number(w),open:Number(v),high:Number(E),low:Number(b),timestamp:m,volume:N}}this._cacheData.set(e,{index:h.length,periodStamp:p})}else{const c=self.workerStorage.get(`request_${this._scriptId}_list`);(c==null?void 0:c.get(l))||c==null||c.set(l,{id:l,calc_bars_count:i,symbol:r,timeframe:n})}}_getDependCodes(t,e,r,n,i,a){for(const l of t){if(!l.isArg){const c=e.filter(h=>{var f;return(f=h==null?void 0:h.depends)==null?void 0:f.some(d=>d.name===l.name&&d.scope===l.scope&&d.isAgainAssign)});for(const h of c){const{code:f,depends:d}=h;if(!r.includes(f)&&(r.unshift(f),d!=null&&d.length)){for(const g of d)g.memberCode&&a.push(g.memberCode);this._getDependCodes(d,e,r,n,i,a)}}const p=e.find(h=>{var f;return((f=h.varNames)==null?void 0:f.split(", ").includes(l.name))&&(!l.isPreArg||l.isPreArg&&h.methodName===l.functionName)||h.funcName===l.name});if(p){const{code:h,depends:f}=p,d=r.findIndex(g=>g===h);if(d!==-1&&r.splice(d,1),r.unshift(h),f!=null&&f.length){for(const g of f)g.memberCode&&a.push(g.memberCode);this._getDependCodes(f,e,r,n,i,a)}continue}}i.some(c=>c.name===l.name)||i.push(l)}}_runScripts(t,e,r,n,i){const a=`${this._scriptId}_${e}`;let{builtInGather:l,buildinConstants:c,buildInFunctions:p,tradingvueFunc:h}=self.workerStorage.get(a)||{};return r&&(l=new oh(a),c=new Qf,p=new sh(this._variables.mintick||1e-5,l,this._scriptId),h=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),self.workerStorage.set(a,{builtInGather:l,buildinConstants:c,buildInFunctions:p,tradingvueFunc:h})),h(l,c,p,n||[],e)}}let uw=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 lw{constructor(t){R(this,"_logs");R(this,"_variables");R(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:i,formatString:a}=t,{time:l,bar_index:c}=this._variables;let p=i;a&&Array.isArray(e)&&e.length&&(p=a.replace(/{(\d+)}/g,(h,f)=>{let d=e[f];return typeof d=="number"&&(d=this._intlFormat.format(parseFloat(d.toFixed(3)))),typeof d=="object"&&(d.isArray?d=JSON.stringify(d._value):d=d.toString()),d!==void 0?d:h})),p&&this._logs.push({message:`[${ee(l).format()}]: ${p}`,time:l,barIndex:c,type:r})}}class cw{constructor(t){R(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,zt.Error)}}class fw{constructor(){R(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Jr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[i,a]=e.split("_").slice(-2),l=this._errors.get(e),c={message:t,endLineNumber:Number(i),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(i),type:r};l?l.push(c):this._errors.set(e,[c])}}class hw{constructor(){R(this,"_isMarketOpen");R(this,"_currentBarIndex");R(this,"_totalBarIndex");R(this,"_isRealTimeBar");R(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}}class pw{constructor(t){R(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=Xr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=Xr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class dw{constructor(t){R(this,"_orders");R(this,"_historyOrders");R(this,"_options");R(this,"_max_contracts_held_all",0);R(this,"_max_contracts_held_long",0);R(this,"_max_contracts_held_short",0);R(this,"_max_drawdown",0);R(this,"_max_runup",0);R(this,"_max_runup_percent",0);R(this,"_max_drawdown_percent",0);R(this,"_variables");R(this,"_netprofit",0);R(this,"_eventrades",0);R(this,"_avg_trade_percent");R(this,"_closedtrades",0);R(this,"_losstrades",0);R(this,"_grossloss",0);R(this,"_grossloss_percent",0);R(this,"_grossprofit",0);R(this,"_grossprofit_percent",0);R(this,"_wintrades",0);R(this,"_opentrades_capital_held",0);R(this,"_position_avg_price",0);R(this,"_position_size",0);this._orders=[],this._historyOrders=[],this._variables=t}update(){this._calcMaxDrawdownAndMaxRunup()}_calcMaxDrawdownAndMaxRunup(){let t=0,e=0;const{high:r,low:n}=this._variables;for(const p of this._orders){const{in_price:h,qty:f=0,commission:d=0,original_qty:g=0,direction:y}=p,m=y===ge.long?1:-1,w=(r-h)*f,v=(n-h)*f,E=m===1?w:-v,b=m===1?-v:w;t+=b+d*f/g,e+=E+d*f/g}const[i,a]=this._historyOrders.reduce((p,h)=>{let[f,d]=p;const{profit:g=0,commission:y=0}=h;return f+=g,d+=g-y,[f,d]},[0,0]);t-=i,e+=a;const l=t/(this.initial_capital+this.netprofit)*100;this._max_drawdown<t&&(this._max_drawdown=t),l>this._max_drawdown_percent&&(this._max_drawdown_percent=l);const c=e/(this.initial_capital+this.netprofit)*100;e>this._max_runup&&(this._max_runup=e),c>this._max_runup_percent&&(this._max_runup_percent=c)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t)return;const[e,r,n,i,a,l]=this._orders.reduce(([c,p,h,f,d,g],y)=>{const{direction:m,qty:w=0,in_price:v}=y;return m===ge.long?(c+=w,p+=w,g+=w):(c+=w,h+=w,g-=w),f+=w*v,d+=v,[c,p,h,f,d,g]},[0,0,0,0,0,0]);this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=i,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,i,a,l,c]=this._historyOrders.reduce((p,h)=>{let[f,d,g,y,m,w]=p;const{profit:v=0,profit_percent:E=0}=h;return f+=v,d+=E,v<0?(g+=v,y+=E):(m+=v,w+=E),[f,d,g,y,m,w]},[0,0,0,0,0,0]);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r,this._grossloss=i,this._grossloss_percent=a,this._grossprofit=l,this._grossprofit_percent=c,this._eventrades=this._historyOrders.filter(p=>p.profit===0).length,this._losstrades=this._historyOrders.filter(p=>(p.profit||0)<0).length,this._wintrades=this._historyOrders.filter(p=>(p.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this.losstrades;return t?Math.abs(this.grossloss/t):void 0}get avg_losing_trade_percent(){const t=this.losstrades;return t?Math.abs(this.grossloss_percent/t):void 0}get avg_trade(){if(this.closedtrades)return Math.abs(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._orders.reduce((t,e)=>{const{profit:r=0}=e;return t+r},0)}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this.wintrades;return t?Math.abs(this.grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this.wintrades;return t?Math.abs(this.grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss_percent}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit_percent}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:i=0}=this._options,a=this._orders[0].direction===ge.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[p,h]=this._orders.reduce((f,d)=>{let[g,y]=f;const{in_price:m,qty:w=0,original_qty:v=0}=d,E=m*w;if(g+=E,i){let b=0;switch(n){case Fr.percent:b=(E+w*c)*i/100;break;case Fr.cashPerContract:b=w*i*2;break;case Fr.cashPerOrder:b=w/v*i+i;break}y+=b}return[g,y]},[0,0]);return(p-(t+this.netprofit-h))*a/this.position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this.netprofit/this.initial_capital*100}get openprofit_percent(){return this.openprofit/(this.initial_capital+this.netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}}class _w{constructor(t){R(this,"_preAccdist");R(this,"_preNvi");R(this,"_prePvi");R(this,"_preObv");R(this,"_prePvt");R(this,"_preWad");R(this,"_preVwap");R(this,"_preValue");R(this,"_currentData");R(this,"_preData");R(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 i=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=i),this._preValue.accdist=i,i}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,i=(2*t-r-e)/((r-e)*n);return this._preValue.iii=i,i}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:i}=this._currentData,a=(t-i)/(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 i=Math.max(e,n),a=Math.min(r,n),l=t-n,p=(l>0?t-a:l<0?t-i:0)+this._preWad;return!this.isRealTime&&(this._preWad=p),this._preValue.wad=p,p}get vwap(){var h,f;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:i}=this._preVwap;if(((f=(h=self.workerStorage)==null?void 0:h.get(this._id))==null?void 0:f.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(i=!0,r=n=0),!i)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:i});const p=l/c;return this._preValue.vwap=p,p}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class mw{constructor(){R(this,"_period");R(this,"_multiplier");R(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=ys(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 gw{constructor(t){R(this,"_variables");R(this,"_bgColor");R(this,"_fgColor");R(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,i;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?i=parseInt(a,16)/255:i=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,i=a[3]||1}return{r:e,g:r,b:n,a:i}}_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 vw{constructor(t){R(this,"_variables");this._variables=t}get basecurrency(){return""}get country(){}get currency(){return"CNY"}get description(){return""}get employees(){return 100}get expiration_date(){}get industry(){}get minmove(){}get mintick(){return this._variables.mintick}get pointvalue(){}get prefix(){}get pricescale(){}get recommendations_buy(){}get recommendations_buy_strong(){}get recommendations_date(){}get recommendations_hold(){}get recommendations_sell(){}get recommendations_sell_strong(){}get recommendations_total(){}get root(){return""}get sector(){}get session(){return fi.regular}get shareholders(){}get shares_outstanding_float(){}get shares_outstanding_total(){}get target_price_average(){}get target_price_date(){}get target_price_estimates(){}get target_price_high(){}get target_price_low(){}get target_price_median(){}get ticker(){}get tickerid(){}get timezone(){}get type(){}get volumetype(){return"n/a"}}class yw{constructor(t){R(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class ww{constructor(t){R(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}ee.extend(Wp),ee.extend(Sl),ee.extend(kp);class oh{constructor(t){R(this,"_cacheData");R(this,"_barIndex");R(this,"_isRealTimeBar");R(this,"_barstate");R(this,"_priceVariables");R(this,"_lastBarIndex");R(this,"_currentBarTime");R(this,"_lastBarTime");R(this,"_period");R(this,"_offsetTime");R(this,"_timeframe");R(this,"_ta");R(this,"_polyline");R(this,"_label");R(this,"_line");R(this,"_linefill");R(this,"_box");R(this,"_table");R(this,"_strategy");R(this,"_session");R(this,"syminfo");R(this,"chart");R(this,"earnings");R(this,"dividends");R(this,"_timeTradingday");R(this,"_mintick");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new hw,this._timeframe=new mw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new _w(t),this._polyline=new Fi,this._label=new Fi,this._line=new Fi,this._linefill=new Fi,this._box=new Fi,this._table=new Fi(1),this._strategy=new dw(this),this._session=new pw(this),this.syminfo=new vw(this),this.chart=new gw(this),this.earnings=new ww(this),this.dividends=new yw(this)}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return ee(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return ee(this._currentBarTime).minute()}get second(){return ee(this._currentBarTime).second()}get month(){return ee(this._currentBarTime).month()+1}get year(){return ee(this._currentBarTime).year()}get dayofweek(){return ee(this._currentBarTime).day()+1}get dayofmonth(){return ee(this._currentBarTime).date()}get weekofyear(){return ee(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=ys(this._period);return this._isRealTimeBar?void 0:ee(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:i}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),i&&this._polyline.setMaxLen(i)}getTimeTradingday(t,e){const[r,n]=ys(e),i=ee(t);return["M","w","y","d"].includes(n)?i.valueOf():(i.subtract(this._offsetTime,"h"),i.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){const{interval:e="1D",offsetTime:r=5,mintick:n,chart:i}=t;this._period=e,this._mintick=n,this._offsetTime=r,this._timeframe.update(e),this.chart.updateOptions(i)}updateData(t){const{barIndex:e,c:r,o:n,h:i,l:a,volume:l,time:c,lastBarIndex:p,lastBarTime:h,complete:f,time_tradingday:d}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(i),low:Number(a),volume:Number(l)},this._isRealTimeBar=f,e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._timeTradingday=d,this._currentBarTime=c*1e3,this._lastBarIndex=p,this._barIndex=e,this._lastBarTime=h*1e3,this._barstate.update(e,p,f,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){const n=this.setCacheData(t,r);return n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};return r.barIndex>this._barIndex||(r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e),r.barIndex=this._barIndex,this._cacheData[t]=r),r.data}getTypeInstance(t,e){return new Rp(t,e)}verifyVarAndVarip(t,e,r){const n=`${t}_${e}`;return!!(r==="var"&&this._cacheData.varData.hasOwnProperty(n)||r==="varip"&&this._cacheData.varipData.hasOwnProperty(n))}getVarValue(t,e,r){const n=`${t}_${e}`;return r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n]}setVarValue(t,e,r,n){const i=`${t}_${e}`;let a;switch(typeof r=="object"&&r&&(n="var",a=r.varipKeys),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[i]=r,a&&a.length)for(const l of a)this._cacheData.varData[i][l]=r[l]}else this._cacheData.varData[i]=r;break;case"varip":this._cacheData.varipData[i]=r;break}return r}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Jr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case ao.name:case th.name:case co.name:case eh.name:case uo.name:case lo.name:t==null||t.delete();break}}}class Fi{constructor(t=50){R(this,"_all");R(this,"_allInstance");R(this,"_pseudoArrayAll");R(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Qt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const i=r.filter(a=>a.endsWith(`_${n}`));for(const a of i){const l=this._all.get(a);l&&e.push(l)}}return e.length?e:void 0}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}/**
|
66
66
|
* @license
|
67
67
|
* Copyright 2019 Google LLC
|
68
68
|
* SPDX-License-Identifier: Apache-2.0
|
@@ -67593,14 +67593,14 @@ function ir(a, n, r) {
|
|
67593
67593
|
function oh() {
|
67594
67594
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
67595
67595
|
}
|
67596
|
-
const Fp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-
|
67596
|
+
const Fp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-iWV0t2US.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
|
67597
67597
|
Fp.onerror = (a) => {
|
67598
67598
|
console.error(a);
|
67599
67599
|
};
|
67600
67600
|
async function Rp(a) {
|
67601
67601
|
return await Ja.setInlayHints(a);
|
67602
67602
|
}
|
67603
|
-
const Bp = ji(Fp), Kp = ji(new Worker(new URL("" + new URL("assets/parserTccWorker-
|
67603
|
+
const Bp = ji(Fp), Kp = ji(new Worker(new URL("" + new URL("assets/parserTccWorker-zBAvnCOS.js", import.meta.url).href, import.meta.url), { type: "module", name: "Parser TccScript Server" }));
|
67604
67604
|
async function lh(a, n = !1) {
|
67605
67605
|
const { functions: r, types: o, constants: c, variables: l, methods: m } = ht;
|
67606
67606
|
return await Kp.parseTcc(a, n, Hi(Rp), { functions: Object.fromEntries(r), methods: Object.fromEntries(m), types: Object.fromEntries(o), constants: Object.fromEntries(c), 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 _o=Symbol("Comlink.proxy"),sm=Symbol("Comlink.endpoint"),am=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),fo=a=>typeof a=="object"&&a!==null||typeof a=="function",nm={canHandle:a=>fo(a)&&a[_o],serialize(a){const{port1:n,port2:s}=new MessageChannel;return bo(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},im={canHandle:a=>fo(a)&&Ys in a,serialize({value:a}){let n;return a instanceof Error?n={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:n={isError:!1,value:a},[n,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},go=new Map([["proxy",nm],["throw",im]]);function om(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function bo(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!om(s,c.origin)){console.warn(`Invalid origin '${c.origin}' for comlink proxy`);return}const{id:l,type:m,path:y}=Object.assign({path:[]},c.data),f=(c.data.argumentList||[]).map(xr);let b;try{const h=y.slice(0,-1).reduce((N,U)=>N[U],a),T=y.reduce((N,U)=>N[U],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=xr(c.data.value),b=!0;break;case"APPLY":b=T.apply(h,f);break;case"CONSTRUCT":{const N=new T(...f);b=gn(N)}break;case"ENDPOINT":{const{port1:N,port2:U}=new MessageChannel;bo(a,U),b=mm(N,[N])}break;case"RELEASE":b=void 0;break;default:return}}catch(h){b={value:h,[Ys]:0}}Promise.resolve(b).catch(h=>({value:h,[Ys]:0})).then(h=>{const[T,N]=ea(h);n.postMessage(Object.assign(Object.assign({},T),{id:l}),N),m==="RELEASE"&&(n.removeEventListener("message",o),xo(n),yn in a&&typeof a[yn]=="function"&&a[yn]())}).catch(h=>{const[T,N]=ea({value:new TypeError("Unserializable return value"),[Ys]:0});n.postMessage(Object.assign(Object.assign({},T),{id:l}),N)})}),n.start&&n.start()}function lm(a){return a.constructor.name==="MessagePort"}function xo(a){lm(a)&&a.close()}function _n(a,n){return fn(a,[],n)}function Qs(a){if(a)throw new Error("Proxy has been released and is not useable")}function ho(a){return Mr(a,{type:"RELEASE"}).then(()=>{xo(a)})}const Zs=new WeakMap,Js="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const n=(Zs.get(a)||0)-1;Zs.set(a,n),n===0&&ho(a)});function cm(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function pm(a){Js&&Js.unregister(a)}function fn(a,n=[],s=function(){}){let o=!1;const c=new Proxy(s,{get(l,m){if(Qs(o),m===am)return()=>{pm(c),ho(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Mr(a,{type:"GET",path:n.map(f=>f.toString())}).then(xr);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Mr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(xr)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===sm)return Mr(a,{type:"ENDPOINT"}).then(xr);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=wo(y);return Mr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(xr)},construct(l,m){Qs(o);const[y,f]=wo(m);return Mr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(xr)}});return cm(c,a),c}function dm(a){return Array.prototype.concat.apply([],a)}function wo(a){const n=a.map(ea);return[n.map(s=>s[0]),dm(n.map(s=>s[1]))]}const vo=new WeakMap;function mm(a,n){return vo.set(a,n),a}function gn(a){return Object.assign(a,{[_o]:!0})}function ea(a){for(const[n,s]of go)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},vo.get(a)||[]]}function xr(a){switch(a.type){case"HANDLER":return go.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Mr(a,n,s){return new Promise(o=>{const c=um();a.addEventListener("message",function l(m){!m.data||!m.data.id||m.data.id!==c||(a.removeEventListener("message",l),o(m.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:c},n),s)})}function um(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const To=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-
|
144
|
+
*/const _o=Symbol("Comlink.proxy"),sm=Symbol("Comlink.endpoint"),am=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),fo=a=>typeof a=="object"&&a!==null||typeof a=="function",nm={canHandle:a=>fo(a)&&a[_o],serialize(a){const{port1:n,port2:s}=new MessageChannel;return bo(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},im={canHandle:a=>fo(a)&&Ys in a,serialize({value:a}){let n;return a instanceof Error?n={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:n={isError:!1,value:a},[n,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},go=new Map([["proxy",nm],["throw",im]]);function om(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function bo(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!om(s,c.origin)){console.warn(`Invalid origin '${c.origin}' for comlink proxy`);return}const{id:l,type:m,path:y}=Object.assign({path:[]},c.data),f=(c.data.argumentList||[]).map(xr);let b;try{const h=y.slice(0,-1).reduce((N,U)=>N[U],a),T=y.reduce((N,U)=>N[U],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=xr(c.data.value),b=!0;break;case"APPLY":b=T.apply(h,f);break;case"CONSTRUCT":{const N=new T(...f);b=gn(N)}break;case"ENDPOINT":{const{port1:N,port2:U}=new MessageChannel;bo(a,U),b=mm(N,[N])}break;case"RELEASE":b=void 0;break;default:return}}catch(h){b={value:h,[Ys]:0}}Promise.resolve(b).catch(h=>({value:h,[Ys]:0})).then(h=>{const[T,N]=ea(h);n.postMessage(Object.assign(Object.assign({},T),{id:l}),N),m==="RELEASE"&&(n.removeEventListener("message",o),xo(n),yn in a&&typeof a[yn]=="function"&&a[yn]())}).catch(h=>{const[T,N]=ea({value:new TypeError("Unserializable return value"),[Ys]:0});n.postMessage(Object.assign(Object.assign({},T),{id:l}),N)})}),n.start&&n.start()}function lm(a){return a.constructor.name==="MessagePort"}function xo(a){lm(a)&&a.close()}function _n(a,n){return fn(a,[],n)}function Qs(a){if(a)throw new Error("Proxy has been released and is not useable")}function ho(a){return Mr(a,{type:"RELEASE"}).then(()=>{xo(a)})}const Zs=new WeakMap,Js="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const n=(Zs.get(a)||0)-1;Zs.set(a,n),n===0&&ho(a)});function cm(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function pm(a){Js&&Js.unregister(a)}function fn(a,n=[],s=function(){}){let o=!1;const c=new Proxy(s,{get(l,m){if(Qs(o),m===am)return()=>{pm(c),ho(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Mr(a,{type:"GET",path:n.map(f=>f.toString())}).then(xr);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Mr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(xr)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===sm)return Mr(a,{type:"ENDPOINT"}).then(xr);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=wo(y);return Mr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(xr)},construct(l,m){Qs(o);const[y,f]=wo(m);return Mr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(xr)}});return cm(c,a),c}function dm(a){return Array.prototype.concat.apply([],a)}function wo(a){const n=a.map(ea);return[n.map(s=>s[0]),dm(n.map(s=>s[1]))]}const vo=new WeakMap;function mm(a,n){return vo.set(a,n),a}function gn(a){return Object.assign(a,{[_o]:!0})}function ea(a){for(const[n,s]of go)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},vo.get(a)||[]]}function xr(a){switch(a.type){case"HANDLER":return go.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Mr(a,n,s){return new Promise(o=>{const c=um();a.addEventListener("message",function l(m){!m.data||!m.data.id||m.data.id!==c||(a.removeEventListener("message",l),o(m.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:c},n),s)})}function um(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const To=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-iWV0t2US.js").href:new URL("assets/scriptsRunWorker-iWV0t2US.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});To.onerror=a=>{console.error(a)};async function Do(a){return await Gs.setInlayHints(a)}const ko=_n(To),Io=_n(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-zBAvnCOS.js").href:new URL("assets/parserTccWorker-zBAvnCOS.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function Ao(a,n=!1){const{functions:s,types:o,constants:c,variables:l,methods:m}=pt;return await Io.parseTcc(a,n,gn(Do),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function ym(a,n){const{functions:s,types:o,constants:c,variables:l,methods:m}=pt;return await Io.parseLibraryCode(a,n,gn(Do),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function qo(a,n,s=!0){return await ko.runScript(a,n,s)}async function _m(a){return await ko.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})}self.MonacoEnvironment={getWorker(){return new fm({name:"Editor Worker"})}},sn.config({paths:{vs:"https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});let Co={};const gm=(a,n)=>{const{height:s,width:o,theme:c,options:l,hasDiff:m,readOnly:y,defaultValue:f,onChange:b,onLinkOpen:h,onDeclareConfigChange:T,onCursorPositionChange:N,onActionTrigger:U,onEditorDidMount:R}=a,L=O.useRef(null),j=O.useRef(null),V=O.useRef(!1);O.useImperativeHandle(n,()=>({setOriginalScript(z){var W;(W=L.current)==null||W.setOriginalScript(z)},setScript(z){var W;(W=L.current)==null||W.setValue(z)},gotoLine(){var z;(z=L.current)==null||z.gotoLine()},getEditorLayout(){var z;return(z=L.current)==null?void 0:z.getEditorLayout()},setPosition(z,W){var Q;(Q=L.current)==null||Q.setPosition({column:z,lineNumber:W})},setModelMarkers(z){var W;(W=L.current)==null||W.setModelMarkers(z)},focus(){var z;(z=L.current)==null||z.focus()}})),O.useEffect(()=>{var z,W;m?(W=L.current)==null||W.addDiffDecorations():(z=L.current)==null||z.removeDiffDecorations()},[m]),O.useEffect(()=>{c&&ke.editor.setTheme(c)},[c]),O.useEffect(()=>{var z;(z=L.current)==null||z.updateActionTrigger(U)},[U]),O.useEffect(()=>{var z;h&&((z=L.current)==null||z.addLinkOpenFunc(h))},[h]);function Y(z,W){var ie,Ze;St.initBuiltinsTrees(),Gs.setEditor(z),L.current=new rm(z,W,U),h&&((ie=L.current)==null||ie.addLinkOpenFunc(h)),m&&((Ze=L.current)==null||Ze.addDiffDecorations()),qd(z),requestAnimationFrame(H);const Q=z.getValue();L.current.onChangeCursorPosition(N),b&&b(Q),!y&&F(Q),R&&R()}const F=O.useCallback(async z=>{var Lt;const W=Date.now();V.current=!1;const{errors:Q,functions:ie,methods:Ze,types:Et,variables:Ue,overloadsFuncs:Ke,imports:J,preParserCode:be,enums:Le}=await Ao(z),Me=new Map(Object.entries(ie)),dt=new Map(Object.entries(Ze)),wt=new Map(Object.entries(Et)),se=new Map(Object.entries(Ue)),he=new Map(Object.entries(J)),Pe=new Map(Object.entries(Le));br.setUserDefined({functions:Me,methods:dt,types:wt,variables:se,imports:he,enums:Pe},Ke),St.setUserDefind(Me,wt,se,dt,Pe);const Nt=Q.map(He=>({...He,severity:He.type||ke.MarkerSeverity.Error}));if(y)return;try{const He=await qo(be||"",{isPreParser:!0});(!io.isEqual(He,Co)||Q.length)&&(He.errors=He.errors.concat(Q),Co=He,T&&T(He))}catch(He){console.log(He),Q.push({message:He.message,startLineNumber:0,endLineNumber:0,startColumn:0,endColumn:0})}!V.current&&((Lt=L.current)==null||Lt.setModelMarkers(Nt));const je=Date.now();console.log((je-W)/1e3)},[T,y]),B=O.useMemo(()=>io.debounce(F,1500),[F]);function q(z){var W;if(y){F(z||"");return}V.current=!0,Gs.clearInlayHints(),(W=L.current)==null||W.setModelMarkers([]),z!==void 0&&(b&&b(z),B(z))}const H=O.useCallback(()=>{var W,Q;const z=(W=j.current)==null?void 0:W.getBoundingClientRect();(Q=L.current)==null||Q.setEditorLayout((z==null?void 0:z.height)||0,z==null?void 0:z.width)},[]);return O.useEffect(()=>{const z=()=>{window.requestAnimationFrame(H)},W=new ResizeObserver(z);return j.current&&W.observe(j.current),()=>{var Q;j.current&&W.unobserve(j.current),W.disconnect(),(Q=L.current)==null||Q.dispose()}},[]),M.jsx("div",{ref:j,children:M.jsx(gd,{height:s,width:o||"100%",defaultLanguage:Se,defaultValue:f||`indicator("我的脚本")
|
145
145
|
plot(close)
|
146
146
|
`,theme:c||"vs-dark",className:`tvue-script ${c||"vs-dark"}`,options:{colorDecorators:!0,useShadowDOM:!1,matchOnWordStartOnly:!0,automaticLayout:!1,unicodeHighlight:{allowedCharacters:{" ":!0}},suggest:{filterGraceful:!0},fontSize:13,...y?Pd:{},readOnlyMessage:{value:"该脚本是只读的。它无法被编辑。"},...l},onMount:Y,onChange:q})})},bm=O.forwardRef(gm),xm=a=>{const{theme:n,modified:s,original:o,height:c,width:l,renderSideBySide:m=!0}=a,y=O.useCallback((f,b)=>{b.languages.register({id:Se}),b.editor.defineTheme("vs-dark",cn),b.editor.defineTheme("vs",ln),b.languages.setMonarchTokensProvider(Se,Lr),b.languages.setLanguageConfiguration(Se,on)},[]);return M.jsx(md,{height:c||"90vh",width:l||"100%",theme:n||"vs-dark",options:{readOnly:!0,renderSideBySide:m,scrollBeyondLastLine:!1},language:Se,modified:s,original:o,onMount:y})};I.VMarkerSeverity=void 0,function(a){a[a.Hint=1]="Hint",a[a.Info=2]="Info",a[a.Warning=4]="Warning",a[a.Error=8]="Error"}(I.VMarkerSeverity||(I.VMarkerSeverity={}));var ta={},hm=function(){var a=document.getSelection();if(!a.rangeCount)return function(){};for(var n=document.activeElement,s=[],o=0;o<a.rangeCount;o++)s.push(a.getRangeAt(o));switch(n.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":n.blur();break;default:n=null;break}return a.removeAllRanges(),function(){a.type==="Caret"&&a.removeAllRanges(),a.rangeCount||s.forEach(function(c){a.addRange(c)}),n&&n.focus()}},wm=hm,zo={"text/plain":"Text","text/html":"Url",default:"Text"},vm="Copy to clipboard: #{key}, Enter";function Tm(a){var n=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return a.replace(/#{\s*key\s*}/g,n)}function Dm(a,n){var s,o,c,l,m,y,f=!1;n||(n={}),s=n.debug||!1;try{c=wm(),l=document.createRange(),m=document.getSelection(),y=document.createElement("span"),y.textContent=a,y.ariaHidden="true",y.style.all="unset",y.style.position="fixed",y.style.top=0,y.style.clip="rect(0, 0, 0, 0)",y.style.whiteSpace="pre",y.style.webkitUserSelect="text",y.style.MozUserSelect="text",y.style.msUserSelect="text",y.style.userSelect="text",y.addEventListener("copy",function(h){if(h.stopPropagation(),n.format)if(h.preventDefault(),typeof h.clipboardData>"u"){s&&console.warn("unable to use e.clipboardData"),s&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var T=zo[n.format]||zo.default;window.clipboardData.setData(T,a)}else h.clipboardData.clearData(),h.clipboardData.setData(n.format,a);n.onCopy&&(h.preventDefault(),n.onCopy(h.clipboardData))}),document.body.appendChild(y),l.selectNodeContents(y),m.addRange(l);var b=document.execCommand("copy");if(!b)throw new Error("copy command was unsuccessful");f=!0}catch(h){s&&console.error("unable to copy using execCommand: ",h),s&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(n.format||"text",a),n.onCopy&&n.onCopy(window.clipboardData),f=!0}catch(T){s&&console.error("unable to copy using clipboardData: ",T),s&&console.error("falling back to prompt"),o=Tm("message"in n?n.message:vm),window.prompt(o,a)}}finally{m&&(typeof m.removeRange=="function"?m.removeRange(l):m.removeAllRanges()),y&&document.body.removeChild(y),c()}return f}var km=Dm;function bn(a){"@babel/helpers - typeof";return bn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},bn(a)}Object.defineProperty(ta,"__esModule",{value:!0}),ta.CopyToClipboard=void 0;var ra=So(O),Im=So(km),Am=["text","onCopy","options","children"];function So(a){return a&&a.__esModule?a:{default:a}}function Eo(a,n){var s=Object.keys(a);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(a);n&&(o=o.filter(function(c){return Object.getOwnPropertyDescriptor(a,c).enumerable})),s.push.apply(s,o)}return s}function No(a){for(var n=1;n<arguments.length;n++){var s=arguments[n]!=null?arguments[n]:{};n%2?Eo(Object(s),!0).forEach(function(o){hn(a,o,s[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(s)):Eo(Object(s)).forEach(function(o){Object.defineProperty(a,o,Object.getOwnPropertyDescriptor(s,o))})}return a}function qm(a,n){if(a==null)return{};var s=Cm(a,n),o,c;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(a);for(c=0;c<l.length;c++)o=l[c],!(n.indexOf(o)>=0)&&Object.prototype.propertyIsEnumerable.call(a,o)&&(s[o]=a[o])}return s}function Cm(a,n){if(a==null)return{};var s={},o=Object.keys(a),c,l;for(l=0;l<o.length;l++)c=o[l],!(n.indexOf(c)>=0)&&(s[c]=a[c]);return s}function zm(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function Lo(a,n){for(var s=0;s<n.length;s++){var o=n[s];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(a,o.key,o)}}function Sm(a,n,s){return n&&Lo(a.prototype,n),s&&Lo(a,s),Object.defineProperty(a,"prototype",{writable:!1}),a}function Em(a,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(n&&n.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),n&&xn(a,n)}function xn(a,n){return xn=Object.setPrototypeOf||function(o,c){return o.__proto__=c,o},xn(a,n)}function Nm(a){var n=Mm();return function(){var o=sa(a),c;if(n){var l=sa(this).constructor;c=Reflect.construct(o,arguments,l)}else c=o.apply(this,arguments);return Lm(this,c)}}function Lm(a,n){if(n&&(bn(n)==="object"||typeof n=="function"))return n;if(n!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Mo(a)}function Mo(a){if(a===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function Mm(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function sa(a){return sa=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},sa(a)}function hn(a,n,s){return n in a?Object.defineProperty(a,n,{value:s,enumerable:!0,configurable:!0,writable:!0}):a[n]=s,a}var Po=function(a){Em(s,a);var n=Nm(s);function s(){var o;zm(this,s);for(var c=arguments.length,l=new Array(c),m=0;m<c;m++)l[m]=arguments[m];return o=n.call.apply(n,[this].concat(l)),hn(Mo(o),"onClick",function(y){var f=o.props,b=f.text,h=f.onCopy,T=f.children,N=f.options,U=ra.default.Children.only(T),R=(0,Im.default)(b,N);h&&h(b,R),U&&U.props&&typeof U.props.onClick=="function"&&U.props.onClick(y)}),o}return Sm(s,[{key:"render",value:function(){var c=this.props;c.text,c.onCopy,c.options;var l=c.children,m=qm(c,Am),y=ra.default.Children.only(l);return ra.default.cloneElement(y,No(No({},m),{},{onClick:this.onClick}))}}]),s}(ra.default.PureComponent);ta.CopyToClipboard=Po,hn(Po,"defaultProps",{onCopy:void 0,options:void 0});var Pm=ta,wn=Pm.CopyToClipboard;wn.CopyToClipboard=wn;var Om=wn;const vn=cp(Om);async function Rm(a,n=0){const s=a[n];if(!s)return;const{name:o,args:c,type:l,desc:m,examples:y,remarks:f,seeAlso:b,syntax:h,detailedDesc:T,fields:N,returns:U}=s,R={name:o};if(a.length>1&&(R.overloads=`${a.length} overloads`),l&&(R.type=l),c&&(R.name=`${o}()`,R.args=c.map(L=>{const{name:j,desc:V,displayType:Y}=L;return{label:`${j} (${Y})`,desc:V&&hr(V)}})),m&&(R.desc=m.map(L=>hr(L))),y&&(R.originalExample=y.join(`
|
147
147
|
`),R.examples=await ke.editor.colorize(R.originalExample,Se,{tabSize:4})),T){R.detailedDesc=[];for(const L of T){const{desc:j,examples:V}=L;let Y=j.map(q=>hr(q)),F,B;V&&(B=V.join(`
|