pinets 0.9.9 → 0.9.10
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.
- package/dist/pinets.min.browser.es.js +14 -14
- package/dist/pinets.min.browser.es.js.map +1 -1
- package/dist/pinets.min.browser.js +12 -12
- package/dist/pinets.min.browser.js.map +1 -1
- package/dist/pinets.min.cjs +4 -4
- package/dist/pinets.min.cjs.map +1 -1
- package/dist/pinets.min.es.js +4 -4
- package/dist/pinets.min.es.js.map +1 -1
- package/dist/types/namespaces/box/BoxHelper.d.ts +5 -0
- package/dist/types/namespaces/label/LabelHelper.d.ts +1 -0
- package/dist/types/namespaces/line/LineHelper.d.ts +1 -0
- package/dist/types/namespaces/polyline/PolylineHelper.d.ts +1 -0
- package/package.json +1 -1
package/dist/pinets.min.cjs
CHANGED
|
@@ -11,9 +11,9 @@ Defaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=1
|
|
|
11
11
|
`,s):(t.write("/*"),Ps(t,s.value,i,r),t.write("*/"+r))}}function Ds(t){let e=t;for(;e!=null;){const{type:i}=e;if(i[0]==="C"&&i[1]==="a")return!0;if(i[0]==="M"&&i[1]==="e"&&i[2]==="m")e=e.object;else return!1}}function ri(t,e){const{generator:i}=t,{declarations:r}=e;t.write(e.kind+" ");const{length:n}=r;if(n>0){i.VariableDeclarator(r[0],t);for(let a=1;a<n;a++)t.write(", "),i.VariableDeclarator(r[a],t)}}let Ui,qi,zi,Ki,Hi,Gi;const ki={Program(t,e){const i=e.indent.repeat(e.indentLevel),{lineEnd:r,writeComments:n}=e;n&&t.comments!=null&&ne(e,t.comments,i,r);const a=t.body,{length:s}=a;for(let o=0;o<s;o++){const l=a[o];n&&l.comments!=null&&ne(e,l.comments,i,r),e.write(i),this[l.type](l,e),e.write(r)}n&&t.trailingComments!=null&&ne(e,t.trailingComments,i,r)},BlockStatement:Gi=function(t,e){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e,a=i+e.indent;e.write("{");const s=t.body;if(s!=null&&s.length>0){e.write(r),n&&t.comments!=null&&ne(e,t.comments,a,r);const{length:o}=s;for(let l=0;l<o;l++){const c=s[l];n&&c.comments!=null&&ne(e,c.comments,a,r),e.write(a),this[c.type](c,e),e.write(r)}e.write(i)}else n&&t.comments!=null&&(e.write(r),ne(e,t.comments,a,r),e.write(i));n&&t.trailingComments!=null&&ne(e,t.trailingComments,a,r),e.write("}"),e.indentLevel--},ClassBody:Gi,StaticBlock(t,e){e.write("static "),this.BlockStatement(t,e)},EmptyStatement(t,e){e.write(";")},ExpressionStatement(t,e){const i=e.expressionsPrecedence[t.expression.type];i===Ne||i===3&&t.expression.left.type[0]==="O"?(e.write("("),this[t.expression.type](t.expression,e),e.write(")")):this[t.expression.type](t.expression,e),e.write(";")},IfStatement(t,e){e.write("if ("),this[t.test.type](t.test,e),e.write(") "),this[t.consequent.type](t.consequent,e),t.alternate!=null&&(e.write(" else "),this[t.alternate.type](t.alternate,e))},LabeledStatement(t,e){this[t.label.type](t.label,e),e.write(": "),this[t.body.type](t.body,e)},BreakStatement(t,e){e.write("break"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},ContinueStatement(t,e){e.write("continue"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},WithStatement(t,e){e.write("with ("),this[t.object.type](t.object,e),e.write(") "),this[t.body.type](t.body,e)},SwitchStatement(t,e){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e;e.indentLevel++;const a=i+e.indent,s=a+e.indent;e.write("switch ("),this[t.discriminant.type](t.discriminant,e),e.write(") {"+r);const{cases:o}=t,{length:l}=o;for(let c=0;c<l;c++){const h=o[c];n&&h.comments!=null&&ne(e,h.comments,a,r),h.test?(e.write(a+"case "),this[h.test.type](h.test,e),e.write(":"+r)):e.write(a+"default:"+r);const{consequent:p}=h,{length:u}=p;for(let f=0;f<u;f++){const m=p[f];n&&m.comments!=null&&ne(e,m.comments,s,r),e.write(s),this[m.type](m,e),e.write(r)}}e.indentLevel-=2,e.write(i+"}")},ReturnStatement(t,e){e.write("return"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e)),e.write(";")},ThrowStatement(t,e){e.write("throw "),this[t.argument.type](t.argument,e),e.write(";")},TryStatement(t,e){if(e.write("try "),this[t.block.type](t.block,e),t.handler){const{handler:i}=t;i.param==null?e.write(" catch "):(e.write(" catch ("),this[i.param.type](i.param,e),e.write(") ")),this[i.body.type](i.body,e)}t.finalizer&&(e.write(" finally "),this[t.finalizer.type](t.finalizer,e))},WhileStatement(t,e){e.write("while ("),this[t.test.type](t.test,e),e.write(") "),this[t.body.type](t.body,e)},DoWhileStatement(t,e){e.write("do "),this[t.body.type](t.body,e),e.write(" while ("),this[t.test.type](t.test,e),e.write(");")},ForStatement(t,e){if(e.write("for ("),t.init!=null){const{init:i}=t;i.type[0]==="V"?ri(e,i):this[i.type](i,e)}e.write("; "),t.test&&this[t.test.type](t.test,e),e.write("; "),t.update&&this[t.update.type](t.update,e),e.write(") "),this[t.body.type](t.body,e)},ForInStatement:Ui=function(t,e){e.write(`for ${t.await?"await ":""}(`);const{left:i}=t;i.type[0]==="V"?ri(e,i):this[i.type](i,e),e.write(t.type[3]==="I"?" in ":" of "),this[t.right.type](t.right,e),e.write(") "),this[t.body.type](t.body,e)},ForOfStatement:Ui,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:qi=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),at(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:qi,VariableDeclaration(t,e){ri(e,t),e.write(";")},VariableDeclarator(t,e){this[t.id.type](t.id,e),t.init!=null&&(e.write(" = "),this[t.init.type](t.init,e))},ClassDeclaration(t,e){if(e.write("class "+(t.id?`${t.id.name} `:""),t),t.superClass){e.write("extends ");const{superClass:i}=t,{type:r}=i,n=e.expressionsPrecedence[r];(r[0]!=="C"||r[1]!=="l"||r[5]!=="E")&&(n===Ne||n<e.expressionsPrecedence.ClassExpression)?(e.write("("),this[t.superClass.type](i,e),e.write(")")):this[i.type](i,e),e.write(" ")}this.ClassBody(t.body,e)},ImportDeclaration(t,e){e.write("import ");const{specifiers:i,attributes:r}=t,{length:n}=i;let a=0;if(n>0){for(;a<n;){a>0&&e.write(", ");const s=i[a],o=s.type[6];if(o==="D")e.write(s.local.name,s),a++;else if(o==="N")e.write("* as "+s.local.name,s),a++;else break}if(a<n){for(e.write("{");;){const s=i[a],{name:o}=s.imported;if(e.write(o,s),o!==s.local.name&&e.write(" as "+s.local.name),++a<n)e.write(", ");else break}e.write("}")}e.write(" from ")}if(this.Literal(t.source,e),r&&r.length>0){e.write(" with { ");for(let s=0;s<r.length;s++)this.ImportAttribute(r[s],e),s<r.length-1&&e.write(", ");e.write(" }")}e.write(";")},ImportAttribute(t,e){this.Identifier(t.key,e),e.write(": "),this.Literal(t.value,e)},ImportExpression(t,e){e.write("import("),this[t.source.type](t.source,e),e.write(")")},ExportDefaultDeclaration(t,e){e.write("export default "),this[t.declaration.type](t.declaration,e),e.expressionsPrecedence[t.declaration.type]!=null&&t.declaration.type[0]!=="F"&&e.write(";")},ExportNamedDeclaration(t,e){if(e.write("export "),t.declaration)this[t.declaration.type](t.declaration,e);else{e.write("{");const{specifiers:i}=t,{length:r}=i;if(r>0)for(let n=0;;){const a=i[n],{name:s}=a.local;if(e.write(s,a),s!==a.exported.name&&e.write(" as "+a.exported.name),++n<r)e.write(", ");else break}if(e.write("}"),t.source&&(e.write(" from "),this.Literal(t.source,e)),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let n=0;n<t.attributes.length;n++)this.ImportAttribute(t.attributes[n],e),n<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")}},ExportAllDeclaration(t,e){if(t.exported!=null?e.write("export * as "+t.exported.name+" from "):e.write("export * from "),this.Literal(t.source,e),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let i=0;i<t.attributes.length;i++)this.ImportAttribute(t.attributes[i],e),i<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")},MethodDefinition(t,e){t.static&&e.write("static ");const i=t.kind[0];(i==="g"||i==="s")&&e.write(t.kind+" "),t.value.async&&e.write("async "),t.value.generator&&e.write("*"),t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),at(e,t.value.params),e.write(" "),this[t.value.body.type](t.value.body,e)},ClassExpression(t,e){this.ClassDeclaration(t,e)},ArrowFunctionExpression(t,e){e.write(t.async?"async ":"",t);const{params:i}=t;i!=null&&(i.length===1&&i[0].type[0]==="I"?e.write(i[0].name,i[0]):at(e,t.params)),e.write(" => "),t.body.type[0]==="O"?(e.write("("),this.ObjectExpression(t.body,e),e.write(")")):this[t.body.type](t.body,e)},ThisExpression(t,e){e.write("this",t)},Super(t,e){e.write("super",t)},RestElement:zi=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:zi,YieldExpression(t,e){e.write(t.delegate?"yield*":"yield"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e))},AwaitExpression(t,e){e.write("await ",t),Mt(e,t.argument,t)},TemplateLiteral(t,e){const{quasis:i,expressions:r}=t;e.write("`");const{length:n}=r;for(let s=0;s<n;s++){const o=r[s],l=i[s];e.write(l.value.raw,l),e.write("${"),this[o.type](o,e),e.write("}")}const a=i[i.length-1];e.write(a.value.raw,a),e.write("`")},TemplateElement(t,e){e.write(t.value.raw,t)},TaggedTemplateExpression(t,e){Mt(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:Hi=function(t,e){if(e.write("["),t.elements.length>0){const{elements:i}=t,{length:r}=i;for(let n=0;;){const a=i[n];if(a!=null&&this[a.type](a,e),++n<r)e.write(", ");else{a==null&&e.write(", ");break}}}e.write("]")},ArrayPattern:Hi,ObjectExpression(t,e){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e,a=i+e.indent;if(e.write("{"),t.properties.length>0){e.write(r),n&&t.comments!=null&&ne(e,t.comments,a,r);const s=","+r,{properties:o}=t,{length:l}=o;for(let c=0;;){const h=o[c];if(n&&h.comments!=null&&ne(e,h.comments,a,r),e.write(a),this[h.type](h,e),++c<l)e.write(s);else break}e.write(r),n&&t.trailingComments!=null&&ne(e,t.trailingComments,a,r),e.write(i+"}")}else n?t.comments!=null?(e.write(r),ne(e,t.comments,a,r),t.trailingComments!=null&&ne(e,t.trailingComments,a,r),e.write(i+"}")):t.trailingComments!=null?(e.write(r),ne(e,t.trailingComments,a,r),e.write(i+"}")):e.write("}"):e.write("}");e.indentLevel--},Property(t,e){t.method||t.kind[0]!=="i"?this.MethodDefinition(t,e):(t.shorthand||(t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),e.write(": ")),this[t.value.type](t.value,e))},PropertyDefinition(t,e){if(t.static&&e.write("static "),t.computed&&e.write("["),this[t.key.type](t.key,e),t.computed&&e.write("]"),t.value==null){t.key.type[0]!=="F"&&e.write(";");return}e.write(" = "),this[t.value.type](t.value,e),e.write(";")},ObjectPattern(t,e){if(e.write("{"),t.properties.length>0){const{properties:i}=t,{length:r}=i;for(let n=0;this[i[n].type](i[n],e),++n<r;)e.write(", ")}e.write("}")},SequenceExpression(t,e){at(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){const{operator:i,argument:r,argument:{type:n}}=t;e.write(i);const a=on(e,r,t);!a&&(i.length>1||n[0]==="U"&&(n[1]==="n"||n[1]==="p")&&r.prefix&&r.operator[0]===i&&(i==="+"||i==="-"))&&e.write(" "),a?(e.write(i.length>1?" (":"("),this[n](r,e),e.write(")")):this[n](r,e)}else this[t.argument.type](t.argument,e),e.write(t.operator)},UpdateExpression(t,e){t.prefix?(e.write(t.operator),this[t.argument.type](t.argument,e)):(this[t.argument.type](t.argument,e),e.write(t.operator))},AssignmentExpression(t,e){this[t.left.type](t.left,e),e.write(" "+t.operator+" "),this[t.right.type](t.right,e)},AssignmentPattern(t,e){this[t.left.type](t.left,e),e.write(" = "),this[t.right.type](t.right,e)},BinaryExpression:Ki=function(t,e){const i=t.operator==="in";i&&e.write("("),Mt(e,t.left,t,!1),e.write(" "+t.operator+" "),Mt(e,t.right,t,!0),i&&e.write(")")},LogicalExpression:Ki,ConditionalExpression(t,e){const{test:i}=t,r=e.expressionsPrecedence[i.type];r===Ne||r<=e.expressionsPrecedence.ConditionalExpression?(e.write("("),this[i.type](i,e),e.write(")")):this[i.type](i,e),e.write(" ? "),this[t.consequent.type](t.consequent,e),e.write(" : "),this[t.alternate.type](t.alternate,e)},NewExpression(t,e){e.write("new ");const i=e.expressionsPrecedence[t.callee.type];i===Ne||i<e.expressionsPrecedence.CallExpression||Ds(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),at(e,t.arguments)},CallExpression(t,e){const i=e.expressionsPrecedence[t.callee.type];i===Ne||i<e.expressionsPrecedence.CallExpression?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),t.optional&&e.write("?."),at(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){const i=e.expressionsPrecedence[t.object.type];i===Ne||i<e.expressionsPrecedence.MemberExpression?(e.write("("),this[t.object.type](t.object,e),e.write(")")):this[t.object.type](t.object,e),t.computed?(t.optional&&e.write("?."),e.write("["),this[t.property.type](t.property,e),e.write("]")):(t.optional?e.write("?."):e.write("."),this[t.property.type](t.property,e))},MetaProperty(t,e){e.write(t.meta.name+"."+t.property.name,t)},Identifier(t,e){e.write(t.name,t)},PrivateIdentifier(t,e){e.write(`#${t.name}`,t)},Literal(t,e){t.raw!=null?e.write(t.raw,t):t.regex!=null?this.RegExpLiteral(t,e):t.bigint!=null?e.write(t.bigint+"n",t):e.write(As(t.value),t)},RegExpLiteral(t,e){const{regex:i}=t;e.write(`/${i.pattern}/${i.flags}`,t)}},Ms={},Rs=ki;class Vs{constructor(e){const i=e??Ms;this.output="",i.output!=null?(this.output=i.output,this.write=this.writeToStream):this.output="",this.generator=i.generator!=null?i.generator:ki,this.expressionsPrecedence=i.expressionsPrecedence!=null?i.expressionsPrecedence:Ts,this.indent=i.indent!=null?i.indent:" ",this.lineEnd=i.lineEnd!=null?i.lineEnd:`
|
|
12
12
|
`,this.indentLevel=i.startingIndentLevel!=null?i.startingIndentLevel:0,this.writeComments=i.comments?i.comments:!1,i.sourceMap!=null&&(this.write=i.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=i.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`
|
|
13
13
|
`).length-1,this.mapping={original:null,generated:this,name:void 0,source:i.sourceMap.file||i.sourceMap._file})}write(e){this.output+=e}writeToStream(e){this.output.write(e)}writeAndMap(e,i){this.output+=e,this.map(e,i)}writeToStreamAndMap(e,i){this.output.write(e),this.map(e,i)}map(e,i){if(i!=null){const{type:a}=i;if(a[0]==="L"&&a[2]==="n"){this.column=0,this.line++;return}if(i.loc!=null){const{mapping:s}=this;s.original=i.loc.start,s.name=i.name,this.sourceMap.addMapping(s)}if(a[0]==="T"&&a[8]==="E"||a[0]==="L"&&a[1]==="i"&&typeof i.value=="string"){const{length:s}=e;let{column:o,line:l}=this;for(let c=0;c<s;c++)e[c]===`
|
|
14
|
-
`?(o=0,l++):o++;this.column=o,this.line=l;return}}const{length:r}=e,{lineEnd:n}=this;r>0&&(this.lineEndSize>0&&(n.length===1?e[r-1]===n:e.endsWith(n))?(this.line+=this.lineEndSize,this.column=0):this.column+=r)}toString(){return this.output}}function ln(t,e){const i=new Vs(e);return i.generator[t.type](t,i),i.output}const Os=new Set(["Infinity","NaN","undefined","null","true","false"]),Ls=new Set(["Math","Array","Object","String","Number","Boolean","Date","RegExp","Error","JSON","Promise","Set","Map","WeakSet","WeakMap","Symbol","BigInt","Proxy","Reflect","console","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","encodeURIComponent","decodeURIComponent"]);class js{scopes=[];scopeTypes=[];scopeCounts=new Map;contextBoundVars=new Set;arrayPatternElements=new Set;rootParams=new Set;localSeriesVars=new Set;varKinds=new Map;loopVars=new Set;loopVarNames=new Map;paramIdCounter=0;cacheIdCounter=0;tempVarCounter=0;taCallIdCounter=0;userCallIdCounter=0;plotCallIdCounter=0;alertCallIdCounter=0;loopGuardCounter=0;hoistingStack=[];suppressHoisting=!1;reservedNames=new Set;userFunctions=new Set;userMethods=new Set;get nextParamIdArg(){return{type:"Identifier",name:`'p${this.paramIdCounter++}'`}}get nextCacheIdArg(){return{type:"Identifier",name:`'cache_${this.cacheIdCounter++}'`}}getNextTACallId(){return{type:"Literal",value:`_ta${this.taCallIdCounter++}`}}getNextUserCallId(){return{type:"Literal",value:`_fn${this.userCallIdCounter++}`}}getNextPlotCallId(){return{type:"Literal",value:`#${this.plotCallIdCounter++}`}}getNextAlertCallId(){return{type:"Literal",value:`alert_${this.alertCallIdCounter++}`}}getNextLoopGuardName(){return`__lg${this.loopGuardCounter++}`}constructor(){this.pushScope("glb")}pushScope(e){this.scopes.push(new Map),this.scopeTypes.push(e),this.scopeCounts.set(e,(this.scopeCounts.get(e)||0)+1)}popScope(){this.scopes.pop(),this.scopeTypes.pop()}getCurrentScopeType(){return this.scopeTypes[this.scopeTypes.length-1]}getCurrentScopeCount(){return this.scopeCounts.get(this.getCurrentScopeType())||1}addLocalSeriesVar(e){this.localSeriesVars.add(e)}removeLocalSeriesVar(e){this.localSeriesVars.delete(e)}isLocalSeriesVar(e){return this.localSeriesVars.has(e)}addContextBoundVar(e,i=!1){this.contextBoundVars.add(e),i&&this.rootParams.add(e)}removeContextBoundVar(e){this.contextBoundVars.has(e)&&(this.contextBoundVars.delete(e),this.rootParams.has(e)&&this.rootParams.delete(e))}addArrayPatternElement(e){this.arrayPatternElements.add(e)}isContextBound(e){return Os.has(e)||Ls.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,i){this.loopVars.add(e),this.loopVarNames.set(e,i)}removeLoopVariable(e){this.loopVars.delete(e),this.loopVarNames.delete(e)}getLoopVariableName(e){return this.loopVarNames.get(e)}isLoopVariable(e){return this.loopVars.has(e)}addReservedName(e){this.reservedNames.add(e)}addUserFunction(e){this.userFunctions.add(e)}isUserFunction(e){return this.userFunctions.has(e)}addUserMethod(e){this.userMethods.add(e)}isUserMethod(e){return this.userMethods.has(e)}addVariable(e,i){if(this.isContextBound(e))return e;const r=this.scopes[this.scopes.length-1],n=this.scopeTypes[this.scopeTypes.length-1],a=this.scopeCounts.get(n)||1,s=`${n}${a}_${e}`;return r.set(e,s),this.varKinds.set(s,i),s}getVariable(e){if(this.loopVars.has(e)){const i=this.loopVarNames.get(e);if(i)return[i,"let"]}if(this.isContextBound(e))return[e,"let"];for(let i=this.scopes.length-1;i>=0;i--){const r=this.scopes[i];if(r.has(e)){const n=r.get(e),a=this.varKinds.get(n)||"let";return[n,a]}}return[e,"let"]}isVariableInFunctionScope(e){for(let i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].has(e)){for(let r=0;r<=i;r++)if(this.scopeTypes[r]==="fn")return!0;return!1}return!1}generateTempVar(){return`temp_${++this.tempVarCounter}`}enterHoistingScope(){this.hoistingStack.push([])}exitHoistingScope(){return this.hoistingStack.pop()||[]}addHoistedStatement(e){this.hoistingStack.length>0&&!this.suppressHoisting&&this.hoistingStack[this.hoistingStack.length-1].push(e)}addOuterHoistedStatement(e){if(this.hoistingStack.length>0&&!this.suppressHoisting){const i=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[i].push(e)}}getCurrentHoistingScope(){return this.hoistingStack.length===0?null:this.hoistingStack[this.hoistingStack.length-1]}setSuppressHoisting(e){this.suppressHoisting=e}shouldSuppressHoisting(){return this.suppressHoisting}hasVariableInScope(e){if(this.reservedNames.has(e))return!0;for(let i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].has(e))return!0;return!!(this.contextBoundVars.has(e)||this.loopVars.has(e)||this.localSeriesVars.has(e))}generateParamId(){let e=`p${this.paramIdCounter++}`;for(;this.hasVariableInScope(e);)e=`p${this.paramIdCounter++}`;const i=this.scopes[this.scopes.length-1];return i&&i.set(e,e),e}}function qe(t,e,i,r,n){i||(i=N),(function a(s,o,l){var c=l||s.type;cn(i,c,s,o,a),e[c]&&e[c](s,o)})(t,r,n)}function Bs(t,e,i,r,n){var a=[];i||(i=N),(function s(o,l,c){var h=c||o.type,p=o!==a[a.length-1];p&&a.push(o),cn(i,h,o,l,s),e[h]&&e[h](o,l||a,a),p&&a.pop()})(t,r,n)}function H(t,e,i,r,n){var a=i?Fs(i,r||void 0):r;(function s(o,l,c){a[c||o.type](o,l,s)})(t,e,n)}function Fs(t,e){var i=Object.create(e||N);for(var r in t)i[r]=t[r];return i}function Ai(t,e,i){i(t,e)}function tt(t,e,i){}function cn(t,e,i,r,n){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](i,r,n)}var N={};N.Program=N.BlockStatement=N.StaticBlock=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var a=n[r];i(a,e,"Statement")}};N.Statement=Ai;N.EmptyStatement=tt;N.ExpressionStatement=N.ParenthesizedExpression=N.ChainExpression=function(t,e,i){return i(t.expression,e,"Expression")};N.IfStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Statement"),t.alternate&&i(t.alternate,e,"Statement")};N.LabeledStatement=function(t,e,i){return i(t.body,e,"Statement")};N.BreakStatement=N.ContinueStatement=tt;N.WithStatement=function(t,e,i){i(t.object,e,"Expression"),i(t.body,e,"Statement")};N.SwitchStatement=function(t,e,i){i(t.discriminant,e,"Expression");for(var r=0,n=t.cases;r<n.length;r+=1){var a=n[r];i(a,e)}};N.SwitchCase=function(t,e,i){t.test&&i(t.test,e,"Expression");for(var r=0,n=t.consequent;r<n.length;r+=1){var a=n[r];i(a,e,"Statement")}};N.ReturnStatement=N.YieldExpression=N.AwaitExpression=function(t,e,i){t.argument&&i(t.argument,e,"Expression")};N.ThrowStatement=N.SpreadElement=function(t,e,i){return i(t.argument,e,"Expression")};N.TryStatement=function(t,e,i){i(t.block,e,"Statement"),t.handler&&i(t.handler,e),t.finalizer&&i(t.finalizer,e,"Statement")};N.CatchClause=function(t,e,i){t.param&&i(t.param,e,"Pattern"),i(t.body,e,"Statement")};N.WhileStatement=N.DoWhileStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.body,e,"Statement")};N.ForStatement=function(t,e,i){t.init&&i(t.init,e,"ForInit"),t.test&&i(t.test,e,"Expression"),t.update&&i(t.update,e,"Expression"),i(t.body,e,"Statement")};N.ForInStatement=N.ForOfStatement=function(t,e,i){i(t.left,e,"ForInit"),i(t.right,e,"Expression"),i(t.body,e,"Statement")};N.ForInit=function(t,e,i){t.type==="VariableDeclaration"?i(t,e):i(t,e,"Expression")};N.DebuggerStatement=tt;N.FunctionDeclaration=function(t,e,i){return i(t,e,"Function")};N.VariableDeclaration=function(t,e,i){for(var r=0,n=t.declarations;r<n.length;r+=1){var a=n[r];i(a,e)}};N.VariableDeclarator=function(t,e,i){i(t.id,e,"Pattern"),t.init&&i(t.init,e,"Expression")};N.Function=function(t,e,i){t.id&&i(t.id,e,"Pattern");for(var r=0,n=t.params;r<n.length;r+=1){var a=n[r];i(a,e,"Pattern")}i(t.body,e,t.expression?"Expression":"Statement")};N.Pattern=function(t,e,i){t.type==="Identifier"?i(t,e,"VariablePattern"):t.type==="MemberExpression"?i(t,e,"MemberPattern"):i(t,e)};N.VariablePattern=tt;N.MemberPattern=Ai;N.RestElement=function(t,e,i){return i(t.argument,e,"Pattern")};N.ArrayPattern=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var a=n[r];a&&i(a,e,"Pattern")}};N.ObjectPattern=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];a.type==="Property"?(a.computed&&i(a.key,e,"Expression"),i(a.value,e,"Pattern")):a.type==="RestElement"&&i(a.argument,e,"Pattern")}};N.Expression=Ai;N.ThisExpression=N.Super=N.MetaProperty=tt;N.ArrayExpression=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var a=n[r];a&&i(a,e,"Expression")}};N.ObjectExpression=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];i(a,e)}};N.FunctionExpression=N.ArrowFunctionExpression=N.FunctionDeclaration;N.SequenceExpression=function(t,e,i){for(var r=0,n=t.expressions;r<n.length;r+=1){var a=n[r];i(a,e,"Expression")}};N.TemplateLiteral=function(t,e,i){for(var r=0,n=t.quasis;r<n.length;r+=1){var a=n[r];i(a,e)}for(var s=0,o=t.expressions;s<o.length;s+=1){var l=o[s];i(l,e,"Expression")}};N.TemplateElement=tt;N.UnaryExpression=N.UpdateExpression=function(t,e,i){i(t.argument,e,"Expression")};N.BinaryExpression=N.LogicalExpression=function(t,e,i){i(t.left,e,"Expression"),i(t.right,e,"Expression")};N.AssignmentExpression=N.AssignmentPattern=function(t,e,i){i(t.left,e,"Pattern"),i(t.right,e,"Expression")};N.ConditionalExpression=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Expression"),i(t.alternate,e,"Expression")};N.NewExpression=N.CallExpression=function(t,e,i){if(i(t.callee,e,"Expression"),t.arguments)for(var r=0,n=t.arguments;r<n.length;r+=1){var a=n[r];i(a,e,"Expression")}};N.MemberExpression=function(t,e,i){i(t.object,e,"Expression"),t.computed&&i(t.property,e,"Expression")};N.ExportNamedDeclaration=N.ExportDefaultDeclaration=function(t,e,i){if(t.declaration&&i(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var a=n[r];i(a,e)}};N.ExportAllDeclaration=function(t,e,i){if(t.exported&&i(t.exported,e),i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var a=n[r];i(a,e)}};N.ImportAttribute=function(t,e,i){i(t.value,e,"Expression")};N.ImportDeclaration=function(t,e,i){for(var r=0,n=t.specifiers;r<n.length;r+=1){var a=n[r];i(a,e)}if(i(t.source,e,"Expression"),t.attributes)for(var s=0,o=t.attributes;s<o.length;s+=1){var l=o[s];i(l,e)}};N.ImportExpression=function(t,e,i){i(t.source,e,"Expression"),t.options&&i(t.options,e,"Expression")};N.ImportSpecifier=N.ImportDefaultSpecifier=N.ImportNamespaceSpecifier=N.Identifier=N.PrivateIdentifier=N.Literal=tt;N.TaggedTemplateExpression=function(t,e,i){i(t.tag,e,"Expression"),i(t.quasi,e,"Expression")};N.ClassDeclaration=N.ClassExpression=function(t,e,i){return i(t,e,"Class")};N.Class=function(t,e,i){t.id&&i(t.id,e,"Pattern"),t.superClass&&i(t.superClass,e,"Expression"),i(t.body,e)};N.ClassBody=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var a=n[r];i(a,e)}};N.MethodDefinition=N.PropertyDefinition=N.Property=function(t,e,i){t.computed&&i(t.key,e,"Expression"),t.value&&i(t.value,e,"Expression")};const z="$",v={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,i=!1){return{type:"MemberExpression",object:t,property:e,computed:i}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createLocalContextVariableReference(t,e){const i=this.createLocalContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createDynamicContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(i,r,!1),e,!0)},createContextVariableAccess0(t,e){const i=this.createContextVariableReference(t,e);return this.createGetCall(i,0)},createDynamicContextVariableAccess0(t,e){const i=this.createDynamicContextVariableReference(t,e);return this.createGetCall(i,0)},createArrayAccess(t,e){const i=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,i,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,i="="){return{type:"AssignmentExpression",operator:i,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,i){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),n=[t,e];return i&&n.push(i),this.createCallExpression(r,n)},createInitVarCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),r=[t,e];return this.createCallExpression(i,r)},createGetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),r=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(i,[t,r])},createSetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(i,[t,e])},createMathEqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__eq"),!1);return this.createCallExpression(n,[t,e])},createMathNeqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__neq"),!1);return this.createCallExpression(n,[t,e])},createWrapperFunction(t){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:t}]}}},createVariableDeclaration(t,e){return{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:this.createIdentifier(t),init:e}]}},createAwaitExpression(t){return{type:"AwaitExpression",argument:t}}},it=["ta","math","request","array","input","color"],Pe=["hline","plot","fill","label","line","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],$s=["request.security","request.security_lower_tf"],Ws=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],ni=new Set([...it,"fill","plot","hline","label","line","size","extend","display","format","location","shape","text","xloc","yloc","linefill","polyline","box","table","map","matrix","chart","alert","barstate","syminfo","timeframe","strategy","log","str"]),hn=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],Ti=[...it,"plotchar","plotshape","plotarrow","plotbar","plotcandle","plot","bgcolor","barcolor","hline","fill","indicator","strategy","library","alertcondition","alert","error","max_bars_back","fixnan","na","nz","timestamp","str","box","line","label","table","chart","linefill","polyline","map","matrix","log","Type","bool","int","float","string","timeframe","syminfo","barstate","bar_index","last_bar_index","last_bar_time","inputs","time","time_close","time_tradingday","dayofmonth","hour","minute","month","second","weekofyear","year","order","currency","display","shape","location","size","format","dayofweek","xloc","yloc","text","font","extend","position","barmerge","adjustment","backadjustment","earnings","dividends","splits"],Us=["na","nz","plot","plotchar","color","hline","fill"];function qs(t){let e=null,i=z;if(t.type==="Program"&&t.body.length>0){const f=t.body[0];if(f.type==="ExpressionStatement"&&(f.expression.type==="ArrowFunctionExpression"||f.expression.type==="FunctionExpression")){const m=f.expression;m.body.type==="BlockStatement"&&(e=m.body.body,m.params.length>0&&m.params[0].type==="Identifier"&&(i=m.params[0].name))}}if(!e)return;const r=new Set,n=new Set,a=f=>{f.type==="Identifier"?r.add(f.name):f.type==="ObjectPattern"?f.properties.forEach(m=>a(m.value)):f.type==="ArrayPattern"&&f.elements.forEach(m=>{m&&a(m)})};H(t,{},{VariableDeclarator(f,m,x){a(f.id),f.init&&x(f.init,m)},FunctionDeclaration(f,m,x){a(f.id),x(f.body,m)},Identifier(f,m,x){n.add(f.name)},MemberExpression(f,m,x){x(f.object,m),f.computed&&x(f.property,m)},Property(f,m,x){f.computed&&x(f.key,m),x(f.value,m)}}),e.forEach(f=>{f.type==="VariableDeclaration"?f.declarations.forEach(m=>a(m.id)):f.type==="FunctionDeclaration"&&a(f.id)});const s=hn,o=Ti,l=s.filter(f=>!r.has(f)),c=o.filter(f=>!r.has(f)),h=l.filter(f=>n.has(f)),p=c.filter(f=>n.has(f)),u=[];h.length>0&&u.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:h.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"data"},computed:!1}}]}),p.length>0&&u.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:p.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"pine"},computed:!1}}]}),u.length>0&&e.unshift(...u)}function zs(t){let e=null,i=z;if(t.type==="Program"&&t.body.length>0){const o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){const l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(i=l.params[0].name))}}if(!e)return;const r=new Set(hn),n=new Set(Ti),a=new Set(Us),s=new Map;e.forEach(o=>{o.type==="VariableDeclaration"&&o.declarations.forEach(l=>{if(l.init&&l.init.type==="MemberExpression"&&l.init.object.type==="Identifier"&&l.init.object.name===i&&l.init.property.type==="Identifier"){const c=l.init.property.name;let h=null;if(c==="data"?h=r:c==="pine"?h=n:c==="core"&&(h=a),h&&l.id.type==="ObjectPattern")l.id.properties.forEach(p=>{if(p.type==="Property"&&p.key.type==="Identifier"&&p.value.type==="Identifier"){const u=p.key.name,f=p.value.name;h.has(u)&&u!==f&&(s.set(f,u),p.value.name=u,p.shorthand=!0)}});else if(l.id.type==="Identifier"&&it.includes(c)){const p=c,u=l.id.name;p!==u&&(s.set(u,p),l.id.name=p)}}})}),s.size>0&&H(t,{},{Identifier(o){s.has(o.name)&&(o.name=s.get(o.name))},MemberExpression(o,l,c){c(o.object,l),o.computed&&c(o.property,l)},Property(o,l,c){o.computed&&c(o.key,l),c(o.value,l)}})}function Ks(t){try{const e=an(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){const i=e.body[0];if(i.type==="ExpressionStatement"){const r=i.expression;if(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}if(i.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:i.async||!1,functionNode:i}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function Hs(t){return t.async=!0,ln(t)}function Gs(t){t=t.trim();const{isWrapped:e,isAsync:i,functionNode:r}=Ks(t);return e&&r?i?t:Hs(r):`async (context) => {
|
|
14
|
+
`?(o=0,l++):o++;this.column=o,this.line=l;return}}const{length:r}=e,{lineEnd:n}=this;r>0&&(this.lineEndSize>0&&(n.length===1?e[r-1]===n:e.endsWith(n))?(this.line+=this.lineEndSize,this.column=0):this.column+=r)}toString(){return this.output}}function ln(t,e){const i=new Vs(e);return i.generator[t.type](t,i),i.output}const Os=new Set(["Infinity","NaN","undefined","null","true","false"]),Ls=new Set(["Math","Array","Object","String","Number","Boolean","Date","RegExp","Error","JSON","Promise","Set","Map","WeakSet","WeakMap","Symbol","BigInt","Proxy","Reflect","console","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","encodeURIComponent","decodeURIComponent"]);class js{scopes=[];scopeTypes=[];scopeCounts=new Map;contextBoundVars=new Set;arrayPatternElements=new Set;rootParams=new Set;localSeriesVars=new Set;varKinds=new Map;loopVars=new Set;loopVarNames=new Map;paramIdCounter=0;cacheIdCounter=0;tempVarCounter=0;taCallIdCounter=0;userCallIdCounter=0;plotCallIdCounter=0;alertCallIdCounter=0;loopGuardCounter=0;hoistingStack=[];suppressHoisting=!1;reservedNames=new Set;userFunctions=new Set;userMethods=new Set;get nextParamIdArg(){return{type:"Identifier",name:`'p${this.paramIdCounter++}'`}}get nextCacheIdArg(){return{type:"Identifier",name:`'cache_${this.cacheIdCounter++}'`}}getNextTACallId(){return{type:"Literal",value:`_ta${this.taCallIdCounter++}`}}getNextUserCallId(){return{type:"Literal",value:`_fn${this.userCallIdCounter++}`}}getNextPlotCallId(){return{type:"Literal",value:`#${this.plotCallIdCounter++}`}}getNextAlertCallId(){return{type:"Literal",value:`alert_${this.alertCallIdCounter++}`}}getNextLoopGuardName(){return`__lg${this.loopGuardCounter++}`}constructor(){this.pushScope("glb")}pushScope(e){this.scopes.push(new Map),this.scopeTypes.push(e),this.scopeCounts.set(e,(this.scopeCounts.get(e)||0)+1)}popScope(){this.scopes.pop(),this.scopeTypes.pop()}getCurrentScopeType(){return this.scopeTypes[this.scopeTypes.length-1]}getCurrentScopeCount(){return this.scopeCounts.get(this.getCurrentScopeType())||1}addLocalSeriesVar(e){this.localSeriesVars.add(e)}removeLocalSeriesVar(e){this.localSeriesVars.delete(e)}isLocalSeriesVar(e){return this.localSeriesVars.has(e)}addContextBoundVar(e,i=!1){this.contextBoundVars.add(e),i&&this.rootParams.add(e)}removeContextBoundVar(e){this.contextBoundVars.has(e)&&(this.contextBoundVars.delete(e),this.rootParams.has(e)&&this.rootParams.delete(e))}addArrayPatternElement(e){this.arrayPatternElements.add(e)}isContextBound(e){return Os.has(e)||Ls.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,i){this.loopVars.add(e),this.loopVarNames.set(e,i)}removeLoopVariable(e){this.loopVars.delete(e),this.loopVarNames.delete(e)}getLoopVariableName(e){return this.loopVarNames.get(e)}isLoopVariable(e){return this.loopVars.has(e)}addReservedName(e){this.reservedNames.add(e)}addUserFunction(e){this.userFunctions.add(e)}isUserFunction(e){return this.userFunctions.has(e)}addUserMethod(e){this.userMethods.add(e)}isUserMethod(e){return this.userMethods.has(e)}addVariable(e,i){if(this.isContextBound(e))return e;const r=this.scopes[this.scopes.length-1],n=this.scopeTypes[this.scopeTypes.length-1],a=this.scopeCounts.get(n)||1,s=`${n}${a}_${e}`;return r.set(e,s),this.varKinds.set(s,i),s}getVariable(e){if(this.loopVars.has(e)){const i=this.loopVarNames.get(e);if(i)return[i,"let"]}if(this.isContextBound(e))return[e,"let"];for(let i=this.scopes.length-1;i>=0;i--){const r=this.scopes[i];if(r.has(e)){const n=r.get(e),a=this.varKinds.get(n)||"let";return[n,a]}}return[e,"let"]}isVariableInFunctionScope(e){for(let i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].has(e)){for(let r=0;r<=i;r++)if(this.scopeTypes[r]==="fn")return!0;return!1}return!1}generateTempVar(){return`temp_${++this.tempVarCounter}`}enterHoistingScope(){this.hoistingStack.push([])}exitHoistingScope(){return this.hoistingStack.pop()||[]}addHoistedStatement(e){this.hoistingStack.length>0&&!this.suppressHoisting&&this.hoistingStack[this.hoistingStack.length-1].push(e)}addOuterHoistedStatement(e){if(this.hoistingStack.length>0&&!this.suppressHoisting){const i=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[i].push(e)}}getCurrentHoistingScope(){return this.hoistingStack.length===0?null:this.hoistingStack[this.hoistingStack.length-1]}setSuppressHoisting(e){this.suppressHoisting=e}shouldSuppressHoisting(){return this.suppressHoisting}hasVariableInScope(e){if(this.reservedNames.has(e))return!0;for(let i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].has(e))return!0;return!!(this.contextBoundVars.has(e)||this.loopVars.has(e)||this.localSeriesVars.has(e))}generateParamId(){let e=`p${this.paramIdCounter++}`;for(;this.hasVariableInScope(e);)e=`p${this.paramIdCounter++}`;const i=this.scopes[this.scopes.length-1];return i&&i.set(e,e),e}}function qe(t,e,i,r,n){i||(i=N),(function a(s,o,l){var c=l||s.type;cn(i,c,s,o,a),e[c]&&e[c](s,o)})(t,r,n)}function Bs(t,e,i,r,n){var a=[];i||(i=N),(function s(o,l,c){var h=c||o.type,p=o!==a[a.length-1];p&&a.push(o),cn(i,h,o,l,s),e[h]&&e[h](o,l||a,a),p&&a.pop()})(t,r,n)}function H(t,e,i,r,n){var a=i?Fs(i,r||void 0):r;(function s(o,l,c){a[c||o.type](o,l,s)})(t,e,n)}function Fs(t,e){var i=Object.create(e||N);for(var r in t)i[r]=t[r];return i}function Ai(t,e,i){i(t,e)}function tt(t,e,i){}function cn(t,e,i,r,n){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](i,r,n)}var N={};N.Program=N.BlockStatement=N.StaticBlock=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var a=n[r];i(a,e,"Statement")}};N.Statement=Ai;N.EmptyStatement=tt;N.ExpressionStatement=N.ParenthesizedExpression=N.ChainExpression=function(t,e,i){return i(t.expression,e,"Expression")};N.IfStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Statement"),t.alternate&&i(t.alternate,e,"Statement")};N.LabeledStatement=function(t,e,i){return i(t.body,e,"Statement")};N.BreakStatement=N.ContinueStatement=tt;N.WithStatement=function(t,e,i){i(t.object,e,"Expression"),i(t.body,e,"Statement")};N.SwitchStatement=function(t,e,i){i(t.discriminant,e,"Expression");for(var r=0,n=t.cases;r<n.length;r+=1){var a=n[r];i(a,e)}};N.SwitchCase=function(t,e,i){t.test&&i(t.test,e,"Expression");for(var r=0,n=t.consequent;r<n.length;r+=1){var a=n[r];i(a,e,"Statement")}};N.ReturnStatement=N.YieldExpression=N.AwaitExpression=function(t,e,i){t.argument&&i(t.argument,e,"Expression")};N.ThrowStatement=N.SpreadElement=function(t,e,i){return i(t.argument,e,"Expression")};N.TryStatement=function(t,e,i){i(t.block,e,"Statement"),t.handler&&i(t.handler,e),t.finalizer&&i(t.finalizer,e,"Statement")};N.CatchClause=function(t,e,i){t.param&&i(t.param,e,"Pattern"),i(t.body,e,"Statement")};N.WhileStatement=N.DoWhileStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.body,e,"Statement")};N.ForStatement=function(t,e,i){t.init&&i(t.init,e,"ForInit"),t.test&&i(t.test,e,"Expression"),t.update&&i(t.update,e,"Expression"),i(t.body,e,"Statement")};N.ForInStatement=N.ForOfStatement=function(t,e,i){i(t.left,e,"ForInit"),i(t.right,e,"Expression"),i(t.body,e,"Statement")};N.ForInit=function(t,e,i){t.type==="VariableDeclaration"?i(t,e):i(t,e,"Expression")};N.DebuggerStatement=tt;N.FunctionDeclaration=function(t,e,i){return i(t,e,"Function")};N.VariableDeclaration=function(t,e,i){for(var r=0,n=t.declarations;r<n.length;r+=1){var a=n[r];i(a,e)}};N.VariableDeclarator=function(t,e,i){i(t.id,e,"Pattern"),t.init&&i(t.init,e,"Expression")};N.Function=function(t,e,i){t.id&&i(t.id,e,"Pattern");for(var r=0,n=t.params;r<n.length;r+=1){var a=n[r];i(a,e,"Pattern")}i(t.body,e,t.expression?"Expression":"Statement")};N.Pattern=function(t,e,i){t.type==="Identifier"?i(t,e,"VariablePattern"):t.type==="MemberExpression"?i(t,e,"MemberPattern"):i(t,e)};N.VariablePattern=tt;N.MemberPattern=Ai;N.RestElement=function(t,e,i){return i(t.argument,e,"Pattern")};N.ArrayPattern=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var a=n[r];a&&i(a,e,"Pattern")}};N.ObjectPattern=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];a.type==="Property"?(a.computed&&i(a.key,e,"Expression"),i(a.value,e,"Pattern")):a.type==="RestElement"&&i(a.argument,e,"Pattern")}};N.Expression=Ai;N.ThisExpression=N.Super=N.MetaProperty=tt;N.ArrayExpression=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var a=n[r];a&&i(a,e,"Expression")}};N.ObjectExpression=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];i(a,e)}};N.FunctionExpression=N.ArrowFunctionExpression=N.FunctionDeclaration;N.SequenceExpression=function(t,e,i){for(var r=0,n=t.expressions;r<n.length;r+=1){var a=n[r];i(a,e,"Expression")}};N.TemplateLiteral=function(t,e,i){for(var r=0,n=t.quasis;r<n.length;r+=1){var a=n[r];i(a,e)}for(var s=0,o=t.expressions;s<o.length;s+=1){var l=o[s];i(l,e,"Expression")}};N.TemplateElement=tt;N.UnaryExpression=N.UpdateExpression=function(t,e,i){i(t.argument,e,"Expression")};N.BinaryExpression=N.LogicalExpression=function(t,e,i){i(t.left,e,"Expression"),i(t.right,e,"Expression")};N.AssignmentExpression=N.AssignmentPattern=function(t,e,i){i(t.left,e,"Pattern"),i(t.right,e,"Expression")};N.ConditionalExpression=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Expression"),i(t.alternate,e,"Expression")};N.NewExpression=N.CallExpression=function(t,e,i){if(i(t.callee,e,"Expression"),t.arguments)for(var r=0,n=t.arguments;r<n.length;r+=1){var a=n[r];i(a,e,"Expression")}};N.MemberExpression=function(t,e,i){i(t.object,e,"Expression"),t.computed&&i(t.property,e,"Expression")};N.ExportNamedDeclaration=N.ExportDefaultDeclaration=function(t,e,i){if(t.declaration&&i(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var a=n[r];i(a,e)}};N.ExportAllDeclaration=function(t,e,i){if(t.exported&&i(t.exported,e),i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var a=n[r];i(a,e)}};N.ImportAttribute=function(t,e,i){i(t.value,e,"Expression")};N.ImportDeclaration=function(t,e,i){for(var r=0,n=t.specifiers;r<n.length;r+=1){var a=n[r];i(a,e)}if(i(t.source,e,"Expression"),t.attributes)for(var s=0,o=t.attributes;s<o.length;s+=1){var l=o[s];i(l,e)}};N.ImportExpression=function(t,e,i){i(t.source,e,"Expression"),t.options&&i(t.options,e,"Expression")};N.ImportSpecifier=N.ImportDefaultSpecifier=N.ImportNamespaceSpecifier=N.Identifier=N.PrivateIdentifier=N.Literal=tt;N.TaggedTemplateExpression=function(t,e,i){i(t.tag,e,"Expression"),i(t.quasi,e,"Expression")};N.ClassDeclaration=N.ClassExpression=function(t,e,i){return i(t,e,"Class")};N.Class=function(t,e,i){t.id&&i(t.id,e,"Pattern"),t.superClass&&i(t.superClass,e,"Expression"),i(t.body,e)};N.ClassBody=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var a=n[r];i(a,e)}};N.MethodDefinition=N.PropertyDefinition=N.Property=function(t,e,i){t.computed&&i(t.key,e,"Expression"),t.value&&i(t.value,e,"Expression")};const z="$",S={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,i=!1){return{type:"MemberExpression",object:t,property:e,computed:i}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createLocalContextVariableReference(t,e){const i=this.createLocalContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createDynamicContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(i,r,!1),e,!0)},createContextVariableAccess0(t,e){const i=this.createContextVariableReference(t,e);return this.createGetCall(i,0)},createDynamicContextVariableAccess0(t,e){const i=this.createDynamicContextVariableReference(t,e);return this.createGetCall(i,0)},createArrayAccess(t,e){const i=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,i,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,i="="){return{type:"AssignmentExpression",operator:i,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,i){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),n=[t,e];return i&&n.push(i),this.createCallExpression(r,n)},createInitVarCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),r=[t,e];return this.createCallExpression(i,r)},createGetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),r=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(i,[t,r])},createSetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(i,[t,e])},createMathEqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__eq"),!1);return this.createCallExpression(n,[t,e])},createMathNeqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__neq"),!1);return this.createCallExpression(n,[t,e])},createWrapperFunction(t){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:t}]}}},createVariableDeclaration(t,e){return{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:this.createIdentifier(t),init:e}]}},createAwaitExpression(t){return{type:"AwaitExpression",argument:t}}},it=["ta","math","request","array","input","color"],Pe=["hline","plot","fill","label","line","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],$s=["request.security","request.security_lower_tf"],Ws=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],ni=new Set([...it,"fill","plot","hline","label","line","size","extend","display","format","location","shape","text","xloc","yloc","linefill","polyline","box","table","map","matrix","chart","alert","barstate","syminfo","timeframe","strategy","log","str"]),hn=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],Ti=[...it,"plotchar","plotshape","plotarrow","plotbar","plotcandle","plot","bgcolor","barcolor","hline","fill","indicator","strategy","library","alertcondition","alert","error","max_bars_back","fixnan","na","nz","timestamp","str","box","line","label","table","chart","linefill","polyline","map","matrix","log","Type","bool","int","float","string","timeframe","syminfo","barstate","bar_index","last_bar_index","last_bar_time","inputs","time","time_close","time_tradingday","dayofmonth","hour","minute","month","second","weekofyear","year","order","currency","display","shape","location","size","format","dayofweek","xloc","yloc","text","font","extend","position","barmerge","adjustment","backadjustment","earnings","dividends","splits"],Us=["na","nz","plot","plotchar","color","hline","fill"];function qs(t){let e=null,i=z;if(t.type==="Program"&&t.body.length>0){const f=t.body[0];if(f.type==="ExpressionStatement"&&(f.expression.type==="ArrowFunctionExpression"||f.expression.type==="FunctionExpression")){const m=f.expression;m.body.type==="BlockStatement"&&(e=m.body.body,m.params.length>0&&m.params[0].type==="Identifier"&&(i=m.params[0].name))}}if(!e)return;const r=new Set,n=new Set,a=f=>{f.type==="Identifier"?r.add(f.name):f.type==="ObjectPattern"?f.properties.forEach(m=>a(m.value)):f.type==="ArrayPattern"&&f.elements.forEach(m=>{m&&a(m)})};H(t,{},{VariableDeclarator(f,m,x){a(f.id),f.init&&x(f.init,m)},FunctionDeclaration(f,m,x){a(f.id),x(f.body,m)},Identifier(f,m,x){n.add(f.name)},MemberExpression(f,m,x){x(f.object,m),f.computed&&x(f.property,m)},Property(f,m,x){f.computed&&x(f.key,m),x(f.value,m)}}),e.forEach(f=>{f.type==="VariableDeclaration"?f.declarations.forEach(m=>a(m.id)):f.type==="FunctionDeclaration"&&a(f.id)});const s=hn,o=Ti,l=s.filter(f=>!r.has(f)),c=o.filter(f=>!r.has(f)),h=l.filter(f=>n.has(f)),p=c.filter(f=>n.has(f)),u=[];h.length>0&&u.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:h.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"data"},computed:!1}}]}),p.length>0&&u.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:p.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"pine"},computed:!1}}]}),u.length>0&&e.unshift(...u)}function zs(t){let e=null,i=z;if(t.type==="Program"&&t.body.length>0){const o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){const l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(i=l.params[0].name))}}if(!e)return;const r=new Set(hn),n=new Set(Ti),a=new Set(Us),s=new Map;e.forEach(o=>{o.type==="VariableDeclaration"&&o.declarations.forEach(l=>{if(l.init&&l.init.type==="MemberExpression"&&l.init.object.type==="Identifier"&&l.init.object.name===i&&l.init.property.type==="Identifier"){const c=l.init.property.name;let h=null;if(c==="data"?h=r:c==="pine"?h=n:c==="core"&&(h=a),h&&l.id.type==="ObjectPattern")l.id.properties.forEach(p=>{if(p.type==="Property"&&p.key.type==="Identifier"&&p.value.type==="Identifier"){const u=p.key.name,f=p.value.name;h.has(u)&&u!==f&&(s.set(f,u),p.value.name=u,p.shorthand=!0)}});else if(l.id.type==="Identifier"&&it.includes(c)){const p=c,u=l.id.name;p!==u&&(s.set(u,p),l.id.name=p)}}})}),s.size>0&&H(t,{},{Identifier(o){s.has(o.name)&&(o.name=s.get(o.name))},MemberExpression(o,l,c){c(o.object,l),o.computed&&c(o.property,l)},Property(o,l,c){o.computed&&c(o.key,l),c(o.value,l)}})}function Ks(t){try{const e=an(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){const i=e.body[0];if(i.type==="ExpressionStatement"){const r=i.expression;if(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}if(i.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:i.async||!1,functionNode:i}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function Hs(t){return t.async=!0,ln(t)}function Gs(t){t=t.trim();const{isWrapped:e,isAsync:i,functionNode:r}=Ks(t);return e&&r?i?t:Hs(r):`async (context) => {
|
|
15
15
|
${t}
|
|
16
|
-
}`}function Ys(t){H(t,null,{VariableDeclaration(e,i,r){e.declarations&&e.declarations.length>0&&e.declarations.forEach(n=>{if(n.init&&n.init.type==="ArrowFunctionExpression"&&n.init.start!==0){const a={type:"FunctionDeclaration",id:n.id,params:n.init.params,body:n.init.body.type==="BlockStatement"?n.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:n.init.body}]},async:n.init.async,generator:!1};Object.assign(e,a)}}),e.body&&e.body.body&&e.body.body.forEach(n=>r(n,i))}})}function Xs(t,e){qe(t,{VariableDeclaration(i){i.declarations.forEach(r=>{const n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===z||r.init.object.name==="context2"),a=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===z||r.init.object.object.name==="context2");(n||a)&&(r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(s=>{s.key.name&&e.addContextBoundVar(s.key.name)}))})}})}function Qs(t,e,i=!1){t.params.forEach(r=>{r.type==="Identifier"&&i&&e.addContextBoundVar(r.name,i)})}function Zs(t,e){let i;return Bs(t,{FunctionDeclaration(r){r.id&&r.id.name&&(e.addReservedName(r.id.name),e.addUserFunction(r.id.name))},ExpressionStatement(r){const n=r.expression;n&&n.type==="AssignmentExpression"&&n.operator==="="&&n.left?.type==="MemberExpression"&&n.left.property?.name==="__pineMethod__"&&n.left.object?.type==="Identifier"&&n.right?.value===!0&&e.addUserMethod(n.left.object.name)},ArrowFunctionExpression(r){const n=r.start===0;n&&r.params&&r.params.length>0&&(i=r.params[0].name,r.params[0].name=z),Qs(r,e,n)},VariableDeclaration(r,n){const a=n.length>1?n[n.length-2]:null,s=a&&(a.type==="ForOfStatement"||a.type==="ForInStatement")&&a.left===r;r.declarations.forEach(o=>{if(o.id.type==="Identifier")e.addReservedName(o.id.name);else if(o.id.type==="ObjectPattern")o.id.properties.forEach(l=>{l.key&&l.key.type==="Identifier"&&e.addReservedName(l.key.name)});else if(o.id.type==="ArrayPattern"){if(o.id.elements?.forEach(u=>{u&&u.type==="Identifier"&&e.addReservedName(u.name)}),s)return;const l=e.generateTempVar(),c={type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:l},init:o.init}]},h=c.declarations[0].init;h&&h.type==="CallExpression"&&(h.callee.type==="ArrowFunctionExpression"||h.callee.type==="FunctionExpression")&&qe(h.callee.body,{ReturnStatement(u){u.argument&&u.argument.type==="ArrayExpression"&&(u.argument={type:"ArrayExpression",elements:[u.argument]})}}),o.id.elements?.forEach(u=>{u.type==="Identifier"&&e.addArrayPatternElement(u.name)});const p=o.id.elements.map((u,f)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:u,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:f},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[c,...p]})}})},ForStatement(r){}}),i}const pi={type:"Identifier",name:"undefined"};function J(t,e){const[i,r]=e.getVariable(t);if((i.match(/^fn\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){const[n]=e.getVariable("$$");if(n)return v.createLocalContextVariableReference(r,i)}return v.createContextVariableReference(r,i)}function un(t,e){const i=J(t,e);return v.createGetCall(i,0)}function rt(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name)){if(t.object.type==="Identifier"&&!e.isLoopVariable(t.object.name)){if(e.isLocalSeriesVar(t.object.name)){const i=v.createIdentifier(t.object.name);i._skipTransformation=!0;const r=v.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){const i=J(t.object.name,e),r=v.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0}}return}e.isContextBound(t.property.name)||(t.property=J(t.property.name,e),t.property=v.createGetCall(t.property,0))}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){const i=v.createIdentifier(t.object.name);i._skipTransformation=!0;const r=v.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=J(t.object.name,e)),t.property.type==="MemberExpression"){const i=t.property;i._indexTransformed||(rt(i,e),i._indexTransformed=!0)}}t.computed&&t.property.type!=="Identifier"&&t.property.type!=="MemberExpression"&&!t._indexTransformed&&(t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression")&&(t.property=Ae(t.property,e))}function le(t,e){const i=v.createGetCall(v.createIdentifier(t.name),0);t.start!==void 0&&(i.start=t.start),t.end!==void 0&&(i.end=t.end),i._indexTransformed=!0,Object.assign(t,i)}function K(t,e){if(!t._skipTransformation&&t.name!==z){if(Pe.includes(t.name)&&e.isContextBound(t.name)){const u=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,f=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!u&&!f){const m={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},x=v.createGetCall(m,0);Object.assign(t,x),delete t.name;return}}if(t.name==="Math"||t.name==="NaN"||t.name==="undefined"||t.name==="Infinity"||t.name==="null"||t.name.startsWith("'")&&t.name.endsWith("'")||t.name.startsWith('"')&&t.name.endsWith('"')||t.name.startsWith("`")&&t.name.endsWith("`")||e.isLoopVariable(t.name))return;let i=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){const u=t.parent.callee;if(u.type==="MemberExpression"&&u.object&&u.object.name===z&&["get","set","init","param","call"].includes(u.property.name)){const f=t.parent.arguments.indexOf(t);u.property.name==="call"?f>=2&&(i=!0):f===0&&(i=!0)}else{const f=u.type==="MemberExpression"&&u.object&&u.object.type==="Identifier"&&it.includes(u.object.name);u.type==="MemberExpression"&&!f?i=!1:i=!0}}const r=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),n=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.property.name==="param";t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left;const a=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,s=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t,o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.property===t&&t.parent.parent&&t.parent.parent.type==="CallExpression"&&t.parent.parent.callee&&t.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.parent.callee.object.name);if(r||n||i||o||a){if(a||t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.object&&t.parent.callee.object.name===z&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;const u=J(t.name,e);Object.assign(t,u);return}const l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){const u=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),f=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,m=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!u&&!f&&!m)return}if(e.isLocalSeriesVar(t.name)){if(!s){const u=v.createIdentifier(t.name),f=v.createGetCall(u,0);Object.assign(t,f)}return}const[c,h]=e.getVariable(t.name);let p;if(l)p=v.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;p=J(t.name,e)}if(s)Object.assign(t,p);else{const u=v.createGetCall(p,0);Object.assign(t,u)}}}function ie(t,e,i){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.object&&t.object.type==="Identifier"&&it.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const l=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,c=t.parent&&(t.parent.type==="VariableDeclarator"&&(t.parent.id.type==="ArrayPattern"||t.parent.id.type==="ObjectPattern")||t.parent.type==="AssignmentExpression"&&(t.parent.left.type==="ArrayPattern"||t.parent.left.type==="ObjectPattern")||t.parent.type==="Property");if(!l&&!c){const h={type:"CallExpression",callee:{type:"MemberExpression",object:t.object,property:t.property,computed:!1},arguments:[],_transformed:!1};t.start!==void 0&&(h.start=t.start),t.end!==void 0&&(h.end=t.end),Object.assign(t,h);return}}if(!t.computed&&t.object&&t.object.type==="Identifier"&&i.isLocalSeriesVar(t.object.name)){const l=v.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=v.createGetCall(l,0);return}const r=i.getCurrentScopeType()=="if",n=i.getCurrentScopeType()=="els",a=i.getCurrentScopeType()=="for";if(!r&&!n&&!a&&t.object&&t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(rt(t,i),t._indexTransformed=!0);const s=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===z||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&i.isContextBound(t.object.name);if(t.computed&&(s||o)){if(t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left===t)return;t.object.type==="Identifier"&&Pe.includes(t.object.name)&&i.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});const l=v.createGetCall(t.object,t.property);t.start&&(l.start=t.start),t.end&&(l.end=t.end),Object.assign(t,l),delete t.object,delete t.property,delete t.computed}}function Nt(t,e){if(t.type==="Identifier"){if(Pe.includes(t.name)&&e.isContextBound(t.name)){const a=t.name;return Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:a},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name,t}if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){const[a,s]=e.getVariable(t.name);return v.createContextVariableReference(s,a)}if(e.isContextBound(t.name))return t;const[i,r]=e.getVariable(t.name),n=i!==t.name;return e.isLocalSeriesVar(t.name)&&!n?t:n?J(t.name,e):i===t.name&&!e.isContextBound(t.name)?t:J(t.name,e)}return t}function Ae(t,e,i=""){switch(t.type){case"BinaryExpression":return fi(t,e,i);case"LogicalExpression":return di(t,e,i);case"MemberExpression":{const r=!t.computed&&t.object.type==="Identifier"&&Pe.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&Pe.includes(t.object.name)&&e.isContextBound(t.object.name)){const s={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return v.createGetCall(s,t.property)}const n=t.object.type==="Identifier"&&!r?Nt(t.object,e):t.object;let a=n;if(!t.computed&&t.object.type==="Identifier"&&!r){const[s]=e.getVariable(t.object.name);s!==t.object.name&&!e.isLoopVariable(t.object.name)&&(a=v.createGetCall(n,0))}return{type:"MemberExpression",object:a,property:t.property,computed:t.computed}}case"Identifier":{if(e.isLoopVariable(t.name)||t.parent&&t.parent.type==="MemberExpression"&&t.parent.property===t)return t;const r=Nt(t,e);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:v.createGetCall(r,0)}case"UnaryExpression":return mi(t,e,i);case"ConditionalExpression":{const r=Ae(t.test,e,i),n=Ae(t.consequent,e,i),a=Ae(t.alternate,e,i);return{type:"ConditionalExpression",test:r,consequent:n,alternate:a,start:t.start,end:t.end}}}return t}function fi(t,e,i){const r=Ae(t.left,e,i),n=Ae(t.right,e,i),a={type:"BinaryExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return H(a,e,{CallExpression(s,o){s._transformed||Q(s,o)},MemberExpression(s){ie(s,"",e)}}),a}function di(t,e,i){const r=Ae(t.left,e,i),n=Ae(t.right,e,i),a={type:"LogicalExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return H(a,e,{CallExpression(s,o){s._transformed||Q(s,o)}}),a}function Yi(t,e,i){H(t,{parent:t,inNamespaceCall:!1},{Identifier(s,o,l){if(s.name=="NaN")return;if(Pe.includes(s.name)&&e.isContextBound(s.name)){if(o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===s&&!o.parent.computed)return;const h={type:"MemberExpression",object:{type:"Identifier",name:s.name},property:{type:"Identifier",name:"__value"},computed:!1},p=v.createGetCall(h,0);Object.assign(s,p),delete s.name;return}s.parent=o.parent,K(s,e);const c=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||c)&&(s.type==="MemberExpression"?rt(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===z&&s.parent.callee.property.name==="get"||le(s)))},MemberExpression(s,o,l){ie(s,"",e),s.object&&l(s.object,{parent:s,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(s,o,l){const c={...o,parent:s};s.test&&l(s.test,c),s.consequent&&l(s.consequent,c),s.alternate&&l(s.alternate,c)},BinaryExpression(s,o,l){const c={...o,parent:s};l(s.left,c),l(s.right,c)},LogicalExpression(s,o,l){const c={...o,parent:s};l(s.left,c),l(s.right,c)},UnaryExpression(s,o,l){const c={...o,parent:s};l(s.argument,c)},CallExpression(s,o,l){const c=s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&s.callee.object.type==="Identifier"&&e.isContextBound(s.callee.object.name);Q(s,e),s.arguments.forEach(h=>l(h,{parent:s,inNamespaceCall:c||o.inNamespaceCall}))}});const r=v.createMemberExpression(v.createIdentifier(i),v.createIdentifier("param")),n=e.generateParamId(),a={type:"CallExpression",callee:r,arguments:[t,pi,{type:"Identifier",name:`'${n}'`}],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){const s=n;e.addLocalSeriesVar(s);const o=v.createVariableDeclaration(s,a);return e.addHoistedStatement(o),v.createIdentifier(s)}return a}function mi(t,e,i){const r=Ae(t.argument,e,i),n={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:r,start:t.start,end:t.end};return H(n,e,{CallExpression(a,s){a._transformed||Q(a,s)},MemberExpression(a){ie(a,"",e)}}),n}function Xe(t,e,i){switch(t?.type){case"BinaryExpression":t=fi(t,i,e);break;case"LogicalExpression":t=di(t,i,e);break;case"ConditionalExpression":return Yi(t,i,e);case"UnaryExpression":t=mi(t,i,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(i.isContextBound(c.name)&&!i.isRootParam(c.name))return c;if(i.isLocalSeriesVar(c.name)){const h=v.createIdentifier(c.name);return v.createGetCall(h,0)}return un(c.name,i)}return c});break}const r=t.type==="MemberExpression"&&t.computed&&t.property,n=t.type==="MemberExpression"&&!t.computed;if(r){t.object.type==="CallExpression"?Q(t.object,i):t.object.type==="MemberExpression"?ie(t.object,"",i):t.object.type==="BinaryExpression"?t.object=fi(t.object,i,e):t.object.type==="LogicalExpression"?t.object=di(t.object,i,e):t.object.type==="ConditionalExpression"?t.object=Yi(t.object,i,e):t.object.type==="UnaryExpression"&&(t.object=mi(t.object,i,e));const c=t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)?t.object:Nt(t.object,i);let h;t.property.type==="Identifier"&&!i.isContextBound(t.property.name)&&!i.isLoopVariable(t.property.name)?h=v.createGetCall(Nt(t.property,i),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?h=Ae(t.property,i,e):h=t.property;const p=v.createMemberExpression(v.createIdentifier(e),v.createIdentifier("param")),u=i.generateParamId(),f={type:"CallExpression",callee:p,arguments:[c,h,{type:"Identifier",name:`'${u}'`}],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const m=u;i.addLocalSeriesVar(m);const x=v.createVariableDeclaration(m,f);return i.addHoistedStatement(x),v.createIdentifier(m)}return f}if(n){if(t.object.type==="Identifier"&&it.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const c=t.object.name,h={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:t.property.name},computed:!1},arguments:[],_transformed:!0};c==="ta"&&h.arguments.push(i.getNextTACallId());const p=i.generateTempVar();i.addLocalSeriesVar(p);const u=v.createVariableDeclaration(p,h);return i.addOuterHoistedStatement(u),Object.assign(t,v.createIdentifier(p)),t}if(t.object.type==="Identifier"){const c=t.object.name,[h,p]=i.getVariable(c);if(h!==c&&!i.isLoopVariable(c)){const u=J(c,i),f=v.createGetCall(u,0);t.object=f}else if(i.isLocalSeriesVar(c)){const u=v.createIdentifier(c);u._skipTransformation=!0,t.object=v.createGetCall(u,0)}}else t.object.type==="MemberExpression"?Xe(t.object,e,i):t.object.type==="CallExpression"&&(t.object._transformed||Q(t.object,i))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>c.value.name?i.isContextBound(c.value.name)||i.isLocalSeriesVar(c.value.name)||i.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:v.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:J(c.value.name,i),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=Xe(c.value,e,i)),c))),t.type==="Identifier"){if(Pe.includes(t.name)&&i.isContextBound(t.name)){const c=t.name;Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name}else if(i.isContextBound(t.name)&&!i.isRootParam(t.name)){const c=v.createMemberExpression(v.createIdentifier(e),v.createIdentifier("param")),h=i.generateParamId(),p={type:"CallExpression",callee:c,arguments:[t,pi,{type:"Identifier",name:`'${h}'`}],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const u=h;i.addLocalSeriesVar(u);const f=v.createVariableDeclaration(u,p);return i.addHoistedStatement(f),v.createIdentifier(u)}return p}}t?.type==="CallExpression"&&Q(t,i);const a=v.createMemberExpression(v.createIdentifier(e),v.createIdentifier("param")),s=t.type==="Identifier"?Nt(t,i):t,o=i.generateParamId(),l={type:"CallExpression",callee:a,arguments:[s,pi,{type:"Identifier",name:`'${o}'`}],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const c=o;i.addLocalSeriesVar(c);const h=v.createVariableDeclaration(c,l);return i.addHoistedStatement(h),v.createIdentifier(c)}return l}function St(t){if(!t)return!1;if(pn(t))return!0;if(t.type==="MemberExpression")return St(t.object);if(t.type==="ChainExpression")return St(t.expression);if(t.type==="CallExpression"){const e=t.callee;if(e?.type==="MemberExpression")return St(e.object);if(e?.type==="ChainExpression")return St(e.expression)}return!1}function pn(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function gi(t,e,i){t&&(t.type==="Identifier"?(t.parent=e,K(t,i)):t.type==="MemberExpression"?gi(t.object,t,i):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&gi(t.callee.object,t.callee,i),t._transformed||Q(t,i)))}function Q(t,e,i){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(it.includes(t.callee.name)||Pe.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=v.createMemberExpression(t.callee,v.createIdentifier("any")));const r=t.callee&&t.callee.type==="MemberExpression"&&t.callee.object&&t.callee.object.type==="Identifier"&&(e.isContextBound(t.callee.object.name)||t.callee.object.name==="math"||t.callee.object.name==="ta");if(r){if(t.callee.object.name===z&&["get","init","param"].includes(t.callee.property.name))return;const n=t.callee.object.name,a=[];if(t.arguments.forEach(h=>{if(h._isParamCall){a.push(h);return}a.push(Xe(h,n,e))}),t.arguments=a,["plot","hline","fill"].includes(n)){const h=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="alert"){const h=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="ta")if(e.getCurrentScopeType()==="fn"){const h=e.getNextTACallId(),[p]=e.getVariable("$$");let u;p?u=v.createMemberExpression(v.createLocalContextIdentifier(),v.createIdentifier("id")):u=v.createLiteral("");const f={type:"BinaryExpression",operator:"+",left:u,right:h};t.arguments.push(f)}else t.arguments.push(e.getNextTACallId());const s=t.callee.property.name,o=`${n}.${s}`,l=$s.includes(o),c=t._insideAwait===!0;if(l&&!c){const h=Object.assign({},t),p=v.createAwaitExpression(h);Object.assign(t,p)}if(!e.shouldSuppressHoisting()){const h=e.generateTempVar();e.addLocalSeriesVar(h);const p=t._insideAwait===!0;let u=Object.assign({},t);p&&(u=v.createAwaitExpression(u));const f=v.createVariableDeclaration(h,u);e.addHoistedStatement(f);const m=v.createIdentifier(h);Object.assign(t,m),t._wasHoisted=!0,t._wasInsideAwait=p;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(n=>n._isParamCall?n:Xe(n,z,e)),!e.isContextBound(t.callee.name)){const n=e.getNextUserCallId(),a=v.createMemberExpression(v.createContextIdentifier(),v.createIdentifier("call")),s=[t.callee,n,...t.arguments];t.callee=a,t.arguments=s}t._transformed=!0}if(!r&&t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.property.name,a=e.isUserFunction(n),s=t.callee.object,o=s.type==="Identifier"&&e.isLocalSeriesVar(s.name),l=s.type==="MemberExpression",c=e.isUserMethod(n);if(a&&c&&!e.isContextBound(n)&&!o&&!l){const h=t.callee.object;t.callee.property;const p=t.arguments.map(b=>b._isParamCall?b:Xe(b,z,e));let u=h;h.type==="Identifier"?u=Xe(h,z,e):h.type==="CallExpression"&&(Q(h,e),u=Xe(h,z,e));const f=v.createMemberExpression(v.createContextIdentifier(),v.createIdentifier("call")),m=e.getNextUserCallId(),x=v.createIdentifier(n);x._skipTransformation=!0;const _=[x,m,u,...p];t.callee=f,t.arguments=_,t._transformed=!0;return}t.callee.object.type==="Identifier"?K(t.callee.object,e):gi(t.callee.object,t.callee,e)}if(t.arguments.forEach(n=>{H(n,{parent:t},{Identifier(a,s,o){a.parent=s.parent,K(a,e);const l=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||l)&&(a.type==="MemberExpression"?rt(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===z&&a.parent.callee.property.name==="get"||le(a)))},BinaryExpression(a,s,o){const l={...s,parent:a};o(a.left,l),o(a.right,l)},LogicalExpression(a,s,o){const l={...s,parent:a};o(a.left,l),o(a.right,l)},UnaryExpression(a,s,o){const l={...s,parent:a};o(a.argument,l)},CallExpression(a,s,o){a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&(a.callee.object.parent=a.callee,o(a.callee.object,{parent:a.callee})),a._transformed||Q(a,e)},MemberExpression(a,s,o){ie(a,"",e),a.object&&o(a.object,{parent:a})}})}),t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.object,a=pn(n),s=n?.type==="MemberExpression"&&St(n);if(a||s){const o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function Pi(t){const e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},i={type:"IfStatement",test:{type:"BinaryExpression",operator:">",left:{type:"UpdateExpression",operator:"++",prefix:!0,argument:{type:"Identifier",name:t}},right:{type:"Identifier",name:"__maxLoops"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:`Loop exceeded maximum iterations (${t})`}]}},alternate:null};return{counterDecl:e,guardCheck:i}}function yi(t,e){let i=null;if(t.left.type==="Identifier")i=J(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){const r=t.left.object.name,[n,a]=e.getVariable(r),s=n!==r,o=e.isContextBound(r);(s||o)&&!e.isLoopVariable(r)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(i=J(r,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let r=null,n=t.left;for(;n.type==="MemberExpression"&&!n.computed;){if(n.object.type==="Identifier"){r=n;break}n=n.object}if(r){const a=r.object.name,[s,o]=e.getVariable(a);if(s!==a&&!e.isLoopVariable(a)){const l=J(a,e),c=v.createGetCall(l,0);r.object=c}else if(e.isLocalSeriesVar(a)){const l=v.createIdentifier(a);l._skipTransformation=!0,r.object=v.createGetCall(l,0)}}}if(H(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(r,n,a){if(Pe.includes(r.name)&&e.isContextBound(r.name)){const m={type:"MemberExpression",object:{type:"Identifier",name:r.name},property:{type:"Identifier",name:"__value"},computed:!1},x=v.createGetCall(m,0);Object.assign(r,x),delete r.name;return}r.parent=n.parent,K(r,e);const s=r.parent&&r.parent.type==="BinaryExpression",o=r.parent&&r.parent.type==="ConditionalExpression",l=e.isContextBound(r.name)&&!e.isRootParam(r.name),c=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.object===r,h=r.parent&&r.parent._isParamCall,p=r.parent&&r.parent.type==="MemberExpression",u=r.name==="NaN",f=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===z&&r.parent.callee.property.name==="get";(l||o||s)&&(r.type==="MemberExpression"?rt(r,e):r.type==="Identifier"&&!p&&!c&&!h&&!u&&!f&&le(r))},MemberExpression(r,n,a){ie(r,"",e),r.type==="CallExpression"?r.arguments.forEach(s=>a(s,{parent:r,inNamespaceCall:n.inNamespaceCall})):r.object&&a(r.object,{parent:r,inNamespaceCall:n.inNamespaceCall})},CallExpression(r,n,a){const s=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&e.isContextBound(r.callee.object.name);Q(r,e),r.type==="CallExpression"&&(r.callee.type==="MemberExpression"&&a(r.callee,{parent:r,inNamespaceCall:s||n.inNamespaceCall}),r.arguments.forEach(o=>a(o,{parent:r,inNamespaceCall:s||n.inNamespaceCall})))}}),i){let r=t.right;if(t.operator!=="="){const a=t.operator.replace("=",""),s=v.createGetCall(i,0);r={type:"BinaryExpression",operator:a,left:s,right:t.right,start:t.start,end:t.end}}const n=v.createSetCall(i,r);t.start&&(n.start=t.start),t.end&&(n.end=t.end),Object.assign(t,n)}}function fn(t,e){t._skipTransformation||t.declarations.forEach(i=>{if(i.init&&i.init.type==="Identifier"&&Pe.includes(i.init.name)&&e.isContextBound(i.init.name)){const u=i.init.name;Object.assign(i.init,{type:"MemberExpression",object:{type:"Identifier",name:u},property:{type:"Identifier",name:"__value"},computed:!1}),delete i.init.name}const r=i.init&&i.init.type==="MemberExpression"&&i.init.object&&(i.init.object.name==="context"||i.init.object.name===z||i.init.object.name==="context2"),n=i.init&&i.init.type==="MemberExpression"&&i.init.object?.object&&(i.init.object.object.name==="context"||i.init.object.object.name===z||i.init.object.object.name==="context2"),a=i.init&&i.init.type==="ArrowFunctionExpression";if(r){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(u=>{u.key.name&&e.addContextBoundVar(u.key.name)}),i.init.object.name=z;return}if(n){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(u=>{u.key.name&&e.addContextBoundVar(u.key.name)}),i.init.object.object.name=z;return}e.addVariable(i.id.name,t.kind);const s=t.kind,o=e.isArrayPatternElement(i.id.name)&&i.init&&i.init.type==="MemberExpression"&&i.init.computed;i.init&&!a&&!o&&(i.init.type==="CallExpression"&&i.init.callee.type==="MemberExpression"&&i.init.callee.object&&i.init.callee.object.type==="Identifier"&&e.isContextBound(i.init.callee.object.name)?Q(i.init,e):H(i.init,{parent:i.init},{Identifier(u,f){u.parent=f.parent,K(u,e);const m=u.parent&&u.parent.type==="BinaryExpression",x=u.parent&&u.parent.type==="UnaryExpression",_=u.parent&&u.parent.type==="ConditionalExpression",b=u.parent&&u.parent.type==="CallExpression"&&u.parent.callee&&u.parent.callee.object&&u.parent.callee.object.name===z&&u.parent.callee.property.name==="get";u.type==="Identifier"&&(m||x||_)&&!b&&le(u)},CallExpression(u,f,m){u.callee.type==="Identifier"&&(u.callee.parent=u),u.arguments.forEach(x=>{x.type==="Identifier"&&(x.parent=u)}),(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&m(u.callee,{parent:u}),Q(u,e),u.type==="CallExpression"&&(u.callee.type==="MemberExpression"&&m(u.callee,{parent:u}),u.arguments.forEach(x=>m(x,{parent:u})))},BinaryExpression(u,f,m){u.left.type==="Identifier"&&(u.left.parent=u),u.right.type==="Identifier"&&(u.right.parent=u),m(u.left,{parent:u}),m(u.right,{parent:u})},MemberExpression(u,f,m){u.object&&u.object.type==="Identifier"&&(u.object.parent=u),u.property&&u.property.type==="Identifier"&&(u.property.parent=u),ie(u,"",e),u.type==="CallExpression"?u.arguments.forEach(x=>m(x,{parent:u})):u.object&&m(u.object,{parent:u})},AwaitExpression(u,f,m){u.argument&&(u.argument._insideAwait=!0,m(u.argument,{parent:u}),u.argument.type==="Identifier"&&u.argument._wasInsideAwait&&Object.assign(u,u.argument))},ArrowFunctionExpression(u,f,m){if(u.body)if(u.body.type==="BlockStatement"){const x=[];u.body.body.forEach(_=>{e.enterHoistingScope(),m(_,{parent:u.body,insideIIFE:!0});const b=e.exitHoistingScope();x.push(...b),x.push(_)}),u.body.body=x}else m(u.body,{parent:u,insideIIFE:!0})},FunctionExpression(u,f,m){if(u.body&&u.body.type==="BlockStatement"){const x=[];u.body.body.forEach(_=>{e.enterHoistingScope(),m(_,{parent:u.body,insideIIFE:!0});const b=e.exitHoistingScope();x.push(...b),x.push(_)}),u.body.body=x}},SwitchStatement(u,f,m){u.discriminant&&(u.discriminant.parent=u,m(u.discriminant,{parent:u})),u.cases&&u.cases.forEach(x=>{x.parent=u,m(x,{parent:u})})},SwitchCase(u,f,m){if(u.test&&(u.test.parent=u,m(u.test,{parent:u})),u.consequent){const x=[];u.consequent.forEach(_=>{e.enterHoistingScope(),_.parent=u,m(_,{parent:u});const b=e.exitHoistingScope();x.push(...b),x.push(_)}),u.consequent=x}},AssignmentExpression(u,f,m){if(f.insideIIFE){if(u.left.type==="Identifier"){const[x]=e.getVariable(u.left.name);if(x===u.left.name&&!e.isContextBound(u.left.name)){m(u.right,{parent:u});return}}yi(u,e)}}}));const l=J(i.id.name,e),c=!o&&i.init&&i.init.type==="MemberExpression"&&i.init.computed&&i.init.property&&(i.init.property.type==="Literal"||i.init.property.type==="MemberExpression");if(i.init?.property?.type==="MemberExpression"&&(i.init.property._indexTransformed||(rt(i.init.property,e),i.init.property._indexTransformed=!0)),s==="var"){const u=e.getCurrentHoistingScope();if(u){for(const f of u)if(f.type==="VariableDeclaration")for(const m of f.declarations){if(!m.init||m.init.type!=="CallExpression")continue;const x=m.init.callee;if(x?.type!=="MemberExpression")continue;let _;const b=x.property?.name;if(x.object?.type==="Identifier"?_=x.object.name:x.object?.type==="MemberExpression"&&x.object.property?.name&&(_=x.object.property.name),_&&b){const S=`${_}.${b}`;Ws.includes(S)&&(m.init={type:"ArrowFunctionExpression",params:[],body:m.init,expression:!0,async:!1})}}}}let h;i.init?a||o?h=i.init:s==="var"?h=v.createInitVarCall(l,i.init):h=v.createInitCall(l,c?i.init.object:i.init,c?i.init.property:void 0):h=v.createIdentifier("undefined");const p=v.createExpressionStatement(v.createAssignmentExpression(l,h));if(o){const u=i.init.object.name,f=J(u,e),m=i.init.property.value,x={type:"MemberExpression",object:v.createGetCall(f,0),property:{type:"Literal",value:m},computed:!0};p.expression.right=v.createCallExpression(v.createMemberExpression(v.createContextIdentifier(),v.createIdentifier("init")),[l,x])}a&&(e.pushScope("fn"),H(i.init.body,e,{IfStatement(u,f,m){f.pushScope("if"),m(u.consequent,f),u.alternate&&(f.pushScope("els"),m(u.alternate,f),f.popScope()),f.popScope()},VariableDeclaration(u,f){fn(u,f)},Identifier(u,f){K(u,f)},AssignmentExpression(u,f){yi(u,f)},SwitchStatement(u,f,m){u.discriminant.parent=u,m(u.discriminant,f),u.cases.forEach(x=>{x.parent=u,m(x,f)})},SwitchCase(u,f,m){u.test&&(u.test.parent=u,m(u.test,f));const x=[];u.consequent.forEach(_=>{f.enterHoistingScope(),m(_,f);const b=f.exitHoistingScope();x.push(...b),x.push(_)}),u.consequent=x},BlockStatement(u,f,m){const x=[];u.body.forEach(_=>{f.enterHoistingScope(),m(_,f);const b=f.exitHoistingScope();x.push(...b),x.push(_)}),u.body=x}}),e.popScope()),Object.assign(t,p)})}function Js(t,e,i){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){const a=t.init.declarations[0],s=a.id.name;e.addLoopVariable(s,s),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:s},init:a.init}]},a.init&&H(a.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),K(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,le(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),ie(o,"",e),e.popScope(),o.type==="MemberExpression"&&o.object&&(o.object.type!=="Identifier"||!e.isContextBound(o.object.name))&&c(o.object,l)},CallExpression(o,l,c){o.callee.parent=o,c(o.callee,l);for(const h of o.arguments)c(h,l)}})}t.test&&H(t.test,e,{Identifier(a,s){!e.isLoopVariable(a.name)&&!a.computed&&(e.pushScope("for"),K(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,le(a))),e.popScope())},MemberExpression(a,s,o){e.pushScope("for"),ie(a,"",e),e.popScope(),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){a.callee.parent=a,o(a.callee,s);for(const l of a.arguments)o(l,s)}}),t.update&&H(t.update,e,{Identifier(a,s){!e.isLoopVariable(a.name)&&!a.computed&&(e.pushScope("for"),K(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,le(a))),e.popScope())},MemberExpression(a,s,o){e.pushScope("for"),ie(a,"",e),e.popScope(),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){a.callee.parent=a,o(a.callee,s);for(const l of a.arguments)o(l,s)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=Pi(r);if(e.addHoistedStatement(n.counterDecl),e.pushScope("for"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck),t.init&&t.init.type==="VariableDeclaration"){const a=t.init.declarations[0];e.removeLoopVariable(a.id.name)}}function ea(t,e,i){e.setSuppressHoisting(!0),t.test&&H(t.test,e,{Identifier(a,s){a.computed||(K(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,le(a))))},MemberExpression(a,s,o){ie(a,"",e),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){if(a.callee.parent=a,o(a.callee,s),Q(a,s),a.arguments)for(const l of a.arguments)o(l,s)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=Pi(r);e.addHoistedStatement(n.counterDecl),e.pushScope("whl"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck)}function ta(t,e){H(t,e,{MemberExpression(i,r,n){i.object&&i.object.type==="Identifier"&&!e.isContextBound(i.object.name)&&!i.computed&&(i.object.parent=i,n(i.object,r)),ie(i,"",e)},CallExpression(i,r){Q(i,r)},Identifier(i,r){K(i,r);const n=e.getCurrentScopeType()==="if";e.isContextBound(i.name)&&!e.isRootParam(i.name)&&n&&le(i)}})}function ia(t,e,i){t.test&&(e.pushScope("if"),ta(t.test,e),e.popScope()),e.pushScope("if"),i(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),i(t.alternate,e),e.popScope())}function ra(t,e){const i=e.getCurrentScopeType();if(t.argument&&(t.argument.type==="ArrayExpression"?(t.argument.elements=t.argument.elements.map(r=>r.type==="Identifier"?e.isContextBound(r.name)&&!e.isRootParam(r.name)?v.createGetCall(r,0):un(r.name,e):r.type==="MemberExpression"?r.object&&r.object.type==="MemberExpression"&&r.object.object&&r.object.object.type==="Identifier"&&r.object.object.name==="$"&&r.object.property&&["const","let","var","params"].includes(r.object.property.name)?v.createGetCall(r,0):(r.computed&&r.object.type==="Identifier"&&e.isContextBound(r.object.name)&&!e.isRootParam(r.object.name)||ie(r,"",e),r):((r.type==="BinaryExpression"||r.type==="LogicalExpression"||r.type==="ConditionalExpression"||r.type==="CallExpression"||r.type==="UnaryExpression")&&H(r,e,{Identifier(n,a){K(n,a),n.type==="Identifier"&&!n._arrayAccessed&&(le(n),n._arrayAccessed=!0)},MemberExpression(n){ie(n,"",e)},CallExpression(n,a,s){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&s(n.callee,a),Q(n,a),n.type==="CallExpression"&&n.arguments.forEach(o=>s(o,a))},BinaryExpression(n,a,s){s(n.left,a),s(n.right,a)}}),r)),t.argument={type:"ArrayExpression",elements:[t.argument]}):t.argument.type==="ObjectExpression"?t.argument.properties=t.argument.properties.map(r=>r.shorthand?e.isContextBound(r.value.name)?r:(e.getVariable(r.value.name),{type:"Property",key:v.createIdentifier(r.key.name),value:J(r.value.name,e),kind:"init",method:!1,shorthand:!1,computed:!1}):(r.value&&r.value.type==="Identifier"&&(e.isContextBound(r.value.name)&&!e.isRootParam(r.value.name)||e.isContextBound(r.value.name)||(r.value=J(r.value.name,e))),r)):t.argument.type==="Identifier"?(K(t.argument,e),t.argument.type==="Identifier"&&le(t.argument)):t.argument.type==="MemberExpression"&&t.argument.object.type==="Identifier"&&!e.isContextBound(t.argument.object.name)&&!e.isLoopVariable(t.argument.object.name)&&K(t.argument.object,e),i==="fn")){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=v.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)&&(t.argument._indexTransformed||(rt(t.argument,e),t.argument._indexTransformed=!0)):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&H(t.argument,e,{Identifier(n,a){K(n,a),n.type==="Identifier"&&!n._arrayAccessed&&(le(n),n._arrayAccessed=!0)},MemberExpression(n){ie(n,"",e)},CallExpression(n,a,s){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&s(n.callee,a),Q(n,a),n.type==="CallExpression"&&n.arguments.forEach(o=>s(o,a))},BinaryExpression(n,a,s){s(n.left,a),s(n.right,a)},ArrowFunctionExpression(n,a,s){if(n.body)if(n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}else s(n.body,a)},FunctionExpression(n,a,s){if(n.body&&n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}},SwitchStatement(n,a,s){n.discriminant.parent=n,s(n.discriminant,a),n.cases.forEach(o=>{o.parent=n,s(o,a)})},SwitchCase(n,a,s){n.test&&(n.test.parent=n,s(n.test,a));const o=[];n.consequent.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.consequent=o},BlockStatement(n,a,s){const o=[];n.body.forEach(l=>{a.enterHoistingScope(),s(l,a);const c=a.exitHoistingScope();o.push(...c),o.push(l)}),n.body=o}});const r=v.createCallExpression(v.createMemberExpression(v.createContextIdentifier(),v.createIdentifier("precision")),[t.argument]);t.argument=r}}function na(t,e,i){const r=v.createVariableDeclaration("$$",v.createCallExpression(v.createMemberExpression(v.createContextIdentifier(),v.createIdentifier("peekCtx")),[]));r._skipTransformation=!0,e.addLoopVariable("$$","$$"),t.body&&t.body.type==="BlockStatement"&&(t.body.body.unshift(r),e.pushScope("fn"),t.params.forEach(n=>{n.type==="Identifier"&&e.addLocalSeriesVar(n.name)}),i(t.body,e),t.params.forEach(n=>{n.type==="Identifier"&&e.removeLocalSeriesVar(n.name)}),e.popScope())}function sa(t){const e={...N,LineComment:()=>{}};function i(o){return o?o.type==="Identifier"?o.name:o.type==="CallExpression"&&o.callee?.type==="MemberExpression"&&o.callee.object?.name==="$"&&o.callee.property?.name==="get"&&o.arguments?.[0]?.type==="Identifier"?o.arguments[0].name:null:null}const r=new Map;qe(t,{FunctionDeclaration(o){o.id?.name&&r.set(o.id.name,o)}},e);function n(o){let l=!1;const c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return qe(o,{AwaitExpression(){l=!0}},c),l}let a=!0,s=0;for(;a&&s<20;){a=!1,s++,qe(t,{ArrowFunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,a=!0)},FunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,a=!0)}},e);const o=[];qe(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(const c of o){const h={};for(const p of Object.keys(c))h[p]=c[p];h._asyncWrapped=!0;for(const p of Object.keys(c))delete c[p];c.type="AwaitExpression",c.argument=h,a=!0}const l=new Set;for(const[c,h]of r)n(h.body)&&(h.async||(h.async=!0,a=!0),l.add(c));if(l.size>0){const c=[];qe(t,{CallExpression(h){if(!h._asyncWrapped&&h.callee?.type==="MemberExpression"&&h.callee.object?.name==="$"&&h.callee.property?.name==="call"&&h.arguments?.length>0){const p=i(h.arguments[0]);p&&l.has(p)&&c.push(h)}}},e);for(const h of c){const p={};for(const u of Object.keys(h))p[u]=h[u];p._asyncWrapped=!0;for(const u of Object.keys(h))delete h[u];h.type="AwaitExpression",h.argument=p,a=!0}}}}function aa(t){const e={...N,LineComment:()=>{}};qe(t,{BinaryExpression(i){if(i.operator==="=="||i.operator==="==="){const r=v.createMathEqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}else if(i.operator==="!="||i.operator==="!=="){const r=v.createMathNeqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}}},e)}function oa(t,e,i,r={debug:!1,ln:!1},n=[]){const a=s=>{if(!r.debug||!s.loc||!n.length)return null;const o=s.loc.start.line-1;if(o>=0&&o<n.length){const l=n[o].trim();if(l)return{type:"LineComment",value:`${r.ln?` [Line ${s.loc.start.line}]`:""} ${l}`}}return null};H(t,e,{Program(s,o,l){const c=[];s.body.forEach(h=>{o.enterHoistingScope(),l(h,o);const p=o.exitHoistingScope(),u=a(h);u&&c.push(u),c.push(...p),c.push(h)}),s.body=c},BlockStatement(s,o,l){const c=[];s.body.forEach(h=>{o.enterHoistingScope(),l(h,o);const p=o.exitHoistingScope(),u=a(h);u&&c.push(u),c.push(...p),c.push(h)}),s.body=c},ReturnStatement(s,o,l){s.argument&&s.argument.type!=="ArrayExpression"&&s.argument.type!=="ObjectExpression"&&s.argument.type!=="Identifier"&&s.argument.type!=="MemberExpression"&&o.getCurrentScopeType()!=="fn"&&l(s.argument,o),ra(s,o)},VariableDeclaration(s,o){fn(s,o)},Identifier(s,o){K(s,o)},CallExpression(s,o,l){s.callee&&(s.callee.type==="ArrowFunctionExpression"||s.callee.type==="FunctionExpression")?l(s.callee,o):s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&(s.callee.object.parent=s.callee,l(s.callee.object,o)),Q(s,o)},ArrowFunctionExpression(s,o,l){s.body&&l(s.body,o)},FunctionExpression(s,o,l){s.body&&l(s.body,o)},ForOfStatement(s,o,l){if(s.left&&s.left.type==="VariableDeclaration"){s.left._skipTransformation=!0;const p=s.left.declarations[0];p.id.type==="Identifier"?o.addLoopVariable(p.id.name,p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(u=>{u.type==="Identifier"&&o.addLoopVariable(u.name,u.name)})}if(s.right&&s.right.type==="Identifier"){K(s.right,o),s.right.type==="Identifier"&&le(s.right);const p={...s.right};let u=v.createMemberExpression(p,v.createIdentifier("array"),!1);s.left&&s.left.type==="VariableDeclaration"&&s.left.declarations[0].id.type==="ArrayPattern"&&(u=v.createCallExpression(v.createMemberExpression(u,v.createIdentifier("entries"),!1),[])),Object.assign(s.right,u)}else s.right&&l(s.right,o);const c=o.getNextLoopGuardName(),h=Pi(c);if(o.addHoistedStatement(h.counterDecl),s.body&&l(s.body,o),s.body&&s.body.type==="BlockStatement"&&s.body.body.unshift(h.guardCheck),s.left&&s.left.type==="VariableDeclaration"){const p=s.left.declarations[0];p.id.type==="Identifier"?o.removeLoopVariable(p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(u=>{u.type==="Identifier"&&o.removeLoopVariable(u.name)})}},ForInStatement(s,o,l){s.left&&s.left.type==="VariableDeclaration"&&(s.left._skipTransformation=!0),s.right&&s.right.type==="Identifier"?(K(s.right,o),s.right.type==="Identifier"&&le(s.right)):s.right&&l(s.right,o),s.body&&l(s.body,o)},MemberExpression(s,o,l){s.object&&(s.object.type==="CallExpression"||s.object.type==="MemberExpression")&&(s.object.parent=s,l(s.object,o)),s.object&&s.object.type==="Identifier"&&!o.isContextBound(s.object.name)&&(s.object.parent=s,l(s.object,o)),ie(s,i,o)},AssignmentExpression(s,o,l){if(yi(s,o),s.type==="CallExpression"&&s.arguments){const c=h=>{h&&(h.type==="CallExpression"&&h.callee&&(h.callee.type==="ArrowFunctionExpression"||h.callee.type==="FunctionExpression")&&l(h.callee,o),h.type==="BinaryExpression"&&(c(h.left),c(h.right)))};s.arguments.forEach(h=>c(h))}},FunctionDeclaration(s,o,l){na(s,o,l)},ForStatement(s,o,l){Js(s,o,l)},WhileStatement(s,o,l){ea(s,o,l)},IfStatement(s,o,l){ia(s,o,l)},SwitchStatement(s,o,l){s.discriminant.parent=s,l(s.discriminant,o),s.cases.forEach(c=>{c.parent=s,l(c,o)})},SwitchCase(s,o,l){s.test&&(s.test.parent=s,l(s.test,o));const c=[];s.consequent.forEach(h=>{o.enterHoistingScope(),l(h,o);const p=o.exitHoistingScope();c.push(...p),c.push(h)}),s.consequent=c},AwaitExpression(s,o,l){s.argument&&(s.argument._insideAwait=!0,l(s.argument,o),s.argument.type==="Identifier"&&s.argument._wasInsideAwait===!0&&(s.type="Identifier",s.name=s.argument.name,s.argument._wasHoisted&&(s._wasHoisted=s.argument._wasHoisted),delete s.argument))}})}const g={NUMBER:"NUMBER",STRING:"STRING",BOOLEAN:"BOOLEAN",IDENTIFIER:"IDENTIFIER",KEYWORD:"KEYWORD",OPERATOR:"OPERATOR",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",LBRACE:"LBRACE",RBRACE:"RBRACE",COMMA:"COMMA",DOT:"DOT",COLON:"COLON",SEMICOLON:"SEMICOLON",INDENT:"INDENT",DEDENT:"DEDENT",NEWLINE:"NEWLINE",COMMENT:"COMMENT",EOF:"EOF"},la=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),ca=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"];class ha{constructor(e,i,r,n,a=0){this.type=e,this.value=i,this.line=r,this.column=n,this.indent=a}}class ua{source;pos;line;column;tokens;indentStack;atLineStart;parenDepth;bracketDepth;braceDepth;constructor(e){this.source=e,this.pos=0,this.line=1,this.column=1,this.tokens=[],this.indentStack=[0],this.atLineStart=!0,this.parenDepth=0,this.bracketDepth=0,this.braceDepth=0}tokenize(){for(;this.pos<this.source.length;){const e=this.peek();if(e==="\r"){this.advance();continue}if(e===`
|
|
16
|
+
}`}function Ys(t){H(t,null,{VariableDeclaration(e,i,r){e.declarations&&e.declarations.length>0&&e.declarations.forEach(n=>{if(n.init&&n.init.type==="ArrowFunctionExpression"&&n.init.start!==0){const a={type:"FunctionDeclaration",id:n.id,params:n.init.params,body:n.init.body.type==="BlockStatement"?n.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:n.init.body}]},async:n.init.async,generator:!1};Object.assign(e,a)}}),e.body&&e.body.body&&e.body.body.forEach(n=>r(n,i))}})}function Xs(t,e){qe(t,{VariableDeclaration(i){i.declarations.forEach(r=>{const n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===z||r.init.object.name==="context2"),a=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===z||r.init.object.object.name==="context2");(n||a)&&(r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(s=>{s.key.name&&e.addContextBoundVar(s.key.name)}))})}})}function Qs(t,e,i=!1){t.params.forEach(r=>{r.type==="Identifier"&&i&&e.addContextBoundVar(r.name,i)})}function Zs(t,e){let i;return Bs(t,{FunctionDeclaration(r){r.id&&r.id.name&&(e.addReservedName(r.id.name),e.addUserFunction(r.id.name))},ExpressionStatement(r){const n=r.expression;n&&n.type==="AssignmentExpression"&&n.operator==="="&&n.left?.type==="MemberExpression"&&n.left.property?.name==="__pineMethod__"&&n.left.object?.type==="Identifier"&&n.right?.value===!0&&e.addUserMethod(n.left.object.name)},ArrowFunctionExpression(r){const n=r.start===0;n&&r.params&&r.params.length>0&&(i=r.params[0].name,r.params[0].name=z),Qs(r,e,n)},VariableDeclaration(r,n){const a=n.length>1?n[n.length-2]:null,s=a&&(a.type==="ForOfStatement"||a.type==="ForInStatement")&&a.left===r;r.declarations.forEach(o=>{if(o.id.type==="Identifier")e.addReservedName(o.id.name);else if(o.id.type==="ObjectPattern")o.id.properties.forEach(l=>{l.key&&l.key.type==="Identifier"&&e.addReservedName(l.key.name)});else if(o.id.type==="ArrayPattern"){if(o.id.elements?.forEach(u=>{u&&u.type==="Identifier"&&e.addReservedName(u.name)}),s)return;const l=e.generateTempVar(),c={type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:l},init:o.init}]},h=c.declarations[0].init;h&&h.type==="CallExpression"&&(h.callee.type==="ArrowFunctionExpression"||h.callee.type==="FunctionExpression")&&qe(h.callee.body,{ReturnStatement(u){u.argument&&u.argument.type==="ArrayExpression"&&(u.argument={type:"ArrayExpression",elements:[u.argument]})}}),o.id.elements?.forEach(u=>{u.type==="Identifier"&&e.addArrayPatternElement(u.name)});const p=o.id.elements.map((u,f)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:u,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:f},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[c,...p]})}})},ForStatement(r){}}),i}const pi={type:"Identifier",name:"undefined"};function J(t,e){const[i,r]=e.getVariable(t);if((i.match(/^fn\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){const[n]=e.getVariable("$$");if(n)return S.createLocalContextVariableReference(r,i)}return S.createContextVariableReference(r,i)}function un(t,e){const i=J(t,e);return S.createGetCall(i,0)}function rt(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name)){if(t.object.type==="Identifier"&&!e.isLoopVariable(t.object.name)){if(e.isLocalSeriesVar(t.object.name)){const i=S.createIdentifier(t.object.name);i._skipTransformation=!0;const r=S.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){const i=J(t.object.name,e),r=S.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0}}return}e.isContextBound(t.property.name)||(t.property=J(t.property.name,e),t.property=S.createGetCall(t.property,0))}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){const i=S.createIdentifier(t.object.name);i._skipTransformation=!0;const r=S.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=J(t.object.name,e)),t.property.type==="MemberExpression"){const i=t.property;i._indexTransformed||(rt(i,e),i._indexTransformed=!0)}}t.computed&&t.property.type!=="Identifier"&&t.property.type!=="MemberExpression"&&!t._indexTransformed&&(t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression")&&(t.property=Ae(t.property,e))}function le(t,e){const i=S.createGetCall(S.createIdentifier(t.name),0);t.start!==void 0&&(i.start=t.start),t.end!==void 0&&(i.end=t.end),i._indexTransformed=!0,Object.assign(t,i)}function K(t,e){if(!t._skipTransformation&&t.name!==z){if(Pe.includes(t.name)&&e.isContextBound(t.name)){const u=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,f=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!u&&!f){const m={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},x=S.createGetCall(m,0);Object.assign(t,x),delete t.name;return}}if(t.name==="Math"||t.name==="NaN"||t.name==="undefined"||t.name==="Infinity"||t.name==="null"||t.name.startsWith("'")&&t.name.endsWith("'")||t.name.startsWith('"')&&t.name.endsWith('"')||t.name.startsWith("`")&&t.name.endsWith("`")||e.isLoopVariable(t.name))return;let i=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){const u=t.parent.callee;if(u.type==="MemberExpression"&&u.object&&u.object.name===z&&["get","set","init","param","call"].includes(u.property.name)){const f=t.parent.arguments.indexOf(t);u.property.name==="call"?f>=2&&(i=!0):f===0&&(i=!0)}else{const f=u.type==="MemberExpression"&&u.object&&u.object.type==="Identifier"&&it.includes(u.object.name);u.type==="MemberExpression"&&!f?i=!1:i=!0}}const r=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),n=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.property.name==="param";t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left;const a=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,s=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t,o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.property===t&&t.parent.parent&&t.parent.parent.type==="CallExpression"&&t.parent.parent.callee&&t.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.parent.callee.object.name);if(r||n||i||o||a){if(a||t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.object&&t.parent.callee.object.name===z&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;const u=J(t.name,e);Object.assign(t,u);return}const l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){const u=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),f=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,m=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!u&&!f&&!m)return}if(e.isLocalSeriesVar(t.name)){if(!s){const u=S.createIdentifier(t.name),f=S.createGetCall(u,0);Object.assign(t,f)}return}const[c,h]=e.getVariable(t.name);let p;if(l)p=S.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;p=J(t.name,e)}if(s)Object.assign(t,p);else{const u=S.createGetCall(p,0);Object.assign(t,u)}}}function ie(t,e,i){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.object&&t.object.type==="Identifier"&&it.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const l=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,c=t.parent&&(t.parent.type==="VariableDeclarator"&&(t.parent.id.type==="ArrayPattern"||t.parent.id.type==="ObjectPattern")||t.parent.type==="AssignmentExpression"&&(t.parent.left.type==="ArrayPattern"||t.parent.left.type==="ObjectPattern")||t.parent.type==="Property");if(!l&&!c){const h={type:"CallExpression",callee:{type:"MemberExpression",object:t.object,property:t.property,computed:!1},arguments:[],_transformed:!1};t.start!==void 0&&(h.start=t.start),t.end!==void 0&&(h.end=t.end),Object.assign(t,h);return}}if(!t.computed&&t.object&&t.object.type==="Identifier"&&i.isLocalSeriesVar(t.object.name)){const l=S.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=S.createGetCall(l,0);return}const r=i.getCurrentScopeType()=="if",n=i.getCurrentScopeType()=="els",a=i.getCurrentScopeType()=="for";if(!r&&!n&&!a&&t.object&&t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(rt(t,i),t._indexTransformed=!0);const s=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===z||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&i.isContextBound(t.object.name);if(t.computed&&(s||o)){if(t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left===t)return;t.object.type==="Identifier"&&Pe.includes(t.object.name)&&i.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});const l=S.createGetCall(t.object,t.property);t.start&&(l.start=t.start),t.end&&(l.end=t.end),Object.assign(t,l),delete t.object,delete t.property,delete t.computed}}function Nt(t,e){if(t.type==="Identifier"){if(Pe.includes(t.name)&&e.isContextBound(t.name)){const a=t.name;return Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:a},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name,t}if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){const[a,s]=e.getVariable(t.name);return S.createContextVariableReference(s,a)}if(e.isContextBound(t.name))return t;const[i,r]=e.getVariable(t.name),n=i!==t.name;return e.isLocalSeriesVar(t.name)&&!n?t:n?J(t.name,e):i===t.name&&!e.isContextBound(t.name)?t:J(t.name,e)}return t}function Ae(t,e,i=""){switch(t.type){case"BinaryExpression":return fi(t,e,i);case"LogicalExpression":return di(t,e,i);case"MemberExpression":{const r=!t.computed&&t.object.type==="Identifier"&&Pe.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&Pe.includes(t.object.name)&&e.isContextBound(t.object.name)){const s={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return S.createGetCall(s,t.property)}const n=t.object.type==="Identifier"&&!r?Nt(t.object,e):t.object;let a=n;if(!t.computed&&t.object.type==="Identifier"&&!r){const[s]=e.getVariable(t.object.name);s!==t.object.name&&!e.isLoopVariable(t.object.name)&&(a=S.createGetCall(n,0))}return{type:"MemberExpression",object:a,property:t.property,computed:t.computed}}case"Identifier":{if(e.isLoopVariable(t.name)||t.parent&&t.parent.type==="MemberExpression"&&t.parent.property===t)return t;const r=Nt(t,e);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:S.createGetCall(r,0)}case"UnaryExpression":return mi(t,e,i);case"ConditionalExpression":{const r=Ae(t.test,e,i),n=Ae(t.consequent,e,i),a=Ae(t.alternate,e,i);return{type:"ConditionalExpression",test:r,consequent:n,alternate:a,start:t.start,end:t.end}}}return t}function fi(t,e,i){const r=Ae(t.left,e,i),n=Ae(t.right,e,i),a={type:"BinaryExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return H(a,e,{CallExpression(s,o){s._transformed||Q(s,o)},MemberExpression(s){ie(s,"",e)}}),a}function di(t,e,i){const r=Ae(t.left,e,i),n=Ae(t.right,e,i),a={type:"LogicalExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return H(a,e,{CallExpression(s,o){s._transformed||Q(s,o)}}),a}function Yi(t,e,i){H(t,{parent:t,inNamespaceCall:!1},{Identifier(s,o,l){if(s.name=="NaN")return;if(Pe.includes(s.name)&&e.isContextBound(s.name)){if(o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===s&&!o.parent.computed)return;const h={type:"MemberExpression",object:{type:"Identifier",name:s.name},property:{type:"Identifier",name:"__value"},computed:!1},p=S.createGetCall(h,0);Object.assign(s,p),delete s.name;return}s.parent=o.parent,K(s,e);const c=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||c)&&(s.type==="MemberExpression"?rt(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===z&&s.parent.callee.property.name==="get"||le(s)))},MemberExpression(s,o,l){ie(s,"",e),s.object&&l(s.object,{parent:s,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(s,o,l){const c={...o,parent:s};s.test&&l(s.test,c),s.consequent&&l(s.consequent,c),s.alternate&&l(s.alternate,c)},BinaryExpression(s,o,l){const c={...o,parent:s};l(s.left,c),l(s.right,c)},LogicalExpression(s,o,l){const c={...o,parent:s};l(s.left,c),l(s.right,c)},UnaryExpression(s,o,l){const c={...o,parent:s};l(s.argument,c)},CallExpression(s,o,l){const c=s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&s.callee.object.type==="Identifier"&&e.isContextBound(s.callee.object.name);Q(s,e),s.arguments.forEach(h=>l(h,{parent:s,inNamespaceCall:c||o.inNamespaceCall}))}});const r=S.createMemberExpression(S.createIdentifier(i),S.createIdentifier("param")),n=e.generateParamId(),a={type:"CallExpression",callee:r,arguments:[t,pi,{type:"Identifier",name:`'${n}'`}],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){const s=n;e.addLocalSeriesVar(s);const o=S.createVariableDeclaration(s,a);return e.addHoistedStatement(o),S.createIdentifier(s)}return a}function mi(t,e,i){const r=Ae(t.argument,e,i),n={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:r,start:t.start,end:t.end};return H(n,e,{CallExpression(a,s){a._transformed||Q(a,s)},MemberExpression(a){ie(a,"",e)}}),n}function Xe(t,e,i){switch(t?.type){case"BinaryExpression":t=fi(t,i,e);break;case"LogicalExpression":t=di(t,i,e);break;case"ConditionalExpression":return Yi(t,i,e);case"UnaryExpression":t=mi(t,i,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(i.isContextBound(c.name)&&!i.isRootParam(c.name))return c;if(i.isLocalSeriesVar(c.name)){const h=S.createIdentifier(c.name);return S.createGetCall(h,0)}return un(c.name,i)}return c});break}const r=t.type==="MemberExpression"&&t.computed&&t.property,n=t.type==="MemberExpression"&&!t.computed;if(r){t.object.type==="CallExpression"?Q(t.object,i):t.object.type==="MemberExpression"?ie(t.object,"",i):t.object.type==="BinaryExpression"?t.object=fi(t.object,i,e):t.object.type==="LogicalExpression"?t.object=di(t.object,i,e):t.object.type==="ConditionalExpression"?t.object=Yi(t.object,i,e):t.object.type==="UnaryExpression"&&(t.object=mi(t.object,i,e));const c=t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)?t.object:Nt(t.object,i);let h;t.property.type==="Identifier"&&!i.isContextBound(t.property.name)&&!i.isLoopVariable(t.property.name)?h=S.createGetCall(Nt(t.property,i),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?h=Ae(t.property,i,e):h=t.property;const p=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),u=i.generateParamId(),f={type:"CallExpression",callee:p,arguments:[c,h,{type:"Identifier",name:`'${u}'`}],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const m=u;i.addLocalSeriesVar(m);const x=S.createVariableDeclaration(m,f);return i.addHoistedStatement(x),S.createIdentifier(m)}return f}if(n){if(t.object.type==="Identifier"&&it.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const c=t.object.name,h={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:t.property.name},computed:!1},arguments:[],_transformed:!0};c==="ta"&&h.arguments.push(i.getNextTACallId());const p=i.generateTempVar();i.addLocalSeriesVar(p);const u=S.createVariableDeclaration(p,h);return i.addOuterHoistedStatement(u),Object.assign(t,S.createIdentifier(p)),t}if(t.object.type==="Identifier"){const c=t.object.name,[h,p]=i.getVariable(c);if(h!==c&&!i.isLoopVariable(c)){const u=J(c,i),f=S.createGetCall(u,0);t.object=f}else if(i.isLocalSeriesVar(c)){const u=S.createIdentifier(c);u._skipTransformation=!0,t.object=S.createGetCall(u,0)}}else t.object.type==="MemberExpression"?Xe(t.object,e,i):t.object.type==="CallExpression"&&(t.object._transformed||Q(t.object,i))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>c.value.name?i.isContextBound(c.value.name)||i.isLocalSeriesVar(c.value.name)||i.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:S.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:J(c.value.name,i),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=Xe(c.value,e,i)),c))),t.type==="Identifier"){if(Pe.includes(t.name)&&i.isContextBound(t.name)){const c=t.name;Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name}else if(i.isContextBound(t.name)&&!i.isRootParam(t.name)){const c=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),h=i.generateParamId(),p={type:"CallExpression",callee:c,arguments:[t,pi,{type:"Identifier",name:`'${h}'`}],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const u=h;i.addLocalSeriesVar(u);const f=S.createVariableDeclaration(u,p);return i.addHoistedStatement(f),S.createIdentifier(u)}return p}}t?.type==="CallExpression"&&Q(t,i);const a=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),s=t.type==="Identifier"?Nt(t,i):t,o=i.generateParamId(),l={type:"CallExpression",callee:a,arguments:[s,pi,{type:"Identifier",name:`'${o}'`}],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const c=o;i.addLocalSeriesVar(c);const h=S.createVariableDeclaration(c,l);return i.addHoistedStatement(h),S.createIdentifier(c)}return l}function St(t){if(!t)return!1;if(pn(t))return!0;if(t.type==="MemberExpression")return St(t.object);if(t.type==="ChainExpression")return St(t.expression);if(t.type==="CallExpression"){const e=t.callee;if(e?.type==="MemberExpression")return St(e.object);if(e?.type==="ChainExpression")return St(e.expression)}return!1}function pn(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function gi(t,e,i){t&&(t.type==="Identifier"?(t.parent=e,K(t,i)):t.type==="MemberExpression"?gi(t.object,t,i):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&gi(t.callee.object,t.callee,i),t._transformed||Q(t,i)))}function Q(t,e,i){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(it.includes(t.callee.name)||Pe.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=S.createMemberExpression(t.callee,S.createIdentifier("any")));const r=t.callee&&t.callee.type==="MemberExpression"&&t.callee.object&&t.callee.object.type==="Identifier"&&(e.isContextBound(t.callee.object.name)||t.callee.object.name==="math"||t.callee.object.name==="ta");if(r){if(t.callee.object.name===z&&["get","init","param"].includes(t.callee.property.name))return;const n=t.callee.object.name,a=[];if(t.arguments.forEach(h=>{if(h._isParamCall){a.push(h);return}a.push(Xe(h,n,e))}),t.arguments=a,["plot","hline","fill"].includes(n)){const h=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="alert"){const h=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="ta")if(e.getCurrentScopeType()==="fn"){const h=e.getNextTACallId(),[p]=e.getVariable("$$");let u;p?u=S.createMemberExpression(S.createLocalContextIdentifier(),S.createIdentifier("id")):u=S.createLiteral("");const f={type:"BinaryExpression",operator:"+",left:u,right:h};t.arguments.push(f)}else t.arguments.push(e.getNextTACallId());const s=t.callee.property.name,o=`${n}.${s}`,l=$s.includes(o),c=t._insideAwait===!0;if(l&&!c){const h=Object.assign({},t),p=S.createAwaitExpression(h);Object.assign(t,p)}if(!e.shouldSuppressHoisting()){const h=e.generateTempVar();e.addLocalSeriesVar(h);const p=t._insideAwait===!0;let u=Object.assign({},t);p&&(u=S.createAwaitExpression(u));const f=S.createVariableDeclaration(h,u);e.addHoistedStatement(f);const m=S.createIdentifier(h);Object.assign(t,m),t._wasHoisted=!0,t._wasInsideAwait=p;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(n=>n._isParamCall?n:Xe(n,z,e)),!e.isContextBound(t.callee.name)){const n=e.getNextUserCallId(),a=S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("call")),s=[t.callee,n,...t.arguments];t.callee=a,t.arguments=s}t._transformed=!0}if(!r&&t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.property.name,a=e.isUserFunction(n),s=t.callee.object,o=s.type==="Identifier"&&e.isLocalSeriesVar(s.name),l=s.type==="MemberExpression",c=e.isUserMethod(n);if(a&&c&&!e.isContextBound(n)&&!o&&!l){const h=t.callee.object;t.callee.property;const p=t.arguments.map(b=>b._isParamCall?b:Xe(b,z,e));let u=h;h.type==="Identifier"?u=Xe(h,z,e):h.type==="CallExpression"&&(Q(h,e),u=Xe(h,z,e));const f=S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("call")),m=e.getNextUserCallId(),x=S.createIdentifier(n);x._skipTransformation=!0;const _=[x,m,u,...p];t.callee=f,t.arguments=_,t._transformed=!0;return}t.callee.object.type==="Identifier"?K(t.callee.object,e):gi(t.callee.object,t.callee,e)}if(t.arguments.forEach(n=>{H(n,{parent:t},{Identifier(a,s,o){a.parent=s.parent,K(a,e);const l=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||l)&&(a.type==="MemberExpression"?rt(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===z&&a.parent.callee.property.name==="get"||le(a)))},BinaryExpression(a,s,o){const l={...s,parent:a};o(a.left,l),o(a.right,l)},LogicalExpression(a,s,o){const l={...s,parent:a};o(a.left,l),o(a.right,l)},UnaryExpression(a,s,o){const l={...s,parent:a};o(a.argument,l)},CallExpression(a,s,o){a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&(a.callee.object.parent=a.callee,o(a.callee.object,{parent:a.callee})),a._transformed||Q(a,e)},MemberExpression(a,s,o){ie(a,"",e),a.object&&o(a.object,{parent:a})}})}),t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.object,a=pn(n),s=n?.type==="MemberExpression"&&St(n);if(a||s){const o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function Pi(t){const e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},i={type:"IfStatement",test:{type:"BinaryExpression",operator:">",left:{type:"UpdateExpression",operator:"++",prefix:!0,argument:{type:"Identifier",name:t}},right:{type:"Identifier",name:"__maxLoops"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:`Loop exceeded maximum iterations (${t})`}]}},alternate:null};return{counterDecl:e,guardCheck:i}}function yi(t,e){let i=null;if(t.left.type==="Identifier")i=J(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){const r=t.left.object.name,[n,a]=e.getVariable(r),s=n!==r,o=e.isContextBound(r);(s||o)&&!e.isLoopVariable(r)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(i=J(r,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let r=null,n=t.left;for(;n.type==="MemberExpression"&&!n.computed;){if(n.object.type==="Identifier"){r=n;break}n=n.object}if(r){const a=r.object.name,[s,o]=e.getVariable(a);if(s!==a&&!e.isLoopVariable(a)){const l=J(a,e),c=S.createGetCall(l,0);r.object=c}else if(e.isLocalSeriesVar(a)){const l=S.createIdentifier(a);l._skipTransformation=!0,r.object=S.createGetCall(l,0)}}}if(H(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(r,n,a){if(Pe.includes(r.name)&&e.isContextBound(r.name)){const m={type:"MemberExpression",object:{type:"Identifier",name:r.name},property:{type:"Identifier",name:"__value"},computed:!1},x=S.createGetCall(m,0);Object.assign(r,x),delete r.name;return}r.parent=n.parent,K(r,e);const s=r.parent&&r.parent.type==="BinaryExpression",o=r.parent&&r.parent.type==="ConditionalExpression",l=e.isContextBound(r.name)&&!e.isRootParam(r.name),c=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.object===r,h=r.parent&&r.parent._isParamCall,p=r.parent&&r.parent.type==="MemberExpression",u=r.name==="NaN",f=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===z&&r.parent.callee.property.name==="get";(l||o||s)&&(r.type==="MemberExpression"?rt(r,e):r.type==="Identifier"&&!p&&!c&&!h&&!u&&!f&&le(r))},MemberExpression(r,n,a){ie(r,"",e),r.type==="CallExpression"?r.arguments.forEach(s=>a(s,{parent:r,inNamespaceCall:n.inNamespaceCall})):r.object&&a(r.object,{parent:r,inNamespaceCall:n.inNamespaceCall})},CallExpression(r,n,a){const s=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&e.isContextBound(r.callee.object.name);Q(r,e),r.type==="CallExpression"&&(r.callee.type==="MemberExpression"&&a(r.callee,{parent:r,inNamespaceCall:s||n.inNamespaceCall}),r.arguments.forEach(o=>a(o,{parent:r,inNamespaceCall:s||n.inNamespaceCall})))}}),i){let r=t.right;if(t.operator!=="="){const a=t.operator.replace("=",""),s=S.createGetCall(i,0);r={type:"BinaryExpression",operator:a,left:s,right:t.right,start:t.start,end:t.end}}const n=S.createSetCall(i,r);t.start&&(n.start=t.start),t.end&&(n.end=t.end),Object.assign(t,n)}}function fn(t,e){t._skipTransformation||t.declarations.forEach(i=>{if(i.init&&i.init.type==="Identifier"&&Pe.includes(i.init.name)&&e.isContextBound(i.init.name)){const u=i.init.name;Object.assign(i.init,{type:"MemberExpression",object:{type:"Identifier",name:u},property:{type:"Identifier",name:"__value"},computed:!1}),delete i.init.name}const r=i.init&&i.init.type==="MemberExpression"&&i.init.object&&(i.init.object.name==="context"||i.init.object.name===z||i.init.object.name==="context2"),n=i.init&&i.init.type==="MemberExpression"&&i.init.object?.object&&(i.init.object.object.name==="context"||i.init.object.object.name===z||i.init.object.object.name==="context2"),a=i.init&&i.init.type==="ArrowFunctionExpression";if(r){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(u=>{u.key.name&&e.addContextBoundVar(u.key.name)}),i.init.object.name=z;return}if(n){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(u=>{u.key.name&&e.addContextBoundVar(u.key.name)}),i.init.object.object.name=z;return}e.addVariable(i.id.name,t.kind);const s=t.kind,o=e.isArrayPatternElement(i.id.name)&&i.init&&i.init.type==="MemberExpression"&&i.init.computed;i.init&&!a&&!o&&(i.init.type==="CallExpression"&&i.init.callee.type==="MemberExpression"&&i.init.callee.object&&i.init.callee.object.type==="Identifier"&&e.isContextBound(i.init.callee.object.name)?Q(i.init,e):H(i.init,{parent:i.init},{Identifier(u,f){u.parent=f.parent,K(u,e);const m=u.parent&&u.parent.type==="BinaryExpression",x=u.parent&&u.parent.type==="UnaryExpression",_=u.parent&&u.parent.type==="ConditionalExpression",b=u.parent&&u.parent.type==="CallExpression"&&u.parent.callee&&u.parent.callee.object&&u.parent.callee.object.name===z&&u.parent.callee.property.name==="get";u.type==="Identifier"&&(m||x||_)&&!b&&le(u)},CallExpression(u,f,m){u.callee.type==="Identifier"&&(u.callee.parent=u),u.arguments.forEach(x=>{x.type==="Identifier"&&(x.parent=u)}),(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&m(u.callee,{parent:u}),Q(u,e),u.type==="CallExpression"&&(u.callee.type==="MemberExpression"&&m(u.callee,{parent:u}),u.arguments.forEach(x=>m(x,{parent:u})))},BinaryExpression(u,f,m){u.left.type==="Identifier"&&(u.left.parent=u),u.right.type==="Identifier"&&(u.right.parent=u),m(u.left,{parent:u}),m(u.right,{parent:u})},MemberExpression(u,f,m){u.object&&u.object.type==="Identifier"&&(u.object.parent=u),u.property&&u.property.type==="Identifier"&&(u.property.parent=u),ie(u,"",e),u.type==="CallExpression"?u.arguments.forEach(x=>m(x,{parent:u})):u.object&&m(u.object,{parent:u})},AwaitExpression(u,f,m){u.argument&&(u.argument._insideAwait=!0,m(u.argument,{parent:u}),u.argument.type==="Identifier"&&u.argument._wasInsideAwait&&Object.assign(u,u.argument))},ArrowFunctionExpression(u,f,m){if(u.body)if(u.body.type==="BlockStatement"){const x=[];u.body.body.forEach(_=>{e.enterHoistingScope(),m(_,{parent:u.body,insideIIFE:!0});const b=e.exitHoistingScope();x.push(...b),x.push(_)}),u.body.body=x}else m(u.body,{parent:u,insideIIFE:!0})},FunctionExpression(u,f,m){if(u.body&&u.body.type==="BlockStatement"){const x=[];u.body.body.forEach(_=>{e.enterHoistingScope(),m(_,{parent:u.body,insideIIFE:!0});const b=e.exitHoistingScope();x.push(...b),x.push(_)}),u.body.body=x}},SwitchStatement(u,f,m){u.discriminant&&(u.discriminant.parent=u,m(u.discriminant,{parent:u})),u.cases&&u.cases.forEach(x=>{x.parent=u,m(x,{parent:u})})},SwitchCase(u,f,m){if(u.test&&(u.test.parent=u,m(u.test,{parent:u})),u.consequent){const x=[];u.consequent.forEach(_=>{e.enterHoistingScope(),_.parent=u,m(_,{parent:u});const b=e.exitHoistingScope();x.push(...b),x.push(_)}),u.consequent=x}},AssignmentExpression(u,f,m){if(f.insideIIFE){if(u.left.type==="Identifier"){const[x]=e.getVariable(u.left.name);if(x===u.left.name&&!e.isContextBound(u.left.name)){m(u.right,{parent:u});return}}yi(u,e)}}}));const l=J(i.id.name,e),c=!o&&i.init&&i.init.type==="MemberExpression"&&i.init.computed&&i.init.property&&(i.init.property.type==="Literal"||i.init.property.type==="MemberExpression");if(i.init?.property?.type==="MemberExpression"&&(i.init.property._indexTransformed||(rt(i.init.property,e),i.init.property._indexTransformed=!0)),s==="var"){const u=e.getCurrentHoistingScope();if(u){for(const f of u)if(f.type==="VariableDeclaration")for(const m of f.declarations){if(!m.init||m.init.type!=="CallExpression")continue;const x=m.init.callee;if(x?.type!=="MemberExpression")continue;let _;const b=x.property?.name;if(x.object?.type==="Identifier"?_=x.object.name:x.object?.type==="MemberExpression"&&x.object.property?.name&&(_=x.object.property.name),_&&b){const v=`${_}.${b}`;Ws.includes(v)&&(m.init={type:"ArrowFunctionExpression",params:[],body:m.init,expression:!0,async:!1})}}}}let h;i.init?a||o?h=i.init:s==="var"?h=S.createInitVarCall(l,i.init):h=S.createInitCall(l,c?i.init.object:i.init,c?i.init.property:void 0):h=S.createIdentifier("undefined");const p=S.createExpressionStatement(S.createAssignmentExpression(l,h));if(o){const u=i.init.object.name,f=J(u,e),m=i.init.property.value,x={type:"MemberExpression",object:S.createGetCall(f,0),property:{type:"Literal",value:m},computed:!0};p.expression.right=S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("init")),[l,x])}a&&(e.pushScope("fn"),H(i.init.body,e,{IfStatement(u,f,m){f.pushScope("if"),m(u.consequent,f),u.alternate&&(f.pushScope("els"),m(u.alternate,f),f.popScope()),f.popScope()},VariableDeclaration(u,f){fn(u,f)},Identifier(u,f){K(u,f)},AssignmentExpression(u,f){yi(u,f)},SwitchStatement(u,f,m){u.discriminant.parent=u,m(u.discriminant,f),u.cases.forEach(x=>{x.parent=u,m(x,f)})},SwitchCase(u,f,m){u.test&&(u.test.parent=u,m(u.test,f));const x=[];u.consequent.forEach(_=>{f.enterHoistingScope(),m(_,f);const b=f.exitHoistingScope();x.push(...b),x.push(_)}),u.consequent=x},BlockStatement(u,f,m){const x=[];u.body.forEach(_=>{f.enterHoistingScope(),m(_,f);const b=f.exitHoistingScope();x.push(...b),x.push(_)}),u.body=x}}),e.popScope()),Object.assign(t,p)})}function Js(t,e,i){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){const a=t.init.declarations[0],s=a.id.name;e.addLoopVariable(s,s),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:s},init:a.init}]},a.init&&H(a.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),K(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,le(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),ie(o,"",e),e.popScope(),o.type==="MemberExpression"&&o.object&&(o.object.type!=="Identifier"||!e.isContextBound(o.object.name))&&c(o.object,l)},CallExpression(o,l,c){o.callee.parent=o,c(o.callee,l);for(const h of o.arguments)c(h,l)}})}t.test&&H(t.test,e,{Identifier(a,s){!e.isLoopVariable(a.name)&&!a.computed&&(e.pushScope("for"),K(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,le(a))),e.popScope())},MemberExpression(a,s,o){e.pushScope("for"),ie(a,"",e),e.popScope(),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){a.callee.parent=a,o(a.callee,s);for(const l of a.arguments)o(l,s)}}),t.update&&H(t.update,e,{Identifier(a,s){!e.isLoopVariable(a.name)&&!a.computed&&(e.pushScope("for"),K(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,le(a))),e.popScope())},MemberExpression(a,s,o){e.pushScope("for"),ie(a,"",e),e.popScope(),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){a.callee.parent=a,o(a.callee,s);for(const l of a.arguments)o(l,s)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=Pi(r);if(e.addHoistedStatement(n.counterDecl),e.pushScope("for"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck),t.init&&t.init.type==="VariableDeclaration"){const a=t.init.declarations[0];e.removeLoopVariable(a.id.name)}}function ea(t,e,i){e.setSuppressHoisting(!0),t.test&&H(t.test,e,{Identifier(a,s){a.computed||(K(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,le(a))))},MemberExpression(a,s,o){ie(a,"",e),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){if(a.callee.parent=a,o(a.callee,s),Q(a,s),a.arguments)for(const l of a.arguments)o(l,s)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=Pi(r);e.addHoistedStatement(n.counterDecl),e.pushScope("whl"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck)}function ta(t,e){H(t,e,{MemberExpression(i,r,n){i.object&&i.object.type==="Identifier"&&!e.isContextBound(i.object.name)&&!i.computed&&(i.object.parent=i,n(i.object,r)),ie(i,"",e)},CallExpression(i,r){Q(i,r)},Identifier(i,r){K(i,r);const n=e.getCurrentScopeType()==="if";e.isContextBound(i.name)&&!e.isRootParam(i.name)&&n&&le(i)}})}function ia(t,e,i){t.test&&(e.pushScope("if"),ta(t.test,e),e.popScope()),e.pushScope("if"),i(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),i(t.alternate,e),e.popScope())}function ra(t,e){const i=e.getCurrentScopeType();if(t.argument&&(t.argument.type==="ArrayExpression"?(t.argument.elements=t.argument.elements.map(r=>r.type==="Identifier"?e.isContextBound(r.name)&&!e.isRootParam(r.name)?S.createGetCall(r,0):un(r.name,e):r.type==="MemberExpression"?r.object&&r.object.type==="MemberExpression"&&r.object.object&&r.object.object.type==="Identifier"&&r.object.object.name==="$"&&r.object.property&&["const","let","var","params"].includes(r.object.property.name)?S.createGetCall(r,0):(r.computed&&r.object.type==="Identifier"&&e.isContextBound(r.object.name)&&!e.isRootParam(r.object.name)||ie(r,"",e),r):((r.type==="BinaryExpression"||r.type==="LogicalExpression"||r.type==="ConditionalExpression"||r.type==="CallExpression"||r.type==="UnaryExpression")&&H(r,e,{Identifier(n,a){K(n,a),n.type==="Identifier"&&!n._arrayAccessed&&(le(n),n._arrayAccessed=!0)},MemberExpression(n){ie(n,"",e)},CallExpression(n,a,s){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&s(n.callee,a),Q(n,a),n.type==="CallExpression"&&n.arguments.forEach(o=>s(o,a))},BinaryExpression(n,a,s){s(n.left,a),s(n.right,a)}}),r)),t.argument={type:"ArrayExpression",elements:[t.argument]}):t.argument.type==="ObjectExpression"?t.argument.properties=t.argument.properties.map(r=>r.shorthand?e.isContextBound(r.value.name)?r:(e.getVariable(r.value.name),{type:"Property",key:S.createIdentifier(r.key.name),value:J(r.value.name,e),kind:"init",method:!1,shorthand:!1,computed:!1}):(r.value&&r.value.type==="Identifier"&&(e.isContextBound(r.value.name)&&!e.isRootParam(r.value.name)||e.isContextBound(r.value.name)||(r.value=J(r.value.name,e))),r)):t.argument.type==="Identifier"?(K(t.argument,e),t.argument.type==="Identifier"&&le(t.argument)):t.argument.type==="MemberExpression"&&t.argument.object.type==="Identifier"&&!e.isContextBound(t.argument.object.name)&&!e.isLoopVariable(t.argument.object.name)&&K(t.argument.object,e),i==="fn")){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=S.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)&&(t.argument._indexTransformed||(rt(t.argument,e),t.argument._indexTransformed=!0)):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&H(t.argument,e,{Identifier(n,a){K(n,a),n.type==="Identifier"&&!n._arrayAccessed&&(le(n),n._arrayAccessed=!0)},MemberExpression(n){ie(n,"",e)},CallExpression(n,a,s){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&s(n.callee,a),Q(n,a),n.type==="CallExpression"&&n.arguments.forEach(o=>s(o,a))},BinaryExpression(n,a,s){s(n.left,a),s(n.right,a)},ArrowFunctionExpression(n,a,s){if(n.body)if(n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}else s(n.body,a)},FunctionExpression(n,a,s){if(n.body&&n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}},SwitchStatement(n,a,s){n.discriminant.parent=n,s(n.discriminant,a),n.cases.forEach(o=>{o.parent=n,s(o,a)})},SwitchCase(n,a,s){n.test&&(n.test.parent=n,s(n.test,a));const o=[];n.consequent.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.consequent=o},BlockStatement(n,a,s){const o=[];n.body.forEach(l=>{a.enterHoistingScope(),s(l,a);const c=a.exitHoistingScope();o.push(...c),o.push(l)}),n.body=o}});const r=S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("precision")),[t.argument]);t.argument=r}}function na(t,e,i){const r=S.createVariableDeclaration("$$",S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("peekCtx")),[]));r._skipTransformation=!0,e.addLoopVariable("$$","$$"),t.body&&t.body.type==="BlockStatement"&&(t.body.body.unshift(r),e.pushScope("fn"),t.params.forEach(n=>{n.type==="Identifier"&&e.addLocalSeriesVar(n.name)}),i(t.body,e),t.params.forEach(n=>{n.type==="Identifier"&&e.removeLocalSeriesVar(n.name)}),e.popScope())}function sa(t){const e={...N,LineComment:()=>{}};function i(o){return o?o.type==="Identifier"?o.name:o.type==="CallExpression"&&o.callee?.type==="MemberExpression"&&o.callee.object?.name==="$"&&o.callee.property?.name==="get"&&o.arguments?.[0]?.type==="Identifier"?o.arguments[0].name:null:null}const r=new Map;qe(t,{FunctionDeclaration(o){o.id?.name&&r.set(o.id.name,o)}},e);function n(o){let l=!1;const c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return qe(o,{AwaitExpression(){l=!0}},c),l}let a=!0,s=0;for(;a&&s<20;){a=!1,s++,qe(t,{ArrowFunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,a=!0)},FunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,a=!0)}},e);const o=[];qe(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(const c of o){const h={};for(const p of Object.keys(c))h[p]=c[p];h._asyncWrapped=!0;for(const p of Object.keys(c))delete c[p];c.type="AwaitExpression",c.argument=h,a=!0}const l=new Set;for(const[c,h]of r)n(h.body)&&(h.async||(h.async=!0,a=!0),l.add(c));if(l.size>0){const c=[];qe(t,{CallExpression(h){if(!h._asyncWrapped&&h.callee?.type==="MemberExpression"&&h.callee.object?.name==="$"&&h.callee.property?.name==="call"&&h.arguments?.length>0){const p=i(h.arguments[0]);p&&l.has(p)&&c.push(h)}}},e);for(const h of c){const p={};for(const u of Object.keys(h))p[u]=h[u];p._asyncWrapped=!0;for(const u of Object.keys(h))delete h[u];h.type="AwaitExpression",h.argument=p,a=!0}}}}function aa(t){const e={...N,LineComment:()=>{}};qe(t,{BinaryExpression(i){if(i.operator==="=="||i.operator==="==="){const r=S.createMathEqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}else if(i.operator==="!="||i.operator==="!=="){const r=S.createMathNeqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}}},e)}function oa(t,e,i,r={debug:!1,ln:!1},n=[]){const a=s=>{if(!r.debug||!s.loc||!n.length)return null;const o=s.loc.start.line-1;if(o>=0&&o<n.length){const l=n[o].trim();if(l)return{type:"LineComment",value:`${r.ln?` [Line ${s.loc.start.line}]`:""} ${l}`}}return null};H(t,e,{Program(s,o,l){const c=[];s.body.forEach(h=>{o.enterHoistingScope(),l(h,o);const p=o.exitHoistingScope(),u=a(h);u&&c.push(u),c.push(...p),c.push(h)}),s.body=c},BlockStatement(s,o,l){const c=[];s.body.forEach(h=>{o.enterHoistingScope(),l(h,o);const p=o.exitHoistingScope(),u=a(h);u&&c.push(u),c.push(...p),c.push(h)}),s.body=c},ReturnStatement(s,o,l){s.argument&&s.argument.type!=="ArrayExpression"&&s.argument.type!=="ObjectExpression"&&s.argument.type!=="Identifier"&&s.argument.type!=="MemberExpression"&&o.getCurrentScopeType()!=="fn"&&l(s.argument,o),ra(s,o)},VariableDeclaration(s,o){fn(s,o)},Identifier(s,o){K(s,o)},CallExpression(s,o,l){s.callee&&(s.callee.type==="ArrowFunctionExpression"||s.callee.type==="FunctionExpression")?l(s.callee,o):s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&(s.callee.object.parent=s.callee,l(s.callee.object,o)),Q(s,o)},ArrowFunctionExpression(s,o,l){s.body&&l(s.body,o)},FunctionExpression(s,o,l){s.body&&l(s.body,o)},ForOfStatement(s,o,l){if(s.left&&s.left.type==="VariableDeclaration"){s.left._skipTransformation=!0;const p=s.left.declarations[0];p.id.type==="Identifier"?o.addLoopVariable(p.id.name,p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(u=>{u.type==="Identifier"&&o.addLoopVariable(u.name,u.name)})}if(s.right&&s.right.type==="Identifier"){K(s.right,o),s.right.type==="Identifier"&&le(s.right);const p={...s.right};let u=S.createMemberExpression(p,S.createIdentifier("array"),!1);s.left&&s.left.type==="VariableDeclaration"&&s.left.declarations[0].id.type==="ArrayPattern"&&(u=S.createCallExpression(S.createMemberExpression(u,S.createIdentifier("entries"),!1),[])),Object.assign(s.right,u)}else s.right&&l(s.right,o);const c=o.getNextLoopGuardName(),h=Pi(c);if(o.addHoistedStatement(h.counterDecl),s.body&&l(s.body,o),s.body&&s.body.type==="BlockStatement"&&s.body.body.unshift(h.guardCheck),s.left&&s.left.type==="VariableDeclaration"){const p=s.left.declarations[0];p.id.type==="Identifier"?o.removeLoopVariable(p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(u=>{u.type==="Identifier"&&o.removeLoopVariable(u.name)})}},ForInStatement(s,o,l){s.left&&s.left.type==="VariableDeclaration"&&(s.left._skipTransformation=!0),s.right&&s.right.type==="Identifier"?(K(s.right,o),s.right.type==="Identifier"&&le(s.right)):s.right&&l(s.right,o),s.body&&l(s.body,o)},MemberExpression(s,o,l){s.object&&(s.object.type==="CallExpression"||s.object.type==="MemberExpression")&&(s.object.parent=s,l(s.object,o)),s.object&&s.object.type==="Identifier"&&!o.isContextBound(s.object.name)&&(s.object.parent=s,l(s.object,o)),ie(s,i,o)},AssignmentExpression(s,o,l){if(yi(s,o),s.type==="CallExpression"&&s.arguments){const c=h=>{h&&(h.type==="CallExpression"&&h.callee&&(h.callee.type==="ArrowFunctionExpression"||h.callee.type==="FunctionExpression")&&l(h.callee,o),h.type==="BinaryExpression"&&(c(h.left),c(h.right)))};s.arguments.forEach(h=>c(h))}},FunctionDeclaration(s,o,l){na(s,o,l)},ForStatement(s,o,l){Js(s,o,l)},WhileStatement(s,o,l){ea(s,o,l)},IfStatement(s,o,l){ia(s,o,l)},SwitchStatement(s,o,l){s.discriminant.parent=s,l(s.discriminant,o),s.cases.forEach(c=>{c.parent=s,l(c,o)})},SwitchCase(s,o,l){s.test&&(s.test.parent=s,l(s.test,o));const c=[];s.consequent.forEach(h=>{o.enterHoistingScope(),l(h,o);const p=o.exitHoistingScope();c.push(...p),c.push(h)}),s.consequent=c},AwaitExpression(s,o,l){s.argument&&(s.argument._insideAwait=!0,l(s.argument,o),s.argument.type==="Identifier"&&s.argument._wasInsideAwait===!0&&(s.type="Identifier",s.name=s.argument.name,s.argument._wasHoisted&&(s._wasHoisted=s.argument._wasHoisted),delete s.argument))}})}const g={NUMBER:"NUMBER",STRING:"STRING",BOOLEAN:"BOOLEAN",IDENTIFIER:"IDENTIFIER",KEYWORD:"KEYWORD",OPERATOR:"OPERATOR",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",LBRACE:"LBRACE",RBRACE:"RBRACE",COMMA:"COMMA",DOT:"DOT",COLON:"COLON",SEMICOLON:"SEMICOLON",INDENT:"INDENT",DEDENT:"DEDENT",NEWLINE:"NEWLINE",COMMENT:"COMMENT",EOF:"EOF"},la=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),ca=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"];class ha{constructor(e,i,r,n,a=0){this.type=e,this.value=i,this.line=r,this.column=n,this.indent=a}}class ua{source;pos;line;column;tokens;indentStack;atLineStart;parenDepth;bracketDepth;braceDepth;constructor(e){this.source=e,this.pos=0,this.line=1,this.column=1,this.tokens=[],this.indentStack=[0],this.atLineStart=!0,this.parenDepth=0,this.bracketDepth=0,this.braceDepth=0}tokenize(){for(;this.pos<this.source.length;){const e=this.peek();if(e==="\r"){this.advance();continue}if(e===`
|
|
17
17
|
`){this.handleNewline();continue}if(this.atLineStart&&e!==`
|
|
18
18
|
`){this.handleIndentation(),this.atLineStart=!1;continue}if(e===" "||e===" "){this.advance();continue}if(this.pos>=this.source.length)break;if(e==="/"&&this.peek(1)==="/"){this.readComment();continue}if(e==='"'||e==="'"){this.readString();continue}if(e==="#"){this.readColorLiteral();continue}if(this.isDigit(e)){this.readNumber();continue}if(this.isIdentifierStart(e)){this.readIdentifier();continue}if(!this.readOperatorOrPunctuation())throw new Error(`Unexpected character '${e}' at ${this.line}:${this.column}`)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.addToken(g.DEDENT,"",this.getCurrentIndent());return this.addToken(g.EOF,""),this.tokens}handleNewline(){this.parenDepth===0&&this.bracketDepth===0&&this.braceDepth===0&&(this.addToken(g.NEWLINE,`
|
|
19
19
|
`),this.atLineStart=!0),this.advance(),this.line++,this.column=1}handleIndentation(){let e=0,i=0;for(this.pos;this.pos<this.source.length;){const n=this.peek();if(n===" ")i++,this.advance();else if(n===" ")e++,this.advance();else break}if(this.peek()===`
|
|
@@ -117,6 +117,6 @@ ${t}
|
|
|
117
117
|
`);const r=e.body;if(r&&r.body&&r.body.length>0){const n=r.body.length-1,a=r.body[n];a.type==="ExpressionStatement"&&(r.body[n]={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:{type:"Identifier",name:"__result"},right:a.expression},_line:a._line})}i==="for"?this.generateForStatement(e):this.generateWhileStatement(e),this.write(this.indentStr.repeat(this.indent)),this.write(`return __result;
|
|
118
118
|
`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let i=0;i<e.expressions.length;i++)this.generateExpression(e.expressions[i]),i<e.expressions.length-1&&this.write(", ");this.write(")")}getPrecedence(e){switch(e.type){case"Literal":case"Identifier":case"ArrayExpression":case"ObjectExpression":return 20;case"CallExpression":case"MemberExpression":return 19;case"UnaryExpression":case"UpdateExpression":return 15;case"BinaryExpression":case"LogicalExpression":switch(e.operator){case"*":case"/":case"%":return 13;case"+":case"-":return 12;case"<":case"<=":case">":case">=":return 10;case"==":case"!=":return 9;case"and":case"&&":return 5;case"or":case"||":return 4;default:return 0}case"ConditionalExpression":return 3;case"AssignmentExpression":case"AssignmentPattern":return 2;case"SequenceExpression":return 1;default:return 0}}}function dn(t){const e=/^\s*\/\/\s*@version\s*=\s*(\d+)\s*$/im,i=t.match(e);return i&&i[1]?parseInt(i[1],10):null}function Sa(t,e={}){const i=dn(t);if(i===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(i<5)return{success:!1,version:i,error:`Pine Script version ${i} is not supported. Only version 5 and above are supported.`};try{const r=new ua(t).tokenize(),n=new ba(r).parse(),a={...e,sourceCode:t},s=new va(a).generate(n);return{success:!0,version:i,code:s,ast:n,tokens:r}}catch(r){return{success:!1,version:i,error:r.message,stack:r.stack}}}function Ea(t){if(typeof t=="function")return t.toString();{const e=dn(t);if(e===null)return t;if(e>=5){const i=Sa(t);if(i.success)return i.code;throw new Error(`Failed to transpile Pine Script version ${e}: ${i.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function Na(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});const{debug:i}=e;let r=Ea(t);r=Gs(r);const n=i?r.split(`
|
|
119
119
|
`):[],a=an(r,{ecmaVersion:"latest",sourceType:"module",locations:i});Ys(a),zs(a),qs(a);const s=new js;Xs(a,s);const o=Zs(a,s)||"";if(oa(a,s,o,e,n),aa(a),sa(a),a.type==="Program"&&a.body.length>0){const p=a.body[0],u=p?.expression||p;u.body?.type==="BlockStatement"&&u.body.body.unshift({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"__maxLoops"},init:{type:"LogicalExpression",operator:"||",left:{type:"MemberExpression",object:{type:"Identifier",name:"$"},property:{type:"Identifier",name:"__maxLoops"},computed:!1},right:{type:"Literal",value:5e5}}}]})}const l=Rs||ki||void 0,c=Object.assign({},l,{LineComment(p,u){u.write("//"+p.value)}}),h=ln(a,{generator:c,comments:i});return new Function("",`var _r = ${h}
|
|
120
|
-
; return _r;`)(this)}function Ca(t){return e=>new D(e.array.map(i=>Math.abs(i)),e.type,t)}function Ia(t){return e=>{let i=0,r=0;for(const n of e.array){const a=Number(n);isNaN(a)||(r++,i+=(a-i)/r)}return r===0?NaN:t.precision(i)}}function ka(t){return(e,i)=>{const r=e.array;let n=0,a=r.length-1;for(;n<=a;){const s=Math.floor((n+a)/2),o=r[s];if(o===i)return s;o<i?n=s+1:a=s-1}return-1}}function Aa(t){return(e,i)=>{const r=e.array;let n=0,a=r.length;for(;n<a;){const s=Math.floor((n+a)/2);r[s]<i?n=s+1:a=s}return n<r.length&&r[n]===i?n:n-1}}function Ta(t){return(e,i)=>{const r=e.array;let n=0,a=r.length;for(;n<a;){const s=Math.floor((n+a)/2);r[s]<=i?n=s+1:a=s}return n>0&&r[n-1]===i?n-1:n}}function Pa(t){return e=>{e.array.length=0}}function Da(t){return(e,i)=>(e.array.push(...i.array),e)}function Ma(t){return e=>new D([...e.array],e.type,t)}function Ra(t){return(e,i,r=!0)=>{const n=e.array,a=i.array;if(n.length!==a.length)return NaN;let s=0,o=0,l=0;const c=[];for(let m=0;m<n.length;m++){const x=Number(n[m]),_=Number(a[m]);!isNaN(x)&&x!==null&&x!==void 0&&!isNaN(_)&&_!==null&&_!==void 0&&(s+=x,o+=_,l++,c.push(m))}if(l===0)return NaN;const h=s/l,p=o/l;let u=0;for(const m of c){const x=Number(n[m]),_=Number(a[m]);u+=(x-h)*(_-p)}const f=r?l:l-1;return f<=0?NaN:t.precision(u/f)}}function Va(t){return e=>e.array.every(i=>!isNaN(i)&&i)}function Oa(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?T.int:T.float:t.every(e=>typeof e=="string")?T.string:t.every(e=>typeof e=="boolean")?T.bool:T.any}function be(t){return typeof t=="number"?Number.isInteger(t)?T.int:T.float:typeof t=="string"?T.string:typeof t=="boolean"?T.bool:T.any}function At(t,e){if(typeof t=="number"&&isNaN(t)||e===T.any)return!0;switch(e){case T.int:return Number.isInteger(t)||isNaN(t);case T.float:return typeof t=="number";case T.string:return typeof t=="string";case T.bool:return typeof t=="boolean";case T.box:case T.label:case T.line:case T.linefill:case T.table:case T.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function La(t){return(e,i,r=0,n)=>{const a=e.array.length,s=n!==void 0?Math.min(n,a):a;for(let o=r;o<s;o++){if(!At(i,e.type))throw new Error(`Cannot call 'array.fill' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array[o]=typeof i=="number"?t.precision(i):i}}}function ja(t){return e=>e.array.length>0?e.array[0]:t.NA}function Ba(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[i])}function Fa(t){return(e,i)=>e.array.includes(i)}function $a(t){return(e,i)=>typeof i=="number"&&i!==i?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(i)}function Wa(t){return(e,i,r)=>{if(!At(r,e.type))throw new Error(`Cannot call 'array.insert' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(i,0,r)}}function Ua(t){return(e,i=",")=>e.array.join(i)}function qa(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function za(t){return(e,i)=>e.array.lastIndexOf(i)}function Ka(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let a=1;a<r.length;a++)r[a]>n&&(n=r[a]);return n??t.NA}return[...r].sort((n,a)=>a-n)[i]??t.NA}}function Ha(t){return e=>{const i=e.array;if(i.length===0)return NaN;const r=new Array(i.length);for(let a=0;a<i.length;a++)r[a]=i[a];r.sort((a,s)=>a-s);const n=Math.floor(r.length/2);return r.length%2!==0?r[n]:(r[n-1]+r[n])/2}}function Ga(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let a=1;a<r.length;a++)r[a]<n&&(n=r[a]);return n??t.NA}return[...r].sort((n,a)=>n-a)[i]??t.NA}}function Ya(t){return e=>{if(e.array.length===0)return NaN;const i=new Map;let r=0;for(const a of e.array){const s=(i.get(a)||0)+1;i.set(a,s),s>r&&(r=s)}const n=[];for(const[a,s]of i)s===r&&n.push(a);return n.sort((a,s)=>typeof a=="number"&&typeof s=="number"?a-s:typeof a=="string"&&typeof s=="string"?a<s?-1:a>s?1:0:0),n[0]}}function Xa(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const a=new Array(n);for(let c=0;c<n;c++){const h=Number(r[c]);if(isNaN(h)||h===null||h===void 0)return NaN;a[c]=h}a.sort((c,h)=>c-h),i<0&&(i=0),i>100&&(i=100);const s=i/100*n-.5;if(s<=0)return t.precision(a[0]);if(s>=n-1)return t.precision(a[n-1]);const o=Math.floor(s),l=s-o;return t.precision(a[o]*(1-l)+a[o+1]*l)}}function Qa(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const a=new Array;for(let o=0;o<n;o++){const l=Number(r[o]);!isNaN(l)&&l!==null&&l!==void 0&&a.push(l)}if(a.length===0)return NaN;a.sort((o,l)=>o-l),i<0&&(i=0),i>100&&(i=100);const s=Math.ceil(i/100*n);return s<=0?a[0]:s>a.length?NaN:a[s-1]}}function Za(t){return(e,i)=>{if(e.array.length===0)return NaN;const r=Math.floor(i);if(r<0||r>=e.array.length)return NaN;const n=Number(e.array[r]);if(isNaN(n)||n===null||n===void 0)return NaN;let a=0;for(const o of e.array){const l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<n&&a++}const s=e.array.length-1;return s<=0?NaN:a/s*100}}function Ja(t){return e=>e.array.pop()}function eo(t){return(e,i)=>{if(!At(i,e.type))throw new Error(`Cannot call 'array.push' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.push(typeof i=="number"?t.precision(i):i)}}function to(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function io(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(i,1)[0])}function ro(t){return e=>{e.array.reverse()}}function no(t){return(e,i,r)=>{if(!At(r,e.type))throw new Error(`Cannot call 'array.set' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>=e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[i]=typeof r=="number"?t.precision(r):r}}function so(t){return e=>e.array.shift()}function ao(t){return e=>e.array.length}function oo(t){return(e,i,r)=>{const n=r!==void 0?r:void 0;return new D(e.array.slice(i,n),e.type,t)}}function lo(t){return e=>e.array.some(i=>!isNaN(i)&&i)}var ft=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(ft||{}),mn=(t=>(t.AED="AED",t.ARS="ARS",t.AUD="AUD",t.BDT="BDT",t.BHD="BHD",t.BRL="BRL",t.BTC="BTC",t.CAD="CAD",t.CHF="CHF",t.CLP="CLP",t.CNY="CNY",t.COP="COP",t.CZK="CZK",t.DKK="DKK",t.EGP="EGP",t.ETH="ETH",t.EUR="EUR",t.GBP="GBP",t.HKD="HKD",t.HUF="HUF",t.IDR="IDR",t.ILS="ILS",t.INR="INR",t.ISK="ISK",t.JPY="JPY",t.KES="KES",t.KRW="KRW",t.KWD="KWD",t.LKR="LKR",t.MAD="MAD",t.MXN="MXN",t.MYR="MYR",t.NGN="NGN",t.NOK="NOK",t.NONE="NONE",t.NZD="NZD",t.PEN="PEN",t.PHP="PHP",t.PKR="PKR",t.PLN="PLN",t.QAR="QAR",t.RON="RON",t.RSD="RSD",t.RUB="RUB",t.SAR="SAR",t.SEK="SEK",t.SGD="SGD",t.THB="THB",t.TND="TND",t.TRY="TRY",t.TWD="TWD",t.USD="USD",t.USDT="USDT",t.VES="VES",t.VND="VND",t.ZAR="ZAR",t))(mn||{}),gn=(t=>(t[t.sunday=1]="sunday",t[t.monday=2]="monday",t[t.tuesday=3]="tuesday",t[t.wednesday=4]="wednesday",t[t.thursday=5]="thursday",t[t.friday=6]="friday",t[t.saturday=7]="saturday",t))(gn||{}),yn=(t=>(t.all="all",t.data_window="data_window",t.none="none",t.pane="pane",t.price_scale="price_scale",t.status_line="status_line",t))(yn||{}),xn=(t=>(t.flag="shape_flag",t.arrowdown="shape_arrow_down",t.arrowup="shape_arrow_up",t.circle="shape_circle",t.cross="shape_cross",t.diamond="shape_diamond",t.labeldown="shape_label_down",t.labelup="shape_label_up",t.square="shape_square",t.triangledown="shape_triangle_down",t.triangleup="shape_triangle_up",t.xcross="shape_xcross",t))(xn||{}),_n=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(_n||{}),bn=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(bn||{}),wn=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(wn||{}),co=(t=>(t.linestyle_dashed="linestyle_dashed",t.linestyle_dotted="linestyle_dotted",t.linestyle_solid="linestyle_solid",t.style_area="style_area",t.style_areabr="style_areabr",t.style_circles="style_circles",t.style_columns="style_columns",t.style_cross="style_cross",t.style_histogram="style_histogram",t.style_line="style_line",t.style_linebr="style_linebr",t.style_stepline="style_stepline",t.style_stepline_diamond="style_stepline_diamond",t.style_steplinebr="style_steplinebr",t))(co||{}),vn=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(vn||{}),Sn=(t=>(t.bar_index="bi",t.bar_time="bt",t))(Sn||{}),En=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(En||{}),Nn=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(Nn||{}),Cn=(t=>(t.align_bottom="bottom",t.align_top="top",t.align_left="left",t.align_center="center",t.align_right="right",t.wrap_auto="auto",t.wrap_none="none",t.format_bold="bold",t.format_italic="italic",t.format_none="none",t))(Cn||{}),In=(t=>(t.family_default="default",t.family_monospace="monospace",t))(In||{}),kn=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(kn||{}),An=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(An||{}),Tn=(t=>(t.actual="earnings_actual",t.estimate="earnings_estimate",t.standardized="earnings_standardized",t.future_eps="earnings_future_eps",t.future_period_end_time="earnings_future_period_end_time",t.future_revenue="earnings_future_revenue",t.future_time="earnings_future_time",t))(Tn||{}),Pn=(t=>(t.gross="dividends_gross",t.net="dividends_net",t.future_amount="dividends_future_amount",t.future_ex_date="dividends_future_ex_date",t.future_pay_date="dividends_future_pay_date",t))(Pn||{}),Dn=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(Dn||{}),Mn=(t=>(t.top_left="top_left",t.top_center="top_center",t.top_right="top_right",t.middle_left="middle_left",t.middle_center="middle_center",t.middle_right="middle_right",t.bottom_left="bottom_left",t.bottom_center="bottom_center",t.bottom_right="bottom_right",t))(Mn||{}),Rn=(t=>(t.left="left",t.none="none",t.right="right",t))(Rn||{}),Vn=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(Vn||{});const ho={order:ft,currency:mn,dayofweek:gn,display:yn,shape:xn,location:_n,size:bn,format:wn,barmerge:vn,xloc:Sn,yloc:En,extend:Nn,text:Cn,font:In,adjustment:kn,backadjustment:An,earnings:Tn,dividends:Pn,splits:Dn,position:Mn,scale:Rn,settlement_as_close:Vn};function uo(t){return(e,i=ft.ascending)=>{e.array.sort((r,n)=>{let a=isNaN(r)?1/0:r,s=isNaN(n)?1/0:n;return i===ft.ascending?a-s:s-a})}}function po(t){return(e,i=ft.ascending)=>{const r=e.array.map((n,a)=>a);return r.sort((n,a)=>{const s=isNaN(e.array[n])?1/0:e.array[n],o=isNaN(e.array[a])?1/0:e.array[a];return i===ft.ascending?s-o:o-s}),new D(r,T.int,t)}}function fo(t){return e=>{const i=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new D(e.array.map(()=>NaN),T.int,t):r===0?new D(e.array.map(()=>1),T.int,t):new D(e.array.map(n=>(n-i)/r),T.int,t)}}function mo(t){return(e,i=!0)=>{const r=e.array,n=r.length;if(n===0)return NaN;let a=0,s=0,o=0;for(let h=0;h<n;h++){const p=Number(r[h]);!isNaN(p)&&p!==null&&p!==void 0&&(a+=p,s+=p*p,o++)}if(o===0)return NaN;const l=a/o;let c=s/o-l*l;return c<0?NaN:(!i&&o>1&&(c=c*o/(o-1)),!i&&o===1?0:t.precision(Math.sqrt(c)))}}function go(t){return e=>t.precision(e.array.reduce((i,r)=>{const n=Number(r);return isNaN(n)?i:i+n},0))}function yo(t){return(e,i)=>{if(!At(i,e.type))throw new Error(`Cannot call 'array.unshift' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.unshift(typeof i=="number"?t.precision(i):i)}}function xo(t){return(e,i=!0)=>{let r=0,n=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,n++)}if(n===0)return NaN;const a=r/n;let s=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(s+=(c-a)*(c-a))}const o=i?n:n-1;return o<=0?NaN:t.precision(s/o)}}var T=(t=>(t.any="",t.box="box",t.bool="bool",t.color="color",t.float="float",t.int="int",t.label="label",t.line="line",t.linefill="linefill",t.string="string",t.table="table",t))(T||{});class D{constructor(e,i,r){this.array=e,this.type=i,this.context=r,this._abs=Ca(this.context),this._avg=Ia(this.context),this._binary_search=ka(this.context),this._binary_search_leftmost=Aa(this.context),this._binary_search_rightmost=Ta(this.context),this._clear=Pa(this.context),this._concat=Da(this.context),this._copy=Ma(this.context),this._covariance=Ra(this.context),this._every=Va(this.context),this._fill=La(this.context),this._first=ja(this.context),this._get=Ba(this.context),this._includes=Fa(this.context),this._indexof=$a(this.context),this._insert=Wa(this.context),this._join=Ua(this.context),this._last=qa(this.context),this._lastindexof=za(this.context),this._max=Ka(this.context),this._median=Ha(this.context),this._min=Ga(this.context),this._mode=Ya(this.context),this._percentile_linear_interpolation=Xa(this.context),this._percentile_nearest_rank=Qa(this.context),this._percentrank=Za(this.context),this._pop=Ja(this.context),this._push=eo(this.context),this._range=to(this.context),this._remove=io(this.context),this._reverse=ro(this.context),this._set=no(this.context),this._shift=so(this.context),this._size=ao(this.context),this._slice=oo(this.context),this._some=lo(this.context),this._sort=uo(this.context),this._sort_indices=po(this.context),this._standardize=fo(this.context),this._stdev=mo(this.context),this._sum=go(this.context),this._unshift=yo(this.context),this._variance=xo(this.context)}_abs;_avg;_binary_search;_binary_search_leftmost;_binary_search_rightmost;_clear;_concat;_copy;_covariance;_every;_fill;_first;_get;_includes;_indexof;_insert;_join;_last;_lastindexof;_max;_median;_min;_mode;_percentile_linear_interpolation;_percentile_nearest_rank;_percentrank;_pop;_push;_range;_remove;_reverse;_set;_shift;_size;_slice;_some;_sort;_sort_indices;_standardize;_stdev;_sum;_unshift;_variance;toString(){return"["+this.array.toString().replace(/,/g,", ")+"]"}[Symbol.iterator](){return this.array[Symbol.iterator]()}abs(...e){return this._abs(this,...e)}avg(...e){return this._avg(this,...e)}binary_search(...e){return this._binary_search(this,...e)}binary_search_leftmost(...e){return this._binary_search_leftmost(this,...e)}binary_search_rightmost(...e){return this._binary_search_rightmost(this,...e)}clear(...e){return this._clear(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}covariance(...e){return this._covariance(this,...e)}every(...e){return this._every(this,...e)}fill(...e){return this._fill(this,...e)}first(...e){return this._first(this,...e)}get(...e){return this._get(this,...e)}includes(...e){return this._includes(this,...e)}indexof(...e){return this._indexof(this,...e)}insert(...e){return this._insert(this,...e)}join(...e){return this._join(this,...e)}last(...e){return this._last(this,...e)}lastindexof(...e){return this._lastindexof(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}percentile_linear_interpolation(...e){return this._percentile_linear_interpolation(this,...e)}percentile_nearest_rank(...e){return this._percentile_nearest_rank(this,...e)}percentrank(...e){return this._percentrank(this,...e)}pop(...e){return this._pop(this,...e)}push(...e){return this._push(this,...e)}range(...e){return this._range(this,...e)}remove(...e){return this._remove(this,...e)}reverse(...e){return this._reverse(this,...e)}set(...e){return this._set(this,...e)}shift(...e){return this._shift(this,...e)}size(...e){return this._size(this,...e)}slice(...e){return this._slice(this,...e)}some(...e){return this._some(this,...e)}sort(...e){return this._sort(this,...e)}sort_indices(...e){return this._sort_indices(this,...e)}standardize(...e){return this._standardize(this,...e)}stdev(...e){return this._stdev(this,...e)}sum(...e){return this._sum(this,...e)}unshift(...e){return this._unshift(this,...e)}variance(...e){return this._variance(this,...e)}}function _o(t){return(...e)=>new D([...e],Oa(e),t)}function bo(t){return(e,i)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(i===void 0){const n=r?Array(r).fill(0):[];return new D(n,T.any,t)}return new D(Array(r).fill(t.precision(i||0)),be(i||0),t)}}function wo(t){return(e=0,i=!1)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.bool,t)}}function vo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.box,t)}}function So(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.color,t)}}function Eo(t){return(e=0,i=NaN)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(t.precision(i)),T.float,t)}}function No(t){return(e=0,i=0)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(t.precision(i)),T.int,t)}}function Co(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.label,t)}}function Io(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.line,t)}}function ko(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.linefill,t)}}function Ao(t){return(e=0,i="")=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.string,t)}}function To(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.table,t)}}class y{constructor(e,i=0){this.data=e,this.offset=i}get(e){const i=this.data.length-1-(this.offset+e);return i<0||i>=this.data.length?NaN:this.data[i]}set(e,i){const r=this.data.length-1-(this.offset+e);r>=0&&r<this.data.length&&(this.data[r]=i)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof y?e:Array.isArray(e)?new y(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof y?e.__value:new y([e])}}function Po(t){return(e,i=0)=>y.from(e).get(i)}class Do{constructor(e){this.context=e,this.abs=(i,...r)=>i.abs(...r),this.avg=(i,...r)=>i.avg(...r),this.binary_search=(i,...r)=>i.binary_search(...r),this.binary_search_leftmost=(i,...r)=>i.binary_search_leftmost(...r),this.binary_search_rightmost=(i,...r)=>i.binary_search_rightmost(...r),this.clear=(i,...r)=>i.clear(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.covariance=(i,...r)=>i.covariance(...r),this.every=(i,...r)=>i.every(...r),this.fill=(i,...r)=>i.fill(...r),this.first=(i,...r)=>i.first(...r),this.from=_o(e),this.get=(i,...r)=>i.get(...r),this.includes=(i,...r)=>i.includes(...r),this.indexof=(i,...r)=>i.indexof(...r),this.insert=(i,...r)=>i.insert(...r),this.join=(i,...r)=>i.join(...r),this.last=(i,...r)=>i.last(...r),this.lastindexof=(i,...r)=>i.lastindexof(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.new=bo(e),this.new_bool=wo(e),this.new_box=vo(e),this.new_color=So(e),this.new_float=Eo(e),this.new_int=No(e),this.new_label=Co(e),this.new_line=Io(e),this.new_linefill=ko(e),this.new_string=Ao(e),this.new_table=To(e),this.param=Po(),this.percentile_linear_interpolation=(i,...r)=>i.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(i,...r)=>i.percentile_nearest_rank(...r),this.percentrank=(i,...r)=>i.percentrank(...r),this.pop=(i,...r)=>i.pop(...r),this.push=(i,...r)=>i.push(...r),this.range=(i,...r)=>i.range(...r),this.remove=(i,...r)=>i.remove(...r),this.reverse=(i,...r)=>i.reverse(...r),this.set=(i,...r)=>i.set(...r),this.shift=(i,...r)=>i.shift(...r),this.size=(i,...r)=>i.size(...r),this.slice=(i,...r)=>i.slice(...r),this.some=(i,...r)=>i.some(...r),this.sort=(i,...r)=>i.sort(...r),this.sort_indices=(i,...r)=>i.sort_indices(...r),this.standardize=(i,...r)=>i.standardize(...r),this.stdev=(i,...r)=>i.stdev(...r),this.sum=(i,...r)=>i.sum(...r),this.unshift=(i,...r)=>i.unshift(...r),this.variance=(i,...r)=>i.variance(...r)}}function Mo(t){return e=>{e.map.clear()}}function Ro(t){return(e,i)=>e.map.has(i)}function Vo(t){return e=>{const i=new On(t);return i.map=new Map(e.map),i}}function Oo(t){return(e,i)=>{const r=e.map.get(i);return r===void 0?NaN:r}}function Lo(t){return e=>{const i=Array.from(e.map.keys()),r=be(i[0]);return new D(i,r,t)}}function jo(t){return(e,i,r)=>{const n=e.map.get(i);return e.map.set(i,r),n===void 0?NaN:n}}function Bo(t){return(e,i)=>{for(const[r,n]of i.map)e.map.set(r,n)}}function Fo(t){return(e,i)=>{const r=e.map.get(i);return e.map.delete(i)?r:NaN}}function $o(t){return e=>e.map.size}function Wo(t){return e=>{const i=Array.from(e.map.values()),r=be(i[0]);return new D(i,r,t)}}class On{constructor(e){this.context=e,this.map=new Map,this._clear=Mo(this.context),this._contains=Ro(this.context),this._copy=Vo(this.context),this._get=Oo(this.context),this._keys=Lo(this.context),this._put=jo(this.context),this._put_all=Bo(this.context),this._remove=Fo(this.context),this._size=$o(this.context),this._values=Wo(this.context)}map;_clear;_contains;_copy;_get;_keys;_put;_put_all;_remove;_size;_values;toString(){return`PineMapObject(${this.map.size})`}clear(...e){return this._clear(this,...e)}contains(...e){return this._contains(this,...e)}copy(...e){return this._copy(this,...e)}get(...e){return this._get(this,...e)}keys(...e){return this._keys(this,...e)}put(...e){return this._put(this,...e)}put_all(...e){return this._put_all(this,...e)}remove(...e){return this._remove(this,...e)}size(...e){return this._size(this,...e)}values(...e){return this._values(this,...e)}}function Uo(t){return()=>new On(t)}function qo(t){return(e,i=0)=>y.from(e).get(i)}class zo{constructor(e){this.context=e,this.clear=(i,...r)=>i.clear(...r),this.contains=(i,...r)=>i.contains(...r),this.copy=(i,...r)=>i.copy(...r),this.get=(i,...r)=>i.get(...r),this.keys=(i,...r)=>i.keys(...r),this.new=Uo(e),this.param=qo(),this.put=(i,...r)=>i.put(...r),this.put_all=(i,...r)=>i.put_all(...r),this.remove=(i,...r)=>i.remove(...r),this.size=(i,...r)=>i.size(...r),this.values=(i,...r)=>i.values(...r)}}function Ko(t){return(e,i,r)=>{const n=e.matrix.length;let a=[];if(r&&(r instanceof D?a=r.array:Array.isArray(r)?a=r:a=[r]),n===0){for(let l=0;l<a.length;l++){let c=a[l];c instanceof y&&(c=c.get(0)),e.matrix.push([c])}return}const s=e.matrix[0].length,o=i!==void 0?i:s;for(let l=0;l<n;l++){let c=l<a.length?a[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function Ho(t){return(e,i,r)=>{const n=e.matrix.length;let a=[];if(r)if(r instanceof D)a=r.array;else if(Array.isArray(r))a=r;else if(r instanceof y){const c=r.get(0);Array.isArray(c)?a=c:a=[c]}else a=[r];const s=n>0?e.matrix[0].length:a.length,o=i!==void 0?i:n,l=[];for(let c=0;c<s;c++)if(c<a.length){let h=a[c];h instanceof y&&(h=h.get(0)),l.push(h)}else l.push(NaN);e.matrix.splice(o,0,l)}}function Go(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;if(r===0)return NaN;let n=0,a=0;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(n+=l,a++)}return a===0?NaN:n/a}}function Yo(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i<0||i>=n){t.warn(`Column index ${i} is out of bounds, matrix has ${n} columns.`,"matrix.col");const o=r>0?be(e.matrix[0][0]):"float";return new D([],o,t)}const a=[];for(let o=0;o<r;o++)a.push(e.matrix[o][i]);const s=be(a[0]);return new D(a,s,t)}}function Xo(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function Qo(t){return(e,i)=>{const r=e.matrix.length,n=i.matrix.length;if(r===0){for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]]);return}const a=e.matrix[0].length,s=n>0?i.matrix[0].length:0;if(a!==s&&n>0){console.error(`matrix.concat: Column count mismatch ${a} vs ${s}`);return}for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]])}}function Zo(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0,n=new F(i,r,NaN,t);return n.matrix=e.matrix.map(a=>[...a]),n}}function Jo(t){const e=t.length;if(e===0)return 0;if(e===1)return t[0][0];if(e===2)return t[0][0]*t[1][1]-t[0][1]*t[1][0];const i=t.map(n=>[...n]);let r=1;for(let n=0;n<e;n++){let a=n;for(;a<e&&i[a][n]===0;)a++;if(a===e)return 0;a!==n&&([i[n],i[a]]=[i[a],i[n]],r*=-1),r*=i[n][n];for(let s=n+1;s<e;s++){const o=i[s][n]/i[n][n];for(let l=n;l<e;l++)i[s][l]-=o*i[n][l]}}return r}function el(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;return i!==r?NaN:Jo(e.matrix)}}function tl(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new F(0,0,NaN,t);const n=e.matrix[0].length,a=new F(r,n,NaN,t);if(i instanceof F)for(let s=0;s<r;s++)for(let o=0;o<n;o++){const l=e.matrix[s][o],c=i.matrix[s]&&i.matrix[s][o]!==void 0?i.matrix[s][o]:NaN;a.matrix[s][o]=l-c}else{const s=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)a.matrix[o][l]=e.matrix[o][l]-s}return a}}function il(t){const e=t.length;if(e!==2)return Array(e).fill(NaN);const i=t[0][0],r=t[0][1],n=t[1][0],a=t[1][1],s=i+a,o=i*a-r*n,l=s*s-4*o;if(l<0)return[NaN,NaN];const c=(s+Math.sqrt(l))/2,h=(s-Math.sqrt(l))/2;return[c,h]}function rl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r){const s=be(e.matrix[0][0]);return new D([],s,t)}const n=il(e.matrix),a=be(n[0]);return new D(n,a,t)}}function nl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new F(0,0,NaN,t);const n=new F(i,r,0,t);for(let a=0;a<i;a++)n.matrix[a][a]=1;return n}}function sl(t){return e=>{const i=e.matrix.length;return i===0?0:i*e.matrix[0].length}}function al(t){return(e,i,r,n,a,s)=>{const o=e.matrix.length;if(o===0)return;const l=e.matrix[0].length,c=r!==void 0?r:0,h=n!==void 0?n:o,p=a!==void 0?a:0,u=s!==void 0?s:l;for(let f=c;f<h&&!(f>=o);f++)for(let m=p;m<u&&!(m>=l);m++)e.matrix[f][m]=i}}function ol(t){return(e,i,r)=>{const n=e.matrix.length,a=n>0?e.matrix[0].length:0;if(i<0||i>=n)return t.warn(`Row index ${i} is out of bounds, matrix has ${n} rows.`,"matrix.get"),NaN;if(r<0||r>=a)return t.warn(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.get"),NaN;const s=e.matrix[i][r];return s===void 0?NaN:s}}function jt(t){const e=t.length;if(e===0)return[];const i=new Array(e);for(let n=0;n<e;n++){i[n]=new Array(2*e);for(let a=0;a<e;a++)i[n][a]=t[n][a];for(let a=0;a<e;a++)i[n][e+a]=n===a?1:0}for(let n=0;n<e;n++){let a=Math.abs(i[n][n]),s=n;for(let l=n+1;l<e;l++){const c=Math.abs(i[l][n]);c>a&&(a=c,s=l)}if(a<1e-14)return t.map(l=>l.map(()=>NaN));if(s!==n){const l=i[n];i[n]=i[s],i[s]=l}const o=i[n][n];for(let l=n;l<2*e;l++)i[n][l]/=o;for(let l=0;l<e;l++){if(l===n)continue;const c=i[l][n];if(c!==0)for(let h=n;h<2*e;h++)i[l][h]-=c*i[n][h]}}const r=new Array(e);for(let n=0;n<e;n++){r[n]=new Array(e);for(let a=0;a<e;a++)r[n][a]=i[n][e+a]}return r}function ll(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new F(i,r,NaN,t);const n=jt(e.matrix),a=new F(i,r,NaN,t);return a.matrix=n,a}}function cl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n+a!==i-1&&e.matrix[n][a]!==0)return!1;return!0}}function hl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(e.matrix[a][n]!==-e.matrix[n][a])return!1;return!0}}function ul(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let a=0;a<r;a++){const s=e.matrix[n][a];if(s!==0&&s!==1)return!1}return!0}}function pl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n!==a&&e.matrix[n][a]!==0)return!1;return!0}}function fl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n===a){if(e.matrix[n][a]!==1)return!1}else if(e.matrix[n][a]!==0)return!1;return!0}}function dl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;return i===r}}function ml(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++){let a=0;for(let s=0;s<r;s++){const o=e.matrix[n][s];if(o<0)return!1;a+=o}if(Math.abs(a-1)>1e-10)return!1}return!0}}function gl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<n;a++)if(e.matrix[n][a]!==e.matrix[a][n])return!1;return!0}}function yl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;let n=!0,a=!0;for(let s=0;s<i;s++)for(let o=0;o<r;o++)s>o&&e.matrix[s][o]!==0&&(n=!1),s<o&&e.matrix[s][o]!==0&&(a=!1);return n||a}}function xl(t){return e=>{const i=e.matrix.length;if(i===0)return!0;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(e.matrix[n][a]!==0)return!1;return!0}}function _l(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0,a=i.matrix.length,s=a>0?i.matrix[0].length:0,o=r*a,l=n*s,c=new F(o,l,NaN,t);for(let h=0;h<r;h++)for(let p=0;p<n;p++){const u=e.matrix[h][p];for(let f=0;f<a;f++)for(let m=0;m<s;m++){const x=i.matrix[f][m];c.matrix[h*a+f][p*s+m]=u*x}}return c}}function bl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=-1/0,a=!1;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(l>n&&(n=l),a=!0)}return a?n:NaN}}function wl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=[];for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||n.push(l)}if(n.length===0)return NaN;n.sort((s,o)=>s-o);const a=Math.floor(n.length/2);return n.length%2!==0?n[a]:(n[a-1]+n[a])/2}}function vl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=1/0,a=!1;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(l<n&&(n=l),a=!0)}return a?n:NaN}}function Sl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=new Map;let a=0,s=NaN;for(let o=0;o<i;o++)for(let l=0;l<r;l++){const c=e.matrix[o][l];if(!isNaN(c)){const h=(n.get(c)||0)+1;n.set(c,h),h>a?(a=h,s=c):h===a&&c<s&&(s=c)}}return s}}function El(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i instanceof F){const a=i.matrix.length,s=a>0?i.matrix[0].length:0;if(n!==a)return new F(0,0,NaN,t);const o=new F(r,s,0,t);for(let l=0;l<r;l++)for(let c=0;c<s;c++){let h=0;for(let p=0;p<n;p++)h+=e.matrix[l][p]*i.matrix[p][c];o.matrix[l][c]=h}return o}else if(i instanceof D||Array.isArray(i.array||i)){const a=i.array||i;if(n!==a.length)return new D([],"float",t);const s=[];for(let o=0;o<r;o++){let l=0;for(let c=0;c<n;c++)l+=e.matrix[o][c]*a[c];s.push(l)}return new D(s,"float",t)}else{const a=i,s=new F(r,n,NaN,t);for(let o=0;o<r;o++)for(let l=0;l<n;l++)s.matrix[o][l]=e.matrix[o][l]*a;return s}}}function Nl(t){return e=>{const i=e.matrix.length;if(i===0)return new F(0,0,NaN,t);const r=e.matrix[0].length;if(i===r){const h=jt(e.matrix),p=new F(i,r,NaN,t);return p.matrix=h,p}const n=h=>{const p=h.length,u=h[0].length,f=new Array(u);for(let m=0;m<u;m++){f[m]=new Array(p);for(let x=0;x<p;x++)f[m][x]=h[x][m]}return f},a=(h,p)=>{const u=h.length,f=h[0].length,m=p[0].length,x=new Array(u);for(let _=0;_<u;_++){x[_]=new Array(m).fill(0);for(let b=0;b<f;b++){const S=h[_][b];if(S!==0)for(let w=0;w<m;w++)x[_][w]+=S*p[b][w]}}return x},s=e.matrix,o=n(s);let l;if(i>r){const h=a(o,s),p=jt(h);l=a(p,o)}else{const h=a(s,o),p=jt(h);l=a(o,p)}const c=new F(r,i,NaN,t);return c.matrix=l,c}}function Cl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new F(0,0,NaN,t);let a=new F(r,n,0,t);for(let l=0;l<r;l++)a.matrix[l][l]=1;let s=new F(r,n,NaN,t);for(let l=0;l<r;l++)s.matrix[l]=[...e.matrix[l]];let o=Math.floor(i);if(o<0)return new F(r,n,NaN,t);for(;o>0;){if(o%2===1){const c=new F(r,n,0,t);for(let h=0;h<r;h++)for(let p=0;p<n;p++){let u=0;for(let f=0;f<r;f++)u+=a.matrix[h][f]*s.matrix[f][p];c.matrix[h][p]=u}a=c}const l=new F(r,n,0,t);for(let c=0;c<r;c++)for(let h=0;h<n;h++){let p=0;for(let u=0;u<r;u++)p+=s.matrix[c][u]*s.matrix[u][h];l.matrix[c][h]=p}s=l,o=Math.floor(o/2)}return a}}function Il(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=e.matrix.map(s=>[...s]);let a=0;for(let s=0;s<r&&a<i;s++){let o=a;for(;o<i&&Math.abs(n[o][s])<1e-10;)o++;if(o<i){[n[a],n[o]]=[n[o],n[a]];const l=n[a][s];for(let c=s;c<r;c++)n[a][c]/=l;for(let c=0;c<i;c++)if(c!==a){const h=n[c][s];for(let p=s;p<r;p++)n[c][p]-=h*n[a][p]}a++}}return a}}function kl(t){return(e,i)=>{const r=e.matrix.length;if(r===0){const s=be(e.matrix[0][0]);return new D([],s,t)}const n=[];for(let s=0;s<r;s++){const o=e.matrix[s].splice(i,1);n.push(o[0])}const a=be(n[0]);return new D(n,a,t)}}function Al(t){return(e,i)=>{const r=e.matrix.splice(i,1),n=be(r[0][0]);return new D(r[0]||[],n,t)}}function Tl(t){return(e,i,r)=>{const n=e.matrix.length,a=n>0?e.matrix[0].length:0,s=i*r,o=[];for(let h=0;h<n;h++)for(let p=0;p<a;p++)o.push(e.matrix[h][p]);for(;o.length<s;)o.push(NaN);o.length>s&&(o.length=s);const l=[];let c=0;for(let h=0;h<i;h++){const p=[];for(let u=0;u<r;u++)p.push(o[c++]);l.push(p)}e.matrix=l}}function Pl(t){return e=>{e.matrix.reverse();for(const i of e.matrix)i.reverse()}}function Dl(t){return(e,i)=>{const r=e.matrix.length;if(i<0||i>=r){t.warn(`Row index ${i} is out of bounds, matrix has ${r} rows.`,"matrix.row");const a=r>0?be(e.matrix[0][0]):"float";return new D([],a,t)}const n=be(e.matrix[i][0]);return new D([...e.matrix[i]],n,t)}}function Ml(t){return e=>e.matrix.length}function Rl(t){return(e,i,r,n)=>{const a=e.matrix.length,s=a>0?e.matrix[0].length:0;if(i<0||i>=a){t.warn(`Row index ${i} is out of bounds, matrix has ${a} rows.`,"matrix.set");return}if(r<0||r>=s){t.warn(`Column index ${r} is out of bounds, matrix has ${s} columns.`,"matrix.set");return}e.matrix[i][r]=n}}function Vl(t){return(e,i=0,r="asc")=>{e.matrix.length!==0&&e.matrix.sort((n,a)=>{const s=n[i],o=a[i];return s<o?r==="asc"?-1:1:s>o?r==="asc"?1:-1:0})}}function Ol(t){return(e,i,r,n,a)=>{const s=r-i,o=a-n,l=new F(s,o,NaN,t);for(let c=0;c<s;c++){const h=i+c;if(h>=e.matrix.length)break;for(let p=0;p<o;p++){const u=n+p;if(u>=e.matrix[h].length)break;l.matrix[c][p]=e.matrix[h][u]}}return l}}function Ll(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new F(0,0,NaN,t);const n=e.matrix[0].length,a=new F(r,n,NaN,t);if(i instanceof F)for(let s=0;s<r;s++)for(let o=0;o<n;o++){const l=e.matrix[s][o],c=i.matrix[s]&&i.matrix[s][o]!==void 0?i.matrix[s][o]:NaN;a.matrix[s][o]=l+c}else{const s=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)a.matrix[o][l]=e.matrix[o][l]+s}return a}}function jl(t){return(e,i,r)=>{const n=e.matrix.length;for(let a=0;a<n;a++){const s=e.matrix[a][i];e.matrix[a][i]=e.matrix[a][r],e.matrix[a][r]=s}}}function Bl(t){return(e,i,r)=>{const n=e.matrix[i];e.matrix[i]=e.matrix[r],e.matrix[r]=n}}function Fl(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=Math.min(i,r);let a=0;for(let s=0;s<n;s++)a+=e.matrix[s][s];return a}}function $l(t){return e=>{const i=e.matrix.length;if(i===0)return new F(0,0,NaN,t);const r=e.matrix[0].length,n=new F(r,i,NaN,t);for(let a=0;a<i;a++)for(let s=0;s<r;s++)n.matrix[s][a]=e.matrix[a][s];return n}}class F{constructor(e=0,i=0,r=NaN,n){if(this.context=n,this.matrix=[],e>0&&i>0)for(let a=0;a<e;a++)this.matrix.push(Array(i).fill(r));this._add_col=Ko(this.context),this._add_row=Ho(this.context),this._avg=Go(this.context),this._col=Yo(this.context),this._columns=Xo(this.context),this._concat=Qo(this.context),this._copy=Zo(this.context),this._det=el(this.context),this._diff=tl(this.context),this._eigenvalues=rl(this.context),this._eigenvectors=nl(this.context),this._elements_count=sl(this.context),this._fill=al(this.context),this._get=ol(this.context),this._inv=ll(this.context),this._is_antidiagonal=cl(this.context),this._is_antisymmetric=hl(this.context),this._is_binary=ul(this.context),this._is_diagonal=pl(this.context),this._is_identity=fl(this.context),this._is_square=dl(this.context),this._is_stochastic=ml(this.context),this._is_symmetric=gl(this.context),this._is_triangular=yl(this.context),this._is_zero=xl(this.context),this._kron=_l(this.context),this._max=bl(this.context),this._median=wl(this.context),this._min=vl(this.context),this._mode=Sl(this.context),this._mult=El(this.context),this._pinv=Nl(this.context),this._pow=Cl(this.context),this._rank=Il(this.context),this._remove_col=kl(this.context),this._remove_row=Al(this.context),this._reshape=Tl(this.context),this._reverse=Pl(this.context),this._row=Dl(this.context),this._rows=Ml(this.context),this._set=Rl(this.context),this._sort=Vl(this.context),this._submatrix=Ol(this.context),this._sum=Ll(this.context),this._swap_columns=jl(this.context),this._swap_rows=Bl(this.context),this._trace=Fl(this.context),this._transpose=$l(this.context)}matrix;_add_col;_add_row;_avg;_col;_columns;_concat;_copy;_det;_diff;_eigenvalues;_eigenvectors;_elements_count;_fill;_get;_inv;_is_antidiagonal;_is_antisymmetric;_is_binary;_is_diagonal;_is_identity;_is_square;_is_stochastic;_is_symmetric;_is_triangular;_is_zero;_kron;_max;_median;_min;_mode;_mult;_pinv;_pow;_rank;_remove_col;_remove_row;_reshape;_reverse;_row;_rows;_set;_sort;_submatrix;_sum;_swap_columns;_swap_rows;_trace;_transpose;toString(){let e="";for(let i=0;i<this.matrix.length;i++)e+=e===""?"":`
|
|
121
|
-
`,e+="["+this.matrix[i].join(", ")+"]";return e}add_col(...e){return this._add_col(this,...e)}add_row(...e){return this._add_row(this,...e)}avg(...e){return this._avg(this,...e)}col(...e){return this._col(this,...e)}columns(...e){return this._columns(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}det(...e){return this._det(this,...e)}diff(...e){return this._diff(this,...e)}eigenvalues(...e){return this._eigenvalues(this,...e)}eigenvectors(...e){return this._eigenvectors(this,...e)}elements_count(...e){return this._elements_count(this,...e)}fill(...e){return this._fill(this,...e)}get(...e){return this._get(this,...e)}inv(...e){return this._inv(this,...e)}is_antidiagonal(...e){return this._is_antidiagonal(this,...e)}is_antisymmetric(...e){return this._is_antisymmetric(this,...e)}is_binary(...e){return this._is_binary(this,...e)}is_diagonal(...e){return this._is_diagonal(this,...e)}is_identity(...e){return this._is_identity(this,...e)}is_square(...e){return this._is_square(this,...e)}is_stochastic(...e){return this._is_stochastic(this,...e)}is_symmetric(...e){return this._is_symmetric(this,...e)}is_triangular(...e){return this._is_triangular(this,...e)}is_zero(...e){return this._is_zero(this,...e)}kron(...e){return this._kron(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}mult(...e){return this._mult(this,...e)}pinv(...e){return this._pinv(this,...e)}pow(...e){return this._pow(this,...e)}rank(...e){return this._rank(this,...e)}remove_col(...e){return this._remove_col(this,...e)}remove_row(...e){return this._remove_row(this,...e)}reshape(...e){return this._reshape(this,...e)}reverse(...e){return this._reverse(this,...e)}row(...e){return this._row(this,...e)}rows(...e){return this._rows(this,...e)}set(...e){return this._set(this,...e)}sort(...e){return this._sort(this,...e)}submatrix(...e){return this._submatrix(this,...e)}sum(...e){return this._sum(this,...e)}swap_columns(...e){return this._swap_columns(this,...e)}swap_rows(...e){return this._swap_rows(this,...e)}trace(...e){return this._trace(this,...e)}transpose(...e){return this._transpose(this,...e)}}function Se(t){return(e,i,r)=>new F(e,i,r,t)}function Wl(t){return(e,i=0)=>y.from(e).get(i)}class Ul{constructor(e){this.context=e,this.add_col=(i,...r)=>i.add_col(...r),this.add_row=(i,...r)=>i.add_row(...r),this.avg=(i,...r)=>i.avg(...r),this.col=(i,...r)=>i.col(...r),this.columns=(i,...r)=>i.columns(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.det=(i,...r)=>i.det(...r),this.diff=(i,...r)=>i.diff(...r),this.eigenvalues=(i,...r)=>i.eigenvalues(...r),this.eigenvectors=(i,...r)=>i.eigenvectors(...r),this.elements_count=(i,...r)=>i.elements_count(...r),this.fill=(i,...r)=>i.fill(...r),this.get=(i,...r)=>i.get(...r),this.inv=(i,...r)=>i.inv(...r),this.is_antidiagonal=(i,...r)=>i.is_antidiagonal(...r),this.is_antisymmetric=(i,...r)=>i.is_antisymmetric(...r),this.is_binary=(i,...r)=>i.is_binary(...r),this.is_diagonal=(i,...r)=>i.is_diagonal(...r),this.is_identity=(i,...r)=>i.is_identity(...r),this.is_square=(i,...r)=>i.is_square(...r),this.is_stochastic=(i,...r)=>i.is_stochastic(...r),this.is_symmetric=(i,...r)=>i.is_symmetric(...r),this.is_triangular=(i,...r)=>i.is_triangular(...r),this.is_zero=(i,...r)=>i.is_zero(...r),this.kron=(i,...r)=>i.kron(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.mult=(i,...r)=>i.mult(...r),this.new=Se(e),this.param=Wl(),this.pinv=(i,...r)=>i.pinv(...r),this.pow=(i,...r)=>i.pow(...r),this.rank=(i,...r)=>i.rank(...r),this.remove_col=(i,...r)=>i.remove_col(...r),this.remove_row=(i,...r)=>i.remove_row(...r),this.reshape=(i,...r)=>i.reshape(...r),this.reverse=(i,...r)=>i.reverse(...r),this.row=(i,...r)=>i.row(...r),this.rows=(i,...r)=>i.rows(...r),this.set=(i,...r)=>i.set(...r),this.sort=(i,...r)=>i.sort(...r),this.submatrix=(i,...r)=>i.submatrix(...r),this.sum=(i,...r)=>i.sum(...r),this.swap_columns=(i,...r)=>i.swap_columns(...r),this.swap_rows=(i,...r)=>i.swap_rows(...r),this.trace=(i,...r)=>i.trace(...r),this.transpose=(i,...r)=>i.transpose(...r),this.new_float=Se(e),this.new_int=Se(e),this.new_string=Se(e),this.new_bool=Se(e),this.new_color=Se(e),this.new_line=Se(e),this.new_label=Se(e),this.new_box=Se(e),this.new_linefill=Se(e),this.new_table=Se(e)}}class ql{constructor(e){this.context=e}_live=!1;setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){const e=this.context.idx,i=this.context.length;if(e===i-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===i-2){const r=this.context.marketData?.[i-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}}class ht{constructor(e,i){this._definition=e,this.context=i;for(let r in e)this[r]=e[r]}get __def__(){return this._definition}copy(){return new ht(this.__def__,this.context)}toString(){const e={};for(let i in this.__def__){const r=this[i];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[i]=r.toString():e[i]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(i=>`"${i}":${String(e[i])}`).join(",")+"}"}}}class se{time;index;price;constructor(e,i,r){this.time=e,this.index=i,this.price=r}copy(){return new se(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}}function zl(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}const ar={series:t=>t instanceof y||typeof t=="number"||typeof t=="string"||typeof t=="boolean",string:t=>typeof t=="string",color:t=>typeof t=="string"||t===null||typeof t=="number"&&isNaN(t)||t instanceof y,number:t=>typeof t=="number",boolean:t=>typeof t=="boolean",array:t=>Array.isArray(t),object:t=>typeof t=="object",point:t=>t instanceof se,primitive:t=>typeof t===null||typeof t!="object"&&typeof t!="function",function:t=>typeof t=="function",undefined:t=>t===void 0,null:t=>t===null,NaN:t=>isNaN(t),remaining_options:t=>t!==null&&typeof t=="object"&&!(t instanceof y)&&!(t instanceof se)&&!zl(t)};function ke(t){const e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function X(t,e,i,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);const n={};let a={};const s=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){const l=t[o];if(ar.remaining_options(l)){a=l;break}const c=e.map((h,p)=>s[p]?h[o]:void 0);for(let h=0;h<c.length;h++){const p=c[h];if(p===void 0){s[h]=!1;continue}const u=i[p];if(typeof l=="number"&&isNaN(l)&&(u==="number"||u==="series"))n[p]=l;else{const f=ar[i[p]];typeof f=="function"&&f(l)?n[p]=l:s[h]=!1}}}return{...n,...a,...r}}const Kl=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Hl={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Gl=["title","shorttitle","overlay","format","precision","scale","max_bars_back","timeframe","timeframe_gaps","explicit_plot_zorder","max_lines_count","max_labels_count","max_boxes_count","calc_bars_count","max_polylines_count","dynamic_requests","behind_chart"],Yl={title:"string",shorttitle:"string",overlay:"boolean",format:"string",precision:"number",scale:"string",max_bars_back:"number",timeframe:"string",timeframe_gaps:"boolean",explicit_plot_zorder:"boolean",max_lines_count:"number",max_labels_count:"number",max_boxes_count:"number",calc_bars_count:"number",max_polylines_count:"number",dynamic_requests:"boolean",behind_chart:"boolean"};function Xl(t){return X(t,Gl,Yl)}class _t{get __value(){return NaN}param(e,i=0){return y.from(e).get(i)}any(e){const i=y.from(e).get(0);return i==null?!0:typeof i=="number"?i!==i:!1}}const ot={freq_all:"alert.freq_all",freq_once_per_bar:"alert.freq_once_per_bar",freq_once_per_bar_close:"alert.freq_once_per_bar_close"};class Ql{constructor(e){this.context=e}_firedKeys=new Set;_fallbackCounter=0;_fallbackLastExecTick=-1;get freq_all(){return ot.freq_all}get freq_once_per_bar(){return ot.freq_once_per_bar}get freq_once_per_bar_close(){return ot.freq_once_per_bar_close}param(e,i,r){return y.from(e).get(0)}any(e,i,r){const n=y.from(e).get(0),a=i?y.from(i).get(0):ot.freq_once_per_bar;let s;if(r&&typeof r=="object"&&r.__callsiteId)s=r.__callsiteId;else{const h=this.context._execTick||0;h!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=h),s=`alert_${this._fallbackCounter++}`}const o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${s}:${o}`;if(a===ot.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(a===ot.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(c))return;this._firedKeys.add(c)}this.context.alerts.push({type:"alert",id:s,message:n,freq:a,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}}class Zl{constructor(e){this.context=e}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}indicator(...e){const i=Xl(e),r={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...r,...i},this.context.indicator}get bar_index(){return this.context.idx}na(e){const i=y.from(e).get(0);return i==null||typeof i=="number"&&isNaN(i)}nz(e,i=0){const r=y.from(e).get(0),n=y.from(i).get(0);return r==null||typeof r=="number"&&isNaN(r)?n:r}fixnan(e){const i=y.from(e);for(let r=0;r<i.length;r++){const n=i.get(r);if(!isNaN(n))return n}return NaN}_acCounter=0;_acLastExecTick=-1;_acFiredKeys=new Set;alertcondition(e,i,r){const n=y.from(e).get(0),a=this.context.idx,s=this.context._execTick||0;s!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=s);const o=`alertcondition_${this._acCounter++}`;if(!n)return;const l=this.context.pine?.barstate?.isrealtime??a===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${o}:${a}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);const h=i?y.from(i).get(0):"",p=r?y.from(r).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:h,message:p,bar_index:a,time:this.context.data.openTime?.data?.[a]??0})}error(...e){console.error("error called but is currently not implemented",e)}max_bars_back(e,i){}timestamp(...e){const i=e.map(n=>n instanceof y?n.get(0):n),r=X(i,Kl,Hl);if(r.year!==void 0){const n=r.year,a=r.month,s=r.day,o=r.hour||0,l=r.minute||0,c=r.second||0,h=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(h,n,a,s,o,l,c)}if(r.dateString!==void 0){const n=r.dateString.trim();if(/[Zz]$/.test(n)||/[+-]\d{2}:?\d{2}$/.test(n))return new Date(n).getTime();const a=n.includes("T")?n+"Z":n.replace(/\s+/,"T")+"Z",s=new Date(a);if(!isNaN(s.getTime())){const o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,s.getUTCFullYear(),s.getUTCMonth()+1,s.getUTCDate(),s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds())}return new Date(n).getTime()}return NaN}_timestampFromComponents(e,i,r,n,a,s,o){const l=new Date(Date.UTC(i,r-1,n,a,s,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();const h=c.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(h){const p=h[1]==="+"?1:-1,u=parseInt(h[2],10),f=parseInt(h[3]||"0",10),m=p*(u*60+f)*60*1e3;return l.getTime()-m}try{return this._timestampFromIANA(e,i,r,n,a,s,o)}catch{return l.getTime()}}_timestampFromIANA(e,i,r,n,a,s,o){const l=new Date(Date.UTC(i,r-1,n,a,s,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),h=w=>parseInt(c.find(E=>E.type===w)?.value||"0",10),p=h("year"),u=h("month"),f=h("day");let m=h("hour");m===24&&(m=0);const x=h("minute"),_=h("second"),b=new Date(Date.UTC(p,u-1,f,m,x,_));p>=0&&p<100&&b.setUTCFullYear(p);const S=b.getTime()-l.getTime();return l.getTime()-S}bool(e){const i=y.from(e).get(0);return!isNaN(i)&&i!==0}int(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "int" with argument "x"="${i}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(i)}float(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "float" with argument "x"="${i}". An argument of "literal string" type was used but a "const float" is expected.`);return i}string(e){return y.from(e).get(0).toString()}Type(e){const i=Object.keys(e),r={};for(const n of i){let a=e[n];a instanceof y&&(a=a.data),Array.isArray(a)&&(a[0],r[n]=a[1])}return{new:function(...n){const a={};let s=null;if(n.length===1&&n[0]&&typeof n[0]=="object"&&!(n[0]instanceof y)&&!Array.isArray(n[0])&&!(n[0]instanceof ht)){const o=Object.keys(n[0]);o.length>0&&o.some(l=>i.includes(l))&&(s=n[0],n=[])}for(let o=0;o<i.length;o++){const l=i[o];s&&l in s?a[l]=s[l]:o<n.length?a[l]=n[o]:l in r&&(a[l]=y.from(r[l]).get(0))}return new ht(a,this.context)},copy:function(n){return new ht(n.__def__,this.context)}}}}function lt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){const i=t.slice(1);return i.length===6?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),1]:i.length===8?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),parseInt(i.slice(6,8),16)/255]:null}const e=t.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function Jl(t,e,i,r){const n=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),s=Math.round(Math.max(0,Math.min(255,i))).toString(16).padStart(2,"0");if(r>=1)return`#${n}${a}${s}`.toUpperCase();const o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${n}${a}${s}${o}`.toUpperCase()}const Y={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:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function Ie(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}class ec{constructor(e){this.context=e}any(e){const i=y.from(e).get(0);return typeof i=="number"&&isNaN(i)?null:i}param(e,i=0){return y.from(e).get(i)}new(e,i){if(e=Ie(e),!e||typeof e!="string")return e;if(typeof i=="number"&&isNaN(i)&&(i=void 0),e.startsWith("#")){const r=e.slice(1),n=r.length===8?r.slice(0,6):r;return i!=null?`#${n}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:`#${r}`}else{const r=Y[e];if(r)return i!=null?`#${r.slice(1)}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:r;const n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);if(n){const a=n[1],s=n[2],o=n[3];if(i!=null){const l=parseInt(a).toString(16).padStart(2,"0"),c=parseInt(s).toString(16).padStart(2,"0"),h=parseInt(o).toString(16).padStart(2,"0"),p=Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${h}${p}`}return e}return i!=null?`rgba(${e}, ${(100-i)/100})`:e}}rgb(e,i,r,n){return typeof n=="number"&&isNaN(n)&&(n=void 0),n!=null?`rgba(${e}, ${i}, ${r}, ${(100-n)/100})`:`rgb(${e}, ${i}, ${r})`}from_gradient(e,i,r,n,a){if(e=Ie(e),i=Ie(i),r=Ie(r),n=Ie(n),a=Ie(a),e==null||typeof e=="number"&&isNaN(e)||i==null||typeof i=="number"&&isNaN(i)||r==null||typeof r=="number"&&isNaN(r)||n==null||typeof n=="number"&&isNaN(n)||a==null||typeof a=="number"&&isNaN(a))return;let s=0;r!==i&&(s=(e-i)/(r-i)),s=Math.max(0,Math.min(1,s));const o=lt(typeof n=="string"?n:"#000000")||[0,0,0,1],l=lt(typeof a=="string"?a:"#FFFFFF")||[255,255,255,1],c=o[0]+(l[0]-o[0])*s,h=o[1]+(l[1]-o[1])*s,p=o[2]+(l[2]-o[2])*s,u=o[3]+(l[3]-o[3])*s;return Jl(c,h,p,u)}r(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?i[0]:NaN}g(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?i[1]:NaN}b(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?i[2]:NaN}t(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?Math.round(100-i[3]*100):NaN}aqua(){return Y.aqua}black(){return Y.black}blue(){return Y.blue}fuchsia(){return Y.fuchsia}gray(){return Y.gray}green(){return Y.green}lime(){return Y.lime}maroon(){return Y.maroon}navy(){return Y.navy}olive(){return Y.olive}orange(){return Y.orange}purple(){return Y.purple}red(){return Y.red}silver(){return Y.silver}teal(){return Y.teal}white(){return Y.white}yellow(){return Y.yellow}}function dt(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC"){const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const n=r[1]==="+"?1:-1,a=parseInt(r[2],10),s=parseInt(r[3]||"0",10),o=n*(a*60+s)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{const n=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),a=c=>parseInt(n.find(h=>h.type===c)?.value||"0",10);let s=a("hour");s===24&&(s=0);const o=n.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:a("year"),month:a("month"),day:a("day"),hour:s,minute:a("minute"),second:a("second"),dayOfWeek:l[o]??0}}catch{const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}}function tc(t,e,i){const r=new Date(Date.UTC(t,e-1,i)),n=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-n);const a=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-a.getTime())/864e5+1)/7)}const ic=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],rc={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"};class or{context;dataField;constructor(e,i="openTime"){this.context=e,this.dataField=i}get __value(){return this.context.data[this.dataField]}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(c=>c instanceof y?c.get(0):c),r=X(i,ic,rc),n=r.bars_back??0,a=r.timeframe_bars_back??0,s=n+a,o=this.context.data[this.dataField],l=y.from(o).get(s);if(r.session!==void 0){const c=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(l,r.session,c)?l:NaN}return l}_isInSession(e,i,r){const n=i.match(/^(\d{2})(\d{2})-(\d{2})(\d{2})$/);if(!n)return!0;const a=parseInt(n[1],10),s=parseInt(n[2],10),o=parseInt(n[3],10),l=parseInt(n[4],10),c=dt(e,r),h=c.hour,p=c.minute,u=h*60+p,f=a*60+s,m=o*60+l;return f<=m?u>=f&&u<m:u>=f||u<m}}const nc=[[],["time"],["time","timezone"]],sc={time:"number",timezone:"string"};class We{context;extractor;constructor(e,i){this.context=e,this.extractor=i}get __value(){const e=y.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;const i=this.context.pine?.syminfo?.timezone||"UTC",r=dt(e,i);return this.extractor(r)}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(o=>o instanceof y?o.get(0):o);if(i.length===0)return this.__value;const r=X(i,nc,sc),n=r.time;if(n===void 0||isNaN(n))return NaN;const a=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",s=dt(n,a);return this.extractor(s)}}const Ue={dayofmonth:t=>t.day,dayofweek:t=>t.dayOfWeek===0?1:t.dayOfWeek+1,hour:t=>t.hour,minute:t=>t.minute,month:t=>t.month,second:t=>t.second,weekofyear:t=>tc(t.year,t.month,t.day),year:t=>t.year},ac=[["defval","title","tooltip","inline","group","display"],["defval","title","tooltip","group","confirm","display"],["defval","title","tooltip","inline","group","confirm","display"],["defval","title","options","tooltip","inline","group","confirm","display"],["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display"]],oc={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function he(t){return X(t,ac,oc)}function pe(t,e){return e.title&&t.inputs&&t.inputs[e.title]!==void 0?t.inputs[e.title]:e.defval}function lc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function cc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function hc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function uc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function pc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function fc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function dc(t){return(e,i=0)=>y.from(e).get(i)}function mc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function gc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function yc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function xc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function _c(t){return(...e)=>{const i=he(e);return pe(t,i)}}function bc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function wc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function vc(t){return(...e)=>he(e).defval}const Sc={any:lc,bool:cc,color:hc,enum:uc,float:pc,int:fc,param:dc,price:mc,session:gc,source:yc,string:xc,symbol:_c,text_area:bc,time:wc,timeframe:vc};class Ec{constructor(e){this.context=e,Object.entries(Sc).forEach(([i,r])=>{this[i]=r(e)})}any;bool;color;enum;float;int;param;price;session;source;string;symbol;text_area;time;timeframe}function Nc(t){return e=>Math.abs(y.from(e).get(0))}function Cc(t){return e=>Math.acos(y.from(e).get(0))}function Ic(t){return e=>Math.asin(y.from(e).get(0))}function kc(t){return e=>Math.atan(y.from(e).get(0))}function Ac(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return i.reduce((r,n)=>r+n,0)/i.length}}function Tc(t){return e=>Math.ceil(y.from(e).get(0))}function Pc(t){return e=>Math.cos(y.from(e).get(0))}function Dc(t){return()=>Math.E}function Mc(t){return e=>Math.exp(y.from(e).get(0))}function Rc(t){return e=>Math.floor(y.from(e).get(0))}function Vc(t){return e=>Math.log(y.from(e).get(0))}function Oc(t){return e=>Math.log(y.from(e).get(0))}function Lc(t){return e=>Math.log10(y.from(e).get(0))}function jc(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.max(...i)}}function Bc(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.min(...i)}}function Fc(t){return(e,i,r)=>typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function $c(t){return()=>1.618033988749895}function Wc(t){return()=>Math.PI}function Uc(t){return(e,i)=>Math.pow(y.from(e).get(0),y.from(i).get(0))}function qc(t){return()=>Math.random()}function si(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function zc(t){return(e,i)=>{const r=y.from(e).get(0);if(i==null)return si(r);const n=y.from(i).get(0);if(n===0)return si(r);const a=Math.pow(10,n);return si(r*a)/a}}function Kc(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Hc(t){return()=>.6180339887498948}function Gc(t){return e=>Math.sign(y.from(e).get(0))}function Yc(t){return e=>Math.sin(y.from(e).get(0))}function Xc(t){return e=>Math.sqrt(y.from(e).get(0))}function Qc(t){return(e,i)=>{const r=y.from(i).get(0),n=y.from(e);let a=0;for(let s=0;s<r;s++){const o=n.get(s);a+=o}return a}}function Zc(t){return e=>Math.tan(y.from(e).get(0))}function Jc(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(180/Math.PI)}}function eh(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(Math.PI/180)}}function th(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)<1e-9:r===n}}function ih(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)>=1e-9:r!==n}}const rh={abs:Nc,acos:Cc,asin:Ic,atan:kc,avg:Ac,ceil:Tc,cos:Pc,e:Dc,exp:Mc,floor:Rc,ln:Vc,log:Oc,log10:Lc,max:jc,min:Bc,param:Fc,phi:$c,pi:Wc,pow:Uc,random:qc,round:zc,round_to_mintick:Kc,rphi:Hc,sign:Gc,sin:Yc,sqrt:Xc,sum:Qc,tan:Zc,todegrees:Jc,toradians:eh,__eq:th,__neq:ih};class nh{constructor(e){this.context=e,Object.entries(rh).forEach(([i,r])=>{this[i]=r(e)})}_cache={};abs;acos;asin;atan;avg;ceil;cos;e;exp;floor;ln;log;log10;max;min;param;phi;pi;pow;random;round;round_to_mintick;rphi;sign;sin;sqrt;sum;tan;todegrees;toradians;__eq;__neq}function sh(t){return(e,i,r)=>{t.params[r]||(t.params[r]=[]);let n;if(e instanceof y)n=e.get(i||0);else if(Array.isArray(e)){const a=e.some(o=>o instanceof y),s=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(a||s)&&e.length>=1?n=e.map(o=>o instanceof y?o.get(0):o):n=y.from(e).get(i||0)}else n=e;return t.params[r].length===0?t.params[r].push(n):t.params[r][t.params[r].length-1]=n,[n,r]}}const mt=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Rt={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function Ut(t){if(mt.includes(t))return t;if(Rt[t])return Rt[t];const e=t.toLowerCase();if(Rt[e])return Rt[e];const i=t.toUpperCase();return mt.includes(i)?i:t}function lr(t,e,i,r,n=!1,a=!1){for(let s=0;s<i.length;s++)if(i[s]<=t&&t<r[s])return n||a||e>=r[s]?s:s-1;return-1}function cr(t,e,i,r,n=!1,a,s=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=e&&i[o]>=t){const l=a&&e>a;if(s&&n)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}if(l&&n&&!s)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}return o}if(r[o]<t)break}return-1}function xi(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(xi):t}function ah(t){return async(e,i,r,n=!1,a=!1,s=!1,o=null,l=null)=>{const c=e[0]instanceof y?e[0].get(0):e[0],h=c===""?t.tickerId:c,p=typeof h=="string"&&h.includes(":")?h.split(":")[1]:h,u=i[0]instanceof y?i[0].get(0):i[0],f=u===""?t.timeframe:typeof u=="string"?u:String(u??""),m=r[0],x=r[1],_=Array.isArray(n)?n[0]:n,b=Array.isArray(a)?a[0]:a,S=_===!0||_==="gaps_on",w=b===!0||b==="lookahead_on";if(t.isSecondaryContext){const ue=xi(m);return Array.isArray(ue)?[ue]:ue}const E=mt.indexOf(Ut(t.timeframe)),A=mt.indexOf(Ut(f));if(E==-1||A==-1)throw new Error("Invalid timeframe");if(E===A){const ue=xi(m);return Array.isArray(ue)?[ue]:ue}const C=E>A,M=y.from(t.data.openTime).get(0),O=y.from(t.data.closeTime).get(0),$=t.idx===t.length-1&&O>Date.now(),B=`${p}_${f}_${x}`,R=`${B}_prevIdx`;if(t.cache[B]){const ue=t.cache[B];t.dataVersion>ue.dataVersion&&(await ue.pineTS.updateTail(ue.context),ue.dataVersion=t.dataVersion);const bt=ue.context,Pt=C?cr(M,O,bt.data.openTime.data,bt.data.closeTime.data,w,t.eDate,S):lr(M,O,bt.data.openTime.data,bt.data.closeTime.data,w,$);if(Pt==-1)return NaN;const nt=bt.params[x][Pt];if(!C&&S){const Li=t.cache[R];return Li!==void 0&&Li===Pt?NaN:(t.cache[R]=Pt,Array.isArray(nt)?[nt]:nt)}return Array.isArray(nt)?[nt]:nt}const q=1e3*60*60*24*30,re=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),fe=re?re-q:void 0,de=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,me=t.eDate?Math.max(t.eDate,de):(de||Date.now())+q,Ge=new Vi(t.source,p,f,void 0,fe,me);Ge.markAsSecondary();const ee=await Ge.run(t.pineTSCode);t.cache[B]={pineTS:Ge,context:ee,dataVersion:t.dataVersion};const Zt=C?cr(M,O,ee.data.openTime.data,ee.data.closeTime.data,w,t.eDate,S):lr(M,O,ee.data.openTime.data,ee.data.closeTime.data,w,$);if(Zt==-1)return NaN;const Jt=ee.params[x][Zt];return!C&&S?(t.cache[R]=Zt,NaN):Array.isArray(Jt)?[Jt]:Jt}}function ct(t){return typeof t=="number"?T.float:typeof t=="boolean"?T.bool:typeof t=="string"?T.string:T.any}function oh(t){return async(e,i,r,n=!1,a=null,s=!1,o=0)=>{const l=e[0]instanceof y?e[0].get(0):e[0],c=l===""?t.tickerId:l,h=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,p=i[0]instanceof y?i[0].get(0):i[0],u=p===""?t.timeframe:typeof p=="string"?p:String(p??""),f=r[0],m=r[1];Array.isArray(n)&&n[0];const x=Array.isArray(s)?s[0]:s;if(t.isSecondaryContext)return Array.isArray(f)?[f.map(R=>new D([R],ct(R),t))]:new D([f],ct(f),t);const _=mt.indexOf(Ut(t.timeframe)),b=mt.indexOf(Ut(u));if(_===-1||b===-1){if(x)return NaN;throw new Error("Invalid timeframe")}if(b>_){if(x)return NaN;throw new Error(`Timeframe ${u} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(b===_)return Array.isArray(f)?[f.map(R=>new D([R],ct(R),t))]:new D([f],ct(f),t);const S=`${h}_${u}_${m}_lower`;if(!t.cache[S]){const R=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),q=R?R-2592e6:void 0,re=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,fe=t.eDate?Math.max(t.eDate,re):(re||Date.now())+2592e6,de=new Vi(t.source,h,u,void 0,q,fe);de.markAsSecondary();const me=await de.run(t.pineTSCode);t.cache[S]={pineTS:de,context:me,dataVersion:t.dataVersion}}const w=t.cache[S];t.dataVersion>w.dataVersion&&(await w.pineTS.updateTail(w.context),w.dataVersion=t.dataVersion);const E=w.context,A=y.from(t.data.openTime).get(0),C=y.from(t.data.closeTime).get(0),M=E.data.openTime.data,O=E.data.closeTime.data,$=E.params[m];if(!$)return Array.isArray(f)?[f.map(()=>new D([],T.float,t))]:new D([],T.float,t);const B=[];for(let R=0;R<M.length;R++){const q=M[R];if(!(O[R]<=A)){if(q>=C)break;q>=A&&q<C&&B.push($[R])}}if(B.length>0&&Array.isArray(B[0])){const R=B[0].length,q=[];for(let re=0;re<R;re++){const fe=B.map(me=>me[re]),de=fe.length>0?ct(fe[0]):T.float;q.push(new D(fe,de,t))}return[q]}else{const R=B.length>0?ct(B[0]):T.float;return new D(B,R,t)}}}const lh={param:sh,security:ah,security_lower_tf:oh};class ch{constructor(e){this.context=e,Object.entries(lh).forEach(([i,r])=>{this[i]=r(e)})}_cache={};param;security;security_lower_tf}function hh(t){return e=>{t.taState||(t.taState={});const i=e||"accdist";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.high,0),s=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(n)||isNaN(a)||isNaN(s)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);const l=a-s;let c=0;l!==0&&(c=(n-s-(a-n))/l*o);const h=r.prevCumulativeSum+c;return r.currentCumulativeSum=h,t.precision(h)}}function uh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0);t.taState||(t.taState={});const c=a||`alma_${s}_${o}_${l}`;if(!t.taState[c]){const x=o*(s-1),_=s/l,b=[];let S=0;for(let w=0;w<s;w++){const E=Math.exp(-Math.pow(w-x,2)/(2*_*_));b.push(E),S+=E}for(let w=0;w<b.length;w++)b[w]/=S;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevWindow=[...h.currentWindow],h.prevCallCount=h.currentCallCount),h.lastIdx=t.idx);const p=y.from(e).get(0),u=[...h.prevWindow];for(u.unshift(p);u.length>s;)u.pop();const f=h.prevCallCount+1;if(u.length<s&&(f>=s||t.idx>=s-1)){const x=y.from(e);for(;u.length<s;)u.push(x.get(u.length))}if(h.currentWindow=u,h.currentCallCount=f,u.length<s)return NaN;let m=0;for(let x=0;x<s;x++)m+=h.weights[x]*u[s-1-x];return t.precision(m)}}function ph(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`atr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});const a=t.taState[n];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevAtr=a.currentAtr,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);const s=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(s)||isNaN(o)||isNaN(l))return NaN;const c=t.idx>0?t.get(t.data.close,1):null;let h;if(c!==null&&!isNaN(c)){const x=s-o,_=Math.abs(s-c),b=Math.abs(o-c);h=Math.max(x,_,b)}else h=s-o;let p=a.prevInitCount,u=a.prevInitSum,f=a.prevAtr;if(p<r){if(u+=h,p++,a.currentInitSum=u,a.currentInitCount=p,p===r){const x=u/r;return a.currentAtr=x,t.precision(x)}return NaN}const m=(f*(r-1)+h)/r;return a.currentAtr=m,t.precision(m)}}function fh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevLastTrueIndex=n.currentLastTrueIndex),n.lastIdx=t.idx);const a=y.from(e).get(0);let s=n.prevLastTrueIndex;return a&&(s=t.idx),n.currentLastTrueIndex=s,s===null?NaN:t.idx-s}}function dh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bb_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}if(h.length<a&&t.idx>=a-1){const b=y.from(e);for(;h.length<a;){const S=b.get(h.length);if(isNaN(S))break;h.push(S),p+=S}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return[[NaN,NaN,NaN]];const u=p/a;let f=0;for(let b=0;b<a;b++)f+=Math.pow(h[b]-u,2);const m=Math.sqrt(f/a),x=u+s*m,_=u-s*m;return[[t.precision(u),t.precision(x),t.precision(_)]]}}function mh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bbw_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const S=h.pop();p-=S}if(h.length<a&&t.idx>=a-1){const S=y.from(e);for(;h.length<a;){const w=S.get(h.length);if(isNaN(w))break;h.push(w),p+=w}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return NaN;const u=p/a;let f=0;for(let S=0;S<a;S++){const w=h[S]-u;f+=w*w}const m=f/a,x=Math.sqrt(m),_=s*x;if(u===0)return t.precision(0);const b=2*_/u*100;return t.precision(b)}}function gh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`cci_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0);if(isNaN(o))return NaN;const l=[...s.prevWindow];let c=s.prevSum;for(l.unshift(o),c+=o;l.length>n;){const x=l.pop();c-=x}const h=s.prevCallCount+1;if(l.length<n&&(h>=n||t.idx>=n-1)){const x=y.from(e);for(;l.length<n;){const _=x.get(l.length);if(isNaN(_))break;l.push(_),c+=_}}if(s.currentWindow=l,s.currentSum=c,s.currentCallCount=h,l.length<n)return NaN;const p=c/n;let u=0;for(let x=0;x<n;x++)u+=Math.abs(l[x]-p);const f=u/n;if(f===0)return 0;const m=(o-p)/(.015*f);return t.precision(m)}}function yh(t){return(e,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`change_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=s.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const p=y.from(e);for(;l.length<n+1;)l.push(p.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<=n)return NaN;const h=o-l[n];return t.precision(h)}}function xh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`cmo_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevGainsWindow=[...s.currentGainsWindow],s.prevLossesWindow=[...s.currentLossesWindow],s.prevGainsSum=s.currentGainsSum,s.prevLossesSum=s.currentLossesSum),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;const c=o-l,h=c>=0?c:0,p=c>=0?0:-c,u=[...s.prevGainsWindow],f=[...s.prevLossesWindow];let m=s.prevGainsSum,x=s.prevLossesSum;if(u.unshift(h),f.unshift(p),m+=h,x+=p,u.length<n)return s.currentGainsWindow=u,s.currentLossesWindow=f,s.currentGainsSum=m,s.currentLossesSum=x,NaN;if(u.length>n){const S=u.pop(),w=f.pop();m-=S,x-=w}s.currentGainsWindow=u,s.currentLossesWindow=f,s.currentGainsSum=m,s.currentLossesSum=x;const _=m+x;if(_===0)return t.precision(0);const b=100*(m-x)/_;return t.precision(b)}}function _h(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);let s=0,o=!1;for(let h=0;h<n;h++){const p=a.get(h);if(isNaN(p)){o=!0;break}s+=p}if(o)return NaN;let l=0;for(let h=0;h<n;h++){const p=a.get(h);l+=p*(h+1)}if(s===0)return NaN;const c=-l/s;return t.precision(c)}}function bh(t){return(e,i,r,n)=>{const a=y.from(r).get(0),s=y.from(e),o=y.from(i);if(t.idx<a-1)return NaN;let l=0,c=0,h=0,p=0,u=0,f=0;for(let S=0;S<a;S++){const w=s.get(S),E=o.get(S);isNaN(w)||isNaN(E)||(l+=w,c+=E,h+=w*E,p+=w*w,u+=E*E,f++)}if(f<2)return NaN;const m=f*h-l*c,x=f*p-l*l,_=f*u-c*c;if(x<=0||_<=0)return t.precision(0);const b=m/Math.sqrt(x*_);return t.precision(b)}}function wh(t){return(e,i,r)=>{const n=y.from(e),a=y.from(i),s=n.get(0),o=a.get(0),l=n.get(1),c=a.get(1);if(isNaN(s)||isNaN(o)||isNaN(l)||isNaN(c))return!1;const h=s>o&&l<=c,p=s<o&&l>=c;return h||p}}function vh(t){return(e,i)=>{const r=y.from(e),n=y.from(i),a=r.get(0),s=n.get(0),o=r.get(1),l=n.get(1);return o<=l&&a>s}}function Sh(t){return(e,i)=>{const r=y.from(e),n=y.from(i),a=r.get(0),s=n.get(0),o=r.get(1),l=n.get(1);return o>=l&&a<s}}function Eh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);const a=y.from(e).get(0);if(isNaN(a))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);const s=n.prevCumulativeSum+a;return n.currentCumulativeSum=s,t.precision(s)}}function Nh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`dev_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0)||0,l=[...s.prevWindow];let c=s.prevSum;for(l.unshift(o),c+=o;l.length>n;){const m=l.pop();c-=m}const h=s.prevCallCount+1;if(l.length<n&&(h>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;){const x=m.get(l.length);l.push(x),c+=x}}if(s.currentWindow=l,s.currentSum=c,s.currentCallCount=h,l.length<n)return NaN;const p=c/n;let u=0;for(let m=0;m<n;m++)u+=Math.abs(l[m]-p);const f=u/n;return t.precision(f)}}function Ch(t){return(e,i,r)=>{const n=y.from(e).get(0),a=y.from(i).get(0);t.taState||(t.taState={});const s=r||`dmi_${n}_${a}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});const o=t.taState[s];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN,NaN]];const p=t.idx>0?t.get(t.data.high,1):NaN,u=t.idx>0?t.get(t.data.low,1):NaN,f=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];const m=Math.max(l-c,Math.abs(l-f),Math.abs(c-f)),x=l-p,_=u-c,b=x>_&&x>0?x:0,S=_>x&&_>0?_:0;let w=o.prevInitCount,E=o.prevTrInitSum,A=o.prevPlusInitSum,C=o.prevMinusInitSum,M=o.prevSmoothedTR,O=o.prevSmoothedPlus,$=o.prevSmoothedMinus;if(w++,w<=n)E+=m,A+=b,C+=S,w===n&&(M=E/n,O=A/n,$=C/n);else{const ee=1/n;M=ee*m+(1-ee)*M,O=ee*b+(1-ee)*O,$=ee*S+(1-ee)*$}if(o.currentInitCount=w,o.currentTrInitSum=E,o.currentPlusInitSum=A,o.currentMinusInitSum=C,o.currentSmoothedTR=M,o.currentSmoothedPlus=O,o.currentSmoothedMinus=$,w<n)return[[NaN,NaN,NaN]];const B=M===0?0:100*O/M,R=M===0?0:100*$/M,q=B+R,re=q===0?0:100*Math.abs(B-R)/q;let fe=o.prevAdxInitCount,de=o.prevDxInitSum,me=o.prevADX,Ge=NaN;if(fe++,fe<=a)de+=re,fe===a&&(me=de/a,Ge=me);else{const ee=1/a;me=ee*re+(1-ee)*me,Ge=me}return o.currentAdxInitCount=fe,o.currentDxInitSum=de,o.currentADX=me,[[t.precision(B),t.precision(R),t.precision(Ge)]]}}function Ih(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`ema_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevEma=s.currentEma,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);const o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=s.prevInitCount,c=s.prevInitSum,h=s.prevEma;if(l<n){if(c+=o,l++,s.currentInitSum=c,s.currentInitCount=l,l===n){const f=c/n;return s.currentEma=f,t.precision(f)}return NaN}const p=2/(n+1),u=o*p+h*(1-p);return s.currentEma=u,t.precision(u)}}function kh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);for(let s=0;s<n;s++){const o=a.get(s),l=a.get(s+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Ah(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.high);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`highest_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const u=y.from(e);for(;l.length<n;)l.push(u.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.max(...h);return t.precision(p)}}function Th(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;let s=-1/0,o=NaN;for(let l=0;l<n;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c>s)&&(s=c,o=-l)}return o}}function Ph(t){return(e,i,r)=>{const n=y.from(i).get(0),a=Math.floor(n/2),s=Math.floor(Math.sqrt(n)),o=t.pine.ta.wma,l=o(e,a,r?`${r}_wma1`:void 0),c=o(e,n,r?`${r}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});const h=r||`hma_raw_${n}`;t.taState[h]||(t.taState[h]={lastIdx:-1,prevValues:[],currentValues:[]});const p=t.taState[h];t.idx>p.lastIdx&&(p.lastIdx>=0&&(p.prevValues=[...p.currentValues]),p.lastIdx=t.idx);const u=2*l-c,f=[...p.prevValues];f.unshift(u),f.length>s+1&&f.pop(),p.currentValues=f;const m=r?`${r}_hma_final`:`hma_final_${n}`;t.taState[m]||(t.taState[m]={lastIdx:-1,prevWindow:[],currentWindow:[]});const x=t.taState[m];t.idx>x.lastIdx&&(x.lastIdx>=0&&(x.prevWindow=[...x.currentWindow]),x.lastIdx=t.idx);const _=[...x.prevWindow];if(_.unshift(u),_.length<s)return x.currentWindow=_,NaN;for(;_.length>s;)_.pop();x.currentWindow=_;let b=0,S=0;for(let E=0;E<s;E++){const A=s-E;b+=_[E]*A,S+=A}const w=b/S;return t.precision(w)}}function Dh(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.high,0),n=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(a))return NaN;const s=(r-n)*a;if(s===0)return t.precision(0);const o=(2*i-r-n)/s;return t.precision(o)}}function Mh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?a=n:n!==void 0&&(l=y.from(n).get(0));let c;const h=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){const E=t.get(t.data.close,1);isNaN(E)?c=NaN:c=Math.max(h-p,Math.abs(h-E),Math.abs(p-E))}else c=h-p;const u=y.from(e).get(0);t.taState||(t.taState={});const f=a||`kc_${s}_${o}_${l}`;t.taState[f]||(t.taState[f]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const m=t.taState[f];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.basisState={...m.currentBasisState},m.rangeState={...m.currentRangeState}),m.lastIdx=t.idx);const x=(E,A,C,M)=>{if(isNaN(C))return Object.assign(A,E),A.prevEma!==null?A.prevEma:NaN;let O=E.initCount,$=E.initSum,B=E.prevEma;if(O<M){if($+=C,O++,A.initSum=$,A.initCount=O,A.prevEma=B,O===M){const re=$/M;return A.prevEma=re,re}return NaN}const R=2/(M+1),q=C*R+B*(1-R);return A.prevEma=q,A.initSum=$,A.initCount=O,q},_=x(m.basisState,m.currentBasisState,u,s),b=x(m.rangeState,m.currentRangeState,c,s);if(isNaN(_)||isNaN(b))return[[NaN,NaN,NaN]];const S=_+b*o,w=_-b*o;return[[t.precision(_),t.precision(S),t.precision(w)]]}}function Rh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?a=n:n!==void 0&&(l=y.from(n).get(0)),t.taState||(t.taState={});const c=a||`kcw_${s}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.basisState={...h.currentBasisState},h.rangeState={...h.currentRangeState}),h.lastIdx=t.idx);const p=(w,E,A,C)=>{if(isNaN(A))return Object.assign(E,w),E.prevEma!==null?E.prevEma:NaN;let M=w.initCount,O=w.initSum,$=w.prevEma;if(M<C){if(O+=A,M++,E.initSum=O,E.initCount=M,E.prevEma=$,M===C){const q=O/C;return E.prevEma=q,q}return NaN}const B=2/(C+1),R=A*B+$*(1-B);return E.prevEma=R,E.initSum=O,E.initCount=M,R};let u;const f=t.get(t.data.high,0),m=t.get(t.data.low,0);if(l){const w=t.get(t.data.close,1);isNaN(w)?u=NaN:u=Math.max(f-m,Math.abs(f-w),Math.abs(m-w))}else u=f-m;const x=y.from(e).get(0),_=p(h.basisState,h.currentBasisState,x,s),b=p(h.rangeState,h.currentRangeState,u,s);if(isNaN(_)||isNaN(b))return NaN;if(_===0)return t.precision(0);const S=2*b*o/_;return t.precision(S)}}function Vh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`linreg_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=y.from(e).get(0),h=[...l.prevWindow];for(h.unshift(c);h.length>a;)h.pop();const p=l.prevCallCount+1;if(h.length<a&&(p>=a||t.idx>=a-1)){const E=y.from(e);for(;h.length<a;)h.push(E.get(h.length))}if(l.currentWindow=h,l.currentCallCount=p,h.length<a)return NaN;let u=0,f=0,m=0,x=0;const _=a;for(let E=0;E<a;E++){const A=a-1-E,C=h[E];u+=A,f+=C,m+=A*C,x+=A*A}const b=_*x-u*u;if(b===0)return NaN;const S=(_*m-u*f)/b,w=(f-S*u)/_+S*(a-1-s);return t.precision(w)}}function Oh(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.low);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`lowest_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const u=y.from(e);for(;l.length<n;)l.push(u.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.min(...h);return t.precision(p)}}function Lh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;let s=1/0,o=NaN;for(let l=0;l<n;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c<s)&&(s=c,o=-l)}return o}}function jh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0),c=a||`macd_${s}_${o}_${l}`,h=`${c}_fast`,p=`${c}_slow`,u=`${c}_signal`,f=t.pine.ta.ema(e,s,h),m=t.pine.ta.ema(e,o,p);let x=NaN;!isNaN(f)&&!isNaN(m)&&(x=f-m);let _=NaN;isNaN(x)||(_=t.pine.ta.ema(x,l,u));let b=NaN;return!isNaN(x)&&!isNaN(_)&&(b=x-_),[[t.precision(x),t.precision(_),t.precision(b)]]}}function Bh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`median_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const h=l.slice().sort((f,m)=>f-m),p=Math.floor(n/2),u=n%2===0?(h[p-1]+h[p])/2:h[p];return t.precision(u)}}function Fh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`mfi_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevUpperWindow=[...s.currentUpperWindow],s.prevLowerWindow=[...s.currentLowerWindow],s.prevUpperSum=s.currentUpperSum,s.prevLowerSum=s.currentLowerSum),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;const h=isNaN(l)?NaN:o-l,p=c*(h<=0?0:o),u=c*(h>=0?0:o),f=[...s.prevUpperWindow],m=[...s.prevLowerWindow];let x=s.prevUpperSum,_=s.prevLowerSum;if(f.unshift(p),m.unshift(u),x+=p,_+=u,f.length<n)return s.currentUpperWindow=f,s.currentLowerWindow=m,s.currentUpperSum=x,s.currentLowerSum=_,NaN;if(f.length>n){const S=f.pop(),w=m.pop();x-=S,_-=w}if(s.currentUpperWindow=f,s.currentLowerWindow=m,s.currentUpperSum=x,s.currentLowerSum=_,_===0)return t.precision(100);if(x===0)return t.precision(0);const b=100-100/(1+x/_);return t.precision(b)}}function $h(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;const s=new Map;for(let c=0;c<n;c++){const h=a.get(c);isNaN(h)||s.set(h,(s.get(h)||0)+1)}if(s.size===0)return NaN;let o=NaN,l=-1;for(const[c,h]of s.entries())h>l?(l=h,o=c):h===l&&c<o&&(o=c);return o}}function Wh(t){return(e,i,r)=>{const n=y.from(i).get(0);return t.pine.ta.change(e,n,r)}}function Uh(t){return e=>{t.taState||(t.taState={});const i=e||"nvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedNVI:1,tentativeNVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(n)?0:n,c=isNaN(a)?0:a,h=isNaN(s)?0:s,p=isNaN(o)?0:o;let u=r.committedNVI;if(!(l===0||c===0)&&h<p){const f=(l-c)/c;u=u+f*u}return r.tentativeNVI=u,t.precision(u)}}function qh(t){return()=>{t.taState||(t.taState={});const e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});const i=t.taState[e];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.committedOBV=i.tentativeOBV),i.lastIdx=t.idx);const r=t.get(t.data.close,0),n=t.get(t.data.volume,0),a=t.get(t.data.close,1);if(isNaN(a))return i.tentativeOBV=0,t.precision(0);let s=i.committedOBV;return r>a?s+=n:r<a&&(s-=n),i.tentativeOBV=s,t.precision(s)}}function zh(t){return(e,i,r)=>e instanceof y?i?new y(e.data,e.offset+i):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function Kh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e);if(t.idx<a-1)return NaN;const l=[];for(let m=0;m<a;m++){const x=o.get(m);if(isNaN(x))return NaN;l.push(x)}l.sort((m,x)=>m-x);let c=s/100*a-.5;c<0&&(c=0),c>a-1&&(c=a-1);const h=Math.floor(c),p=Math.ceil(c);if(h===p)return t.precision(l[h]);const u=c-h,f=l[h]+u*(l[p]-l[h]);return t.precision(f)}}function Hh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e);if(t.idx<a-1)return NaN;const l=[];for(let h=0;h<a;h++){const p=o.get(h);isNaN(p)||l.push(p)}if(l.length===0)return NaN;l.sort((h,p)=>h-p);let c=Math.ceil(s/100*l.length)-1;return c<0&&(c=0),c>=l.length&&(c=l.length-1),t.precision(l[c])}}function Gh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n)return NaN;const s=a.get(0);if(isNaN(s))return NaN;let o=0,l=0;for(let c=1;c<=n;c++){const h=a.get(c);isNaN(h)||(l++,h<=s&&o++)}return l===0?NaN:t.precision(o/l*100)}}function Yh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const a=t[n-i];let s=!0;for(let o=1;o<=e;o++)if(t[n-i-o]>=a){s=!1;break}if(s){for(let o=1;o<=i;o++)if(t[n-i+o]>=a){s=!1;break}}s&&(r[n]=a)}return r}function Xh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.high);const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e).toArray(),l=Yh(o,a,s),c=t.idx;return t.precision(l[c])}}function Qh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const a=t[n-i];let s=!0;for(let o=1;o<=e;o++)if(t[n-i-o]<=a){s=!1;break}if(s){for(let o=1;o<=i;o++)if(t[n-i+o]<=a){s=!1;break}}s&&(r[n]=a)}return r}function Zh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.low);const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e).toArray(),l=Qh(o,a,s),c=t.idx;return t.precision(l[c])}}function Jh(t){return e=>{t.taState||(t.taState={});const i=e||"pvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedPVI:1,tentativePVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(n)?0:n,c=isNaN(a)?0:a,h=isNaN(s)?0:s,p=isNaN(o)?0:o;let u=r.committedPVI;if(!(l===0||c===0)&&h>p){const f=(l-c)/c;u=u+f*u}return r.tentativePVI=u,t.precision(u)}}function eu(t){return e=>{t.taState||(t.taState={});const i=e||"pvt";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0);let o=r.prevCumulativeSum;if(!isNaN(n)&&!isNaN(a)&&!isNaN(s)&&a!==0){const l=(n-a)/a*s;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function tu(t){return(e,i,r)=>{const n=t.pine.ta.highest(e,i,(r||"range")+"_h"),a=t.pine.ta.lowest(e,i,(r||"range")+"_l");return isNaN(n)||isNaN(a)?NaN:t.precision(n-a)}}function iu(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);for(let s=0;s<n;s++){const o=a.get(s),l=a.get(s+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function ru(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`rma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevRma=s.currentRma,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);const o=y.from(e).get(0)||0;let l=s.prevInitCount,c=s.prevInitSum,h=s.prevRma;if(l<n){if(c+=o,l++,s.currentInitSum=c,s.currentInitCount=l,l===n){const f=c/n;return s.currentRma=f,t.precision(f)}return NaN}const p=1/n,u=o*p+h*(1-p);return s.currentRma=u,t.precision(u)}}function nu(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`roc_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=s.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const u=y.from(e);for(;l.length<n+1;)l.push(u.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<=n)return NaN;const h=l[n],p=(o-h)/h*100;return t.precision(p)}}function su(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`rsi_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevPrevValue=s.currentPrevValue,s.prevAvgGain=s.currentAvgGain,s.prevAvgLoss=s.currentAvgLoss,s.prevInitGains=[...s.currentInitGains],s.prevInitLosses=[...s.currentInitLosses]),s.lastIdx=t.idx);const o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;const l=s.prevPrevValue;if(l===null||isNaN(l))return s.currentPrevValue=o,s.currentInitGains=[...s.prevInitGains],s.currentInitLosses=[...s.prevInitLosses],s.currentAvgGain=s.prevAvgGain,s.currentAvgLoss=s.prevAvgLoss,NaN;let c=s.prevAvgGain,h=s.prevAvgLoss;const p=[...s.prevInitGains],u=[...s.prevInitLosses],f=o-l,m=f>0?f:0,x=f<0?-f:0;if(p.length<n){if(p.push(m),u.push(x),s.currentInitGains=p,s.currentInitLosses=u,s.currentPrevValue=o,p.length===n){c=p.reduce((S,w)=>S+w,0)/n,h=u.reduce((S,w)=>S+w,0)/n,s.currentAvgGain=c,s.currentAvgLoss=h;const b=h===0?100:100-100/(1+c/h);return t.precision(b)}return NaN}c=(c*(n-1)+m)/n,h=(h*(n-1)+x)/n,s.currentAvgGain=c,s.currentAvgLoss=h,s.currentPrevValue=o;const _=h===0?100:100-100/(1+c/h);return t.precision(_)}}function au(t){return(e,i,r,n)=>{const a=y.from(e).get(0),s=y.from(i).get(0),o=y.from(r).get(0);t.taState||(t.taState={});const l=n||`sar_${a}_${s}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});const c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let h=c.prevResult,p=c.prevMaxMin,u=c.prevAcceleration,f=c.prevIsBelow,m=c.prevBarIndex;const x=t.get(t.data.high,0),_=t.get(t.data.low,0),b=t.get(t.data.close,0),S=t.get(t.data.close,1),w=t.get(t.data.high,1),E=t.get(t.data.low,1),A=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(x)||isNaN(_)||isNaN(b))return c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,NaN;let M=!1;return m===1&&(b>S?(f=!0,p=x,h=E):(f=!1,p=_,h=w),M=!0,u=a),m>=1&&(h=h+u*(p-h),f?h>_&&(M=!0,f=!1,h=Math.max(x,p),p=_,u=a):h<x&&(M=!0,f=!0,h=Math.min(_,p),p=x,u=a),M||(f?x>p&&(p=x,u=Math.min(u+s,o)):_<p&&(p=_,u=Math.min(u+s,o))),f?(h=Math.min(h,E),m>1&&(h=Math.min(h,C))):(h=Math.max(h,w),m>1&&(h=Math.max(h,A)))),m++,c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,m<=1?NaN:t.precision(h)}}function ou(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`sma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;let h=!1;if(l.length<n&&(c>=n||t.idx>=n-1)){const x=y.from(e);for(;l.length<n;)l.push(x.get(l.length));h=!0}let p;const u=o==null||Number.isNaN(o);let f=!Number.isNaN(s.prevSum)&&!u&&!h;if(f){let x=s.prevSum+o;if(s.prevWindow.length>=n){const _=s.prevWindow[s.prevWindow.length-1];_==null||Number.isNaN(_)?f=!1:x-=_}f&&(p=x)}if(!f){p=0;let x=!1;for(const _ of l){if(_==null||Number.isNaN(_)){x=!0;break}p+=_}x&&(p=NaN)}if(s.currentWindow=l,s.currentSum=p,s.currentCallCount=c,l.length<n)return NaN;const m=p/n;return t.precision(m)}}function lu(t){return(e,i,r=!0,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`stdev_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum,l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=y.from(e).get(0);if(c==null||isNaN(c))return NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}const u=l.prevCallCount+1;if(h.length<a&&(u>=a||t.idx>=a-1)){const b=y.from(e);for(;h.length<a;){const S=b.get(h.length);if(S==null||isNaN(S))break;h.push(S),p+=S}}if(l.currentWindow=h,l.currentSum=p,l.currentCallCount=u,h.length<a)return NaN;const f=p/a;let m=0;for(let b=0;b<a;b++)m+=Math.pow(h[b]-f,2);const x=s?a:a-1,_=Math.sqrt(m/x);return t.precision(_)}}function cu(t){return(e,i,r,n,a)=>{const s=y.from(n).get(0);t.taState||(t.taState={});const o=a||`stoch_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);const c=y.from(e).get(0),h=y.from(i).get(0),p=y.from(r).get(0);if(isNaN(c)||isNaN(h)||isNaN(p))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;const u=[...l.prevHighWindow],f=[...l.prevLowWindow];if(u.unshift(h),f.unshift(p),u.length>s&&(u.pop(),f.pop()),l.currentHighWindow=u,l.currentLowWindow=f,u.length<s)return NaN;let m=u[0],x=f[0];for(let S=1;S<s;S++)u[S]>m&&(m=u[S]),f[S]<x&&(x=f[S]);const _=m-x;if(_===0)return NaN;const b=100*(c-x)/_;return t.precision(b)}}function hu(t){return(e,i,r)=>{const n=y.from(e).get(0),a=y.from(i).get(0);t.taState||(t.taState={});const s=r||`supertrend_${n}_${a}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});const o=t.taState[s];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrSum=o.currentTrSum,o.prevAtrValue=o.currentAtrValue,o.prevAtrCount=o.currentAtrCount,o.prevLowerBand=o.currentLowerBand,o.prevUpperBand=o.currentUpperBand,o.prevSuperTrend=o.currentSuperTrend,o.prevDirection=o.currentDirection),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN]];const p=(l+c)/2,u=t.idx>0?t.get(t.data.close,1):NaN;let f;isNaN(u)?f=l-c:f=Math.max(l-c,Math.abs(l-u),Math.abs(c-u));let m=o.prevAtrCount,x=o.prevTrSum,_=o.prevAtrValue;m++,m<=a?(x+=f,m===a&&(_=x/a)):_=(_*(a-1)+f)/a;const b=_;if(o.currentAtrCount=m,o.currentTrSum=x,o.currentAtrValue=_,isNaN(b))return[[NaN,NaN]];let S=p+n*b,w=p-n*b;const E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,A=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>E||u<E||(w=E),isNaN(o.prevUpperBand)||S<A||u>A||(S=A);let C,M;const O=o.prevSuperTrend;return m===a?C=1:O===o.prevUpperBand?C=h>S?-1:1:C=h<w?1:-1,M=C===-1?w:S,o.currentLowerBand=w,o.currentUpperBand=S,o.currentSuperTrend=M,o.currentDirection=C,[[t.precision(M),C]]}}function uu(t){return(e,i)=>{const r=[1,2,2,1],n=6;t.taState||(t.taState={});const a=i||"swma";t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],currentWindow:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){const h=y.from(e);for(;l.length<4;)l.push(h.get(l.length))}if(s.currentWindow=l,l.length<4)return NaN;let c=0;for(let h=0;h<4;h++)c+=r[h]*l[3-h];return c/=n,t.precision(c)}}function pu(t){return(e,i)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=y.from(e).get(0));const n=t.get(t.data.high,0),a=t.get(t.data.low,0),s=t.get(t.data.close,1);if(isNaN(s))return r?t.precision(n-a):NaN;const o=Math.max(n-a,Math.abs(n-s),Math.abs(a-s));return t.precision(o)}}function fu(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`tsi_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return NaN;const h=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(h))return NaN;const p=Math.abs(h),u=2/(s+1),f=2/(a+1),m=2/(s+1),x=2/(a+1);let _=l.prevEma1PcCount,b=l.prevEma1PcSum,S=l.prevEma1PcValue;_++,_<=s?(b+=h,_===s&&(S=b/s)):S=h*u+S*(1-u);let w=l.prevEma1AbsCount,E=l.prevEma1AbsSum,A=l.prevEma1AbsValue;if(w++,w<=s?(E+=p,w===s&&(A=E/s)):A=p*m+A*(1-m),isNaN(S)||isNaN(A))return l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=S,l.currentEma1AbsCount=w,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,NaN;let C=l.prevEma2PcCount,M=l.prevEma2PcSum,O=l.prevEma2PcValue;C++,C<=a?(M+=S,C===a&&(O=M/a)):O=S*f+O*(1-f);let $=l.prevEma2AbsCount,B=l.prevEma2AbsSum,R=l.prevEma2AbsValue;if($++,$<=a?(B+=A,$===a&&(R=B/a)):R=A*x+R*(1-x),l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=S,l.currentEma1AbsCount=w,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,l.currentEma2PcCount=C,l.currentEma2PcSum=M,l.currentEma2PcValue=O,l.currentEma2AbsCount=$,l.currentEma2AbsSum=B,l.currentEma2AbsValue=R,isNaN(O)||isNaN(R))return NaN;if(R===0)return t.precision(0);const q=O/R;return t.precision(q)}}function du(t){return(e,i,r,n)=>{t.taState||(t.taState={});const a=n||"valuewhen";t.taState[a]||(t.taState[a]={lastIdx:-1,prevValues:[],currentValues:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevValues=[...s.currentValues]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(i).get(0),c=y.from(r).get(0),h=[...s.prevValues];if(o&&h.push(l),s.currentValues=h,isNaN(c)||c<0)return NaN;const p=h.length-1-c;if(p<0)return NaN;const u=h[p];return typeof u=="number"?t.precision(u):u}}function mu(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`variance_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;)l.push(m.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;let h=0,p=0;for(let m=0;m<n;m++)h+=l[m],p+=l[m]*l[m];const u=h/n,f=p/n-u*u;return t.precision(f)}}function gu(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"vwap";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativePV=n.currentCumulativePV,n.prevCumulativeVolume=n.currentCumulativeVolume,n.prevLastSessionDate=n.currentLastSessionDate),n.lastIdx=t.idx);const a=y.from(e).get(0),s=y.from(t.data.volume).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=dt(o,l),h=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`;let p=n.prevCumulativePV,u=n.prevCumulativeVolume,f=n.prevLastSessionDate;if(f!==h&&(p=0,u=0,f=h),p+=a*s,u+=s,n.currentCumulativePV=p,n.currentCumulativeVolume=u,n.currentLastSessionDate=f,u===0)return NaN;const m=p/u;return t.precision(m)}}function yu(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`vwma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevVolumeWindow=[...s.currentVolumeWindow]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=t.get(t.data.volume,0),c=[...s.prevWindow],h=[...s.prevVolumeWindow];for(c.unshift(o),h.unshift(l);c.length>n;)c.pop(),h.pop();if(c.length<n&&t.idx>=n-1){const m=y.from(e),x=y.from(t.data.volume);for(;c.length<n;)c.push(m.get(c.length)),h.push(x.get(h.length))}if(s.currentWindow=c,s.currentVolumeWindow=h,c.length<n)return NaN;let p=0,u=0;for(let m=0;m<n;m++)p+=c[m]*h[m],u+=h[m];const f=p/u;return t.precision(f)}}function xu(t){return e=>{t.taState||(t.taState={});const i=e||"wad";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.high,0),s=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(n)||isNaN(a)||isNaN(s))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){const h=Math.max(a,o),p=Math.min(s,o),u=n-o;u>0?l=n-p:u<0&&(l=n-h)}const c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function _u(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`wma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;let h=0,p=0;for(let f=0;f<n;f++){const m=n-f;h+=l[f]*m,p+=m}const u=h/p;return t.precision(u)}}function bu(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`wpr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const a=t.taState[n];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevHighWindow=[...a.currentHighWindow],a.prevLowWindow=[...a.currentLowWindow]),a.lastIdx=t.idx);const s=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(s)||isNaN(o)||isNaN(l))return a.currentHighWindow=[...a.prevHighWindow],a.currentLowWindow=[...a.prevLowWindow],NaN;const c=[...a.prevHighWindow],h=[...a.prevLowWindow];if(c.unshift(s),h.unshift(o),c.length>r&&(c.pop(),h.pop()),a.currentHighWindow=c,a.currentLowWindow=h,c.length<r)return NaN;let p=c[0],u=h[0];for(let x=1;x<r;x++)c[x]>p&&(p=c[x]),h[x]<u&&(u=h[x]);const f=p-u;if(f===0)return t.precision(0);const m=(p-l)/f*-100;return t.precision(m)}}function wu(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.open,0),n=t.get(t.data.high,0),a=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(a)||isNaN(s))return NaN;const o=n-a;if(o===0)return t.precision(0);const l=(i-r)/o*s;return t.precision(l)}}const vu={accdist:hh,alma:uh,atr:ph,barssince:fh,bb:dh,bbw:mh,cci:gh,change:yh,cmo:xh,cog:_h,correlation:bh,cross:wh,crossover:vh,crossunder:Sh,cum:Eh,dev:Nh,dmi:Ch,ema:Ih,falling:kh,highest:Ah,highestbars:Th,hma:Ph,iii:Dh,kc:Mh,kcw:Rh,linreg:Vh,lowest:Oh,lowestbars:Lh,macd:jh,median:Bh,mfi:Fh,mode:$h,mom:Wh,nvi:Uh,obv:qh,param:zh,percentile_linear_interpolation:Kh,percentile_nearest_rank:Hh,percentrank:Gh,pivothigh:Xh,pivotlow:Zh,pvi:Jh,pvt:eu,range:tu,rising:iu,rma:ru,roc:nu,rsi:su,sar:au,sma:ou,stdev:lu,stoch:cu,supertrend:hu,swma:uu,tr:pu,tsi:fu,valuewhen:du,variance:mu,vwap:gu,vwma:yu,wad:xu,wma:_u,wpr:bu,wvad:wu};class Su{constructor(e){this.context=e,Object.entries(vu).forEach(([i,r])=>{this[i]=r(e)})}accdist;alma;atr;barssince;bb;bbw;cci;change;cmo;cog;correlation;cross;crossover;crossunder;cum;dev;dmi;ema;falling;highest;highestbars;hma;iii;kc;kcw;linreg;lowest;lowestbars;macd;median;mfi;mode;mom;nvi;obv;param;percentile_linear_interpolation;percentile_nearest_rank;percentrank;pivothigh;pivotlow;pvi;pvt;range;rising;rma;roc;rsi;sar;sma;stdev;stoch;supertrend;swma;tr;tsi;valuewhen;variance;vwap;vwma;wad;wma;wpr;wvad}function Eu(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC")return 0;const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const s=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return s*(o*60+l)}const n=dt(t,e),a=new Date(Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second));return Math.round((a.getTime()-t)/6e4)}function Nu(t,e){const i=e>=0?"+":"-",r=a=>String(Math.floor(Math.abs(a))).padStart(2,"0"),n=i+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${n}]`}class Cu{constructor(e){this.context=e}logFormat(e,...i){return e.replace(/{(\d+)}/g,(r,n)=>i[n])}param(e,i=0,r){return y.from(e).get(i)}_formatTimestamp(){const e=this.context.data.openTime.data[this.context.idx],i=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=Eu(e,i);return Nu(e,r)}warning(e,...i){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}error(e,...i){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}info(e,...i){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}}class Iu{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}tostring(e,i){if(typeof e!="number"||isNaN(e)||!i)return String(e);if(i==="mintick"){const n=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(a)}if(i==="integer")return String(Math.round(e));if(i==="percent")return(e*100).toFixed(2)+"%";if(i==="price"){const n=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(a)}if(i==="volume")return String(Math.round(e));const r=i.indexOf(".");if(r>=0){const n=i.substring(r+1).length;return e.toFixed(n)}return i.includes("#")||i.includes("0")?String(Math.round(e)):String(e)}tonumber(e){return Number(e)}lower(e){return String(e).toLowerCase()}upper(e){return String(e).toUpperCase()}trim(e){return String(e).trim()}repeat(e,i,r=""){return Array(i).fill(e).join(r||"")}replace_all(e,i,r){return String(e).replaceAll(i,r)}replace(e,i,r,n=0){const a=String(e),s=String(i),o=String(r),l=Math.floor(Number(n))||0;if(s==="")return a;let c=0,h=0;for(;;){const p=a.indexOf(s,c);if(p===-1)return a;if(h===l)return a.substring(0,p)+o+a.substring(p+s.length);h++,c=p+s.length}}contains(e,i){return String(e).includes(i)}endswith(e,i){return String(e).endsWith(i)}startswith(e,i){return String(e).startsWith(i)}pos(e,i){const r=String(e).indexOf(i);return r===-1?NaN:r}length(e){return String(e).length}match(e,i){return String(e).match(new RegExp(i))}split(e,i){return new D(String(e).split(i),T.string,this.context)}substring(e,i,r){return String(e).substring(i,r)}format(e,...i){return e.replace(/\{(\d+)(?:,number,([^}]+))?\}/g,(r,n,a)=>{const s=i[n];return a&&typeof s=="number"&&!isNaN(s)?this.tostring(s,a):String(s)})}}const Vt={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function hr(t){if(!t||/^\d+$/.test(t))return t;if(Vt[t])return Vt[t];const e=t.toLowerCase();if(Vt[e])return Vt[e];if(t.length===1){const r=t.toUpperCase();if(["D","W","M","S"].includes(r))return r}const i=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(i)){const r=parseInt(t);if(!isNaN(r))return r+i}return t}class ku{constructor(e){this.context=e}_normalized=null;param(e,i=0,r){return y.from(e).get(i)}get normalized(){return this._normalized===null&&(this._normalized=hr(this.context.timeframe)),this._normalized}get unit(){return this.normalized.slice(-1).toUpperCase()}get main_period(){return this.normalized}get period(){return this.normalized}get multiplier(){const e=parseInt(this.normalized);return isNaN(e)?1:e}get isdwm(){return["D","W","M"].includes(this.unit)}get isdaily(){return this.unit==="D"}get isweekly(){return this.unit==="W"}get ismonthly(){return this.unit==="M"}get isseconds(){return this.unit==="S"}get isminutes(){return/^\d+$/.test(this.normalized)}get isintraday(){return!this.isdwm}from_seconds(e){return e<60?Math.ceil(e/5)*5+"S":e<3600*24?Math.ceil(e/60):e<=3600*24*7*52?e%(3600*24*7)===0?Math.ceil(e/604800)+"W":Math.ceil(e/(3600*24))+"D":"12M"}in_seconds(e){e==null?e=this.normalized:e=hr(e);const i=e.slice(-1).toUpperCase(),r=parseInt(e);return i==="S"?isNaN(r)?1:r:i==="D"?(isNaN(r)?1:r)*60*60*24:i==="W"?(isNaN(r)?1:r)*60*60*24*7:i==="M"?(isNaN(r)?1:r)*60*60*24*30:isNaN(r)?0:r*60}}const Au=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],Tu=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Pu={series:"series",title:"string",char:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Du=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Mu=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],Ru=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],Vu=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],ur=["color","offset","editable","show_last","title","display","force_overlay"],Ou=["price","title","color","linestyle","linewidth","editable","display"],Lu=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],ju={series:"series",title:"string",color:"color",linewidth:"number",style:"string",trackprice:"boolean",histbase:"number",offset:"number",join:"bool",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Bu={series:"series",title:"string",style:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Fu={series:"series",title:"string",colorup:"color",colordown:"color",offset:"number",minheight:"number",maxheight:"number",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},$u={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Wu={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",wickcolor:"color",bordercolor:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},pr={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},Uu={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},qu={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"};class zu{constructor(e){this.context=e}_resolvePlotKey(e,i){if(e){const r=this.context.plots[e];return!r||!i||r._callsiteId===i?e:e+i}return i||"plot"}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}get linestyle_dashed(){return"linestyle_dashed"}get linestyle_dotted(){return"linestyle_dotted"}get linestyle_solid(){return"linestyle_solid"}get style_area(){return"style_area"}get style_areabr(){return"style_areabr"}get style_circles(){return"style_circles"}get style_columns(){return"style_columns"}get style_cross(){return"style_cross"}get style_histogram(){return"style_histogram"}get style_line(){return"style_line"}get style_linebr(){return"style_linebr"}get style_stepline(){return"style_stepline"}get style_stepline_diamond(){return"style_stepline_diamond"}get style_steplinebr(){return"style_steplinebr"}param(e,i=0,r){return y.from(e).get(i)}plotchar(...e){const i=ke(e),r=X(e,Tu,Pu),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:a,_plotKey:l,_callsiteId:i});const c=y.from(n).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){const i=ke(e),r=X(e,Au,ju),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i),c="color"in s;if(!this.context.plots[l]){const f=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:f},title:a,_plotKey:l,_callsiteId:i}}const h=y.from(n).get(0),p=o.color,u={color:c?typeof p=="string"?p:void 0:p||"#2962ff"};return"offset"in s&&(u.offset=o.offset),this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:h,options:u}),this.context.plots[l]}plotshape(...e){const i=ke(e),r=X(e,Du,Bu),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i);if(!this.context.plots[l]){const h=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:h},title:a,_plotKey:l,_callsiteId:i}}const c=y.from(n).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){const i=ke(e),r=X(e,Mu,Fu),{series:n,title:a,...s}=r,o=y.from(n).get(0),l=this.extractPlotOptions(s),c=this._resolvePlotKey(a,i);if(!this.context.plots[c]){const h=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:h},title:a,_plotKey:c,_callsiteId:i}}return this.context.plots[c].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){const i=ke(e),r=X(e,Ru,$u),{open:n,high:a,low:s,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"bar",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[y.from(n).get(0),y.from(a).get(0),y.from(s).get(0),y.from(o).get(0)];this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color}})}plotcandle(...e){const i=ke(e),r=X(e,Vu,Wu),{open:n,high:a,low:s,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"candle",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[y.from(n).get(0),y.from(a).get(0),y.from(s).get(0),y.from(o).get(0)];return this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color,wickcolor:h.wickcolor,bordercolor:h.bordercolor}}),this.context.plots[p]}bgcolor(...e){const i=ke(e),r=X(e,ur,pr),{title:n,...a}=r,s=this.extractPlotOptions(a),o=this._resolvePlotKey(n,i);if(!this.context.plots[o]){const l=s.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...s,style:"background",overlay:l},title:n,_plotKey:o,_callsiteId:i}}this.context.plots[o].data.push({title:n,time:this.context.marketData[this.context.idx].openTime,value:s.color&&s.color!=="na"&&s?.color.toString()!=="NaN",options:{color:s.color}})}barcolor(...e){const i=ke(e),r=X(e,ur,pr),{title:n,...a}=r,s=this.extractPlotOptions(a),o=this._resolvePlotKey(n,i);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...s,style:"barcolor"},title:n,_plotKey:o,_callsiteId:i}),this.context.plots[o].data.push({title:n,time:this.context.marketData[this.context.idx].openTime,value:s.color&&s.color!=="na"&&s?.color.toString()!=="NaN",options:{color:s.color}}),this.context.plots[o]}}class Ku{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=ke(e),r=X(e,Ou,Uu),{price:n,title:a,color:s,linestyle:o,linewidth:l,editable:c,display:h}=r,p=[n,{title:a,color:s,linestyle:o,linewidth:l,editable:c,display:h,style:"hline"}];return i&&p.push({__callsiteId:i}),this.context.pine.plot.any(...p)}}class Hu{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=ke(e),r=e.length>=6&&typeof e[2]=="number",n=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||n!==null){const a=e[0],s=e[1],o=n?y.from(n.top_value).get(0):e[2],l=n?y.from(n.bottom_value).get(0):e[3],c=n?y.from(n.top_color).get(0):e[4],h=n?y.from(n.bottom_color).get(0):e[5],p=n?n.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,u=a?._plotKey||a?.title,f=s?._plotKey||s?.title;let m=p||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i),this.context.plots[m]||(this.context.plots[m]={title:p||"Fill",plot1:u,plot2:f,data:[],options:{plot1:u,plot2:f,style:"fill",gradient:!0},_plotKey:m,_callsiteId:i}),this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:h}})}else{const a=X(e,Lu,qu),{plot1:s,plot2:o,color:l,title:c,editable:h,show_last:p,fillgaps:u,display:f}=a;let m=c||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i);const _=y.from(l).get(0);if(!this.context.plots[m]){const b=s?._plotKey||s?.title,S=o?._plotKey||o?.title;this.context.plots[m]={title:c||"Fill",plot1:b,plot2:S,data:[],options:{plot1:b,plot2:S,color:_,editable:h,show_last:p,fillgaps:u,display:f,style:"fill"},_plotKey:m,_callsiteId:i}}this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:_}})}}}class Gu{constructor(e){this.context=e;const i=this.context;this.point={new(r,n,a){return new se(r,n,a??NaN)},from_index(r,n){return new se(void 0,r,n)},from_time(r,n){return new se(r,void 0,n)},copy(r){return r.copy()},now(r){const n=i.idx,a=i.marketData[n]?.openTime;return new se(a,n,r)}}}point;param(e,i=0,r){return y.from(e).get(i)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){return!0}is_heikinashi(){return!1}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}}let Yu=0;class Di{id;x;y;text;xloc;yloc;color;style;textcolor;size;textalign;tooltip;text_font_family;force_overlay;_deleted;_helper;_createdAtBar=-1;constructor(e,i,r="",n="bi",a="pr",s="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){this.id=Yu++,this.x=e,this.y=i,this.text=r,this.xloc=n,this.yloc=a,this.color=s,this.style=o,this.textcolor=l,this.size=c,this.textalign=h,this.tooltip=p,this.text_font_family=u,this.force_overlay=f,this._deleted=!1,this._helper=null}set_x(e){this._helper?this._helper.set_x(this,e):this._deleted||(this.x=e)}set_y(e){this._helper?this._helper.set_y(this,e):this._deleted||(this.y=e)}set_xy(e,i){this._helper?this._helper.set_xy(this,e,i):this._deleted||(this.x=e,this.y=i)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_textcolor(e){this._helper?this._helper.set_textcolor(this,e):this._deleted||(this.textcolor=e)}set_size(e){this._helper?this._helper.set_size(this,e):this._deleted||(this.size=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_textalign(e){this._helper?this._helper.set_textalign(this,e):this._deleted||(this.textalign=e)}set_tooltip(e){this._helper?this._helper.set_tooltip(this,e):this._deleted||(this.tooltip=e)}set_xloc(e){this._helper?this._helper.set_xloc(this,e):this._deleted||(this.xloc=e)}set_yloc(e){this._helper?this._helper.set_yloc(this,e):this._deleted||(this.yloc=e)}set_point(e){this._helper&&this._helper.set_point(this,e)}set_text_font_family(e){this._deleted||(this.text_font_family=e)}get_x(){return this.x}get_y(){return this.y}get_text(){return this.text}delete(){this._deleted=!0}copy(){return new Di(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay)}toPlotData(){return{id:this.id,x:this.x,y:this.y,text:this.text,xloc:this.xloc,yloc:this.yloc,color:this.color,style:this.style,textcolor:this.textcolor,size:this.size,textalign:this.textalign,tooltip:this.tooltip,text_font_family:this.text_font_family,force_overlay:this.force_overlay,_deleted:this._deleted}}}const Xu=[["x","y","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"],["point","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"]],Qu={x:"number",y:"number",text:"string",xloc:"string",yloc:"string",color:"color",style:"string",textcolor:"color",size:"string",textalign:"string",tooltip:"string",text_font_family:"string",force_overlay:"boolean",point:"point"};class Zu{constructor(e){this.context=e}_labels=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._labels.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],n.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:n,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof _t)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){const i=e.get(0);return typeof i=="number"&&isNaN(i)?null:i}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,i,r="",n="bi",a="pr",s="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){const m=new Di(e,i,this._resolve(r),this._resolve(n),this._resolve(a),this._resolve(s),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(h),this._resolve(p),this._resolve(u),f);return m._helper=this,m._createdAtBar=this.context.idx,this._labels.push(m),this.syncToPlot(),m}new(...e){const i=X(e,Xu,Qu);let r,n,a=i.xloc;if(i.point instanceof se){const s=i.point;s.index!==void 0?(r=s.index,a=a||"bi"):s.time!==void 0?(r=s.time,a=a||"bt"):(r=0,a=a||"bi"),n=s.price}else r=i.x,n=i.y;return this._createLabel(r,n,i.text,a,i.yloc,i.color,i.style,i.textcolor,i.size,i.textalign,i.tooltip,i.text_font_family,i.force_overlay)}any(...e){return this.new(...e)}set_x(e,i){e&&!e._deleted&&(e.x=i)}set_y(e,i){e&&!e._deleted&&(e.y=i)}set_xy(e,i,r){e&&!e._deleted&&(e.x=i,e.y=r)}set_text(e,i){e&&!e._deleted&&(e.text=i)}set_color(e,i){e&&!e._deleted&&(e.color=i)}set_textcolor(e,i){e&&!e._deleted&&(e.textcolor=i)}set_size(e,i){e&&!e._deleted&&(e.size=i)}set_style(e,i){e&&!e._deleted&&(e.style=i)}set_textalign(e,i){e&&!e._deleted&&(e.textalign=i)}set_tooltip(e,i){e&&!e._deleted&&(e.tooltip=i)}set_xloc(e,i){e&&!e._deleted&&(e.xloc=i)}set_yloc(e,i){e&&!e._deleted&&(e.yloc=i)}set_point(e,i){e&&!e._deleted&&i&&(i.index!==void 0?(e.x=i.index,e.xloc="bi"):i.time!==void 0&&(e.x=i.time,e.xloc="bt"),e.y=i.price)}get_x(e){return e?e.x:NaN}get_y(e){return e?e.y:NaN}get_text(e){return e?e.text:""}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._labels.push(i),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_label_down(){return"style_label_down"}get style_label_up(){return"style_label_up"}get style_label_left(){return"style_label_left"}get style_label_right(){return"style_label_right"}get style_label_lower_left(){return"style_label_lower_left"}get style_label_lower_right(){return"style_label_lower_right"}get style_label_upper_left(){return"style_label_upper_left"}get style_label_upper_right(){return"style_label_upper_right"}get style_label_center(){return"style_label_center"}get style_circle(){return"style_circle"}get style_square(){return"style_square"}get style_diamond(){return"style_diamond"}get style_flag(){return"style_flag"}get style_arrowup(){return"style_arrowup"}get style_arrowdown(){return"style_arrowdown"}get style_cross(){return"style_cross"}get style_xcross(){return"style_xcross"}get style_triangleup(){return"style_triangleup"}get style_triangledown(){return"style_triangledown"}get style_none(){return"style_none"}get style_text_outline(){return"style_text_outline"}}let Ju=0;class Mi{id;x1;y1;x2;y2;xloc;extend;color;style;width;force_overlay;_deleted;_helper;_createdAtBar=-1;constructor(e,i,r,n,a="bi",s="none",o="",l="style_solid",c=1,h=!1){this.id=Ju++,this.x1=e,this.y1=i,this.x2=r,this.y2=n,this.xloc=a,this.extend=s,this.color=o,this.style=l,this.width=c,this.force_overlay=h,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,i){this._helper?this._helper.set_xy1(this,e,i):this._deleted||(this.x1=e,this.y1=i)}set_xy2(e,i){this._helper?this._helper.set_xy2(this,e,i):this._deleted||(this.x2=e,this.y2=i)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_width(e){this._helper?this._helper.set_width(this,e):this._deleted||(this.width=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.x1=e,this.x2=i,this.xloc=r)}set_first_point(e){this._helper&&this._helper.set_first_point(this,e)}set_second_point(e){this._helper&&this._helper.set_second_point(this,e)}get_x1(){return this.x1}get_y1(){return this.y1}get_x2(){return this.x2}get_y2(){return this.y2}get_price(e){return this._helper?this._helper.get_price(this,e):NaN}delete(){this._deleted=!0}copy(){return new Mi(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}}const ep=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],tp={x1:"number",y1:"number",x2:"number",y2:"number",xloc:"string",extend:"string",color:"color",style:"string",width:"number",force_overlay:"boolean",first_point:"point",second_point:"point"};class ip{constructor(e){this.context=e}_lines=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._lines.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],n.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:n,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_createLine(e,i,r,n,a="bi",s="none",o="",l="style_solid",c=1,h=!1){const p=new Mi(e,i,r,n,a,this._resolve(s),this._resolve(o),this._resolve(l),this._resolve(c)||1,h);return p._helper=this,p._createdAtBar=this.context.idx,this._lines.push(p),this.syncToPlot(),p}new(...e){const i=X(e,ep,tp);let r,n,a,s,o=i.xloc;if(i.first_point instanceof se){const l=i.first_point,c=i.second_point,h=this._resolvePoint(l);r=h.x,n=l.price,o=o||h.xloc,c instanceof se?(a=this._resolvePoint(c).x,s=c.price):(a=0,s=NaN)}else r=i.x1,n=i.y1,a=i.x2,s=i.y2;return this._createLine(r,n,a,s,o,i.extend,i.color,i.style,i.width,i.force_overlay)}any(...e){return this.new(...e)}set_x1(e,i){e&&!e._deleted&&(e.x1=this._resolve(i))}set_y1(e,i){e&&!e._deleted&&(e.y1=this._resolve(i))}set_x2(e,i){e&&!e._deleted&&(e.x2=this._resolve(i))}set_y2(e,i){e&&!e._deleted&&(e.y2=this._resolve(i))}set_xy1(e,i,r){e&&!e._deleted&&(e.x1=this._resolve(i),e.y1=this._resolve(r))}set_xy2(e,i,r){e&&!e._deleted&&(e.x2=this._resolve(i),e.y2=this._resolve(r))}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i))}set_width(e,i){e&&!e._deleted&&(e.width=this._resolve(i)||1)}set_style(e,i){e&&!e._deleted&&(e.style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_xloc(e,i,r,n){e&&!e._deleted&&(e.x1=i,e.x2=r,e.xloc=n)}set_first_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x1=r.x,e.y1=i.price,e.xloc=r.xloc}}set_second_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x2=r.x,e.y2=i.price,e.xloc=r.xloc}}get_x1(e){return e?e.x1:NaN}get_y1(e){return e?e.y1:NaN}get_x2(e){return e?e.x2:NaN}get_y2(e){return e?e.y2:NaN}get_price(e,i){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;const r=e.x2-e.x1;return r===0?e.y1:e.y1+(i-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._lines.push(i),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_solid(){return"style_solid"}get style_dotted(){return"style_dotted"}get style_dashed(){return"style_dashed"}get style_arrow_left(){return"style_arrow_left"}get style_arrow_right(){return"style_arrow_right"}get style_arrow_both(){return"style_arrow_both"}}let rp=0;class Ri{id;left;top;right;bottom;xloc;extend;border_color;border_style;border_width;bgcolor;text;text_color;text_size;text_halign;text_valign;text_wrap;text_font_family;text_formatting;force_overlay;_deleted;_helper;_createdAtBar=-1;constructor(e,i,r,n,a="bi",s="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",S="format_none",w=!1){this.id=rp++,this.left=e,this.top=i,this.right=r,this.bottom=n,this.xloc=a,this.extend=s,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=h,this.text=p,this.text_color=u,this.text_size=f,this.text_halign=m,this.text_valign=x,this.text_wrap=_,this.text_font_family=b,this.text_formatting=S,this.force_overlay=w,this._deleted=!1,this._helper=null}set_left(e){this._helper?this._helper.set_left(this,e):this._deleted||(this.left=e)}set_right(e){this._helper?this._helper.set_right(this,e):this._deleted||(this.right=e)}set_top(e){this._helper?this._helper.set_top(this,e):this._deleted||(this.top=e)}set_bottom(e){this._helper?this._helper.set_bottom(this,e):this._deleted||(this.bottom=e)}set_lefttop(e,i){this._helper?this._helper.set_lefttop(this,e,i):this._deleted||(this.left=e,this.top=i)}set_rightbottom(e,i){this._helper?this._helper.set_rightbottom(this,e,i):this._deleted||(this.right=e,this.bottom=i)}set_top_left_point(e){this._helper&&this._helper.set_top_left_point(this,e)}set_bottom_right_point(e){this._helper&&this._helper.set_bottom_right_point(this,e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.left=e,this.right=i,this.xloc=r)}set_bgcolor(e){this._helper?this._helper.set_bgcolor(this,e):this._deleted||(this.bgcolor=e)}set_border_color(e){this._helper?this._helper.set_border_color(this,e):this._deleted||(this.border_color=e)}set_border_width(e){this._helper?this._helper.set_border_width(this,e):this._deleted||(this.border_width=e)}set_border_style(e){this._helper?this._helper.set_border_style(this,e):this._deleted||(this.border_style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_text_color(e){this._helper?this._helper.set_text_color(this,e):this._deleted||(this.text_color=e)}set_text_size(e){this._helper?this._helper.set_text_size(this,e):this._deleted||(this.text_size=e)}set_text_halign(e){this._helper?this._helper.set_text_halign(this,e):this._deleted||(this.text_halign=e)}set_text_valign(e){this._helper?this._helper.set_text_valign(this,e):this._deleted||(this.text_valign=e)}set_text_wrap(e){this._helper?this._helper.set_text_wrap(this,e):this._deleted||(this.text_wrap=e)}set_text_font_family(e){this._helper?this._helper.set_text_font_family(this,e):this._deleted||(this.text_font_family=e)}set_text_formatting(e){this._helper?this._helper.set_text_formatting(this,e):this._deleted||(this.text_formatting=e)}get_left(){return this.left}get_right(){return this.right}get_top(){return this.top}get_bottom(){return this.bottom}delete(){this._deleted=!0}toPlotData(){return{id:this.id,left:this.left,top:this.top,right:this.right,bottom:this.bottom,xloc:this.xloc,extend:this.extend,border_color:this.border_color,border_style:this.border_style,border_width:this.border_width,bgcolor:this.bgcolor,text:this.text,text_color:this.text_color,text_size:this.text_size,text_halign:this.text_halign,text_valign:this.text_valign,text_wrap:this.text_wrap,text_font_family:this.text_font_family,text_formatting:this.text_formatting,force_overlay:this.force_overlay,_deleted:this._deleted}}copy(){return new Ri(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}}const np=[["left","top","right","bottom","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"],["top_left","bottom_right","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"]],sp={left:"number",top:"number",right:"number",bottom:"number",top_left:"point",bottom_right:"point",border_color:"color",border_width:"number",border_style:"string",extend:"string",xloc:"string",bgcolor:"color",text:"string",text_size:"string",text_color:"color",text_halign:"string",text_valign:"string",text_wrap:"string",text_font_family:"string",force_overlay:"boolean"};class ap{constructor(e){this.context=e}_boxes=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._boxes.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],n.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:n,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_createBox(e,i,r,n,a="bi",s="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",S="format_none",w=!1){const E=new Ri(e,i,r,n,a,this._resolve(s),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(h,"#2962ff"),this._resolve(p)||"",this._resolveColor(u,"#000000"),this._resolve(f)||"auto",this._resolve(m)||"center",this._resolve(x)||"center",this._resolve(_)||"wrap_none",this._resolve(b)||"default",this._resolve(S)||"format_none",w);return E._helper=this,E._createdAtBar=this.context.idx,this._boxes.push(E),this.syncToPlot(),E}new(...e){const i=X(e,np,sp);let r,n,a,s,o=i.xloc;if(i.top_left instanceof se){const l=i.top_left,c=i.bottom_right,h=this._resolvePoint(l);r=h.x,n=l.price,o=o||h.xloc,c instanceof se?(a=this._resolvePoint(c).x,s=c.price):(a=0,s=NaN)}else r=this._resolve(i.left),n=this._resolve(i.top),a=this._resolve(i.right),s=this._resolve(i.bottom);return this._createBox(r,n,a,s,o,i.extend,i.border_color,i.border_style,i.border_width,i.bgcolor,i.text,i.text_color,i.text_size,i.text_halign,i.text_valign,i.text_wrap,i.text_font_family,void 0,i.force_overlay)}any(...e){return this.new(...e)}set_left(e,i){e&&!e._deleted&&(e.left=this._resolve(i))}set_right(e,i){e&&!e._deleted&&(e.right=this._resolve(i))}set_top(e,i){e&&!e._deleted&&(e.top=this._resolve(i))}set_bottom(e,i){e&&!e._deleted&&(e.bottom=this._resolve(i))}set_lefttop(e,i,r){e&&!e._deleted&&(e.left=this._resolve(i),e.top=this._resolve(r))}set_rightbottom(e,i,r){e&&!e._deleted&&(e.right=this._resolve(i),e.bottom=this._resolve(r))}set_top_left_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.left=r.x,e.top=i.price,e.xloc=r.xloc}}set_bottom_right_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.right=r.x,e.bottom=i.price,e.xloc=r.xloc}}set_xloc(e,i,r,n){e&&!e._deleted&&(e.left=this._resolve(i),e.right=this._resolve(r),e.xloc=this._resolve(n))}set_bgcolor(e,i){e&&!e._deleted&&(e.bgcolor=this._resolve(i))}set_border_color(e,i){e&&!e._deleted&&(e.border_color=this._resolve(i))}set_border_width(e,i){e&&!e._deleted&&(e.border_width=this._resolve(i)??1)}set_border_style(e,i){e&&!e._deleted&&(e.border_style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_text(e,i){e&&!e._deleted&&(e.text=this._resolve(i)||"")}set_text_color(e,i){e&&!e._deleted&&(e.text_color=this._resolve(i))}set_text_size(e,i){e&&!e._deleted&&(e.text_size=this._resolve(i))}set_text_halign(e,i){e&&!e._deleted&&(e.text_halign=this._resolve(i))}set_text_valign(e,i){e&&!e._deleted&&(e.text_valign=this._resolve(i))}set_text_wrap(e,i){e&&!e._deleted&&(e.text_wrap=this._resolve(i))}set_text_font_family(e,i){e&&!e._deleted&&(e.text_font_family=this._resolve(i))}set_text_formatting(e,i){e&&!e._deleted&&(e.text_formatting=this._resolve(i))}get_left(e){return e?e.left:NaN}get_right(e){return e?e.right:NaN}get_top(e){return e?e.top:NaN}get_bottom(e){return e?e.bottom:NaN}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._boxes.push(i),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(i=>i._createdAtBar<e),this.syncToPlot()}}let op=0;class lp{id;line1;line2;color;_deleted;_createdAtBar=-1;constructor(e,i,r){this.id=op++,this.line1=e,this.line2=i,this.color=r,this._deleted=!1}get_line1(){return this.line1}get_line2(){return this.line2}set_color(e){this._deleted||(typeof e=="function"&&(e=e()),e&&typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"&&(e=e.get(0)),this.color=e||"")}delete(){this._deleted=!0}toPlotData(){const e=i=>i?{id:i.id,x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,xloc:i.xloc,extend:i.extend,color:i.color,style:i.style,width:i.width,_deleted:i._deleted}:null;return{id:this.id,line1:e(this.line1),line2:e(this.line2),color:this.color,_deleted:this._deleted}}}class cp{constructor(e){this.context=e}_linefills=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__linefills__.data=[{time:e,value:this._linefills.map(i=>i.toPlotData()),options:{style:"linefill"}}]}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(e,i,r){const n=this._resolve(e),a=this._resolve(i),s=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolve(s)||"",l=new lp(n,a,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),this.syncToPlot(),l}any(...e){return this.new(e[0],e[1],e[2])}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i)||"")}get_line1(e){return e?e.line1:void 0}get_line2(e){return e?e.line2:void 0}delete(e){e&&(e._deleted=!0)}get all(){return this._linefills.filter(e=>!e._deleted)}rollbackFromBar(e){this._linefills=this._linefills.filter(i=>i._createdAtBar<e),this.syncToPlot()}}let hp=0;class up{id;points;curved;closed;xloc;line_color;fill_color;line_style;line_width;force_overlay;_deleted;_createdAtBar=-1;constructor(e,i=!1,r=!1,n="bi",a="#2962ff",s="",o="style_solid",l=1,c=!1){this.id=hp++,this.points=e,this.curved=i,this.closed=r,this.xloc=n,this.line_color=a,this.fill_color=s,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}}class pp{constructor(e){this.context=e}_polylines=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(i=>i.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_extractPoints(e){let i=this._resolve(e);const r=i&&i.array?i.array:i;return Array.isArray(r)?r.filter(n=>n instanceof se):[]}new(...e){let i,r=!1,n=!1,a="bi",s="#2962ff",o="",l="style_solid",c=1,h=!1;const p=_=>{r=_.curved??r,n=_.closed??n,a=_.xloc??a,s=_.line_color??s,o=_.fill_color??o,l=_.line_style??l,c=_.line_width??c,h=_.force_overlay??h},u=e.length>=1?e[e.length-1]:null,f=e.length>=2&&u&&typeof u=="object"&&!Array.isArray(u)&&!(u instanceof y)&&!(u instanceof se);if(e.length===1&&u&&typeof u=="object"&&!Array.isArray(u)&&"points"in u)i=u.points,p(u);else{const _=f?e.slice(0,-1):e;i=_[0],r=_[1]??r,n=_[2]??n,a=_[3]??a,s=_[4]??s,o=_[5]??o,l=_[6]??l,c=_[7]??c,h=_[8]??h,f&&p(u)}const m=this._extractPoints(i),x=new up(m,this._resolve(r)??!1,this._resolve(n)??!1,this._resolve(a)||"bi",this._resolveColor(s,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(h)??!1);return x._createdAtBar=this.context.idx,this._polylines.push(x),this.syncToPlot(),x}any(...e){return this.new(...e)}delete(e){e&&(e._deleted=!0)}get all(){return this._polylines.filter(e=>!e._deleted)}rollbackFromBar(e){this._polylines=this._polylines.filter(i=>i._createdAtBar<e),this.syncToPlot()}}let fp=0;class dp{id;position;columns;rows;bgcolor;frame_color;frame_width;border_color;border_width;force_overlay;_deleted;cells;merges;_helper;constructor(e="top_right",i=1,r=1,n="",a="",s=0,o="",l=0,c=!1){this.id=fp++,this.position=e,this.columns=i,this.rows=r,this.bgcolor=n,this.frame_color=a,this.frame_width=s,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let h=0;h<r;h++){this.cells[h]=[];for(let p=0;p<i;p++)this.cells[h][p]=null}}delete(){this._deleted=!0}toPlotData(){const e=this.cells.map(i=>i.map(r=>r?{...r}:null));return{id:this.id,position:this.position,columns:this.columns,rows:this.rows,bgcolor:this.bgcolor,frame_color:this.frame_color,frame_width:this.frame_width,border_color:this.border_color,border_width:this.border_width,force_overlay:this.force_overlay,_deleted:this._deleted,cells:e,merges:this.merges.map(i=>({...i}))}}setCell(e,i,r){if(i<0||i>=this.rows||e<0||e>=this.columns)return;const n=this.cells[i][e];if(n&&n._merged&&n._merge_parent){const[s,o]=n._merge_parent;if(s===e&&o===i)n._merged=!1,n._merge_parent=void 0;else{this.setCell(s,o,r);return}}const a=n||this._defaultCell();Object.assign(a,r),this.cells[i][e]=a}getCell(e,i){return i<0||i>=this.rows||e<0||e>=this.columns?null:this.cells[i][e]}clearCell(e,i){i<0||i>=this.rows||e<0||e>=this.columns||(this.cells[i][e]=null)}_setHelper(e){this._helper=e}cell(...e){return this._helper.cell(this,...e)}clear(...e){return this._helper.clear(this,...e)}merge_cells(...e){return this._helper.merge_cells(this,...e)}cell_set_text(...e){return this._helper.cell_set_text(this,...e)}cell_set_bgcolor(...e){return this._helper.cell_set_bgcolor(this,...e)}cell_set_text_color(...e){return this._helper.cell_set_text_color(this,...e)}cell_set_text_size(...e){return this._helper.cell_set_text_size(this,...e)}cell_set_height(...e){return this._helper.cell_set_height(this,...e)}cell_set_width(...e){return this._helper.cell_set_width(this,...e)}cell_set_tooltip(...e){return this._helper.cell_set_tooltip(this,...e)}cell_set_text_halign(...e){return this._helper.cell_set_text_halign(this,...e)}cell_set_text_valign(...e){return this._helper.cell_set_text_valign(this,...e)}cell_set_text_font_family(...e){return this._helper.cell_set_text_font_family(this,...e)}set_position(...e){return this._helper.set_position(this,...e)}set_bgcolor(...e){return this._helper.set_bgcolor(this,...e)}set_border_color(...e){return this._helper.set_border_color(this,...e)}set_border_width(...e){return this._helper.set_border_width(this,...e)}set_frame_color(...e){return this._helper.set_frame_color(this,...e)}set_frame_width(...e){return this._helper.set_frame_width(this,...e)}_defaultCell(){return{text:"",width:0,height:0,text_color:"#000000",text_halign:"center",text_valign:"center",text_size:"normal",bgcolor:"",tooltip:"",text_font_family:"default",_merged:!1,_merge_parent:null}}}class mp{constructor(e){this.context=e}_tables=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__tables__.data=[{time:e,value:this._tables.map(i=>i.toPlotData()),options:{style:"table"}}]}_resolve(e){return e==null?e:typeof e=="object"&&"__value"in e?e.__value:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(...e){let i="top_right",r=1,n=1,a="",s="",o=0,l="",c=0,h=!1;const p=e[e.length-1];if(p&&typeof p=="object"&&!Array.isArray(p)&&("bgcolor"in p||"frame_color"in p||"border_color"in p||"position"in p||"columns"in p||"rows"in p)){const f=p,m=e.slice(0,-1);i=m[0]??f.position??i,r=m[1]??f.columns??r,n=m[2]??f.rows??n,a=f.bgcolor??a,s=f.frame_color??s,o=f.frame_width??o,l=f.border_color??l,c=f.border_width??c,h=f.force_overlay??h}else i=e[0]??i,r=e[1]??r,n=e[2]??n,a=e[3]??a,s=e[4]??s,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h;const u=new dp(this._resolve(i)||"top_right",this._resolve(r)||1,this._resolve(n)||1,this._resolve(a)||"",this._resolve(s)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(h)??!1);return u._setHelper(this),this._tables.push(u),this.syncToPlot(),u}any(...e){return this.new(...e)}cell(...e){let i,r,n,a="",s=0,o=0,l="#000000",c="center",h="center",p="normal",u="",f="",m="default";const x=e[e.length-1];if(x&&typeof x=="object"&&!Array.isArray(x)&&("text"in x||"bgcolor"in x||"text_color"in x||"text_size"in x||"text_halign"in x||"tooltip"in x||"column"in x||"row"in x||"height"in x||"width"in x||"text_valign"in x||"text_font_family"in x)){const w=x,E=e.slice(0,-1);i=E[0],r=E.length>1?E[1]:w.column??0,n=E.length>2?E[2]:w.row??0,a=E[3]??w.text??a,s=E[4]??w.width??s,o=E[5]??w.height??o,l=E[6]??w.text_color??l,c=E[7]??w.text_halign??c,h=E[8]??w.text_valign??h,p=E[9]??w.text_size??p,u=E[10]??w.bgcolor??u,f=E[11]??w.tooltip??f,m=E[12]??w.text_font_family??m}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??a,s=e[4]??s,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h,p=e[9]??p,u=e[10]??u,f=e[11]??f,m=e[12]??m;const _=this._resolve(i);if(!_||_._deleted)return;const b=this._resolve(r)??0,S=this._resolve(n)??0;_.setCell(b,S,{text:this._resolveText(this._resolve(a)),width:this._resolve(s)||0,height:this._resolve(o)||0,text_color:this._resolve(l)||"#000000",text_halign:this._resolve(c)||"center",text_valign:this._resolve(h)||"center",text_size:this._resolve(p)||"normal",bgcolor:this._resolve(u)||"",tooltip:this._resolveText(this._resolve(f)),text_font_family:this._resolve(m)||"default"}),this.syncToPlot()}delete(e){e&&(e._deleted=!0)}clear(...e){let i,r,n,a,s;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:r),s=f.end_row??(e.length>5?e[4]:n)}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??r,s=e[4]??n;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(n)??0,p=this._resolve(a)??c,u=this._resolve(s)??h;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)l.clearCell(m,f);this.syncToPlot()}merge_cells(...e){let i,r,n,a,s;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:0),s=f.end_row??(e.length>5?e[4]:0)}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??0,s=e[4]??0;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(n)??0,p=this._resolve(a)??0,u=this._resolve(s)??0;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)f===h&&m===c||l.setCell(m,f,{_merged:!0,_merge_parent:[c,h]});l.merges.push({startCol:c,startRow:h,endCol:p,endRow:u}),this.syncToPlot()}cell_set_text(e,i,r,n){this._setCellProp(e,i,r,"text",n,!0)}cell_set_bgcolor(e,i,r,n){this._setCellProp(e,i,r,"bgcolor",n)}cell_set_text_color(e,i,r,n){this._setCellProp(e,i,r,"text_color",n)}cell_set_text_size(e,i,r,n){this._setCellProp(e,i,r,"text_size",n)}cell_set_height(e,i,r,n){this._setCellProp(e,i,r,"height",n)}cell_set_width(e,i,r,n){this._setCellProp(e,i,r,"width",n)}cell_set_tooltip(e,i,r,n){this._setCellProp(e,i,r,"tooltip",n,!0)}cell_set_text_halign(e,i,r,n){this._setCellProp(e,i,r,"text_halign",n)}cell_set_text_valign(e,i,r,n){this._setCellProp(e,i,r,"text_valign",n)}cell_set_text_font_family(e,i,r,n){this._setCellProp(e,i,r,"text_font_family",n)}set_position(e,i){const r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(i)||r.position,this.syncToPlot())}set_bgcolor(e,i){const r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(i)||"",this.syncToPlot())}set_border_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(i)||"",this.syncToPlot())}set_border_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(i)||0,this.syncToPlot())}set_frame_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(i)||"",this.syncToPlot())}set_frame_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(i)||0,this.syncToPlot())}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,i,r,n,a,s=!1){const o=this._resolve(e);if(!o||o._deleted)return;const l=this._resolve(i)??0,c=this._resolve(r)??0,h=this._resolve(a);o.setCell(l,c,{[n]:s?this._resolveText(h):h}),this.syncToPlot()}_resolveText(e){return e==null||e!==e?"":String(e)}}class Qe{data={open:new y([]),high:new y([]),low:new y([]),close:new y([]),volume:new y([]),hl2:new y([]),hlc3:new y([]),ohlc4:new y([]),hlcc4:new y([]),bar_index:new y([])};indicator;cache={};taState={};isSecondaryContext=!1;chartTimezone=null;dataVersion=0;__maxLoops=5e5;NA=NaN;warnings=[];alerts=[];_alertMode="realtime";_execTick=0;warn(e,i){this.warnings.push({message:e,method:i,bar:this.idx})}lang;length=0;_drawingHelpers=[];pine;static _deprecationWarningsShown=new Set;idx=0;params={};const={};var={};let={};lctx=new Map;result=void 0;plots={};marketData;source;tickerId;timeframe="";limit;sDate;eDate;fullContext;pineTSCode;inputs={};constructor({marketData:e,source:i,tickerId:r,timeframe:n,limit:a,sDate:s,eDate:o,fullContext:l,inputs:c}){this.marketData=e,this.source=i,this.tickerId=r,this.timeframe=n,this.limit=a,this.sDate=s,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};const h=new Zl(this),p={Type:h.Type.bind(h),na:new _t,nz:h.nz.bind(h),indicator:h.indicator.bind(h),fixnan:h.fixnan.bind(h),alertcondition:h.alertcondition.bind(h),alert:new Ql(this),error:h.error.bind(h),max_bars_back:h.max_bars_back.bind(h),timestamp:h.timestamp.bind(h),time:new or(this,"openTime"),time_close:new or(this,"closeTime"),dayofmonth:new We(this,Ue.dayofmonth),dayofweek:new We(this,Ue.dayofweek),hour:new We(this,Ue.hour),minute:new We(this,Ue.minute),month:new We(this,Ue.month),second:new We(this,Ue.second),weekofyear:new We(this,Ue.weekofyear),year:new We(this,Ue.year),bool:h.bool.bind(h),int:h.int.bind(h),float:h.float.bind(h),string:h.string.bind(h)},u=this;this.pine={input:new Ec(this),ta:new Su(this),math:new nh(this),request:new ch(this),array:new Do(this),map:new zo(this),matrix:new Ul(this),syminfo:null,timeframe:new ku(this),barstate:new ql(this),get bar_index(){return u.data.bar_index},get last_bar_index(){return u.data.close.length-1},get last_bar_time(){return u.data.openTime.get(u.data.openTime.length-1)},get timenow(){return new Date().getTime()},get time_tradingday(){const $=y.from(u.data.closeTime).get(0);if(isNaN($))return NaN;const B=u.pine?.syminfo?.timezone||"UTC",R=dt($,B);return Date.UTC(R.year,R.month-1,R.day,0,0,0)},get inputs(){return u.inputs},log:new Cu(this),str:new Iu(this),...p,...ho};const f=p.dayofweek;Object.assign(f,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=f;const m=new zu(this),x=new Ku(this),_=new Hu(this);this.bindContextObject(m,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(m,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(x,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(_,["any","param"],"fill");const b=new Gu(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),is_standard:b.is_standard.bind(b),is_heikinashi:b.is_heikinashi.bind(b),is_kagi:b.is_kagi.bind(b),is_linebreak:b.is_linebreak.bind(b),is_pnf:b.is_pnf.bind(b),is_range:b.is_range.bind(b),is_renko:b.is_renko.bind(b),point:b.point};const S=new Zu(this);this.bindContextObject(S,["any","new","param","set_x","set_y","set_xy","set_text","set_color","set_textcolor","set_size","set_style","set_textalign","set_tooltip","set_point","set_xloc","set_yloc","get_x","get_y","get_text","copy","delete","style_label_down","style_label_up","style_label_left","style_label_right","style_label_lower_left","style_label_lower_right","style_label_upper_left","style_label_upper_right","style_label_center","style_circle","style_square","style_diamond","style_flag","style_arrowup","style_arrowdown","style_cross","style_xcross","style_triangleup","style_triangledown","style_none","style_text_outline"],"label"),Object.defineProperty(this.pine.label,"all",{get:()=>S.all});const w=new ip(this);this.bindContextObject(w,["any","new","param","set_x1","set_y1","set_x2","set_y2","set_xy1","set_xy2","set_color","set_width","set_style","set_extend","set_xloc","set_first_point","set_second_point","get_x1","get_y1","get_x2","get_y2","get_price","copy","delete","style_solid","style_dotted","style_dashed","style_arrow_left","style_arrow_right","style_arrow_both"],"line"),Object.defineProperty(this.pine.line,"all",{get:()=>w.all});const E=new ap(this);this.bindContextObject(E,["any","new","param","copy","delete","set_left","set_right","set_top","set_bottom","set_lefttop","set_rightbottom","set_top_left_point","set_bottom_right_point","set_bgcolor","set_border_color","set_border_width","set_border_style","set_extend","set_xloc","set_text","set_text_color","set_text_size","set_text_halign","set_text_valign","set_text_wrap","set_text_font_family","set_text_formatting","get_left","get_right","get_top","get_bottom"],"box"),Object.defineProperty(this.pine.box,"all",{get:()=>E.all});const A=new cp(this);this.bindContextObject(A,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>A.all});const C=new pp(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>C.all});const M=new mp(this);this.bindContextObject(M,["any","new","param","cell","delete","clear","merge_cells","cell_set_text","cell_set_bgcolor","cell_set_text_color","cell_set_text_size","cell_set_height","cell_set_width","cell_set_tooltip","cell_set_text_halign","cell_set_text_valign","cell_set_text_font_family","set_position","set_bgcolor","set_border_color","set_border_width","set_frame_color","set_frame_width"],"table"),Object.defineProperty(this.pine.table,"all",{get:()=>M.all}),this._drawingHelpers=[S,w,E,A,C,M];const O=new ec(this);this.bindContextObject(O,["any","param","new","rgb","from_gradient","r","g","b","t","aqua","black","blue","fuchsia","gray","green","lime","maroon","navy","olive","orange","purple","red","silver","teal","white","yellow"],"color")}rollbackDrawings(e){for(const i of this._drawingHelpers)i.rollbackFromBar(e)}bindContextObject(e,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const n=r?this.pine[r]:this.pine;for(const a of i)typeof e[a]=="function"?n[a]=e[a].bind(e):n[a]=e[a]}init(e,i,r=0){let n;return i instanceof y?n=i.get(0):Array.isArray(i)?Array.isArray(i[0])?n=i[0]:n=i[i.length-1+r]:n=i,e?e instanceof y?(e.data[e.data.length-1]=n,e):Array.isArray(e)?(e[e.length-1]=n,new y(e)):new y([n]):new y([n])}initVar(e,i){if(e)return e;if(typeof i=="function"&&(i=i()),i instanceof ht){const n=i.__def__;for(const a in n)typeof i[a]=="function"&&(i[a]=i[a]())}let r;return i instanceof y?r=i.get(0):Array.isArray(i)?Array.isArray(i[0])?r=i[0]:r=this.precision(i[i.length-1]):r=this.precision(i),new y([r])}static PRECISION_EPSILON=10**10;precision(e,i=10){const r=i===10?Qe.PRECISION_EPSILON:10**i;return typeof e=="number"?Math.round(e*r)/r:e}param(e,i,r){return typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new y(e,i||0):(this.params[r].length===0?this.params[r].push(e):this.params[r][this.params[r].length-1]=e,new y(this.params[r],i||0)))}get(e,i){if(e instanceof y)return e.get(i);if(Array.isArray(e)){const r=e.length-1-i;return r<0||r>=e.length?NaN:e[r]}return e}set(e,i){if(e instanceof y){e.set(0,typeof i=="number"?this.precision(i):i);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=i:e.push(i);return}}_callStack=[];pushId(e){this._callStack.push(e)}popId(){this._callStack.pop()}peekId(){return this._callStack.length>0?this._callStack[this._callStack.length-1]:""}peekCtx(){const e=this.peekId();if(!e)return this;let i=this.lctx.get(e);return i||(i={id:e,let:{},const:{},var:{}},this.lctx.set(e,i)),i}call(e,i,...r){this.pushId(i);try{return e(...r)}finally{this.popId()}}get math(){return this._showDeprecationWarning("const math = context.math","const { math, ta, input } = context.pine"),this.pine.math}get ta(){return this._showDeprecationWarning("const ta = context.ta","const { ta, math, input } = context.pine"),this.pine.ta}get input(){return this._showDeprecationWarning("const input = context.input","const { input, math, ta } = context.pine"),this.pine.input}get request(){return this._showDeprecationWarning("const request = context.request","const { request, math, ta } = context.pine"),this.pine.request}get array(){return this._showDeprecationWarning("const array = context.array","const { array, math, ta } = context.pine"),this.pine.array}get core(){return this._showDeprecationWarning("context.core.*","context.pine (e.g., const { na, plotchar, color, plot, nz } = context.pine)"),{na:this.pine.na,fill:this.pine.fill,plotchar:this.pine.plotchar,plotshape:this.pine.plotshape,plotarrow:this.pine.plotarrow,color:this.pine.color,plot:this.pine.plot,nz:this.pine.nz}}_showDeprecationWarning(e,i){const r=`${e}->${i}`;Qe._deprecationWarningsShown.has(r)||(Qe._deprecationWarningsShown.add(r),typeof window<"u"?console.warn("%c[WARNING]%c %s syntax is deprecated. Use %s instead. This will be removed in a future version.","color: #FFA500; font-weight: bold;","color: #FFA500;",e,i):console.warn(`\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}}class _i{source;inputs;constructor(e,i={}){this.source=e,this.inputs=i}}const fr={1:6e4,3:18e4,5:3e5,15:9e5,30:18e5,60:36e5,120:72e5,180:108e5,240:144e5,"4H":144e5,"1D":864e5,D:864e5,"1W":6048e5,W:6048e5,"1M":30*864e5,M:30*864e5};function gp(t){return t?fr[t]??fr[t.toUpperCase()]??864e5:864e5}class Vi{constructor(e,i,r,n,a,s){this.source=e,this.tickerId=i,this.timeframe=r,this.limit=n,this.sDate=a,this.eDate=s,this._readyPromise=new Promise(o=>{this.loadMarketData(e,i,r,n,a,s).then(l=>{const c=l;this.data=c;const h=c.map(C=>C.open),p=c.map(C=>C.close),u=c.map(C=>C.high),f=c.map(C=>C.low),m=c.map(C=>C.volume),x=c.map(C=>(C.high+C.low+C.close)/3),_=c.map(C=>(C.high+C.low)/2),b=c.map(C=>(C.high+C.low+C.open+C.close)/4),S=c.map(C=>(C.high+C.low+C.close+C.close)/4),w=c.map(C=>C.openTime),E=gp(this.timeframe),A=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+E);this.open=h,this.close=p,this.high=u,this.low=f,this.volume=m,this.hl2=_,this.hlc3=x,this.ohlc4=b,this.hlcc4=S,this.openTime=w,this.closeTime=A,e&&e.getSymbolInfo?e.getSymbolInfo(i).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}data=[];open=[];high=[];low=[];close=[];volume=[];hl2=[];hlc3=[];ohlc4=[];hlcc4=[];openTime=[];closeTime=[];_readyPromise=null;_ready=!1;_debugSettings={ln:!1,debug:!1};_transpiledCode=null;get transpiledCode(){return this._transpiledCode}_isSecondaryContext=!1;markAsSecondary(){this._isSecondaryContext=!0}_syminfo;_chartTimezone=null;setTimezone(e){this._chartTimezone=e}_maxLoops=5e5;setMaxLoops(e){this._maxLoops=e}_alertMode="realtime";setAlertMode(e){this._alertMode=e}setDebugSettings({ln:e,debug:i}){this._debugSettings.ln=e,this._debugSettings.debug=i}async loadMarketData(e,i,r,n,a,s){return Array.isArray(e)?e:e.getMarketData(i,r,n,a,s)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,i,r){let n,a={};if(e instanceof _i?(n=e.source,a=e.inputs||{}):n=e,r&&r>0){const s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(n,a,i,r,s)}else return this._runComplete(n,a,i)}stream(e,i={}){const{live:r=!0,interval:n=1e3}=i,a=i.pageSize||this.data.length;let s,o={};e instanceof _i?(s=e.source,o=e.inputs||{}):s=e;const l={data:[],error:[],warning:[],alert:[]};let c=!1;const h=(f,...m)=>{l[f]&&l[f].forEach(x=>x(...m))},p=(f,m)=>{l[f]||(l[f]=[]),l[f].push(m)},u=()=>{c=!0};return(async()=>{try{const f=typeof this.eDate>"u"&&!Array.isArray(this.source)&&r,m=this._runPaginated(s,o,void 0,a,f);for await(const x of m){if(c)break;if(x===null){await new Promise(_=>setTimeout(_,n));continue}if(h("data",x),x.warnings&&x.warnings.length>0){for(const _ of x.warnings)h("warning",_);x.warnings.length=0}if(x.alerts&&x.alerts.length>0){for(const _ of x.alerts)h("alert",_);x.alerts.length=0}if(f&&!c){const _=x.marketData[x.idx];_&&_.closeTime<Date.now()||await new Promise(b=>setTimeout(b,n))}}}catch(f){h("error",f)}})(),{on:p,stop:u}}async _runComplete(e,i,r){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(e,i,this._isSecondaryContext);return this._transpiledCode=this._transpileCode(e),await this._executeIterations(n,this._transpiledCode,this.data.length-r,this.data.length),n}async*_runPaginated(e,i,r,n,a=!1){await this.ready(),r||(r=this.data.length);const s=this._initializeContext(e,i,this._isSecondaryContext);this._transpiledCode=this._transpileCode(e);let o=this.data.length-r;for(;;){const l=this.data.length-o;if(l>0){const p=Math.min(l,n),u=this._getResultLength(s.result);await this._executeIterations(s,this._transpiledCode,o,o+p),o+=p,yield this._createPageContext(s,u);continue}if(!a||Array.isArray(this.source))break;const{newCandles:c,updatedLastCandle:h}=await this._updateMarketData();if(c===0&&!h){yield null;continue}s.dataVersion++,s.length=this.data.length,this._removeLastResult(s),o=this.data.length-(c+1),s.rollbackDrawings(o),s.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const i=Object.keys(e);if(i.length>0&&Array.isArray(e[i[0]]))return e[i[0]].length}return 0}_createPageContext(e,i){const r=new Qe({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:e,inputs:e.inputs});if(r.pineTSCode=e.pineTSCode,r.idx=e.idx,Array.isArray(e.result))r.result=e.result.slice(i);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let n in e.result)Array.isArray(e.result[n])?r.result[n]=e.result[n].slice(i):r.result[n]=e.result[n]}else r.result=e.result;return r.plots={...e.plots},r.warnings=e.warnings,r.alerts=e.alerts,r}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const i=this.source,r=this.data.length-1,n=this.data[r].openTime;try{const a=await i.getMarketData(this.tickerId,this.timeframe,void 0,n,e);if(!a||a.length===0)return{newCandles:0,updatedLastCandle:!1};let s=!1,o=0;for(let l=0;l<a.length;l++){const c=a[l];c.openTime===n?(this._replaceCandle(r,c),s=!0):c.openTime>n&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:s}}catch(a){return console.error("Error updating market data:",a),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,i){this.data[e]=i,this.open[e]=i.open,this.close[e]=i.close,this.high[e]=i.high,this.low[e]=i.low,this.volume[e]=i.volume,this.hl2[e]=(i.high+i.low)/2,this.hlc3[e]=(i.high+i.low+i.close)/3,this.ohlc4[e]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[e]=(i.high+i.low+i.close+i.close)/4,this.openTime[e]=i.openTime,this.closeTime[e]=i.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;const{newCandles:i,updatedLastCandle:r}=await this._updateMarketData();if(i===0&&!r)return!1;this._removeLastResult(e),e.length=this.data.length;const n=this.data.length-(i+1);return e.rollbackDrawings(n),await this._executeIterations(e,this._transpiledCode,n,this.data.length),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let n in e.result)Array.isArray(e.result[n])&&e.result[n].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();const i=["const","var","let","params"],r=n=>{for(let a of i)if(n[a])for(let s in n[a]){const o=n[a][s];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(n=>r(n))}_initializeContext(e,i={},r=!1){const n=new Qe({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:i});return n.pine.syminfo=this._syminfo,this._chartTimezone&&(n.chartTimezone=this._chartTimezone),n.__maxLoops=this._maxLoops,n._alertMode=this._alertMode,n.pineTSCode=e,n.isSecondaryContext=r,n.data.close=new y([]),n.data.open=new y([]),n.data.high=new y([]),n.data.low=new y([]),n.data.volume=new y([]),n.data.hl2=new y([]),n.data.hlc3=new y([]),n.data.ohlc4=new y([]),n.data.hlcc4=new y([]),n.data.openTime=new y([]),n.data.closeTime=new y([]),n.length=this.data.length,n}_transpileCode(e){return Na.bind(this)(e,this._debugSettings)}async _executeIterations(e,i,r,n){const a=["const","var","let","params"];for(let s=r;s<n;s++){e.idx=s,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[s]),e.data.open.data.push(this.open[s]),e.data.high.data.push(this.high[s]),e.data.low.data.push(this.low[s]),e.data.volume.data.push(this.volume[s]),e.data.hl2.data.push(this.hl2[s]),e.data.hlc3.data.push(this.hlc3[s]),e.data.ohlc4.data.push(this.ohlc4[s]),e.data.hlcc4.data.push(this.hlcc4[s]),e.data.openTime.data.push(this.openTime[s]),e.data.closeTime.data.push(this.closeTime[s]),e.data.bar_index.data.push(s);const o=await i(e);if(typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let h;o[c]instanceof y?h=o[c].get(0):Array.isArray(o[c])?h=o[c][o[c].length-1]:h=o[c],e.result[c].push(h)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(const c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();const l=c=>{for(let h of a)if(c[h])for(let p in c[h]){const u=c[h][p];if(u instanceof y){const f=u.get(0);u.data.push(f)}else if(Array.isArray(u)){const f=u[u.length-1];u.push(f)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}}}const dr={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},ut={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3},yp={"1S":{periodType:"second",multiplier:1},"5S":{periodType:"second",multiplier:5},"10S":{periodType:"second",multiplier:10},"15S":{periodType:"second",multiplier:15},"30S":{periodType:"second",multiplier:30},1:{periodType:"minute",multiplier:1},3:{periodType:"minute",multiplier:3},5:{periodType:"minute",multiplier:5},15:{periodType:"minute",multiplier:15},30:{periodType:"minute",multiplier:30},45:{periodType:"minute",multiplier:45},60:{periodType:"hour",multiplier:1},120:{periodType:"hour",multiplier:2},180:{periodType:"hour",multiplier:3},240:{periodType:"hour",multiplier:4},D:{periodType:"day",multiplier:1},W:{periodType:"week",multiplier:1},M:{periodType:"month",multiplier:1}};function pt(t,e,i=1){if(e==="month"){const n=new Date(t);return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+i,1,n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}const r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+i*r[e]}function Ce(t,e,i){const[r,n,a]=t.split("-").map(Number),[s,o]=e.split(":").map(Number),l=Date.UTC(r,n-1,a,s,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(l)),h=b=>parseInt(c.find(S=>S.type===b).value,10);let p=h("year"),u=h("month"),f=h("day"),m=h("hour");m===24&&(m=0);let x=h("minute");const _=Date.UTC(p,u-1,f,m,x,0,0)-l;return l-_}function bi(t,e,i,r,n=1){if(e==="24x7")return pt(t,r,n);const a=e.split("-")[1];if(!a||a.length!==4)return pt(t,r,n);const s=a.slice(0,2),o=a.slice(2,4),l=`${s}:${o}`,c=mr(t,i);if(r==="second"||r==="minute"||r==="hour"){const h=t+n*{second:1e3,minute:6e4,hour:36e5}[r],p=Ce(c,l,i);return Math.min(h,p)}if(r==="day")return Ce(c,l,i);if(r==="week"){const h=new Date(t).getUTCDay(),p=h<=5?5-h:5-h+7,u=t+p*864e5,f=mr(u,i);return Ce(f,l,i)}if(r==="month"){const h=new Date(t),p=h.getUTCFullYear(),u=h.getUTCMonth()+n,f=new Date(Date.UTC(p,u,1)),m=new Date(f.getTime()-864e5);for(;m.getUTCDay()===0||m.getUTCDay()===6;)m.setUTCDate(m.getUTCDate()-1);const x=m.toISOString().split("T")[0];return Ce(x,l,i)}return pt(t,r,n)}function mr(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function xp(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}const _p=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function Ln(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;const i=ut[t];if(!i)return null;const r=_p.filter(n=>n!=="W"&&n!=="M"&&e.has(n)&&ut[n]<i&&i%ut[n]===0);return r.length===0?null:r[r.length-1]}function Oi(t,e){if(t==="W"||t==="M")return 1/0;const i=ut[t],r=ut[e];return!i||!r||r===0?1/0:i/r}function jn(t,e,i){if(t.length===0)return[];if(e==="W")return wp(t);if(e==="M")return vp(t);const r=Oi(e,i);return bp(t,r)}function bp(t,e){if(t.length===0)return[];const i=[];let r=[t[0]];const n=Sp(t),a=n>0?n*1.5:0;for(let s=1;s<t.length;s++){const o=t[s].openTime-t[s-1].openTime;(a>0&&o>a||r.length>=e)&&(i.push(qt(r)),r=[]),r.push(t[s])}return r.length>0&&i.push(qt(r)),i}function wp(t){const e=[];let i=[],r="";for(const n of t){const a=Ep(n.openTime);a!==r&&i.length>0&&(e.push(i),i=[]),r=a,i.push(n)}return i.length>0&&e.push(i),e.map(qt)}function vp(t){const e=[];let i=[],r="";for(const n of t){const a=new Date(n.openTime),s=`${a.getUTCFullYear()}-${a.getUTCMonth()}`;s!==r&&i.length>0&&(e.push(i),i=[]),r=s,i.push(n)}return i.length>0&&e.push(i),e.map(qt)}function qt(t){const e=t[0],i=t[t.length-1];let r=e.high,n=e.low,a=0,s=0,o=0,l=0,c=0;for(let h=0;h<t.length;h++){const p=t[h];p.high>r&&(r=p.high),p.low<n&&(n=p.low),a+=p.volume,s+=p.quoteAssetVolume,o+=p.numberOfTrades,l+=p.takerBuyBaseAssetVolume,c+=p.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:r,low:n,close:i.close,volume:a,closeTime:i.closeTime,quoteAssetVolume:s,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function Sp(t){if(t.length<2)return 0;const e=Math.min(t.length-1,20);let i=1/0;for(let r=0;r<e;r++){const n=t[r+1].openTime-t[r].openTime;n>0&&n<i&&(i=n)}return i===1/0?0:i}function Ep(t){const e=new Date(t),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1)),n=Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${n}`}const Ot={"1s":"1S","5s":"5S","10s":"10S","15s":"15S","30s":"30S","1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1D":"D","1W":"W","1M":"M","4H":"240",D:"D",W:"W",M:"M"};function Np(t){if(Ot[t]!==void 0)return Ot[t];const e=t.toLowerCase();return Ot[e]!==void 0?Ot[e]:/^\d+$/.test(t)?t:/^\d+S$/i.test(t)?t.toUpperCase():t}class Tt{_configured;_requiresApiKey;_providerName;_aggregationSubTimeframe=null;constructor(e){this._requiresApiKey=e.requiresApiKey,this._providerName=e.providerName,this._configured=!e.requiresApiKey}ensureConfigured(){if(!this._configured)throw new Error(`${this._providerName} requires configuration before use. Call Provider.${this._providerName}.configure({ apiKey: '...' }) or instantiate directly: new ${this._providerName}Provider({ apiKey: '...' })`)}configure(e){this._configured=!0}get isConfigured(){return this._configured}normalizeCloseTime(e){xp(e)}setAggregationSubTimeframe(e){this._aggregationSubTimeframe=e}getSupportedTimeframes(){return new Set(["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"])}async getMarketData(e,i,r,n,a){const s=Np(i),o=this.getSupportedTimeframes();if(o.has(s))return this._getMarketDataNative(e,s,r,n,a);const l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:Ln(s,o);if(!c)return console.error(`${this._providerName}: Timeframe '${i}' is not supported and no valid sub-timeframe found for aggregation.`),[];const h=this._computeSubLimit(s,c,r),p=await this._getMarketDataNative(e,c,h,n,a);if(p.length===0)return[];const u=jn(p,s,c);return r&&r>0&&u.length>r?u.slice(u.length-r):u}_computeSubLimit(e,i,r){if(!r)return;const n=Oi(e,i);return n===1/0?e==="W"?r*7+14:e==="M"?r*31+31:r*30:Math.ceil(r*n)+Math.ceil(n)}}const ai="https://api.binance.com/api/v3",gr="https://api.binance.us/api/v3",Lt={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",45:null,60:"1h",120:"2h",180:null,240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"};class Cp{cache;cacheDuration;constructor(e=300*1e3){this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(e){const i=this.generateKey(e),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(e,i){const r=this.generateKey(e);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[i,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class Bn extends Tt{cacheManager;activeApiUrl=null;constructor(){super({requiresApiKey:!1,providerName:"Binance"}),this.cacheManager=new Cp(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${ai}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=ai,this.activeApiUrl}catch{}try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${gr}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=gr,this.activeApiUrl}catch{}return ai}async _fetchRawChunk(e,i,r,n,a){const s=Lt[i.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${i}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${s}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),n&&(o+=`&startTime=${n}`),a&&(o+=`&endTime=${a}`);const l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,i,r,n){try{const a=Lt[i.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${i}`),[];let s=[],o=r;const l=n,c=dr[a];if(!c)return console.error(`Duration not defined for interval: ${a}`),[];for(;o<l;){const h=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,i,1e3,o,h);if(p.length===0)break;s=s.concat(p),o=p[p.length-1].closeTime+1}return this.normalizeCloseTime(s),s}catch(a){return console.error("Error in getMarketDataInterval:",a),[]}}async getMarketDataBackwards(e,i,r,n){let a=r,s=[],o=n,l=0;const c=Math.ceil(r/1e3)+5;for(;a>0&&l<c;){l++;const h=Math.min(a,1e3),p=await this._fetchRawChunk(e,i,h,void 0,o);if(p.length===0||(s=p.concat(s),a-=p.length,o=p[0].openTime-1,p.length<h))break}return this.normalizeCloseTime(s),s}getSupportedTimeframes(){return new Set(["1","3","5","15","30","60","120","240","D","W","M"])}async _getMarketDataNative(e,i,r,n,a){try{const s=a!==void 0,o={tickerId:e,timeframe:i,limit:r,sDate:n,eDate:a};if(s){const c=this.cacheManager.get(o);if(c)return c}if(!Lt[i.toUpperCase()])return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,n,a)){if(n&&a){const c=await this.getMarketDataInterval(e,i,n,a),h=r?c.slice(0,r):c;return this.cacheManager.set(o,h),h}else if(r&&r>1e3){const c=await this.getMarketDataBackwards(e,i,r,a);return this.cacheManager.set(o,c),c}}const l=await this._fetchRawChunk(e,i,r,n,a);return this.normalizeCloseTime(l),s&&this.cacheManager.set(o,l),l}catch(s){return console.error("Error in binance.klines:",s),[]}}shouldPaginate(e,i,r,n){if(i&&i>1e3)return!0;if(r&&n){const a=Lt[e.toUpperCase()],s=dr[a];if(s)return Math.ceil((n-r)/s)>1e3}return!1}async getSymbolInfo(e){try{let i="crypto",r=await this.getBaseUrl(),n=e,a="";e.endsWith(".P")?(i="futures",n=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",a="Perpetual"):e.includes("_")&&(i="futures",n=e,r="https://dapi.binance.com/dapi/v1",a="Delivery");const s=i==="crypto"?`${r}/exchangeInfo?symbol=${n}`:`${r}/exchangeInfo`,o=await fetch(s);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;const c=i==="futures"?l.find(w=>w.symbol===n):l[0];if(!c)return console.error(`Symbol ${n} not found in exchange info`),null;const h=c.filters?.find(w=>w.filterType==="PRICE_FILTER"),p=c.filters?.find(w=>w.filterType==="LOT_SIZE"),u=h?parseFloat(h.tickSize):.01,f=p?parseFloat(p.minQty):0,m=Math.round(1/u),x=c.baseAsset,_=c.quoteAsset,b=a?` ${a}`:"",S=`${x} / ${_}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:x,description:S,type:i,main_tickerid:`BINANCE:${e}`,current_contract:a,isin:"",basecurrency:x,currency:_,timezone:"Etc/UTC",country:"",mintick:u,pricescale:m,minmove:1,pointvalue:c.contractSize||1,mincontract:f,session:"24x7",volumetype:"base",expiration_date:c.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in binance.exchangeInfo:",i),null}}}const Ip="https://financialmodelingprep.com",yr={"1D":{endpoint:"/stable/historical-price-eod/full",type:"daily"},D:{endpoint:"/stable/historical-price-eod/full",type:"daily"},1:{endpoint:"/stable/historical-chart/1min",interval:"1min",type:"intraday"},5:{endpoint:"/stable/historical-chart/5min",interval:"5min",type:"intraday"},15:{endpoint:"/stable/historical-chart/15min",interval:"15min",type:"intraday"},30:{endpoint:"/stable/historical-chart/30min",interval:"30min",type:"intraday"},60:{endpoint:"/stable/historical-chart/1hour",interval:"1hour",type:"intraday"},240:{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"},"4H":{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"}},xr={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",NYSEArca:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",PNK:"America/New_York",TSX:"America/Toronto",TSXV:"America/Toronto",LSE:"Europe/London",EURONEXT:"Europe/Paris",XETRA:"Europe/Berlin",JPX:"Asia/Tokyo",HKSE:"Asia/Hong_Kong",SSE:"Asia/Shanghai",SHZ:"Asia/Shanghai",ASX:"Australia/Sydney",NSE:"Asia/Kolkata",BSE:"Asia/Kolkata",KRX:"Asia/Seoul",CRYPTO:"Etc/UTC"},_r={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",NYSEArca:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",PNK:"0930-1600",TSX:"0930-1600",TSXV:"0930-1600",LSE:"0800-1630",EURONEXT:"0900-1730",XETRA:"0900-1730",JPX:"0900-1530",HKSE:"0930-1600",SSE:"0930-1500",SHZ:"0930-1500",ASX:"1000-1600",NSE:"0915-1530",BSE:"0915-1530",KRX:"0900-1530",CRYPTO:"24x7"},kp={daily:{periodType:"day",multiplier:1},"1min":{periodType:"minute",multiplier:1},"5min":{periodType:"minute",multiplier:5},"15min":{periodType:"minute",multiplier:15},"30min":{periodType:"minute",multiplier:30},"1hour":{periodType:"hour",multiplier:1},"4hour":{periodType:"hour",multiplier:4}};class Fn extends Tt{_apiKey=null;_baseUrl=Ip;_profileCache=new Map;constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),e?.apiKey&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,e.baseUrl&&(this._baseUrl=e.baseUrl)}getSupportedTimeframes(){return new Set(["1","5","15","30","60","240","D"])}async _getMarketDataNative(e,i,r,n,a){this.ensureConfigured();try{const s=i.toUpperCase(),o=yr[s]||yr[i];return o?o.type==="intraday"?this._fetchIntradayData(e,o.endpoint,o.interval,n,a,r):this._fetchDailyData(e,n,a,r):(console.error(`FMP: Unsupported timeframe: ${i}`),[])}catch(s){return console.error("Error in FMPProvider.getMarketData:",s),[]}}async _fetchDailyData(e,i,r,n){let a=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;i&&(a+=`&from=${this._msToDateStr(i)}`),r&&(a+=`&to=${this._msToDateStr(r)}`);const s=await fetch(a);if(!s.ok){const p=await s.text();throw new Error(`FMP HTTP ${s.status}: ${p}`)}const o=await s.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();const l=n&&n>0&&n<o.length?o.slice(o.length-n):o,{session:c,timezone:h}=await this._resolveSessionInfo(e);return l.map(p=>{const u=this._dateStrToMs(p.date),f=bi(u,c,h,"day");return{openTime:u,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:f,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,i,r,n,a,s){let o=`${this._baseUrl}${i}?symbol=${e}&apikey=${this._apiKey}`;n&&(o+=`&from=${this._msToDateStr(n)}`),a&&(o+=`&to=${this._msToDateStr(a)}`);const l=await fetch(o);if(!l.ok){const x=await l.text();if(l.status===403||x.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${r}) requires a paid plan. Use daily timeframe ('D') with a free API key, or upgrade at https://financialmodelingprep.com/`),[];throw new Error(`FMP HTTP ${l.status}: ${x}`)}const c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();const h=s&&s>0&&s<c.length?c.slice(c.length-s):c,{periodType:p,multiplier:u}=kp[r]||{periodType:"minute",multiplier:1},{session:f,timezone:m}=await this._resolveSessionInfo(e);return h.map(x=>{const _=this._dateTimeStrToMs(x.date),b=bi(_,f,m,p,u);return{openTime:_,open:x.open,high:x.high,low:x.low,close:x.close,volume:x.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchProfile(e);if(!i)return console.error(`FMP: Symbol ${e} not found`),null;const r=i.exchange||"",n=xr[r]||"America/New_York",a=_r[r]||"0930-1600";let s="stock";return i.isEtf?s="etf":i.isFund?s="fund":this._isCrypto(e)?s="crypto":this._isForex(e)&&(s="forex"),{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:i.symbol,description:i.companyName||i.symbol,type:s,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:i.isin||"",basecurrency:i.currency||"USD",currency:i.currency||"USD",timezone:s==="crypto"?"Etc/UTC":n,country:i.country||"",mintick:.01,pricescale:100,minmove:1,pointvalue:1,mincontract:0,session:s==="crypto"?"24x7":a,volumetype:"base",expiration_date:0,employees:parseInt(i.fullTimeEmployees)||0,industry:i.industry||"",sector:i.sector||"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in FMPProvider.getSymbolInfo:",i),null}}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);const i=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(i);if(!r.ok)return null;const n=await r.json();if(!Array.isArray(n)||n.length===0)return null;const a=n[0];return this._profileCache.set(e,a),a}async _resolveSessionInfo(e){try{const i=await this._fetchProfile(e);if(i){const r=i.exchange||"",n=this._isCrypto(e),a=n?"Etc/UTC":xr[r]||"America/New_York";return{session:n?"24x7":_r[r]||"0930-1600",timezone:a}}}catch{}return{session:"0930-1600",timezone:"America/New_York"}}_msToDateStr(e){return new Date(e).toISOString().split("T")[0]}_dateStrToMs(e){return new Date(e+"T00:00:00Z").getTime()}_dateTimeStrToMs(e){return new Date(e.replace(" ","T")+"Z").getTime()}_isCrypto(e){return/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=10}_isForex(e){return/^[A-Z]{6}$/.test(e)&&!this._isCrypto(e)}}const Ap="https://data.alpaca.markets",Tp="https://paper-api.alpaca.markets/v2",Pp="https://api.alpaca.markets/v2",oi=1e4,br={1:"1Min",3:"3Min",5:"5Min",15:"15Min",30:"30Min",60:"1Hour",120:"2Hour",240:"4Hour","4H":"4Hour","1D":"1Day",D:"1Day","1W":"1Week",W:"1Week","1M":"1Month",M:"1Month"},Dp={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",ARCA:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",CRYPTO:"Etc/UTC"},Mp={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},Rp={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"};class $n extends Tt{_apiKey=null;_apiSecret=null;_dataUrl=Ap;_tradingUrl=Tp;_feed=null;_assetCache=new Map;_calendarCache=new Map;constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),e?.apiKey&&e?.apiSecret&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,this._apiSecret=e.apiSecret,e.feed&&(this._feed=e.feed),e.dataUrl&&(this._dataUrl=e.dataUrl),e.tradingUrl?this._tradingUrl=e.tradingUrl:e.paper===!1&&(this._tradingUrl=Pp)}_headers(){return{"APCA-API-KEY-ID":this._apiKey,"APCA-API-SECRET-KEY":this._apiSecret}}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,n,a){this.ensureConfigured();try{const s=this._resolveTimeframe(i);if(!s)return console.error(`Alpaca: Unsupported timeframe: ${i}`),[];const o=this._isCrypto(e),l=await this._fetchAllBars(e,s,o,n,a,r);if(l.length===0)return[];const{periodType:c,multiplier:h}=this._parseAlpacaTimeframe(s);if(o)return this._convertBarsCrypto(l,c,h);const p=l[0].t.slice(0,10),u=l[l.length-1].t.slice(0,10),f=this._addDaysToDate(u,40);return await this._ensureCalendar(p,f),this._convertBarsStock(l,c,h)}catch(s){return console.error("Error in AlpacaProvider.getMarketData:",s),[]}}async _fetchAllBars(e,i,r,n,a,s){const o=[];let l=null;const c=s||1/0,h=Math.min(s||oi,oi);do{const p=this._buildBarsUrl(e,i,r,n,a,h,l),u=await fetch(p,{headers:this._headers()});if(!u.ok){const x=await u.text();throw new Error(`Alpaca HTTP ${u.status}: ${x}`)}const f=await u.json(),m=Object.keys(f.bars||{})[0];if(!m||!f.bars[m]||(o.push(...f.bars[m]),l=f.next_page_token,o.length>=c))break}while(l);return s&&s>0&&o.length>s?o.slice(0,s):o}_buildBarsUrl(e,i,r,n,a,s,o){const l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",i),c.set("sort","asc"),n&&c.set("start",new Date(n).toISOString()),a&&c.set("end",new Date(a).toISOString()),s&&c.set("limit",String(Math.min(s,oi))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchAsset(e);if(!i)return console.error(`Alpaca: Symbol ${e} not found`),null;const r=i.exchange||"",n=i.class==="crypto",a=n?"Etc/UTC":Dp[r]||"America/New_York",s=n?"24x7":Mp[r]||"0930-1600";let o="stock";n&&(o="crypto");const l=n&&e.split("/")[1]||"USD",c=n?e.split("/")[0]||e:l,h=i.price_increment?parseFloat(i.price_increment):.01,p=Math.round(1/h);return{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:n?e.split("/")[0]:i.symbol,description:i.name||i.symbol,type:o,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:a,country:n?"":"US",mintick:h,pricescale:p,minmove:1,pointvalue:1,mincontract:i.min_order_size?parseFloat(i.min_order_size):0,session:s,volumetype:"base",expiration_date:0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in AlpacaProvider.getSymbolInfo:",i),null}}_convertBarsCrypto(e,i,r){return e.map((n,a,s)=>{const o=new Date(n.t).getTime(),l=a<s.length-1?new Date(s[a+1].t).getTime():pt(o,i,r);return this._toKline(n,o,l)})}_convertBarsStock(e,i,r){const n="America/New_York";return e.map(a=>{const s=new Date(a.t).getTime(),o=a.t.slice(0,10);let l;if(i==="day"){const c=this._calendarCache.get(o),h=c?c.close:"16:00";l=Ce(o,h,n)}else if(i==="minute"||i==="hour"){const c=s+r*{minute:6e4,hour:36e5}[i],h=this._calendarCache.get(o),p=h?h.close:"16:00",u=Ce(o,p,n);l=Math.min(c,u)}else i==="week"?l=this._weeklyCloseFromCalendar(o,n):i==="month"?l=this._monthlyCloseFromCalendar(o,n):l=pt(s,i,r);return this._toKline(a,s,l)})}_toKline(e,i,r){return{openTime:i,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:r,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,i){const r=new Date(e+"T00:00:00Z"),n=r.getUTCDay(),a=n<=5?5-n:5-n+7;for(let l=a;l>=0;l--){const c=r.getTime()+l*864e5,h=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(h);if(p)return Ce(h,p.close,i)}const s=r.getTime()+a*864e5,o=new Date(s).toISOString().split("T")[0];return Ce(o,"16:00",i)}_monthlyCloseFromCalendar(e,i){const[r,n]=e.split("-").map(Number),a=new Date(Date.UTC(r,n,0)).getUTCDate();for(let o=a;o>=1;o--){const l=`${r}-${String(n).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return Ce(l,c.close,i)}const s=new Date(Date.UTC(r,n,0));for(;s.getUTCDay()===0||s.getUTCDay()===6;)s.setUTCDate(s.getUTCDate()-1);return Ce(s.toISOString().split("T")[0],"16:00",i)}async _ensureCalendar(e,i){if(this._calendarCache.has(e)&&this._calendarCache.has(i))return;const r=`${this._tradingUrl}/calendar?start=${e}&end=${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok){console.warn(`Alpaca calendar API returned ${n.status}, falling back to defaults`);return}const a=await n.json();for(const s of a)this._calendarCache.set(s.date,s)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);const i=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok)return null;const a=await n.json();return this._assetCache.set(e,a),a}_parseAlpacaTimeframe(e){const i=e.match(/^(\d+)(Min|Hour|Day|Week|Month)$/);if(i){const r=parseInt(i[1],10),n=Rp[i[2]];if(n)return{periodType:n,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return br[e.toUpperCase()]||br[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,i){const r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+i),r.toISOString().split("T")[0]}}const Vp=qn.fileURLToPath(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||new URL("pinets.min.cjs",document.baseURI).href),Op=vt.dirname(Vp);class Lp extends Tt{dataCache=new Map;exchangeInfoCache={};dataDirectory;constructor(e){super({requiresApiKey:!1,providerName:"Mock"});const i=typeof e=="string"?e:e?.dataDirectory;if(i)this.dataDirectory=i;else{const r=vt.resolve(Op,"../../../");this.dataDirectory=vt.join(r,"tests","compatibility","_data")}}configure(e){super.configure(e),e.dataDirectory&&(this.dataDirectory=e.dataDirectory)}getDataFileName(e,i,r,n){return r&&n?`${e}-${i}-${r}-${n}.json`:null}loadDataFromFile(e){const i=`file:${e}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=vt.join(this.dataDirectory,e);if(!st.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const n=st.readFileSync(r,"utf-8"),a=JSON.parse(n);return this.dataCache.set(i,a),a}findDataFile(e,i,r,n){if(!st.existsSync(this.dataDirectory))return null;const a=st.readdirSync(this.dataDirectory).filter(l=>l.endsWith(".json"));if(r&&n){const l=`${e}-${i}-${r}-${n}.json`;if(a.includes(l))return l}const s=new RegExp(`^${e}-${i}-(\\d+)-(\\d+)\\.json$`),o=a.filter(l=>s.test(l)).map(l=>{const c=l.match(s);return{file:l,startTime:parseInt(c[1]),endTime:parseInt(c[2])}}).sort((l,c)=>c.endTime-l.endTime);if(o.length===0)return null;if(r&&n){const l=o.find(c=>c.startTime<=r&&c.endTime>=n);if(l)return l.file}return o[0].file}filterData(e,i,r,n){let a=e;return(i||r)&&(a=e.filter(s=>{const o=!i||s.openTime>=i,l=!r||s.openTime<=r;return o&&l})),a.sort((s,o)=>s.openTime-o.openTime),n&&n>0&&(a=a.slice(0,n)),a}normalizeTimeframe(e){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[e.toUpperCase()]||e.toLowerCase()}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,n,a){try{const s=this.normalizeTimeframe(i),o=this.findDataFile(e,s,n,a);if(!o)return console.warn(`No mock data file found for ${e} ${s}. Searched in: ${this.dataDirectory}`),[];const l=this.loadDataFromFile(o),c=this.filterData(l,n,a,r);return this.normalizeCloseTime(c),c}catch(s){return console.error("Error in MockProvider.getMarketData:",s),[]}}loadExchangeInfo(e){if(this.exchangeInfoCache[e])return this.exchangeInfoCache[e];const i=e==="spot"?"api-exchangeInfo.json":"fapi-exchangeInfo.json",r=vt.join(this.dataDirectory,i);if(!st.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const n=st.readFileSync(r,"utf-8"),a=JSON.parse(n);return this.exchangeInfoCache[e]=a,a}catch(n){return console.error(`Error loading exchange info from ${i}:`,n),null}}async getSymbolInfo(e){try{let i="crypto",r=e,n="";e.endsWith(".P")?(i="futures",r=e.replace(".P",""),n="Perpetual"):e.includes("_")&&(i="futures",r=e,n="Delivery");const a=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!a||!a.symbols)return console.error(`Exchange info not available for ${i}`),null;const s=a.symbols.find(_=>_.symbol===r);if(!s)return console.error(`Symbol ${r} not found in ${i} exchange info`),null;const o=s.filters?.find(_=>_.filterType==="PRICE_FILTER"),l=s.filters?.find(_=>_.filterType==="LOT_SIZE"),c=o?parseFloat(o.tickSize):.01,h=l?parseFloat(l.minQty):0,p=Math.round(1/c),u=s.baseAsset,f=s.quoteAsset,m=n?` ${n}`:"",x=`${u} / ${f}${m}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:u,description:x,type:i,main_tickerid:`BINANCE:${e}`,current_contract:n,isin:"",basecurrency:u,currency:f,timezone:"Etc/UTC",country:"",mintick:c,pricescale:p,minmove:1,pointvalue:s.contractSize||1,mincontract:h,session:"24x7",volumetype:"base",expiration_date:s.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in MockProvider.getSymbolInfo:",i),null}}clearCache(){this.dataCache.clear(),this.exchangeInfoCache={}}setDataDirectory(e){this.dataDirectory=e,this.clearCache()}}const jp=typeof process<"u"&&process.versions&&process.versions.node;let zt=null;if(jp)try{zt=new Lp}catch{zt=null}const Bp={Binance:new Bn,FMP:new Fn,Alpaca:new $n,...zt?{Mock:zt}:{}};class Fp extends Error{method;constructor(e,i){super(e),this.name="PineRuntimeError",this.method=i}}exports.AlpacaProvider=$n;exports.BaseProvider=Tt;exports.BinanceProvider=Bn;exports.Context=Qe;exports.FMPProvider=Fn;exports.Indicator=_i;exports.PineRuntimeError=Fp;exports.PineTS=Vi;exports.Provider=Bp;exports.TIMEFRAME_PERIOD_INFO=yp;exports.TIMEFRAME_SECONDS=ut;exports.aggregateCandles=jn;exports.computeNextPeriodStart=pt;exports.computeSessionClose=bi;exports.getAggregationRatio=Oi;exports.localTimeToUTC=Ce;exports.selectSubTimeframe=Ln;
|
|
120
|
+
; return _r;`)(this)}function Ca(t){return e=>new D(e.array.map(i=>Math.abs(i)),e.type,t)}function Ia(t){return e=>{let i=0,r=0;for(const n of e.array){const a=Number(n);isNaN(a)||(r++,i+=(a-i)/r)}return r===0?NaN:t.precision(i)}}function ka(t){return(e,i)=>{const r=e.array;let n=0,a=r.length-1;for(;n<=a;){const s=Math.floor((n+a)/2),o=r[s];if(o===i)return s;o<i?n=s+1:a=s-1}return-1}}function Aa(t){return(e,i)=>{const r=e.array;let n=0,a=r.length;for(;n<a;){const s=Math.floor((n+a)/2);r[s]<i?n=s+1:a=s}return n<r.length&&r[n]===i?n:n-1}}function Ta(t){return(e,i)=>{const r=e.array;let n=0,a=r.length;for(;n<a;){const s=Math.floor((n+a)/2);r[s]<=i?n=s+1:a=s}return n>0&&r[n-1]===i?n-1:n}}function Pa(t){return e=>{e.array.length=0}}function Da(t){return(e,i)=>(e.array.push(...i.array),e)}function Ma(t){return e=>new D([...e.array],e.type,t)}function Ra(t){return(e,i,r=!0)=>{const n=e.array,a=i.array;if(n.length!==a.length)return NaN;let s=0,o=0,l=0;const c=[];for(let m=0;m<n.length;m++){const x=Number(n[m]),_=Number(a[m]);!isNaN(x)&&x!==null&&x!==void 0&&!isNaN(_)&&_!==null&&_!==void 0&&(s+=x,o+=_,l++,c.push(m))}if(l===0)return NaN;const h=s/l,p=o/l;let u=0;for(const m of c){const x=Number(n[m]),_=Number(a[m]);u+=(x-h)*(_-p)}const f=r?l:l-1;return f<=0?NaN:t.precision(u/f)}}function Va(t){return e=>e.array.every(i=>!isNaN(i)&&i)}function Oa(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?T.int:T.float:t.every(e=>typeof e=="string")?T.string:t.every(e=>typeof e=="boolean")?T.bool:T.any}function be(t){return typeof t=="number"?Number.isInteger(t)?T.int:T.float:typeof t=="string"?T.string:typeof t=="boolean"?T.bool:T.any}function At(t,e){if(typeof t=="number"&&isNaN(t)||e===T.any)return!0;switch(e){case T.int:return Number.isInteger(t)||isNaN(t);case T.float:return typeof t=="number";case T.string:return typeof t=="string";case T.bool:return typeof t=="boolean";case T.box:case T.label:case T.line:case T.linefill:case T.table:case T.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function La(t){return(e,i,r=0,n)=>{const a=e.array.length,s=n!==void 0?Math.min(n,a):a;for(let o=r;o<s;o++){if(!At(i,e.type))throw new Error(`Cannot call 'array.fill' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array[o]=typeof i=="number"?t.precision(i):i}}}function ja(t){return e=>e.array.length>0?e.array[0]:t.NA}function Ba(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[i])}function Fa(t){return(e,i)=>e.array.includes(i)}function $a(t){return(e,i)=>typeof i=="number"&&i!==i?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(i)}function Wa(t){return(e,i,r)=>{if(!At(r,e.type))throw new Error(`Cannot call 'array.insert' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(i,0,r)}}function Ua(t){return(e,i=",")=>e.array.join(i)}function qa(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function za(t){return(e,i)=>e.array.lastIndexOf(i)}function Ka(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let a=1;a<r.length;a++)r[a]>n&&(n=r[a]);return n??t.NA}return[...r].sort((n,a)=>a-n)[i]??t.NA}}function Ha(t){return e=>{const i=e.array;if(i.length===0)return NaN;const r=new Array(i.length);for(let a=0;a<i.length;a++)r[a]=i[a];r.sort((a,s)=>a-s);const n=Math.floor(r.length/2);return r.length%2!==0?r[n]:(r[n-1]+r[n])/2}}function Ga(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let a=1;a<r.length;a++)r[a]<n&&(n=r[a]);return n??t.NA}return[...r].sort((n,a)=>n-a)[i]??t.NA}}function Ya(t){return e=>{if(e.array.length===0)return NaN;const i=new Map;let r=0;for(const a of e.array){const s=(i.get(a)||0)+1;i.set(a,s),s>r&&(r=s)}const n=[];for(const[a,s]of i)s===r&&n.push(a);return n.sort((a,s)=>typeof a=="number"&&typeof s=="number"?a-s:typeof a=="string"&&typeof s=="string"?a<s?-1:a>s?1:0:0),n[0]}}function Xa(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const a=new Array(n);for(let c=0;c<n;c++){const h=Number(r[c]);if(isNaN(h)||h===null||h===void 0)return NaN;a[c]=h}a.sort((c,h)=>c-h),i<0&&(i=0),i>100&&(i=100);const s=i/100*n-.5;if(s<=0)return t.precision(a[0]);if(s>=n-1)return t.precision(a[n-1]);const o=Math.floor(s),l=s-o;return t.precision(a[o]*(1-l)+a[o+1]*l)}}function Qa(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const a=new Array;for(let o=0;o<n;o++){const l=Number(r[o]);!isNaN(l)&&l!==null&&l!==void 0&&a.push(l)}if(a.length===0)return NaN;a.sort((o,l)=>o-l),i<0&&(i=0),i>100&&(i=100);const s=Math.ceil(i/100*n);return s<=0?a[0]:s>a.length?NaN:a[s-1]}}function Za(t){return(e,i)=>{if(e.array.length===0)return NaN;const r=Math.floor(i);if(r<0||r>=e.array.length)return NaN;const n=Number(e.array[r]);if(isNaN(n)||n===null||n===void 0)return NaN;let a=0;for(const o of e.array){const l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<n&&a++}const s=e.array.length-1;return s<=0?NaN:a/s*100}}function Ja(t){return e=>e.array.pop()}function eo(t){return(e,i)=>{if(!At(i,e.type))throw new Error(`Cannot call 'array.push' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.push(typeof i=="number"?t.precision(i):i)}}function to(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function io(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(i,1)[0])}function ro(t){return e=>{e.array.reverse()}}function no(t){return(e,i,r)=>{if(!At(r,e.type))throw new Error(`Cannot call 'array.set' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>=e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[i]=typeof r=="number"?t.precision(r):r}}function so(t){return e=>e.array.shift()}function ao(t){return e=>e.array.length}function oo(t){return(e,i,r)=>{const n=r!==void 0?r:void 0;return new D(e.array.slice(i,n),e.type,t)}}function lo(t){return e=>e.array.some(i=>!isNaN(i)&&i)}var ft=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(ft||{}),mn=(t=>(t.AED="AED",t.ARS="ARS",t.AUD="AUD",t.BDT="BDT",t.BHD="BHD",t.BRL="BRL",t.BTC="BTC",t.CAD="CAD",t.CHF="CHF",t.CLP="CLP",t.CNY="CNY",t.COP="COP",t.CZK="CZK",t.DKK="DKK",t.EGP="EGP",t.ETH="ETH",t.EUR="EUR",t.GBP="GBP",t.HKD="HKD",t.HUF="HUF",t.IDR="IDR",t.ILS="ILS",t.INR="INR",t.ISK="ISK",t.JPY="JPY",t.KES="KES",t.KRW="KRW",t.KWD="KWD",t.LKR="LKR",t.MAD="MAD",t.MXN="MXN",t.MYR="MYR",t.NGN="NGN",t.NOK="NOK",t.NONE="NONE",t.NZD="NZD",t.PEN="PEN",t.PHP="PHP",t.PKR="PKR",t.PLN="PLN",t.QAR="QAR",t.RON="RON",t.RSD="RSD",t.RUB="RUB",t.SAR="SAR",t.SEK="SEK",t.SGD="SGD",t.THB="THB",t.TND="TND",t.TRY="TRY",t.TWD="TWD",t.USD="USD",t.USDT="USDT",t.VES="VES",t.VND="VND",t.ZAR="ZAR",t))(mn||{}),gn=(t=>(t[t.sunday=1]="sunday",t[t.monday=2]="monday",t[t.tuesday=3]="tuesday",t[t.wednesday=4]="wednesday",t[t.thursday=5]="thursday",t[t.friday=6]="friday",t[t.saturday=7]="saturday",t))(gn||{}),yn=(t=>(t.all="all",t.data_window="data_window",t.none="none",t.pane="pane",t.price_scale="price_scale",t.status_line="status_line",t))(yn||{}),xn=(t=>(t.flag="shape_flag",t.arrowdown="shape_arrow_down",t.arrowup="shape_arrow_up",t.circle="shape_circle",t.cross="shape_cross",t.diamond="shape_diamond",t.labeldown="shape_label_down",t.labelup="shape_label_up",t.square="shape_square",t.triangledown="shape_triangle_down",t.triangleup="shape_triangle_up",t.xcross="shape_xcross",t))(xn||{}),_n=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(_n||{}),bn=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(bn||{}),wn=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(wn||{}),co=(t=>(t.linestyle_dashed="linestyle_dashed",t.linestyle_dotted="linestyle_dotted",t.linestyle_solid="linestyle_solid",t.style_area="style_area",t.style_areabr="style_areabr",t.style_circles="style_circles",t.style_columns="style_columns",t.style_cross="style_cross",t.style_histogram="style_histogram",t.style_line="style_line",t.style_linebr="style_linebr",t.style_stepline="style_stepline",t.style_stepline_diamond="style_stepline_diamond",t.style_steplinebr="style_steplinebr",t))(co||{}),vn=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(vn||{}),Sn=(t=>(t.bar_index="bi",t.bar_time="bt",t))(Sn||{}),En=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(En||{}),Nn=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(Nn||{}),Cn=(t=>(t.align_bottom="bottom",t.align_top="top",t.align_left="left",t.align_center="center",t.align_right="right",t.wrap_auto="auto",t.wrap_none="none",t.format_bold="bold",t.format_italic="italic",t.format_none="none",t))(Cn||{}),In=(t=>(t.family_default="default",t.family_monospace="monospace",t))(In||{}),kn=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(kn||{}),An=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(An||{}),Tn=(t=>(t.actual="earnings_actual",t.estimate="earnings_estimate",t.standardized="earnings_standardized",t.future_eps="earnings_future_eps",t.future_period_end_time="earnings_future_period_end_time",t.future_revenue="earnings_future_revenue",t.future_time="earnings_future_time",t))(Tn||{}),Pn=(t=>(t.gross="dividends_gross",t.net="dividends_net",t.future_amount="dividends_future_amount",t.future_ex_date="dividends_future_ex_date",t.future_pay_date="dividends_future_pay_date",t))(Pn||{}),Dn=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(Dn||{}),Mn=(t=>(t.top_left="top_left",t.top_center="top_center",t.top_right="top_right",t.middle_left="middle_left",t.middle_center="middle_center",t.middle_right="middle_right",t.bottom_left="bottom_left",t.bottom_center="bottom_center",t.bottom_right="bottom_right",t))(Mn||{}),Rn=(t=>(t.left="left",t.none="none",t.right="right",t))(Rn||{}),Vn=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(Vn||{});const ho={order:ft,currency:mn,dayofweek:gn,display:yn,shape:xn,location:_n,size:bn,format:wn,barmerge:vn,xloc:Sn,yloc:En,extend:Nn,text:Cn,font:In,adjustment:kn,backadjustment:An,earnings:Tn,dividends:Pn,splits:Dn,position:Mn,scale:Rn,settlement_as_close:Vn};function uo(t){return(e,i=ft.ascending)=>{e.array.sort((r,n)=>{let a=isNaN(r)?1/0:r,s=isNaN(n)?1/0:n;return i===ft.ascending?a-s:s-a})}}function po(t){return(e,i=ft.ascending)=>{const r=e.array.map((n,a)=>a);return r.sort((n,a)=>{const s=isNaN(e.array[n])?1/0:e.array[n],o=isNaN(e.array[a])?1/0:e.array[a];return i===ft.ascending?s-o:o-s}),new D(r,T.int,t)}}function fo(t){return e=>{const i=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new D(e.array.map(()=>NaN),T.int,t):r===0?new D(e.array.map(()=>1),T.int,t):new D(e.array.map(n=>(n-i)/r),T.int,t)}}function mo(t){return(e,i=!0)=>{const r=e.array,n=r.length;if(n===0)return NaN;let a=0,s=0,o=0;for(let h=0;h<n;h++){const p=Number(r[h]);!isNaN(p)&&p!==null&&p!==void 0&&(a+=p,s+=p*p,o++)}if(o===0)return NaN;const l=a/o;let c=s/o-l*l;return c<0?NaN:(!i&&o>1&&(c=c*o/(o-1)),!i&&o===1?0:t.precision(Math.sqrt(c)))}}function go(t){return e=>t.precision(e.array.reduce((i,r)=>{const n=Number(r);return isNaN(n)?i:i+n},0))}function yo(t){return(e,i)=>{if(!At(i,e.type))throw new Error(`Cannot call 'array.unshift' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.unshift(typeof i=="number"?t.precision(i):i)}}function xo(t){return(e,i=!0)=>{let r=0,n=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,n++)}if(n===0)return NaN;const a=r/n;let s=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(s+=(c-a)*(c-a))}const o=i?n:n-1;return o<=0?NaN:t.precision(s/o)}}var T=(t=>(t.any="",t.box="box",t.bool="bool",t.color="color",t.float="float",t.int="int",t.label="label",t.line="line",t.linefill="linefill",t.string="string",t.table="table",t))(T||{});class D{constructor(e,i,r){this.array=e,this.type=i,this.context=r,this._abs=Ca(this.context),this._avg=Ia(this.context),this._binary_search=ka(this.context),this._binary_search_leftmost=Aa(this.context),this._binary_search_rightmost=Ta(this.context),this._clear=Pa(this.context),this._concat=Da(this.context),this._copy=Ma(this.context),this._covariance=Ra(this.context),this._every=Va(this.context),this._fill=La(this.context),this._first=ja(this.context),this._get=Ba(this.context),this._includes=Fa(this.context),this._indexof=$a(this.context),this._insert=Wa(this.context),this._join=Ua(this.context),this._last=qa(this.context),this._lastindexof=za(this.context),this._max=Ka(this.context),this._median=Ha(this.context),this._min=Ga(this.context),this._mode=Ya(this.context),this._percentile_linear_interpolation=Xa(this.context),this._percentile_nearest_rank=Qa(this.context),this._percentrank=Za(this.context),this._pop=Ja(this.context),this._push=eo(this.context),this._range=to(this.context),this._remove=io(this.context),this._reverse=ro(this.context),this._set=no(this.context),this._shift=so(this.context),this._size=ao(this.context),this._slice=oo(this.context),this._some=lo(this.context),this._sort=uo(this.context),this._sort_indices=po(this.context),this._standardize=fo(this.context),this._stdev=mo(this.context),this._sum=go(this.context),this._unshift=yo(this.context),this._variance=xo(this.context)}_abs;_avg;_binary_search;_binary_search_leftmost;_binary_search_rightmost;_clear;_concat;_copy;_covariance;_every;_fill;_first;_get;_includes;_indexof;_insert;_join;_last;_lastindexof;_max;_median;_min;_mode;_percentile_linear_interpolation;_percentile_nearest_rank;_percentrank;_pop;_push;_range;_remove;_reverse;_set;_shift;_size;_slice;_some;_sort;_sort_indices;_standardize;_stdev;_sum;_unshift;_variance;toString(){return"["+this.array.toString().replace(/,/g,", ")+"]"}[Symbol.iterator](){return this.array[Symbol.iterator]()}abs(...e){return this._abs(this,...e)}avg(...e){return this._avg(this,...e)}binary_search(...e){return this._binary_search(this,...e)}binary_search_leftmost(...e){return this._binary_search_leftmost(this,...e)}binary_search_rightmost(...e){return this._binary_search_rightmost(this,...e)}clear(...e){return this._clear(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}covariance(...e){return this._covariance(this,...e)}every(...e){return this._every(this,...e)}fill(...e){return this._fill(this,...e)}first(...e){return this._first(this,...e)}get(...e){return this._get(this,...e)}includes(...e){return this._includes(this,...e)}indexof(...e){return this._indexof(this,...e)}insert(...e){return this._insert(this,...e)}join(...e){return this._join(this,...e)}last(...e){return this._last(this,...e)}lastindexof(...e){return this._lastindexof(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}percentile_linear_interpolation(...e){return this._percentile_linear_interpolation(this,...e)}percentile_nearest_rank(...e){return this._percentile_nearest_rank(this,...e)}percentrank(...e){return this._percentrank(this,...e)}pop(...e){return this._pop(this,...e)}push(...e){return this._push(this,...e)}range(...e){return this._range(this,...e)}remove(...e){return this._remove(this,...e)}reverse(...e){return this._reverse(this,...e)}set(...e){return this._set(this,...e)}shift(...e){return this._shift(this,...e)}size(...e){return this._size(this,...e)}slice(...e){return this._slice(this,...e)}some(...e){return this._some(this,...e)}sort(...e){return this._sort(this,...e)}sort_indices(...e){return this._sort_indices(this,...e)}standardize(...e){return this._standardize(this,...e)}stdev(...e){return this._stdev(this,...e)}sum(...e){return this._sum(this,...e)}unshift(...e){return this._unshift(this,...e)}variance(...e){return this._variance(this,...e)}}function _o(t){return(...e)=>new D([...e],Oa(e),t)}function bo(t){return(e,i)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(i===void 0){const n=r?Array(r).fill(0):[];return new D(n,T.any,t)}return new D(Array(r).fill(t.precision(i||0)),be(i||0),t)}}function wo(t){return(e=0,i=!1)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.bool,t)}}function vo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.box,t)}}function So(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.color,t)}}function Eo(t){return(e=0,i=NaN)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(t.precision(i)),T.float,t)}}function No(t){return(e=0,i=0)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(t.precision(i)),T.int,t)}}function Co(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.label,t)}}function Io(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.line,t)}}function ko(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.linefill,t)}}function Ao(t){return(e=0,i="")=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.string,t)}}function To(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new D(Array(r).fill(i),T.table,t)}}class y{constructor(e,i=0){this.data=e,this.offset=i}get(e){const i=this.data.length-1-(this.offset+e);return i<0||i>=this.data.length?NaN:this.data[i]}set(e,i){const r=this.data.length-1-(this.offset+e);r>=0&&r<this.data.length&&(this.data[r]=i)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof y?e:Array.isArray(e)?new y(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof y?e.__value:new y([e])}}function Po(t){return(e,i=0)=>y.from(e).get(i)}class Do{constructor(e){this.context=e,this.abs=(i,...r)=>i.abs(...r),this.avg=(i,...r)=>i.avg(...r),this.binary_search=(i,...r)=>i.binary_search(...r),this.binary_search_leftmost=(i,...r)=>i.binary_search_leftmost(...r),this.binary_search_rightmost=(i,...r)=>i.binary_search_rightmost(...r),this.clear=(i,...r)=>i.clear(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.covariance=(i,...r)=>i.covariance(...r),this.every=(i,...r)=>i.every(...r),this.fill=(i,...r)=>i.fill(...r),this.first=(i,...r)=>i.first(...r),this.from=_o(e),this.get=(i,...r)=>i.get(...r),this.includes=(i,...r)=>i.includes(...r),this.indexof=(i,...r)=>i.indexof(...r),this.insert=(i,...r)=>i.insert(...r),this.join=(i,...r)=>i.join(...r),this.last=(i,...r)=>i.last(...r),this.lastindexof=(i,...r)=>i.lastindexof(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.new=bo(e),this.new_bool=wo(e),this.new_box=vo(e),this.new_color=So(e),this.new_float=Eo(e),this.new_int=No(e),this.new_label=Co(e),this.new_line=Io(e),this.new_linefill=ko(e),this.new_string=Ao(e),this.new_table=To(e),this.param=Po(),this.percentile_linear_interpolation=(i,...r)=>i.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(i,...r)=>i.percentile_nearest_rank(...r),this.percentrank=(i,...r)=>i.percentrank(...r),this.pop=(i,...r)=>i.pop(...r),this.push=(i,...r)=>i.push(...r),this.range=(i,...r)=>i.range(...r),this.remove=(i,...r)=>i.remove(...r),this.reverse=(i,...r)=>i.reverse(...r),this.set=(i,...r)=>i.set(...r),this.shift=(i,...r)=>i.shift(...r),this.size=(i,...r)=>i.size(...r),this.slice=(i,...r)=>i.slice(...r),this.some=(i,...r)=>i.some(...r),this.sort=(i,...r)=>i.sort(...r),this.sort_indices=(i,...r)=>i.sort_indices(...r),this.standardize=(i,...r)=>i.standardize(...r),this.stdev=(i,...r)=>i.stdev(...r),this.sum=(i,...r)=>i.sum(...r),this.unshift=(i,...r)=>i.unshift(...r),this.variance=(i,...r)=>i.variance(...r)}}function Mo(t){return e=>{e.map.clear()}}function Ro(t){return(e,i)=>e.map.has(i)}function Vo(t){return e=>{const i=new On(t);return i.map=new Map(e.map),i}}function Oo(t){return(e,i)=>{const r=e.map.get(i);return r===void 0?NaN:r}}function Lo(t){return e=>{const i=Array.from(e.map.keys()),r=be(i[0]);return new D(i,r,t)}}function jo(t){return(e,i,r)=>{const n=e.map.get(i);return e.map.set(i,r),n===void 0?NaN:n}}function Bo(t){return(e,i)=>{for(const[r,n]of i.map)e.map.set(r,n)}}function Fo(t){return(e,i)=>{const r=e.map.get(i);return e.map.delete(i)?r:NaN}}function $o(t){return e=>e.map.size}function Wo(t){return e=>{const i=Array.from(e.map.values()),r=be(i[0]);return new D(i,r,t)}}class On{constructor(e){this.context=e,this.map=new Map,this._clear=Mo(this.context),this._contains=Ro(this.context),this._copy=Vo(this.context),this._get=Oo(this.context),this._keys=Lo(this.context),this._put=jo(this.context),this._put_all=Bo(this.context),this._remove=Fo(this.context),this._size=$o(this.context),this._values=Wo(this.context)}map;_clear;_contains;_copy;_get;_keys;_put;_put_all;_remove;_size;_values;toString(){return`PineMapObject(${this.map.size})`}clear(...e){return this._clear(this,...e)}contains(...e){return this._contains(this,...e)}copy(...e){return this._copy(this,...e)}get(...e){return this._get(this,...e)}keys(...e){return this._keys(this,...e)}put(...e){return this._put(this,...e)}put_all(...e){return this._put_all(this,...e)}remove(...e){return this._remove(this,...e)}size(...e){return this._size(this,...e)}values(...e){return this._values(this,...e)}}function Uo(t){return()=>new On(t)}function qo(t){return(e,i=0)=>y.from(e).get(i)}class zo{constructor(e){this.context=e,this.clear=(i,...r)=>i.clear(...r),this.contains=(i,...r)=>i.contains(...r),this.copy=(i,...r)=>i.copy(...r),this.get=(i,...r)=>i.get(...r),this.keys=(i,...r)=>i.keys(...r),this.new=Uo(e),this.param=qo(),this.put=(i,...r)=>i.put(...r),this.put_all=(i,...r)=>i.put_all(...r),this.remove=(i,...r)=>i.remove(...r),this.size=(i,...r)=>i.size(...r),this.values=(i,...r)=>i.values(...r)}}function Ko(t){return(e,i,r)=>{const n=e.matrix.length;let a=[];if(r&&(r instanceof D?a=r.array:Array.isArray(r)?a=r:a=[r]),n===0){for(let l=0;l<a.length;l++){let c=a[l];c instanceof y&&(c=c.get(0)),e.matrix.push([c])}return}const s=e.matrix[0].length,o=i!==void 0?i:s;for(let l=0;l<n;l++){let c=l<a.length?a[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function Ho(t){return(e,i,r)=>{const n=e.matrix.length;let a=[];if(r)if(r instanceof D)a=r.array;else if(Array.isArray(r))a=r;else if(r instanceof y){const c=r.get(0);Array.isArray(c)?a=c:a=[c]}else a=[r];const s=n>0?e.matrix[0].length:a.length,o=i!==void 0?i:n,l=[];for(let c=0;c<s;c++)if(c<a.length){let h=a[c];h instanceof y&&(h=h.get(0)),l.push(h)}else l.push(NaN);e.matrix.splice(o,0,l)}}function Go(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;if(r===0)return NaN;let n=0,a=0;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(n+=l,a++)}return a===0?NaN:n/a}}function Yo(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i<0||i>=n){t.warn(`Column index ${i} is out of bounds, matrix has ${n} columns.`,"matrix.col");const o=r>0?be(e.matrix[0][0]):"float";return new D([],o,t)}const a=[];for(let o=0;o<r;o++)a.push(e.matrix[o][i]);const s=be(a[0]);return new D(a,s,t)}}function Xo(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function Qo(t){return(e,i)=>{const r=e.matrix.length,n=i.matrix.length;if(r===0){for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]]);return}const a=e.matrix[0].length,s=n>0?i.matrix[0].length:0;if(a!==s&&n>0){console.error(`matrix.concat: Column count mismatch ${a} vs ${s}`);return}for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]])}}function Zo(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0,n=new F(i,r,NaN,t);return n.matrix=e.matrix.map(a=>[...a]),n}}function Jo(t){const e=t.length;if(e===0)return 0;if(e===1)return t[0][0];if(e===2)return t[0][0]*t[1][1]-t[0][1]*t[1][0];const i=t.map(n=>[...n]);let r=1;for(let n=0;n<e;n++){let a=n;for(;a<e&&i[a][n]===0;)a++;if(a===e)return 0;a!==n&&([i[n],i[a]]=[i[a],i[n]],r*=-1),r*=i[n][n];for(let s=n+1;s<e;s++){const o=i[s][n]/i[n][n];for(let l=n;l<e;l++)i[s][l]-=o*i[n][l]}}return r}function el(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;return i!==r?NaN:Jo(e.matrix)}}function tl(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new F(0,0,NaN,t);const n=e.matrix[0].length,a=new F(r,n,NaN,t);if(i instanceof F)for(let s=0;s<r;s++)for(let o=0;o<n;o++){const l=e.matrix[s][o],c=i.matrix[s]&&i.matrix[s][o]!==void 0?i.matrix[s][o]:NaN;a.matrix[s][o]=l-c}else{const s=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)a.matrix[o][l]=e.matrix[o][l]-s}return a}}function il(t){const e=t.length;if(e!==2)return Array(e).fill(NaN);const i=t[0][0],r=t[0][1],n=t[1][0],a=t[1][1],s=i+a,o=i*a-r*n,l=s*s-4*o;if(l<0)return[NaN,NaN];const c=(s+Math.sqrt(l))/2,h=(s-Math.sqrt(l))/2;return[c,h]}function rl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r){const s=be(e.matrix[0][0]);return new D([],s,t)}const n=il(e.matrix),a=be(n[0]);return new D(n,a,t)}}function nl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new F(0,0,NaN,t);const n=new F(i,r,0,t);for(let a=0;a<i;a++)n.matrix[a][a]=1;return n}}function sl(t){return e=>{const i=e.matrix.length;return i===0?0:i*e.matrix[0].length}}function al(t){return(e,i,r,n,a,s)=>{const o=e.matrix.length;if(o===0)return;const l=e.matrix[0].length,c=r!==void 0?r:0,h=n!==void 0?n:o,p=a!==void 0?a:0,u=s!==void 0?s:l;for(let f=c;f<h&&!(f>=o);f++)for(let m=p;m<u&&!(m>=l);m++)e.matrix[f][m]=i}}function ol(t){return(e,i,r)=>{const n=e.matrix.length,a=n>0?e.matrix[0].length:0;if(i<0||i>=n)return t.warn(`Row index ${i} is out of bounds, matrix has ${n} rows.`,"matrix.get"),NaN;if(r<0||r>=a)return t.warn(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.get"),NaN;const s=e.matrix[i][r];return s===void 0?NaN:s}}function jt(t){const e=t.length;if(e===0)return[];const i=new Array(e);for(let n=0;n<e;n++){i[n]=new Array(2*e);for(let a=0;a<e;a++)i[n][a]=t[n][a];for(let a=0;a<e;a++)i[n][e+a]=n===a?1:0}for(let n=0;n<e;n++){let a=Math.abs(i[n][n]),s=n;for(let l=n+1;l<e;l++){const c=Math.abs(i[l][n]);c>a&&(a=c,s=l)}if(a<1e-14)return t.map(l=>l.map(()=>NaN));if(s!==n){const l=i[n];i[n]=i[s],i[s]=l}const o=i[n][n];for(let l=n;l<2*e;l++)i[n][l]/=o;for(let l=0;l<e;l++){if(l===n)continue;const c=i[l][n];if(c!==0)for(let h=n;h<2*e;h++)i[l][h]-=c*i[n][h]}}const r=new Array(e);for(let n=0;n<e;n++){r[n]=new Array(e);for(let a=0;a<e;a++)r[n][a]=i[n][e+a]}return r}function ll(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new F(i,r,NaN,t);const n=jt(e.matrix),a=new F(i,r,NaN,t);return a.matrix=n,a}}function cl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n+a!==i-1&&e.matrix[n][a]!==0)return!1;return!0}}function hl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(e.matrix[a][n]!==-e.matrix[n][a])return!1;return!0}}function ul(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let a=0;a<r;a++){const s=e.matrix[n][a];if(s!==0&&s!==1)return!1}return!0}}function pl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n!==a&&e.matrix[n][a]!==0)return!1;return!0}}function fl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n===a){if(e.matrix[n][a]!==1)return!1}else if(e.matrix[n][a]!==0)return!1;return!0}}function dl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;return i===r}}function ml(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++){let a=0;for(let s=0;s<r;s++){const o=e.matrix[n][s];if(o<0)return!1;a+=o}if(Math.abs(a-1)>1e-10)return!1}return!0}}function gl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<n;a++)if(e.matrix[n][a]!==e.matrix[a][n])return!1;return!0}}function yl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;let n=!0,a=!0;for(let s=0;s<i;s++)for(let o=0;o<r;o++)s>o&&e.matrix[s][o]!==0&&(n=!1),s<o&&e.matrix[s][o]!==0&&(a=!1);return n||a}}function xl(t){return e=>{const i=e.matrix.length;if(i===0)return!0;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(e.matrix[n][a]!==0)return!1;return!0}}function _l(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0,a=i.matrix.length,s=a>0?i.matrix[0].length:0,o=r*a,l=n*s,c=new F(o,l,NaN,t);for(let h=0;h<r;h++)for(let p=0;p<n;p++){const u=e.matrix[h][p];for(let f=0;f<a;f++)for(let m=0;m<s;m++){const x=i.matrix[f][m];c.matrix[h*a+f][p*s+m]=u*x}}return c}}function bl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=-1/0,a=!1;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(l>n&&(n=l),a=!0)}return a?n:NaN}}function wl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=[];for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||n.push(l)}if(n.length===0)return NaN;n.sort((s,o)=>s-o);const a=Math.floor(n.length/2);return n.length%2!==0?n[a]:(n[a-1]+n[a])/2}}function vl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=1/0,a=!1;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(l<n&&(n=l),a=!0)}return a?n:NaN}}function Sl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=new Map;let a=0,s=NaN;for(let o=0;o<i;o++)for(let l=0;l<r;l++){const c=e.matrix[o][l];if(!isNaN(c)){const h=(n.get(c)||0)+1;n.set(c,h),h>a?(a=h,s=c):h===a&&c<s&&(s=c)}}return s}}function El(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i instanceof F){const a=i.matrix.length,s=a>0?i.matrix[0].length:0;if(n!==a)return new F(0,0,NaN,t);const o=new F(r,s,0,t);for(let l=0;l<r;l++)for(let c=0;c<s;c++){let h=0;for(let p=0;p<n;p++)h+=e.matrix[l][p]*i.matrix[p][c];o.matrix[l][c]=h}return o}else if(i instanceof D||Array.isArray(i.array||i)){const a=i.array||i;if(n!==a.length)return new D([],"float",t);const s=[];for(let o=0;o<r;o++){let l=0;for(let c=0;c<n;c++)l+=e.matrix[o][c]*a[c];s.push(l)}return new D(s,"float",t)}else{const a=i,s=new F(r,n,NaN,t);for(let o=0;o<r;o++)for(let l=0;l<n;l++)s.matrix[o][l]=e.matrix[o][l]*a;return s}}}function Nl(t){return e=>{const i=e.matrix.length;if(i===0)return new F(0,0,NaN,t);const r=e.matrix[0].length;if(i===r){const h=jt(e.matrix),p=new F(i,r,NaN,t);return p.matrix=h,p}const n=h=>{const p=h.length,u=h[0].length,f=new Array(u);for(let m=0;m<u;m++){f[m]=new Array(p);for(let x=0;x<p;x++)f[m][x]=h[x][m]}return f},a=(h,p)=>{const u=h.length,f=h[0].length,m=p[0].length,x=new Array(u);for(let _=0;_<u;_++){x[_]=new Array(m).fill(0);for(let b=0;b<f;b++){const v=h[_][b];if(v!==0)for(let w=0;w<m;w++)x[_][w]+=v*p[b][w]}}return x},s=e.matrix,o=n(s);let l;if(i>r){const h=a(o,s),p=jt(h);l=a(p,o)}else{const h=a(s,o),p=jt(h);l=a(o,p)}const c=new F(r,i,NaN,t);return c.matrix=l,c}}function Cl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new F(0,0,NaN,t);let a=new F(r,n,0,t);for(let l=0;l<r;l++)a.matrix[l][l]=1;let s=new F(r,n,NaN,t);for(let l=0;l<r;l++)s.matrix[l]=[...e.matrix[l]];let o=Math.floor(i);if(o<0)return new F(r,n,NaN,t);for(;o>0;){if(o%2===1){const c=new F(r,n,0,t);for(let h=0;h<r;h++)for(let p=0;p<n;p++){let u=0;for(let f=0;f<r;f++)u+=a.matrix[h][f]*s.matrix[f][p];c.matrix[h][p]=u}a=c}const l=new F(r,n,0,t);for(let c=0;c<r;c++)for(let h=0;h<n;h++){let p=0;for(let u=0;u<r;u++)p+=s.matrix[c][u]*s.matrix[u][h];l.matrix[c][h]=p}s=l,o=Math.floor(o/2)}return a}}function Il(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=e.matrix.map(s=>[...s]);let a=0;for(let s=0;s<r&&a<i;s++){let o=a;for(;o<i&&Math.abs(n[o][s])<1e-10;)o++;if(o<i){[n[a],n[o]]=[n[o],n[a]];const l=n[a][s];for(let c=s;c<r;c++)n[a][c]/=l;for(let c=0;c<i;c++)if(c!==a){const h=n[c][s];for(let p=s;p<r;p++)n[c][p]-=h*n[a][p]}a++}}return a}}function kl(t){return(e,i)=>{const r=e.matrix.length;if(r===0){const s=be(e.matrix[0][0]);return new D([],s,t)}const n=[];for(let s=0;s<r;s++){const o=e.matrix[s].splice(i,1);n.push(o[0])}const a=be(n[0]);return new D(n,a,t)}}function Al(t){return(e,i)=>{const r=e.matrix.splice(i,1),n=be(r[0][0]);return new D(r[0]||[],n,t)}}function Tl(t){return(e,i,r)=>{const n=e.matrix.length,a=n>0?e.matrix[0].length:0,s=i*r,o=[];for(let h=0;h<n;h++)for(let p=0;p<a;p++)o.push(e.matrix[h][p]);for(;o.length<s;)o.push(NaN);o.length>s&&(o.length=s);const l=[];let c=0;for(let h=0;h<i;h++){const p=[];for(let u=0;u<r;u++)p.push(o[c++]);l.push(p)}e.matrix=l}}function Pl(t){return e=>{e.matrix.reverse();for(const i of e.matrix)i.reverse()}}function Dl(t){return(e,i)=>{const r=e.matrix.length;if(i<0||i>=r){t.warn(`Row index ${i} is out of bounds, matrix has ${r} rows.`,"matrix.row");const a=r>0?be(e.matrix[0][0]):"float";return new D([],a,t)}const n=be(e.matrix[i][0]);return new D([...e.matrix[i]],n,t)}}function Ml(t){return e=>e.matrix.length}function Rl(t){return(e,i,r,n)=>{const a=e.matrix.length,s=a>0?e.matrix[0].length:0;if(i<0||i>=a){t.warn(`Row index ${i} is out of bounds, matrix has ${a} rows.`,"matrix.set");return}if(r<0||r>=s){t.warn(`Column index ${r} is out of bounds, matrix has ${s} columns.`,"matrix.set");return}e.matrix[i][r]=n}}function Vl(t){return(e,i=0,r="asc")=>{e.matrix.length!==0&&e.matrix.sort((n,a)=>{const s=n[i],o=a[i];return s<o?r==="asc"?-1:1:s>o?r==="asc"?1:-1:0})}}function Ol(t){return(e,i,r,n,a)=>{const s=r-i,o=a-n,l=new F(s,o,NaN,t);for(let c=0;c<s;c++){const h=i+c;if(h>=e.matrix.length)break;for(let p=0;p<o;p++){const u=n+p;if(u>=e.matrix[h].length)break;l.matrix[c][p]=e.matrix[h][u]}}return l}}function Ll(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new F(0,0,NaN,t);const n=e.matrix[0].length,a=new F(r,n,NaN,t);if(i instanceof F)for(let s=0;s<r;s++)for(let o=0;o<n;o++){const l=e.matrix[s][o],c=i.matrix[s]&&i.matrix[s][o]!==void 0?i.matrix[s][o]:NaN;a.matrix[s][o]=l+c}else{const s=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)a.matrix[o][l]=e.matrix[o][l]+s}return a}}function jl(t){return(e,i,r)=>{const n=e.matrix.length;for(let a=0;a<n;a++){const s=e.matrix[a][i];e.matrix[a][i]=e.matrix[a][r],e.matrix[a][r]=s}}}function Bl(t){return(e,i,r)=>{const n=e.matrix[i];e.matrix[i]=e.matrix[r],e.matrix[r]=n}}function Fl(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=Math.min(i,r);let a=0;for(let s=0;s<n;s++)a+=e.matrix[s][s];return a}}function $l(t){return e=>{const i=e.matrix.length;if(i===0)return new F(0,0,NaN,t);const r=e.matrix[0].length,n=new F(r,i,NaN,t);for(let a=0;a<i;a++)for(let s=0;s<r;s++)n.matrix[s][a]=e.matrix[a][s];return n}}class F{constructor(e=0,i=0,r=NaN,n){if(this.context=n,this.matrix=[],e>0&&i>0)for(let a=0;a<e;a++)this.matrix.push(Array(i).fill(r));this._add_col=Ko(this.context),this._add_row=Ho(this.context),this._avg=Go(this.context),this._col=Yo(this.context),this._columns=Xo(this.context),this._concat=Qo(this.context),this._copy=Zo(this.context),this._det=el(this.context),this._diff=tl(this.context),this._eigenvalues=rl(this.context),this._eigenvectors=nl(this.context),this._elements_count=sl(this.context),this._fill=al(this.context),this._get=ol(this.context),this._inv=ll(this.context),this._is_antidiagonal=cl(this.context),this._is_antisymmetric=hl(this.context),this._is_binary=ul(this.context),this._is_diagonal=pl(this.context),this._is_identity=fl(this.context),this._is_square=dl(this.context),this._is_stochastic=ml(this.context),this._is_symmetric=gl(this.context),this._is_triangular=yl(this.context),this._is_zero=xl(this.context),this._kron=_l(this.context),this._max=bl(this.context),this._median=wl(this.context),this._min=vl(this.context),this._mode=Sl(this.context),this._mult=El(this.context),this._pinv=Nl(this.context),this._pow=Cl(this.context),this._rank=Il(this.context),this._remove_col=kl(this.context),this._remove_row=Al(this.context),this._reshape=Tl(this.context),this._reverse=Pl(this.context),this._row=Dl(this.context),this._rows=Ml(this.context),this._set=Rl(this.context),this._sort=Vl(this.context),this._submatrix=Ol(this.context),this._sum=Ll(this.context),this._swap_columns=jl(this.context),this._swap_rows=Bl(this.context),this._trace=Fl(this.context),this._transpose=$l(this.context)}matrix;_add_col;_add_row;_avg;_col;_columns;_concat;_copy;_det;_diff;_eigenvalues;_eigenvectors;_elements_count;_fill;_get;_inv;_is_antidiagonal;_is_antisymmetric;_is_binary;_is_diagonal;_is_identity;_is_square;_is_stochastic;_is_symmetric;_is_triangular;_is_zero;_kron;_max;_median;_min;_mode;_mult;_pinv;_pow;_rank;_remove_col;_remove_row;_reshape;_reverse;_row;_rows;_set;_sort;_submatrix;_sum;_swap_columns;_swap_rows;_trace;_transpose;toString(){let e="";for(let i=0;i<this.matrix.length;i++)e+=e===""?"":`
|
|
121
|
+
`,e+="["+this.matrix[i].join(", ")+"]";return e}add_col(...e){return this._add_col(this,...e)}add_row(...e){return this._add_row(this,...e)}avg(...e){return this._avg(this,...e)}col(...e){return this._col(this,...e)}columns(...e){return this._columns(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}det(...e){return this._det(this,...e)}diff(...e){return this._diff(this,...e)}eigenvalues(...e){return this._eigenvalues(this,...e)}eigenvectors(...e){return this._eigenvectors(this,...e)}elements_count(...e){return this._elements_count(this,...e)}fill(...e){return this._fill(this,...e)}get(...e){return this._get(this,...e)}inv(...e){return this._inv(this,...e)}is_antidiagonal(...e){return this._is_antidiagonal(this,...e)}is_antisymmetric(...e){return this._is_antisymmetric(this,...e)}is_binary(...e){return this._is_binary(this,...e)}is_diagonal(...e){return this._is_diagonal(this,...e)}is_identity(...e){return this._is_identity(this,...e)}is_square(...e){return this._is_square(this,...e)}is_stochastic(...e){return this._is_stochastic(this,...e)}is_symmetric(...e){return this._is_symmetric(this,...e)}is_triangular(...e){return this._is_triangular(this,...e)}is_zero(...e){return this._is_zero(this,...e)}kron(...e){return this._kron(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}mult(...e){return this._mult(this,...e)}pinv(...e){return this._pinv(this,...e)}pow(...e){return this._pow(this,...e)}rank(...e){return this._rank(this,...e)}remove_col(...e){return this._remove_col(this,...e)}remove_row(...e){return this._remove_row(this,...e)}reshape(...e){return this._reshape(this,...e)}reverse(...e){return this._reverse(this,...e)}row(...e){return this._row(this,...e)}rows(...e){return this._rows(this,...e)}set(...e){return this._set(this,...e)}sort(...e){return this._sort(this,...e)}submatrix(...e){return this._submatrix(this,...e)}sum(...e){return this._sum(this,...e)}swap_columns(...e){return this._swap_columns(this,...e)}swap_rows(...e){return this._swap_rows(this,...e)}trace(...e){return this._trace(this,...e)}transpose(...e){return this._transpose(this,...e)}}function Se(t){return(e,i,r)=>new F(e,i,r,t)}function Wl(t){return(e,i=0)=>y.from(e).get(i)}class Ul{constructor(e){this.context=e,this.add_col=(i,...r)=>i.add_col(...r),this.add_row=(i,...r)=>i.add_row(...r),this.avg=(i,...r)=>i.avg(...r),this.col=(i,...r)=>i.col(...r),this.columns=(i,...r)=>i.columns(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.det=(i,...r)=>i.det(...r),this.diff=(i,...r)=>i.diff(...r),this.eigenvalues=(i,...r)=>i.eigenvalues(...r),this.eigenvectors=(i,...r)=>i.eigenvectors(...r),this.elements_count=(i,...r)=>i.elements_count(...r),this.fill=(i,...r)=>i.fill(...r),this.get=(i,...r)=>i.get(...r),this.inv=(i,...r)=>i.inv(...r),this.is_antidiagonal=(i,...r)=>i.is_antidiagonal(...r),this.is_antisymmetric=(i,...r)=>i.is_antisymmetric(...r),this.is_binary=(i,...r)=>i.is_binary(...r),this.is_diagonal=(i,...r)=>i.is_diagonal(...r),this.is_identity=(i,...r)=>i.is_identity(...r),this.is_square=(i,...r)=>i.is_square(...r),this.is_stochastic=(i,...r)=>i.is_stochastic(...r),this.is_symmetric=(i,...r)=>i.is_symmetric(...r),this.is_triangular=(i,...r)=>i.is_triangular(...r),this.is_zero=(i,...r)=>i.is_zero(...r),this.kron=(i,...r)=>i.kron(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.mult=(i,...r)=>i.mult(...r),this.new=Se(e),this.param=Wl(),this.pinv=(i,...r)=>i.pinv(...r),this.pow=(i,...r)=>i.pow(...r),this.rank=(i,...r)=>i.rank(...r),this.remove_col=(i,...r)=>i.remove_col(...r),this.remove_row=(i,...r)=>i.remove_row(...r),this.reshape=(i,...r)=>i.reshape(...r),this.reverse=(i,...r)=>i.reverse(...r),this.row=(i,...r)=>i.row(...r),this.rows=(i,...r)=>i.rows(...r),this.set=(i,...r)=>i.set(...r),this.sort=(i,...r)=>i.sort(...r),this.submatrix=(i,...r)=>i.submatrix(...r),this.sum=(i,...r)=>i.sum(...r),this.swap_columns=(i,...r)=>i.swap_columns(...r),this.swap_rows=(i,...r)=>i.swap_rows(...r),this.trace=(i,...r)=>i.trace(...r),this.transpose=(i,...r)=>i.transpose(...r),this.new_float=Se(e),this.new_int=Se(e),this.new_string=Se(e),this.new_bool=Se(e),this.new_color=Se(e),this.new_line=Se(e),this.new_label=Se(e),this.new_box=Se(e),this.new_linefill=Se(e),this.new_table=Se(e)}}class ql{constructor(e){this.context=e}_live=!1;setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){const e=this.context.idx,i=this.context.length;if(e===i-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===i-2){const r=this.context.marketData?.[i-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}}class ht{constructor(e,i){this._definition=e,this.context=i;for(let r in e)this[r]=e[r]}get __def__(){return this._definition}copy(){return new ht(this.__def__,this.context)}toString(){const e={};for(let i in this.__def__){const r=this[i];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[i]=r.toString():e[i]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(i=>`"${i}":${String(e[i])}`).join(",")+"}"}}}class se{time;index;price;constructor(e,i,r){this.time=e,this.index=i,this.price=r}copy(){return new se(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}}function zl(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}const ar={series:t=>t instanceof y||typeof t=="number"||typeof t=="string"||typeof t=="boolean",string:t=>typeof t=="string",color:t=>typeof t=="string"||t===null||typeof t=="number"&&isNaN(t)||t instanceof y,number:t=>typeof t=="number",boolean:t=>typeof t=="boolean",array:t=>Array.isArray(t),object:t=>typeof t=="object",point:t=>t instanceof se,primitive:t=>typeof t===null||typeof t!="object"&&typeof t!="function",function:t=>typeof t=="function",undefined:t=>t===void 0,null:t=>t===null,NaN:t=>isNaN(t),remaining_options:t=>t!==null&&typeof t=="object"&&!(t instanceof y)&&!(t instanceof se)&&!zl(t)};function ke(t){const e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function X(t,e,i,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);const n={};let a={};const s=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){const l=t[o];if(ar.remaining_options(l)){a=l;break}const c=e.map((h,p)=>s[p]?h[o]:void 0);for(let h=0;h<c.length;h++){const p=c[h];if(p===void 0){s[h]=!1;continue}const u=i[p];if(typeof l=="number"&&isNaN(l)&&(u==="number"||u==="series"))n[p]=l;else{const f=ar[i[p]];typeof f=="function"&&f(l)?n[p]=l:s[h]=!1}}}return{...n,...a,...r}}const Kl=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Hl={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Gl=["title","shorttitle","overlay","format","precision","scale","max_bars_back","timeframe","timeframe_gaps","explicit_plot_zorder","max_lines_count","max_labels_count","max_boxes_count","calc_bars_count","max_polylines_count","dynamic_requests","behind_chart"],Yl={title:"string",shorttitle:"string",overlay:"boolean",format:"string",precision:"number",scale:"string",max_bars_back:"number",timeframe:"string",timeframe_gaps:"boolean",explicit_plot_zorder:"boolean",max_lines_count:"number",max_labels_count:"number",max_boxes_count:"number",calc_bars_count:"number",max_polylines_count:"number",dynamic_requests:"boolean",behind_chart:"boolean"};function Xl(t){return X(t,Gl,Yl)}class _t{get __value(){return NaN}param(e,i=0){return y.from(e).get(i)}any(e){const i=y.from(e).get(0);return i==null?!0:typeof i=="number"?i!==i:!1}}const ot={freq_all:"alert.freq_all",freq_once_per_bar:"alert.freq_once_per_bar",freq_once_per_bar_close:"alert.freq_once_per_bar_close"};class Ql{constructor(e){this.context=e}_firedKeys=new Set;_fallbackCounter=0;_fallbackLastExecTick=-1;get freq_all(){return ot.freq_all}get freq_once_per_bar(){return ot.freq_once_per_bar}get freq_once_per_bar_close(){return ot.freq_once_per_bar_close}param(e,i,r){return y.from(e).get(0)}any(e,i,r){const n=y.from(e).get(0),a=i?y.from(i).get(0):ot.freq_once_per_bar;let s;if(r&&typeof r=="object"&&r.__callsiteId)s=r.__callsiteId;else{const h=this.context._execTick||0;h!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=h),s=`alert_${this._fallbackCounter++}`}const o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${s}:${o}`;if(a===ot.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(a===ot.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(c))return;this._firedKeys.add(c)}this.context.alerts.push({type:"alert",id:s,message:n,freq:a,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}}class Zl{constructor(e){this.context=e}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}indicator(...e){const i=Xl(e),r={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...r,...i},this.context.indicator}get bar_index(){return this.context.idx}na(e){const i=y.from(e).get(0);return i==null||typeof i=="number"&&isNaN(i)}nz(e,i=0){const r=y.from(e).get(0),n=y.from(i).get(0);return r==null||typeof r=="number"&&isNaN(r)?n:r}fixnan(e){const i=y.from(e);for(let r=0;r<i.length;r++){const n=i.get(r);if(!isNaN(n))return n}return NaN}_acCounter=0;_acLastExecTick=-1;_acFiredKeys=new Set;alertcondition(e,i,r){const n=y.from(e).get(0),a=this.context.idx,s=this.context._execTick||0;s!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=s);const o=`alertcondition_${this._acCounter++}`;if(!n)return;const l=this.context.pine?.barstate?.isrealtime??a===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${o}:${a}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);const h=i?y.from(i).get(0):"",p=r?y.from(r).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:h,message:p,bar_index:a,time:this.context.data.openTime?.data?.[a]??0})}error(...e){console.error("error called but is currently not implemented",e)}max_bars_back(e,i){}timestamp(...e){const i=e.map(n=>n instanceof y?n.get(0):n),r=X(i,Kl,Hl);if(r.year!==void 0){const n=r.year,a=r.month,s=r.day,o=r.hour||0,l=r.minute||0,c=r.second||0,h=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(h,n,a,s,o,l,c)}if(r.dateString!==void 0){const n=r.dateString.trim();if(/[Zz]$/.test(n)||/[+-]\d{2}:?\d{2}$/.test(n))return new Date(n).getTime();const a=n.includes("T")?n+"Z":n.replace(/\s+/,"T")+"Z",s=new Date(a);if(!isNaN(s.getTime())){const o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,s.getUTCFullYear(),s.getUTCMonth()+1,s.getUTCDate(),s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds())}return new Date(n).getTime()}return NaN}_timestampFromComponents(e,i,r,n,a,s,o){const l=new Date(Date.UTC(i,r-1,n,a,s,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();const h=c.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(h){const p=h[1]==="+"?1:-1,u=parseInt(h[2],10),f=parseInt(h[3]||"0",10),m=p*(u*60+f)*60*1e3;return l.getTime()-m}try{return this._timestampFromIANA(e,i,r,n,a,s,o)}catch{return l.getTime()}}_timestampFromIANA(e,i,r,n,a,s,o){const l=new Date(Date.UTC(i,r-1,n,a,s,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),h=w=>parseInt(c.find(E=>E.type===w)?.value||"0",10),p=h("year"),u=h("month"),f=h("day");let m=h("hour");m===24&&(m=0);const x=h("minute"),_=h("second"),b=new Date(Date.UTC(p,u-1,f,m,x,_));p>=0&&p<100&&b.setUTCFullYear(p);const v=b.getTime()-l.getTime();return l.getTime()-v}bool(e){const i=y.from(e).get(0);return!isNaN(i)&&i!==0}int(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "int" with argument "x"="${i}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(i)}float(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "float" with argument "x"="${i}". An argument of "literal string" type was used but a "const float" is expected.`);return i}string(e){return y.from(e).get(0).toString()}Type(e){const i=Object.keys(e),r={};for(const n of i){let a=e[n];a instanceof y&&(a=a.data),Array.isArray(a)&&(a[0],r[n]=a[1])}return{new:function(...n){const a={};let s=null;if(n.length===1&&n[0]&&typeof n[0]=="object"&&!(n[0]instanceof y)&&!Array.isArray(n[0])&&!(n[0]instanceof ht)){const o=Object.keys(n[0]);o.length>0&&o.some(l=>i.includes(l))&&(s=n[0],n=[])}for(let o=0;o<i.length;o++){const l=i[o];s&&l in s?a[l]=s[l]:o<n.length?a[l]=n[o]:l in r&&(a[l]=y.from(r[l]).get(0))}return new ht(a,this.context)},copy:function(n){return new ht(n.__def__,this.context)}}}}function lt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){const i=t.slice(1);return i.length===6?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),1]:i.length===8?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),parseInt(i.slice(6,8),16)/255]:null}const e=t.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function Jl(t,e,i,r){const n=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),s=Math.round(Math.max(0,Math.min(255,i))).toString(16).padStart(2,"0");if(r>=1)return`#${n}${a}${s}`.toUpperCase();const o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${n}${a}${s}${o}`.toUpperCase()}const Y={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:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function Ie(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}class ec{constructor(e){this.context=e}any(e){const i=y.from(e).get(0);return typeof i=="number"&&isNaN(i)?null:i}param(e,i=0){return y.from(e).get(i)}new(e,i){if(e=Ie(e),!e||typeof e!="string")return e;if(typeof i=="number"&&isNaN(i)&&(i=void 0),e.startsWith("#")){const r=e.slice(1),n=r.length===8?r.slice(0,6):r;return i!=null?`#${n}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:`#${r}`}else{const r=Y[e];if(r)return i!=null?`#${r.slice(1)}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:r;const n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);if(n){const a=n[1],s=n[2],o=n[3];if(i!=null){const l=parseInt(a).toString(16).padStart(2,"0"),c=parseInt(s).toString(16).padStart(2,"0"),h=parseInt(o).toString(16).padStart(2,"0"),p=Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${h}${p}`}return e}return i!=null?`rgba(${e}, ${(100-i)/100})`:e}}rgb(e,i,r,n){return typeof n=="number"&&isNaN(n)&&(n=void 0),n!=null?`rgba(${e}, ${i}, ${r}, ${(100-n)/100})`:`rgb(${e}, ${i}, ${r})`}from_gradient(e,i,r,n,a){if(e=Ie(e),i=Ie(i),r=Ie(r),n=Ie(n),a=Ie(a),e==null||typeof e=="number"&&isNaN(e)||i==null||typeof i=="number"&&isNaN(i)||r==null||typeof r=="number"&&isNaN(r)||n==null||typeof n=="number"&&isNaN(n)||a==null||typeof a=="number"&&isNaN(a))return;let s=0;r!==i&&(s=(e-i)/(r-i)),s=Math.max(0,Math.min(1,s));const o=lt(typeof n=="string"?n:"#000000")||[0,0,0,1],l=lt(typeof a=="string"?a:"#FFFFFF")||[255,255,255,1],c=o[0]+(l[0]-o[0])*s,h=o[1]+(l[1]-o[1])*s,p=o[2]+(l[2]-o[2])*s,u=o[3]+(l[3]-o[3])*s;return Jl(c,h,p,u)}r(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?i[0]:NaN}g(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?i[1]:NaN}b(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?i[2]:NaN}t(e){if(e=Ie(e),!e||typeof e!="string")return NaN;const i=lt(e);return i?Math.round(100-i[3]*100):NaN}aqua(){return Y.aqua}black(){return Y.black}blue(){return Y.blue}fuchsia(){return Y.fuchsia}gray(){return Y.gray}green(){return Y.green}lime(){return Y.lime}maroon(){return Y.maroon}navy(){return Y.navy}olive(){return Y.olive}orange(){return Y.orange}purple(){return Y.purple}red(){return Y.red}silver(){return Y.silver}teal(){return Y.teal}white(){return Y.white}yellow(){return Y.yellow}}function dt(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC"){const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const n=r[1]==="+"?1:-1,a=parseInt(r[2],10),s=parseInt(r[3]||"0",10),o=n*(a*60+s)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{const n=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),a=c=>parseInt(n.find(h=>h.type===c)?.value||"0",10);let s=a("hour");s===24&&(s=0);const o=n.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:a("year"),month:a("month"),day:a("day"),hour:s,minute:a("minute"),second:a("second"),dayOfWeek:l[o]??0}}catch{const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}}function tc(t,e,i){const r=new Date(Date.UTC(t,e-1,i)),n=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-n);const a=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-a.getTime())/864e5+1)/7)}const ic=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],rc={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"};class or{context;dataField;constructor(e,i="openTime"){this.context=e,this.dataField=i}get __value(){return this.context.data[this.dataField]}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(c=>c instanceof y?c.get(0):c),r=X(i,ic,rc),n=r.bars_back??0,a=r.timeframe_bars_back??0,s=n+a,o=this.context.data[this.dataField],l=y.from(o).get(s);if(r.session!==void 0){const c=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(l,r.session,c)?l:NaN}return l}_isInSession(e,i,r){const n=i.match(/^(\d{2})(\d{2})-(\d{2})(\d{2})$/);if(!n)return!0;const a=parseInt(n[1],10),s=parseInt(n[2],10),o=parseInt(n[3],10),l=parseInt(n[4],10),c=dt(e,r),h=c.hour,p=c.minute,u=h*60+p,f=a*60+s,m=o*60+l;return f<=m?u>=f&&u<m:u>=f||u<m}}const nc=[[],["time"],["time","timezone"]],sc={time:"number",timezone:"string"};class We{context;extractor;constructor(e,i){this.context=e,this.extractor=i}get __value(){const e=y.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;const i=this.context.pine?.syminfo?.timezone||"UTC",r=dt(e,i);return this.extractor(r)}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(o=>o instanceof y?o.get(0):o);if(i.length===0)return this.__value;const r=X(i,nc,sc),n=r.time;if(n===void 0||isNaN(n))return NaN;const a=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",s=dt(n,a);return this.extractor(s)}}const Ue={dayofmonth:t=>t.day,dayofweek:t=>t.dayOfWeek===0?1:t.dayOfWeek+1,hour:t=>t.hour,minute:t=>t.minute,month:t=>t.month,second:t=>t.second,weekofyear:t=>tc(t.year,t.month,t.day),year:t=>t.year},ac=[["defval","title","tooltip","inline","group","display"],["defval","title","tooltip","group","confirm","display"],["defval","title","tooltip","inline","group","confirm","display"],["defval","title","options","tooltip","inline","group","confirm","display"],["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display"]],oc={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function he(t){return X(t,ac,oc)}function pe(t,e){return e.title&&t.inputs&&t.inputs[e.title]!==void 0?t.inputs[e.title]:e.defval}function lc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function cc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function hc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function uc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function pc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function fc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function dc(t){return(e,i=0)=>y.from(e).get(i)}function mc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function gc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function yc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function xc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function _c(t){return(...e)=>{const i=he(e);return pe(t,i)}}function bc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function wc(t){return(...e)=>{const i=he(e);return pe(t,i)}}function vc(t){return(...e)=>he(e).defval}const Sc={any:lc,bool:cc,color:hc,enum:uc,float:pc,int:fc,param:dc,price:mc,session:gc,source:yc,string:xc,symbol:_c,text_area:bc,time:wc,timeframe:vc};class Ec{constructor(e){this.context=e,Object.entries(Sc).forEach(([i,r])=>{this[i]=r(e)})}any;bool;color;enum;float;int;param;price;session;source;string;symbol;text_area;time;timeframe}function Nc(t){return e=>Math.abs(y.from(e).get(0))}function Cc(t){return e=>Math.acos(y.from(e).get(0))}function Ic(t){return e=>Math.asin(y.from(e).get(0))}function kc(t){return e=>Math.atan(y.from(e).get(0))}function Ac(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return i.reduce((r,n)=>r+n,0)/i.length}}function Tc(t){return e=>Math.ceil(y.from(e).get(0))}function Pc(t){return e=>Math.cos(y.from(e).get(0))}function Dc(t){return()=>Math.E}function Mc(t){return e=>Math.exp(y.from(e).get(0))}function Rc(t){return e=>Math.floor(y.from(e).get(0))}function Vc(t){return e=>Math.log(y.from(e).get(0))}function Oc(t){return e=>Math.log(y.from(e).get(0))}function Lc(t){return e=>Math.log10(y.from(e).get(0))}function jc(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.max(...i)}}function Bc(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.min(...i)}}function Fc(t){return(e,i,r)=>typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function $c(t){return()=>1.618033988749895}function Wc(t){return()=>Math.PI}function Uc(t){return(e,i)=>Math.pow(y.from(e).get(0),y.from(i).get(0))}function qc(t){return()=>Math.random()}function si(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function zc(t){return(e,i)=>{const r=y.from(e).get(0);if(i==null)return si(r);const n=y.from(i).get(0);if(n===0)return si(r);const a=Math.pow(10,n);return si(r*a)/a}}function Kc(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Hc(t){return()=>.6180339887498948}function Gc(t){return e=>Math.sign(y.from(e).get(0))}function Yc(t){return e=>Math.sin(y.from(e).get(0))}function Xc(t){return e=>Math.sqrt(y.from(e).get(0))}function Qc(t){return(e,i)=>{const r=y.from(i).get(0),n=y.from(e);let a=0;for(let s=0;s<r;s++){const o=n.get(s);a+=o}return a}}function Zc(t){return e=>Math.tan(y.from(e).get(0))}function Jc(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(180/Math.PI)}}function eh(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(Math.PI/180)}}function th(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)<1e-9:r===n}}function ih(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)>=1e-9:r!==n}}const rh={abs:Nc,acos:Cc,asin:Ic,atan:kc,avg:Ac,ceil:Tc,cos:Pc,e:Dc,exp:Mc,floor:Rc,ln:Vc,log:Oc,log10:Lc,max:jc,min:Bc,param:Fc,phi:$c,pi:Wc,pow:Uc,random:qc,round:zc,round_to_mintick:Kc,rphi:Hc,sign:Gc,sin:Yc,sqrt:Xc,sum:Qc,tan:Zc,todegrees:Jc,toradians:eh,__eq:th,__neq:ih};class nh{constructor(e){this.context=e,Object.entries(rh).forEach(([i,r])=>{this[i]=r(e)})}_cache={};abs;acos;asin;atan;avg;ceil;cos;e;exp;floor;ln;log;log10;max;min;param;phi;pi;pow;random;round;round_to_mintick;rphi;sign;sin;sqrt;sum;tan;todegrees;toradians;__eq;__neq}function sh(t){return(e,i,r)=>{t.params[r]||(t.params[r]=[]);let n;if(e instanceof y)n=e.get(i||0);else if(Array.isArray(e)){const a=e.some(o=>o instanceof y),s=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(a||s)&&e.length>=1?n=e.map(o=>o instanceof y?o.get(0):o):n=y.from(e).get(i||0)}else n=e;return t.params[r].length===0?t.params[r].push(n):t.params[r][t.params[r].length-1]=n,[n,r]}}const mt=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Rt={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function Ut(t){if(mt.includes(t))return t;if(Rt[t])return Rt[t];const e=t.toLowerCase();if(Rt[e])return Rt[e];const i=t.toUpperCase();return mt.includes(i)?i:t}function lr(t,e,i,r,n=!1,a=!1){for(let s=0;s<i.length;s++)if(i[s]<=t&&t<r[s])return n||a||e>=r[s]?s:s-1;return-1}function cr(t,e,i,r,n=!1,a,s=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=e&&i[o]>=t){const l=a&&e>a;if(s&&n)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}if(l&&n&&!s)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}return o}if(r[o]<t)break}return-1}function xi(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(xi):t}function ah(t){return async(e,i,r,n=!1,a=!1,s=!1,o=null,l=null)=>{const c=e[0]instanceof y?e[0].get(0):e[0],h=c===""?t.tickerId:c,p=typeof h=="string"&&h.includes(":")?h.split(":")[1]:h,u=i[0]instanceof y?i[0].get(0):i[0],f=u===""?t.timeframe:typeof u=="string"?u:String(u??""),m=r[0],x=r[1],_=Array.isArray(n)?n[0]:n,b=Array.isArray(a)?a[0]:a,v=_===!0||_==="gaps_on",w=b===!0||b==="lookahead_on";if(t.isSecondaryContext){const ue=xi(m);return Array.isArray(ue)?[ue]:ue}const E=mt.indexOf(Ut(t.timeframe)),A=mt.indexOf(Ut(f));if(E==-1||A==-1)throw new Error("Invalid timeframe");if(E===A){const ue=xi(m);return Array.isArray(ue)?[ue]:ue}const C=E>A,M=y.from(t.data.openTime).get(0),O=y.from(t.data.closeTime).get(0),$=t.idx===t.length-1&&O>Date.now(),B=`${p}_${f}_${x}`,R=`${B}_prevIdx`;if(t.cache[B]){const ue=t.cache[B];t.dataVersion>ue.dataVersion&&(await ue.pineTS.updateTail(ue.context),ue.dataVersion=t.dataVersion);const bt=ue.context,Pt=C?cr(M,O,bt.data.openTime.data,bt.data.closeTime.data,w,t.eDate,v):lr(M,O,bt.data.openTime.data,bt.data.closeTime.data,w,$);if(Pt==-1)return NaN;const nt=bt.params[x][Pt];if(!C&&v){const Li=t.cache[R];return Li!==void 0&&Li===Pt?NaN:(t.cache[R]=Pt,Array.isArray(nt)?[nt]:nt)}return Array.isArray(nt)?[nt]:nt}const q=1e3*60*60*24*30,re=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),fe=re?re-q:void 0,de=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,me=t.eDate?Math.max(t.eDate,de):(de||Date.now())+q,Ge=new Vi(t.source,p,f,void 0,fe,me);Ge.markAsSecondary();const ee=await Ge.run(t.pineTSCode);t.cache[B]={pineTS:Ge,context:ee,dataVersion:t.dataVersion};const Zt=C?cr(M,O,ee.data.openTime.data,ee.data.closeTime.data,w,t.eDate,v):lr(M,O,ee.data.openTime.data,ee.data.closeTime.data,w,$);if(Zt==-1)return NaN;const Jt=ee.params[x][Zt];return!C&&v?(t.cache[R]=Zt,NaN):Array.isArray(Jt)?[Jt]:Jt}}function ct(t){return typeof t=="number"?T.float:typeof t=="boolean"?T.bool:typeof t=="string"?T.string:T.any}function oh(t){return async(e,i,r,n=!1,a=null,s=!1,o=0)=>{const l=e[0]instanceof y?e[0].get(0):e[0],c=l===""?t.tickerId:l,h=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,p=i[0]instanceof y?i[0].get(0):i[0],u=p===""?t.timeframe:typeof p=="string"?p:String(p??""),f=r[0],m=r[1];Array.isArray(n)&&n[0];const x=Array.isArray(s)?s[0]:s;if(t.isSecondaryContext)return Array.isArray(f)?[f.map(R=>new D([R],ct(R),t))]:new D([f],ct(f),t);const _=mt.indexOf(Ut(t.timeframe)),b=mt.indexOf(Ut(u));if(_===-1||b===-1){if(x)return NaN;throw new Error("Invalid timeframe")}if(b>_){if(x)return NaN;throw new Error(`Timeframe ${u} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(b===_)return Array.isArray(f)?[f.map(R=>new D([R],ct(R),t))]:new D([f],ct(f),t);const v=`${h}_${u}_${m}_lower`;if(!t.cache[v]){const R=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),q=R?R-2592e6:void 0,re=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,fe=t.eDate?Math.max(t.eDate,re):(re||Date.now())+2592e6,de=new Vi(t.source,h,u,void 0,q,fe);de.markAsSecondary();const me=await de.run(t.pineTSCode);t.cache[v]={pineTS:de,context:me,dataVersion:t.dataVersion}}const w=t.cache[v];t.dataVersion>w.dataVersion&&(await w.pineTS.updateTail(w.context),w.dataVersion=t.dataVersion);const E=w.context,A=y.from(t.data.openTime).get(0),C=y.from(t.data.closeTime).get(0),M=E.data.openTime.data,O=E.data.closeTime.data,$=E.params[m];if(!$)return Array.isArray(f)?[f.map(()=>new D([],T.float,t))]:new D([],T.float,t);const B=[];for(let R=0;R<M.length;R++){const q=M[R];if(!(O[R]<=A)){if(q>=C)break;q>=A&&q<C&&B.push($[R])}}if(B.length>0&&Array.isArray(B[0])){const R=B[0].length,q=[];for(let re=0;re<R;re++){const fe=B.map(me=>me[re]),de=fe.length>0?ct(fe[0]):T.float;q.push(new D(fe,de,t))}return[q]}else{const R=B.length>0?ct(B[0]):T.float;return new D(B,R,t)}}}const lh={param:sh,security:ah,security_lower_tf:oh};class ch{constructor(e){this.context=e,Object.entries(lh).forEach(([i,r])=>{this[i]=r(e)})}_cache={};param;security;security_lower_tf}function hh(t){return e=>{t.taState||(t.taState={});const i=e||"accdist";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.high,0),s=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(n)||isNaN(a)||isNaN(s)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);const l=a-s;let c=0;l!==0&&(c=(n-s-(a-n))/l*o);const h=r.prevCumulativeSum+c;return r.currentCumulativeSum=h,t.precision(h)}}function uh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0);t.taState||(t.taState={});const c=a||`alma_${s}_${o}_${l}`;if(!t.taState[c]){const x=o*(s-1),_=s/l,b=[];let v=0;for(let w=0;w<s;w++){const E=Math.exp(-Math.pow(w-x,2)/(2*_*_));b.push(E),v+=E}for(let w=0;w<b.length;w++)b[w]/=v;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevWindow=[...h.currentWindow],h.prevCallCount=h.currentCallCount),h.lastIdx=t.idx);const p=y.from(e).get(0),u=[...h.prevWindow];for(u.unshift(p);u.length>s;)u.pop();const f=h.prevCallCount+1;if(u.length<s&&(f>=s||t.idx>=s-1)){const x=y.from(e);for(;u.length<s;)u.push(x.get(u.length))}if(h.currentWindow=u,h.currentCallCount=f,u.length<s)return NaN;let m=0;for(let x=0;x<s;x++)m+=h.weights[x]*u[s-1-x];return t.precision(m)}}function ph(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`atr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});const a=t.taState[n];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevAtr=a.currentAtr,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);const s=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(s)||isNaN(o)||isNaN(l))return NaN;const c=t.idx>0?t.get(t.data.close,1):null;let h;if(c!==null&&!isNaN(c)){const x=s-o,_=Math.abs(s-c),b=Math.abs(o-c);h=Math.max(x,_,b)}else h=s-o;let p=a.prevInitCount,u=a.prevInitSum,f=a.prevAtr;if(p<r){if(u+=h,p++,a.currentInitSum=u,a.currentInitCount=p,p===r){const x=u/r;return a.currentAtr=x,t.precision(x)}return NaN}const m=(f*(r-1)+h)/r;return a.currentAtr=m,t.precision(m)}}function fh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevLastTrueIndex=n.currentLastTrueIndex),n.lastIdx=t.idx);const a=y.from(e).get(0);let s=n.prevLastTrueIndex;return a&&(s=t.idx),n.currentLastTrueIndex=s,s===null?NaN:t.idx-s}}function dh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bb_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}if(h.length<a&&t.idx>=a-1){const b=y.from(e);for(;h.length<a;){const v=b.get(h.length);if(isNaN(v))break;h.push(v),p+=v}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return[[NaN,NaN,NaN]];const u=p/a;let f=0;for(let b=0;b<a;b++)f+=Math.pow(h[b]-u,2);const m=Math.sqrt(f/a),x=u+s*m,_=u-s*m;return[[t.precision(u),t.precision(x),t.precision(_)]]}}function mh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bbw_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const v=h.pop();p-=v}if(h.length<a&&t.idx>=a-1){const v=y.from(e);for(;h.length<a;){const w=v.get(h.length);if(isNaN(w))break;h.push(w),p+=w}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return NaN;const u=p/a;let f=0;for(let v=0;v<a;v++){const w=h[v]-u;f+=w*w}const m=f/a,x=Math.sqrt(m),_=s*x;if(u===0)return t.precision(0);const b=2*_/u*100;return t.precision(b)}}function gh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`cci_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0);if(isNaN(o))return NaN;const l=[...s.prevWindow];let c=s.prevSum;for(l.unshift(o),c+=o;l.length>n;){const x=l.pop();c-=x}const h=s.prevCallCount+1;if(l.length<n&&(h>=n||t.idx>=n-1)){const x=y.from(e);for(;l.length<n;){const _=x.get(l.length);if(isNaN(_))break;l.push(_),c+=_}}if(s.currentWindow=l,s.currentSum=c,s.currentCallCount=h,l.length<n)return NaN;const p=c/n;let u=0;for(let x=0;x<n;x++)u+=Math.abs(l[x]-p);const f=u/n;if(f===0)return 0;const m=(o-p)/(.015*f);return t.precision(m)}}function yh(t){return(e,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`change_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=s.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const p=y.from(e);for(;l.length<n+1;)l.push(p.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<=n)return NaN;const h=o-l[n];return t.precision(h)}}function xh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`cmo_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevGainsWindow=[...s.currentGainsWindow],s.prevLossesWindow=[...s.currentLossesWindow],s.prevGainsSum=s.currentGainsSum,s.prevLossesSum=s.currentLossesSum),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;const c=o-l,h=c>=0?c:0,p=c>=0?0:-c,u=[...s.prevGainsWindow],f=[...s.prevLossesWindow];let m=s.prevGainsSum,x=s.prevLossesSum;if(u.unshift(h),f.unshift(p),m+=h,x+=p,u.length<n)return s.currentGainsWindow=u,s.currentLossesWindow=f,s.currentGainsSum=m,s.currentLossesSum=x,NaN;if(u.length>n){const v=u.pop(),w=f.pop();m-=v,x-=w}s.currentGainsWindow=u,s.currentLossesWindow=f,s.currentGainsSum=m,s.currentLossesSum=x;const _=m+x;if(_===0)return t.precision(0);const b=100*(m-x)/_;return t.precision(b)}}function _h(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);let s=0,o=!1;for(let h=0;h<n;h++){const p=a.get(h);if(isNaN(p)){o=!0;break}s+=p}if(o)return NaN;let l=0;for(let h=0;h<n;h++){const p=a.get(h);l+=p*(h+1)}if(s===0)return NaN;const c=-l/s;return t.precision(c)}}function bh(t){return(e,i,r,n)=>{const a=y.from(r).get(0),s=y.from(e),o=y.from(i);if(t.idx<a-1)return NaN;let l=0,c=0,h=0,p=0,u=0,f=0;for(let v=0;v<a;v++){const w=s.get(v),E=o.get(v);isNaN(w)||isNaN(E)||(l+=w,c+=E,h+=w*E,p+=w*w,u+=E*E,f++)}if(f<2)return NaN;const m=f*h-l*c,x=f*p-l*l,_=f*u-c*c;if(x<=0||_<=0)return t.precision(0);const b=m/Math.sqrt(x*_);return t.precision(b)}}function wh(t){return(e,i,r)=>{const n=y.from(e),a=y.from(i),s=n.get(0),o=a.get(0),l=n.get(1),c=a.get(1);if(isNaN(s)||isNaN(o)||isNaN(l)||isNaN(c))return!1;const h=s>o&&l<=c,p=s<o&&l>=c;return h||p}}function vh(t){return(e,i)=>{const r=y.from(e),n=y.from(i),a=r.get(0),s=n.get(0),o=r.get(1),l=n.get(1);return o<=l&&a>s}}function Sh(t){return(e,i)=>{const r=y.from(e),n=y.from(i),a=r.get(0),s=n.get(0),o=r.get(1),l=n.get(1);return o>=l&&a<s}}function Eh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);const a=y.from(e).get(0);if(isNaN(a))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);const s=n.prevCumulativeSum+a;return n.currentCumulativeSum=s,t.precision(s)}}function Nh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`dev_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0)||0,l=[...s.prevWindow];let c=s.prevSum;for(l.unshift(o),c+=o;l.length>n;){const m=l.pop();c-=m}const h=s.prevCallCount+1;if(l.length<n&&(h>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;){const x=m.get(l.length);l.push(x),c+=x}}if(s.currentWindow=l,s.currentSum=c,s.currentCallCount=h,l.length<n)return NaN;const p=c/n;let u=0;for(let m=0;m<n;m++)u+=Math.abs(l[m]-p);const f=u/n;return t.precision(f)}}function Ch(t){return(e,i,r)=>{const n=y.from(e).get(0),a=y.from(i).get(0);t.taState||(t.taState={});const s=r||`dmi_${n}_${a}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});const o=t.taState[s];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN,NaN]];const p=t.idx>0?t.get(t.data.high,1):NaN,u=t.idx>0?t.get(t.data.low,1):NaN,f=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];const m=Math.max(l-c,Math.abs(l-f),Math.abs(c-f)),x=l-p,_=u-c,b=x>_&&x>0?x:0,v=_>x&&_>0?_:0;let w=o.prevInitCount,E=o.prevTrInitSum,A=o.prevPlusInitSum,C=o.prevMinusInitSum,M=o.prevSmoothedTR,O=o.prevSmoothedPlus,$=o.prevSmoothedMinus;if(w++,w<=n)E+=m,A+=b,C+=v,w===n&&(M=E/n,O=A/n,$=C/n);else{const ee=1/n;M=ee*m+(1-ee)*M,O=ee*b+(1-ee)*O,$=ee*v+(1-ee)*$}if(o.currentInitCount=w,o.currentTrInitSum=E,o.currentPlusInitSum=A,o.currentMinusInitSum=C,o.currentSmoothedTR=M,o.currentSmoothedPlus=O,o.currentSmoothedMinus=$,w<n)return[[NaN,NaN,NaN]];const B=M===0?0:100*O/M,R=M===0?0:100*$/M,q=B+R,re=q===0?0:100*Math.abs(B-R)/q;let fe=o.prevAdxInitCount,de=o.prevDxInitSum,me=o.prevADX,Ge=NaN;if(fe++,fe<=a)de+=re,fe===a&&(me=de/a,Ge=me);else{const ee=1/a;me=ee*re+(1-ee)*me,Ge=me}return o.currentAdxInitCount=fe,o.currentDxInitSum=de,o.currentADX=me,[[t.precision(B),t.precision(R),t.precision(Ge)]]}}function Ih(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`ema_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevEma=s.currentEma,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);const o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=s.prevInitCount,c=s.prevInitSum,h=s.prevEma;if(l<n){if(c+=o,l++,s.currentInitSum=c,s.currentInitCount=l,l===n){const f=c/n;return s.currentEma=f,t.precision(f)}return NaN}const p=2/(n+1),u=o*p+h*(1-p);return s.currentEma=u,t.precision(u)}}function kh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);for(let s=0;s<n;s++){const o=a.get(s),l=a.get(s+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Ah(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.high);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`highest_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const u=y.from(e);for(;l.length<n;)l.push(u.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.max(...h);return t.precision(p)}}function Th(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;let s=-1/0,o=NaN;for(let l=0;l<n;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c>s)&&(s=c,o=-l)}return o}}function Ph(t){return(e,i,r)=>{const n=y.from(i).get(0),a=Math.floor(n/2),s=Math.floor(Math.sqrt(n)),o=t.pine.ta.wma,l=o(e,a,r?`${r}_wma1`:void 0),c=o(e,n,r?`${r}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});const h=r||`hma_raw_${n}`;t.taState[h]||(t.taState[h]={lastIdx:-1,prevValues:[],currentValues:[]});const p=t.taState[h];t.idx>p.lastIdx&&(p.lastIdx>=0&&(p.prevValues=[...p.currentValues]),p.lastIdx=t.idx);const u=2*l-c,f=[...p.prevValues];f.unshift(u),f.length>s+1&&f.pop(),p.currentValues=f;const m=r?`${r}_hma_final`:`hma_final_${n}`;t.taState[m]||(t.taState[m]={lastIdx:-1,prevWindow:[],currentWindow:[]});const x=t.taState[m];t.idx>x.lastIdx&&(x.lastIdx>=0&&(x.prevWindow=[...x.currentWindow]),x.lastIdx=t.idx);const _=[...x.prevWindow];if(_.unshift(u),_.length<s)return x.currentWindow=_,NaN;for(;_.length>s;)_.pop();x.currentWindow=_;let b=0,v=0;for(let E=0;E<s;E++){const A=s-E;b+=_[E]*A,v+=A}const w=b/v;return t.precision(w)}}function Dh(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.high,0),n=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(a))return NaN;const s=(r-n)*a;if(s===0)return t.precision(0);const o=(2*i-r-n)/s;return t.precision(o)}}function Mh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?a=n:n!==void 0&&(l=y.from(n).get(0));let c;const h=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){const E=t.get(t.data.close,1);isNaN(E)?c=NaN:c=Math.max(h-p,Math.abs(h-E),Math.abs(p-E))}else c=h-p;const u=y.from(e).get(0);t.taState||(t.taState={});const f=a||`kc_${s}_${o}_${l}`;t.taState[f]||(t.taState[f]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const m=t.taState[f];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.basisState={...m.currentBasisState},m.rangeState={...m.currentRangeState}),m.lastIdx=t.idx);const x=(E,A,C,M)=>{if(isNaN(C))return Object.assign(A,E),A.prevEma!==null?A.prevEma:NaN;let O=E.initCount,$=E.initSum,B=E.prevEma;if(O<M){if($+=C,O++,A.initSum=$,A.initCount=O,A.prevEma=B,O===M){const re=$/M;return A.prevEma=re,re}return NaN}const R=2/(M+1),q=C*R+B*(1-R);return A.prevEma=q,A.initSum=$,A.initCount=O,q},_=x(m.basisState,m.currentBasisState,u,s),b=x(m.rangeState,m.currentRangeState,c,s);if(isNaN(_)||isNaN(b))return[[NaN,NaN,NaN]];const v=_+b*o,w=_-b*o;return[[t.precision(_),t.precision(v),t.precision(w)]]}}function Rh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?a=n:n!==void 0&&(l=y.from(n).get(0)),t.taState||(t.taState={});const c=a||`kcw_${s}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.basisState={...h.currentBasisState},h.rangeState={...h.currentRangeState}),h.lastIdx=t.idx);const p=(w,E,A,C)=>{if(isNaN(A))return Object.assign(E,w),E.prevEma!==null?E.prevEma:NaN;let M=w.initCount,O=w.initSum,$=w.prevEma;if(M<C){if(O+=A,M++,E.initSum=O,E.initCount=M,E.prevEma=$,M===C){const q=O/C;return E.prevEma=q,q}return NaN}const B=2/(C+1),R=A*B+$*(1-B);return E.prevEma=R,E.initSum=O,E.initCount=M,R};let u;const f=t.get(t.data.high,0),m=t.get(t.data.low,0);if(l){const w=t.get(t.data.close,1);isNaN(w)?u=NaN:u=Math.max(f-m,Math.abs(f-w),Math.abs(m-w))}else u=f-m;const x=y.from(e).get(0),_=p(h.basisState,h.currentBasisState,x,s),b=p(h.rangeState,h.currentRangeState,u,s);if(isNaN(_)||isNaN(b))return NaN;if(_===0)return t.precision(0);const v=2*b*o/_;return t.precision(v)}}function Vh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`linreg_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=y.from(e).get(0),h=[...l.prevWindow];for(h.unshift(c);h.length>a;)h.pop();const p=l.prevCallCount+1;if(h.length<a&&(p>=a||t.idx>=a-1)){const E=y.from(e);for(;h.length<a;)h.push(E.get(h.length))}if(l.currentWindow=h,l.currentCallCount=p,h.length<a)return NaN;let u=0,f=0,m=0,x=0;const _=a;for(let E=0;E<a;E++){const A=a-1-E,C=h[E];u+=A,f+=C,m+=A*C,x+=A*A}const b=_*x-u*u;if(b===0)return NaN;const v=(_*m-u*f)/b,w=(f-v*u)/_+v*(a-1-s);return t.precision(w)}}function Oh(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.low);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`lowest_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const u=y.from(e);for(;l.length<n;)l.push(u.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.min(...h);return t.precision(p)}}function Lh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;let s=1/0,o=NaN;for(let l=0;l<n;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c<s)&&(s=c,o=-l)}return o}}function jh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0),c=a||`macd_${s}_${o}_${l}`,h=`${c}_fast`,p=`${c}_slow`,u=`${c}_signal`,f=t.pine.ta.ema(e,s,h),m=t.pine.ta.ema(e,o,p);let x=NaN;!isNaN(f)&&!isNaN(m)&&(x=f-m);let _=NaN;isNaN(x)||(_=t.pine.ta.ema(x,l,u));let b=NaN;return!isNaN(x)&&!isNaN(_)&&(b=x-_),[[t.precision(x),t.precision(_),t.precision(b)]]}}function Bh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`median_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const h=l.slice().sort((f,m)=>f-m),p=Math.floor(n/2),u=n%2===0?(h[p-1]+h[p])/2:h[p];return t.precision(u)}}function Fh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`mfi_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevUpperWindow=[...s.currentUpperWindow],s.prevLowerWindow=[...s.currentLowerWindow],s.prevUpperSum=s.currentUpperSum,s.prevLowerSum=s.currentLowerSum),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;const h=isNaN(l)?NaN:o-l,p=c*(h<=0?0:o),u=c*(h>=0?0:o),f=[...s.prevUpperWindow],m=[...s.prevLowerWindow];let x=s.prevUpperSum,_=s.prevLowerSum;if(f.unshift(p),m.unshift(u),x+=p,_+=u,f.length<n)return s.currentUpperWindow=f,s.currentLowerWindow=m,s.currentUpperSum=x,s.currentLowerSum=_,NaN;if(f.length>n){const v=f.pop(),w=m.pop();x-=v,_-=w}if(s.currentUpperWindow=f,s.currentLowerWindow=m,s.currentUpperSum=x,s.currentLowerSum=_,_===0)return t.precision(100);if(x===0)return t.precision(0);const b=100-100/(1+x/_);return t.precision(b)}}function $h(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;const s=new Map;for(let c=0;c<n;c++){const h=a.get(c);isNaN(h)||s.set(h,(s.get(h)||0)+1)}if(s.size===0)return NaN;let o=NaN,l=-1;for(const[c,h]of s.entries())h>l?(l=h,o=c):h===l&&c<o&&(o=c);return o}}function Wh(t){return(e,i,r)=>{const n=y.from(i).get(0);return t.pine.ta.change(e,n,r)}}function Uh(t){return e=>{t.taState||(t.taState={});const i=e||"nvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedNVI:1,tentativeNVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(n)?0:n,c=isNaN(a)?0:a,h=isNaN(s)?0:s,p=isNaN(o)?0:o;let u=r.committedNVI;if(!(l===0||c===0)&&h<p){const f=(l-c)/c;u=u+f*u}return r.tentativeNVI=u,t.precision(u)}}function qh(t){return()=>{t.taState||(t.taState={});const e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});const i=t.taState[e];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.committedOBV=i.tentativeOBV),i.lastIdx=t.idx);const r=t.get(t.data.close,0),n=t.get(t.data.volume,0),a=t.get(t.data.close,1);if(isNaN(a))return i.tentativeOBV=0,t.precision(0);let s=i.committedOBV;return r>a?s+=n:r<a&&(s-=n),i.tentativeOBV=s,t.precision(s)}}function zh(t){return(e,i,r)=>e instanceof y?i?new y(e.data,e.offset+i):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function Kh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e);if(t.idx<a-1)return NaN;const l=[];for(let m=0;m<a;m++){const x=o.get(m);if(isNaN(x))return NaN;l.push(x)}l.sort((m,x)=>m-x);let c=s/100*a-.5;c<0&&(c=0),c>a-1&&(c=a-1);const h=Math.floor(c),p=Math.ceil(c);if(h===p)return t.precision(l[h]);const u=c-h,f=l[h]+u*(l[p]-l[h]);return t.precision(f)}}function Hh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e);if(t.idx<a-1)return NaN;const l=[];for(let h=0;h<a;h++){const p=o.get(h);isNaN(p)||l.push(p)}if(l.length===0)return NaN;l.sort((h,p)=>h-p);let c=Math.ceil(s/100*l.length)-1;return c<0&&(c=0),c>=l.length&&(c=l.length-1),t.precision(l[c])}}function Gh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n)return NaN;const s=a.get(0);if(isNaN(s))return NaN;let o=0,l=0;for(let c=1;c<=n;c++){const h=a.get(c);isNaN(h)||(l++,h<=s&&o++)}return l===0?NaN:t.precision(o/l*100)}}function Yh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const a=t[n-i];let s=!0;for(let o=1;o<=e;o++)if(t[n-i-o]>=a){s=!1;break}if(s){for(let o=1;o<=i;o++)if(t[n-i+o]>=a){s=!1;break}}s&&(r[n]=a)}return r}function Xh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.high);const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e).toArray(),l=Yh(o,a,s),c=t.idx;return t.precision(l[c])}}function Qh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const a=t[n-i];let s=!0;for(let o=1;o<=e;o++)if(t[n-i-o]<=a){s=!1;break}if(s){for(let o=1;o<=i;o++)if(t[n-i+o]<=a){s=!1;break}}s&&(r[n]=a)}return r}function Zh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.low);const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e).toArray(),l=Qh(o,a,s),c=t.idx;return t.precision(l[c])}}function Jh(t){return e=>{t.taState||(t.taState={});const i=e||"pvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedPVI:1,tentativePVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(n)?0:n,c=isNaN(a)?0:a,h=isNaN(s)?0:s,p=isNaN(o)?0:o;let u=r.committedPVI;if(!(l===0||c===0)&&h>p){const f=(l-c)/c;u=u+f*u}return r.tentativePVI=u,t.precision(u)}}function eu(t){return e=>{t.taState||(t.taState={});const i=e||"pvt";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0);let o=r.prevCumulativeSum;if(!isNaN(n)&&!isNaN(a)&&!isNaN(s)&&a!==0){const l=(n-a)/a*s;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function tu(t){return(e,i,r)=>{const n=t.pine.ta.highest(e,i,(r||"range")+"_h"),a=t.pine.ta.lowest(e,i,(r||"range")+"_l");return isNaN(n)||isNaN(a)?NaN:t.precision(n-a)}}function iu(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);for(let s=0;s<n;s++){const o=a.get(s),l=a.get(s+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function ru(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`rma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevRma=s.currentRma,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);const o=y.from(e).get(0)||0;let l=s.prevInitCount,c=s.prevInitSum,h=s.prevRma;if(l<n){if(c+=o,l++,s.currentInitSum=c,s.currentInitCount=l,l===n){const f=c/n;return s.currentRma=f,t.precision(f)}return NaN}const p=1/n,u=o*p+h*(1-p);return s.currentRma=u,t.precision(u)}}function nu(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`roc_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=s.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const u=y.from(e);for(;l.length<n+1;)l.push(u.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<=n)return NaN;const h=l[n],p=(o-h)/h*100;return t.precision(p)}}function su(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`rsi_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevPrevValue=s.currentPrevValue,s.prevAvgGain=s.currentAvgGain,s.prevAvgLoss=s.currentAvgLoss,s.prevInitGains=[...s.currentInitGains],s.prevInitLosses=[...s.currentInitLosses]),s.lastIdx=t.idx);const o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;const l=s.prevPrevValue;if(l===null||isNaN(l))return s.currentPrevValue=o,s.currentInitGains=[...s.prevInitGains],s.currentInitLosses=[...s.prevInitLosses],s.currentAvgGain=s.prevAvgGain,s.currentAvgLoss=s.prevAvgLoss,NaN;let c=s.prevAvgGain,h=s.prevAvgLoss;const p=[...s.prevInitGains],u=[...s.prevInitLosses],f=o-l,m=f>0?f:0,x=f<0?-f:0;if(p.length<n){if(p.push(m),u.push(x),s.currentInitGains=p,s.currentInitLosses=u,s.currentPrevValue=o,p.length===n){c=p.reduce((v,w)=>v+w,0)/n,h=u.reduce((v,w)=>v+w,0)/n,s.currentAvgGain=c,s.currentAvgLoss=h;const b=h===0?100:100-100/(1+c/h);return t.precision(b)}return NaN}c=(c*(n-1)+m)/n,h=(h*(n-1)+x)/n,s.currentAvgGain=c,s.currentAvgLoss=h,s.currentPrevValue=o;const _=h===0?100:100-100/(1+c/h);return t.precision(_)}}function au(t){return(e,i,r,n)=>{const a=y.from(e).get(0),s=y.from(i).get(0),o=y.from(r).get(0);t.taState||(t.taState={});const l=n||`sar_${a}_${s}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});const c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let h=c.prevResult,p=c.prevMaxMin,u=c.prevAcceleration,f=c.prevIsBelow,m=c.prevBarIndex;const x=t.get(t.data.high,0),_=t.get(t.data.low,0),b=t.get(t.data.close,0),v=t.get(t.data.close,1),w=t.get(t.data.high,1),E=t.get(t.data.low,1),A=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(x)||isNaN(_)||isNaN(b))return c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,NaN;let M=!1;return m===1&&(b>v?(f=!0,p=x,h=E):(f=!1,p=_,h=w),M=!0,u=a),m>=1&&(h=h+u*(p-h),f?h>_&&(M=!0,f=!1,h=Math.max(x,p),p=_,u=a):h<x&&(M=!0,f=!0,h=Math.min(_,p),p=x,u=a),M||(f?x>p&&(p=x,u=Math.min(u+s,o)):_<p&&(p=_,u=Math.min(u+s,o))),f?(h=Math.min(h,E),m>1&&(h=Math.min(h,C))):(h=Math.max(h,w),m>1&&(h=Math.max(h,A)))),m++,c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,m<=1?NaN:t.precision(h)}}function ou(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`sma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;let h=!1;if(l.length<n&&(c>=n||t.idx>=n-1)){const x=y.from(e);for(;l.length<n;)l.push(x.get(l.length));h=!0}let p;const u=o==null||Number.isNaN(o);let f=!Number.isNaN(s.prevSum)&&!u&&!h;if(f){let x=s.prevSum+o;if(s.prevWindow.length>=n){const _=s.prevWindow[s.prevWindow.length-1];_==null||Number.isNaN(_)?f=!1:x-=_}f&&(p=x)}if(!f){p=0;let x=!1;for(const _ of l){if(_==null||Number.isNaN(_)){x=!0;break}p+=_}x&&(p=NaN)}if(s.currentWindow=l,s.currentSum=p,s.currentCallCount=c,l.length<n)return NaN;const m=p/n;return t.precision(m)}}function lu(t){return(e,i,r=!0,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`stdev_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum,l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=y.from(e).get(0);if(c==null||isNaN(c))return NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}const u=l.prevCallCount+1;if(h.length<a&&(u>=a||t.idx>=a-1)){const b=y.from(e);for(;h.length<a;){const v=b.get(h.length);if(v==null||isNaN(v))break;h.push(v),p+=v}}if(l.currentWindow=h,l.currentSum=p,l.currentCallCount=u,h.length<a)return NaN;const f=p/a;let m=0;for(let b=0;b<a;b++)m+=Math.pow(h[b]-f,2);const x=s?a:a-1,_=Math.sqrt(m/x);return t.precision(_)}}function cu(t){return(e,i,r,n,a)=>{const s=y.from(n).get(0);t.taState||(t.taState={});const o=a||`stoch_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);const c=y.from(e).get(0),h=y.from(i).get(0),p=y.from(r).get(0);if(isNaN(c)||isNaN(h)||isNaN(p))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;const u=[...l.prevHighWindow],f=[...l.prevLowWindow];if(u.unshift(h),f.unshift(p),u.length>s&&(u.pop(),f.pop()),l.currentHighWindow=u,l.currentLowWindow=f,u.length<s)return NaN;let m=u[0],x=f[0];for(let v=1;v<s;v++)u[v]>m&&(m=u[v]),f[v]<x&&(x=f[v]);const _=m-x;if(_===0)return NaN;const b=100*(c-x)/_;return t.precision(b)}}function hu(t){return(e,i,r)=>{const n=y.from(e).get(0),a=y.from(i).get(0);t.taState||(t.taState={});const s=r||`supertrend_${n}_${a}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});const o=t.taState[s];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrSum=o.currentTrSum,o.prevAtrValue=o.currentAtrValue,o.prevAtrCount=o.currentAtrCount,o.prevLowerBand=o.currentLowerBand,o.prevUpperBand=o.currentUpperBand,o.prevSuperTrend=o.currentSuperTrend,o.prevDirection=o.currentDirection),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN]];const p=(l+c)/2,u=t.idx>0?t.get(t.data.close,1):NaN;let f;isNaN(u)?f=l-c:f=Math.max(l-c,Math.abs(l-u),Math.abs(c-u));let m=o.prevAtrCount,x=o.prevTrSum,_=o.prevAtrValue;m++,m<=a?(x+=f,m===a&&(_=x/a)):_=(_*(a-1)+f)/a;const b=_;if(o.currentAtrCount=m,o.currentTrSum=x,o.currentAtrValue=_,isNaN(b))return[[NaN,NaN]];let v=p+n*b,w=p-n*b;const E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,A=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>E||u<E||(w=E),isNaN(o.prevUpperBand)||v<A||u>A||(v=A);let C,M;const O=o.prevSuperTrend;return m===a?C=1:O===o.prevUpperBand?C=h>v?-1:1:C=h<w?1:-1,M=C===-1?w:v,o.currentLowerBand=w,o.currentUpperBand=v,o.currentSuperTrend=M,o.currentDirection=C,[[t.precision(M),C]]}}function uu(t){return(e,i)=>{const r=[1,2,2,1],n=6;t.taState||(t.taState={});const a=i||"swma";t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],currentWindow:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){const h=y.from(e);for(;l.length<4;)l.push(h.get(l.length))}if(s.currentWindow=l,l.length<4)return NaN;let c=0;for(let h=0;h<4;h++)c+=r[h]*l[3-h];return c/=n,t.precision(c)}}function pu(t){return(e,i)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=y.from(e).get(0));const n=t.get(t.data.high,0),a=t.get(t.data.low,0),s=t.get(t.data.close,1);if(isNaN(s))return r?t.precision(n-a):NaN;const o=Math.max(n-a,Math.abs(n-s),Math.abs(a-s));return t.precision(o)}}function fu(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`tsi_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return NaN;const h=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(h))return NaN;const p=Math.abs(h),u=2/(s+1),f=2/(a+1),m=2/(s+1),x=2/(a+1);let _=l.prevEma1PcCount,b=l.prevEma1PcSum,v=l.prevEma1PcValue;_++,_<=s?(b+=h,_===s&&(v=b/s)):v=h*u+v*(1-u);let w=l.prevEma1AbsCount,E=l.prevEma1AbsSum,A=l.prevEma1AbsValue;if(w++,w<=s?(E+=p,w===s&&(A=E/s)):A=p*m+A*(1-m),isNaN(v)||isNaN(A))return l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=w,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,NaN;let C=l.prevEma2PcCount,M=l.prevEma2PcSum,O=l.prevEma2PcValue;C++,C<=a?(M+=v,C===a&&(O=M/a)):O=v*f+O*(1-f);let $=l.prevEma2AbsCount,B=l.prevEma2AbsSum,R=l.prevEma2AbsValue;if($++,$<=a?(B+=A,$===a&&(R=B/a)):R=A*x+R*(1-x),l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=w,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,l.currentEma2PcCount=C,l.currentEma2PcSum=M,l.currentEma2PcValue=O,l.currentEma2AbsCount=$,l.currentEma2AbsSum=B,l.currentEma2AbsValue=R,isNaN(O)||isNaN(R))return NaN;if(R===0)return t.precision(0);const q=O/R;return t.precision(q)}}function du(t){return(e,i,r,n)=>{t.taState||(t.taState={});const a=n||"valuewhen";t.taState[a]||(t.taState[a]={lastIdx:-1,prevValues:[],currentValues:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevValues=[...s.currentValues]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(i).get(0),c=y.from(r).get(0),h=[...s.prevValues];if(o&&h.push(l),s.currentValues=h,isNaN(c)||c<0)return NaN;const p=h.length-1-c;if(p<0)return NaN;const u=h[p];return typeof u=="number"?t.precision(u):u}}function mu(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`variance_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;)l.push(m.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;let h=0,p=0;for(let m=0;m<n;m++)h+=l[m],p+=l[m]*l[m];const u=h/n,f=p/n-u*u;return t.precision(f)}}function gu(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"vwap";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativePV=n.currentCumulativePV,n.prevCumulativeVolume=n.currentCumulativeVolume,n.prevLastSessionDate=n.currentLastSessionDate),n.lastIdx=t.idx);const a=y.from(e).get(0),s=y.from(t.data.volume).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=dt(o,l),h=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`;let p=n.prevCumulativePV,u=n.prevCumulativeVolume,f=n.prevLastSessionDate;if(f!==h&&(p=0,u=0,f=h),p+=a*s,u+=s,n.currentCumulativePV=p,n.currentCumulativeVolume=u,n.currentLastSessionDate=f,u===0)return NaN;const m=p/u;return t.precision(m)}}function yu(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`vwma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevVolumeWindow=[...s.currentVolumeWindow]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=t.get(t.data.volume,0),c=[...s.prevWindow],h=[...s.prevVolumeWindow];for(c.unshift(o),h.unshift(l);c.length>n;)c.pop(),h.pop();if(c.length<n&&t.idx>=n-1){const m=y.from(e),x=y.from(t.data.volume);for(;c.length<n;)c.push(m.get(c.length)),h.push(x.get(h.length))}if(s.currentWindow=c,s.currentVolumeWindow=h,c.length<n)return NaN;let p=0,u=0;for(let m=0;m<n;m++)p+=c[m]*h[m],u+=h[m];const f=p/u;return t.precision(f)}}function xu(t){return e=>{t.taState||(t.taState={});const i=e||"wad";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.high,0),s=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(n)||isNaN(a)||isNaN(s))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){const h=Math.max(a,o),p=Math.min(s,o),u=n-o;u>0?l=n-p:u<0&&(l=n-h)}const c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function _u(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`wma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;let h=0,p=0;for(let f=0;f<n;f++){const m=n-f;h+=l[f]*m,p+=m}const u=h/p;return t.precision(u)}}function bu(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`wpr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const a=t.taState[n];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevHighWindow=[...a.currentHighWindow],a.prevLowWindow=[...a.currentLowWindow]),a.lastIdx=t.idx);const s=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(s)||isNaN(o)||isNaN(l))return a.currentHighWindow=[...a.prevHighWindow],a.currentLowWindow=[...a.prevLowWindow],NaN;const c=[...a.prevHighWindow],h=[...a.prevLowWindow];if(c.unshift(s),h.unshift(o),c.length>r&&(c.pop(),h.pop()),a.currentHighWindow=c,a.currentLowWindow=h,c.length<r)return NaN;let p=c[0],u=h[0];for(let x=1;x<r;x++)c[x]>p&&(p=c[x]),h[x]<u&&(u=h[x]);const f=p-u;if(f===0)return t.precision(0);const m=(p-l)/f*-100;return t.precision(m)}}function wu(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.open,0),n=t.get(t.data.high,0),a=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(a)||isNaN(s))return NaN;const o=n-a;if(o===0)return t.precision(0);const l=(i-r)/o*s;return t.precision(l)}}const vu={accdist:hh,alma:uh,atr:ph,barssince:fh,bb:dh,bbw:mh,cci:gh,change:yh,cmo:xh,cog:_h,correlation:bh,cross:wh,crossover:vh,crossunder:Sh,cum:Eh,dev:Nh,dmi:Ch,ema:Ih,falling:kh,highest:Ah,highestbars:Th,hma:Ph,iii:Dh,kc:Mh,kcw:Rh,linreg:Vh,lowest:Oh,lowestbars:Lh,macd:jh,median:Bh,mfi:Fh,mode:$h,mom:Wh,nvi:Uh,obv:qh,param:zh,percentile_linear_interpolation:Kh,percentile_nearest_rank:Hh,percentrank:Gh,pivothigh:Xh,pivotlow:Zh,pvi:Jh,pvt:eu,range:tu,rising:iu,rma:ru,roc:nu,rsi:su,sar:au,sma:ou,stdev:lu,stoch:cu,supertrend:hu,swma:uu,tr:pu,tsi:fu,valuewhen:du,variance:mu,vwap:gu,vwma:yu,wad:xu,wma:_u,wpr:bu,wvad:wu};class Su{constructor(e){this.context=e,Object.entries(vu).forEach(([i,r])=>{this[i]=r(e)})}accdist;alma;atr;barssince;bb;bbw;cci;change;cmo;cog;correlation;cross;crossover;crossunder;cum;dev;dmi;ema;falling;highest;highestbars;hma;iii;kc;kcw;linreg;lowest;lowestbars;macd;median;mfi;mode;mom;nvi;obv;param;percentile_linear_interpolation;percentile_nearest_rank;percentrank;pivothigh;pivotlow;pvi;pvt;range;rising;rma;roc;rsi;sar;sma;stdev;stoch;supertrend;swma;tr;tsi;valuewhen;variance;vwap;vwma;wad;wma;wpr;wvad}function Eu(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC")return 0;const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const s=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return s*(o*60+l)}const n=dt(t,e),a=new Date(Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second));return Math.round((a.getTime()-t)/6e4)}function Nu(t,e){const i=e>=0?"+":"-",r=a=>String(Math.floor(Math.abs(a))).padStart(2,"0"),n=i+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${n}]`}class Cu{constructor(e){this.context=e}logFormat(e,...i){return e.replace(/{(\d+)}/g,(r,n)=>i[n])}param(e,i=0,r){return y.from(e).get(i)}_formatTimestamp(){const e=this.context.data.openTime.data[this.context.idx],i=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=Eu(e,i);return Nu(e,r)}warning(e,...i){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}error(e,...i){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}info(e,...i){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}}class Iu{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}tostring(e,i){if(typeof e!="number"||isNaN(e)||!i)return String(e);if(i==="mintick"){const n=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(a)}if(i==="integer")return String(Math.round(e));if(i==="percent")return(e*100).toFixed(2)+"%";if(i==="price"){const n=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(a)}if(i==="volume")return String(Math.round(e));const r=i.indexOf(".");if(r>=0){const n=i.substring(r+1).length;return e.toFixed(n)}return i.includes("#")||i.includes("0")?String(Math.round(e)):String(e)}tonumber(e){return Number(e)}lower(e){return String(e).toLowerCase()}upper(e){return String(e).toUpperCase()}trim(e){return String(e).trim()}repeat(e,i,r=""){return Array(i).fill(e).join(r||"")}replace_all(e,i,r){return String(e).replaceAll(i,r)}replace(e,i,r,n=0){const a=String(e),s=String(i),o=String(r),l=Math.floor(Number(n))||0;if(s==="")return a;let c=0,h=0;for(;;){const p=a.indexOf(s,c);if(p===-1)return a;if(h===l)return a.substring(0,p)+o+a.substring(p+s.length);h++,c=p+s.length}}contains(e,i){return String(e).includes(i)}endswith(e,i){return String(e).endsWith(i)}startswith(e,i){return String(e).startsWith(i)}pos(e,i){const r=String(e).indexOf(i);return r===-1?NaN:r}length(e){return String(e).length}match(e,i){return String(e).match(new RegExp(i))}split(e,i){return new D(String(e).split(i),T.string,this.context)}substring(e,i,r){return String(e).substring(i,r)}format(e,...i){return e.replace(/\{(\d+)(?:,number,([^}]+))?\}/g,(r,n,a)=>{const s=i[n];return a&&typeof s=="number"&&!isNaN(s)?this.tostring(s,a):String(s)})}}const Vt={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function hr(t){if(!t||/^\d+$/.test(t))return t;if(Vt[t])return Vt[t];const e=t.toLowerCase();if(Vt[e])return Vt[e];if(t.length===1){const r=t.toUpperCase();if(["D","W","M","S"].includes(r))return r}const i=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(i)){const r=parseInt(t);if(!isNaN(r))return r+i}return t}class ku{constructor(e){this.context=e}_normalized=null;param(e,i=0,r){return y.from(e).get(i)}get normalized(){return this._normalized===null&&(this._normalized=hr(this.context.timeframe)),this._normalized}get unit(){return this.normalized.slice(-1).toUpperCase()}get main_period(){return this.normalized}get period(){return this.normalized}get multiplier(){const e=parseInt(this.normalized);return isNaN(e)?1:e}get isdwm(){return["D","W","M"].includes(this.unit)}get isdaily(){return this.unit==="D"}get isweekly(){return this.unit==="W"}get ismonthly(){return this.unit==="M"}get isseconds(){return this.unit==="S"}get isminutes(){return/^\d+$/.test(this.normalized)}get isintraday(){return!this.isdwm}from_seconds(e){return e<60?Math.ceil(e/5)*5+"S":e<3600*24?Math.ceil(e/60):e<=3600*24*7*52?e%(3600*24*7)===0?Math.ceil(e/604800)+"W":Math.ceil(e/(3600*24))+"D":"12M"}in_seconds(e){e==null?e=this.normalized:e=hr(e);const i=e.slice(-1).toUpperCase(),r=parseInt(e);return i==="S"?isNaN(r)?1:r:i==="D"?(isNaN(r)?1:r)*60*60*24:i==="W"?(isNaN(r)?1:r)*60*60*24*7:i==="M"?(isNaN(r)?1:r)*60*60*24*30:isNaN(r)?0:r*60}}const Au=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],Tu=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Pu={series:"series",title:"string",char:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Du=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Mu=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],Ru=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],Vu=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],ur=["color","offset","editable","show_last","title","display","force_overlay"],Ou=["price","title","color","linestyle","linewidth","editable","display"],Lu=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],ju={series:"series",title:"string",color:"color",linewidth:"number",style:"string",trackprice:"boolean",histbase:"number",offset:"number",join:"bool",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Bu={series:"series",title:"string",style:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Fu={series:"series",title:"string",colorup:"color",colordown:"color",offset:"number",minheight:"number",maxheight:"number",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},$u={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Wu={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",wickcolor:"color",bordercolor:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},pr={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},Uu={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},qu={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"};class zu{constructor(e){this.context=e}_resolvePlotKey(e,i){if(e){const r=this.context.plots[e];return!r||!i||r._callsiteId===i?e:e+i}return i||"plot"}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}get linestyle_dashed(){return"linestyle_dashed"}get linestyle_dotted(){return"linestyle_dotted"}get linestyle_solid(){return"linestyle_solid"}get style_area(){return"style_area"}get style_areabr(){return"style_areabr"}get style_circles(){return"style_circles"}get style_columns(){return"style_columns"}get style_cross(){return"style_cross"}get style_histogram(){return"style_histogram"}get style_line(){return"style_line"}get style_linebr(){return"style_linebr"}get style_stepline(){return"style_stepline"}get style_stepline_diamond(){return"style_stepline_diamond"}get style_steplinebr(){return"style_steplinebr"}param(e,i=0,r){return y.from(e).get(i)}plotchar(...e){const i=ke(e),r=X(e,Tu,Pu),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:a,_plotKey:l,_callsiteId:i});const c=y.from(n).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){const i=ke(e),r=X(e,Au,ju),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i),c="color"in s;if(!this.context.plots[l]){const f=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:f},title:a,_plotKey:l,_callsiteId:i}}const h=y.from(n).get(0);let p=o.color;typeof p=="function"&&(p=p());const u={color:c?typeof p=="string"?p:void 0:p||"#2962ff"};return"offset"in s&&(u.offset=o.offset),this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:h,options:u}),this.context.plots[l]}plotshape(...e){const i=ke(e),r=X(e,Du,Bu),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i);if(!this.context.plots[l]){const h=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:h},title:a,_plotKey:l,_callsiteId:i}}const c=y.from(n).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){const i=ke(e),r=X(e,Mu,Fu),{series:n,title:a,...s}=r,o=y.from(n).get(0),l=this.extractPlotOptions(s),c=this._resolvePlotKey(a,i);if(!this.context.plots[c]){const h=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:h},title:a,_plotKey:c,_callsiteId:i}}return this.context.plots[c].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){const i=ke(e),r=X(e,Ru,$u),{open:n,high:a,low:s,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"bar",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[y.from(n).get(0),y.from(a).get(0),y.from(s).get(0),y.from(o).get(0)];this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color}})}plotcandle(...e){const i=ke(e),r=X(e,Vu,Wu),{open:n,high:a,low:s,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"candle",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[y.from(n).get(0),y.from(a).get(0),y.from(s).get(0),y.from(o).get(0)];return this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color,wickcolor:h.wickcolor,bordercolor:h.bordercolor}}),this.context.plots[p]}bgcolor(...e){const i=ke(e),r=X(e,ur,pr),{title:n,...a}=r,s=this.extractPlotOptions(a),o=this._resolvePlotKey(n,i);if(!this.context.plots[o]){const l=s.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...s,style:"background",overlay:l},title:n,_plotKey:o,_callsiteId:i}}this.context.plots[o].data.push({title:n,time:this.context.marketData[this.context.idx].openTime,value:s.color&&s.color!=="na"&&s?.color.toString()!=="NaN",options:{color:s.color}})}barcolor(...e){const i=ke(e),r=X(e,ur,pr),{title:n,...a}=r,s=this.extractPlotOptions(a),o=this._resolvePlotKey(n,i);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...s,style:"barcolor"},title:n,_plotKey:o,_callsiteId:i}),this.context.plots[o].data.push({title:n,time:this.context.marketData[this.context.idx].openTime,value:s.color&&s.color!=="na"&&s?.color.toString()!=="NaN",options:{color:s.color}}),this.context.plots[o]}}class Ku{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=ke(e),r=X(e,Ou,Uu),{price:n,title:a,color:s,linestyle:o,linewidth:l,editable:c,display:h}=r,p=[n,{title:a,color:s,linestyle:o,linewidth:l,editable:c,display:h,style:"hline"}];return i&&p.push({__callsiteId:i}),this.context.pine.plot.any(...p)}}class Hu{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=ke(e),r=e.length>=6&&typeof e[2]=="number",n=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||n!==null){const a=e[0],s=e[1],o=n?y.from(n.top_value).get(0):e[2],l=n?y.from(n.bottom_value).get(0):e[3],c=n?y.from(n.top_color).get(0):e[4],h=n?y.from(n.bottom_color).get(0):e[5],p=n?n.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,u=a?._plotKey||a?.title,f=s?._plotKey||s?.title;let m=p||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i),this.context.plots[m]||(this.context.plots[m]={title:p||"Fill",plot1:u,plot2:f,data:[],options:{plot1:u,plot2:f,style:"fill",gradient:!0},_plotKey:m,_callsiteId:i}),this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:h}})}else{const a=X(e,Lu,qu),{plot1:s,plot2:o,color:l,title:c,editable:h,show_last:p,fillgaps:u,display:f}=a;let m=c||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i);const _=y.from(l).get(0);if(!this.context.plots[m]){const b=s?._plotKey||s?.title,v=o?._plotKey||o?.title;this.context.plots[m]={title:c||"Fill",plot1:b,plot2:v,data:[],options:{plot1:b,plot2:v,color:_,editable:h,show_last:p,fillgaps:u,display:f,style:"fill"},_plotKey:m,_callsiteId:i}}this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:_}})}}}class Gu{constructor(e){this.context=e;const i=this.context;this.point={new(r,n,a){return new se(r,n,a??NaN)},from_index(r,n){return new se(void 0,r,n)},from_time(r,n){return new se(r,void 0,n)},copy(r){return r.copy()},now(r){const n=i.idx,a=i.marketData[n]?.openTime;return new se(a,n,r)}}}point;param(e,i=0,r){return y.from(e).get(i)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){return!0}is_heikinashi(){return!1}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}}let Yu=0;class Di{id;x;y;text;xloc;yloc;color;style;textcolor;size;textalign;tooltip;text_font_family;force_overlay;_deleted;_helper;_createdAtBar=-1;constructor(e,i,r="",n="bi",a="pr",s="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){this.id=Yu++,this.x=e,this.y=i,this.text=r,this.xloc=n,this.yloc=a,this.color=s,this.style=o,this.textcolor=l,this.size=c,this.textalign=h,this.tooltip=p,this.text_font_family=u,this.force_overlay=f,this._deleted=!1,this._helper=null}set_x(e){this._helper?this._helper.set_x(this,e):this._deleted||(this.x=e)}set_y(e){this._helper?this._helper.set_y(this,e):this._deleted||(this.y=e)}set_xy(e,i){this._helper?this._helper.set_xy(this,e,i):this._deleted||(this.x=e,this.y=i)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_textcolor(e){this._helper?this._helper.set_textcolor(this,e):this._deleted||(this.textcolor=e)}set_size(e){this._helper?this._helper.set_size(this,e):this._deleted||(this.size=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_textalign(e){this._helper?this._helper.set_textalign(this,e):this._deleted||(this.textalign=e)}set_tooltip(e){this._helper?this._helper.set_tooltip(this,e):this._deleted||(this.tooltip=e)}set_xloc(e){this._helper?this._helper.set_xloc(this,e):this._deleted||(this.xloc=e)}set_yloc(e){this._helper?this._helper.set_yloc(this,e):this._deleted||(this.yloc=e)}set_point(e){this._helper&&this._helper.set_point(this,e)}set_text_font_family(e){this._deleted||(this.text_font_family=e)}get_x(){return this.x}get_y(){return this.y}get_text(){return this.text}delete(){this._deleted=!0}copy(){return new Di(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay)}toPlotData(){return{id:this.id,x:this.x,y:this.y,text:this.text,xloc:this.xloc,yloc:this.yloc,color:this.color,style:this.style,textcolor:this.textcolor,size:this.size,textalign:this.textalign,tooltip:this.tooltip,text_font_family:this.text_font_family,force_overlay:this.force_overlay,_deleted:this._deleted}}}const Xu=[["x","y","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"],["point","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"]],Qu={x:"number",y:"number",text:"string",xloc:"string",yloc:"string",color:"color",style:"string",textcolor:"color",size:"string",textalign:"string",tooltip:"string",text_font_family:"string",force_overlay:"boolean",point:"point"};class Zu{constructor(e){this.context=e}_labels=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._labels.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],n.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:n,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof _t)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){const i=e.get(0);return typeof i=="number"&&isNaN(i)?null:i}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,i,r="",n="bi",a="pr",s="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){const m=new Di(e,i,this._resolve(r),this._resolve(n),this._resolve(a),this._resolve(s),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(h),this._resolve(p),this._resolve(u),f);return m._helper=this,m._createdAtBar=this.context.idx,this._labels.push(m),this._enforceMaxCount(),this.syncToPlot(),m}_enforceMaxCount(){const e=this.context.indicator?.max_labels_count??50,i=this._labels.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._labels){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}new(...e){const i=X(e,Xu,Qu);let r,n,a=i.xloc;if(i.point instanceof se){const s=i.point;s.index!==void 0?(r=s.index,a=a||"bi"):s.time!==void 0?(r=s.time,a=a||"bt"):(r=0,a=a||"bi"),n=s.price}else r=i.x,n=i.y;return this._createLabel(r,n,i.text,a,i.yloc,i.color,i.style,i.textcolor,i.size,i.textalign,i.tooltip,i.text_font_family,i.force_overlay)}any(...e){return this.new(...e)}set_x(e,i){e&&!e._deleted&&(e.x=i)}set_y(e,i){e&&!e._deleted&&(e.y=i)}set_xy(e,i,r){e&&!e._deleted&&(e.x=i,e.y=r)}set_text(e,i){e&&!e._deleted&&(e.text=i)}set_color(e,i){e&&!e._deleted&&(e.color=i)}set_textcolor(e,i){e&&!e._deleted&&(e.textcolor=i)}set_size(e,i){e&&!e._deleted&&(e.size=i)}set_style(e,i){e&&!e._deleted&&(e.style=i)}set_textalign(e,i){e&&!e._deleted&&(e.textalign=i)}set_tooltip(e,i){e&&!e._deleted&&(e.tooltip=i)}set_xloc(e,i){e&&!e._deleted&&(e.xloc=i)}set_yloc(e,i){e&&!e._deleted&&(e.yloc=i)}set_point(e,i){e&&!e._deleted&&i&&(i.index!==void 0?(e.x=i.index,e.xloc="bi"):i.time!==void 0&&(e.x=i.time,e.xloc="bt"),e.y=i.price)}get_x(e){return e?e.x:NaN}get_y(e){return e?e.y:NaN}get_text(e){return e?e.text:""}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._labels.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_label_down(){return"style_label_down"}get style_label_up(){return"style_label_up"}get style_label_left(){return"style_label_left"}get style_label_right(){return"style_label_right"}get style_label_lower_left(){return"style_label_lower_left"}get style_label_lower_right(){return"style_label_lower_right"}get style_label_upper_left(){return"style_label_upper_left"}get style_label_upper_right(){return"style_label_upper_right"}get style_label_center(){return"style_label_center"}get style_circle(){return"style_circle"}get style_square(){return"style_square"}get style_diamond(){return"style_diamond"}get style_flag(){return"style_flag"}get style_arrowup(){return"style_arrowup"}get style_arrowdown(){return"style_arrowdown"}get style_cross(){return"style_cross"}get style_xcross(){return"style_xcross"}get style_triangleup(){return"style_triangleup"}get style_triangledown(){return"style_triangledown"}get style_none(){return"style_none"}get style_text_outline(){return"style_text_outline"}}let Ju=0;class Mi{id;x1;y1;x2;y2;xloc;extend;color;style;width;force_overlay;_deleted;_helper;_createdAtBar=-1;constructor(e,i,r,n,a="bi",s="none",o="",l="style_solid",c=1,h=!1){this.id=Ju++,this.x1=e,this.y1=i,this.x2=r,this.y2=n,this.xloc=a,this.extend=s,this.color=o,this.style=l,this.width=c,this.force_overlay=h,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,i){this._helper?this._helper.set_xy1(this,e,i):this._deleted||(this.x1=e,this.y1=i)}set_xy2(e,i){this._helper?this._helper.set_xy2(this,e,i):this._deleted||(this.x2=e,this.y2=i)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_width(e){this._helper?this._helper.set_width(this,e):this._deleted||(this.width=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.x1=e,this.x2=i,this.xloc=r)}set_first_point(e){this._helper&&this._helper.set_first_point(this,e)}set_second_point(e){this._helper&&this._helper.set_second_point(this,e)}get_x1(){return this.x1}get_y1(){return this.y1}get_x2(){return this.x2}get_y2(){return this.y2}get_price(e){return this._helper?this._helper.get_price(this,e):NaN}delete(){this._deleted=!0}copy(){return new Mi(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}}const ep=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],tp={x1:"number",y1:"number",x2:"number",y2:"number",xloc:"string",extend:"string",color:"color",style:"string",width:"number",force_overlay:"boolean",first_point:"point",second_point:"point"};class ip{constructor(e){this.context=e}_lines=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._lines.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],n.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:n,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_createLine(e,i,r,n,a="bi",s="none",o="",l="style_solid",c=1,h=!1){const p=new Mi(e,i,r,n,a,this._resolve(s),this._resolve(o),this._resolve(l),this._resolve(c)||1,h);return p._helper=this,p._createdAtBar=this.context.idx,this._lines.push(p),this._enforceMaxCount(),this.syncToPlot(),p}_enforceMaxCount(){const e=this.context.indicator?.max_lines_count??50,i=this._lines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._lines){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}new(...e){const i=X(e,ep,tp);let r,n,a,s,o=i.xloc;if(i.first_point instanceof se){const l=i.first_point,c=i.second_point,h=this._resolvePoint(l);r=h.x,n=l.price,o=o||h.xloc,c instanceof se?(a=this._resolvePoint(c).x,s=c.price):(a=0,s=NaN)}else r=i.x1,n=i.y1,a=i.x2,s=i.y2;return this._createLine(r,n,a,s,o,i.extend,i.color,i.style,i.width,i.force_overlay)}any(...e){return this.new(...e)}set_x1(e,i){e&&!e._deleted&&(e.x1=this._resolve(i))}set_y1(e,i){e&&!e._deleted&&(e.y1=this._resolve(i))}set_x2(e,i){e&&!e._deleted&&(e.x2=this._resolve(i))}set_y2(e,i){e&&!e._deleted&&(e.y2=this._resolve(i))}set_xy1(e,i,r){e&&!e._deleted&&(e.x1=this._resolve(i),e.y1=this._resolve(r))}set_xy2(e,i,r){e&&!e._deleted&&(e.x2=this._resolve(i),e.y2=this._resolve(r))}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i))}set_width(e,i){e&&!e._deleted&&(e.width=this._resolve(i)||1)}set_style(e,i){e&&!e._deleted&&(e.style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_xloc(e,i,r,n){e&&!e._deleted&&(e.x1=i,e.x2=r,e.xloc=n)}set_first_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x1=r.x,e.y1=i.price,e.xloc=r.xloc}}set_second_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x2=r.x,e.y2=i.price,e.xloc=r.xloc}}get_x1(e){return e?e.x1:NaN}get_y1(e){return e?e.y1:NaN}get_x2(e){return e?e.x2:NaN}get_y2(e){return e?e.y2:NaN}get_price(e,i){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;const r=e.x2-e.x1;return r===0?e.y1:e.y1+(i-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._lines.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_solid(){return"style_solid"}get style_dotted(){return"style_dotted"}get style_dashed(){return"style_dashed"}get style_arrow_left(){return"style_arrow_left"}get style_arrow_right(){return"style_arrow_right"}get style_arrow_both(){return"style_arrow_both"}}let rp=0;class Ri{id;left;top;right;bottom;xloc;extend;border_color;border_style;border_width;bgcolor;text;text_color;text_size;text_halign;text_valign;text_wrap;text_font_family;text_formatting;force_overlay;_deleted;_helper;_createdAtBar=-1;constructor(e,i,r,n,a="bi",s="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",v="format_none",w=!1){this.id=rp++,this.left=e,this.top=i,this.right=r,this.bottom=n,this.xloc=a,this.extend=s,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=h,this.text=p,this.text_color=u,this.text_size=f,this.text_halign=m,this.text_valign=x,this.text_wrap=_,this.text_font_family=b,this.text_formatting=v,this.force_overlay=w,this._deleted=!1,this._helper=null}set_left(e){this._helper?this._helper.set_left(this,e):this._deleted||(this.left=e)}set_right(e){this._helper?this._helper.set_right(this,e):this._deleted||(this.right=e)}set_top(e){this._helper?this._helper.set_top(this,e):this._deleted||(this.top=e)}set_bottom(e){this._helper?this._helper.set_bottom(this,e):this._deleted||(this.bottom=e)}set_lefttop(e,i){this._helper?this._helper.set_lefttop(this,e,i):this._deleted||(this.left=e,this.top=i)}set_rightbottom(e,i){this._helper?this._helper.set_rightbottom(this,e,i):this._deleted||(this.right=e,this.bottom=i)}set_top_left_point(e){this._helper&&this._helper.set_top_left_point(this,e)}set_bottom_right_point(e){this._helper&&this._helper.set_bottom_right_point(this,e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.left=e,this.right=i,this.xloc=r)}set_bgcolor(e){this._helper?this._helper.set_bgcolor(this,e):this._deleted||(this.bgcolor=e)}set_border_color(e){this._helper?this._helper.set_border_color(this,e):this._deleted||(this.border_color=e)}set_border_width(e){this._helper?this._helper.set_border_width(this,e):this._deleted||(this.border_width=e)}set_border_style(e){this._helper?this._helper.set_border_style(this,e):this._deleted||(this.border_style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_text_color(e){this._helper?this._helper.set_text_color(this,e):this._deleted||(this.text_color=e)}set_text_size(e){this._helper?this._helper.set_text_size(this,e):this._deleted||(this.text_size=e)}set_text_halign(e){this._helper?this._helper.set_text_halign(this,e):this._deleted||(this.text_halign=e)}set_text_valign(e){this._helper?this._helper.set_text_valign(this,e):this._deleted||(this.text_valign=e)}set_text_wrap(e){this._helper?this._helper.set_text_wrap(this,e):this._deleted||(this.text_wrap=e)}set_text_font_family(e){this._helper?this._helper.set_text_font_family(this,e):this._deleted||(this.text_font_family=e)}set_text_formatting(e){this._helper?this._helper.set_text_formatting(this,e):this._deleted||(this.text_formatting=e)}get_left(){return this.left}get_right(){return this.right}get_top(){return this.top}get_bottom(){return this.bottom}delete(){this._deleted=!0}toPlotData(){return{id:this.id,left:this.left,top:this.top,right:this.right,bottom:this.bottom,xloc:this.xloc,extend:this.extend,border_color:this.border_color,border_style:this.border_style,border_width:this.border_width,bgcolor:this.bgcolor,text:this.text,text_color:this.text_color,text_size:this.text_size,text_halign:this.text_halign,text_valign:this.text_valign,text_wrap:this.text_wrap,text_font_family:this.text_font_family,text_formatting:this.text_formatting,force_overlay:this.force_overlay,_deleted:this._deleted}}copy(){return new Ri(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}}const np=[["left","top","right","bottom","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"],["top_left","bottom_right","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"]],sp={left:"number",top:"number",right:"number",bottom:"number",top_left:"point",bottom_right:"point",border_color:"color",border_width:"number",border_style:"string",extend:"string",xloc:"string",bgcolor:"color",text:"string",text_size:"string",text_color:"color",text_halign:"string",text_valign:"string",text_wrap:"string",text_font_family:"string",force_overlay:"boolean"};class ap{constructor(e){this.context=e}_boxes=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._boxes.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],n.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:n,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_createBox(e,i,r,n,a="bi",s="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",v="format_none",w=!1){const E=new Ri(e,i,r,n,a,this._resolve(s),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(h,"#2962ff"),this._resolve(p)||"",this._resolveColor(u,"#000000"),this._resolve(f)||"auto",this._resolve(m)||"center",this._resolve(x)||"center",this._resolve(_)||"wrap_none",this._resolve(b)||"default",this._resolve(v)||"format_none",w);return E._helper=this,E._createdAtBar=this.context.idx,this._boxes.push(E),this._enforceMaxCount(),this.syncToPlot(),E}_enforceMaxCount(){const e=this.context.indicator?.max_boxes_count??50,i=this._boxes.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._boxes){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}new(...e){const i=X(e,np,sp);let r,n,a,s,o=i.xloc;if(i.top_left instanceof se){const l=i.top_left,c=i.bottom_right,h=this._resolvePoint(l);r=h.x,n=l.price,o=o||h.xloc,c instanceof se?(a=this._resolvePoint(c).x,s=c.price):(a=0,s=NaN)}else r=this._resolve(i.left),n=this._resolve(i.top),a=this._resolve(i.right),s=this._resolve(i.bottom);return this._createBox(r,n,a,s,o,i.extend,i.border_color,i.border_style,i.border_width,i.bgcolor,i.text,i.text_color,i.text_size,i.text_halign,i.text_valign,i.text_wrap,i.text_font_family,void 0,i.force_overlay)}any(...e){return this.new(...e)}set_left(e,i){e&&!e._deleted&&(e.left=this._resolve(i))}set_right(e,i){e&&!e._deleted&&(e.right=this._resolve(i))}set_top(e,i){e&&!e._deleted&&(e.top=this._resolve(i))}set_bottom(e,i){e&&!e._deleted&&(e.bottom=this._resolve(i))}set_lefttop(e,i,r){e&&!e._deleted&&(e.left=this._resolve(i),e.top=this._resolve(r))}set_rightbottom(e,i,r){e&&!e._deleted&&(e.right=this._resolve(i),e.bottom=this._resolve(r))}set_top_left_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.left=r.x,e.top=i.price,e.xloc=r.xloc}}set_bottom_right_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.right=r.x,e.bottom=i.price,e.xloc=r.xloc}}set_xloc(e,i,r,n){e&&!e._deleted&&(e.left=this._resolve(i),e.right=this._resolve(r),e.xloc=this._resolve(n))}set_bgcolor(e,i){e&&!e._deleted&&(e.bgcolor=this._resolve(i))}set_border_color(e,i){e&&!e._deleted&&(e.border_color=this._resolve(i))}set_border_width(e,i){e&&!e._deleted&&(e.border_width=this._resolve(i)??1)}set_border_style(e,i){e&&!e._deleted&&(e.border_style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_text(e,i){e&&!e._deleted&&(e.text=this._resolve(i)||"")}set_text_color(e,i){e&&!e._deleted&&(e.text_color=this._resolve(i))}set_text_size(e,i){e&&!e._deleted&&(e.text_size=this._resolve(i))}set_text_halign(e,i){e&&!e._deleted&&(e.text_halign=this._resolve(i))}set_text_valign(e,i){e&&!e._deleted&&(e.text_valign=this._resolve(i))}set_text_wrap(e,i){e&&!e._deleted&&(e.text_wrap=this._resolve(i))}set_text_font_family(e,i){e&&!e._deleted&&(e.text_font_family=this._resolve(i))}set_text_formatting(e,i){e&&!e._deleted&&(e.text_formatting=this._resolve(i))}get_left(e){return e?e.left:NaN}get_right(e){return e?e.right:NaN}get_top(e){return e?e.top:NaN}get_bottom(e){return e?e.bottom:NaN}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._boxes.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(i=>i._createdAtBar<e),this.syncToPlot()}}let op=0;class lp{id;line1;line2;color;_deleted;_createdAtBar=-1;constructor(e,i,r){this.id=op++,this.line1=e,this.line2=i,this.color=r,this._deleted=!1}get_line1(){return this.line1}get_line2(){return this.line2}set_color(e){this._deleted||(typeof e=="function"&&(e=e()),e&&typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"&&(e=e.get(0)),this.color=e||"")}delete(){this._deleted=!0}toPlotData(){const e=r=>r?{id:r.id,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,xloc:r.xloc,extend:r.extend,color:r.color,style:r.style,width:r.width,_deleted:r._deleted}:null,i=!!(this.line1?.force_overlay||this.line2?.force_overlay);return{id:this.id,line1:e(this.line1),line2:e(this.line2),color:this.color,force_overlay:i,_deleted:this._deleted}}}class cp{constructor(e){this.context=e}_linefills=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._linefills.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:r,options:{style:"linefill"}}],n.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:n,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(e,i,r){const n=this._resolve(e),a=this._resolve(i),s=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolve(s)||"";if(n&&a){const c=n.id,h=a.id;for(const p of this._linefills){if(p._deleted)continue;const u=p.line1?.id,f=p.line2?.id;if(u===c&&f===h||u===h&&f===c)return p.color=o,p._createdAtBar=this.context.idx,this.syncToPlot(),p}}const l=new lp(n,a,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),this.syncToPlot(),l}any(...e){return this.new(e[0],e[1],e[2])}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i)||"")}get_line1(e){return e?e.line1:void 0}get_line2(e){return e?e.line2:void 0}delete(e){e&&(e._deleted=!0)}get all(){return this._linefills.filter(e=>!e._deleted)}rollbackFromBar(e){this._linefills=this._linefills.filter(i=>i._createdAtBar<e),this.syncToPlot()}}let hp=0;class up{id;points;curved;closed;xloc;line_color;fill_color;line_style;line_width;force_overlay;_deleted;_createdAtBar=-1;constructor(e,i=!1,r=!1,n="bi",a="#2962ff",s="",o="style_solid",l=1,c=!1){this.id=hp++,this.points=e,this.curved=i,this.closed=r,this.xloc=n,this.line_color=a,this.fill_color=s,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}}class pp{constructor(e){this.context=e}_polylines=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(i=>i.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof _t?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_extractPoints(e){let i=this._resolve(e);const r=i&&i.array?i.array:i;return Array.isArray(r)?r.filter(n=>n instanceof se):[]}new(...e){let i,r=!1,n=!1,a="bi",s="#2962ff",o="",l="style_solid",c=1,h=!1;const p=_=>{r=_.curved??r,n=_.closed??n,a=_.xloc??a,s=_.line_color??s,o=_.fill_color??o,l=_.line_style??l,c=_.line_width??c,h=_.force_overlay??h},u=e.length>=1?e[e.length-1]:null,f=e.length>=2&&u&&typeof u=="object"&&!Array.isArray(u)&&!(u instanceof y)&&!(u instanceof se);if(e.length===1&&u&&typeof u=="object"&&!Array.isArray(u)&&"points"in u)i=u.points,p(u);else{const _=f?e.slice(0,-1):e;i=_[0],r=_[1]??r,n=_[2]??n,a=_[3]??a,s=_[4]??s,o=_[5]??o,l=_[6]??l,c=_[7]??c,h=_[8]??h,f&&p(u)}const m=this._extractPoints(i),x=new up(m,this._resolve(r)??!1,this._resolve(n)??!1,this._resolve(a)||"bi",this._resolveColor(s,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(h)??!1);return x._createdAtBar=this.context.idx,this._polylines.push(x),this._enforceMaxCount(),this.syncToPlot(),x}_enforceMaxCount(){const e=this.context.indicator?.max_polylines_count??50,i=this._polylines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._polylines){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}any(...e){return this.new(...e)}delete(e){e&&(e._deleted=!0)}get all(){return this._polylines.filter(e=>!e._deleted)}rollbackFromBar(e){this._polylines=this._polylines.filter(i=>i._createdAtBar<e),this.syncToPlot()}}let fp=0;class dp{id;position;columns;rows;bgcolor;frame_color;frame_width;border_color;border_width;force_overlay;_deleted;cells;merges;_helper;constructor(e="top_right",i=1,r=1,n="",a="",s=0,o="",l=0,c=!1){this.id=fp++,this.position=e,this.columns=i,this.rows=r,this.bgcolor=n,this.frame_color=a,this.frame_width=s,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let h=0;h<r;h++){this.cells[h]=[];for(let p=0;p<i;p++)this.cells[h][p]=null}}delete(){this._deleted=!0}toPlotData(){const e=this.cells.map(i=>i.map(r=>r?{...r}:null));return{id:this.id,position:this.position,columns:this.columns,rows:this.rows,bgcolor:this.bgcolor,frame_color:this.frame_color,frame_width:this.frame_width,border_color:this.border_color,border_width:this.border_width,force_overlay:this.force_overlay,_deleted:this._deleted,cells:e,merges:this.merges.map(i=>({...i}))}}setCell(e,i,r){if(i<0||i>=this.rows||e<0||e>=this.columns)return;const n=this.cells[i][e];if(n&&n._merged&&n._merge_parent){const[s,o]=n._merge_parent;if(s===e&&o===i)n._merged=!1,n._merge_parent=void 0;else{this.setCell(s,o,r);return}}const a=n||this._defaultCell();Object.assign(a,r),this.cells[i][e]=a}getCell(e,i){return i<0||i>=this.rows||e<0||e>=this.columns?null:this.cells[i][e]}clearCell(e,i){i<0||i>=this.rows||e<0||e>=this.columns||(this.cells[i][e]=null)}_setHelper(e){this._helper=e}cell(...e){return this._helper.cell(this,...e)}clear(...e){return this._helper.clear(this,...e)}merge_cells(...e){return this._helper.merge_cells(this,...e)}cell_set_text(...e){return this._helper.cell_set_text(this,...e)}cell_set_bgcolor(...e){return this._helper.cell_set_bgcolor(this,...e)}cell_set_text_color(...e){return this._helper.cell_set_text_color(this,...e)}cell_set_text_size(...e){return this._helper.cell_set_text_size(this,...e)}cell_set_height(...e){return this._helper.cell_set_height(this,...e)}cell_set_width(...e){return this._helper.cell_set_width(this,...e)}cell_set_tooltip(...e){return this._helper.cell_set_tooltip(this,...e)}cell_set_text_halign(...e){return this._helper.cell_set_text_halign(this,...e)}cell_set_text_valign(...e){return this._helper.cell_set_text_valign(this,...e)}cell_set_text_font_family(...e){return this._helper.cell_set_text_font_family(this,...e)}set_position(...e){return this._helper.set_position(this,...e)}set_bgcolor(...e){return this._helper.set_bgcolor(this,...e)}set_border_color(...e){return this._helper.set_border_color(this,...e)}set_border_width(...e){return this._helper.set_border_width(this,...e)}set_frame_color(...e){return this._helper.set_frame_color(this,...e)}set_frame_width(...e){return this._helper.set_frame_width(this,...e)}_defaultCell(){return{text:"",width:0,height:0,text_color:"#000000",text_halign:"center",text_valign:"center",text_size:"normal",bgcolor:"",tooltip:"",text_font_family:"default",_merged:!1,_merge_parent:null}}}class mp{constructor(e){this.context=e}_tables=[];param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__tables__.data=[{time:e,value:this._tables.map(i=>i.toPlotData()),options:{style:"table"}}]}_resolve(e){return e==null?e:typeof e=="object"&&"__value"in e?e.__value:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(...e){let i="top_right",r=1,n=1,a="",s="",o=0,l="",c=0,h=!1;const p=e[e.length-1];if(p&&typeof p=="object"&&!Array.isArray(p)&&("bgcolor"in p||"frame_color"in p||"border_color"in p||"position"in p||"columns"in p||"rows"in p)){const f=p,m=e.slice(0,-1);i=m[0]??f.position??i,r=m[1]??f.columns??r,n=m[2]??f.rows??n,a=f.bgcolor??a,s=f.frame_color??s,o=f.frame_width??o,l=f.border_color??l,c=f.border_width??c,h=f.force_overlay??h}else i=e[0]??i,r=e[1]??r,n=e[2]??n,a=e[3]??a,s=e[4]??s,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h;const u=new dp(this._resolve(i)||"top_right",this._resolve(r)||1,this._resolve(n)||1,this._resolve(a)||"",this._resolve(s)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(h)??!1);return u._setHelper(this),this._tables.push(u),this.syncToPlot(),u}any(...e){return this.new(...e)}cell(...e){let i,r,n,a="",s=0,o=0,l="#000000",c="center",h="center",p="normal",u="",f="",m="default";const x=e[e.length-1];if(x&&typeof x=="object"&&!Array.isArray(x)&&("text"in x||"bgcolor"in x||"text_color"in x||"text_size"in x||"text_halign"in x||"tooltip"in x||"column"in x||"row"in x||"height"in x||"width"in x||"text_valign"in x||"text_font_family"in x)){const w=x,E=e.slice(0,-1);i=E[0],r=E.length>1?E[1]:w.column??0,n=E.length>2?E[2]:w.row??0,a=E[3]??w.text??a,s=E[4]??w.width??s,o=E[5]??w.height??o,l=E[6]??w.text_color??l,c=E[7]??w.text_halign??c,h=E[8]??w.text_valign??h,p=E[9]??w.text_size??p,u=E[10]??w.bgcolor??u,f=E[11]??w.tooltip??f,m=E[12]??w.text_font_family??m}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??a,s=e[4]??s,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h,p=e[9]??p,u=e[10]??u,f=e[11]??f,m=e[12]??m;const _=this._resolve(i);if(!_||_._deleted)return;const b=this._resolve(r)??0,v=this._resolve(n)??0;_.setCell(b,v,{text:this._resolveText(this._resolve(a)),width:this._resolve(s)||0,height:this._resolve(o)||0,text_color:this._resolve(l)||"#000000",text_halign:this._resolve(c)||"center",text_valign:this._resolve(h)||"center",text_size:this._resolve(p)||"normal",bgcolor:this._resolve(u)||"",tooltip:this._resolveText(this._resolve(f)),text_font_family:this._resolve(m)||"default"}),this.syncToPlot()}delete(e){e&&(e._deleted=!0)}clear(...e){let i,r,n,a,s;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:r),s=f.end_row??(e.length>5?e[4]:n)}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??r,s=e[4]??n;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(n)??0,p=this._resolve(a)??c,u=this._resolve(s)??h;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)l.clearCell(m,f);this.syncToPlot()}merge_cells(...e){let i,r,n,a,s;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:0),s=f.end_row??(e.length>5?e[4]:0)}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??0,s=e[4]??0;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(n)??0,p=this._resolve(a)??0,u=this._resolve(s)??0;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)f===h&&m===c||l.setCell(m,f,{_merged:!0,_merge_parent:[c,h]});l.merges.push({startCol:c,startRow:h,endCol:p,endRow:u}),this.syncToPlot()}cell_set_text(e,i,r,n){this._setCellProp(e,i,r,"text",n,!0)}cell_set_bgcolor(e,i,r,n){this._setCellProp(e,i,r,"bgcolor",n)}cell_set_text_color(e,i,r,n){this._setCellProp(e,i,r,"text_color",n)}cell_set_text_size(e,i,r,n){this._setCellProp(e,i,r,"text_size",n)}cell_set_height(e,i,r,n){this._setCellProp(e,i,r,"height",n)}cell_set_width(e,i,r,n){this._setCellProp(e,i,r,"width",n)}cell_set_tooltip(e,i,r,n){this._setCellProp(e,i,r,"tooltip",n,!0)}cell_set_text_halign(e,i,r,n){this._setCellProp(e,i,r,"text_halign",n)}cell_set_text_valign(e,i,r,n){this._setCellProp(e,i,r,"text_valign",n)}cell_set_text_font_family(e,i,r,n){this._setCellProp(e,i,r,"text_font_family",n)}set_position(e,i){const r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(i)||r.position,this.syncToPlot())}set_bgcolor(e,i){const r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(i)||"",this.syncToPlot())}set_border_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(i)||"",this.syncToPlot())}set_border_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(i)||0,this.syncToPlot())}set_frame_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(i)||"",this.syncToPlot())}set_frame_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(i)||0,this.syncToPlot())}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,i,r,n,a,s=!1){const o=this._resolve(e);if(!o||o._deleted)return;const l=this._resolve(i)??0,c=this._resolve(r)??0,h=this._resolve(a);o.setCell(l,c,{[n]:s?this._resolveText(h):h}),this.syncToPlot()}_resolveText(e){return e==null||e!==e?"":String(e)}}class Qe{data={open:new y([]),high:new y([]),low:new y([]),close:new y([]),volume:new y([]),hl2:new y([]),hlc3:new y([]),ohlc4:new y([]),hlcc4:new y([]),bar_index:new y([])};indicator;cache={};taState={};isSecondaryContext=!1;chartTimezone=null;dataVersion=0;__maxLoops=5e5;NA=NaN;warnings=[];alerts=[];_alertMode="realtime";_execTick=0;warn(e,i){this.warnings.push({message:e,method:i,bar:this.idx})}lang;length=0;_drawingHelpers=[];pine;static _deprecationWarningsShown=new Set;idx=0;params={};const={};var={};let={};lctx=new Map;result=void 0;plots={};marketData;source;tickerId;timeframe="";limit;sDate;eDate;fullContext;pineTSCode;inputs={};constructor({marketData:e,source:i,tickerId:r,timeframe:n,limit:a,sDate:s,eDate:o,fullContext:l,inputs:c}){this.marketData=e,this.source=i,this.tickerId=r,this.timeframe=n,this.limit=a,this.sDate=s,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};const h=new Zl(this),p={Type:h.Type.bind(h),na:new _t,nz:h.nz.bind(h),indicator:h.indicator.bind(h),fixnan:h.fixnan.bind(h),alertcondition:h.alertcondition.bind(h),alert:new Ql(this),error:h.error.bind(h),max_bars_back:h.max_bars_back.bind(h),timestamp:h.timestamp.bind(h),time:new or(this,"openTime"),time_close:new or(this,"closeTime"),dayofmonth:new We(this,Ue.dayofmonth),dayofweek:new We(this,Ue.dayofweek),hour:new We(this,Ue.hour),minute:new We(this,Ue.minute),month:new We(this,Ue.month),second:new We(this,Ue.second),weekofyear:new We(this,Ue.weekofyear),year:new We(this,Ue.year),bool:h.bool.bind(h),int:h.int.bind(h),float:h.float.bind(h),string:h.string.bind(h)},u=this;this.pine={input:new Ec(this),ta:new Su(this),math:new nh(this),request:new ch(this),array:new Do(this),map:new zo(this),matrix:new Ul(this),syminfo:null,timeframe:new ku(this),barstate:new ql(this),get bar_index(){return u.data.bar_index},get last_bar_index(){return u.data.close.length-1},get last_bar_time(){return u.data.openTime.get(u.data.openTime.length-1)},get timenow(){return new Date().getTime()},get time_tradingday(){const $=y.from(u.data.closeTime).get(0);if(isNaN($))return NaN;const B=u.pine?.syminfo?.timezone||"UTC",R=dt($,B);return Date.UTC(R.year,R.month-1,R.day,0,0,0)},get inputs(){return u.inputs},log:new Cu(this),str:new Iu(this),...p,...ho};const f=p.dayofweek;Object.assign(f,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=f;const m=new zu(this),x=new Ku(this),_=new Hu(this);this.bindContextObject(m,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(m,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(x,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(_,["any","param"],"fill");const b=new Gu(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),is_standard:b.is_standard.bind(b),is_heikinashi:b.is_heikinashi.bind(b),is_kagi:b.is_kagi.bind(b),is_linebreak:b.is_linebreak.bind(b),is_pnf:b.is_pnf.bind(b),is_range:b.is_range.bind(b),is_renko:b.is_renko.bind(b),point:b.point};const v=new Zu(this);this.bindContextObject(v,["any","new","param","set_x","set_y","set_xy","set_text","set_color","set_textcolor","set_size","set_style","set_textalign","set_tooltip","set_point","set_xloc","set_yloc","get_x","get_y","get_text","copy","delete","style_label_down","style_label_up","style_label_left","style_label_right","style_label_lower_left","style_label_lower_right","style_label_upper_left","style_label_upper_right","style_label_center","style_circle","style_square","style_diamond","style_flag","style_arrowup","style_arrowdown","style_cross","style_xcross","style_triangleup","style_triangledown","style_none","style_text_outline"],"label"),Object.defineProperty(this.pine.label,"all",{get:()=>v.all});const w=new ip(this);this.bindContextObject(w,["any","new","param","set_x1","set_y1","set_x2","set_y2","set_xy1","set_xy2","set_color","set_width","set_style","set_extend","set_xloc","set_first_point","set_second_point","get_x1","get_y1","get_x2","get_y2","get_price","copy","delete","style_solid","style_dotted","style_dashed","style_arrow_left","style_arrow_right","style_arrow_both"],"line"),Object.defineProperty(this.pine.line,"all",{get:()=>w.all});const E=new ap(this);this.bindContextObject(E,["any","new","param","copy","delete","set_left","set_right","set_top","set_bottom","set_lefttop","set_rightbottom","set_top_left_point","set_bottom_right_point","set_bgcolor","set_border_color","set_border_width","set_border_style","set_extend","set_xloc","set_text","set_text_color","set_text_size","set_text_halign","set_text_valign","set_text_wrap","set_text_font_family","set_text_formatting","get_left","get_right","get_top","get_bottom"],"box"),Object.defineProperty(this.pine.box,"all",{get:()=>E.all});const A=new cp(this);this.bindContextObject(A,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>A.all});const C=new pp(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>C.all});const M=new mp(this);this.bindContextObject(M,["any","new","param","cell","delete","clear","merge_cells","cell_set_text","cell_set_bgcolor","cell_set_text_color","cell_set_text_size","cell_set_height","cell_set_width","cell_set_tooltip","cell_set_text_halign","cell_set_text_valign","cell_set_text_font_family","set_position","set_bgcolor","set_border_color","set_border_width","set_frame_color","set_frame_width"],"table"),Object.defineProperty(this.pine.table,"all",{get:()=>M.all}),this._drawingHelpers=[v,w,E,A,C,M];const O=new ec(this);this.bindContextObject(O,["any","param","new","rgb","from_gradient","r","g","b","t","aqua","black","blue","fuchsia","gray","green","lime","maroon","navy","olive","orange","purple","red","silver","teal","white","yellow"],"color")}rollbackDrawings(e){for(const i of this._drawingHelpers)i.rollbackFromBar(e)}bindContextObject(e,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const n=r?this.pine[r]:this.pine;for(const a of i)typeof e[a]=="function"?n[a]=e[a].bind(e):n[a]=e[a]}init(e,i,r=0){let n;return i instanceof y?n=i.get(0):Array.isArray(i)?Array.isArray(i[0])?n=i[0]:n=i[i.length-1+r]:n=i,e?e instanceof y?(e.data[e.data.length-1]=n,e):Array.isArray(e)?(e[e.length-1]=n,new y(e)):new y([n]):new y([n])}initVar(e,i){if(e)return e;if(typeof i=="function"&&(i=i()),i instanceof ht){const n=i.__def__;for(const a in n)typeof i[a]=="function"&&(i[a]=i[a]())}let r;return i instanceof y?r=i.get(0):Array.isArray(i)?Array.isArray(i[0])?r=i[0]:r=this.precision(i[i.length-1]):r=this.precision(i),new y([r])}static PRECISION_EPSILON=10**10;precision(e,i=10){const r=i===10?Qe.PRECISION_EPSILON:10**i;return typeof e=="number"?Math.round(e*r)/r:e}param(e,i,r){return typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new y(e,i||0):(this.params[r].length===0?this.params[r].push(e):this.params[r][this.params[r].length-1]=e,new y(this.params[r],i||0)))}get(e,i){if(e instanceof y)return e.get(i);if(Array.isArray(e)){const r=e.length-1-i;return r<0||r>=e.length?NaN:e[r]}return e}set(e,i){if(e instanceof y){e.set(0,typeof i=="number"?this.precision(i):i);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=i:e.push(i);return}}_callStack=[];pushId(e){this._callStack.push(e)}popId(){this._callStack.pop()}peekId(){return this._callStack.length>0?this._callStack[this._callStack.length-1]:""}peekCtx(){const e=this.peekId();if(!e)return this;let i=this.lctx.get(e);return i||(i={id:e,let:{},const:{},var:{}},this.lctx.set(e,i)),i}call(e,i,...r){this.pushId(i);try{return e(...r)}finally{this.popId()}}get math(){return this._showDeprecationWarning("const math = context.math","const { math, ta, input } = context.pine"),this.pine.math}get ta(){return this._showDeprecationWarning("const ta = context.ta","const { ta, math, input } = context.pine"),this.pine.ta}get input(){return this._showDeprecationWarning("const input = context.input","const { input, math, ta } = context.pine"),this.pine.input}get request(){return this._showDeprecationWarning("const request = context.request","const { request, math, ta } = context.pine"),this.pine.request}get array(){return this._showDeprecationWarning("const array = context.array","const { array, math, ta } = context.pine"),this.pine.array}get core(){return this._showDeprecationWarning("context.core.*","context.pine (e.g., const { na, plotchar, color, plot, nz } = context.pine)"),{na:this.pine.na,fill:this.pine.fill,plotchar:this.pine.plotchar,plotshape:this.pine.plotshape,plotarrow:this.pine.plotarrow,color:this.pine.color,plot:this.pine.plot,nz:this.pine.nz}}_showDeprecationWarning(e,i){const r=`${e}->${i}`;Qe._deprecationWarningsShown.has(r)||(Qe._deprecationWarningsShown.add(r),typeof window<"u"?console.warn("%c[WARNING]%c %s syntax is deprecated. Use %s instead. This will be removed in a future version.","color: #FFA500; font-weight: bold;","color: #FFA500;",e,i):console.warn(`\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}}class _i{source;inputs;constructor(e,i={}){this.source=e,this.inputs=i}}const fr={1:6e4,3:18e4,5:3e5,15:9e5,30:18e5,60:36e5,120:72e5,180:108e5,240:144e5,"4H":144e5,"1D":864e5,D:864e5,"1W":6048e5,W:6048e5,"1M":30*864e5,M:30*864e5};function gp(t){return t?fr[t]??fr[t.toUpperCase()]??864e5:864e5}class Vi{constructor(e,i,r,n,a,s){this.source=e,this.tickerId=i,this.timeframe=r,this.limit=n,this.sDate=a,this.eDate=s,this._readyPromise=new Promise(o=>{this.loadMarketData(e,i,r,n,a,s).then(l=>{const c=l;this.data=c;const h=c.map(C=>C.open),p=c.map(C=>C.close),u=c.map(C=>C.high),f=c.map(C=>C.low),m=c.map(C=>C.volume),x=c.map(C=>(C.high+C.low+C.close)/3),_=c.map(C=>(C.high+C.low)/2),b=c.map(C=>(C.high+C.low+C.open+C.close)/4),v=c.map(C=>(C.high+C.low+C.close+C.close)/4),w=c.map(C=>C.openTime),E=gp(this.timeframe),A=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+E);this.open=h,this.close=p,this.high=u,this.low=f,this.volume=m,this.hl2=_,this.hlc3=x,this.ohlc4=b,this.hlcc4=v,this.openTime=w,this.closeTime=A,e&&e.getSymbolInfo?e.getSymbolInfo(i).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}data=[];open=[];high=[];low=[];close=[];volume=[];hl2=[];hlc3=[];ohlc4=[];hlcc4=[];openTime=[];closeTime=[];_readyPromise=null;_ready=!1;_debugSettings={ln:!1,debug:!1};_transpiledCode=null;get transpiledCode(){return this._transpiledCode}_isSecondaryContext=!1;markAsSecondary(){this._isSecondaryContext=!0}_syminfo;_chartTimezone=null;setTimezone(e){this._chartTimezone=e}_maxLoops=5e5;setMaxLoops(e){this._maxLoops=e}_alertMode="realtime";setAlertMode(e){this._alertMode=e}setDebugSettings({ln:e,debug:i}){this._debugSettings.ln=e,this._debugSettings.debug=i}async loadMarketData(e,i,r,n,a,s){return Array.isArray(e)?e:e.getMarketData(i,r,n,a,s)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,i,r){let n,a={};if(e instanceof _i?(n=e.source,a=e.inputs||{}):n=e,r&&r>0){const s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(n,a,i,r,s)}else return this._runComplete(n,a,i)}stream(e,i={}){const{live:r=!0,interval:n=1e3}=i,a=i.pageSize||this.data.length;let s,o={};e instanceof _i?(s=e.source,o=e.inputs||{}):s=e;const l={data:[],error:[],warning:[],alert:[]};let c=!1;const h=(f,...m)=>{l[f]&&l[f].forEach(x=>x(...m))},p=(f,m)=>{l[f]||(l[f]=[]),l[f].push(m)},u=()=>{c=!0};return(async()=>{try{const f=typeof this.eDate>"u"&&!Array.isArray(this.source)&&r,m=this._runPaginated(s,o,void 0,a,f);for await(const x of m){if(c)break;if(x===null){await new Promise(_=>setTimeout(_,n));continue}if(h("data",x),x.warnings&&x.warnings.length>0){for(const _ of x.warnings)h("warning",_);x.warnings.length=0}if(x.alerts&&x.alerts.length>0){for(const _ of x.alerts)h("alert",_);x.alerts.length=0}if(f&&!c){const _=x.marketData[x.idx],b=_&&_.closeTime<Date.now(),v=x.idx>=x.marketData.length-1;(!b||v)&&await new Promise(w=>setTimeout(w,n))}}}catch(f){h("error",f)}})(),{on:p,stop:u}}async _runComplete(e,i,r){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(e,i,this._isSecondaryContext);return this._transpiledCode=this._transpileCode(e),await this._executeIterations(n,this._transpiledCode,this.data.length-r,this.data.length),n}async*_runPaginated(e,i,r,n,a=!1){await this.ready(),r||(r=this.data.length);const s=this._initializeContext(e,i,this._isSecondaryContext);this._transpiledCode=this._transpileCode(e);let o=this.data.length-r;for(;;){const l=this.data.length-o;if(l>0){const f=Math.min(l,n),m=this._getResultLength(s.result);await this._executeIterations(s,this._transpiledCode,o,o+f),o+=f,yield this._createPageContext(s,m);continue}if(!a||Array.isArray(this.source))break;const c=Date.now(),{newCandles:h,updatedLastCandle:p}=await this._updateMarketData(),u=Date.now()-c;if(h===0&&!p){yield null;continue}h===0&&p&&u<1e3&&await new Promise(f=>setTimeout(f,1e3-u)),s.dataVersion++,s.length=this.data.length,this._removeLastResult(s),o=this.data.length-(h+1),s.rollbackDrawings(o),s.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const i=Object.keys(e);if(i.length>0&&Array.isArray(e[i[0]]))return e[i[0]].length}return 0}_createPageContext(e,i){const r=new Qe({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:e,inputs:e.inputs});if(r.pineTSCode=e.pineTSCode,r.idx=e.idx,Array.isArray(e.result))r.result=e.result.slice(i);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let n in e.result)Array.isArray(e.result[n])?r.result[n]=e.result[n].slice(i):r.result[n]=e.result[n]}else r.result=e.result;return r.plots={...e.plots},r.warnings=e.warnings,r.alerts=e.alerts,r}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const i=this.source,r=this.data.length-1,n=this.data[r].openTime;try{const a=await i.getMarketData(this.tickerId,this.timeframe,void 0,n,e);if(!a||a.length===0)return{newCandles:0,updatedLastCandle:!1};let s=!1,o=0;for(let l=0;l<a.length;l++){const c=a[l];c.openTime===n?(this._replaceCandle(r,c),s=!0):c.openTime>n&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:s}}catch(a){return console.error("Error updating market data:",a),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,i){this.data[e]=i,this.open[e]=i.open,this.close[e]=i.close,this.high[e]=i.high,this.low[e]=i.low,this.volume[e]=i.volume,this.hl2[e]=(i.high+i.low)/2,this.hlc3[e]=(i.high+i.low+i.close)/3,this.ohlc4[e]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[e]=(i.high+i.low+i.close+i.close)/4,this.openTime[e]=i.openTime,this.closeTime[e]=i.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;const{newCandles:i,updatedLastCandle:r}=await this._updateMarketData();if(i===0&&!r)return!1;this._removeLastResult(e),e.length=this.data.length;const n=this.data.length-(i+1);return e.rollbackDrawings(n),await this._executeIterations(e,this._transpiledCode,n,this.data.length),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let n in e.result)Array.isArray(e.result[n])&&e.result[n].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();const i=["const","var","let","params"],r=n=>{for(let a of i)if(n[a])for(let s in n[a]){const o=n[a][s];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(n=>r(n))}_initializeContext(e,i={},r=!1){const n=new Qe({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:i});return n.pine.syminfo=this._syminfo,this._chartTimezone&&(n.chartTimezone=this._chartTimezone),n.__maxLoops=this._maxLoops,n._alertMode=this._alertMode,n.pineTSCode=e,n.isSecondaryContext=r,n.data.close=new y([]),n.data.open=new y([]),n.data.high=new y([]),n.data.low=new y([]),n.data.volume=new y([]),n.data.hl2=new y([]),n.data.hlc3=new y([]),n.data.ohlc4=new y([]),n.data.hlcc4=new y([]),n.data.openTime=new y([]),n.data.closeTime=new y([]),n.length=this.data.length,n}_transpileCode(e){return Na.bind(this)(e,this._debugSettings)}async _executeIterations(e,i,r,n){const a=["const","var","let","params"];for(let s=r;s<n;s++){e.idx=s,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[s]),e.data.open.data.push(this.open[s]),e.data.high.data.push(this.high[s]),e.data.low.data.push(this.low[s]),e.data.volume.data.push(this.volume[s]),e.data.hl2.data.push(this.hl2[s]),e.data.hlc3.data.push(this.hlc3[s]),e.data.ohlc4.data.push(this.ohlc4[s]),e.data.hlcc4.data.push(this.hlcc4[s]),e.data.openTime.data.push(this.openTime[s]),e.data.closeTime.data.push(this.closeTime[s]),e.data.bar_index.data.push(s);const o=await i(e);if(typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let h;o[c]instanceof y?h=o[c].get(0):Array.isArray(o[c])?h=o[c][o[c].length-1]:h=o[c],e.result[c].push(h)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(const c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();const l=c=>{for(let h of a)if(c[h])for(let p in c[h]){const u=c[h][p];if(u instanceof y){const f=u.get(0);u.data.push(f)}else if(Array.isArray(u)){const f=u[u.length-1];u.push(f)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}}}const dr={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},ut={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3},yp={"1S":{periodType:"second",multiplier:1},"5S":{periodType:"second",multiplier:5},"10S":{periodType:"second",multiplier:10},"15S":{periodType:"second",multiplier:15},"30S":{periodType:"second",multiplier:30},1:{periodType:"minute",multiplier:1},3:{periodType:"minute",multiplier:3},5:{periodType:"minute",multiplier:5},15:{periodType:"minute",multiplier:15},30:{periodType:"minute",multiplier:30},45:{periodType:"minute",multiplier:45},60:{periodType:"hour",multiplier:1},120:{periodType:"hour",multiplier:2},180:{periodType:"hour",multiplier:3},240:{periodType:"hour",multiplier:4},D:{periodType:"day",multiplier:1},W:{periodType:"week",multiplier:1},M:{periodType:"month",multiplier:1}};function pt(t,e,i=1){if(e==="month"){const n=new Date(t);return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+i,1,n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}const r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+i*r[e]}function Ce(t,e,i){const[r,n,a]=t.split("-").map(Number),[s,o]=e.split(":").map(Number),l=Date.UTC(r,n-1,a,s,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(l)),h=b=>parseInt(c.find(v=>v.type===b).value,10);let p=h("year"),u=h("month"),f=h("day"),m=h("hour");m===24&&(m=0);let x=h("minute");const _=Date.UTC(p,u-1,f,m,x,0,0)-l;return l-_}function bi(t,e,i,r,n=1){if(e==="24x7")return pt(t,r,n);const a=e.split("-")[1];if(!a||a.length!==4)return pt(t,r,n);const s=a.slice(0,2),o=a.slice(2,4),l=`${s}:${o}`,c=mr(t,i);if(r==="second"||r==="minute"||r==="hour"){const h=t+n*{second:1e3,minute:6e4,hour:36e5}[r],p=Ce(c,l,i);return Math.min(h,p)}if(r==="day")return Ce(c,l,i);if(r==="week"){const h=new Date(t).getUTCDay(),p=h<=5?5-h:5-h+7,u=t+p*864e5,f=mr(u,i);return Ce(f,l,i)}if(r==="month"){const h=new Date(t),p=h.getUTCFullYear(),u=h.getUTCMonth()+n,f=new Date(Date.UTC(p,u,1)),m=new Date(f.getTime()-864e5);for(;m.getUTCDay()===0||m.getUTCDay()===6;)m.setUTCDate(m.getUTCDate()-1);const x=m.toISOString().split("T")[0];return Ce(x,l,i)}return pt(t,r,n)}function mr(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function xp(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}const _p=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function Ln(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;const i=ut[t];if(!i)return null;const r=_p.filter(n=>n!=="W"&&n!=="M"&&e.has(n)&&ut[n]<i&&i%ut[n]===0);return r.length===0?null:r[r.length-1]}function Oi(t,e){if(t==="W"||t==="M")return 1/0;const i=ut[t],r=ut[e];return!i||!r||r===0?1/0:i/r}function jn(t,e,i){if(t.length===0)return[];if(e==="W")return wp(t);if(e==="M")return vp(t);const r=Oi(e,i);return bp(t,r)}function bp(t,e){if(t.length===0)return[];const i=[];let r=[t[0]];const n=Sp(t),a=n>0?n*1.5:0;for(let s=1;s<t.length;s++){const o=t[s].openTime-t[s-1].openTime;(a>0&&o>a||r.length>=e)&&(i.push(qt(r)),r=[]),r.push(t[s])}return r.length>0&&i.push(qt(r)),i}function wp(t){const e=[];let i=[],r="";for(const n of t){const a=Ep(n.openTime);a!==r&&i.length>0&&(e.push(i),i=[]),r=a,i.push(n)}return i.length>0&&e.push(i),e.map(qt)}function vp(t){const e=[];let i=[],r="";for(const n of t){const a=new Date(n.openTime),s=`${a.getUTCFullYear()}-${a.getUTCMonth()}`;s!==r&&i.length>0&&(e.push(i),i=[]),r=s,i.push(n)}return i.length>0&&e.push(i),e.map(qt)}function qt(t){const e=t[0],i=t[t.length-1];let r=e.high,n=e.low,a=0,s=0,o=0,l=0,c=0;for(let h=0;h<t.length;h++){const p=t[h];p.high>r&&(r=p.high),p.low<n&&(n=p.low),a+=p.volume,s+=p.quoteAssetVolume,o+=p.numberOfTrades,l+=p.takerBuyBaseAssetVolume,c+=p.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:r,low:n,close:i.close,volume:a,closeTime:i.closeTime,quoteAssetVolume:s,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function Sp(t){if(t.length<2)return 0;const e=Math.min(t.length-1,20);let i=1/0;for(let r=0;r<e;r++){const n=t[r+1].openTime-t[r].openTime;n>0&&n<i&&(i=n)}return i===1/0?0:i}function Ep(t){const e=new Date(t),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1)),n=Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${n}`}const Ot={"1s":"1S","5s":"5S","10s":"10S","15s":"15S","30s":"30S","1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1D":"D","1W":"W","1M":"M","4H":"240",D:"D",W:"W",M:"M"};function Np(t){if(Ot[t]!==void 0)return Ot[t];const e=t.toLowerCase();return Ot[e]!==void 0?Ot[e]:/^\d+$/.test(t)?t:/^\d+S$/i.test(t)?t.toUpperCase():t}class Tt{_configured;_requiresApiKey;_providerName;_aggregationSubTimeframe=null;constructor(e){this._requiresApiKey=e.requiresApiKey,this._providerName=e.providerName,this._configured=!e.requiresApiKey}ensureConfigured(){if(!this._configured)throw new Error(`${this._providerName} requires configuration before use. Call Provider.${this._providerName}.configure({ apiKey: '...' }) or instantiate directly: new ${this._providerName}Provider({ apiKey: '...' })`)}configure(e){this._configured=!0}get isConfigured(){return this._configured}normalizeCloseTime(e){xp(e)}setAggregationSubTimeframe(e){this._aggregationSubTimeframe=e}getSupportedTimeframes(){return new Set(["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"])}async getMarketData(e,i,r,n,a){const s=Np(i),o=this.getSupportedTimeframes();if(o.has(s))return this._getMarketDataNative(e,s,r,n,a);const l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:Ln(s,o);if(!c)return console.error(`${this._providerName}: Timeframe '${i}' is not supported and no valid sub-timeframe found for aggregation.`),[];const h=this._computeSubLimit(s,c,r),p=await this._getMarketDataNative(e,c,h,n,a);if(p.length===0)return[];const u=jn(p,s,c);return r&&r>0&&u.length>r?u.slice(u.length-r):u}_computeSubLimit(e,i,r){if(!r)return;const n=Oi(e,i);return n===1/0?e==="W"?r*7+14:e==="M"?r*31+31:r*30:Math.ceil(r*n)+Math.ceil(n)}}const ai="https://api.binance.com/api/v3",gr="https://api.binance.us/api/v3",Lt={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",45:null,60:"1h",120:"2h",180:null,240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"};class Cp{cache;cacheDuration;constructor(e=300*1e3){this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(e){const i=this.generateKey(e),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(e,i){const r=this.generateKey(e);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[i,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class Bn extends Tt{cacheManager;activeApiUrl=null;constructor(){super({requiresApiKey:!1,providerName:"Binance"}),this.cacheManager=new Cp(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${ai}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=ai,this.activeApiUrl}catch{}try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${gr}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=gr,this.activeApiUrl}catch{}return ai}async _fetchRawChunk(e,i,r,n,a){const s=Lt[i.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${i}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${s}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),n&&(o+=`&startTime=${n}`),a&&(o+=`&endTime=${a}`);const l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,i,r,n){try{const a=Lt[i.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${i}`),[];let s=[],o=r;const l=n,c=dr[a];if(!c)return console.error(`Duration not defined for interval: ${a}`),[];for(;o<l;){const h=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,i,1e3,o,h);if(p.length===0)break;s=s.concat(p),o=p[p.length-1].closeTime+1}return this.normalizeCloseTime(s),s}catch(a){return console.error("Error in getMarketDataInterval:",a),[]}}async getMarketDataBackwards(e,i,r,n){let a=r,s=[],o=n,l=0;const c=Math.ceil(r/1e3)+5;for(;a>0&&l<c;){l++;const h=Math.min(a,1e3),p=await this._fetchRawChunk(e,i,h,void 0,o);if(p.length===0||(s=p.concat(s),a-=p.length,o=p[0].openTime-1,p.length<h))break}return this.normalizeCloseTime(s),s}getSupportedTimeframes(){return new Set(["1","3","5","15","30","60","120","240","D","W","M"])}async _getMarketDataNative(e,i,r,n,a){try{const s=a!==void 0,o={tickerId:e,timeframe:i,limit:r,sDate:n,eDate:a};if(s){const c=this.cacheManager.get(o);if(c)return c}if(!Lt[i.toUpperCase()])return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,n,a)){if(n&&a){const c=await this.getMarketDataInterval(e,i,n,a),h=r?c.slice(0,r):c;return this.cacheManager.set(o,h),h}else if(r&&r>1e3){const c=await this.getMarketDataBackwards(e,i,r,a);return this.cacheManager.set(o,c),c}}const l=await this._fetchRawChunk(e,i,r,n,a);return this.normalizeCloseTime(l),s&&this.cacheManager.set(o,l),l}catch(s){return console.error("Error in binance.klines:",s),[]}}shouldPaginate(e,i,r,n){if(i&&i>1e3)return!0;if(r&&n){const a=Lt[e.toUpperCase()],s=dr[a];if(s)return Math.ceil((n-r)/s)>1e3}return!1}async getSymbolInfo(e){try{let i="crypto",r=await this.getBaseUrl(),n=e,a="";e.endsWith(".P")?(i="futures",n=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",a="Perpetual"):e.includes("_")&&(i="futures",n=e,r="https://dapi.binance.com/dapi/v1",a="Delivery");const s=i==="crypto"?`${r}/exchangeInfo?symbol=${n}`:`${r}/exchangeInfo`,o=await fetch(s);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;const c=i==="futures"?l.find(w=>w.symbol===n):l[0];if(!c)return console.error(`Symbol ${n} not found in exchange info`),null;const h=c.filters?.find(w=>w.filterType==="PRICE_FILTER"),p=c.filters?.find(w=>w.filterType==="LOT_SIZE"),u=h?parseFloat(h.tickSize):.01,f=p?parseFloat(p.minQty):0,m=Math.round(1/u),x=c.baseAsset,_=c.quoteAsset,b=a?` ${a}`:"",v=`${x} / ${_}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:x,description:v,type:i,main_tickerid:`BINANCE:${e}`,current_contract:a,isin:"",basecurrency:x,currency:_,timezone:"Etc/UTC",country:"",mintick:u,pricescale:m,minmove:1,pointvalue:c.contractSize||1,mincontract:f,session:"24x7",volumetype:"base",expiration_date:c.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in binance.exchangeInfo:",i),null}}}const Ip="https://financialmodelingprep.com",yr={"1D":{endpoint:"/stable/historical-price-eod/full",type:"daily"},D:{endpoint:"/stable/historical-price-eod/full",type:"daily"},1:{endpoint:"/stable/historical-chart/1min",interval:"1min",type:"intraday"},5:{endpoint:"/stable/historical-chart/5min",interval:"5min",type:"intraday"},15:{endpoint:"/stable/historical-chart/15min",interval:"15min",type:"intraday"},30:{endpoint:"/stable/historical-chart/30min",interval:"30min",type:"intraday"},60:{endpoint:"/stable/historical-chart/1hour",interval:"1hour",type:"intraday"},240:{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"},"4H":{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"}},xr={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",NYSEArca:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",PNK:"America/New_York",TSX:"America/Toronto",TSXV:"America/Toronto",LSE:"Europe/London",EURONEXT:"Europe/Paris",XETRA:"Europe/Berlin",JPX:"Asia/Tokyo",HKSE:"Asia/Hong_Kong",SSE:"Asia/Shanghai",SHZ:"Asia/Shanghai",ASX:"Australia/Sydney",NSE:"Asia/Kolkata",BSE:"Asia/Kolkata",KRX:"Asia/Seoul",CRYPTO:"Etc/UTC"},_r={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",NYSEArca:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",PNK:"0930-1600",TSX:"0930-1600",TSXV:"0930-1600",LSE:"0800-1630",EURONEXT:"0900-1730",XETRA:"0900-1730",JPX:"0900-1530",HKSE:"0930-1600",SSE:"0930-1500",SHZ:"0930-1500",ASX:"1000-1600",NSE:"0915-1530",BSE:"0915-1530",KRX:"0900-1530",CRYPTO:"24x7"},kp={daily:{periodType:"day",multiplier:1},"1min":{periodType:"minute",multiplier:1},"5min":{periodType:"minute",multiplier:5},"15min":{periodType:"minute",multiplier:15},"30min":{periodType:"minute",multiplier:30},"1hour":{periodType:"hour",multiplier:1},"4hour":{periodType:"hour",multiplier:4}};class Fn extends Tt{_apiKey=null;_baseUrl=Ip;_profileCache=new Map;constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),e?.apiKey&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,e.baseUrl&&(this._baseUrl=e.baseUrl)}getSupportedTimeframes(){return new Set(["1","5","15","30","60","240","D"])}async _getMarketDataNative(e,i,r,n,a){this.ensureConfigured();try{const s=i.toUpperCase(),o=yr[s]||yr[i];return o?o.type==="intraday"?this._fetchIntradayData(e,o.endpoint,o.interval,n,a,r):this._fetchDailyData(e,n,a,r):(console.error(`FMP: Unsupported timeframe: ${i}`),[])}catch(s){return console.error("Error in FMPProvider.getMarketData:",s),[]}}async _fetchDailyData(e,i,r,n){let a=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;i&&(a+=`&from=${this._msToDateStr(i)}`),r&&(a+=`&to=${this._msToDateStr(r)}`);const s=await fetch(a);if(!s.ok){const p=await s.text();throw new Error(`FMP HTTP ${s.status}: ${p}`)}const o=await s.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();const l=n&&n>0&&n<o.length?o.slice(o.length-n):o,{session:c,timezone:h}=await this._resolveSessionInfo(e);return l.map(p=>{const u=this._dateStrToMs(p.date),f=bi(u,c,h,"day");return{openTime:u,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:f,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,i,r,n,a,s){let o=`${this._baseUrl}${i}?symbol=${e}&apikey=${this._apiKey}`;n&&(o+=`&from=${this._msToDateStr(n)}`),a&&(o+=`&to=${this._msToDateStr(a)}`);const l=await fetch(o);if(!l.ok){const x=await l.text();if(l.status===403||x.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${r}) requires a paid plan. Use daily timeframe ('D') with a free API key, or upgrade at https://financialmodelingprep.com/`),[];throw new Error(`FMP HTTP ${l.status}: ${x}`)}const c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();const h=s&&s>0&&s<c.length?c.slice(c.length-s):c,{periodType:p,multiplier:u}=kp[r]||{periodType:"minute",multiplier:1},{session:f,timezone:m}=await this._resolveSessionInfo(e);return h.map(x=>{const _=this._dateTimeStrToMs(x.date),b=bi(_,f,m,p,u);return{openTime:_,open:x.open,high:x.high,low:x.low,close:x.close,volume:x.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchProfile(e);if(!i)return console.error(`FMP: Symbol ${e} not found`),null;const r=i.exchange||"",n=xr[r]||"America/New_York",a=_r[r]||"0930-1600";let s="stock";return i.isEtf?s="etf":i.isFund?s="fund":this._isCrypto(e)?s="crypto":this._isForex(e)&&(s="forex"),{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:i.symbol,description:i.companyName||i.symbol,type:s,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:i.isin||"",basecurrency:i.currency||"USD",currency:i.currency||"USD",timezone:s==="crypto"?"Etc/UTC":n,country:i.country||"",mintick:.01,pricescale:100,minmove:1,pointvalue:1,mincontract:0,session:s==="crypto"?"24x7":a,volumetype:"base",expiration_date:0,employees:parseInt(i.fullTimeEmployees)||0,industry:i.industry||"",sector:i.sector||"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in FMPProvider.getSymbolInfo:",i),null}}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);const i=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(i);if(!r.ok)return null;const n=await r.json();if(!Array.isArray(n)||n.length===0)return null;const a=n[0];return this._profileCache.set(e,a),a}async _resolveSessionInfo(e){try{const i=await this._fetchProfile(e);if(i){const r=i.exchange||"",n=this._isCrypto(e),a=n?"Etc/UTC":xr[r]||"America/New_York";return{session:n?"24x7":_r[r]||"0930-1600",timezone:a}}}catch{}return{session:"0930-1600",timezone:"America/New_York"}}_msToDateStr(e){return new Date(e).toISOString().split("T")[0]}_dateStrToMs(e){return new Date(e+"T00:00:00Z").getTime()}_dateTimeStrToMs(e){return new Date(e.replace(" ","T")+"Z").getTime()}_isCrypto(e){return/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=10}_isForex(e){return/^[A-Z]{6}$/.test(e)&&!this._isCrypto(e)}}const Ap="https://data.alpaca.markets",Tp="https://paper-api.alpaca.markets/v2",Pp="https://api.alpaca.markets/v2",oi=1e4,br={1:"1Min",3:"3Min",5:"5Min",15:"15Min",30:"30Min",60:"1Hour",120:"2Hour",240:"4Hour","4H":"4Hour","1D":"1Day",D:"1Day","1W":"1Week",W:"1Week","1M":"1Month",M:"1Month"},Dp={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",ARCA:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",CRYPTO:"Etc/UTC"},Mp={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},Rp={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"};class $n extends Tt{_apiKey=null;_apiSecret=null;_dataUrl=Ap;_tradingUrl=Tp;_feed=null;_assetCache=new Map;_calendarCache=new Map;constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),e?.apiKey&&e?.apiSecret&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,this._apiSecret=e.apiSecret,e.feed&&(this._feed=e.feed),e.dataUrl&&(this._dataUrl=e.dataUrl),e.tradingUrl?this._tradingUrl=e.tradingUrl:e.paper===!1&&(this._tradingUrl=Pp)}_headers(){return{"APCA-API-KEY-ID":this._apiKey,"APCA-API-SECRET-KEY":this._apiSecret}}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,n,a){this.ensureConfigured();try{const s=this._resolveTimeframe(i);if(!s)return console.error(`Alpaca: Unsupported timeframe: ${i}`),[];const o=this._isCrypto(e),l=await this._fetchAllBars(e,s,o,n,a,r);if(l.length===0)return[];const{periodType:c,multiplier:h}=this._parseAlpacaTimeframe(s);if(o)return this._convertBarsCrypto(l,c,h);const p=l[0].t.slice(0,10),u=l[l.length-1].t.slice(0,10),f=this._addDaysToDate(u,40);return await this._ensureCalendar(p,f),this._convertBarsStock(l,c,h)}catch(s){return console.error("Error in AlpacaProvider.getMarketData:",s),[]}}async _fetchAllBars(e,i,r,n,a,s){const o=[];let l=null;const c=s||1/0,h=Math.min(s||oi,oi);do{const p=this._buildBarsUrl(e,i,r,n,a,h,l),u=await fetch(p,{headers:this._headers()});if(!u.ok){const x=await u.text();throw new Error(`Alpaca HTTP ${u.status}: ${x}`)}const f=await u.json(),m=Object.keys(f.bars||{})[0];if(!m||!f.bars[m]||(o.push(...f.bars[m]),l=f.next_page_token,o.length>=c))break}while(l);return s&&s>0&&o.length>s?o.slice(0,s):o}_buildBarsUrl(e,i,r,n,a,s,o){const l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",i),c.set("sort","asc"),n&&c.set("start",new Date(n).toISOString()),a&&c.set("end",new Date(a).toISOString()),s&&c.set("limit",String(Math.min(s,oi))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchAsset(e);if(!i)return console.error(`Alpaca: Symbol ${e} not found`),null;const r=i.exchange||"",n=i.class==="crypto",a=n?"Etc/UTC":Dp[r]||"America/New_York",s=n?"24x7":Mp[r]||"0930-1600";let o="stock";n&&(o="crypto");const l=n&&e.split("/")[1]||"USD",c=n?e.split("/")[0]||e:l,h=i.price_increment?parseFloat(i.price_increment):.01,p=Math.round(1/h);return{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:n?e.split("/")[0]:i.symbol,description:i.name||i.symbol,type:o,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:a,country:n?"":"US",mintick:h,pricescale:p,minmove:1,pointvalue:1,mincontract:i.min_order_size?parseFloat(i.min_order_size):0,session:s,volumetype:"base",expiration_date:0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in AlpacaProvider.getSymbolInfo:",i),null}}_convertBarsCrypto(e,i,r){return e.map((n,a,s)=>{const o=new Date(n.t).getTime(),l=a<s.length-1?new Date(s[a+1].t).getTime():pt(o,i,r);return this._toKline(n,o,l)})}_convertBarsStock(e,i,r){const n="America/New_York";return e.map(a=>{const s=new Date(a.t).getTime(),o=a.t.slice(0,10);let l;if(i==="day"){const c=this._calendarCache.get(o),h=c?c.close:"16:00";l=Ce(o,h,n)}else if(i==="minute"||i==="hour"){const c=s+r*{minute:6e4,hour:36e5}[i],h=this._calendarCache.get(o),p=h?h.close:"16:00",u=Ce(o,p,n);l=Math.min(c,u)}else i==="week"?l=this._weeklyCloseFromCalendar(o,n):i==="month"?l=this._monthlyCloseFromCalendar(o,n):l=pt(s,i,r);return this._toKline(a,s,l)})}_toKline(e,i,r){return{openTime:i,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:r,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,i){const r=new Date(e+"T00:00:00Z"),n=r.getUTCDay(),a=n<=5?5-n:5-n+7;for(let l=a;l>=0;l--){const c=r.getTime()+l*864e5,h=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(h);if(p)return Ce(h,p.close,i)}const s=r.getTime()+a*864e5,o=new Date(s).toISOString().split("T")[0];return Ce(o,"16:00",i)}_monthlyCloseFromCalendar(e,i){const[r,n]=e.split("-").map(Number),a=new Date(Date.UTC(r,n,0)).getUTCDate();for(let o=a;o>=1;o--){const l=`${r}-${String(n).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return Ce(l,c.close,i)}const s=new Date(Date.UTC(r,n,0));for(;s.getUTCDay()===0||s.getUTCDay()===6;)s.setUTCDate(s.getUTCDate()-1);return Ce(s.toISOString().split("T")[0],"16:00",i)}async _ensureCalendar(e,i){if(this._calendarCache.has(e)&&this._calendarCache.has(i))return;const r=`${this._tradingUrl}/calendar?start=${e}&end=${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok){console.warn(`Alpaca calendar API returned ${n.status}, falling back to defaults`);return}const a=await n.json();for(const s of a)this._calendarCache.set(s.date,s)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);const i=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok)return null;const a=await n.json();return this._assetCache.set(e,a),a}_parseAlpacaTimeframe(e){const i=e.match(/^(\d+)(Min|Hour|Day|Week|Month)$/);if(i){const r=parseInt(i[1],10),n=Rp[i[2]];if(n)return{periodType:n,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return br[e.toUpperCase()]||br[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,i){const r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+i),r.toISOString().split("T")[0]}}const Vp=qn.fileURLToPath(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||new URL("pinets.min.cjs",document.baseURI).href),Op=vt.dirname(Vp);class Lp extends Tt{dataCache=new Map;exchangeInfoCache={};dataDirectory;constructor(e){super({requiresApiKey:!1,providerName:"Mock"});const i=typeof e=="string"?e:e?.dataDirectory;if(i)this.dataDirectory=i;else{const r=vt.resolve(Op,"../../../");this.dataDirectory=vt.join(r,"tests","compatibility","_data")}}configure(e){super.configure(e),e.dataDirectory&&(this.dataDirectory=e.dataDirectory)}getDataFileName(e,i,r,n){return r&&n?`${e}-${i}-${r}-${n}.json`:null}loadDataFromFile(e){const i=`file:${e}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=vt.join(this.dataDirectory,e);if(!st.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const n=st.readFileSync(r,"utf-8"),a=JSON.parse(n);return this.dataCache.set(i,a),a}findDataFile(e,i,r,n){if(!st.existsSync(this.dataDirectory))return null;const a=st.readdirSync(this.dataDirectory).filter(l=>l.endsWith(".json"));if(r&&n){const l=`${e}-${i}-${r}-${n}.json`;if(a.includes(l))return l}const s=new RegExp(`^${e}-${i}-(\\d+)-(\\d+)\\.json$`),o=a.filter(l=>s.test(l)).map(l=>{const c=l.match(s);return{file:l,startTime:parseInt(c[1]),endTime:parseInt(c[2])}}).sort((l,c)=>c.endTime-l.endTime);if(o.length===0)return null;if(r&&n){const l=o.find(c=>c.startTime<=r&&c.endTime>=n);if(l)return l.file}return o[0].file}filterData(e,i,r,n){let a=e;return(i||r)&&(a=e.filter(s=>{const o=!i||s.openTime>=i,l=!r||s.openTime<=r;return o&&l})),a.sort((s,o)=>s.openTime-o.openTime),n&&n>0&&(a=a.slice(0,n)),a}normalizeTimeframe(e){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[e.toUpperCase()]||e.toLowerCase()}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,n,a){try{const s=this.normalizeTimeframe(i),o=this.findDataFile(e,s,n,a);if(!o)return console.warn(`No mock data file found for ${e} ${s}. Searched in: ${this.dataDirectory}`),[];const l=this.loadDataFromFile(o),c=this.filterData(l,n,a,r);return this.normalizeCloseTime(c),c}catch(s){return console.error("Error in MockProvider.getMarketData:",s),[]}}loadExchangeInfo(e){if(this.exchangeInfoCache[e])return this.exchangeInfoCache[e];const i=e==="spot"?"api-exchangeInfo.json":"fapi-exchangeInfo.json",r=vt.join(this.dataDirectory,i);if(!st.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const n=st.readFileSync(r,"utf-8"),a=JSON.parse(n);return this.exchangeInfoCache[e]=a,a}catch(n){return console.error(`Error loading exchange info from ${i}:`,n),null}}async getSymbolInfo(e){try{let i="crypto",r=e,n="";e.endsWith(".P")?(i="futures",r=e.replace(".P",""),n="Perpetual"):e.includes("_")&&(i="futures",r=e,n="Delivery");const a=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!a||!a.symbols)return console.error(`Exchange info not available for ${i}`),null;const s=a.symbols.find(_=>_.symbol===r);if(!s)return console.error(`Symbol ${r} not found in ${i} exchange info`),null;const o=s.filters?.find(_=>_.filterType==="PRICE_FILTER"),l=s.filters?.find(_=>_.filterType==="LOT_SIZE"),c=o?parseFloat(o.tickSize):.01,h=l?parseFloat(l.minQty):0,p=Math.round(1/c),u=s.baseAsset,f=s.quoteAsset,m=n?` ${n}`:"",x=`${u} / ${f}${m}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:u,description:x,type:i,main_tickerid:`BINANCE:${e}`,current_contract:n,isin:"",basecurrency:u,currency:f,timezone:"Etc/UTC",country:"",mintick:c,pricescale:p,minmove:1,pointvalue:s.contractSize||1,mincontract:h,session:"24x7",volumetype:"base",expiration_date:s.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in MockProvider.getSymbolInfo:",i),null}}clearCache(){this.dataCache.clear(),this.exchangeInfoCache={}}setDataDirectory(e){this.dataDirectory=e,this.clearCache()}}const jp=typeof process<"u"&&process.versions&&process.versions.node;let zt=null;if(jp)try{zt=new Lp}catch{zt=null}const Bp={Binance:new Bn,FMP:new Fn,Alpaca:new $n,...zt?{Mock:zt}:{}};class Fp extends Error{method;constructor(e,i){super(e),this.name="PineRuntimeError",this.method=i}}exports.AlpacaProvider=$n;exports.BaseProvider=Tt;exports.BinanceProvider=Bn;exports.Context=Qe;exports.FMPProvider=Fn;exports.Indicator=_i;exports.PineRuntimeError=Fp;exports.PineTS=Vi;exports.Provider=Bp;exports.TIMEFRAME_PERIOD_INFO=yp;exports.TIMEFRAME_SECONDS=ut;exports.aggregateCandles=jn;exports.computeNextPeriodStart=pt;exports.computeSessionClose=bi;exports.getAggregationRatio=Oi;exports.localTimeToUTC=Ce;exports.selectSubTimeframe=Ln;
|
|
122
122
|
//# sourceMappingURL=pinets.min.cjs.map
|