pinets 0.3.0 → 0.5.0
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/README.md +3 -0
- package/dist/pinets.dev.browser.js +3739 -1372
- package/dist/pinets.dev.cjs +3734 -1368
- package/dist/pinets.dev.cjs.map +1 -1
- package/dist/pinets.dev.es.js +3688 -1326
- package/dist/pinets.dev.es.js.map +1 -1
- package/dist/pinets.min.browser.js +15 -11
- package/dist/pinets.min.cjs +15 -11
- package/dist/pinets.min.es.js +5 -1
- package/dist/types/Context.class.d.ts +61 -15
- package/dist/types/PineTS.class.d.ts +11 -1
- package/dist/types/namespaces/Core.d.ts +1 -0
- package/dist/types/namespaces/array/methods/from.d.ts +1 -1
- package/dist/types/namespaces/request/methods/security.d.ts +1 -1
- package/dist/types/namespaces/request/types/barmerge.type.d.ts +7 -0
- package/dist/types/namespaces/request/utils/findLTFContextIdx.d.ts +1 -0
- package/dist/types/namespaces/ta/getters/obv.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/accdist.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/alma.d.ts +18 -0
- package/dist/types/namespaces/ta/methods/barssince.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/bb.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/bbw.d.ts +9 -0
- package/dist/types/namespaces/ta/methods/cci.d.ts +20 -0
- package/dist/types/namespaces/ta/methods/cmo.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/cog.d.ts +18 -0
- package/dist/types/namespaces/ta/methods/correlation.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/cross.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/cum.d.ts +14 -0
- package/dist/types/namespaces/ta/methods/dmi.d.ts +24 -0
- package/dist/types/namespaces/ta/methods/falling.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/highestbars.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/iii.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/kc.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/kcw.d.ts +11 -0
- package/dist/types/namespaces/ta/methods/lowestbars.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/macd.d.ts +18 -0
- package/dist/types/namespaces/ta/methods/mfi.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/mode.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/nvi.d.ts +10 -0
- package/dist/types/namespaces/ta/methods/obv.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/percentile_linear_interpolation.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/percentile_nearest_rank.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/percentrank.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/pvi.d.ts +10 -0
- package/dist/types/namespaces/ta/methods/pvt.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/range.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/rising.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/sar.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/stoch.d.ts +21 -0
- package/dist/types/namespaces/ta/methods/supertrend.d.ts +23 -0
- package/dist/types/namespaces/ta/methods/swma.d.ts +14 -0
- package/dist/types/namespaces/ta/methods/tr.d.ts +1 -0
- package/dist/types/namespaces/ta/methods/tsi.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/valuewhen.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/vwap.d.ts +14 -0
- package/dist/types/namespaces/ta/methods/wad.d.ts +11 -0
- package/dist/types/namespaces/ta/methods/wpr.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/wvad.d.ts +7 -0
- package/dist/types/namespaces/ta/ta.index.d.ts +120 -5
- package/dist/types/transpiler/analysis/ScopeManager.d.ts +11 -0
- package/dist/types/transpiler/index.d.ts +4 -1
- package/dist/types/transpiler/transformers/InjectionTransformer.d.ts +6 -0
- package/dist/types/transpiler/transformers/MainTransformer.d.ts +4 -1
- package/dist/types/transpiler/transformers/NormalizationTransformer.d.ts +15 -0
- package/dist/types/transpiler/transformers/WrapperTransformer.d.ts +9 -0
- package/dist/types/transpiler/utils/ASTFactory.d.ts +2 -0
- package/package.json +1 -1
package/dist/pinets.min.es.js
CHANGED
|
@@ -15,4 +15,8 @@
|
|
|
15
15
|
* You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
|
-
import*as re from"acorn";import*as ne from"astring";import*as j from"acorn-walk";import*as R from"fs";import*as F from"path";import{fileURLToPath as ae}from"url";var ie=Object.defineProperty,oe=(t,e,r)=>e in t?ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_=(t,e,r)=>oe(t,typeof e!="symbol"?e+"":e,r);class se{constructor(){_(this,"scopes",[]),_(this,"scopeTypes",[]),_(this,"scopeCounts",new Map),_(this,"contextBoundVars",new Set),_(this,"arrayPatternElements",new Set),_(this,"rootParams",new Set),_(this,"varKinds",new Map),_(this,"loopVars",new Set),_(this,"loopVarNames",new Map),_(this,"paramIdCounter",0),_(this,"cacheIdCounter",0),_(this,"tempVarCounter",0),_(this,"taCallIdCounter",0),this.pushScope("glb")}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++}`}}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}addContextBoundVar(e,r=!1){this.contextBoundVars.add(e),r&&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 this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,r){this.loopVars.add(e),this.loopVarNames.set(e,r)}getLoopVariableName(e){return this.loopVarNames.get(e)}isLoopVariable(e){return this.loopVars.has(e)}addVariable(e,r){if(this.isContextBound(e))return e;const n=this.scopes[this.scopes.length-1],a=this.scopeTypes[this.scopeTypes.length-1],o=this.scopeCounts.get(a)||1,i=`${a}${o}_${e}`;return n.set(e,i),this.varKinds.set(i,r),i}getVariable(e){if(this.loopVars.has(e)){const r=this.loopVarNames.get(e);if(r)return[r,"let"]}if(this.isContextBound(e))return[e,"let"];for(let r=this.scopes.length-1;r>=0;r--){const n=this.scopes[r];if(n.has(e)){const a=n.get(e),o=this.varKinds.get(a)||"let";return[a,o]}}return[e,"let"]}generateTempVar(){return`temp_${++this.tempVarCounter}`}}const A="$",y={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,r=!1){return{type:"MemberExpression",object:t,property:e,computed:r}},createContextIdentifier(){return this.createIdentifier(A)},createContextVariableReference(t,e){const r=this.createContextIdentifier(),n=this.createIdentifier(t),a=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(r,n,!1),a,!1)},createContextVariableAccess0(t,e){const r=this.createContextVariableReference(t,e);return this.createArrayAccess(r,0)},createArrayAccess(t,e){const r=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,r,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,r="="){return{type:"AssignmentExpression",operator:r,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,r){const n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),a=[t,e];return r&&a.push(r),this.createCallExpression(n,a)},createGetCall(t,e){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),n=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(r,[t,n])},createSetCall(t,e){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(r,[t,e])},createMathEqCall(t,e){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__eq"),!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}]}}}};function ce(t){j.recursive(t,null,{VariableDeclaration(e,r,n){e.declarations&&e.declarations.length>0&&e.declarations.forEach(a=>{if(a.init&&a.init.type==="ArrowFunctionExpression"&&a.init.start!==0){const o={type:"FunctionDeclaration",id:a.id,params:a.init.params,body:a.init.body.type==="BlockStatement"?a.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:a.init.body}]},async:a.init.async,generator:!1};Object.assign(e,o)}}),e.body&&e.body.body&&e.body.body.forEach(a=>n(a,r))}})}function pe(t,e){j.simple(t,{VariableDeclaration(r){r.declarations.forEach(n=>{const a=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===A||n.init.object.name==="context2"),o=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===A||n.init.object.object.name==="context2");(a||o)&&(n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(i=>{i.key.name&&e.addContextBoundVar(i.key.name)}))})}})}function le(t,e,r=!1){t.params.forEach(n=>{n.type==="Identifier"&&e.addContextBoundVar(n.name,r)})}function ue(t,e){t.params.forEach(r=>{r.type==="Identifier"&&e.addContextBoundVar(r.name,!1)})}function me(t,e){let r;return j.simple(t,{FunctionDeclaration(n){ue(n,e)},ArrowFunctionExpression(n){const a=n.start===0;a&&n.params&&n.params.length>0&&(r=n.params[0].name,n.params[0].name=A),le(n,e,a)},VariableDeclaration(n){n.declarations.forEach(a=>{if(a.id.type==="ArrayPattern"){const o=e.generateTempVar(),i={type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:o},init:a.init}]};a.id.elements?.forEach(c=>{c.type==="Identifier"&&e.addArrayPatternElement(c.name)});const s=a.id.elements.map((c,u)=>({type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:c,init:{type:"MemberExpression",object:{type:"Identifier",name:o},property:{type:"Literal",value:u},computed:!0}}]}));Object.assign(n,{type:"BlockStatement",body:[i,...s]})}})},ForStatement(n){}}),r}const U={type:"Identifier",name:"undefined"};function k(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name))return;if(!e.isContextBound(t.property.name)){const[r,n]=e.getVariable(t.property.name);t.property=y.createContextVariableReference(n,r),t.property=y.createGetCall(t.property,0)}}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(!e.isContextBound(t.object.name)){const[r,n]=e.getVariable(t.object.name);t.object=y.createContextVariableReference(n,r)}if(t.property.type==="MemberExpression"){const r=t.property;r._indexTransformed||(k(r,e),r._indexTransformed=!0)}}}function B(t,e){const r=y.createGetCall(y.createIdentifier(t.name),0);t.start!==void 0&&(r.start=t.start),t.end!==void 0&&(r.end=t.end),r._indexTransformed=!0,Object.assign(t,r)}function $(t,e){if(t.name!==A){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)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;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.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.callee.object.name),o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed,i=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),s=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t;if(r||n||a||i||s){if(s)return;const[f,m]=e.getVariable(t.name),p=y.createContextVariableReference(m,f);Object.assign(t,p);return}const[c,u]=e.getVariable(t.name),h=y.createContextVariableReference(u,c);if(!(t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t)&&!o){const f=y.createGetCall(h,0);Object.assign(t,f)}else Object.assign(t,h)}}function T(t,e,r){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;const n=r.getCurrentScopeType()=="if",a=r.getCurrentScopeType()=="els",o=r.getCurrentScopeType()=="for";if(!n&&!a&&!o&&t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(k(t,r),t._indexTransformed=!0);const i=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&t.object.object.object.name===A,s=t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name);if(t.computed&&(i||s)){if(t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left===t)return;const c=y.createGetCall(t.object,t.property);t.start&&(c.start=t.start),t.end&&(c.end=t.end),Object.assign(t,c)}}function L(t,e){if(t.type==="Identifier"){if(t.name==="na")return t.name="NaN",t;if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){const[a,o]=e.getVariable(t.name);return y.createContextVariableReference(o,a)}if(e.isContextBound(t.name))return t;const[r,n]=e.getVariable(t.name);return y.createContextVariableReference(n,r)}return t}function O(t,e,r=""){switch(t.type){case"BinaryExpression":return Y(t,e,r);case"MemberExpression":return{type:"MemberExpression",object:t.object.type==="Identifier"?L(t.object,e):t.object,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 n=L(t,e);return y.createGetCall(n,0)}case"UnaryExpression":return Z(t,e,r)}return t}function Y(t,e,r){const n=O(t.left,e,r),a=O(t.right,e,r),o={type:"BinaryExpression",operator:t.operator,left:n,right:a,start:t.start,end:t.end};return j.recursive(o,e,{CallExpression(i,s){i._transformed||D(i,s)},MemberExpression(i){T(i,"",e)}}),o}function he(t,e,r){const n=O(t.left,e,r),a=O(t.right,e,r),o={type:"LogicalExpression",operator:t.operator,left:n,right:a,start:t.start,end:t.end};return j.recursive(o,e,{CallExpression(i,s){i._transformed||D(i,s)}}),o}function fe(t,e,r){return j.recursive(t,{parent:t,inNamespaceCall:!1},{Identifier(n,a,o){if(n.name=="NaN")return;if(n.name=="na"){n.name="NaN";return}n.parent=a.parent,$(n,e);const i=n.parent&&n.parent.type==="BinaryExpression";(n.parent&&n.parent.type==="ConditionalExpression"||i)&&(n.type==="MemberExpression"?k(n,e):n.type==="Identifier"&&(n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.object&&n.parent.callee.object.name===A&&n.parent.callee.property.name==="get"||B(n)))},MemberExpression(n,a,o){k(n,e),n.object&&o(n.object,{parent:n,inNamespaceCall:a.inNamespaceCall})},CallExpression(n,a,o){const i=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&e.isContextBound(n.callee.object.name);D(n,e),n.arguments.forEach(s=>o(s,{parent:n,inNamespaceCall:i||a.inNamespaceCall}))}}),{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(r),y.createIdentifier("param")),arguments:[t,U,e.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function Z(t,e,r){const n=O(t.argument,e,r);return{type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:n,start:t.start,end:t.end}}function K(t,e,r){switch(t?.type){case"BinaryExpression":t=Y(t,r,e);break;case"LogicalExpression":t=he(t,r,e);break;case"ConditionalExpression":return fe(t,r,e);case"UnaryExpression":t=Z(t,r,e);break}if(t.type==="MemberExpression"&&t.computed&&t.property){const n=t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)?t.object:L(t.object,r),a=t.property.type==="Identifier"&&!r.isContextBound(t.property.name)&&!r.isLoopVariable(t.property.name)?L(t.property,r):t.property;return{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(e),y.createIdentifier("param")),arguments:[n,a,r.nextParamIdArg],_transformed:!0,_isParamCall:!0}}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(n=>{if(n.value.name){const[a,o]=r.getVariable(n.value.name);return{type:"Property",key:{type:"Identifier",name:n.key.name},value:y.createContextVariableReference(o,a),kind:"init",method:!1,shorthand:!1,computed:!1}}return n})),t.type==="Identifier"){if(t.name==="na")return t.name="NaN",t;if(r.isContextBound(t.name)&&!r.isRootParam(t.name))return{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(e),y.createIdentifier("param")),arguments:[t,U,r.nextParamIdArg],_transformed:!0,_isParamCall:!0}}return t?.type==="CallExpression"&&D(t,r),{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(e),y.createIdentifier("param")),arguments:[t.type==="Identifier"?L(t,r):t,U,r.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function D(t,e,r){if(!t._transformed){if(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(t.callee.object.name===A&&["get","init","param"].includes(t.callee.property.name))return;const n=t.callee.object.name;t.arguments=t.arguments.map(a=>a._isParamCall?a:K(a,n,e)),n==="ta"&&t.arguments.push(e.getNextTACallId()),t._transformed=!0}else t.callee&&t.callee.type==="Identifier"&&(t.arguments=t.arguments.map(n=>n._isParamCall?n:K(n,A,e)),t._transformed=!0);t.arguments.forEach(n=>{j.recursive(n,e,{Identifier(a,o,i){a.parent=o.parent,$(a,e);const s=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||s)&&(a.type==="MemberExpression"?k(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===A&&a.parent.callee.property.name==="get"||B(a)))},CallExpression(a,o,i){a._transformed||D(a,o)},MemberExpression(a,o,i){T(a,"",e),a.object&&i(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})}})})}}function ee(t,e){let r=null;if(t.left.type==="Identifier"){const[n,a]=e.getVariable(t.left.name);r=y.createContextVariableReference(a,n)}else if(t.left.type==="MemberExpression"&&t.left.computed&&t.left.object.type==="Identifier"){const n=t.left.object.name,[a,o]=e.getVariable(n),i=a!==n,s=e.isContextBound(n);(i||s)&&!e.isLoopVariable(n)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(r=y.createContextVariableReference(o,a))}if(j.recursive(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(n,a,o){n.name=="na"&&(n.name="NaN"),n.parent=a.parent,$(n,e);const i=n.parent&&n.parent.type==="BinaryExpression",s=n.parent&&n.parent.type==="ConditionalExpression",c=e.isContextBound(n.name)&&!e.isRootParam(n.name),u=n.parent&&n.parent.type==="MemberExpression"&&n.parent.computed&&n.parent.object===n,h=n.parent&&n.parent._isParamCall,f=n.parent&&n.parent.type==="MemberExpression",m=n.name==="NaN",p=n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.object&&n.parent.callee.object.name===A&&n.parent.callee.property.name==="get";(c||s||i)&&(n.type==="MemberExpression"?k(n,e):n.type==="Identifier"&&!f&&!u&&!h&&!m&&!p&&B(n))},MemberExpression(n,a,o){T(n,"",e),n.type==="CallExpression"?n.arguments.forEach(i=>o(i,{parent:n,inNamespaceCall:a.inNamespaceCall})):n.object&&o(n.object,{parent:n,inNamespaceCall:a.inNamespaceCall})},CallExpression(n,a,o){const i=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&e.isContextBound(n.callee.object.name);D(n,e),n.arguments.forEach(s=>o(s,{parent:n,inNamespaceCall:i||a.inNamespaceCall}))}}),r){let n=t.right;if(t.operator!=="="){const o=t.operator.replace("=",""),i=y.createGetCall(r,0);n={type:"BinaryExpression",operator:o,left:i,right:t.right,start:t.start,end:t.end}}const a=y.createSetCall(r,n);t.start&&(a.start=t.start),t.end&&(a.end=t.end),Object.assign(t,a)}}function te(t,e){t.declarations.forEach(r=>{r.init.name=="na"&&(r.init.name="NaN");const n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===A||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===A||r.init.object.object.name==="context2"),o=r.init&&r.init.type==="ArrowFunctionExpression";if(n){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.name=A;return}if(a){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.object.name=A;return}o&&r.init.params.forEach(p=>{p.type==="Identifier"&&e.addContextBoundVar(p.name)});const i=e.addVariable(r.id.name,t.kind),s=t.kind;r.init&&!o&&(r.init.type==="CallExpression"&&r.init.callee.type==="MemberExpression"&&r.init.callee.object&&r.init.callee.object.type==="Identifier"&&e.isContextBound(r.init.callee.object.name)?D(r.init,e):j.recursive(r.init,{parent:r.init},{Identifier(p,d){p.parent=d.parent,$(p,e);const b=p.parent&&p.parent.type==="BinaryExpression",x=p.parent&&p.parent.type==="ConditionalExpression",S=p.parent&&p.parent.type==="CallExpression"&&p.parent.callee&&p.parent.callee.object&&p.parent.callee.object.name===A&&p.parent.callee.property.name==="get";p.type==="Identifier"&&(b||x)&&!S&&B(p)},CallExpression(p,d,b){p.callee.type==="Identifier"&&(p.callee.parent=p),p.arguments.forEach(x=>{x.type==="Identifier"&&(x.parent=p)}),D(p,e),p.arguments.forEach(x=>b(x,{parent:p}))},BinaryExpression(p,d,b){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),b(p.left,{parent:p}),b(p.right,{parent:p})},MemberExpression(p,d,b){p.object&&p.object.type==="Identifier"&&(p.object.parent=p),p.property&&p.property.type==="Identifier"&&(p.property.parent=p),T(p,"",e),p.type==="CallExpression"?p.arguments.forEach(x=>b(x,{parent:p})):p.object&&b(p.object,{parent:p})}}));const c=y.createContextVariableReference(s,i),u=e.isArrayPatternElement(r.id.name),h=!u&&r.init&&r.init.type==="MemberExpression"&&r.init.computed&&r.init.property&&(r.init.property.type==="Literal"||r.init.property.type==="MemberExpression");r.init?.property?.type==="MemberExpression"&&(r.init.property._indexTransformed||(k(r.init.property,e),r.init.property._indexTransformed=!0));let f;r.init?o||u?f=r.init:f=y.createInitCall(c,h?r.init.object:r.init,h?r.init.property:void 0):f=y.createIdentifier("undefined");const m=y.createExpressionStatement(y.createAssignmentExpression(c,f));if(u){m.expression.right.object.property.name+=`?.[0][${r.init.property.value}]`;const p=m.expression.right.object;m.expression.right=y.createCallExpression(y.createMemberExpression(y.createContextIdentifier(),y.createIdentifier("init")),[c,p])}o&&(e.pushScope("fn"),j.recursive(r.init.body,e,{BlockStatement(p,d,b){p.body.forEach(x=>b(x,d))},IfStatement(p,d,b){d.pushScope("if"),b(p.consequent,d),p.alternate&&(d.pushScope("els"),b(p.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(p,d){te(p,d)},Identifier(p,d){$(p,d)},AssignmentExpression(p,d){ee(p,d)}}),e.popScope()),Object.assign(t,m)})}function de(t,e,r){if(t.init&&t.init.type==="VariableDeclaration"){const n=t.init.declarations[0],a=n.id.name;e.addLoopVariable(a,a),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:n.init}]},n.init&&j.recursive(n.init,e,{Identifier(o,i){e.isLoopVariable(o.name)||(e.pushScope("for"),$(o,i),e.popScope())},MemberExpression(o){e.pushScope("for"),T(o,"",e),e.popScope()}})}t.test&&j.recursive(t.test,e,{Identifier(n,a){!e.isLoopVariable(n.name)&&!n.computed&&(e.pushScope("for"),$(n,a),n.type==="Identifier"&&(n.computed=!0,B(n)),e.popScope())},MemberExpression(n){e.pushScope("for"),T(n,"",e),e.popScope()}}),t.update&&j.recursive(t.update,e,{Identifier(n,a){e.isLoopVariable(n.name)||(e.pushScope("for"),$(n,a),e.popScope())}}),e.pushScope("for"),r(t.body,e),e.popScope()}function ye(t,e){j.recursive(t,e,{MemberExpression(r){T(r,"",e)},CallExpression(r,n){D(r,n)},Identifier(r,n){$(r,n);const a=e.getCurrentScopeType()==="if";e.isContextBound(r.name)&&!e.isRootParam(r.name)&&a&&B(r)}})}function ge(t,e,r){t.test&&(e.pushScope("if"),ye(t.test,e),e.popScope()),e.pushScope("if"),r(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),r(t.alternate,e),e.popScope())}function be(t,e){const r=e.getCurrentScopeType();if(t.argument&&(t.argument.type==="ArrayExpression"?(t.argument.elements=t.argument.elements.map(n=>{if(n.type==="Identifier"){if(e.isContextBound(n.name)&&!e.isRootParam(n.name))return y.createArrayAccess(n,0);const[a,o]=e.getVariable(n.name);return y.createContextVariableAccess0(o,a)}else if(n.type==="MemberExpression")return n.computed&&n.object.type==="Identifier"&&e.isContextBound(n.object.name)&&!e.isRootParam(n.object.name)||T(n,"",e),n;return n}),t.argument={type:"ArrayExpression",elements:[t.argument]}):t.argument.type==="BinaryExpression"?j.recursive(t.argument,e,{Identifier(n,a){$(n,a),n.type==="Identifier"&&B(n)},MemberExpression(n){T(n,"",e)}}):t.argument.type==="ObjectExpression"?t.argument.properties=t.argument.properties.map(n=>{if(n.shorthand){const[a,o]=e.getVariable(n.value.name);return{type:"Property",key:y.createIdentifier(n.key.name),value:y.createContextVariableReference(o,a),kind:"init",method:!1,shorthand:!1,computed:!1}}return n}):t.argument.type==="Identifier"&&($(t.argument,e),t.argument.type==="Identifier"&&B(t.argument)),r==="fn")){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=y.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||(k(t.argument,e),t.argument._indexTransformed=!0)):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression")&&j.recursive(t.argument,e,{Identifier(a,o){$(a,o),a.type==="Identifier"&&!a._arrayAccessed&&(B(a),a._arrayAccessed=!0)},MemberExpression(a){T(a,"",e)},CallExpression(a,o){D(a,o)}});const n=y.createCallExpression(y.createMemberExpression(y.createContextIdentifier(),y.createIdentifier("precision")),[t.argument]);t.argument=n}}function we(t,e,r){t.body&&t.body.type==="BlockStatement"&&(e.pushScope("fn"),r(t.body,e),e.popScope())}function xe(t){j.simple(t,{BinaryExpression(e){if(e.operator==="=="||e.operator==="==="){const r=e.left,n=e.right,a=y.createMathEqCall(r,n);a._transformed=!0,Object.assign(e,a)}}})}function ve(t,e,r){j.recursive(t,e,{BlockStatement(n,a,o){n.body.forEach(i=>o(i,a))},ReturnStatement(n,a){be(n,a)},VariableDeclaration(n,a){te(n,a)},Identifier(n,a){$(n,a)},CallExpression(n,a){D(n,a)},MemberExpression(n,a){T(n,r,a)},AssignmentExpression(n,a){ee(n,a)},FunctionDeclaration(n,a,o){we(n,a,o)},ForStatement(n,a,o){de(n,a,o)},IfStatement(n,a,o){ge(n,a,o)}})}function Ce(t){let e=typeof t=="function"?t.toString():t;const r=re.parse(e.trim(),{ecmaVersion:"latest",sourceType:"module"});ce(r);const n=new se;pe(r,n);const a=me(r,n)||"";ve(r,n,a),xe(r);const o=ne.generate(r);return new Function("",`return ${o}`)(this)}class l{constructor(e,r=0){this.data=e,this.offset=r}get(e){const r=this.data.length-1-(this.offset+e);return r<0||r>=this.data.length?NaN:this.data[r]}set(e,r){const n=this.data.length-1-(this.offset+e);n>=0&&n<this.data.length&&(this.data[n]=r)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof l?e:Array.isArray(e)?new l(e):new l([e])}}var Ee=Object.defineProperty,Se=(t,e,r)=>e in t?Ee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,je=(t,e,r)=>Se(t,typeof e!="symbol"?e+"":e,r);class Ae{constructor(e){this.context=e,je(this,"color",{param:(r,n=0)=>l.from(r).get(n),rgb:(r,n,a,o)=>o?`rgba(${r}, ${n}, ${a}, ${o})`:`rgb(${r}, ${n}, ${a})`,new:(r,n)=>{if(r&&r.startsWith("#")){const a=r.slice(1),o=parseInt(a.slice(0,2),16),i=parseInt(a.slice(2,4),16),s=parseInt(a.slice(4,6),16);return n?`rgba(${o}, ${i}, ${s}, ${n})`:`rgb(${o}, ${i}, ${s})`}return n?`rgba(${r}, ${n})`:r},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue"})}extractPlotOptions(e){const r={};for(let n in e)r[n]=l.from(e[n]).get(0);return r}indicator(e,r,n){}plotchar(e,r,n){this.context.plots[r]||(this.context.plots[r]={data:[],options:this.extractPlotOptions(n),title:r});const a=l.from(e).get(0);this.context.plots[r].data.push({time:this.context.marketData[this.context.idx].openTime,value:a,options:{...this.extractPlotOptions(n),style:"char"}})}plot(e,r,n){this.context.plots[r]||(this.context.plots[r]={data:[],options:this.extractPlotOptions(n),title:r});const a=l.from(e).get(0);this.context.plots[r].data.push({time:this.context.marketData[this.context.idx].openTime,value:a,options:this.extractPlotOptions(n)})}na(e){return isNaN(l.from(e).get(0))}nz(e,r=0){const n=l.from(e).get(0),a=l.from(r).get(0);return isNaN(n)?a:n}}function Me(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Ie(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Ne(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function _e(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function $e(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Ve(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Te(t){return(e,r=0)=>[l.from(e).get(r)]}function De(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Pe(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Be(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function ke(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Le(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Oe(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Re(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Fe(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}var qe=Object.defineProperty,We=(t,e,r)=>e in t?qe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,M=(t,e,r)=>We(t,typeof e!="symbol"?e+"":e,r);const Ge={any:Me,bool:Ie,color:Ne,enum:_e,float:$e,int:Ve,param:Te,price:De,session:Pe,source:Be,string:ke,symbol:Le,text_area:Oe,time:Re,timeframe:Fe};class Ue{constructor(e){this.context=e,M(this,"any"),M(this,"bool"),M(this,"color"),M(this,"enum"),M(this,"float"),M(this,"int"),M(this,"param"),M(this,"price"),M(this,"session"),M(this,"source"),M(this,"string"),M(this,"symbol"),M(this,"text_area"),M(this,"time"),M(this,"timeframe"),Object.entries(Ge).forEach(([r,n])=>{this[r]=n(e)})}}function ze(t){return e=>Math.abs(l.from(e).get(0))}function Ke(t){return e=>Math.acos(l.from(e).get(0))}function He(t){return e=>Math.asin(l.from(e).get(0))}function Xe(t){return e=>Math.atan(l.from(e).get(0))}function Je(t){return(...e)=>{const r=e.map(n=>l.from(n).get(0));return r.reduce((n,a)=>n+a,0)/r.length}}function Qe(t){return e=>Math.ceil(l.from(e).get(0))}function Ye(t){return e=>Math.cos(l.from(e).get(0))}function Ze(t){return e=>Math.exp(l.from(e).get(0))}function et(t){return e=>Math.floor(l.from(e).get(0))}function tt(t){return e=>Math.log(l.from(e).get(0))}function rt(t){return e=>Math.log(l.from(e).get(0))}function nt(t){return e=>Math.log10(l.from(e).get(0))}function at(t){return(...e)=>{const r=e.map(n=>l.from(n).get(0));return Math.max(...r)}}function it(t){return(...e)=>{const r=e.map(n=>l.from(n).get(0));return Math.min(...r)}}function ot(t){return(e,r,n)=>typeof e=="string"?e:e instanceof l?r?new l(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new l(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new l(t.params[n],0)))}function st(t){return(e,r)=>Math.pow(l.from(e).get(0),l.from(r).get(0))}function ct(t){return()=>Math.random()}function pt(t){return e=>Math.round(l.from(e).get(0))}function lt(t){return e=>Math.sin(l.from(e).get(0))}function ut(t){return e=>Math.sqrt(l.from(e).get(0))}function mt(t){return(e,r)=>{const n=l.from(r).get(0),a=l.from(e);let o=0;for(let i=0;i<n;i++){const s=a.get(i);isNaN(s)||(o+=s)}return o}}function ht(t){return e=>Math.tan(l.from(e).get(0))}function ft(t){return(e,r)=>{const n=l.from(e).get(0),a=l.from(r).get(0);return isNaN(n)&&isNaN(a)?!0:isNaN(n)||isNaN(a)?!1:Math.abs(n-a)<1e-8}}var dt=Object.defineProperty,yt=(t,e,r)=>e in t?dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,E=(t,e,r)=>yt(t,typeof e!="symbol"?e+"":e,r);const gt={abs:ze,acos:Ke,asin:He,atan:Xe,avg:Je,ceil:Qe,cos:Ye,exp:Ze,floor:et,ln:tt,log:rt,log10:nt,max:at,min:it,param:ot,pow:st,random:ct,round:pt,sin:lt,sqrt:ut,sum:mt,tan:ht,__eq:ft};class bt{constructor(e){this.context=e,E(this,"_cache",{}),E(this,"abs"),E(this,"acos"),E(this,"asin"),E(this,"atan"),E(this,"avg"),E(this,"ceil"),E(this,"cos"),E(this,"exp"),E(this,"floor"),E(this,"ln"),E(this,"log"),E(this,"log10"),E(this,"max"),E(this,"min"),E(this,"param"),E(this,"pow"),E(this,"random"),E(this,"round"),E(this,"sin"),E(this,"sqrt"),E(this,"sum"),E(this,"tan"),E(this,"__eq"),Object.entries(gt).forEach(([r,n])=>{this[r]=n(e)})}}function wt(t){return(e,r,n)=>(t.params[n]||(t.params[n]=[]),e instanceof l||Array.isArray(e)?[l.from(e).get(r||0),n]:(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,[e,n]))}const H=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function X(t,e,r,n,a=!1){for(let o=0;o<r.length;o++)if(r[o]<=t&&e<=n[o])return o+(a?1:2);return-1}function xt(t){return async(e,r,n,a=!1,o=!1,i=!1,s=null,c=null)=>{const u=e[0],h=r[0],f=n[0],m=n[1],p=H.indexOf(t.timeframe),d=H.indexOf(h);if(p==-1||d==-1)throw new Error("Invalid timeframe");if(p>d)throw new Error("Only higher timeframes are supported for now");if(p===d)return f;const b=t.data.openTime[0],x=t.data.closeTime[0];if(t.cache[m]){const P=t.cache[m],w=X(b,x,P.data.openTime,P.data.closeTime,o);return w==-1?NaN:P.params[m][w]}const S=await new Zr(t.source,u,h,t.limit||1e3,t.sDate,t.eDate).run(t.pineTSCode);t.cache[m]=S;const V=X(b,x,S.data.openTime,S.data.closeTime,o);return V==-1?NaN:S.params[m][V]}}var vt=Object.defineProperty,Ct=(t,e,r)=>e in t?vt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,W=(t,e,r)=>Ct(t,typeof e!="symbol"?e+"":e,r);const Et={param:wt,security:xt};class St{constructor(e){this.context=e,W(this,"_cache",{}),W(this,"param"),W(this,"security"),Object.entries(Et).forEach(([r,n])=>{this[r]=n(e)})}}function jt(t){return()=>{const e=t.get(t.data.high,0),r=t.get(t.data.low,0),n=t.get(t.data.close,1);return isNaN(n)?e-r:Math.max(e-r,Math.abs(e-n),Math.abs(r-n))}}function At(t){return(e,r)=>{const n=l.from(e).get(0);t.taState||(t.taState={});const a=r||`atr_${n}`;t.taState[a]||(t.taState[a]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const o=t.taState[a],i=t.get(t.data.high,0),s=t.get(t.data.low,0),c=t.get(t.data.close,0);let u;if(o.prevClose!==null){const f=i-s,m=Math.abs(i-o.prevClose),p=Math.abs(s-o.prevClose);u=Math.max(f,m,p)}else u=i-s;if(o.prevClose=c,o.initCount<n)return o.initSum+=u,o.initCount++,o.initCount===n?(o.prevAtr=o.initSum/n,t.precision(o.prevAtr)):NaN;const h=(o.prevAtr*(n-1)+u)/n;return o.prevAtr=h,t.precision(h)}}function Mt(t){return(e,r=1,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`change_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<=a)return NaN;i.window.length>a+1&&i.window.pop();const c=s-i.window[a];return t.precision(c)}}function It(t){return(e,r)=>{const n=l.from(e),a=l.from(r),o=n.get(0),i=a.get(0),s=n.get(1),c=a.get(1);return s<c&&o>i}}function Nt(t){return(e,r)=>{const n=l.from(e),a=l.from(r),o=n.get(0),i=a.get(0),s=n.get(1),c=a.get(1);return s>c&&o<i}}function _t(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`dev_${a}`;t.taState[o]||(t.taState[o]={window:[],sum:0});const i=t.taState[o],s=l.from(e).get(0)||0;if(i.window.unshift(s),i.sum+=s,i.window.length<a)return NaN;if(i.window.length>a){const f=i.window.pop();i.sum-=f}const c=i.sum/a;let u=0;for(let f=0;f<a;f++)u+=Math.abs(i.window[f]-c);const h=u/a;return t.precision(h)}}function $t(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`ema_${a}`;t.taState[o]||(t.taState[o]={prevEma:null,initSum:0,initCount:0});const i=t.taState[o],s=l.from(e).get(0);if(i.initCount<a)return i.initSum+=s,i.initCount++,i.initCount===a?(i.prevEma=i.initSum/a,t.precision(i.prevEma)):NaN;const c=2/(a+1),u=s*c+i.prevEma*(1-c);return i.prevEma=u,t.precision(u)}}function Vt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`highest_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=Math.max(...i.window.filter(u=>!isNaN(u)));return t.precision(c)}}function Tt(t){return(e,r,n)=>{const a=l.from(r).get(0),o=Math.floor(a/2),i=Math.floor(Math.sqrt(a)),s=t.ta.wma,c=s(e,o,n?`${n}_wma1`:void 0),u=s(e,a,n?`${n}_wma2`:void 0);if(isNaN(c)||isNaN(u))return NaN;t.taState||(t.taState={});const h=n||`hma_raw_${a}`;t.taState[h]||(t.taState[h]=[]);const f=2*c-u;t.taState[h].unshift(f);const m=n?`${n}_hma_final`:`hma_final_${a}`;t.taState[m]||(t.taState[m]={window:[]});const p=t.taState[m];if(p.window.unshift(f),p.window.length<i)return NaN;p.window.length>i&&p.window.pop();let d=0,b=0;for(let S=0;S<i;S++){const V=i-S;d+=p.window[S]*V,b+=V}const x=d/b;return t.precision(x)}}function Dt(t){return(e,r,n,a)=>{const o=l.from(r).get(0),i=l.from(n).get(0);t.taState||(t.taState={});const s=a||`linreg_${o}_${i}`;t.taState[s]||(t.taState[s]={window:[]});const c=t.taState[s],u=l.from(e).get(0);if(c.window.unshift(u),c.window.length<o)return NaN;c.window.length>o&&c.window.pop();let h=0,f=0,m=0,p=0;const d=o;for(let V=0;V<o;V++){const P=o-1-V,w=c.window[V];h+=P,f+=w,m+=P*w,p+=P*P}const b=d*p-h*h;if(b===0)return NaN;const x=(d*m-h*f)/b,S=(f-x*h)/d+x*(o-1-i);return t.precision(S)}}function Pt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`lowest_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=i.window.filter(h=>!isNaN(h)&&h!==void 0),u=c.length>0?Math.min(...c):NaN;return t.precision(u)}}function Bt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`median_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=i.window.slice().sort((f,m)=>f-m),u=Math.floor(a/2),h=a%2===0?(c[u-1]+c[u])/2:c[u];return t.precision(h)}}function kt(t){return(e,r,n)=>{const a=l.from(r).get(0);return t.ta.change(e,a)}}function Lt(t){return(e,r,n)=>e instanceof l?r?new l(e.data,e.offset+r):e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new l(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new l(t.params[n],0)))}function Ot(t,e,r){const n=new Array(t.length).fill(NaN);for(let a=e+r;a<t.length;a++){const o=t[a-r];let i=!0;for(let s=1;s<=e;s++)if(t[a-r-s]>=o){i=!1;break}if(i){for(let s=1;s<=r;s++)if(t[a-r+s]>=o){i=!1;break}}i&&(n[a]=o)}return n}function Rt(t){return(e,r,n)=>{n==null&&(n=r,r=e,e=t.data.high);const a=l.from(r).get(0),o=l.from(n).get(0),i=l.from(e).toArray(),s=Ot(i,a,o),c=t.idx;return t.precision(s[c])}}function Ft(t,e,r){const n=new Array(t.length).fill(NaN);for(let a=e+r;a<t.length;a++){const o=t[a-r];let i=!0;for(let s=1;s<=e;s++)if(t[a-r-s]<=o){i=!1;break}if(i){for(let s=1;s<=r;s++)if(t[a-r+s]<=o){i=!1;break}}i&&(n[a]=o)}return n}function qt(t){return(e,r,n)=>{n==null&&(n=r,r=e,e=t.data.low);const a=l.from(r).get(0),o=l.from(n).get(0),i=l.from(e).toArray(),s=Ft(i,a,o),c=t.idx;return t.precision(s[c])}}function Wt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`rma_${a}`;t.taState[o]||(t.taState[o]={prevRma:null,initSum:0,initCount:0});const i=t.taState[o],s=l.from(e).get(0)||0;if(i.initCount<a)return i.initSum+=s,i.initCount++,i.initCount===a?(i.prevRma=i.initSum/a,t.precision(i.prevRma)):NaN;const c=1/a,u=s*c+i.prevRma*(1-c);return i.prevRma=u,t.precision(u)}}function Gt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`roc_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<=a)return NaN;i.window.length>a+1&&i.window.pop();const c=i.window[a],u=(s-c)/c*100;return t.precision(u)}}function Ut(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`rsi_${a}`;t.taState[o]||(t.taState[o]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.prevValue!==null){const c=s-i.prevValue,u=c>0?c:0,h=c<0?-c:0;if(i.initGains.length<a){if(i.initGains.push(u),i.initLosses.push(h),i.initGains.length===a){i.avgGain=i.initGains.reduce((p,d)=>p+d,0)/a,i.avgLoss=i.initLosses.reduce((p,d)=>p+d,0)/a,i.prevValue=s;const m=i.avgLoss===0?100:100-100/(1+i.avgGain/i.avgLoss);return t.precision(m)}return i.prevValue=s,NaN}i.avgGain=(i.avgGain*(a-1)+u)/a,i.avgLoss=(i.avgLoss*(a-1)+h)/a;const f=i.avgLoss===0?100:100-100/(1+i.avgGain/i.avgLoss);return i.prevValue=s,t.precision(f)}return i.prevValue=s,NaN}}function zt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`sma_${a}`;t.taState[o]||(t.taState[o]={window:[],sum:0});const i=t.taState[o],s=l.from(e).get(0)||0;if(i.window.unshift(s),i.sum+=s,i.window.length<a)return NaN;if(i.window.length>a){const u=i.window.pop();i.sum-=u}const c=i.sum/a;return t.precision(c)}}function Kt(t){return(e,r,n=!0,a)=>{const o=l.from(r).get(0),i=l.from(n).get(0);t.taState||(t.taState={});const s=a||`stdev_${o}_${i}`;t.taState[s]||(t.taState[s]={window:[],sum:0});const c=t.taState[s],u=l.from(e).get(0);if(c.window.unshift(u),c.sum+=u,c.window.length<o)return NaN;if(c.window.length>o){const d=c.window.pop();c.sum-=d}const h=c.sum/o;let f=0;for(let d=0;d<o;d++)f+=Math.pow(c.window[d]-h,2);const m=i?o:o-1,p=Math.sqrt(f/m);return t.precision(p)}}function Ht(t){return(e,r,n)=>{const a=l.from(e).get(0),o=l.from(r).get(0);t.taState||(t.taState={});const i=`supertrend_${a}_${o}`;t.taState[i]||(t.taState[i]={prevUpperBand:null,prevLowerBand:null,prevSupertrend:null,prevDirection:null});const s=t.taState[i],c=t.get(t.data.high,0),u=t.get(t.data.low,0),h=t.get(t.data.close,0),f=t.get(t.data.close,1),m=t.ta.atr(o,n?`${n}_atr`:void 0);if(isNaN(m))return[[NaN,0]];const p=(c+u)/2;let d=p+a*m,b=p-a*m;s.prevUpperBand!==null&&(d<s.prevUpperBand||f>s.prevUpperBand?d=d:d=s.prevUpperBand,b>s.prevLowerBand||f<s.prevLowerBand?b=b:b=s.prevLowerBand);let x,S;return s.prevSupertrend===null?(x=h<=d?-1:1,S=x===-1?d:b):s.prevSupertrend===s.prevUpperBand?h>d?(x=1,S=b):(x=-1,S=d):h<b?(x=-1,S=d):(x=1,S=b),s.prevUpperBand=d,s.prevLowerBand=b,s.prevSupertrend=S,s.prevDirection=x,[[t.precision(S),x]]}}function Xt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`variance_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();let c=0,u=0;for(let m=0;m<a;m++)c+=i.window[m],u+=i.window[m]*i.window[m];const h=c/a,f=u/a-h*h;return t.precision(f)}}function Jt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`vwma_${a}`;t.taState[o]||(t.taState[o]={window:[],volumeWindow:[]});const i=t.taState[o],s=l.from(e).get(0),c=t.get(t.data.volume,0);if(i.window.unshift(s),i.volumeWindow.unshift(c),i.window.length<a)return NaN;i.window.length>a&&(i.window.pop(),i.volumeWindow.pop());let u=0,h=0;for(let m=0;m<a;m++)u+=i.window[m]*i.volumeWindow[m],h+=i.volumeWindow[m];const f=u/h;return t.precision(f)}}function Qt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`wma_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();let c=0,u=0;for(let f=0;f<a;f++){const m=a-f;c+=i.window[f]*m,u+=m}const h=c/u;return t.precision(h)}}var Yt=Object.defineProperty,Zt=(t,e,r)=>e in t?Yt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,C=(t,e,r)=>Zt(t,typeof e!="symbol"?e+"":e,r);const er={tr:jt},tr={atr:At,change:Mt,crossover:It,crossunder:Nt,dev:_t,ema:$t,highest:Vt,hma:Tt,linreg:Dt,lowest:Pt,median:Bt,mom:kt,param:Lt,pivothigh:Rt,pivotlow:qt,rma:Wt,roc:Gt,rsi:Ut,sma:zt,stdev:Kt,supertrend:Ht,variance:Xt,vwma:Jt,wma:Qt};class rr{constructor(e){this.context=e,C(this,"tr"),C(this,"atr"),C(this,"change"),C(this,"crossover"),C(this,"crossunder"),C(this,"dev"),C(this,"ema"),C(this,"highest"),C(this,"hma"),C(this,"linreg"),C(this,"lowest"),C(this,"median"),C(this,"mom"),C(this,"param"),C(this,"pivothigh"),C(this,"pivotlow"),C(this,"rma"),C(this,"roc"),C(this,"rsi"),C(this,"sma"),C(this,"stdev"),C(this,"supertrend"),C(this,"variance"),C(this,"vwma"),C(this,"wma"),Object.entries(er).forEach(([r,n])=>{Object.defineProperty(this,r,{get:n(e),enumerable:!0})}),Object.entries(tr).forEach(([r,n])=>{this[r]=n(e)})}}class N{constructor(e){this.array=e}toString(){return"PineArrayObject:"+this.array.toString()}}function nr(t){return e=>new N(e.array.map(r=>Math.abs(r)))}function ar(t){return e=>t.array.sum(e)/e.array.length}function ir(t){return e=>{e.array.length=0}}function or(t){return(e,r)=>(e.array.push(...r.array),e)}function sr(t){return e=>new N([...e.array])}function cr(t){return(e,r,n=!0)=>{if(e.array.length!==r.array.length||e.array.length<2)return NaN;const a=n?e.array.length:e.array.length-1,o=t.array.avg(e),i=t.array.avg(r);let s=0;for(let c=0;c<e.array.length;c++)s+=(e.array[c]-o)*(r.array[c]-i);return s/a}}function pr(t){return(e,r)=>e.array.every(r)}function lr(t){return(e,r,n=0,a)=>{const o=e.array.length,i=a!==void 0?Math.min(a,o):o;for(let s=n;s<i;s++)e.array[s]=r}}function ur(t){return e=>e.array.length>0?e.array[0]:t.NA}function mr(t){return e=>new N([...e])}function hr(t){return(e,r)=>e.array[r]}function fr(t){return(e,r)=>e.array.includes(r)}function dr(t){return(e,r)=>e.array.indexOf(r)}function yr(t){return(e,r,n)=>{e.array.splice(r,0,n)}}function gr(t){return(e,r=",")=>e.array.join(r)}function br(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function wr(t){return(e,r)=>e.array.lastIndexOf(r)}function xr(t){return(e,r=0)=>[...e.array].sort((n,a)=>a-n)[r]??t.NA}function vr(t){return(e,r=0)=>[...e.array].sort((n,a)=>n-a)[r]??t.NA}function Cr(t){return(e,r)=>new N(Array(e).fill(r))}function Er(t){return(e,r=!1)=>new N(Array(e).fill(r))}function Sr(t){return(e,r=NaN)=>new N(Array(e).fill(r))}function jr(t){return(e,r=0)=>new N(Array(e).fill(Math.round(r)))}function Ar(t){return(e,r="")=>new N(Array(e).fill(r))}function Mr(t){return(e,r=0)=>l.from(e).get(r)}function Ir(t){return e=>e.array.pop()}function Nr(t){return(e,r)=>{e.array.push(r)}}function _r(t){return e=>t.array.max(e)-t.array.min(e)}function $r(t){return(e,r)=>r>=0&&r<e.array.length?e.array.splice(r,1)[0]:t.NA}function Vr(t){return e=>{e.array.reverse()}}function Tr(t){return(e,r,n)=>{e.array[r]=n}}function Dr(t){return e=>e.array.shift()}function Pr(t){return e=>e.array.length}function Br(t){return(e,r,n)=>{const a=n!==void 0?n+1:void 0;return new N(e.array.slice(r,a))}}function kr(t){return(e,r)=>e.array.some(r)}function Lr(t){return(e,r="asc")=>{e.array.sort((n,a)=>r==="asc"?n-a:a-n)}}function Or(t){return(e,r)=>{const n=e.array.map((a,o)=>o);return n.sort((a,o)=>{const i=e.array[a],s=e.array[o];return r?r(i,s):i-s}),new N(n)}}function Rr(t){return e=>{const r=t.array.avg(e),n=t.array.stdev(e);return n===0?new N(e.array.map(()=>0)):new N(e.array.map(a=>(a-r)/n))}}function Fr(t){return(e,r=!0)=>{const n=t.array.avg(e),a=e.array.map(i=>Math.pow(i-n,2)),o=r?e.array.length:e.array.length-1;return Math.sqrt(t.array.sum(new N(a))/o)}}function qr(t){return e=>e.array.reduce((r,n)=>r+(isNaN(n)?0:n),0)}function Wr(t){return(e,r)=>{e.array.unshift(r)}}function Gr(t){return(e,r=!0)=>{const n=t.array.avg(e),a=e.array.map(i=>Math.pow(i-n,2)),o=r?e.array.length:e.array.length-1;return t.array.sum(new N(a))/o}}var Ur=Object.defineProperty,zr=(t,e,r)=>e in t?Ur(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,g=(t,e,r)=>zr(t,typeof e!="symbol"?e+"":e,r);const Kr={abs:nr,avg:ar,clear:ir,concat:or,copy:sr,covariance:cr,every:pr,fill:lr,first:ur,from:mr,get:hr,includes:fr,indexof:dr,insert:yr,join:gr,last:br,lastindexof:wr,max:xr,min:vr,new:Cr,new_bool:Er,new_float:Sr,new_int:jr,new_string:Ar,param:Mr,pop:Ir,push:Nr,range:_r,remove:$r,reverse:Vr,set:Tr,shift:Dr,size:Pr,slice:Br,some:kr,sort:Lr,sort_indices:Or,standardize:Rr,stdev:Fr,sum:qr,unshift:Wr,variance:Gr};class Hr{constructor(e){this.context=e,g(this,"_cache",{}),g(this,"abs"),g(this,"avg"),g(this,"clear"),g(this,"concat"),g(this,"copy"),g(this,"covariance"),g(this,"every"),g(this,"fill"),g(this,"first"),g(this,"from"),g(this,"get"),g(this,"includes"),g(this,"indexof"),g(this,"insert"),g(this,"join"),g(this,"last"),g(this,"lastindexof"),g(this,"max"),g(this,"min"),g(this,"new"),g(this,"new_bool"),g(this,"new_float"),g(this,"new_int"),g(this,"new_string"),g(this,"param"),g(this,"pop"),g(this,"push"),g(this,"range"),g(this,"remove"),g(this,"reverse"),g(this,"set"),g(this,"shift"),g(this,"size"),g(this,"slice"),g(this,"some"),g(this,"sort"),g(this,"sort_indices"),g(this,"standardize"),g(this,"stdev"),g(this,"sum"),g(this,"unshift"),g(this,"variance"),Object.entries(Kr).forEach(([r,n])=>{this[r]=n(e)})}}var Xr=Object.defineProperty,Jr=(t,e,r)=>e in t?Xr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>Jr(t,typeof e!="symbol"?e+"":e,r);class J{constructor({marketData:e,source:r,tickerId:n,timeframe:a,limit:o,sDate:i,eDate:s}){v(this,"data",{open:[],high:[],low:[],close:[],volume:[],hl2:[],hlc3:[],ohlc4:[]}),v(this,"cache",{}),v(this,"taState",{}),v(this,"NA",NaN),v(this,"math"),v(this,"ta"),v(this,"input"),v(this,"request"),v(this,"array"),v(this,"core"),v(this,"lang"),v(this,"idx",0),v(this,"params",{}),v(this,"const",{}),v(this,"var",{}),v(this,"let",{}),v(this,"result"),v(this,"plots",{}),v(this,"marketData"),v(this,"source"),v(this,"tickerId"),v(this,"timeframe",""),v(this,"limit"),v(this,"sDate"),v(this,"eDate"),v(this,"pineTSCode"),this.marketData=e,this.source=r,this.tickerId=n,this.timeframe=a,this.limit=o,this.sDate=i,this.eDate=s,this.math=new bt(this),this.ta=new rr(this),this.input=new Ue(this),this.request=new St(this),this.array=new Hr(this);const c=new Ae(this);this.core={plotchar:c.plotchar.bind(c),na:c.na.bind(c),color:c.color,plot:c.plot.bind(c),nz:c.nz.bind(c)}}init(e,r,n=0){return r instanceof l&&(r=r.get(0)),e?!Array.isArray(r)||Array.isArray(r[0])?e[e.length-1]=Array.isArray(r?.[0])?r[0]:this.precision(r):e[e.length-1]=this.precision(r[r.length-1+n]):Array.isArray(r)?e=[this.precision(r[r.length-1+n])]:e=[this.precision(r)],e}precision(e,r=10){return typeof e!="number"||isNaN(e)?e:Number(e.toFixed(r))}param(e,r,n){return typeof e=="string"?e:e instanceof l?r?new l(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[n]||(this.params[n]=[]),Array.isArray(e)?new l(e,r||0):(this.params[n].length===0?this.params[n].push(e):this.params[n][this.params[n].length-1]=e,new l(this.params[n],0)))}get(e,r){if(e instanceof l)return e.get(r);if(Array.isArray(e)){const n=e.length-1-r;return n<0||n>=e.length?NaN:e[n]}return e}set(e,r){if(e instanceof l){e.set(0,r);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=r:e.push(r);return}}}var Qr=Object.defineProperty,Yr=(t,e,r)=>e in t?Qr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,I=(t,e,r)=>Yr(t,typeof e!="symbol"?e+"":e,r);class Zr{constructor(e,r,n,a,o,i){this.source=e,this.tickerId=r,this.timeframe=n,this.limit=a,this.sDate=o,this.eDate=i,I(this,"data",[]),I(this,"open",[]),I(this,"high",[]),I(this,"low",[]),I(this,"close",[]),I(this,"volume",[]),I(this,"hl2",[]),I(this,"hlc3",[]),I(this,"ohlc4",[]),I(this,"openTime",[]),I(this,"closeTime",[]),I(this,"_readyPromise",null),I(this,"_ready",!1),I(this,"_transpiledCode",null),this._readyPromise=new Promise(s=>{this.loadMarketData(e,r,n,a,o,i).then(c=>{const u=c;this.data=u;const h=u.map(w=>w.open),f=u.map(w=>w.close),m=u.map(w=>w.high),p=u.map(w=>w.low),d=u.map(w=>w.volume),b=u.map(w=>(w.high+w.low+w.close)/3),x=u.map(w=>(w.high+w.low)/2),S=u.map(w=>(w.high+w.low+w.open+w.close)/4),V=u.map(w=>w.openTime),P=u.map(w=>w.closeTime);this.open=h,this.close=f,this.high=m,this.low=p,this.volume=d,this.hl2=x,this.hlc3=b,this.ohlc4=S,this.openTime=V,this.closeTime=P,this._ready=!0,s(!0)})})}get transpiledCode(){return this._transpiledCode}async loadMarketData(e,r,n,a,o,i){return Array.isArray(e)?e:e.getMarketData(r,n,a,o,i)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,r,n){if(n&&n>0){const a=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(e,r,n,a)}else return this._runComplete(e,r)}async _runComplete(e,r){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(e);return this._transpiledCode=this._transpileCode(e),await this._executeIterations(n,this._transpiledCode,this.data.length-r,this.data.length),n}async*_runPaginated(e,r,n,a=!1){await this.ready(),r||(r=this.data.length);const o=this._initializeContext(e);this._transpiledCode=this._transpileCode(e);let i=this.data.length-r;for(;;){const s=this.data.length-i;if(s>0){const h=Math.min(s,n),f=this._getResultLength(o.result);await this._executeIterations(o,this._transpiledCode,i,i+h),i+=h,yield this._createPageContext(o,f);continue}if(!a||Array.isArray(this.source))break;const{newCandles:c,updatedLastCandle:u}=await this._updateMarketData();if(c===0&&!u){yield null;continue}this._removeLastResult(o),i=this.data.length-(c+1)}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const r=Object.keys(e);if(r.length>0&&Array.isArray(e[r[0]]))return e[r[0]].length}return 0}_createPageContext(e,r){const n=new J({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});if(n.pineTSCode=e.pineTSCode,n.idx=e.idx,Array.isArray(e.result))n.result=e.result.slice(r);else if(typeof e.result=="object"&&e.result!==null){n.result={};for(let a in e.result)Array.isArray(e.result[a])?n.result[a]=e.result[a].slice(r):n.result[a]=e.result[a]}else n.result=e.result;return n.plots={...e.plots},n}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const r=this.source,n=this.data.length-1,a=this.data[n].openTime;try{const o=await r.getMarketData(this.tickerId,this.timeframe,void 0,a,e);if(!o||o.length===0)return{newCandles:0,updatedLastCandle:!1};let i=!1,s=0;for(let c=0;c<o.length;c++){const u=o[c];u.openTime===a?(this._replaceCandle(n,u),i=!0):u.openTime>a&&(this._appendCandle(u),s++)}return{newCandles:s,updatedLastCandle:i}}catch(o){return console.error("Error updating market data:",o),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,r){this.data[e]=r,this.open[e]=r.open,this.close[e]=r.close,this.high[e]=r.high,this.low[e]=r.low,this.volume[e]=r.volume,this.hl2[e]=(r.high+r.low)/2,this.hlc3[e]=(r.high+r.low+r.close)/3,this.ohlc4[e]=(r.high+r.low+r.open+r.close)/4,this.openTime[e]=r.openTime,this.closeTime[e]=r.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.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let r in e.result)Array.isArray(e.result[r])&&e.result[r].pop();e.data.close.pop(),e.data.open.pop(),e.data.high.pop(),e.data.low.pop(),e.data.volume.pop(),e.data.hl2.pop(),e.data.hlc3.pop(),e.data.ohlc4.pop(),e.data.openTime.pop(),e.data.closeTime&&e.data.closeTime.pop()}_initializeContext(e){const r=new J({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});return r.pineTSCode=e,r.data.close=[],r.data.open=[],r.data.high=[],r.data.low=[],r.data.volume=[],r.data.hl2=[],r.data.hlc3=[],r.data.ohlc4=[],r.data.openTime=[],r.data.closeTime=[],r}_transpileCode(e){return Ce.bind(this)(e)}async _executeIterations(e,r,n,a){const o=["const","var","let","params"];for(let i=n;i<a;i++){e.idx=i,e.data.close.push(this.close[i]),e.data.open.push(this.open[i]),e.data.high.push(this.high[i]),e.data.low.push(this.low[i]),e.data.volume.push(this.volume[i]),e.data.hl2.push(this.hl2[i]),e.data.hlc3.push(this.hlc3[i]),e.data.ohlc4.push(this.ohlc4[i]),e.data.openTime.push(this.openTime[i]);const s=await r(e);if(typeof s=="object"){typeof e.result!="object"&&(e.result={});for(let c in s){e.result[c]===void 0&&(e.result[c]=[]);const u=Array.isArray(s[c])?s[c][s[c].length-1]:s[c];e.result[c].push(u)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(s);for(let c of o)for(let u in e[c])if(Array.isArray(e[c][u])){const h=e[c][u],f=h[h.length-1];h.push(f)}}}}var en=Object.defineProperty,tn=(t,e,r)=>e in t?en(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,z=(t,e,r)=>tn(t,typeof e!="symbol"?e+"":e,r);const rn="https://api.binance.com/api/v3",G={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 nn{constructor(e=5*60*1e3){z(this,"cache"),z(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([r,n])=>n!==void 0).map(([r,n])=>`${r}:${n}`).join("|")}get(e){const r=this.generateKey(e),n=this.cache.get(r);return n?Date.now()-n.timestamp>this.cacheDuration?(this.cache.delete(r),null):n.data:null}set(e,r){const n=this.generateKey(e);this.cache.set(n,{data:r,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[r,n]of this.cache.entries())e-n.timestamp>this.cacheDuration&&this.cache.delete(r)}}class an{constructor(){z(this,"cacheManager"),this.cacheManager=new nn(5*60*1e3)}async getMarketDataInterval(e,r,n,a){try{const o=G[r.toUpperCase()];if(!o)return console.error(`Unsupported timeframe: ${r}`),[];const i={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3};let s=[],c=n;const u=a,h=i[o];if(!h)return console.error(`Duration not defined for interval: ${o}`),[];for(;c<u;){const f=Math.min(c+1e3*h,u),m=await this.getMarketData(e,r,1e3,c,f);if(m.length===0)break;s=s.concat(m),c=m[m.length-1].closeTime+1}return s}catch(o){return console.error("Error in getMarketDataInterval:",o),[]}}async getMarketData(e,r,n,a,o){try{const i={tickerId:e,timeframe:r,limit:n,sDate:a,eDate:o},s=this.cacheManager.get(i);if(s)return console.log("cache hit",e,r,n,a,o),s;const c=G[r.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${r}`),[];if(this.shouldPaginate(r,n,a,o)&&a&&o){const m=await this.getMarketDataInterval(e,r,a,o),p=n?m.slice(0,n):m;return this.cacheManager.set(i,p),p}let u=`${rn}/klines?symbol=${e}&interval=${c}`;n&&(u+=`&limit=${Math.min(n,1e3)}`),a&&(u+=`&startTime=${a}`),o&&(u+=`&endTime=${o}`);const h=await fetch(u);if(!h.ok)throw new Error(`HTTP error! status: ${h.status}`);const f=(await h.json()).map(m=>({openTime:parseInt(m[0]),open:parseFloat(m[1]),high:parseFloat(m[2]),low:parseFloat(m[3]),close:parseFloat(m[4]),volume:parseFloat(m[5]),closeTime:parseInt(m[6]),quoteAssetVolume:parseFloat(m[7]),numberOfTrades:parseInt(m[8]),takerBuyBaseAssetVolume:parseFloat(m[9]),takerBuyQuoteAssetVolume:parseFloat(m[10]),ignore:m[11]}));return this.cacheManager.set(i,f),f}catch(i){return console.error("Error in binance.klines:",i),[]}}shouldPaginate(e,r,n,a){if(r&&r>1e3)return!0;if(n&&a){const o=G[e.toUpperCase()],i={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3}[o];if(i)return Math.ceil((a-n)/i)>1e3}return!1}}var on=Object.defineProperty,sn=(t,e,r)=>e in t?on(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Q=(t,e,r)=>sn(t,typeof e!="symbol"?e+"":e,r);const cn=ae(import.meta.url),pn=F.dirname(cn);class ln{constructor(e){if(Q(this,"dataCache",new Map),Q(this,"dataDirectory"),e)this.dataDirectory=e;else{const r=F.resolve(pn,"../../../");this.dataDirectory=F.join(r,"tests","compatibility","_data")}}getDataFileName(e,r,n,a){return n&&a?`${e}-${r}-${n}-${a}.json`:null}loadDataFromFile(e){const r=`file:${e}`;if(this.dataCache.has(r))return this.dataCache.get(r);const n=F.join(this.dataDirectory,e);if(!R.existsSync(n))throw new Error(`Mock data file not found: ${n}`);const a=R.readFileSync(n,"utf-8"),o=JSON.parse(a);return this.dataCache.set(r,o),o}findDataFile(e,r,n,a){if(!R.existsSync(this.dataDirectory))return null;const o=R.readdirSync(this.dataDirectory).filter(c=>c.endsWith(".json"));if(n&&a){const c=`${e}-${r}-${n}-${a}.json`;if(o.includes(c))return c}const i=new RegExp(`^${e}-${r}-(\\d+)-(\\d+)\\.json$`),s=o.filter(c=>i.test(c)).map(c=>{const u=c.match(i);return{file:c,startTime:parseInt(u[1]),endTime:parseInt(u[2])}}).sort((c,u)=>u.endTime-c.endTime);if(s.length===0)return null;if(n&&a){const c=s.find(u=>u.startTime<=n&&u.endTime>=a);if(c)return c.file}return s[0].file}filterData(e,r,n,a){let o=e;return(r||n)&&(o=e.filter(i=>{const s=!r||i.openTime>=r,c=!n||i.openTime<=n;return s&&c})),o.sort((i,s)=>i.openTime-s.openTime),a&&a>0&&(o=o.slice(0,a)),o}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()}async getMarketData(e,r,n,a,o){try{const i=this.normalizeTimeframe(r),s=this.findDataFile(e,i,a,o);if(!s)return console.warn(`No mock data file found for ${e} ${i}. Searched in: ${this.dataDirectory}`),[];const c=this.loadDataFromFile(s);return this.filterData(c,a,o,n)}catch(i){return console.error("Error in MockProvider.getMarketData:",i),[]}}clearCache(){this.dataCache.clear()}setDataDirectory(e){this.dataDirectory=e,this.clearCache()}}const un=typeof process<"u"&&process.versions&&process.versions.node;let q=null;if(un)try{q=new ln}catch{q=null}const hn={Binance:new an,...q?{Mock:q}:{}};export{J as Context,Zr as PineTS,hn as Provider};
|
|
18
|
+
import*as he from"acorn";import*as z from"astring";import*as I from"acorn-walk";import*as K from"fs";import*as J from"path";import{fileURLToPath as we}from"url";var Ne=Object.defineProperty,Se=(e,t,n)=>t in e?Ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,A=(e,t,n)=>Se(e,typeof t!="symbol"?t+"":t,n);const ve=new Set(["Infinity","NaN","undefined","null","true","false"]),xe=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 _e{constructor(){A(this,"scopes",[]),A(this,"scopeTypes",[]),A(this,"scopeCounts",new Map),A(this,"contextBoundVars",new Set),A(this,"arrayPatternElements",new Set),A(this,"rootParams",new Set),A(this,"localSeriesVars",new Set),A(this,"varKinds",new Map),A(this,"loopVars",new Set),A(this,"loopVarNames",new Map),A(this,"paramIdCounter",0),A(this,"cacheIdCounter",0),A(this,"tempVarCounter",0),A(this,"taCallIdCounter",0),A(this,"hoistingStack",[]),A(this,"suppressHoisting",!1),this.pushScope("glb")}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++}`}}pushScope(t){this.scopes.push(new Map),this.scopeTypes.push(t),this.scopeCounts.set(t,(this.scopeCounts.get(t)||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(t){this.localSeriesVars.add(t)}isLocalSeriesVar(t){return this.localSeriesVars.has(t)}addContextBoundVar(t,n=!1){this.contextBoundVars.add(t),n&&this.rootParams.add(t)}removeContextBoundVar(t){this.contextBoundVars.has(t)&&(this.contextBoundVars.delete(t),this.rootParams.has(t)&&this.rootParams.delete(t))}addArrayPatternElement(t){this.arrayPatternElements.add(t)}isContextBound(t){return ve.has(t)||xe.has(t)?!1:this.contextBoundVars.has(t)}isArrayPatternElement(t){return this.arrayPatternElements.has(t)}isRootParam(t){return this.rootParams.has(t)}addLoopVariable(t,n){this.loopVars.add(t),this.loopVarNames.set(t,n)}getLoopVariableName(t){return this.loopVarNames.get(t)}isLoopVariable(t){return this.loopVars.has(t)}addVariable(t,n){if(this.isContextBound(t))return t;const r=this.scopes[this.scopes.length-1],i=this.scopeTypes[this.scopeTypes.length-1],o=this.scopeCounts.get(i)||1,a=`${i}${o}_${t}`;return r.set(t,a),this.varKinds.set(a,n),a}getVariable(t){if(this.loopVars.has(t)){const n=this.loopVarNames.get(t);if(n)return[n,"let"]}if(this.isContextBound(t))return[t,"let"];for(let n=this.scopes.length-1;n>=0;n--){const r=this.scopes[n];if(r.has(t)){const i=r.get(t),o=this.varKinds.get(i)||"let";return[i,o]}}return[t,"let"]}generateTempVar(){return`temp_${++this.tempVarCounter}`}enterHoistingScope(){this.hoistingStack.push([])}exitHoistingScope(){return this.hoistingStack.pop()||[]}addHoistedStatement(t){this.hoistingStack.length>0&&!this.suppressHoisting&&this.hoistingStack[this.hoistingStack.length-1].push(t)}setSuppressHoisting(t){this.suppressHoisting=t}shouldSuppressHoisting(){return this.suppressHoisting}generateParamId(){return`p${this.paramIdCounter++}`}}const M="$",b={createIdentifier(e){return{type:"Identifier",name:e}},createLiteral(e){return{type:"Literal",value:e}},createMemberExpression(e,t,n=!1){return{type:"MemberExpression",object:e,property:t,computed:n}},createContextIdentifier(){return this.createIdentifier(M)},createContextVariableReference(e,t){const n=this.createContextIdentifier(),r=this.createIdentifier(e),i=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(n,r,!1),i,!1)},createContextVariableAccess0(e,t){const n=this.createContextVariableReference(e,t);return this.createGetCall(n,0)},createArrayAccess(e,t){const n=typeof t=="number"?this.createLiteral(t):t;return this.createMemberExpression(e,n,!0)},createCallExpression(e,t){return{type:"CallExpression",callee:e,arguments:t}},createAssignmentExpression(e,t,n="="){return{type:"AssignmentExpression",operator:n,left:e,right:t}},createExpressionStatement(e){return{type:"ExpressionStatement",expression:e}},createInitCall(e,t,n){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),i=[e,t];return n&&i.push(n),this.createCallExpression(r,i)},createInitVarCall(e,t){const n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),r=[e,t];return this.createCallExpression(n,r)},createGetCall(e,t){const n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),r=typeof t=="number"?this.createLiteral(t):t;return this.createCallExpression(n,[e,r])},createSetCall(e,t){const n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(n,[e,t])},createMathEqCall(e,t){const n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("math"),!1),r=this.createMemberExpression(n,this.createIdentifier("__eq"),!1);return this.createCallExpression(r,[e,t])},createWrapperFunction(e){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:e}]}}},createVariableDeclaration(e,t){return{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:this.createIdentifier(e),init:t}]}}};function Ce(e){let t=null,n=M;if(e.type==="Program"&&e.body.length>0){const l=e.body[0];if(l.type==="ExpressionStatement"&&(l.expression.type==="ArrowFunctionExpression"||l.expression.type==="FunctionExpression")){const f=l.expression;f.body.type==="BlockStatement"&&(t=f.body.body,f.params.length>0&&f.params[0].type==="Identifier"&&(n=f.params[0].name))}}if(!t)return;const r=new Set,i=new Set,o=l=>{l.type==="Identifier"?r.add(l.name):l.type==="ObjectPattern"?l.properties.forEach(f=>o(f.value)):l.type==="ArrayPattern"&&l.elements.forEach(f=>{f&&o(f)})};I.recursive(e,{},{VariableDeclarator(l,f,g){o(l.id),l.init&&g(l.init,f)},FunctionDeclaration(l,f,g){o(l.id),g(l.body,f)},Identifier(l,f,g){i.add(l.name)},MemberExpression(l,f,g){g(l.object,f),l.computed&&g(l.property,f)},Property(l,f,g){l.computed&&g(l.key,f),g(l.value,f)}}),t.forEach(l=>{l.type==="VariableDeclaration"?l.declarations.forEach(f=>o(f.id)):l.type==="FunctionDeclaration"&&o(l.id)});const a=["open","high","low","close","volume","hl2","hlc3","ohlc4","openTime","closeTime"],s=["input","ta","math","request","array","na","plotchar","color","plot","nz","strategy","library","str","box","line","label","table","map","matrix"],c=a.filter(l=>!r.has(l)),p=s.filter(l=>!r.has(l)),m=c.filter(l=>i.has(l)),h=p.filter(l=>i.has(l)),d=[];m.length>0&&d.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:m.map(l=>({type:"Property",key:{type:"Identifier",name:l},value:{type:"Identifier",name:l},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},property:{type:"Identifier",name:"data"},computed:!1}}]}),h.length>0&&d.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:h.map(l=>({type:"Property",key:{type:"Identifier",name:l},value:{type:"Identifier",name:l},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},property:{type:"Identifier",name:"pine"},computed:!1}}]}),d.length>0&&t.unshift(...d)}function Ee(e){let t=null,n=M;if(e.type==="Program"&&e.body.length>0){const s=e.body[0];if(s.type==="ExpressionStatement"&&(s.expression.type==="ArrowFunctionExpression"||s.expression.type==="FunctionExpression")){const c=s.expression;c.body.type==="BlockStatement"&&(t=c.body.body,c.params.length>0&&c.params[0].type==="Identifier"&&(n=c.params[0].name))}}if(!t)return;const r=new Set(["open","high","low","close","volume","hl2","hlc3","ohlc4","openTime","closeTime"]),i=new Set(["input","ta","math","request","array","na","plotchar","color","plot","nz","strategy","library","str","box","line","label","table","map","matrix"]),o=new Set(["na","nz","plot","plotchar","color"]),a=new Map;t.forEach(s=>{s.type==="VariableDeclaration"&&s.declarations.forEach(c=>{if(c.init&&c.init.type==="MemberExpression"&&c.init.object.type==="Identifier"&&c.init.object.name===n&&c.init.property.type==="Identifier"){const p=c.init.property.name;let m=null;if(p==="data"?m=r:p==="pine"?m=i:p==="core"&&(m=o),m&&c.id.type==="ObjectPattern")c.id.properties.forEach(h=>{if(h.type==="Property"&&h.key.type==="Identifier"&&h.value.type==="Identifier"){const d=h.key.name,l=h.value.name;m.has(d)&&d!==l&&(a.set(l,d),h.value.name=d,h.shorthand=!0)}});else if(c.id.type==="Identifier"&&["ta","math","input","request","array"].includes(p)){const h=p,d=c.id.name;h!==d&&(a.set(d,h),c.id.name=h)}}})}),a.size>0&&I.recursive(e,{},{Identifier(s){a.has(s.name)&&(s.name=a.get(s.name))},MemberExpression(s,c,p){p(s.object,c),s.computed&&p(s.property,c)},Property(s,c,p){s.computed&&p(s.key,c),p(s.value,c)}})}function Ie(e){try{const t=he.parse(e,{ecmaVersion:"latest",sourceType:"module"});if(t.type==="Program"&&t.body.length===1){const n=t.body[0];if(n.type==="ExpressionStatement"){const r=n.expression;if(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")return!0}if(n.type==="FunctionDeclaration")return!0}return!1}catch{return!1}}function Me(e){return e=e.trim(),Ie(e)?e:`(context) => {
|
|
19
|
+
${e}
|
|
20
|
+
}`}function je(e){I.recursive(e,null,{VariableDeclaration(t,n,r){t.declarations&&t.declarations.length>0&&t.declarations.forEach(i=>{if(i.init&&i.init.type==="ArrowFunctionExpression"&&i.init.start!==0){const o={type:"FunctionDeclaration",id:i.id,params:i.init.params,body:i.init.body.type==="BlockStatement"?i.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:i.init.body}]},async:i.init.async,generator:!1};Object.assign(t,o)}}),t.body&&t.body.body&&t.body.body.forEach(i=>r(i,n))}})}function Ae(e,t){I.simple(e,{VariableDeclaration(n){n.declarations.forEach(r=>{const i=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===M||r.init.object.name==="context2"),o=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===M||r.init.object.object.name==="context2");(i||o)&&(r.id.name&&t.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(a=>{a.key.name&&t.addContextBoundVar(a.key.name)}))})}})}function $e(e,t,n=!1){e.params.forEach(r=>{r.type==="Identifier"&&t.addContextBoundVar(r.name,n)})}function Ve(e,t){e.params.forEach(n=>{n.type==="Identifier"&&t.addContextBoundVar(n.name,!1)})}function De(e,t){let n;return I.simple(e,{FunctionDeclaration(r){Ve(r,t)},ArrowFunctionExpression(r){const i=r.start===0;i&&r.params&&r.params.length>0&&(n=r.params[0].name,r.params[0].name=M),$e(r,t,i)},VariableDeclaration(r){r.declarations.forEach(i=>{if(i.id.type==="ArrayPattern"){const o=t.generateTempVar(),a={type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:o},init:i.init}]};i.id.elements?.forEach(c=>{c.type==="Identifier"&&t.addArrayPatternElement(c.name)});const s=i.id.elements.map((c,p)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:c,init:{type:"MemberExpression",object:{type:"Identifier",name:o},property:{type:"Literal",value:p},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[a,...s]})}})},ForStatement(r){}}),n}const ne={type:"Identifier",name:"undefined"};function F(e,t){if(e.computed&&e.property.type==="Identifier"){if(t.isLoopVariable(e.property.name)){if(e.object.type==="Identifier"&&!t.isLoopVariable(e.object.name)&&!t.isContextBound(e.object.name)){const[n,r]=t.getVariable(e.object.name),i=b.createContextVariableReference(r,n),o=b.createGetCall(i,e.property);Object.assign(e,o),e._indexTransformed=!0}return}if(!t.isContextBound(e.property.name)){const[n,r]=t.getVariable(e.property.name);e.property=b.createContextVariableReference(r,n),e.property=b.createGetCall(e.property,0)}}if(e.computed&&e.object.type==="Identifier"){if(t.isLoopVariable(e.object.name))return;if(!t.isContextBound(e.object.name)){const[n,r]=t.getVariable(e.object.name);e.object=b.createContextVariableReference(r,n)}if(e.property.type==="MemberExpression"){const n=e.property;n._indexTransformed||(F(n,t),n._indexTransformed=!0)}}}function L(e,t){const n=b.createGetCall(b.createIdentifier(e.name),0);e.start!==void 0&&(n.start=e.start),e.end!==void 0&&(n.end=e.end),n._indexTransformed=!0,Object.assign(e,n)}function T(e,t){if(e.name!==M){if(e.name==="na"&&!(e.parent&&e.parent.type==="CallExpression"&&e.parent.callee===e)){e.name="NaN";return}if(e.name==="Math"||e.name==="NaN"||e.name==="undefined"||e.name==="Infinity"||e.name==="null"||e.name.startsWith("'")&&e.name.endsWith("'")||e.name.startsWith('"')&&e.name.endsWith('"')||e.name.startsWith("`")&&e.name.endsWith("`")||t.isLoopVariable(e.name)||t.isContextBound(e.name)&&!t.isRootParam(e.name))return;const n=e.parent&&e.parent.type==="MemberExpression"&&e.parent.object===e&&t.isContextBound(e.name),r=e.parent&&e.parent.type==="CallExpression"&&e.parent.callee&&e.parent.callee.type==="MemberExpression"&&e.parent.callee.property.name==="param";e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left;let i=!1;if(e.parent&&e.parent.type==="CallExpression"&&e.parent.arguments.includes(e)){const d=e.parent.callee;d.type==="MemberExpression"&&d.object&&d.object.name===M&&["get","set","init","param"].includes(d.property.name)?e.parent.arguments.indexOf(e)===0&&(i=!0):i=!0}const o=e.parent&&e.parent.type==="MemberExpression"&&e.parent.computed,a=e.parent&&e.parent.type==="MemberExpression"&&e.parent.computed&&e.parent.property===e&&e.parent.parent&&e.parent.parent.type==="CallExpression"&&e.parent.parent.callee&&e.parent.parent.callee.type==="MemberExpression"&&t.isContextBound(e.parent.parent.callee.object.name),s=e.parent&&e.parent.type==="CallExpression"&&e.parent.callee===e,c=e.parent&&e.parent.type==="MemberExpression"&&e.parent.computed&&e.parent.object===e;if(n||r||i||a||s){if(s||t.isLocalSeriesVar(e.name))return;const[d,l]=t.getVariable(e.name),f=b.createContextVariableReference(l,d);Object.assign(e,f);return}if(t.isLocalSeriesVar(e.name)){if(!c&&!o){const d=b.createIdentifier(e.name),l=b.createGetCall(d,0);Object.assign(e,l)}return}const[p,m]=t.getVariable(e.name),h=b.createContextVariableReference(m,p);if(!c&&!o){const d=b.createGetCall(h,0);Object.assign(e,d)}else Object.assign(e,h)}}function B(e,t,n){if(e.object&&e.object.type==="Identifier"&&e.object.name==="Math")return;const r=["ta","math","request","array","input"];if(e.object&&e.object.type==="Identifier"&&r.includes(e.object.name)&&n.isContextBound(e.object.name)&&!e.computed){const p=e.parent&&e.parent.type==="CallExpression"&&e.parent.callee===e,m=e.parent&&(e.parent.type==="VariableDeclarator"||e.parent.type==="Property"||e.parent.type==="AssignmentExpression");if(!p&&!m){const h={type:"CallExpression",callee:{type:"MemberExpression",object:e.object,property:e.property,computed:!1},arguments:[],_transformed:!1};e.start!==void 0&&(h.start=e.start),e.end!==void 0&&(h.end=e.end),Object.assign(e,h);return}}const i=n.getCurrentScopeType()=="if",o=n.getCurrentScopeType()=="els",a=n.getCurrentScopeType()=="for";if(!i&&!o&&!a&&e.object&&e.object.type==="Identifier"&&n.isContextBound(e.object.name)&&!n.isRootParam(e.object.name)&&!e.computed)return;e._indexTransformed||(F(e,n),e._indexTransformed=!0);const s=e.object&&e.object.type==="MemberExpression"&&e.object.object&&e.object.object.type==="MemberExpression"&&e.object.object.object&&e.object.object.object.name===M,c=e.object&&e.object.type==="Identifier"&&n.isContextBound(e.object.name);if(e.computed&&(s||c)){if(e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e)return;const p=b.createGetCall(e.object,e.property);e.start&&(p.start=e.start),e.end&&(p.end=e.end),Object.assign(e,p)}}function U(e,t){if(e.type==="Identifier"){if(e.name==="na")return e.name="NaN",e;if(t.isLoopVariable(e.name))return e;if(t.isRootParam(e.name)){const[i,o]=t.getVariable(e.name);return b.createContextVariableReference(o,i)}if(t.isContextBound(e.name)||t.isLocalSeriesVar(e.name))return e;const[n,r]=t.getVariable(e.name);return n===e.name&&!t.isContextBound(e.name)?e:b.createContextVariableReference(r,n)}return e}function R(e,t,n=""){switch(e.type){case"BinaryExpression":return de(e,t,n);case"MemberExpression":return{type:"MemberExpression",object:e.object.type==="Identifier"?U(e.object,t):e.object,property:e.property,computed:e.computed};case"Identifier":{if(t.isLoopVariable(e.name)||e.parent&&e.parent.type==="MemberExpression"&&e.parent.property===e)return e;const r=U(e,t);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:b.createGetCall(r,0)}case"UnaryExpression":return fe(e,t,n);case"ConditionalExpression":{const r=R(e.test,t,n),i=R(e.consequent,t,n),o=R(e.alternate,t,n);return{type:"ConditionalExpression",test:r,consequent:i,alternate:o,start:e.start,end:e.end}}}return e}function de(e,t,n){const r=R(e.left,t,n),i=R(e.right,t,n),o={type:"BinaryExpression",operator:e.operator,left:r,right:i,start:e.start,end:e.end};return I.recursive(o,t,{CallExpression(a,s){a._transformed||W(a,s)},MemberExpression(a){B(a,"",t)}}),o}function Te(e,t,n){const r=R(e.left,t,n),i=R(e.right,t,n),o={type:"LogicalExpression",operator:e.operator,left:r,right:i,start:e.start,end:e.end};return I.recursive(o,t,{CallExpression(a,s){a._transformed||W(a,s)}}),o}function ke(e,t,n){I.recursive(e,{parent:e,inNamespaceCall:!1},{Identifier(a,s,c){if(a.name=="NaN")return;if(a.name=="na"){a.name="NaN";return}a.parent=s.parent,T(a,t);const p=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||p)&&(a.type==="MemberExpression"?F(a,t):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===M&&a.parent.callee.property.name==="get"||L(a)))},MemberExpression(a,s,c){F(a,t),a.object&&c(a.object,{parent:a,inNamespaceCall:s.inNamespaceCall})},ConditionalExpression(a,s,c){a.test&&c(a.test,{parent:a,inNamespaceCall:s.inNamespaceCall}),a.consequent&&c(a.consequent,{parent:a,inNamespaceCall:s.inNamespaceCall}),a.alternate&&c(a.alternate,{parent:a,inNamespaceCall:s.inNamespaceCall})},CallExpression(a,s,c){const p=a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&a.callee.object.type==="Identifier"&&t.isContextBound(a.callee.object.name);W(a,t),a.arguments.forEach(m=>c(m,{parent:a,inNamespaceCall:p||s.inNamespaceCall}))}});const r=b.createMemberExpression(b.createIdentifier(n),b.createIdentifier("param")),i=t.generateParamId(),o={type:"CallExpression",callee:r,arguments:[e,ne,{type:"Identifier",name:`'${i}'`}],_transformed:!0,_isParamCall:!0};if(!t.shouldSuppressHoisting()){const a=i;t.addLocalSeriesVar(a);const s=b.createVariableDeclaration(a,o);return t.addHoistedStatement(s),b.createIdentifier(a)}return o}function fe(e,t,n){const r=R(e.argument,t,n);return{type:"UnaryExpression",operator:e.operator,prefix:e.prefix,argument:r,start:e.start,end:e.end}}function se(e,t,n){switch(e?.type){case"BinaryExpression":e=de(e,n,t);break;case"LogicalExpression":e=Te(e,n,t);break;case"ConditionalExpression":return ke(e,n,t);case"UnaryExpression":e=fe(e,n,t);break;case"ArrayExpression":e.elements=e.elements.map(s=>{if(s.type==="Identifier"){if(n.isContextBound(s.name)&&!n.isRootParam(s.name))return s;const[c,p]=n.getVariable(s.name);return b.createContextVariableAccess0(p,c)}return s});break}if(e.type==="MemberExpression"&&e.computed&&e.property){const s=e.object.type==="Identifier"&&n.isContextBound(e.object.name)&&!n.isRootParam(e.object.name)?e.object:U(e.object,n),c=e.property.type==="Identifier"&&!n.isContextBound(e.property.name)&&!n.isLoopVariable(e.property.name)?U(e.property,n):e.property,p=b.createMemberExpression(b.createIdentifier(t),b.createIdentifier("param")),m=n.generateParamId(),h={type:"CallExpression",callee:p,arguments:[s,c,{type:"Identifier",name:`'${m}'`}],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){const d=m;n.addLocalSeriesVar(d);const l=b.createVariableDeclaration(d,h);return n.addHoistedStatement(l),b.createIdentifier(d)}return h}if(e.type==="ObjectExpression"&&(e.properties=e.properties.map(s=>{if(s.value.name){const[c,p]=n.getVariable(s.value.name);return{type:"Property",key:{type:"Identifier",name:s.key.name},value:b.createContextVariableReference(p,c),kind:"init",method:!1,shorthand:!1,computed:!1}}return s})),e.type==="Identifier"){if(e.name==="na")return e.name="NaN",e;if(n.isContextBound(e.name)&&!n.isRootParam(e.name)){const s=b.createMemberExpression(b.createIdentifier(t),b.createIdentifier("param")),c=n.generateParamId(),p={type:"CallExpression",callee:s,arguments:[e,ne,{type:"Identifier",name:`'${c}'`}],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){const m=c;n.addLocalSeriesVar(m);const h=b.createVariableDeclaration(m,p);return n.addHoistedStatement(h),b.createIdentifier(m)}return p}}e?.type==="CallExpression"&&W(e,n);const r=b.createMemberExpression(b.createIdentifier(t),b.createIdentifier("param")),i=e.type==="Identifier"?U(e,n):e,o=n.generateParamId(),a={type:"CallExpression",callee:r,arguments:[i,ne,{type:"Identifier",name:`'${o}'`}],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){const s=o;n.addLocalSeriesVar(s);const c=b.createVariableDeclaration(s,a);return n.addHoistedStatement(c),b.createIdentifier(s)}return a}function W(e,t,n){if(!e._transformed){if(e.callee&&e.callee.type==="MemberExpression"&&e.callee.object&&e.callee.object.type==="Identifier"&&(t.isContextBound(e.callee.object.name)||e.callee.object.name==="math"||e.callee.object.name==="ta")){if(e.callee.object.name===M&&["get","init","param"].includes(e.callee.property.name))return;const r=e.callee.object.name,i=[];if(e.arguments.forEach(o=>{if(o._isParamCall){i.push(o);return}i.push(se(o,r,t))}),e.arguments=i,r==="ta"&&e.arguments.push(t.getNextTACallId()),!t.shouldSuppressHoisting()){const o=t.generateTempVar();t.addLocalSeriesVar(o);const a=b.createVariableDeclaration(o,Object.assign({},e));t.addHoistedStatement(a),Object.assign(e,b.createIdentifier(o));return}e._transformed=!0}else e.callee&&e.callee.type==="Identifier"&&(e.arguments=e.arguments.map(r=>r._isParamCall?r:se(r,M,t)),e._transformed=!0);e.arguments.forEach(r=>{I.recursive(r,{parent:e},{Identifier(i,o,a){i.parent=o.parent,T(i,t);const s=i.parent&&i.parent.type==="BinaryExpression";(i.parent&&i.parent.type==="ConditionalExpression"||s)&&(i.type==="MemberExpression"?F(i,t):i.type==="Identifier"&&(i.parent&&i.parent.type==="CallExpression"&&i.parent.callee&&i.parent.callee.object&&i.parent.callee.object.name===M&&i.parent.callee.property.name==="get"||L(i)))},CallExpression(i,o,a){i._transformed||W(i,t)},MemberExpression(i,o,a){B(i,"",t),i.object&&a(i.object,{parent:i})}})})}}function ge(e,t){let n=null;if(e.left.type==="Identifier"){const[r,i]=t.getVariable(e.left.name);n=b.createContextVariableReference(i,r)}else if(e.left.type==="MemberExpression"&&e.left.computed&&e.left.object.type==="Identifier"){const r=e.left.object.name,[i,o]=t.getVariable(r),a=i!==r,s=t.isContextBound(r);(a||s)&&!t.isLoopVariable(r)&&e.left.property.type==="Literal"&&e.left.property.value===0&&(n=b.createContextVariableReference(o,i))}if(I.recursive(e.right,{parent:e.right,inNamespaceCall:!1},{Identifier(r,i,o){r.name=="na"&&(r.name="NaN"),r.parent=i.parent,T(r,t);const a=r.parent&&r.parent.type==="BinaryExpression",s=r.parent&&r.parent.type==="ConditionalExpression",c=t.isContextBound(r.name)&&!t.isRootParam(r.name),p=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.object===r,m=r.parent&&r.parent._isParamCall,h=r.parent&&r.parent.type==="MemberExpression",d=r.name==="NaN",l=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===M&&r.parent.callee.property.name==="get";(c||s||a)&&(r.type==="MemberExpression"?F(r,t):r.type==="Identifier"&&!h&&!p&&!m&&!d&&!l&&L(r))},MemberExpression(r,i,o){B(r,"",t),r.type==="CallExpression"?r.arguments.forEach(a=>o(a,{parent:r,inNamespaceCall:i.inNamespaceCall})):r.object&&o(r.object,{parent:r,inNamespaceCall:i.inNamespaceCall})},CallExpression(r,i,o){const a=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&t.isContextBound(r.callee.object.name);W(r,t),r.type==="CallExpression"&&r.arguments.forEach(s=>o(s,{parent:r,inNamespaceCall:a||i.inNamespaceCall}))}}),n){let r=e.right;if(e.operator!=="="){const o=e.operator.replace("=",""),a=b.createGetCall(n,0);r={type:"BinaryExpression",operator:o,left:a,right:e.right,start:e.start,end:e.end}}const i=b.createSetCall(n,r);e.start&&(i.start=e.start),e.end&&(i.end=e.end),Object.assign(e,i)}}function ye(e,t){e.declarations.forEach(n=>{n.init.name=="na"&&(n.init.name="NaN");const r=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===M||n.init.object.name==="context2"),i=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===M||n.init.object.object.name==="context2"),o=n.init&&n.init.type==="ArrowFunctionExpression";if(r){n.id.name&&t.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(l=>{l.key.name&&t.addContextBoundVar(l.key.name)}),n.init.object.name=M;return}if(i){n.id.name&&t.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(l=>{l.key.name&&t.addContextBoundVar(l.key.name)}),n.init.object.object.name=M;return}o&&n.init.params.forEach(l=>{l.type==="Identifier"&&t.addContextBoundVar(l.name)});const a=t.addVariable(n.id.name,e.kind),s=e.kind;n.init&&!o&&(n.init.type==="CallExpression"&&n.init.callee.type==="MemberExpression"&&n.init.callee.object&&n.init.callee.object.type==="Identifier"&&t.isContextBound(n.init.callee.object.name)?W(n.init,t):I.recursive(n.init,{parent:n.init},{Identifier(l,f){l.parent=f.parent,T(l,t);const g=l.parent&&l.parent.type==="BinaryExpression",y=l.parent&&l.parent.type==="UnaryExpression",S=l.parent&&l.parent.type==="ConditionalExpression",_=l.parent&&l.parent.type==="CallExpression"&&l.parent.callee&&l.parent.callee.object&&l.parent.callee.object.name===M&&l.parent.callee.property.name==="get";l.type==="Identifier"&&(g||y||S)&&!_&&L(l)},CallExpression(l,f,g){l.callee.type==="Identifier"&&(l.callee.parent=l),l.arguments.forEach(y=>{y.type==="Identifier"&&(y.parent=l)}),W(l,t),l.type==="CallExpression"&&l.arguments.forEach(y=>g(y,{parent:l}))},BinaryExpression(l,f,g){l.left.type==="Identifier"&&(l.left.parent=l),l.right.type==="Identifier"&&(l.right.parent=l),g(l.left,{parent:l}),g(l.right,{parent:l})},MemberExpression(l,f,g){l.object&&l.object.type==="Identifier"&&(l.object.parent=l),l.property&&l.property.type==="Identifier"&&(l.property.parent=l),B(l,"",t),l.type==="CallExpression"?l.arguments.forEach(y=>g(y,{parent:l})):l.object&&g(l.object,{parent:l})}}));const c=b.createContextVariableReference(s,a),p=t.isArrayPatternElement(n.id.name),m=!p&&n.init&&n.init.type==="MemberExpression"&&n.init.computed&&n.init.property&&(n.init.property.type==="Literal"||n.init.property.type==="MemberExpression");n.init?.property?.type==="MemberExpression"&&(n.init.property._indexTransformed||(F(n.init.property,t),n.init.property._indexTransformed=!0));let h;n.init?o||p?h=n.init:s==="var"?h=b.createInitVarCall(c,n.init):h=b.createInitCall(c,m?n.init.object:n.init,m?n.init.property:void 0):h=b.createIdentifier("undefined");const d=b.createExpressionStatement(b.createAssignmentExpression(c,h));if(p){const l=d.expression.right.object,f=n.init.property.value,g={type:"MemberExpression",object:b.createGetCall(l,0),property:{type:"Literal",value:f},computed:!0};d.expression.right=b.createCallExpression(b.createMemberExpression(b.createContextIdentifier(),b.createIdentifier("init")),[c,g])}o&&(t.pushScope("fn"),I.recursive(n.init.body,t,{BlockStatement(l,f,g){l.body.forEach(y=>g(y,f))},IfStatement(l,f,g){f.pushScope("if"),g(l.consequent,f),l.alternate&&(f.pushScope("els"),g(l.alternate,f),f.popScope()),f.popScope()},VariableDeclaration(l,f){ye(l,f)},Identifier(l,f){T(l,f)},AssignmentExpression(l,f){ge(l,f)}}),t.popScope()),Object.assign(e,d)})}function Pe(e,t,n){if(t.setSuppressHoisting(!0),e.init&&e.init.type==="VariableDeclaration"){const r=e.init.declarations[0],i=r.id.name;t.addLoopVariable(i,i),e.init={type:"VariableDeclaration",kind:e.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:i},init:r.init}]},r.init&&I.recursive(r.init,t,{Identifier(o,a){t.isLoopVariable(o.name)||(t.pushScope("for"),T(o,a),t.popScope())},MemberExpression(o){t.pushScope("for"),B(o,"",t),t.popScope()}})}e.test&&I.recursive(e.test,t,{Identifier(r,i){!t.isLoopVariable(r.name)&&!r.computed&&(t.pushScope("for"),T(r,i),r.type==="Identifier"&&(r.computed=!0,L(r)),t.popScope())},MemberExpression(r){t.pushScope("for"),B(r,"",t),t.popScope()}}),e.update&&I.recursive(e.update,t,{Identifier(r,i){t.isLoopVariable(r.name)||(t.pushScope("for"),T(r,i),t.popScope())}}),t.setSuppressHoisting(!1),t.pushScope("for"),n(e.body,t),t.popScope()}function Be(e,t){I.recursive(e,t,{MemberExpression(n){B(n,"",t)},CallExpression(n,r){W(n,r)},Identifier(n,r){T(n,r);const i=t.getCurrentScopeType()==="if";t.isContextBound(n.name)&&!t.isRootParam(n.name)&&i&&L(n)}})}function We(e,t,n){e.test&&(t.pushScope("if"),Be(e.test,t),t.popScope()),t.pushScope("if"),n(e.consequent,t),t.popScope(),e.alternate&&(t.pushScope("els"),n(e.alternate,t),t.popScope())}function Le(e,t){const n=t.getCurrentScopeType();if(e.argument&&(e.argument.type==="ArrayExpression"?(e.argument.elements=e.argument.elements.map(r=>{if(r.type==="Identifier"){if(t.isContextBound(r.name)&&!t.isRootParam(r.name))return b.createGetCall(r,0);const[i,o]=t.getVariable(r.name);return b.createContextVariableAccess0(o,i)}else if(r.type==="MemberExpression")return 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)?b.createGetCall(r,0):(r.computed&&r.object.type==="Identifier"&&t.isContextBound(r.object.name)&&!t.isRootParam(r.object.name)||B(r,"",t),r);return r}),e.argument={type:"ArrayExpression",elements:[e.argument]}):e.argument.type==="BinaryExpression"?I.recursive(e.argument,t,{Identifier(r,i){T(r,i),r.type==="Identifier"&&L(r)},MemberExpression(r){B(r,"",t)}}):e.argument.type==="ObjectExpression"?e.argument.properties=e.argument.properties.map(r=>{if(r.shorthand){const[i,o]=t.getVariable(r.value.name);return{type:"Property",key:b.createIdentifier(r.key.name),value:b.createContextVariableReference(o,i),kind:"init",method:!1,shorthand:!1,computed:!1}}if(r.value&&r.value.type==="Identifier"){if(t.isContextBound(r.value.name)&&!t.isRootParam(r.value.name))r.value=b.createGetCall(r.value,0);else if(!t.isContextBound(r.value.name)){const[i,o]=t.getVariable(r.value.name);r.value=b.createContextVariableReference(o,i)}}return r}):e.argument.type==="Identifier"&&(T(e.argument,t),e.argument.type==="Identifier"&&L(e.argument)),n==="fn")){e.argument.type==="Identifier"&&t.isContextBound(e.argument.name)&&!t.isRootParam(e.argument.name)?e.argument=b.createArrayAccess(e.argument,0):e.argument.type==="MemberExpression"?e.argument.object.type==="Identifier"&&t.isContextBound(e.argument.object.name)&&!t.isRootParam(e.argument.object.name)&&(e.argument._indexTransformed||(F(e.argument,t),e.argument._indexTransformed=!0)):(e.argument.type==="BinaryExpression"||e.argument.type==="LogicalExpression"||e.argument.type==="ConditionalExpression"||e.argument.type==="CallExpression")&&I.recursive(e.argument,t,{Identifier(i,o){T(i,o),i.type==="Identifier"&&!i._arrayAccessed&&(L(i),i._arrayAccessed=!0)},MemberExpression(i){B(i,"",t)},CallExpression(i,o){W(i,o)}});const r=b.createCallExpression(b.createMemberExpression(b.createContextIdentifier(),b.createIdentifier("precision")),[e.argument]);e.argument=r}}function Oe(e,t,n){e.body&&e.body.type==="BlockStatement"&&(t.pushScope("fn"),n(e.body,t),t.popScope())}function Re(e){const t={...I.base,LineComment:()=>{}};I.simple(e,{BinaryExpression(n){if(n.operator==="=="||n.operator==="==="){const r=n.left,i=n.right,o=b.createMathEqCall(r,i);o._transformed=!0,Object.assign(n,o)}}},t)}function Fe(e,t,n,r={debug:!1,ln:!1},i=[]){const o=a=>{if(!r.debug||!a.loc||!i.length)return null;const s=a.loc.start.line-1;if(s>=0&&s<i.length){const c=i[s].trim();if(c)return{type:"LineComment",value:`${r.ln?` [Line ${a.loc.start.line}]`:""} ${c}`}}return null};I.recursive(e,t,{Program(a,s,c){const p=[];a.body.forEach(m=>{s.enterHoistingScope(),c(m,s);const h=s.exitHoistingScope(),d=o(m);d&&p.push(d),p.push(...h),p.push(m)}),a.body=p},BlockStatement(a,s,c){const p=[];a.body.forEach(m=>{s.enterHoistingScope(),c(m,s);const h=s.exitHoistingScope(),d=o(m);d&&p.push(d),p.push(...h),p.push(m)}),a.body=p},ReturnStatement(a,s){Le(a,s)},VariableDeclaration(a,s){ye(a,s)},Identifier(a,s){T(a,s)},CallExpression(a,s){W(a,s)},MemberExpression(a,s){B(a,n,s)},AssignmentExpression(a,s){ge(a,s)},FunctionDeclaration(a,s,c){Oe(a,s,c)},ForStatement(a,s,c){Pe(a,s,c)},IfStatement(a,s,c){We(a,s,c)}})}function qe(e,t={debug:!1,ln:!1}){typeof t=="boolean"&&(t={debug:t,ln:!0});const{debug:n}=t;let r=typeof e=="function"?e.toString():e;r=r.trim(),r=Me(r);const i=n?r.split(`
|
|
21
|
+
`):[],o=he.parse(r,{ecmaVersion:"latest",sourceType:"module",locations:n});je(o),Ee(o),Ce(o);const a=new _e;Ae(o,a);const s=De(o,a)||"";Fe(o,a,s,t,i),Re(o);const c=z.baseGenerator||z.GENERATOR||z.default&&z.default.BASE_GENERATOR,p=Object.assign({},c,{LineComment(h,d){d.write("//"+h.value)}}),m=z.generate(o,{generator:p,comments:n});return new Function("",`var _r = ${m}
|
|
22
|
+
; return _r;`)(this)}class D{constructor(t){this.array=t}toString(){return"PineArrayObject:"+this.array.toString()}}function He(e){return t=>new D(t.array.map(n=>Math.abs(n)))}function Ge(e){return t=>e.array.sum(t)/t.array.length}function ze(e){return t=>{t.array.length=0}}function Ue(e){return(t,n)=>(t.array.push(...n.array),t)}function Xe(e){return t=>new D([...t.array])}function Ke(e){return(t,n,r=!0)=>{if(t.array.length!==n.array.length||t.array.length<2)return NaN;const i=r?t.array.length:t.array.length-1,o=e.array.avg(t),a=e.array.avg(n);let s=0;for(let c=0;c<t.array.length;c++)s+=(t.array[c]-o)*(n.array[c]-a);return s/i}}function Je(e){return(t,n)=>t.array.every(n)}function Qe(e){return(t,n,r=0,i)=>{const o=t.array.length,a=i!==void 0?Math.min(i,o):o;for(let s=r;s<a;s++)t.array[s]=n}}function Ye(e){return t=>t.array.length>0?t.array[0]:e.NA}function Ze(e){return(...t)=>new D([...t])}function et(e){return(t,n)=>t.array[n]}function tt(e){return(t,n)=>t.array.includes(n)}function nt(e){return(t,n)=>t.array.indexOf(n)}function rt(e){return(t,n,r)=>{t.array.splice(n,0,r)}}function at(e){return(t,n=",")=>t.array.join(n)}function it(e){return t=>t.array.length>0?t.array[t.array.length-1]:e.NA}function ot(e){return(t,n)=>t.array.lastIndexOf(n)}function st(e){return(t,n=0)=>[...t.array].sort((r,i)=>i-r)[n]??e.NA}function ct(e){return(t,n=0)=>[...t.array].sort((r,i)=>r-i)[n]??e.NA}function pt(e){return(t,n)=>new D(Array(t).fill(n))}function lt(e){return(t,n=!1)=>new D(Array(t).fill(n))}function ut(e){return(t,n=NaN)=>new D(Array(t).fill(n))}function mt(e){return(t,n=0)=>new D(Array(t).fill(Math.round(n)))}function ht(e){return(t,n="")=>new D(Array(t).fill(n))}class u{constructor(t,n=0){this.data=t,this.offset=n}get(t){const n=this.data.length-1-(this.offset+t);return n<0||n>=this.data.length?NaN:this.data[n]}set(t,n){const r=this.data.length-1-(this.offset+t);r>=0&&r<this.data.length&&(this.data[r]=n)}get length(){return this.data.length}toArray(){return this.data}static from(t){return t instanceof u?t:Array.isArray(t)?new u(t):new u([t])}}function dt(e){return(t,n=0)=>u.from(t).get(n)}function ft(e){return t=>t.array.pop()}function gt(e){return(t,n)=>{t.array.push(n)}}function yt(e){return t=>e.array.max(t)-e.array.min(t)}function bt(e){return(t,n)=>n>=0&&n<t.array.length?t.array.splice(n,1)[0]:e.NA}function wt(e){return t=>{t.array.reverse()}}function Nt(e){return(t,n,r)=>{t.array[n]=r}}function St(e){return t=>t.array.shift()}function vt(e){return t=>t.array.length}function xt(e){return(t,n,r)=>{const i=r!==void 0?r+1:void 0;return new D(t.array.slice(n,i))}}function _t(e){return(t,n)=>t.array.some(n)}function Ct(e){return(t,n="asc")=>{t.array.sort((r,i)=>n==="asc"?r-i:i-r)}}function Et(e){return(t,n)=>{const r=t.array.map((i,o)=>o);return r.sort((i,o)=>{const a=t.array[i],s=t.array[o];return n?n(a,s):a-s}),new D(r)}}function It(e){return t=>{const n=e.array.avg(t),r=e.array.stdev(t);return r===0?new D(t.array.map(()=>0)):new D(t.array.map(i=>(i-n)/r))}}function Mt(e){return(t,n=!0)=>{const r=e.array.avg(t),i=t.array.map(a=>Math.pow(a-r,2)),o=n?t.array.length:t.array.length-1;return Math.sqrt(e.array.sum(new D(i))/o)}}function jt(e){return t=>t.array.reduce((n,r)=>n+(isNaN(r)?0:r),0)}function At(e){return(t,n)=>{t.array.unshift(n)}}function $t(e){return(t,n=!0)=>{const r=e.array.avg(t),i=t.array.map(a=>Math.pow(a-r,2)),o=n?t.array.length:t.array.length-1;return e.array.sum(new D(i))/o}}var Vt=Object.defineProperty,Dt=(e,t,n)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,x=(e,t,n)=>Dt(e,typeof t!="symbol"?t+"":t,n);const Tt={abs:He,avg:Ge,clear:ze,concat:Ue,copy:Xe,covariance:Ke,every:Je,fill:Qe,first:Ye,from:Ze,get:et,includes:tt,indexof:nt,insert:rt,join:at,last:it,lastindexof:ot,max:st,min:ct,new:pt,new_bool:lt,new_float:ut,new_int:mt,new_string:ht,param:dt,pop:ft,push:gt,range:yt,remove:bt,reverse:wt,set:Nt,shift:St,size:vt,slice:xt,some:_t,sort:Ct,sort_indices:Et,standardize:It,stdev:Mt,sum:jt,unshift:At,variance:$t};class kt{constructor(t){this.context=t,x(this,"_cache",{}),x(this,"abs"),x(this,"avg"),x(this,"clear"),x(this,"concat"),x(this,"copy"),x(this,"covariance"),x(this,"every"),x(this,"fill"),x(this,"first"),x(this,"from"),x(this,"get"),x(this,"includes"),x(this,"indexof"),x(this,"insert"),x(this,"join"),x(this,"last"),x(this,"lastindexof"),x(this,"max"),x(this,"min"),x(this,"new"),x(this,"new_bool"),x(this,"new_float"),x(this,"new_int"),x(this,"new_string"),x(this,"param"),x(this,"pop"),x(this,"push"),x(this,"range"),x(this,"remove"),x(this,"reverse"),x(this,"set"),x(this,"shift"),x(this,"size"),x(this,"slice"),x(this,"some"),x(this,"sort"),x(this,"sort_indices"),x(this,"standardize"),x(this,"stdev"),x(this,"sum"),x(this,"unshift"),x(this,"variance"),Object.entries(Tt).forEach(([n,r])=>{this[n]=r(t)})}}var Pt=Object.defineProperty,Bt=(e,t,n)=>t in e?Pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Wt=(e,t,n)=>Bt(e,typeof t!="symbol"?t+"":t,n);class Lt{constructor(t){this.context=t,Wt(this,"color",{param:(n,r=0)=>u.from(n).get(r),rgb:(n,r,i,o)=>o?`rgba(${n}, ${r}, ${i}, ${o})`:`rgb(${n}, ${r}, ${i})`,new:(n,r)=>{if(n&&n.startsWith("#")){const i=n.slice(1),o=parseInt(i.slice(0,2),16),a=parseInt(i.slice(2,4),16),s=parseInt(i.slice(4,6),16);return r?`rgba(${o}, ${a}, ${s}, ${r})`:`rgb(${o}, ${a}, ${s})`}return r?`rgba(${n}, ${r})`:n},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue"})}extractPlotOptions(t){const n={};for(let r in t)n[r]=u.from(t[r]).get(0);return n}indicator(t,n,r){}plotchar(t,n,r){this.context.plots[n]||(this.context.plots[n]={data:[],options:this.extractPlotOptions(r),title:n});const i=u.from(t).get(0);this.context.plots[n].data.push({time:this.context.marketData[this.context.idx].openTime,value:i,options:{...this.extractPlotOptions(r),style:"char"}})}plot(t,n,r){this.context.plots[n]||(this.context.plots[n]={data:[],options:this.extractPlotOptions(r),title:n});const i=u.from(t).get(0);this.context.plots[n].data.push({time:this.context.marketData[this.context.idx].openTime,value:i,options:this.extractPlotOptions(r)})}get bar_index(){return this.context.idx}na(t){return isNaN(u.from(t).get(0))}nz(t,n=0){const r=u.from(t).get(0),i=u.from(n).get(0);return isNaN(r)?i:r}}function Ot(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Rt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Ft(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function qt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Ht(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Gt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function zt(e){return(t,n=0)=>[u.from(t).get(n)]}function Ut(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Xt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Kt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Jt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Qt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Yt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function Zt(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}function en(e){return(t,{title:n,group:r}={})=>Array.isArray(t)?t[0]:t}var tn=Object.defineProperty,nn=(e,t,n)=>t in e?tn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,V=(e,t,n)=>nn(e,typeof t!="symbol"?t+"":t,n);const rn={any:Ot,bool:Rt,color:Ft,enum:qt,float:Ht,int:Gt,param:zt,price:Ut,session:Xt,source:Kt,string:Jt,symbol:Qt,text_area:Yt,time:Zt,timeframe:en};class an{constructor(t){this.context=t,V(this,"any"),V(this,"bool"),V(this,"color"),V(this,"enum"),V(this,"float"),V(this,"int"),V(this,"param"),V(this,"price"),V(this,"session"),V(this,"source"),V(this,"string"),V(this,"symbol"),V(this,"text_area"),V(this,"time"),V(this,"timeframe"),Object.entries(rn).forEach(([n,r])=>{this[n]=r(t)})}}function on(e){return t=>Math.abs(u.from(t).get(0))}function sn(e){return t=>Math.acos(u.from(t).get(0))}function cn(e){return t=>Math.asin(u.from(t).get(0))}function pn(e){return t=>Math.atan(u.from(t).get(0))}function ln(e){return(...t)=>{const n=t.map(r=>u.from(r).get(0));return n.reduce((r,i)=>r+i,0)/n.length}}function un(e){return t=>Math.ceil(u.from(t).get(0))}function mn(e){return t=>Math.cos(u.from(t).get(0))}function hn(e){return t=>Math.exp(u.from(t).get(0))}function dn(e){return t=>Math.floor(u.from(t).get(0))}function fn(e){return t=>Math.log(u.from(t).get(0))}function gn(e){return t=>Math.log(u.from(t).get(0))}function yn(e){return t=>Math.log10(u.from(t).get(0))}function bn(e){return(...t)=>{const n=t.map(r=>u.from(r).get(0));return Math.max(...n)}}function wn(e){return(...t)=>{const n=t.map(r=>u.from(r).get(0));return Math.min(...n)}}function Nn(e){return(t,n,r)=>typeof t=="string"?t:t instanceof u?n?new u(t.data,t.offset+n):t:!Array.isArray(t)&&typeof t=="object"?t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new u(t,n||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new u(e.params[r],0)))}function Sn(e){return(t,n)=>Math.pow(u.from(t).get(0),u.from(n).get(0))}function vn(e){return()=>Math.random()}function xn(e){return t=>Math.round(u.from(t).get(0))}function _n(e){return t=>Math.sin(u.from(t).get(0))}function Cn(e){return t=>Math.sqrt(u.from(t).get(0))}function En(e){return(t,n)=>{const r=u.from(n).get(0),i=u.from(t);let o=0;for(let a=0;a<r;a++){const s=i.get(a);o+=s}return o}}function In(e){return t=>Math.tan(u.from(t).get(0))}function Mn(e){return(t,n)=>{const r=u.from(t).get(0),i=u.from(n).get(0);return isNaN(r)&&isNaN(i)?!0:isNaN(r)||isNaN(i)?!1:Math.abs(r-i)<1e-8}}var jn=Object.defineProperty,An=(e,t,n)=>t in e?jn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t,n)=>An(e,typeof t!="symbol"?t+"":t,n);const $n={abs:on,acos:sn,asin:cn,atan:pn,avg:ln,ceil:un,cos:mn,exp:hn,floor:dn,ln:fn,log:gn,log10:yn,max:bn,min:wn,param:Nn,pow:Sn,random:vn,round:xn,sin:_n,sqrt:Cn,sum:En,tan:In,__eq:Mn};class Vn{constructor(t){this.context=t,C(this,"_cache",{}),C(this,"abs"),C(this,"acos"),C(this,"asin"),C(this,"atan"),C(this,"avg"),C(this,"ceil"),C(this,"cos"),C(this,"exp"),C(this,"floor"),C(this,"ln"),C(this,"log"),C(this,"log10"),C(this,"max"),C(this,"min"),C(this,"param"),C(this,"pow"),C(this,"random"),C(this,"round"),C(this,"sin"),C(this,"sqrt"),C(this,"sum"),C(this,"tan"),C(this,"__eq"),Object.entries($n).forEach(([n,r])=>{this[n]=r(t)})}}function Dn(e){return(t,n,r)=>{e.params[r]||(e.params[r]=[]);let i;if(t instanceof u)i=t.get(n||0);else if(Array.isArray(t)){const o=t.every(s=>s instanceof u),a=t.every(s=>!(s instanceof u)&&!Array.isArray(s));(o||a)&&t.length>=1?o?i=t.map(s=>s.get(0)):i=t:i=u.from(t).get(n||0)}else i=t;return e.params[r].length===0?e.params[r].push(i):e.params[r][e.params[r].length-1]=i,[i,r]}}const ce=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function pe(e,t,n,r,i=!1){for(let o=0;o<n.length;o++)if(n[o]<=e&&t<=r[o])return i||t>=r[o]?o:o-1;return-1}function le(e,t,n,r,i=!1,o,a=!1){for(let s=n.length-1;s>=0;s--){if(r[s]<=t&&n[s]>=e){const c=o&&t>o;if(a&&i)for(let p=0;p<n.length;p++){if(n[p]>=e&&n[p]<t)return p;if(n[p]>=t)break}if(c&&i&&!a)for(let p=0;p<n.length;p++){if(n[p]>=e&&n[p]<t)return p;if(n[p]>=t)break}return s}if(r[s]<e)break}return-1}function Tn(e){return async(t,n,r,i=!1,o=!1,a=!1,s=null,c=null)=>{const p=t[0],m=n[0],h=r[0],d=r[1],l=Array.isArray(i)?i[0]:i,f=Array.isArray(o)?o[0]:o;if(e.isSecondaryContext)return h;const g=ce.indexOf(e.timeframe),y=ce.indexOf(m);if(g==-1||y==-1)throw new Error("Invalid timeframe");if(g===y)return h;const S=g>y,_=u.from(e.data.openTime).get(0),v=u.from(e.data.closeTime).get(0),w=`${p}_${m}_${d}`,j=`${w}_prevIdx`;if(e.cache[w]){const G=e.cache[w],X=S?le(_,v,G.data.openTime.data,G.data.closeTime.data,f,e.eDate,l):pe(_,v,G.data.openTime.data,G.data.closeTime.data,f);if(X==-1)return NaN;const H=G.params[d][X];if(!S&&l){const oe=e.cache[j];return oe!==void 0&&oe===X?NaN:(e.cache[j]=X,Array.isArray(H)?[H]:H)}return Array.isArray(H)?[H]:H}const k=1e3*60*60*24*30,O=e.sDate?e.sDate-k:void 0,P=e.sDate&&e.eDate?void 0:e.limit||1e3,ie=new ia(e.source,p,m,P,O,void 0);ie.markAsSecondary();const q=await ie.run(e.pineTSCode);e.cache[w]=q;const Y=S?le(_,v,q.data.openTime.data,q.data.closeTime.data,f,e.eDate,l):pe(_,v,q.data.openTime.data,q.data.closeTime.data,f);if(Y==-1)return NaN;const Z=q.params[d][Y];return!S&&l?(e.cache[j]=Y,NaN):Array.isArray(Z)?[Z]:Z}}var kn=Object.defineProperty,Pn=(e,t,n)=>t in e?kn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ee=(e,t,n)=>Pn(e,typeof t!="symbol"?t+"":t,n);const Bn={param:Dn,security:Tn};class Wn{constructor(t){this.context=t,ee(this,"_cache",{}),ee(this,"param"),ee(this,"security"),Object.entries(Bn).forEach(([n,r])=>{this[n]=r(t)})}}function Ln(e){return t=>{e.taState||(e.taState={});const n=t||"accdist";e.taState[n]||(e.taState[n]={cumulativeSum:0});const r=e.taState[n],i=e.get(e.data.close,0),o=e.get(e.data.high,0),a=e.get(e.data.low,0),s=e.get(e.data.volume,0);if(isNaN(i)||isNaN(o)||isNaN(a)||isNaN(s))return e.precision(r.cumulativeSum);const c=o-a;let p=0;return c!==0&&(p=(i-a-(o-i))/c*s),r.cumulativeSum+=p,e.precision(r.cumulativeSum)}}function On(e){return(t,n,r,i,o)=>{const a=u.from(n).get(0),s=u.from(r).get(0),c=u.from(i).get(0);e.taState||(e.taState={});const p=o||`alma_${a}_${s}_${c}`;if(!e.taState[p]){const l=s*(a-1),f=a/c,g=[];let y=0;for(let S=0;S<a;S++){const _=Math.exp(-Math.pow(S-l,2)/(2*f*f));g.push(_),y+=_}for(let S=0;S<g.length;S++)g[S]/=y;e.taState[p]={window:[],weights:g}}const m=e.taState[p],h=u.from(t).get(0);if(m.window.unshift(h),m.window.length<a)return NaN;m.window.length>a&&m.window.pop();let d=0;for(let l=0;l<a;l++)d+=m.weights[l]*m.window[a-1-l];return e.precision(d)}}function Rn(e){return(t,n)=>{const r=u.from(t).get(0);e.taState||(e.taState={});const i=n||`atr_${r}`;e.taState[i]||(e.taState[i]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const o=e.taState[i],a=e.get(e.data.high,0),s=e.get(e.data.low,0),c=e.get(e.data.close,0);let p;if(o.prevClose!==null){const h=a-s,d=Math.abs(a-o.prevClose),l=Math.abs(s-o.prevClose);p=Math.max(h,d,l)}else p=a-s;if(o.prevClose=c,o.initCount<r)return o.initSum+=p,o.initCount++,o.initCount===r?(o.prevAtr=o.initSum/r,e.precision(o.prevAtr)):NaN;const m=(o.prevAtr*(r-1)+p)/r;return o.prevAtr=m,e.precision(m)}}function Fn(e){return(t,n)=>{e.taState||(e.taState={});const r=n||"barssince";e.taState[r]||(e.taState[r]={lastTrueIndex:null});const i=e.taState[r];return u.from(t).get(0)?(i.lastTrueIndex=e.idx,0):i.lastTrueIndex===null?NaN:e.idx-i.lastTrueIndex}}function qn(e){return(t,n,r,i)=>{const o=u.from(n).get(0),a=u.from(r).get(0);e.taState||(e.taState={});const s=i||`bb_${o}_${a}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const c=e.taState[s],p=u.from(t).get(0);if(isNaN(p))return[[NaN,NaN,NaN]];if(c.window.unshift(p),c.sum+=p,c.window.length<o)return[[NaN,NaN,NaN]];if(c.window.length>o){const g=c.window.pop();c.sum-=g}const m=c.sum/o;let h=0;for(let g=0;g<o;g++)h+=Math.pow(c.window[g]-m,2);const d=Math.sqrt(h/o),l=m+a*d,f=m-a*d;return[[e.precision(l),e.precision(m),e.precision(f)]]}}function Hn(e){return(t,n,r,i)=>{const o=u.from(n).get(0),a=u.from(r).get(0);e.taState||(e.taState={});const s=i||`bbw_${o}_${a}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const c=e.taState[s],p=u.from(t).get(0);if(isNaN(p))return NaN;if(c.window.unshift(p),c.sum+=p,c.window.length<o)return NaN;if(c.window.length>o){const y=c.window.pop();c.sum-=y}const m=c.sum/o;let h=0;for(let y=0;y<o;y++){const S=c.window[y]-m;h+=S*S}const d=h/o,l=Math.sqrt(d),f=a*l;if(m===0)return e.precision(0);const g=2*f/m*100;return e.precision(g)}}function Gn(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`cci_${i}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const a=e.taState[o],s=u.from(t).get(0);if(isNaN(s))return NaN;if(a.window.unshift(s),a.sum+=s,a.window.length<i)return NaN;if(a.window.length>i){const d=a.window.pop();a.sum-=d}const c=a.sum/i;let p=0;for(let d=0;d<i;d++)p+=Math.abs(a.window[d]-c);const m=p/i;if(m===0)return 0;const h=(s-c)/(.015*m);return e.precision(h)}}function zn(e){return(t,n=1,r)=>{typeof n=="string"&&(r=n,n=1);const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`change_${i}`;e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<=i)return NaN;a.window.length>i+1&&a.window.pop();const c=s-a.window[i];return e.precision(c)}}function Un(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`cmo_${i}`;e.taState[o]||(e.taState[o]={gainsWindow:[],lossesWindow:[],gainsSum:0,lossesSum:0});const a=e.taState[o],s=u.from(t).get(0),c=u.from(t).get(1);if(isNaN(s)||isNaN(c))return NaN;const p=s-c,m=p>=0?p:0,h=p>=0?0:-p;if(a.gainsWindow.unshift(m),a.lossesWindow.unshift(h),a.gainsSum+=m,a.lossesSum+=h,a.gainsWindow.length<i)return NaN;if(a.gainsWindow.length>i){const f=a.gainsWindow.pop(),g=a.lossesWindow.pop();a.gainsSum-=f,a.lossesSum-=g}const d=a.gainsSum+a.lossesSum;if(d===0)return e.precision(0);const l=100*(a.gainsSum-a.lossesSum)/d;return e.precision(l)}}function Xn(e){return(t,n,r)=>{const i=u.from(n).get(0),o=u.from(t);let a=0,s=!1;for(let m=0;m<i;m++){const h=o.get(m);if(isNaN(h)){s=!0;break}a+=h}if(s)return NaN;let c=0;for(let m=0;m<i;m++){const h=o.get(m);c+=h*(m+1)}if(a===0)return NaN;const p=-c/a;return e.precision(p)}}function Kn(e){return(t,n,r,i)=>{const o=u.from(r).get(0),a=u.from(t),s=u.from(n);if(e.idx<o-1)return NaN;let c=0,p=0,m=0,h=0,d=0,l=0;for(let _=0;_<o;_++){const v=a.get(_),w=s.get(_);isNaN(v)||isNaN(w)||(c+=v,p+=w,m+=v*w,h+=v*v,d+=w*w,l++)}if(l<2)return NaN;const f=l*m-c*p,g=l*h-c*c,y=l*d-p*p;if(g<=0||y<=0)return e.precision(0);const S=f/Math.sqrt(g*y);return e.precision(S)}}function Jn(e){return(t,n,r)=>{const i=u.from(t),o=u.from(n),a=i.get(0),s=o.get(0),c=i.get(1),p=o.get(1);if(isNaN(a)||isNaN(s)||isNaN(c)||isNaN(p))return!1;const m=a>s&&c<=p,h=a<s&&c>=p;return m||h}}function Qn(e){return(t,n)=>{const r=u.from(t),i=u.from(n),o=r.get(0),a=i.get(0),s=r.get(1),c=i.get(1);return s<c&&o>a}}function Yn(e){return(t,n)=>{const r=u.from(t),i=u.from(n),o=r.get(0),a=i.get(0),s=r.get(1),c=i.get(1);return s>c&&o<a}}function Zn(e){return(t,n)=>{e.taState||(e.taState={});const r=n||"cum";e.taState[r]||(e.taState[r]={cumulativeSum:0});const i=e.taState[r],o=u.from(t).get(0);return isNaN(o)||(i.cumulativeSum+=o),e.precision(i.cumulativeSum)}}function er(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`dev_${i}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const a=e.taState[o],s=u.from(t).get(0)||0;if(a.window.unshift(s),a.sum+=s,a.window.length<i)return NaN;if(a.window.length>i){const h=a.window.pop();a.sum-=h}const c=a.sum/i;let p=0;for(let h=0;h<i;h++)p+=Math.abs(a.window[h]-c);const m=p/i;return e.precision(m)}}function tr(e){return(t,n,r)=>{const i=u.from(t).get(0),o=u.from(n).get(0);e.taState||(e.taState={});const a=r||`dmi_${i}_${o}`;e.taState[a]||(e.taState[a]={prevHigh:NaN,prevLow:NaN,prevClose:NaN,trInitSum:0,plusInitSum:0,minusInitSum:0,initCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,dxInitSum:0,adxInitCount:0,prevADX:NaN});const s=e.taState[a],c=e.get(e.data.high,0),p=e.get(e.data.low,0),m=e.get(e.data.close,0);if(isNaN(c)||isNaN(p)||isNaN(m))return[[NaN,NaN,NaN]];if(isNaN(s.prevHigh))return s.prevHigh=c,s.prevLow=p,s.prevClose=m,[[NaN,NaN,NaN]];const h=Math.max(c-p,Math.abs(c-s.prevClose),Math.abs(p-s.prevClose)),d=c-s.prevHigh,l=s.prevLow-p,f=d>l&&d>0?d:0,g=l>d&&l>0?l:0;s.prevHigh=c,s.prevLow=p,s.prevClose=m;let y,S,_;if(s.initCount++,s.initCount<=i)s.trInitSum+=h,s.plusInitSum+=f,s.minusInitSum+=g,s.initCount===i&&(s.prevSmoothedTR=s.trInitSum/i,s.prevSmoothedPlus=s.plusInitSum/i,s.prevSmoothedMinus=s.minusInitSum/i);else{const P=1/i;s.prevSmoothedTR=P*h+(1-P)*s.prevSmoothedTR,s.prevSmoothedPlus=P*f+(1-P)*s.prevSmoothedPlus,s.prevSmoothedMinus=P*g+(1-P)*s.prevSmoothedMinus}if(y=s.prevSmoothedTR,S=s.prevSmoothedPlus,_=s.prevSmoothedMinus,s.initCount<i)return[[NaN,NaN,NaN]];const v=y===0?0:100*S/y,w=y===0?0:100*_/y,j=v+w,k=j===0?0:100*Math.abs(v-w)/j;let O=NaN;if(s.adxInitCount++,s.adxInitCount<=o)s.dxInitSum+=k,s.adxInitCount===o&&(s.prevADX=s.dxInitSum/o,O=s.prevADX);else{const P=1/o;s.prevADX=P*k+(1-P)*s.prevADX,O=s.prevADX}return[[e.precision(v),e.precision(w),e.precision(O)]]}}function nr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`ema_${i}`;e.taState[o]||(e.taState[o]={prevEma:null,initSum:0,initCount:0});const a=e.taState[o],s=u.from(t).get(0);if(a.initCount<i)return a.initSum+=s,a.initCount++,a.initCount===i?(a.prevEma=a.initSum/i,e.precision(a.prevEma)):NaN;const c=2/(i+1),p=s*c+a.prevEma*(1-c);return a.prevEma=p,e.precision(p)}}function rr(e){return(t,n,r)=>{const i=u.from(n).get(0),o=u.from(t);for(let a=0;a<i;a++){const s=o.get(a),c=o.get(a+1);if(isNaN(s)||isNaN(c)||s>=c)return!1}return!0}}function ar(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`highest_${i}`;e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();const c=Math.max(...a.window.filter(p=>!isNaN(p)));return e.precision(c)}}function ir(e){return(t,n,r)=>{const i=u.from(n).get(0),o=u.from(t);if(e.idx<i-1)return NaN;let a=-1/0,s=NaN;for(let c=0;c<i;c++){const p=o.get(c);isNaN(p)||(isNaN(s)||p>a)&&(a=p,s=-c)}return s}}function or(e){return(t,n,r)=>{const i=u.from(n).get(0),o=Math.floor(i/2),a=Math.floor(Math.sqrt(i)),s=e.ta.wma,c=s(t,o,r?`${r}_wma1`:void 0),p=s(t,i,r?`${r}_wma2`:void 0);if(isNaN(c)||isNaN(p))return NaN;e.taState||(e.taState={});const m=r||`hma_raw_${i}`;e.taState[m]||(e.taState[m]=[]);const h=2*c-p;e.taState[m].unshift(h);const d=r?`${r}_hma_final`:`hma_final_${i}`;e.taState[d]||(e.taState[d]={window:[]});const l=e.taState[d];if(l.window.unshift(h),l.window.length<a)return NaN;l.window.length>a&&l.window.pop();let f=0,g=0;for(let S=0;S<a;S++){const _=a-S;f+=l.window[S]*_,g+=_}const y=f/g;return e.precision(y)}}function sr(e){return t=>{const n=e.get(e.data.close,0),r=e.get(e.data.high,0),i=e.get(e.data.low,0),o=e.get(e.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(o))return NaN;const a=(r-i)*o;if(a===0)return e.precision(0);const s=(2*n-r-i)/a;return e.precision(s)}}function cr(e){return(t,n,r,i,o)=>{const a=u.from(n).get(0),s=u.from(r).get(0);let c=!0;typeof i=="string"?o=i:i!==void 0&&(c=u.from(i).get(0));let p;const m=e.get(e.data.high,0),h=e.get(e.data.low,0);if(c){const w=e.get(e.data.close,1);isNaN(w)?p=NaN:p=Math.max(m-h,Math.abs(m-w),Math.abs(h-w))}else p=m-h;const d=u.from(t).get(0);e.taState||(e.taState={});const l=o||`kc_${a}_${s}_${c}`;e.taState[l]||(e.taState[l]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const f=e.taState[l],g=(w,j,k)=>{if(isNaN(j))return NaN;if(w.initCount<k)return w.initSum+=j,w.initCount++,w.initCount===k?(w.prevEma=w.initSum/k,w.prevEma):NaN;const O=2/(k+1);return w.prevEma=j*O+w.prevEma*(1-O),w.prevEma},y=g(f.basisState,d,a),S=g(f.rangeState,p,a);if(isNaN(y)||isNaN(S))return[[NaN,NaN,NaN]];const _=y+S*s,v=y-S*s;return[[e.precision(y),e.precision(_),e.precision(v)]]}}function pr(e){return(t,n,r,i,o)=>{const a=u.from(n).get(0),s=u.from(r).get(0);let c=!0;typeof i=="string"?o=i:i!==void 0&&(c=u.from(i).get(0)),e.taState||(e.taState={});const p=o||`kcw_${a}_${s}_${c}`;e.taState[p]||(e.taState[p]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const m=e.taState[p],h=(v,w,j)=>{if(isNaN(w))return NaN;if(v.initCount<j)return v.initSum+=w,v.initCount++,v.initCount===j?(v.prevEma=v.initSum/j,v.prevEma):NaN;const k=2/(j+1);return v.prevEma=w*k+v.prevEma*(1-k),v.prevEma};let d;const l=e.get(e.data.high,0),f=e.get(e.data.low,0);if(c){const v=e.get(e.data.close,1);isNaN(v)?d=NaN:d=Math.max(l-f,Math.abs(l-v),Math.abs(f-v))}else d=l-f;const g=u.from(t).get(0),y=h(m.basisState,g,a),S=h(m.rangeState,d,a);if(isNaN(y)||isNaN(S))return NaN;if(y===0)return e.precision(0);const _=2*S*s/y;return e.precision(_)}}function lr(e){return(t,n,r,i)=>{const o=u.from(n).get(0),a=u.from(r).get(0);e.taState||(e.taState={});const s=i||`linreg_${o}_${a}`;e.taState[s]||(e.taState[s]={window:[]});const c=e.taState[s],p=u.from(t).get(0);if(c.window.unshift(p),c.window.length<o)return NaN;c.window.length>o&&c.window.pop();let m=0,h=0,d=0,l=0;const f=o;for(let _=0;_<o;_++){const v=o-1-_,w=c.window[_];m+=v,h+=w,d+=v*w,l+=v*v}const g=f*l-m*m;if(g===0)return NaN;const y=(f*d-m*h)/g,S=(h-y*m)/f+y*(o-1-a);return e.precision(S)}}function ur(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`lowest_${i}`;e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();const c=a.window.filter(m=>!isNaN(m)&&m!==void 0),p=c.length>0?Math.min(...c):NaN;return e.precision(p)}}function mr(e){return(t,n,r)=>{const i=u.from(n).get(0),o=u.from(t);if(e.idx<i-1)return NaN;let a=1/0,s=NaN;for(let c=0;c<i;c++){const p=o.get(c);isNaN(p)||(isNaN(s)||p<a)&&(a=p,s=-c)}return s}}function hr(e){return(t,n,r,i,o)=>{const a=u.from(n).get(0),s=u.from(r).get(0),c=u.from(i).get(0),p=o||`macd_${a}_${s}_${c}`,m=`${p}_fast`,h=`${p}_slow`,d=`${p}_signal`,l=e.ta.ema(t,a,m),f=e.ta.ema(t,s,h);let g=NaN;!isNaN(l)&&!isNaN(f)&&(g=l-f);let y=NaN;isNaN(g)||(y=e.ta.ema(g,c,d));let S=NaN;return!isNaN(g)&&!isNaN(y)&&(S=g-y),[[e.precision(g),e.precision(y),e.precision(S)]]}}function dr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`median_${i}`;e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();const c=a.window.slice().sort((h,d)=>h-d),p=Math.floor(i/2),m=i%2===0?(c[p-1]+c[p])/2:c[p];return e.precision(m)}}function fr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`mfi_${i}`;e.taState[o]||(e.taState[o]={upperWindow:[],lowerWindow:[],upperSum:0,lowerSum:0});const a=e.taState[o],s=u.from(t).get(0),c=u.from(t).get(1),p=e.get(e.data.volume,0);if(isNaN(s)||isNaN(p))return NaN;const m=isNaN(c)?NaN:s-c;let h=0,d=0;if(h=p*(m<=0?0:s),d=p*(m>=0?0:s),a.upperWindow.unshift(h),a.lowerWindow.unshift(d),a.upperSum+=h,a.lowerSum+=d,a.upperWindow.length<i)return NaN;if(a.upperWindow.length>i){const f=a.upperWindow.pop(),g=a.lowerWindow.pop();a.upperSum-=f,a.lowerSum-=g}if(a.lowerSum===0)return a.upperSum,e.precision(100);if(a.upperSum===0)return e.precision(0);const l=100-100/(1+a.upperSum/a.lowerSum);return e.precision(l)}}function gr(e){return(t,n,r)=>{const i=u.from(n).get(0),o=u.from(t);if(e.idx<i-1)return NaN;const a=new Map;for(let p=0;p<i;p++){const m=o.get(p);isNaN(m)||a.set(m,(a.get(m)||0)+1)}if(a.size===0)return NaN;let s=NaN,c=-1;for(const[p,m]of a.entries())m>c?(c=m,s=p):m===c&&p<s&&(s=p);return s}}function yr(e){return(t,n,r)=>{const i=u.from(n).get(0);return e.ta.change(t,i)}}function br(e){return t=>{e.taState||(e.taState={});const n=t||"nvi";e.taState[n]||(e.taState[n]={nvi:1});const r=e.taState[n],i=e.get(e.data.close,0),o=e.get(e.data.close,1),a=e.get(e.data.volume,0),s=e.get(e.data.volume,1),c=isNaN(i)?0:i,p=isNaN(o)?0:o,m=isNaN(a)?0:a,h=isNaN(s)?0:s;if(!(c===0||p===0)&&m<h){const d=(c-p)/p;r.nvi=r.nvi+d*r.nvi}return e.precision(r.nvi)}}function wr(e){return()=>{e.taState||(e.taState={});const t="obv";e.taState[t]||(e.taState[t]={prevOBV:0});const n=e.taState[t],r=e.get(e.data.close,0),i=e.get(e.data.volume,0),o=e.get(e.data.close,1);if(isNaN(o))return n.prevOBV=0,e.precision(0);let a;return r>o?a=n.prevOBV+i:r<o?a=n.prevOBV-i:a=n.prevOBV,n.prevOBV=a,e.precision(a)}}function Nr(e){return(t,n,r)=>t instanceof u?n?new u(t.data,t.offset+n):t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new u(t,n||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new u(e.params[r],0)))}function Sr(e){return(t,n,r,i)=>{const o=u.from(n).get(0),a=u.from(r).get(0),s=u.from(t);if(e.idx<o-1)return NaN;const c=[];for(let f=0;f<o;f++){const g=s.get(f);if(isNaN(g))return NaN;c.push(g)}c.sort((f,g)=>f-g);let p=a/100*o-.5;p<0&&(p=0),p>o-1&&(p=o-1);const m=Math.floor(p),h=Math.ceil(p);if(m===h)return e.precision(c[m]);const d=p-m,l=c[m]+d*(c[h]-c[m]);return e.precision(l)}}function vr(e){return(t,n,r,i)=>{const o=u.from(n).get(0),a=u.from(r).get(0),s=u.from(t);if(e.idx<o-1)return NaN;const c=[];for(let m=0;m<o;m++){const h=s.get(m);isNaN(h)||c.push(h)}if(c.length===0)return NaN;c.sort((m,h)=>m-h);let p=Math.ceil(a/100*c.length)-1;return p<0&&(p=0),p>=c.length&&(p=c.length-1),e.precision(c[p])}}function xr(e){return(t,n,r)=>{const i=u.from(n).get(0),o=u.from(t);if(e.idx<i)return NaN;const a=o.get(0);if(isNaN(a))return NaN;let s=0,c=0;for(let p=1;p<=i;p++){const m=o.get(p);isNaN(m)||(c++,m<=a&&s++)}return c===0?NaN:e.precision(s/c*100)}}function _r(e,t,n){const r=new Array(e.length).fill(NaN);for(let i=t+n;i<e.length;i++){const o=e[i-n];let a=!0;for(let s=1;s<=t;s++)if(e[i-n-s]>=o){a=!1;break}if(a){for(let s=1;s<=n;s++)if(e[i-n+s]>=o){a=!1;break}}a&&(r[i]=o)}return r}function Cr(e){return(t,n,r)=>{r==null&&(r=n,n=t,t=e.data.high);const i=u.from(n).get(0),o=u.from(r).get(0),a=u.from(t).toArray(),s=_r(a,i,o),c=e.idx;return e.precision(s[c])}}function Er(e,t,n){const r=new Array(e.length).fill(NaN);for(let i=t+n;i<e.length;i++){const o=e[i-n];let a=!0;for(let s=1;s<=t;s++)if(e[i-n-s]<=o){a=!1;break}if(a){for(let s=1;s<=n;s++)if(e[i-n+s]<=o){a=!1;break}}a&&(r[i]=o)}return r}function Ir(e){return(t,n,r)=>{r==null&&(r=n,n=t,t=e.data.low);const i=u.from(n).get(0),o=u.from(r).get(0),a=u.from(t).toArray(),s=Er(a,i,o),c=e.idx;return e.precision(s[c])}}function Mr(e){return t=>{e.taState||(e.taState={});const n=t||"pvi";e.taState[n]||(e.taState[n]={pvi:1});const r=e.taState[n],i=e.get(e.data.close,0),o=e.get(e.data.close,1),a=e.get(e.data.volume,0),s=e.get(e.data.volume,1),c=isNaN(i)?0:i,p=isNaN(o)?0:o,m=isNaN(a)?0:a,h=isNaN(s)?0:s;if(!(c===0||p===0)&&m>h){const d=(c-p)/p;r.pvi=r.pvi+d*r.pvi}return e.precision(r.pvi)}}function jr(e){return t=>{e.taState||(e.taState={});const n=t||"pvt";e.taState[n]||(e.taState[n]={cumulativeSum:0});const r=e.taState[n],i=e.get(e.data.close,0),o=e.get(e.data.close,1),a=e.get(e.data.volume,0);if(!isNaN(i)&&!isNaN(o)&&!isNaN(a)&&o!==0){const s=(i-o)/o*a;r.cumulativeSum+=s}return e.precision(r.cumulativeSum)}}function Ar(e){return(t,n,r)=>{const i=e.pine.ta.highest(t,n,(r||"range")+"_h"),o=e.pine.ta.lowest(t,n,(r||"range")+"_l");return isNaN(i)||isNaN(o)?NaN:e.precision(i-o)}}function $r(e){return(t,n,r)=>{const i=u.from(n).get(0),o=u.from(t);for(let a=0;a<i;a++){const s=o.get(a),c=o.get(a+1);if(isNaN(s)||isNaN(c)||s<=c)return!1}return!0}}function Vr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`rma_${i}`;e.taState[o]||(e.taState[o]={prevRma:null,initSum:0,initCount:0});const a=e.taState[o],s=u.from(t).get(0)||0;if(a.initCount<i)return a.initSum+=s,a.initCount++,a.initCount===i?(a.prevRma=a.initSum/i,e.precision(a.prevRma)):NaN;const c=1/i,p=s*c+a.prevRma*(1-c);return a.prevRma=p,e.precision(p)}}function Dr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`roc_${i}`;e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<=i)return NaN;a.window.length>i+1&&a.window.pop();const c=a.window[i],p=(s-c)/c*100;return e.precision(p)}}function Tr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`rsi_${i}`;e.taState[o]||(e.taState[o]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.prevValue!==null){const c=s-a.prevValue,p=c>0?c:0,m=c<0?-c:0;if(a.initGains.length<i){if(a.initGains.push(p),a.initLosses.push(m),a.initGains.length===i){a.avgGain=a.initGains.reduce((l,f)=>l+f,0)/i,a.avgLoss=a.initLosses.reduce((l,f)=>l+f,0)/i,a.prevValue=s;const d=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return e.precision(d)}return a.prevValue=s,NaN}a.avgGain=(a.avgGain*(i-1)+p)/i,a.avgLoss=(a.avgLoss*(i-1)+m)/i;const h=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return a.prevValue=s,e.precision(h)}return a.prevValue=s,NaN}}function kr(e){return(t,n,r,i)=>{const o=u.from(t).get(0),a=u.from(n).get(0),s=u.from(r).get(0);e.taState||(e.taState={});const c=i||`sar_${o}_${a}_${s}`;e.taState[c]||(e.taState[c]={result:NaN,maxMin:NaN,acceleration:NaN,isBelow:!1,barIndex:0});const p=e.taState[c],m=e.get(e.data.high,0),h=e.get(e.data.low,0),d=e.get(e.data.close,0),l=e.get(e.data.close,1),f=e.get(e.data.high,1),g=e.get(e.data.low,1),y=e.get(e.data.high,2),S=e.get(e.data.low,2);if(isNaN(m)||isNaN(h)||isNaN(d))return NaN;let _=!1;return p.barIndex===1&&(d>l?(p.isBelow=!0,p.maxMin=m,p.result=g):(p.isBelow=!1,p.maxMin=h,p.result=f),_=!0,p.acceleration=o),p.barIndex>=1&&(p.result=p.result+p.acceleration*(p.maxMin-p.result),p.isBelow?p.result>h&&(_=!0,p.isBelow=!1,p.result=Math.max(m,p.maxMin),p.maxMin=h,p.acceleration=o):p.result<m&&(_=!0,p.isBelow=!0,p.result=Math.min(h,p.maxMin),p.maxMin=m,p.acceleration=o),_||(p.isBelow?m>p.maxMin&&(p.maxMin=m,p.acceleration=Math.min(p.acceleration+a,s)):h<p.maxMin&&(p.maxMin=h,p.acceleration=Math.min(p.acceleration+a,s))),p.isBelow?(p.result=Math.min(p.result,g),p.barIndex>1&&(p.result=Math.min(p.result,S))):(p.result=Math.max(p.result,f),p.barIndex>1&&(p.result=Math.max(p.result,y)))),p.barIndex++,p.barIndex<=1?NaN:e.precision(p.result)}}function Pr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`sma_${i}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const a=e.taState[o],s=u.from(t).get(0)||0;if(a.window.unshift(s),a.sum+=s,a.window.length<i)return NaN;if(a.window.length>i){const p=a.window.pop();a.sum-=p}const c=a.sum/i;return e.precision(c)}}function Br(e){return(t,n,r=!0,i)=>{const o=u.from(n).get(0),a=u.from(r).get(0);e.taState||(e.taState={});const s=i||`stdev_${o}_${a}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const c=e.taState[s],p=u.from(t).get(0);if(c.window.unshift(p),c.sum+=p,c.window.length<o)return NaN;if(c.window.length>o){const f=c.window.pop();c.sum-=f}const m=c.sum/o;let h=0;for(let f=0;f<o;f++)h+=Math.pow(c.window[f]-m,2);const d=a?o:o-1,l=Math.sqrt(h/d);return e.precision(l)}}function Wr(e){return(t,n,r,i,o)=>{const a=u.from(i).get(0);e.taState||(e.taState={});const s=o||`stoch_${a}`;e.taState[s]||(e.taState[s]={highWindow:[],lowWindow:[]});const c=e.taState[s],p=u.from(t).get(0),m=u.from(n).get(0),h=u.from(r).get(0);if(isNaN(p)||isNaN(m)||isNaN(h))return NaN;if(c.highWindow.unshift(m),c.lowWindow.unshift(h),c.highWindow.length<a)return NaN;c.highWindow.length>a&&(c.highWindow.pop(),c.lowWindow.pop());let d=c.highWindow[0],l=c.lowWindow[0];for(let y=1;y<a;y++)c.highWindow[y]>d&&(d=c.highWindow[y]),c.lowWindow[y]<l&&(l=c.lowWindow[y]);const f=d-l;if(f===0)return NaN;const g=100*(p-l)/f;return e.precision(g)}}function Lr(e){return(t,n,r)=>{const i=u.from(t).get(0),o=u.from(n).get(0);e.taState||(e.taState={});const a=r||`supertrend_${i}_${o}`;e.taState[a]||(e.taState[a]={trWindow:[],trSum:0,atrValue:NaN,atrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,prevClose:NaN});const s=e.taState[a],c=e.get(e.data.high,0),p=e.get(e.data.low,0),m=e.get(e.data.close,0);if(isNaN(c)||isNaN(p)||isNaN(m))return[[NaN,NaN]];const h=(c+p)/2;let d;isNaN(s.prevClose)?d=c-p:d=Math.max(c-p,Math.abs(c-s.prevClose),Math.abs(p-s.prevClose)),s.atrCount++,s.atrCount<=o?(s.trWindow.push(d),s.trSum+=d,s.atrCount===o&&(s.atrValue=s.trSum/o)):s.atrValue=(s.atrValue*(o-1)+d)/o;const l=s.atrValue,f=s.prevClose;if(s.prevClose=m,isNaN(l))return[[NaN,NaN]];let g=h+i*l,y=h-i*l;const S=isNaN(s.prevLowerBand)?0:s.prevLowerBand,_=isNaN(s.prevUpperBand)?0:s.prevUpperBand;isNaN(s.prevLowerBand)||y>S||f<S||(y=S),isNaN(s.prevUpperBand)||g<_||f>_||(g=_);let v,w;const j=s.prevSuperTrend;return s.atrCount===o?v=1:j===s.prevUpperBand?v=m>g?-1:1:v=m<y?1:-1,w=v===-1?y:g,s.prevLowerBand=y,s.prevUpperBand=g,s.prevSuperTrend=w,s.prevDirection=v,[[e.precision(w),v]]}}function Or(e){return(t,n)=>{const r=[1,2,2,1],i=6;e.taState||(e.taState={});const o=n||"swma";e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<4)return NaN;a.window.length>4&&a.window.pop();let c=0;for(let p=0;p<4;p++)c+=r[p]*a.window[3-p];return c/=i,e.precision(c)}}function Rr(e){return(t,n)=>{let r=!0;typeof t=="string"||t!==void 0&&(r=u.from(t).get(0));const i=e.get(e.data.high,0),o=e.get(e.data.low,0),a=e.get(e.data.close,1);return isNaN(a)?r?i-o:NaN:Math.max(i-o,Math.abs(i-a),Math.abs(o-a))}}function Fr(e){return(t,n,r,i)=>{const o=u.from(n).get(0),a=u.from(r).get(0);e.taState||(e.taState={});const s=i||`tsi_${o}_${a}`;e.taState[s]||(e.taState[s]={prevSource:NaN,ema1_pc_multiplier:2/(a+1),ema1_pc_value:NaN,ema1_pc_count:0,ema1_pc_sum:0,ema2_pc_multiplier:2/(o+1),ema2_pc_value:NaN,ema2_pc_count:0,ema2_pc_sum:0,ema1_abs_multiplier:2/(a+1),ema1_abs_value:NaN,ema1_abs_count:0,ema1_abs_sum:0,ema2_abs_multiplier:2/(o+1),ema2_abs_value:NaN,ema2_abs_count:0,ema2_abs_sum:0});const c=e.taState[s],p=u.from(t).get(0);if(isNaN(p))return NaN;const m=isNaN(c.prevSource)?NaN:p-c.prevSource;if(c.prevSource=p,isNaN(m))return NaN;const h=Math.abs(m);if(c.ema1_pc_count++,c.ema1_pc_count<=a?(c.ema1_pc_sum+=m,c.ema1_pc_count===a&&(c.ema1_pc_value=c.ema1_pc_sum/a)):c.ema1_pc_value=m*c.ema1_pc_multiplier+c.ema1_pc_value*(1-c.ema1_pc_multiplier),c.ema1_abs_count++,c.ema1_abs_count<=a?(c.ema1_abs_sum+=h,c.ema1_abs_count===a&&(c.ema1_abs_value=c.ema1_abs_sum/a)):c.ema1_abs_value=h*c.ema1_abs_multiplier+c.ema1_abs_value*(1-c.ema1_abs_multiplier),isNaN(c.ema1_pc_value)||isNaN(c.ema1_abs_value))return NaN;if(c.ema2_pc_count++,c.ema2_pc_count<=o?(c.ema2_pc_sum+=c.ema1_pc_value,c.ema2_pc_count===o&&(c.ema2_pc_value=c.ema2_pc_sum/o)):c.ema2_pc_value=c.ema1_pc_value*c.ema2_pc_multiplier+c.ema2_pc_value*(1-c.ema2_pc_multiplier),c.ema2_abs_count++,c.ema2_abs_count<=o?(c.ema2_abs_sum+=c.ema1_abs_value,c.ema2_abs_count===o&&(c.ema2_abs_value=c.ema2_abs_sum/o)):c.ema2_abs_value=c.ema1_abs_value*c.ema2_abs_multiplier+c.ema2_abs_value*(1-c.ema2_abs_multiplier),isNaN(c.ema2_pc_value)||isNaN(c.ema2_abs_value))return NaN;if(c.ema2_abs_value===0)return e.precision(0);const d=c.ema2_pc_value/c.ema2_abs_value;return e.precision(d)}}function qr(e){return(t,n,r,i)=>{e.taState||(e.taState={});const o=i||"valuewhen";e.taState[o]||(e.taState[o]={values:[]});const a=e.taState[o],s=u.from(t).get(0),c=u.from(n).get(0),p=u.from(r).get(0);if(s&&a.values.push(c),isNaN(p)||p<0)return NaN;const m=a.values.length-1-p;if(m<0)return NaN;const h=a.values[m];return typeof h=="number"?e.precision(h):h}}function Hr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`variance_${i}`;e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();let c=0,p=0;for(let d=0;d<i;d++)c+=a.window[d],p+=a.window[d]*a.window[d];const m=c/i,h=p/i-m*m;return e.precision(h)}}function Gr(e){return(t,n)=>{e.taState||(e.taState={});const r=n||"vwap";e.taState[r]||(e.taState[r]={cumulativePV:0,cumulativeVolume:0,lastSessionDate:null});const i=e.taState[r],o=u.from(t).get(0),a=u.from(e.data.volume).get(0),s=u.from(e.data.openTime).get(0),c=new Date(s).toISOString().slice(0,10);if(i.lastSessionDate!==c&&(i.cumulativePV=0,i.cumulativeVolume=0,i.lastSessionDate=c),i.cumulativePV+=o*a,i.cumulativeVolume+=a,i.cumulativeVolume===0)return NaN;const p=i.cumulativePV/i.cumulativeVolume;return e.precision(p)}}function zr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`vwma_${i}`;e.taState[o]||(e.taState[o]={window:[],volumeWindow:[]});const a=e.taState[o],s=u.from(t).get(0),c=e.get(e.data.volume,0);if(a.window.unshift(s),a.volumeWindow.unshift(c),a.window.length<i)return NaN;a.window.length>i&&(a.window.pop(),a.volumeWindow.pop());let p=0,m=0;for(let d=0;d<i;d++)p+=a.window[d]*a.volumeWindow[d],m+=a.volumeWindow[d];const h=p/m;return e.precision(h)}}function Ur(e){return t=>{e.taState||(e.taState={});const n=t||"wad";e.taState[n]||(e.taState[n]={cumulativeSum:0});const r=e.taState[n],i=e.get(e.data.close,0),o=e.get(e.data.high,0),a=e.get(e.data.low,0),s=e.get(e.data.close,1);if(isNaN(i)||isNaN(o)||isNaN(a))return e.precision(r.cumulativeSum);let c=0;if(!isNaN(s)){const p=Math.max(o,s),m=Math.min(a,s),h=i-s;h>0?c=i-m:h<0&&(c=i-p)}return r.cumulativeSum+=c,e.precision(r.cumulativeSum)}}function Xr(e){return(t,n,r)=>{const i=u.from(n).get(0);e.taState||(e.taState={});const o=r||`wma_${i}`;e.taState[o]||(e.taState[o]={window:[]});const a=e.taState[o],s=u.from(t).get(0);if(a.window.unshift(s),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();let c=0,p=0;for(let h=0;h<i;h++){const d=i-h;c+=a.window[h]*d,p+=d}const m=c/p;return e.precision(m)}}function Kr(e){return(t,n)=>{const r=u.from(t).get(0);e.taState||(e.taState={});const i=n||`wpr_${r}`;e.taState[i]||(e.taState[i]={highWindow:[],lowWindow:[]});const o=e.taState[i],a=e.get(e.data.high,0),s=e.get(e.data.low,0),c=e.get(e.data.close,0);if(isNaN(a)||isNaN(s)||isNaN(c))return NaN;if(o.highWindow.unshift(a),o.lowWindow.unshift(s),o.highWindow.length<r)return NaN;o.highWindow.length>r&&(o.highWindow.pop(),o.lowWindow.pop());let p=o.highWindow[0],m=o.lowWindow[0];for(let l=1;l<r;l++)o.highWindow[l]>p&&(p=o.highWindow[l]),o.lowWindow[l]<m&&(m=o.lowWindow[l]);const h=p-m;if(h===0)return e.precision(0);const d=(p-c)/h*-100;return e.precision(d)}}function Jr(e){return t=>{const n=e.get(e.data.close,0),r=e.get(e.data.open,0),i=e.get(e.data.high,0),o=e.get(e.data.low,0),a=e.get(e.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(o)||isNaN(a))return NaN;const s=i-o;if(s===0)return e.precision(0);const c=(n-r)/s*a;return e.precision(c)}}var Qr=Object.defineProperty,Yr=(e,t,n)=>t in e?Qr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,N=(e,t,n)=>Yr(e,typeof t!="symbol"?t+"":t,n);const Zr={accdist:Ln,alma:On,atr:Rn,barssince:Fn,bb:qn,bbw:Hn,cci:Gn,change:zn,cmo:Un,cog:Xn,correlation:Kn,cross:Jn,crossover:Qn,crossunder:Yn,cum:Zn,dev:er,dmi:tr,ema:nr,falling:rr,highest:ar,highestbars:ir,hma:or,iii:sr,kc:cr,kcw:pr,linreg:lr,lowest:ur,lowestbars:mr,macd:hr,median:dr,mfi:fr,mode:gr,mom:yr,nvi:br,obv:wr,param:Nr,percentile_linear_interpolation:Sr,percentile_nearest_rank:vr,percentrank:xr,pivothigh:Cr,pivotlow:Ir,pvi:Mr,pvt:jr,range:Ar,rising:$r,rma:Vr,roc:Dr,rsi:Tr,sar:kr,sma:Pr,stdev:Br,stoch:Wr,supertrend:Lr,swma:Or,tr:Rr,tsi:Fr,valuewhen:qr,variance:Hr,vwap:Gr,vwma:zr,wad:Ur,wma:Xr,wpr:Kr,wvad:Jr};class ea{constructor(t){this.context=t,N(this,"accdist"),N(this,"alma"),N(this,"atr"),N(this,"barssince"),N(this,"bb"),N(this,"bbw"),N(this,"cci"),N(this,"change"),N(this,"cmo"),N(this,"cog"),N(this,"correlation"),N(this,"cross"),N(this,"crossover"),N(this,"crossunder"),N(this,"cum"),N(this,"dev"),N(this,"dmi"),N(this,"ema"),N(this,"falling"),N(this,"highest"),N(this,"highestbars"),N(this,"hma"),N(this,"iii"),N(this,"kc"),N(this,"kcw"),N(this,"linreg"),N(this,"lowest"),N(this,"lowestbars"),N(this,"macd"),N(this,"median"),N(this,"mfi"),N(this,"mode"),N(this,"mom"),N(this,"nvi"),N(this,"obv"),N(this,"param"),N(this,"percentile_linear_interpolation"),N(this,"percentile_nearest_rank"),N(this,"percentrank"),N(this,"pivothigh"),N(this,"pivotlow"),N(this,"pvi"),N(this,"pvt"),N(this,"range"),N(this,"rising"),N(this,"rma"),N(this,"roc"),N(this,"rsi"),N(this,"sar"),N(this,"sma"),N(this,"stdev"),N(this,"stoch"),N(this,"supertrend"),N(this,"swma"),N(this,"tr"),N(this,"tsi"),N(this,"valuewhen"),N(this,"variance"),N(this,"vwap"),N(this,"vwma"),N(this,"wad"),N(this,"wma"),N(this,"wpr"),N(this,"wvad"),Object.entries(Zr).forEach(([n,r])=>{this[n]=r(t)})}}var ta=Object.defineProperty,na=(e,t,n)=>t in e?ta(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,E=(e,t,n)=>na(e,typeof t!="symbol"?t+"":t,n);const be=class re{constructor({marketData:t,source:n,tickerId:r,timeframe:i,limit:o,sDate:a,eDate:s}){E(this,"data",{open:new u([]),high:new u([]),low:new u([]),close:new u([]),volume:new u([]),hl2:new u([]),hlc3:new u([]),ohlc4:new u([])}),E(this,"cache",{}),E(this,"taState",{}),E(this,"isSecondaryContext",!1),E(this,"NA",NaN),E(this,"lang"),E(this,"pine"),E(this,"idx",0),E(this,"params",{}),E(this,"const",{}),E(this,"var",{}),E(this,"let",{}),E(this,"result"),E(this,"plots",{}),E(this,"marketData"),E(this,"source"),E(this,"tickerId"),E(this,"timeframe",""),E(this,"limit"),E(this,"sDate"),E(this,"eDate"),E(this,"pineTSCode"),this.marketData=t,this.source=n,this.tickerId=r,this.timeframe=i,this.limit=o,this.sDate=a,this.eDate=s;const c=new Lt(this),p={plotchar:c.plotchar.bind(c),na:c.na.bind(c),color:c.color,plot:c.plot.bind(c),nz:c.nz.bind(c)},m=this;this.pine={input:new an(this),ta:new ea(this),math:new Vn(this),request:new Wn(this),array:new kt(this),na:p.na,plotchar:p.plotchar,color:p.color,plot:p.plot,nz:p.nz,get bar_index(){return m.idx}}}init(t,n,r=0){let i;return n instanceof u?i=n.get(0):Array.isArray(n)?Array.isArray(n[0])?i=n[0]:i=this.precision(n[n.length-1+r]):i=this.precision(n),t?t instanceof u?(t.data[t.data.length-1]=i,t):Array.isArray(t)?(t[t.length-1]=i,new u(t)):new u([i]):new u([i])}initVar(t,n){if(t)return t;let r;return n instanceof u?r=n.get(0):Array.isArray(n)?Array.isArray(n[0])?r=n[0]:r=this.precision(n[n.length-1]):r=this.precision(n),new u([r])}precision(t,n=10){return typeof t!="number"||isNaN(t)?t:Number(t.toFixed(n))}param(t,n,r){return typeof t=="string"?t:t instanceof u?n?new u(t.data,t.offset+n):t:!Array.isArray(t)&&typeof t=="object"?t:(this.params[r]||(this.params[r]=[]),Array.isArray(t)?new u(t,n||0):(this.params[r].length===0?this.params[r].push(t):this.params[r][this.params[r].length-1]=t,new u(this.params[r],0)))}get(t,n){if(t instanceof u)return t.get(n);if(Array.isArray(t)){const r=t.length-1-n;return r<0||r>=t.length?NaN:t[r]}return t}set(t,n){if(t instanceof u){t.set(0,n);return}if(Array.isArray(t)){t.length>0?t[t.length-1]=n:t.push(n);return}}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,plotchar:this.pine.plotchar,color:this.pine.color,plot:this.pine.plot,nz:this.pine.nz}}_showDeprecationWarning(t,n){const r=`${t}->${n}`;re._deprecationWarningsShown.has(r)||(re._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;",t,n):console.warn(`\x1B[33m[WARNING] ${t} syntax is deprecated. Use ${n} instead. This will be removed in a future version.\x1B[0m`))}};E(be,"_deprecationWarningsShown",new Set);let ue=be;var ra=Object.defineProperty,aa=(e,t,n)=>t in e?ra(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$=(e,t,n)=>aa(e,typeof t!="symbol"?t+"":t,n);class ia{constructor(t,n,r,i,o,a){this.source=t,this.tickerId=n,this.timeframe=r,this.limit=i,this.sDate=o,this.eDate=a,$(this,"data",[]),$(this,"open",[]),$(this,"high",[]),$(this,"low",[]),$(this,"close",[]),$(this,"volume",[]),$(this,"hl2",[]),$(this,"hlc3",[]),$(this,"ohlc4",[]),$(this,"openTime",[]),$(this,"closeTime",[]),$(this,"_readyPromise",null),$(this,"_ready",!1),$(this,"_debugSettings",{ln:!1,debug:!1}),$(this,"_transpiledCode",null),$(this,"_isSecondaryContext",!1),this._readyPromise=new Promise(s=>{this.loadMarketData(t,n,r,i,o,a).then(c=>{const p=c;this.data=p;const m=p.map(w=>w.open),h=p.map(w=>w.close),d=p.map(w=>w.high),l=p.map(w=>w.low),f=p.map(w=>w.volume),g=p.map(w=>(w.high+w.low+w.close)/3),y=p.map(w=>(w.high+w.low)/2),S=p.map(w=>(w.high+w.low+w.open+w.close)/4),_=p.map(w=>w.openTime),v=p.map(w=>w.closeTime);this.open=m,this.close=h,this.high=d,this.low=l,this.volume=f,this.hl2=y,this.hlc3=g,this.ohlc4=S,this.openTime=_,this.closeTime=v,this._ready=!0,s(!0)})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setDebugSettings({ln:t,debug:n}){this._debugSettings.ln=t,this._debugSettings.debug=n}async loadMarketData(t,n,r,i,o,a){return Array.isArray(t)?t:t.getMarketData(n,r,i,o,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(t,n,r){if(r&&r>0){const i=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(t,n,r,i)}else return this._runComplete(t,n)}async _runComplete(t,n){await this.ready(),n||(n=this.data.length);const r=this._initializeContext(t,this._isSecondaryContext);return this._transpiledCode=this._transpileCode(t),await this._executeIterations(r,this._transpiledCode,this.data.length-n,this.data.length),r}async*_runPaginated(t,n,r,i=!1){await this.ready(),n||(n=this.data.length);const o=this._initializeContext(t,this._isSecondaryContext);this._transpiledCode=this._transpileCode(t);let a=this.data.length-n;for(;;){const s=this.data.length-a;if(s>0){const m=Math.min(s,r),h=this._getResultLength(o.result);await this._executeIterations(o,this._transpiledCode,a,a+m),a+=m,yield this._createPageContext(o,h);continue}if(!i||Array.isArray(this.source))break;const{newCandles:c,updatedLastCandle:p}=await this._updateMarketData();if(c===0&&!p){yield null;continue}this._removeLastResult(o),a=this.data.length-(c+1)}}_getResultLength(t){if(Array.isArray(t))return t.length;if(typeof t=="object"&&t!==null){const n=Object.keys(t);if(n.length>0&&Array.isArray(t[n[0]]))return t[n[0]].length}return 0}_createPageContext(t,n){const r=new ue({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});if(r.pineTSCode=t.pineTSCode,r.idx=t.idx,Array.isArray(t.result))r.result=t.result.slice(n);else if(typeof t.result=="object"&&t.result!==null){r.result={};for(let i in t.result)Array.isArray(t.result[i])?r.result[i]=t.result[i].slice(n):r.result[i]=t.result[i]}else r.result=t.result;return r.plots={...t.plots},r}async _updateMarketData(t){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const n=this.source,r=this.data.length-1,i=this.data[r].openTime;try{const o=await n.getMarketData(this.tickerId,this.timeframe,void 0,i,t);if(!o||o.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,s=0;for(let c=0;c<o.length;c++){const p=o[c];p.openTime===i?(this._replaceCandle(r,p),a=!0):p.openTime>i&&(this._appendCandle(p),s++)}return{newCandles:s,updatedLastCandle:a}}catch(o){return console.error("Error updating market data:",o),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(t,n){this.data[t]=n,this.open[t]=n.open,this.close[t]=n.close,this.high[t]=n.high,this.low[t]=n.low,this.volume[t]=n.volume,this.hl2[t]=(n.high+n.low)/2,this.hlc3[t]=(n.high+n.low+n.close)/3,this.ohlc4[t]=(n.high+n.low+n.open+n.close)/4,this.openTime[t]=n.openTime,this.closeTime[t]=n.closeTime}_appendCandle(t){this.data.push(t),this.open.push(t.open),this.close.push(t.close),this.high.push(t.high),this.low.push(t.low),this.volume.push(t.volume),this.hl2.push((t.high+t.low)/2),this.hlc3.push((t.high+t.low+t.close)/3),this.ohlc4.push((t.high+t.low+t.open+t.close)/4),this.openTime.push(t.openTime),this.closeTime.push(t.closeTime)}_removeLastResult(t){if(Array.isArray(t.result))t.result.pop();else if(typeof t.result=="object"&&t.result!==null)for(let n in t.result)Array.isArray(t.result[n])&&t.result[n].pop();t.data.close.data.pop(),t.data.open.data.pop(),t.data.high.data.pop(),t.data.low.data.pop(),t.data.volume.data.pop(),t.data.hl2.data.pop(),t.data.hlc3.data.pop(),t.data.ohlc4.data.pop(),t.data.openTime.data.pop(),t.data.closeTime&&t.data.closeTime.data.pop()}_initializeContext(t,n=!1){const r=new ue({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});return r.pineTSCode=t,r.isSecondaryContext=n,r.data.close=new u([]),r.data.open=new u([]),r.data.high=new u([]),r.data.low=new u([]),r.data.volume=new u([]),r.data.hl2=new u([]),r.data.hlc3=new u([]),r.data.ohlc4=new u([]),r.data.openTime=new u([]),r.data.closeTime=new u([]),r}_transpileCode(t){return qe.bind(this)(t,this._debugSettings)}async _executeIterations(t,n,r,i){const o=["const","var","let","params"];for(let a=r;a<i;a++){t.idx=a,t.data.close.data.push(this.close[a]),t.data.open.data.push(this.open[a]),t.data.high.data.push(this.high[a]),t.data.low.data.push(this.low[a]),t.data.volume.data.push(this.volume[a]),t.data.hl2.data.push(this.hl2[a]),t.data.hlc3.data.push(this.hlc3[a]),t.data.ohlc4.data.push(this.ohlc4[a]),t.data.openTime.data.push(this.openTime[a]),t.data.closeTime.data.push(this.closeTime[a]);const s=await n(t);if(typeof s=="object"){typeof t.result!="object"&&(t.result={});for(let c in s){t.result[c]===void 0&&(t.result[c]=[]);let p;s[c]instanceof u?p=s[c].get(0):Array.isArray(s[c])?p=s[c][s[c].length-1]:p=s[c],t.result[c].push(p)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(s);for(let c of o)for(let p in t[c]){const m=t[c][p];if(m instanceof u){const h=m.get(0);m.data.push(h)}else if(Array.isArray(m)){const h=m[m.length-1];m.push(h)}}}}}var oa=Object.defineProperty,sa=(e,t,n)=>t in e?oa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ae=(e,t,n)=>sa(e,typeof t!="symbol"?t+"":t,n);const ca="https://api.binance.com/api/v3",te={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 pa{constructor(t=5*60*1e3){ae(this,"cache"),ae(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=t}generateKey(t){return Object.entries(t).filter(([n,r])=>r!==void 0).map(([n,r])=>`${n}:${r}`).join("|")}get(t){const n=this.generateKey(t),r=this.cache.get(n);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(n),null):r.data:null}set(t,n){const r=this.generateKey(t);this.cache.set(r,{data:n,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const t=Date.now();for(const[n,r]of this.cache.entries())t-r.timestamp>this.cacheDuration&&this.cache.delete(n)}}class la{constructor(){ae(this,"cacheManager"),this.cacheManager=new pa(5*60*1e3)}async getMarketDataInterval(t,n,r,i){try{const o=te[n.toUpperCase()];if(!o)return console.error(`Unsupported timeframe: ${n}`),[];const a={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3};let s=[],c=r;const p=i,m=a[o];if(!m)return console.error(`Duration not defined for interval: ${o}`),[];for(;c<p;){const h=Math.min(c+1e3*m,p),d=await this.getMarketData(t,n,1e3,c,h);if(d.length===0)break;s=s.concat(d),c=d[d.length-1].closeTime+1}return s}catch(o){return console.error("Error in getMarketDataInterval:",o),[]}}async getMarketData(t,n,r,i,o){try{const a={tickerId:t,timeframe:n,limit:r,sDate:i,eDate:o},s=this.cacheManager.get(a);if(s)return s;const c=te[n.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${n}`),[];if(this.shouldPaginate(n,r,i,o)&&i&&o){const d=await this.getMarketDataInterval(t,n,i,o),l=r?d.slice(0,r):d;return this.cacheManager.set(a,l),l}let p=`${ca}/klines?symbol=${t}&interval=${c}`;r&&(p+=`&limit=${Math.min(r,1e3)}`),i&&(p+=`&startTime=${i}`),o&&(p+=`&endTime=${o}`);const m=await fetch(p);if(!m.ok)throw new Error(`HTTP error! status: ${m.status}`);const h=(await m.json()).map(d=>({openTime:parseInt(d[0]),open:parseFloat(d[1]),high:parseFloat(d[2]),low:parseFloat(d[3]),close:parseFloat(d[4]),volume:parseFloat(d[5]),closeTime:parseInt(d[6]),quoteAssetVolume:parseFloat(d[7]),numberOfTrades:parseInt(d[8]),takerBuyBaseAssetVolume:parseFloat(d[9]),takerBuyQuoteAssetVolume:parseFloat(d[10]),ignore:d[11]}));return this.cacheManager.set(a,h),h}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(t,n,r,i){if(n&&n>1e3)return!0;if(r&&i){const o=te[t.toUpperCase()],a={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3}[o];if(a)return Math.ceil((i-r)/a)>1e3}return!1}}var ua=Object.defineProperty,ma=(e,t,n)=>t in e?ua(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,me=(e,t,n)=>ma(e,typeof t!="symbol"?t+"":t,n);const ha=we(import.meta.url),da=J.dirname(ha);class fa{constructor(t){if(me(this,"dataCache",new Map),me(this,"dataDirectory"),t)this.dataDirectory=t;else{const n=J.resolve(da,"../../../");this.dataDirectory=J.join(n,"tests","compatibility","_data")}}getDataFileName(t,n,r,i){return r&&i?`${t}-${n}-${r}-${i}.json`:null}loadDataFromFile(t){const n=`file:${t}`;if(this.dataCache.has(n))return this.dataCache.get(n);const r=J.join(this.dataDirectory,t);if(!K.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const i=K.readFileSync(r,"utf-8"),o=JSON.parse(i);return this.dataCache.set(n,o),o}findDataFile(t,n,r,i){if(!K.existsSync(this.dataDirectory))return null;const o=K.readdirSync(this.dataDirectory).filter(c=>c.endsWith(".json"));if(r&&i){const c=`${t}-${n}-${r}-${i}.json`;if(o.includes(c))return c}const a=new RegExp(`^${t}-${n}-(\\d+)-(\\d+)\\.json$`),s=o.filter(c=>a.test(c)).map(c=>{const p=c.match(a);return{file:c,startTime:parseInt(p[1]),endTime:parseInt(p[2])}}).sort((c,p)=>p.endTime-c.endTime);if(s.length===0)return null;if(r&&i){const c=s.find(p=>p.startTime<=r&&p.endTime>=i);if(c)return c.file}return s[0].file}filterData(t,n,r,i){let o=t;return(n||r)&&(o=t.filter(a=>{const s=!n||a.openTime>=n,c=!r||a.openTime<=r;return s&&c})),o.sort((a,s)=>a.openTime-s.openTime),i&&i>0&&(o=o.slice(0,i)),o}normalizeTimeframe(t){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"}[t.toUpperCase()]||t.toLowerCase()}async getMarketData(t,n,r,i,o){try{const a=this.normalizeTimeframe(n),s=this.findDataFile(t,a,i,o);if(!s)return console.warn(`No mock data file found for ${t} ${a}. Searched in: ${this.dataDirectory}`),[];const c=this.loadDataFromFile(s);return this.filterData(c,i,o,r)}catch(a){return console.error("Error in MockProvider.getMarketData:",a),[]}}clearCache(){this.dataCache.clear()}setDataDirectory(t){this.dataDirectory=t,this.clearCache()}}const ga=typeof process<"u"&&process.versions&&process.versions.node;let Q=null;if(ga)try{Q=new fa}catch{Q=null}const ba={Binance:new la,...Q?{Mock:Q}:{}};export{ue as Context,ia as PineTS,ba as Provider};
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import { Input } from '@pinets/namespaces/input/input.index';
|
|
2
|
-
import PineMath from '@pinets/namespaces/math/math.index';
|
|
3
|
-
import { PineRequest } from '@pinets/namespaces/request/request.index';
|
|
4
|
-
import TechnicalAnalysis from '@pinets/namespaces/ta/ta.index';
|
|
5
|
-
import { PineArray } from './namespaces/array/array.index';
|
|
6
1
|
import { IProvider } from './marketData/IProvider';
|
|
2
|
+
import { PineArray } from './namespaces/array/array.index';
|
|
3
|
+
import { Input } from './namespaces/input/input.index';
|
|
4
|
+
import PineMath from './namespaces/math/math.index';
|
|
5
|
+
import { PineRequest } from './namespaces/request/request.index';
|
|
6
|
+
import TechnicalAnalysis from './namespaces/ta/ta.index';
|
|
7
|
+
import { Series } from './Series';
|
|
7
8
|
export declare class Context {
|
|
8
9
|
data: any;
|
|
9
10
|
cache: any;
|
|
10
11
|
taState: any;
|
|
12
|
+
isSecondaryContext: boolean;
|
|
11
13
|
NA: any;
|
|
12
|
-
math: PineMath;
|
|
13
|
-
ta: TechnicalAnalysis;
|
|
14
|
-
input: Input;
|
|
15
|
-
request: PineRequest;
|
|
16
|
-
array: PineArray;
|
|
17
|
-
core: any;
|
|
18
14
|
lang: any;
|
|
15
|
+
pine: {
|
|
16
|
+
input: Input;
|
|
17
|
+
ta: TechnicalAnalysis;
|
|
18
|
+
math: PineMath;
|
|
19
|
+
request: PineRequest;
|
|
20
|
+
array: PineArray;
|
|
21
|
+
na: () => any;
|
|
22
|
+
plotchar: (...args: any[]) => any;
|
|
23
|
+
color: any;
|
|
24
|
+
plot: (...args: any[]) => any;
|
|
25
|
+
nz: (...args: any[]) => any;
|
|
26
|
+
bar_index: number;
|
|
27
|
+
};
|
|
28
|
+
private static _deprecationWarningsShown;
|
|
19
29
|
idx: number;
|
|
20
30
|
params: any;
|
|
21
31
|
const: any;
|
|
@@ -44,17 +54,25 @@ export declare class Context {
|
|
|
44
54
|
* this function is used to initialize the target variable with the source array
|
|
45
55
|
* this array will represent a time series and its values will be shifted at runtime in order to mimic Pine script behavior
|
|
46
56
|
* @param trg - the target variable name : used internally to maintain the series in the execution context
|
|
47
|
-
* @param src - the source data, can be
|
|
57
|
+
* @param src - the source data, can be Series, array, or a single value
|
|
48
58
|
* @param idx - the index of the source array, used to get a sub-series of the source data
|
|
49
|
-
* @returns
|
|
59
|
+
* @returns Series object
|
|
50
60
|
*/
|
|
51
|
-
init(trg: any, src: any, idx?: number):
|
|
61
|
+
init(trg: any, src: any, idx?: number): Series;
|
|
62
|
+
/**
|
|
63
|
+
* Initializes a 'var' variable.
|
|
64
|
+
* - First bar: uses the initial value.
|
|
65
|
+
* - Subsequent bars: maintains the previous value (state).
|
|
66
|
+
* @param trg - The target variable
|
|
67
|
+
* @param src - The source initializer value
|
|
68
|
+
* @returns Series object
|
|
69
|
+
*/
|
|
70
|
+
initVar(trg: any, src: any): Series;
|
|
52
71
|
/**
|
|
53
72
|
* this function is used to set the floating point precision of a number
|
|
54
73
|
* by default it is set to 10 decimals which is the same as pine script
|
|
55
74
|
* @param n - the number to be precision
|
|
56
75
|
* @param decimals - the number of decimals to precision to
|
|
57
|
-
|
|
58
76
|
* @returns the precision number
|
|
59
77
|
*/
|
|
60
78
|
precision(n: number, decimals?: number): number;
|
|
@@ -78,5 +96,33 @@ export declare class Context {
|
|
|
78
96
|
* @param value - The value to set
|
|
79
97
|
*/
|
|
80
98
|
set(target: any, value: any): void;
|
|
99
|
+
/**
|
|
100
|
+
* @deprecated Use context.pine.math instead. This will be removed in a future version.
|
|
101
|
+
*/
|
|
102
|
+
get math(): PineMath;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use context.pine.ta instead. This will be removed in a future version.
|
|
105
|
+
*/
|
|
106
|
+
get ta(): TechnicalAnalysis;
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use context.pine.input instead. This will be removed in a future version.
|
|
109
|
+
*/
|
|
110
|
+
get input(): Input;
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated Use context.pine.request instead. This will be removed in a future version.
|
|
113
|
+
*/
|
|
114
|
+
get request(): PineRequest;
|
|
115
|
+
/**
|
|
116
|
+
* @deprecated Use context.pine.array instead. This will be removed in a future version.
|
|
117
|
+
*/
|
|
118
|
+
get array(): PineArray;
|
|
119
|
+
/**
|
|
120
|
+
* @deprecated Use context.pine.* (e.g., context.pine.na, context.pine.plot) instead. This will be removed in a future version.
|
|
121
|
+
*/
|
|
122
|
+
get core(): any;
|
|
123
|
+
/**
|
|
124
|
+
* Shows a deprecation warning once per property access pattern
|
|
125
|
+
*/
|
|
126
|
+
private _showDeprecationWarning;
|
|
81
127
|
}
|
|
82
128
|
export default Context;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { IProvider } from './marketData/IProvider';
|
|
1
2
|
import { Context } from './Context.class';
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* This class is a wrapper for the Pine Script language, it allows to run Pine Script code in a JavaScript environment
|
|
5
|
+
*/
|
|
3
6
|
export declare class PineTS {
|
|
4
7
|
private source;
|
|
5
8
|
private tickerId?;
|
|
@@ -20,9 +23,16 @@ export declare class PineTS {
|
|
|
20
23
|
closeTime: any;
|
|
21
24
|
private _readyPromise;
|
|
22
25
|
private _ready;
|
|
26
|
+
private _debugSettings;
|
|
23
27
|
private _transpiledCode;
|
|
24
28
|
get transpiledCode(): Function | String;
|
|
29
|
+
private _isSecondaryContext;
|
|
30
|
+
markAsSecondary(): void;
|
|
25
31
|
constructor(source: IProvider | any[], tickerId?: string, timeframe?: string, limit?: number, sDate?: number, eDate?: number);
|
|
32
|
+
setDebugSettings({ ln, debug }: {
|
|
33
|
+
ln: boolean;
|
|
34
|
+
debug: boolean;
|
|
35
|
+
}): void;
|
|
26
36
|
private loadMarketData;
|
|
27
37
|
ready(): Promise<any>;
|
|
28
38
|
/**
|
|
@@ -18,6 +18,7 @@ export declare class Core {
|
|
|
18
18
|
indicator(title: string, shorttitle?: string, options?: IndicatorOptions): void;
|
|
19
19
|
plotchar(series: number[], title: string, options: PlotCharOptions): void;
|
|
20
20
|
plot(series: any, title: string, options: PlotOptions): void;
|
|
21
|
+
get bar_index(): any;
|
|
21
22
|
na(series: any): boolean;
|
|
22
23
|
nz(series: any, replacement?: number): any;
|
|
23
24
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PineArrayObject } from '../PineArrayObject';
|
|
2
|
-
export declare function from(context: any): (
|
|
2
|
+
export declare function from(context: any): (...values: any[]) => PineArrayObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function security(context: any): (symbol: any, timeframe: any, expression: any, gaps?: boolean, lookahead?: boolean, ignore_invalid_symbol?: boolean, currency?: any, calc_bars_count?: any) => Promise<any>;
|
|
1
|
+
export declare function security(context: any): (symbol: any, timeframe: any, expression: any, gaps?: boolean | any[], lookahead?: boolean | any[], ignore_invalid_symbol?: boolean, currency?: any, calc_bars_count?: any) => Promise<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findLTFContextIdx(myOpenTime: number, myCloseTime: number, openTime: number[], closeTime: number[], lookahead?: boolean, mainContextEDate?: number, gaps?: boolean): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-Balance Volume (OBV)
|
|
3
|
+
* Cumulative indicator that adds volume on up days and subtracts on down days
|
|
4
|
+
*
|
|
5
|
+
* Logic:
|
|
6
|
+
* - If close > close[1]: OBV = OBV[1] + volume
|
|
7
|
+
* - If close < close[1]: OBV = OBV[1] - volume
|
|
8
|
+
* - If close == close[1]: OBV = OBV[1]
|
|
9
|
+
*
|
|
10
|
+
* Note: OBV starts at 0 on the first bar (when there's no previous close to compare)
|
|
11
|
+
*/
|
|
12
|
+
export declare function obv(context: any): () => any;
|