pinets 0.5.0 → 0.6.1
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 +47 -3
- package/dist/pinets.dev.browser.js +3019 -391
- package/dist/pinets.dev.cjs +3106 -365
- package/dist/pinets.dev.cjs.map +1 -1
- package/dist/pinets.dev.es.js +3110 -360
- package/dist/pinets.dev.es.js.map +1 -1
- package/dist/pinets.min.browser.js +15 -14
- package/dist/pinets.min.cjs +15 -14
- package/dist/pinets.min.es.js +5 -4
- package/dist/types/Context.class.d.ts +19 -3
- package/dist/types/PineTS.class.d.ts +2 -0
- package/dist/types/marketData/Binance/BinanceProvider.class.d.ts +2 -1
- package/dist/types/marketData/IProvider.d.ts +43 -0
- package/dist/types/marketData/Mock/MockProvider.class.d.ts +13 -1
- package/dist/types/namespaces/Barstate.d.ts +13 -0
- package/dist/types/namespaces/Core.d.ts +15 -0
- package/dist/types/namespaces/Log.d.ts +10 -0
- package/dist/types/namespaces/Str.d.ts +23 -0
- package/dist/types/namespaces/Timeframe.d.ts +17 -0
- package/dist/types/namespaces/Types.d.ts +86 -0
- package/dist/types/namespaces/array/PineArrayObject.d.ts +102 -1
- package/dist/types/namespaces/array/array.index.d.ts +1 -129
- package/dist/types/namespaces/array/methods/avg.d.ts +2 -1
- package/dist/types/namespaces/array/methods/binary_search.d.ts +2 -0
- package/dist/types/namespaces/array/methods/binary_search_leftmost.d.ts +2 -0
- package/dist/types/namespaces/array/methods/binary_search_rightmost.d.ts +2 -0
- package/dist/types/namespaces/array/methods/covariance.d.ts +2 -1
- package/dist/types/namespaces/array/methods/every.d.ts +1 -1
- package/dist/types/namespaces/array/methods/fill.d.ts +2 -1
- package/dist/types/namespaces/array/methods/join.d.ts +5 -0
- package/dist/types/namespaces/array/methods/median.d.ts +2 -0
- package/dist/types/namespaces/array/methods/mode.d.ts +2 -0
- package/dist/types/namespaces/array/methods/new.d.ts +2 -1
- package/dist/types/namespaces/array/methods/new_float.d.ts +2 -1
- package/dist/types/namespaces/array/methods/new_int.d.ts +2 -1
- package/dist/types/namespaces/array/methods/percentile_linear_interpolation.d.ts +3 -0
- package/dist/types/namespaces/array/methods/percentile_nearest_rank.d.ts +2 -0
- package/dist/types/namespaces/array/methods/percentrank.d.ts +2 -0
- package/dist/types/namespaces/array/methods/push.d.ts +2 -1
- package/dist/types/namespaces/array/methods/range.d.ts +2 -1
- package/dist/types/namespaces/array/methods/set.d.ts +2 -1
- package/dist/types/namespaces/array/methods/some.d.ts +1 -1
- package/dist/types/namespaces/array/methods/sort.d.ts +2 -1
- package/dist/types/namespaces/array/methods/sort_indices.d.ts +2 -1
- package/dist/types/namespaces/array/methods/stdev.d.ts +2 -1
- package/dist/types/namespaces/array/methods/sum.d.ts +2 -1
- package/dist/types/namespaces/array/methods/unshift.d.ts +2 -1
- package/dist/types/namespaces/array/methods/variance.d.ts +2 -1
- package/dist/types/namespaces/array/utils.d.ts +5 -0
- package/dist/types/namespaces/input/methods/any.d.ts +1 -2
- package/dist/types/namespaces/input/methods/bool.d.ts +1 -2
- package/dist/types/namespaces/input/methods/color.d.ts +1 -2
- package/dist/types/namespaces/input/methods/enum.d.ts +1 -2
- package/dist/types/namespaces/input/methods/float.d.ts +1 -2
- package/dist/types/namespaces/input/methods/int.d.ts +1 -2
- package/dist/types/namespaces/input/methods/param.d.ts +1 -1
- package/dist/types/namespaces/input/methods/price.d.ts +1 -2
- package/dist/types/namespaces/input/methods/session.d.ts +1 -2
- package/dist/types/namespaces/input/methods/source.d.ts +1 -2
- package/dist/types/namespaces/input/methods/string.d.ts +1 -2
- package/dist/types/namespaces/input/methods/symbol.d.ts +1 -2
- package/dist/types/namespaces/input/methods/text_area.d.ts +1 -2
- package/dist/types/namespaces/input/methods/time.d.ts +1 -2
- package/dist/types/namespaces/input/methods/timeframe.d.ts +1 -2
- package/dist/types/namespaces/input/types.d.ts +12 -1
- package/dist/types/namespaces/input/utils.d.ts +14 -0
- package/dist/types/namespaces/map/PineMapObject.d.ts +26 -0
- package/dist/types/namespaces/map/map.index.d.ts +7 -0
- package/dist/types/namespaces/map/methods/clear.d.ts +3 -0
- package/dist/types/namespaces/map/methods/contains.d.ts +3 -0
- package/dist/types/namespaces/map/methods/copy.d.ts +3 -0
- package/dist/types/namespaces/map/methods/get.d.ts +3 -0
- package/dist/types/namespaces/map/methods/keys.d.ts +4 -0
- package/dist/types/namespaces/map/methods/new.d.ts +3 -0
- package/dist/types/namespaces/map/methods/param.d.ts +1 -0
- package/dist/types/namespaces/map/methods/put.d.ts +3 -0
- package/dist/types/namespaces/map/methods/put_all.d.ts +3 -0
- package/dist/types/namespaces/map/methods/remove.d.ts +3 -0
- package/dist/types/namespaces/map/methods/size.d.ts +3 -0
- package/dist/types/namespaces/map/methods/values.d.ts +4 -0
- package/dist/types/namespaces/math/math.index.d.ts +18 -0
- package/dist/types/namespaces/math/methods/abs.d.ts +2 -1
- package/dist/types/namespaces/math/methods/e.d.ts +5 -0
- package/dist/types/namespaces/math/methods/phi.d.ts +5 -0
- package/dist/types/namespaces/math/methods/pi.d.ts +5 -0
- package/dist/types/namespaces/math/methods/round_to_mintick.d.ts +2 -0
- package/dist/types/namespaces/math/methods/rphi.d.ts +5 -0
- package/dist/types/namespaces/math/methods/sign.d.ts +2 -0
- package/dist/types/namespaces/matrix/PineMatrixObject.d.ts +102 -0
- package/dist/types/namespaces/matrix/matrix.index.d.ts +7 -0
- package/dist/types/namespaces/matrix/methods/add_col.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/add_row.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/avg.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/col.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/columns.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/concat.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/copy.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/det.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/diff.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/eigenvalues.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/eigenvectors.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/elements_count.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/fill.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/get.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/inv.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_antidiagonal.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_antisymmetric.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_binary.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_diagonal.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_identity.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_square.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_stochastic.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_symmetric.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_triangular.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/is_zero.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/kron.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/max.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/median.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/min.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/mode.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/mult.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/new.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/param.d.ts +1 -0
- package/dist/types/namespaces/matrix/methods/pinv.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/pow.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/rank.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/remove_col.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/remove_row.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/reshape.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/reverse.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/row.d.ts +4 -0
- package/dist/types/namespaces/matrix/methods/rows.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/set.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/sort.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/submatrix.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/sum.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/swap_columns.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/swap_rows.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/trace.d.ts +3 -0
- package/dist/types/namespaces/matrix/methods/transpose.d.ts +3 -0
- package/dist/types/namespaces/request/methods/security_lower_tf.d.ts +9 -0
- package/dist/types/namespaces/request/request.index.d.ts +3 -0
- package/dist/types/namespaces/ta/methods/atr.d.ts +2 -1
- package/dist/types/namespaces/ta/methods/tr.d.ts +2 -1
- package/dist/types/transpiler/settings.d.ts +4 -0
- package/dist/types/types/PineTypes.d.ts +11 -0
- package/package.json +6 -4
package/dist/pinets.min.es.js
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
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
|
|
18
|
+
import*as St from"acorn";import*as et from"astring";import*as k from"acorn-walk";import*as Z from"fs";import*as nt from"path";import{fileURLToPath as Bt}from"url";var Dt=Object.defineProperty,Lt=(e,t,n)=>t in e?Dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,D=(e,t,n)=>Lt(e,typeof t!="symbol"?t+"":t,n);const Wt=new Set(["Infinity","NaN","undefined","null","true","false"]),Ot=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 Rt{constructor(){D(this,"scopes",[]),D(this,"scopeTypes",[]),D(this,"scopeCounts",new Map),D(this,"contextBoundVars",new Set),D(this,"arrayPatternElements",new Set),D(this,"rootParams",new Set),D(this,"localSeriesVars",new Set),D(this,"varKinds",new Map),D(this,"loopVars",new Set),D(this,"loopVarNames",new Map),D(this,"paramIdCounter",0),D(this,"cacheIdCounter",0),D(this,"tempVarCounter",0),D(this,"taCallIdCounter",0),D(this,"hoistingStack",[]),D(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 Wt.has(t)||Ot.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],s=this.scopeCounts.get(i)||1,a=`${i}${s}_${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),s=this.varKinds.get(i)||"let";return[i,s]}}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 T="$",_={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(T)},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}]}}},lt=["ta","math","request","array","input"],Ct=["open","high","low","close","volume","hl2","hlc3","ohlc4","openTime","closeTime"],Et=["input","ta","math","request","array","na","plotchar","color","plot","nz","strategy","library","str","box","line","label","table","map","matrix","log","map","timeframe","syminfo","barstate","bar_index","last_bar_index","last_bar_time","order","currency","display","dayofweek"],Ft=["na","nz","plot","plotchar","color"];function zt(e){let t=null,n=T;if(e.type==="Program"&&e.body.length>0){const h=e.body[0];if(h.type==="ExpressionStatement"&&(h.expression.type==="ArrowFunctionExpression"||h.expression.type==="FunctionExpression")){const d=h.expression;d.body.type==="BlockStatement"&&(t=d.body.body,d.params.length>0&&d.params[0].type==="Identifier"&&(n=d.params[0].name))}}if(!t)return;const r=new Set,i=new Set,s=h=>{h.type==="Identifier"?r.add(h.name):h.type==="ObjectPattern"?h.properties.forEach(d=>s(d.value)):h.type==="ArrayPattern"&&h.elements.forEach(d=>{d&&s(d)})};k.recursive(e,{},{VariableDeclarator(h,d,g){s(h.id),h.init&&g(h.init,d)},FunctionDeclaration(h,d,g){s(h.id),g(h.body,d)},Identifier(h,d,g){i.add(h.name)},MemberExpression(h,d,g){g(h.object,d),h.computed&&g(h.property,d)},Property(h,d,g){h.computed&&g(h.key,d),g(h.value,d)}}),t.forEach(h=>{h.type==="VariableDeclaration"?h.declarations.forEach(d=>s(d.id)):h.type==="FunctionDeclaration"&&s(h.id)});const a=Ct,o=Et,c=a.filter(h=>!r.has(h)),l=o.filter(h=>!r.has(h)),u=c.filter(h=>i.has(h)),p=l.filter(h=>i.has(h)),f=[];u.length>0&&f.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:u.map(h=>({type:"Property",key:{type:"Identifier",name:h},value:{type:"Identifier",name:h},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},property:{type:"Identifier",name:"data"},computed:!1}}]}),p.length>0&&f.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:p.map(h=>({type:"Property",key:{type:"Identifier",name:h},value:{type:"Identifier",name:h},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},property:{type:"Identifier",name:"pine"},computed:!1}}]}),f.length>0&&t.unshift(...f)}function Ht(e){let t=null,n=T;if(e.type==="Program"&&e.body.length>0){const o=e.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){const c=o.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(Ct),i=new Set(Et),s=new Set(Ft),a=new Map;t.forEach(o=>{o.type==="VariableDeclaration"&&o.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 l=c.init.property.name;let u=null;if(l==="data"?u=r:l==="pine"?u=i:l==="core"&&(u=s),u&&c.id.type==="ObjectPattern")c.id.properties.forEach(p=>{if(p.type==="Property"&&p.key.type==="Identifier"&&p.value.type==="Identifier"){const f=p.key.name,h=p.value.name;u.has(f)&&f!==h&&(a.set(h,f),p.value.name=f,p.shorthand=!0)}});else if(c.id.type==="Identifier"&<.includes(l)){const p=l,f=c.id.name;p!==f&&(a.set(f,p),c.id.name=p)}}})}),a.size>0&&k.recursive(e,{},{Identifier(o){a.has(o.name)&&(o.name=a.get(o.name))},MemberExpression(o,c,l){l(o.object,c),o.computed&&l(o.property,c)},Property(o,c,l){o.computed&&l(o.key,c),l(o.value,c)}})}function qt(e){try{const t=St.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 Ut(e){return e=e.trim(),qt(e)?e:`(context) => {
|
|
19
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
|
-
`):[],
|
|
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};
|
|
20
|
+
}`}function Gt(e){k.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 s={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,s)}}),t.body&&t.body.body&&t.body.body.forEach(i=>r(i,n))}})}function Kt(e,t){k.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===T||r.init.object.name==="context2"),s=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===T||r.init.object.object.name==="context2");(i||s)&&(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 Xt(e,t,n=!1){e.params.forEach(r=>{r.type==="Identifier"&&t.addContextBoundVar(r.name,n)})}function Yt(e,t){e.params.forEach(n=>{n.type==="Identifier"&&t.addContextBoundVar(n.name,!1)})}function Zt(e,t){let n;return k.simple(e,{FunctionDeclaration(r){Yt(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=T),Xt(r,t,i)},VariableDeclaration(r){r.declarations.forEach(i=>{if(i.id.type==="ArrayPattern"){const s=t.generateTempVar(),a={type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:s},init:i.init}]};i.id.elements?.forEach(c=>{c.type==="Identifier"&&t.addArrayPatternElement(c.name)});const o=i.id.elements.map((c,l)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:c,init:{type:"MemberExpression",object:{type:"Identifier",name:s},property:{type:"Literal",value:l},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[a,...o]})}})},ForStatement(r){}}),n}const ft={type:"Identifier",name:"undefined"};function X(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=_.createContextVariableReference(r,n),s=_.createGetCall(i,e.property);Object.assign(e,s),e._indexTransformed=!0}return}if(!t.isContextBound(e.property.name)){const[n,r]=t.getVariable(e.property.name);e.property=_.createContextVariableReference(r,n),e.property=_.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=_.createContextVariableReference(r,n)}if(e.property.type==="MemberExpression"){const n=e.property;n._indexTransformed||(X(n,t),n._indexTransformed=!0)}}}function U(e,t){const n=_.createGetCall(_.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 O(e,t){if(e.name!==T){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))return;let n=!1;if(e.parent&&e.parent.type==="CallExpression"&&e.parent.arguments.includes(e)){const f=e.parent.callee;if(f.type==="MemberExpression"&&f.object&&f.object.name===T&&["get","set","init","param"].includes(f.property.name))e.parent.arguments.indexOf(e)===0&&(n=!0);else{const h=f.type==="MemberExpression"&&f.object&&f.object.type==="Identifier"&<.includes(f.object.name);f.type==="MemberExpression"&&!h?n=!1:n=!0}}const r=e.parent&&e.parent.type==="MemberExpression"&&e.parent.object===e&&t.isContextBound(e.name),i=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;const s=e.parent&&e.parent.type==="CallExpression"&&e.parent.callee===e,a=e.parent&&e.parent.type==="MemberExpression"&&e.parent.computed&&e.parent.object===e,o=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);if(r||i||n||o||s){if(s||t.isLocalSeriesVar(e.name)||t.isContextBound(e.name)&&!t.isRootParam(e.name))return;const[f,h]=t.getVariable(e.name),d=_.createContextVariableReference(h,f);Object.assign(e,d);return}const c=t.isContextBound(e.name)&&!t.isRootParam(e.name);if(c&&!(e.parent&&e.parent.type==="CallExpression"&&e.parent.arguments.includes(e)))return;if(t.isLocalSeriesVar(e.name)){if(!a){const f=_.createIdentifier(e.name),h=_.createGetCall(f,0);Object.assign(e,h)}return}const[l,u]=t.getVariable(e.name);let p;if(c)p=_.createIdentifier(e.name);else{if(l===e.name&&!t.isContextBound(e.name))return;p=_.createContextVariableReference(u,l)}if(a)Object.assign(e,p);else{const f=_.createGetCall(p,0);Object.assign(e,f)}}}function z(e,t,n){if(e.object&&e.object.type==="Identifier"&&e.object.name==="Math")return;if(e.object&&e.object.type==="Identifier"&<.includes(e.object.name)&&n.isContextBound(e.object.name)&&!e.computed){const c=e.parent&&e.parent.type==="CallExpression"&&e.parent.callee===e,l=e.parent&&(e.parent.type==="VariableDeclarator"||e.parent.type==="Property"||e.parent.type==="AssignmentExpression");if(!c&&!l){const u={type:"CallExpression",callee:{type:"MemberExpression",object:e.object,property:e.property,computed:!1},arguments:[],_transformed:!1};e.start!==void 0&&(u.start=e.start),e.end!==void 0&&(u.end=e.end),Object.assign(e,u);return}}const r=n.getCurrentScopeType()=="if",i=n.getCurrentScopeType()=="els",s=n.getCurrentScopeType()=="for";if(!r&&!i&&!s&&e.object&&e.object.type==="Identifier"&&n.isContextBound(e.object.name)&&!n.isRootParam(e.object.name)&&!e.computed)return;e._indexTransformed||(X(e,n),e._indexTransformed=!0);const a=e.object&&e.object.type==="MemberExpression"&&e.object.object&&e.object.object.type==="MemberExpression"&&e.object.object.object&&e.object.object.object.name===T,o=e.object&&e.object.type==="Identifier"&&n.isContextBound(e.object.name);if(e.computed&&(a||o)){if(e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e)return;const c=_.createGetCall(e.object,e.property);e.start&&(c.start=e.start),e.end&&(c.end=e.end),Object.assign(e,c),delete e.object,delete e.property,delete e.computed}}function rt(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,s]=t.getVariable(e.name);return _.createContextVariableReference(s,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:_.createContextVariableReference(r,n)}return e}function K(e,t,n=""){switch(e.type){case"BinaryExpression":return It(e,t,n);case"MemberExpression":return{type:"MemberExpression",object:e.object.type==="Identifier"?rt(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=rt(e,t);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:_.createGetCall(r,0)}case"UnaryExpression":return Mt(e,t,n);case"ConditionalExpression":{const r=K(e.test,t,n),i=K(e.consequent,t,n),s=K(e.alternate,t,n);return{type:"ConditionalExpression",test:r,consequent:i,alternate:s,start:e.start,end:e.end}}}return e}function It(e,t,n){const r=K(e.left,t,n),i=K(e.right,t,n),s={type:"BinaryExpression",operator:e.operator,left:r,right:i,start:e.start,end:e.end};return k.recursive(s,t,{CallExpression(a,o){a._transformed||H(a,o)},MemberExpression(a){z(a,"",t)}}),s}function Jt(e,t,n){const r=K(e.left,t,n),i=K(e.right,t,n),s={type:"LogicalExpression",operator:e.operator,left:r,right:i,start:e.start,end:e.end};return k.recursive(s,t,{CallExpression(a,o){a._transformed||H(a,o)}}),s}function Qt(e,t,n){k.recursive(e,{parent:e,inNamespaceCall:!1},{Identifier(a,o,c){if(a.name=="NaN")return;if(a.name=="na"){a.name="NaN";return}a.parent=o.parent,O(a,t);const l=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||l)&&(a.type==="MemberExpression"?X(a,t):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===T&&a.parent.callee.property.name==="get"||U(a)))},MemberExpression(a,o,c){X(a,t),a.object&&c(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(a,o,c){const l={...o,parent:a};a.test&&c(a.test,l),a.consequent&&c(a.consequent,l),a.alternate&&c(a.alternate,l)},BinaryExpression(a,o,c){const l={...o,parent:a};c(a.left,l),c(a.right,l)},LogicalExpression(a,o,c){const l={...o,parent:a};c(a.left,l),c(a.right,l)},UnaryExpression(a,o,c){const l={...o,parent:a};c(a.argument,l)},CallExpression(a,o,c){const l=a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&a.callee.object.type==="Identifier"&&t.isContextBound(a.callee.object.name);H(a,t),a.arguments.forEach(u=>c(u,{parent:a,inNamespaceCall:l||o.inNamespaceCall}))}});const r=_.createMemberExpression(_.createIdentifier(n),_.createIdentifier("param")),i=t.generateParamId(),s={type:"CallExpression",callee:r,arguments:[e,ft,{type:"Identifier",name:`'${i}'`}],_transformed:!0,_isParamCall:!0};if(!t.shouldSuppressHoisting()){const a=i;t.addLocalSeriesVar(a);const o=_.createVariableDeclaration(a,s);return t.addHoistedStatement(o),_.createIdentifier(a)}return s}function Mt(e,t,n){const r=K(e.argument,t,n);return{type:"UnaryExpression",operator:e.operator,prefix:e.prefix,argument:r,start:e.start,end:e.end}}function _t(e,t,n){switch(e?.type){case"BinaryExpression":e=It(e,n,t);break;case"LogicalExpression":e=Jt(e,n,t);break;case"ConditionalExpression":return Qt(e,n,t);case"UnaryExpression":e=Mt(e,n,t);break;case"ArrayExpression":e.elements=e.elements.map(o=>{if(o.type==="Identifier"){if(n.isContextBound(o.name)&&!n.isRootParam(o.name))return o;const[c,l]=n.getVariable(o.name);return _.createContextVariableAccess0(l,c)}return o});break}if(e.type==="MemberExpression"&&e.computed&&e.property){const o=e.object.type==="Identifier"&&n.isContextBound(e.object.name)&&!n.isRootParam(e.object.name)?e.object:rt(e.object,n),c=e.property.type==="Identifier"&&!n.isContextBound(e.property.name)&&!n.isLoopVariable(e.property.name)?rt(e.property,n):e.property,l=_.createMemberExpression(_.createIdentifier(t),_.createIdentifier("param")),u=n.generateParamId(),p={type:"CallExpression",callee:l,arguments:[o,c,{type:"Identifier",name:`'${u}'`}],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){const f=u;n.addLocalSeriesVar(f);const h=_.createVariableDeclaration(f,p);return n.addHoistedStatement(h),_.createIdentifier(f)}return p}if(e.type==="ObjectExpression"&&(e.properties=e.properties.map(o=>{if(o.value.name){if(n.isContextBound(o.value.name)&&!n.isRootParam(o.value.name))return{type:"Property",key:{type:"Identifier",name:o.key.name},value:_.createIdentifier(o.value.name),kind:"init",method:!1,shorthand:!1,computed:!1};const[c,l]=n.getVariable(o.value.name);return{type:"Property",key:{type:"Identifier",name:o.key.name},value:_.createContextVariableReference(l,c),kind:"init",method:!1,shorthand:!1,computed:!1}}return o})),e.type==="Identifier"){if(e.name==="na")return e.name="NaN",e;if(n.isContextBound(e.name)&&!n.isRootParam(e.name)){const o=_.createMemberExpression(_.createIdentifier(t),_.createIdentifier("param")),c=n.generateParamId(),l={type:"CallExpression",callee:o,arguments:[e,ft,{type:"Identifier",name:`'${c}'`}],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){const u=c;n.addLocalSeriesVar(u);const p=_.createVariableDeclaration(u,l);return n.addHoistedStatement(p),_.createIdentifier(u)}return l}}e?.type==="CallExpression"&&H(e,n);const r=_.createMemberExpression(_.createIdentifier(t),_.createIdentifier("param")),i=e.type==="Identifier"?rt(e,n):e,s=n.generateParamId(),a={type:"CallExpression",callee:r,arguments:[i,ft,{type:"Identifier",name:`'${s}'`}],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){const o=s;n.addLocalSeriesVar(o);const c=_.createVariableDeclaration(o,a);return n.addHoistedStatement(c),_.createIdentifier(o)}return a}function H(e,t,n){if(e._transformed)return;e.callee&&e.callee.type==="Identifier"&<.includes(e.callee.name)&&t.isContextBound(e.callee.name)&&(e.callee=_.createMemberExpression(e.callee,_.createIdentifier("any")));const r=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(r){if(e.callee.object.name===T&&["get","init","param"].includes(e.callee.property.name))return;const i=e.callee.object.name,s=[];if(e.arguments.forEach(a=>{if(a._isParamCall){s.push(a);return}s.push(_t(a,i,t))}),e.arguments=s,i==="ta"&&e.arguments.push(t.getNextTACallId()),!t.shouldSuppressHoisting()){const a=t.generateTempVar();t.addLocalSeriesVar(a);const o=_.createVariableDeclaration(a,Object.assign({},e));t.addHoistedStatement(o),Object.assign(e,_.createIdentifier(a));return}e._transformed=!0}else e.callee&&e.callee.type==="Identifier"&&(e.arguments=e.arguments.map(i=>i._isParamCall?i:_t(i,T,t)),e._transformed=!0);!r&&e.callee&&e.callee.type==="MemberExpression"&&e.callee.object.type==="Identifier"&&O(e.callee.object,t),e.arguments.forEach(i=>{k.recursive(i,{parent:e},{Identifier(s,a,o){s.parent=a.parent,O(s,t);const c=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||c)&&(s.type==="MemberExpression"?X(s,t):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===T&&s.parent.callee.property.name==="get"||U(s)))},BinaryExpression(s,a,o){const c={...a,parent:s};o(s.left,c),o(s.right,c)},LogicalExpression(s,a,o){const c={...a,parent:s};o(s.left,c),o(s.right,c)},UnaryExpression(s,a,o){const c={...a,parent:s};o(s.argument,c)},CallExpression(s,a,o){s._transformed||H(s,t)},MemberExpression(s,a,o){z(s,"",t),s.object&&o(s.object,{parent:s})}})})}function $t(e,t){let n=null;if(e.left.type==="Identifier"){const[r,i]=t.getVariable(e.left.name);n=_.createContextVariableReference(i,r)}else if(e.left.type==="MemberExpression"&&e.left.computed&&e.left.object.type==="Identifier"){const r=e.left.object.name,[i,s]=t.getVariable(r),a=i!==r,o=t.isContextBound(r);(a||o)&&!t.isLoopVariable(r)&&e.left.property.type==="Literal"&&e.left.property.value===0&&(n=_.createContextVariableReference(s,i))}if(k.recursive(e.right,{parent:e.right,inNamespaceCall:!1},{Identifier(r,i,s){r.name=="na"&&(r.name="NaN"),r.parent=i.parent,O(r,t);const a=r.parent&&r.parent.type==="BinaryExpression",o=r.parent&&r.parent.type==="ConditionalExpression",c=t.isContextBound(r.name)&&!t.isRootParam(r.name),l=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.object===r,u=r.parent&&r.parent._isParamCall,p=r.parent&&r.parent.type==="MemberExpression",f=r.name==="NaN",h=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===T&&r.parent.callee.property.name==="get";(c||o||a)&&(r.type==="MemberExpression"?X(r,t):r.type==="Identifier"&&!p&&!l&&!u&&!f&&!h&&U(r))},MemberExpression(r,i,s){z(r,"",t),r.type==="CallExpression"?r.arguments.forEach(a=>s(a,{parent:r,inNamespaceCall:i.inNamespaceCall})):r.object&&s(r.object,{parent:r,inNamespaceCall:i.inNamespaceCall})},CallExpression(r,i,s){const a=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&t.isContextBound(r.callee.object.name);H(r,t),r.type==="CallExpression"&&r.arguments.forEach(o=>s(o,{parent:r,inNamespaceCall:a||i.inNamespaceCall}))}}),n){let r=e.right;if(e.operator!=="="){const s=e.operator.replace("=",""),a=_.createGetCall(n,0);r={type:"BinaryExpression",operator:s,left:a,right:e.right,start:e.start,end:e.end}}const i=_.createSetCall(n,r);e.start&&(i.start=e.start),e.end&&(i.end=e.end),Object.assign(e,i)}}function jt(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===T||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===T||n.init.object.object.name==="context2"),s=n.init&&n.init.type==="ArrowFunctionExpression";if(r){n.id.name&&t.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(h=>{h.key.name&&t.addContextBoundVar(h.key.name)}),n.init.object.name=T;return}if(i){n.id.name&&t.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(h=>{h.key.name&&t.addContextBoundVar(h.key.name)}),n.init.object.object.name=T;return}s&&n.init.params.forEach(h=>{h.type==="Identifier"&&t.addContextBoundVar(h.name)});const a=t.addVariable(n.id.name,e.kind),o=e.kind,c=t.isArrayPatternElement(n.id.name);n.init&&!s&&!c&&(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)?H(n.init,t):k.recursive(n.init,{parent:n.init},{Identifier(h,d){h.parent=d.parent,O(h,t);const g=h.parent&&h.parent.type==="BinaryExpression",y=h.parent&&h.parent.type==="UnaryExpression",w=h.parent&&h.parent.type==="ConditionalExpression",S=h.parent&&h.parent.type==="CallExpression"&&h.parent.callee&&h.parent.callee.object&&h.parent.callee.object.name===T&&h.parent.callee.property.name==="get";h.type==="Identifier"&&(g||y||w)&&!S&&U(h)},CallExpression(h,d,g){h.callee.type==="Identifier"&&(h.callee.parent=h),h.arguments.forEach(y=>{y.type==="Identifier"&&(y.parent=h)}),H(h,t),h.type==="CallExpression"&&h.arguments.forEach(y=>g(y,{parent:h}))},BinaryExpression(h,d,g){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),g(h.left,{parent:h}),g(h.right,{parent:h})},MemberExpression(h,d,g){h.object&&h.object.type==="Identifier"&&(h.object.parent=h),h.property&&h.property.type==="Identifier"&&(h.property.parent=h),z(h,"",t),h.type==="CallExpression"?h.arguments.forEach(y=>g(y,{parent:h})):h.object&&g(h.object,{parent:h})}}));const l=_.createContextVariableReference(o,a),u=!c&&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||(X(n.init.property,t),n.init.property._indexTransformed=!0));let p;n.init?s||c?p=n.init:o==="var"?p=_.createInitVarCall(l,n.init):p=_.createInitCall(l,u?n.init.object:n.init,u?n.init.property:void 0):p=_.createIdentifier("undefined");const f=_.createExpressionStatement(_.createAssignmentExpression(l,p));if(c){const h=n.init.object.name,[d,g]=t.getVariable(h),y=_.createContextVariableReference(g,d),w=n.init.property.value,S={type:"MemberExpression",object:_.createGetCall(y,0),property:{type:"Literal",value:w},computed:!0};f.expression.right=_.createCallExpression(_.createMemberExpression(_.createContextIdentifier(),_.createIdentifier("init")),[l,S])}s&&(t.pushScope("fn"),k.recursive(n.init.body,t,{BlockStatement(h,d,g){h.body.forEach(y=>g(y,d))},IfStatement(h,d,g){d.pushScope("if"),g(h.consequent,d),h.alternate&&(d.pushScope("els"),g(h.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(h,d){jt(h,d)},Identifier(h,d){O(h,d)},AssignmentExpression(h,d){$t(h,d)}}),t.popScope()),Object.assign(e,f)})}function te(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&&k.recursive(r.init,t,{Identifier(s,a){t.isLoopVariable(s.name)||(t.pushScope("for"),O(s,a),t.popScope())},MemberExpression(s){t.pushScope("for"),z(s,"",t),t.popScope()}})}e.test&&k.recursive(e.test,t,{Identifier(r,i){!t.isLoopVariable(r.name)&&!r.computed&&(t.pushScope("for"),O(r,i),r.type==="Identifier"&&(r.computed=!0,U(r)),t.popScope())},MemberExpression(r){t.pushScope("for"),z(r,"",t),t.popScope()}}),e.update&&k.recursive(e.update,t,{Identifier(r,i){t.isLoopVariable(r.name)||(t.pushScope("for"),O(r,i),t.popScope())}}),t.setSuppressHoisting(!1),t.pushScope("for"),n(e.body,t),t.popScope()}function ee(e,t){k.recursive(e,t,{MemberExpression(n){z(n,"",t)},CallExpression(n,r){H(n,r)},Identifier(n,r){O(n,r);const i=t.getCurrentScopeType()==="if";t.isContextBound(n.name)&&!t.isRootParam(n.name)&&i&&U(n)}})}function ne(e,t,n){e.test&&(t.pushScope("if"),ee(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 re(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 _.createGetCall(r,0);const[i,s]=t.getVariable(r.name);return _.createContextVariableAccess0(s,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)?_.createGetCall(r,0):(r.computed&&r.object.type==="Identifier"&&t.isContextBound(r.object.name)&&!t.isRootParam(r.object.name)||z(r,"",t),r);return r}),e.argument={type:"ArrayExpression",elements:[e.argument]}):e.argument.type==="BinaryExpression"?k.recursive(e.argument,t,{Identifier(r,i){O(r,i),r.type==="Identifier"&&U(r)},MemberExpression(r){z(r,"",t)}}):e.argument.type==="ObjectExpression"?e.argument.properties=e.argument.properties.map(r=>{if(r.shorthand){if(t.isContextBound(r.value.name))return r;const[i,s]=t.getVariable(r.value.name);return{type:"Property",key:_.createIdentifier(r.key.name),value:_.createContextVariableReference(s,i),kind:"init",method:!1,shorthand:!1,computed:!1}}if(r.value&&r.value.type==="Identifier"&&!(t.isContextBound(r.value.name)&&!t.isRootParam(r.value.name))&&!t.isContextBound(r.value.name)){const[i,s]=t.getVariable(r.value.name);r.value=_.createContextVariableReference(s,i)}return r}):e.argument.type==="Identifier"&&(O(e.argument,t),e.argument.type==="Identifier"&&U(e.argument)),n==="fn")){e.argument.type==="Identifier"&&t.isContextBound(e.argument.name)&&!t.isRootParam(e.argument.name)?e.argument=_.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||(X(e.argument,t),e.argument._indexTransformed=!0)):(e.argument.type==="BinaryExpression"||e.argument.type==="LogicalExpression"||e.argument.type==="ConditionalExpression"||e.argument.type==="CallExpression")&&k.recursive(e.argument,t,{Identifier(i,s){O(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(U(i),i._arrayAccessed=!0)},MemberExpression(i){z(i,"",t)},CallExpression(i,s){H(i,s)}});const r=_.createCallExpression(_.createMemberExpression(_.createContextIdentifier(),_.createIdentifier("precision")),[e.argument]);e.argument=r}}function ie(e,t,n){e.body&&e.body.type==="BlockStatement"&&(t.pushScope("fn"),n(e.body,t),t.popScope())}function ae(e){const t={...k.base,LineComment:()=>{}};k.simple(e,{BinaryExpression(n){if(n.operator==="=="||n.operator==="==="){const r=n.left,i=n.right,s=_.createMathEqCall(r,i);s._transformed=!0,Object.assign(n,s)}}},t)}function se(e,t,n,r={debug:!1,ln:!1},i=[]){const s=a=>{if(!r.debug||!a.loc||!i.length)return null;const o=a.loc.start.line-1;if(o>=0&&o<i.length){const c=i[o].trim();if(c)return{type:"LineComment",value:`${r.ln?` [Line ${a.loc.start.line}]`:""} ${c}`}}return null};k.recursive(e,t,{Program(a,o,c){const l=[];a.body.forEach(u=>{o.enterHoistingScope(),c(u,o);const p=o.exitHoistingScope(),f=s(u);f&&l.push(f),l.push(...p),l.push(u)}),a.body=l},BlockStatement(a,o,c){const l=[];a.body.forEach(u=>{o.enterHoistingScope(),c(u,o);const p=o.exitHoistingScope(),f=s(u);f&&l.push(f),l.push(...p),l.push(u)}),a.body=l},ReturnStatement(a,o){re(a,o)},VariableDeclaration(a,o){jt(a,o)},Identifier(a,o){O(a,o)},CallExpression(a,o){H(a,o)},MemberExpression(a,o){z(a,n,o)},AssignmentExpression(a,o){$t(a,o)},FunctionDeclaration(a,o,c){ie(a,o,c)},ForStatement(a,o,c){te(a,o,c)},IfStatement(a,o,c){ne(a,o,c)}})}function oe(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=Ut(r);const i=n?r.split(`
|
|
21
|
+
`):[],s=St.parse(r,{ecmaVersion:"latest",sourceType:"module",locations:n});Gt(s),Ht(s),zt(s);const a=new Rt;Kt(s,a);const o=Zt(s,a)||"";se(s,a,o,t,i),ae(s);const c=et.baseGenerator||et.GENERATOR||et.default&&et.default.BASE_GENERATOR,l=Object.assign({},c,{LineComment(p,f){f.write("//"+p.value)}}),u=et.generate(s,{generator:l,comments:n});return new Function("",`var _r = ${u}
|
|
22
|
+
; return _r;`)(this)}function ce(e){return t=>new $(t.array.map(n=>Math.abs(n)),t.type,e)}function le(e){return t=>{let n=0,r=0;for(const i of t.array){const s=Number(i);isNaN(s)||(r++,n+=(s-n)/r)}return r===0?NaN:e.precision(n)}}function ue(e){return(t,n)=>{const r=t.array;let i=0,s=r.length-1;for(;i<=s;){const a=Math.floor((i+s)/2),o=r[a];if(o===n)return a;o<n?i=a+1:s=a-1}return-1}}function he(e){return(t,n)=>{const r=t.array;let i=0,s=r.length;for(;i<s;){const a=Math.floor((i+s)/2);r[a]<n?i=a+1:s=a}return i<r.length&&r[i]===n?i:i-1}}function pe(e){return(t,n)=>{const r=t.array;let i=0,s=r.length;for(;i<s;){const a=Math.floor((i+s)/2);r[a]<=n?i=a+1:s=a}return i>0&&r[i-1]===n?i-1:i}}function me(e){return t=>{t.array.length=0}}function fe(e){return(t,n)=>(t.array.push(...n.array),t)}function de(e){return t=>new $([...t.array],t.type,e)}function ge(e){return(t,n,r=!0)=>{const i=t.array,s=n.array;if(i.length!==s.length)return NaN;let a=0,o=0,c=0;const l=[];for(let d=0;d<i.length;d++){const g=Number(i[d]),y=Number(s[d]);!isNaN(g)&&g!==null&&g!==void 0&&!isNaN(y)&&y!==null&&y!==void 0&&(a+=g,o+=y,c++,l.push(d))}if(c===0)return NaN;const u=a/c,p=o/c;let f=0;for(const d of l){const g=Number(i[d]),y=Number(s[d]);f+=(g-u)*(y-p)}const h=r?c:c-1;return h<=0?NaN:e.precision(f/h)}}function ye(e){return t=>t.array.every(n=>!isNaN(n)&&n)}function _e(e){if(e.every(t=>typeof t=="number"))return e.every(t=>(t|0)===t)?A.int:A.float;if(e.every(t=>typeof t=="string"))return A.string;if(e.every(t=>typeof t=="boolean"))return A.bool;throw new Error("Cannot infer type from values")}function q(e){if(typeof e=="number")return(e|0)===e?A.int:A.float;if(typeof e=="string")return A.string;if(typeof e=="boolean")return A.bool;throw new Error("Cannot infer type from value")}function it(e,t){switch(t){case A.int:return typeof e=="number"&&(e|0)===e||isNaN(e);case A.float:return typeof e=="number"||isNaN(e);case A.string:return typeof e=="string";case A.bool:return typeof e=="boolean"}return!1}function xe(e){return(t,n,r=0,i)=>{const s=t.array.length,a=i!==void 0?Math.min(i,s):s;for(let o=r;o<a;o++){if(!it(n,t.type))throw new Error(`Cannot call 'array.fill' with argument 'value'='${n}'. An argument of 'literal ${typeof n}' type was used but a '${t.type}' is expected.`);t.array[o]=e.precision(n)}}}function Ne(e){return t=>t.array.length>0?t.array[0]:e.NA}function we(e){return(t,n)=>t.array[n]}function be(e){return(t,n)=>t.array.includes(n)}function ve(e){return(t,n)=>t.array.indexOf(n)}function Se(e){return(t,n,r)=>{if(!it(r,t.type))throw new Error(`Cannot call 'array.insert' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${t.type}' is expected.`);t.array.splice(n,0,r)}}function Ce(e){return(t,n=",")=>t.array.join(n)}function Ee(e){return t=>t.array.length>0?t.array[t.array.length-1]:e.NA}function Ie(e){return(t,n)=>t.array.lastIndexOf(n)}function Me(e){return(t,n=0)=>[...t.array].sort((r,i)=>i-r)[n]??e.NA}function $e(e){return t=>{if(t.array.length===0)return NaN;const n=[...t.array].sort((i,s)=>typeof i=="number"&&typeof s=="number"?i-s:0),r=Math.floor(n.length/2);return n.length%2!==0?n[r]:(n[r-1]+n[r])/2}}function je(e){return(t,n=0)=>[...t.array].sort((r,i)=>r-i)[n]??e.NA}function Ae(e){return t=>{if(t.array.length===0)return NaN;const n=new Map;let r=0;for(const s of t.array){const a=(n.get(s)||0)+1;n.set(s,a),a>r&&(r=a)}const i=[];for(const[s,a]of n)a===r&&i.push(s);return i.sort((s,a)=>typeof s=="number"&&typeof a=="number"?s-a:typeof s=="string"&&typeof a=="string"?s<a?-1:s>a?1:0:0),i[0]}}function ke(e){return(t,n)=>{const r=t.array;if(r.length===0)return NaN;const i=[];for(const c of r){const l=Number(c);if(isNaN(l)||l===null||l===void 0)return NaN;i.push(l)}i.sort((c,l)=>c-l),n<0&&(n=0),n>100&&(n=100);const s=n/100*i.length-.5;if(s<=0)return e.precision(i[0]);if(s>=i.length-1)return e.precision(i[i.length-1]);const a=Math.floor(s),o=s-a;return e.precision(i[a]*(1-o)+i[a+1]*o)}}function Te(e){return(t,n)=>{const r=t.array;if(r.length===0)return NaN;const i=[];for(const o of r){const c=Number(o);!isNaN(c)&&c!==null&&c!==void 0&&i.push(c)}if(i.length===0)return NaN;i.sort((o,c)=>o-c),n<0&&(n=0),n>100&&(n=100);const s=r.length,a=Math.ceil(n/100*s);return a<=0?i[0]:a>i.length?NaN:i[a-1]}}function Ve(e){return(t,n)=>{if(t.array.length===0)return NaN;const r=Math.floor(n);if(r<0||r>=t.array.length)return NaN;const i=Number(t.array[r]);if(isNaN(i)||i===null||i===void 0)return NaN;let s=0;for(const o of t.array){const c=Number(o);!isNaN(c)&&c!==null&&c!==void 0&&c<i&&s++}const a=t.array.length-1;return a<=0?NaN:s/a*100}}function Pe(e){return t=>t.array.pop()}function Be(e){return(t,n)=>{if(!it(n,t.type))throw new Error(`Cannot call 'array.push' with argument 'value'='${n}'. An argument of 'literal ${typeof n}' type was used but a '${t.type}' is expected.`);t.array.push(e.precision(n))}}function De(e){return t=>e.precision(e.pine.array.max(t)-e.pine.array.min(t))}function Le(e){return(t,n)=>n>=0&&n<t.array.length?t.array.splice(n,1)[0]:e.NA}function We(e){return t=>{t.array.reverse()}}function Oe(e){return(t,n,r)=>{if(!it(r,t.type))throw new Error(`Cannot call 'array.set' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${t.type}' is expected.`);t.array[n]=e.precision(r)}}function Re(e){return t=>t.array.shift()}function Fe(e){return t=>t.array.length}function ze(e){return(t,n,r)=>{const i=r!==void 0?r:void 0;return new $(t.array.slice(n,i),t.type,e)}}function He(e){return t=>t.array.some(n=>!isNaN(n)&&n)}var J=(e=>(e[e.ascending=1]="ascending",e[e.descending=0]="descending",e))(J||{}),At=(e=>(e.AED="AED",e.ARS="ARS",e.AUD="AUD",e.BDT="BDT",e.BHD="BHD",e.BRL="BRL",e.BTC="BTC",e.CAD="CAD",e.CHF="CHF",e.CLP="CLP",e.CNY="CNY",e.COP="COP",e.CZK="CZK",e.DKK="DKK",e.EGP="EGP",e.ETH="ETH",e.EUR="EUR",e.GBP="GBP",e.HKD="HKD",e.HUF="HUF",e.IDR="IDR",e.ILS="ILS",e.INR="INR",e.ISK="ISK",e.JPY="JPY",e.KES="KES",e.KRW="KRW",e.KWD="KWD",e.LKR="LKR",e.MAD="MAD",e.MXN="MXN",e.MYR="MYR",e.NGN="NGN",e.NOK="NOK",e.NONE="NONE",e.NZD="NZD",e.PEN="PEN",e.PHP="PHP",e.PKR="PKR",e.PLN="PLN",e.QAR="QAR",e.RON="RON",e.RSD="RSD",e.RUB="RUB",e.SAR="SAR",e.SEK="SEK",e.SGD="SGD",e.THB="THB",e.TND="TND",e.TRY="TRY",e.TWD="TWD",e.USD="USD",e.USDT="USDT",e.VES="VES",e.VND="VND",e.ZAR="ZAR",e))(At||{}),kt=(e=>(e[e.sunday=1]="sunday",e[e.monday=2]="monday",e[e.tuesday=3]="tuesday",e[e.wednesday=4]="wednesday",e[e.thursday=5]="thursday",e[e.friday=6]="friday",e[e.saturday=7]="saturday",e))(kt||{}),qe=(e=>(e.all="all",e.data_window="data_window",e.none="none",e.pane="pane",e.pine_screener="pine_screener",e.price_scale="price_scale",e.status_line="status_line",e))(qe||{});const Ue={order:J,currency:At,dayofweek:kt};function Ge(e){return(t,n=J.ascending)=>{t.array.sort((r,i)=>{let s=isNaN(r)?1/0:r,a=isNaN(i)?1/0:i;return n===J.ascending?s-a:a-s})}}function Ke(e){return(t,n=J.ascending)=>{const r=t.array.map((i,s)=>s);return r.sort((i,s)=>{const a=isNaN(t.array[i])?1/0:t.array[i],o=isNaN(t.array[s])?1/0:t.array[s];return n===J.ascending?a-o:o-a}),new $(r,A.int,e)}}function Xe(e){return t=>{const n=e.array.avg(t),r=e.array.stdev(t);return isNaN(r)?new $(t.array.map(()=>NaN),A.int,e):r===0?new $(t.array.map(()=>1),A.int,e):new $(t.array.map(i=>(i-n)/r),A.int,e)}}function Ye(e){return(t,n=!0)=>{const r=t.array,i=r.length;if(i===0)return NaN;let s=0,a=0,o=0;for(let u=0;u<i;u++){const p=Number(r[u]);!isNaN(p)&&p!==null&&p!==void 0&&(s+=p,a+=p*p,o++)}if(o===0)return NaN;const c=s/o;let l=a/o-c*c;return l<0?NaN:(!n&&o>1&&(l=l*o/(o-1)),!n&&o===1?0:e.precision(Math.sqrt(l)))}}function Ze(e){return t=>e.precision(t.array.reduce((n,r)=>{const i=Number(r);return isNaN(i)?n:n+i},0))}function Je(e){return(t,n)=>{if(!it(n,t.type))throw new Error(`Cannot call 'array.unshift' with argument 'value'='${n}'. An argument of 'literal ${typeof n}' type was used but a '${t.type}' is expected.`);t.array.unshift(e.precision(n))}}function Qe(e){return(t,n=!0)=>{let r=0,i=0;for(const c of t.array){const l=Number(c);!isNaN(l)&&l!==null&&l!==void 0&&(r+=l,i++)}if(i===0)return NaN;const s=r/i;let a=0;for(const c of t.array){const l=Number(c);!isNaN(l)&&l!==null&&l!==void 0&&(a+=(l-s)*(l-s))}const o=n?i:i-1;return o<=0?NaN:e.precision(a/o)}}var tn=Object.defineProperty,en=(e,t,n)=>t in e?tn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,E=(e,t,n)=>en(e,typeof t!="symbol"?t+"":t,n),A=(e=>(e.any="",e.box="box",e.bool="bool",e.color="color",e.float="float",e.int="int",e.label="label",e.line="line",e.linefill="linefill",e.string="string",e.table="table",e))(A||{});class ${constructor(t,n,r){this.array=t,this.type=n,this.context=r,E(this,"_abs"),E(this,"_avg"),E(this,"_binary_search"),E(this,"_binary_search_leftmost"),E(this,"_binary_search_rightmost"),E(this,"_clear"),E(this,"_concat"),E(this,"_copy"),E(this,"_covariance"),E(this,"_every"),E(this,"_fill"),E(this,"_first"),E(this,"_get"),E(this,"_includes"),E(this,"_indexof"),E(this,"_insert"),E(this,"_join"),E(this,"_last"),E(this,"_lastindexof"),E(this,"_max"),E(this,"_median"),E(this,"_min"),E(this,"_mode"),E(this,"_percentile_linear_interpolation"),E(this,"_percentile_nearest_rank"),E(this,"_percentrank"),E(this,"_pop"),E(this,"_push"),E(this,"_range"),E(this,"_remove"),E(this,"_reverse"),E(this,"_set"),E(this,"_shift"),E(this,"_size"),E(this,"_slice"),E(this,"_some"),E(this,"_sort"),E(this,"_sort_indices"),E(this,"_standardize"),E(this,"_stdev"),E(this,"_sum"),E(this,"_unshift"),E(this,"_variance"),this._abs=ce(this.context),this._avg=le(this.context),this._binary_search=ue(this.context),this._binary_search_leftmost=he(this.context),this._binary_search_rightmost=pe(this.context),this._clear=me(this.context),this._concat=fe(this.context),this._copy=de(this.context),this._covariance=ge(this.context),this._every=ye(this.context),this._fill=xe(this.context),this._first=Ne(this.context),this._get=we(this.context),this._includes=be(this.context),this._indexof=ve(this.context),this._insert=Se(this.context),this._join=Ce(this.context),this._last=Ee(this.context),this._lastindexof=Ie(this.context),this._max=Me(this.context),this._median=$e(this.context),this._min=je(this.context),this._mode=Ae(this.context),this._percentile_linear_interpolation=ke(this.context),this._percentile_nearest_rank=Te(this.context),this._percentrank=Ve(this.context),this._pop=Pe(this.context),this._push=Be(this.context),this._range=De(this.context),this._remove=Le(this.context),this._reverse=We(this.context),this._set=Oe(this.context),this._shift=Re(this.context),this._size=Fe(this.context),this._slice=ze(this.context),this._some=He(this.context),this._sort=Ge(this.context),this._sort_indices=Ke(this.context),this._standardize=Xe(this.context),this._stdev=Ye(this.context),this._sum=Ze(this.context),this._unshift=Je(this.context),this._variance=Qe(this.context)}toString(){return"["+this.array.toString().replace(/,/g,", ")+"]"}abs(...t){return this._abs(this,...t)}avg(...t){return this._avg(this,...t)}binary_search(...t){return this._binary_search(this,...t)}binary_search_leftmost(...t){return this._binary_search_leftmost(this,...t)}binary_search_rightmost(...t){return this._binary_search_rightmost(this,...t)}clear(...t){return this._clear(this,...t)}concat(...t){return this._concat(this,...t)}copy(...t){return this._copy(this,...t)}covariance(...t){return this._covariance(this,...t)}every(...t){return this._every(this,...t)}fill(...t){return this._fill(this,...t)}first(...t){return this._first(this,...t)}get(...t){return this._get(this,...t)}includes(...t){return this._includes(this,...t)}indexof(...t){return this._indexof(this,...t)}insert(...t){return this._insert(this,...t)}join(...t){return this._join(this,...t)}last(...t){return this._last(this,...t)}lastindexof(...t){return this._lastindexof(this,...t)}max(...t){return this._max(this,...t)}median(...t){return this._median(this,...t)}min(...t){return this._min(this,...t)}mode(...t){return this._mode(this,...t)}percentile_linear_interpolation(...t){return this._percentile_linear_interpolation(this,...t)}percentile_nearest_rank(...t){return this._percentile_nearest_rank(this,...t)}percentrank(...t){return this._percentrank(this,...t)}pop(...t){return this._pop(this,...t)}push(...t){return this._push(this,...t)}range(...t){return this._range(this,...t)}remove(...t){return this._remove(this,...t)}reverse(...t){return this._reverse(this,...t)}set(...t){return this._set(this,...t)}shift(...t){return this._shift(this,...t)}size(...t){return this._size(this,...t)}slice(...t){return this._slice(this,...t)}some(...t){return this._some(this,...t)}sort(...t){return this._sort(this,...t)}sort_indices(...t){return this._sort_indices(this,...t)}standardize(...t){return this._standardize(this,...t)}stdev(...t){return this._stdev(this,...t)}sum(...t){return this._sum(this,...t)}unshift(...t){return this._unshift(this,...t)}variance(...t){return this._variance(this,...t)}}function nn(e){return(...t)=>new $([...t],_e(t),e)}function rn(e){return(t,n)=>new $(Array(t).fill(e.precision(n||0)),q(n||0),e)}function an(e){return(t,n=!1)=>new $(Array(t).fill(n),A.bool,e)}function sn(e){return(t,n=NaN)=>new $(Array(t).fill(e.precision(n)),A.float,e)}function on(e){return(t,n=0)=>new $(Array(t).fill(e.precision(n)),A.int,e)}function cn(e){return(t,n="")=>new $(Array(t).fill(n),A.string,e)}class m{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 m?t:Array.isArray(t)?new m(t):new m([t])}}function ln(e){return(t,n=0)=>m.from(t).get(n)}class un{constructor(t){this.context=t,this.abs=(n,...r)=>n.abs(...r),this.avg=(n,...r)=>n.avg(...r),this.binary_search=(n,...r)=>n.binary_search(...r),this.binary_search_leftmost=(n,...r)=>n.binary_search_leftmost(...r),this.binary_search_rightmost=(n,...r)=>n.binary_search_rightmost(...r),this.clear=(n,...r)=>n.clear(...r),this.concat=(n,...r)=>n.concat(...r),this.copy=(n,...r)=>n.copy(...r),this.covariance=(n,...r)=>n.covariance(...r),this.every=(n,...r)=>n.every(...r),this.fill=(n,...r)=>n.fill(...r),this.first=(n,...r)=>n.first(...r),this.from=nn(t),this.get=(n,...r)=>n.get(...r),this.includes=(n,...r)=>n.includes(...r),this.indexof=(n,...r)=>n.indexof(...r),this.insert=(n,...r)=>n.insert(...r),this.join=(n,...r)=>n.join(...r),this.last=(n,...r)=>n.last(...r),this.lastindexof=(n,...r)=>n.lastindexof(...r),this.max=(n,...r)=>n.max(...r),this.median=(n,...r)=>n.median(...r),this.min=(n,...r)=>n.min(...r),this.mode=(n,...r)=>n.mode(...r),this.new=rn(t),this.new_bool=an(t),this.new_float=sn(t),this.new_int=on(t),this.new_string=cn(t),this.param=ln(),this.percentile_linear_interpolation=(n,...r)=>n.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(n,...r)=>n.percentile_nearest_rank(...r),this.percentrank=(n,...r)=>n.percentrank(...r),this.pop=(n,...r)=>n.pop(...r),this.push=(n,...r)=>n.push(...r),this.range=(n,...r)=>n.range(...r),this.remove=(n,...r)=>n.remove(...r),this.reverse=(n,...r)=>n.reverse(...r),this.set=(n,...r)=>n.set(...r),this.shift=(n,...r)=>n.shift(...r),this.size=(n,...r)=>n.size(...r),this.slice=(n,...r)=>n.slice(...r),this.some=(n,...r)=>n.some(...r),this.sort=(n,...r)=>n.sort(...r),this.sort_indices=(n,...r)=>n.sort_indices(...r),this.standardize=(n,...r)=>n.standardize(...r),this.stdev=(n,...r)=>n.stdev(...r),this.sum=(n,...r)=>n.sum(...r),this.unshift=(n,...r)=>n.unshift(...r),this.variance=(n,...r)=>n.variance(...r)}}function hn(e){return t=>{t.map.clear()}}function pn(e){return(t,n)=>t.map.has(n)}function mn(e){return t=>{const n=new Tt(e);return n.map=new Map(t.map),n}}function fn(e){return(t,n)=>{const r=t.map.get(n);return r===void 0?NaN:r}}function dn(e){return t=>{const n=Array.from(t.map.keys()),r=q(n[0]);return new $(n,r,e)}}function gn(e){return(t,n,r)=>{const i=t.map.get(n);return t.map.set(n,r),i===void 0?NaN:i}}function yn(e){return(t,n)=>{for(const[r,i]of n.map)t.map.set(r,i)}}function _n(e){return(t,n)=>{const r=t.map.get(n);return t.map.delete(n)?r:NaN}}function xn(e){return t=>t.map.size}function Nn(e){return t=>{const n=Array.from(t.map.values()),r=q(n[0]);return new $(n,r,e)}}var wn=Object.defineProperty,bn=(e,t,n)=>t in e?wn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,F=(e,t,n)=>bn(e,typeof t!="symbol"?t+"":t,n);class Tt{constructor(t){this.context=t,F(this,"map"),F(this,"_clear"),F(this,"_contains"),F(this,"_copy"),F(this,"_get"),F(this,"_keys"),F(this,"_put"),F(this,"_put_all"),F(this,"_remove"),F(this,"_size"),F(this,"_values"),this.map=new Map,this._clear=hn(this.context),this._contains=pn(this.context),this._copy=mn(this.context),this._get=fn(this.context),this._keys=dn(this.context),this._put=gn(this.context),this._put_all=yn(this.context),this._remove=_n(this.context),this._size=xn(this.context),this._values=Nn(this.context)}toString(){return`PineMapObject(${this.map.size})`}clear(...t){return this._clear(this,...t)}contains(...t){return this._contains(this,...t)}copy(...t){return this._copy(this,...t)}get(...t){return this._get(this,...t)}keys(...t){return this._keys(this,...t)}put(...t){return this._put(this,...t)}put_all(...t){return this._put_all(this,...t)}remove(...t){return this._remove(this,...t)}size(...t){return this._size(this,...t)}values(...t){return this._values(this,...t)}}function vn(e){return()=>new Tt(e)}function Sn(e){return(t,n=0)=>m.from(t).get(n)}class Cn{constructor(t){this.context=t,this.clear=(n,...r)=>n.clear(...r),this.contains=(n,...r)=>n.contains(...r),this.copy=(n,...r)=>n.copy(...r),this.get=(n,...r)=>n.get(...r),this.keys=(n,...r)=>n.keys(...r),this.new=vn(t),this.param=Sn(),this.put=(n,...r)=>n.put(...r),this.put_all=(n,...r)=>n.put_all(...r),this.remove=(n,...r)=>n.remove(...r),this.size=(n,...r)=>n.size(...r),this.values=(n,...r)=>n.values(...r)}}function En(e){return(t,n,r)=>{const i=t.matrix.length;let s=[];if(r&&(r instanceof $?s=r.array:Array.isArray(r)?s=r:s=[r]),i===0){for(let c=0;c<s.length;c++){let l=s[c];l instanceof m&&(l=l.get(0)),t.matrix.push([l])}return}const a=t.matrix[0].length,o=n!==void 0?n:a;for(let c=0;c<i;c++){let l=c<s.length?s[c]:NaN;l instanceof m&&(l=l.get(0)),t.matrix[c].splice(o,0,l)}}}function In(e){return(t,n,r)=>{const i=t.matrix.length;let s=[];if(r)if(r instanceof $)s=r.array;else if(Array.isArray(r))s=r;else if(r instanceof m){const l=r.get(0);Array.isArray(l)?s=l:s=[l]}else s=[r];const a=i>0?t.matrix[0].length:s.length,o=n!==void 0?n:i,c=[];for(let l=0;l<a;l++)if(l<s.length){let u=s[l];u instanceof m&&(u=u.get(0)),c.push(u)}else c.push(NaN);t.matrix.splice(o,0,c)}}function Mn(e){return t=>{const n=t.matrix.length;if(n===0)return NaN;const r=t.matrix[0].length;if(r===0)return NaN;let i=0,s=0;for(let a=0;a<n;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||(i+=c,s++)}return s===0?NaN:i/s}}function $n(e){return(t,n)=>{const r=t.matrix.length,i=[];for(let a=0;a<r;a++)i.push(t.matrix[a][n]);const s=q(i[0]);return new $(i,s,e)}}function jn(e){return t=>t.matrix.length===0?0:t.matrix[0].length}function An(e){return(t,n)=>{const r=t.matrix.length,i=n.matrix.length;if(r===0){for(let o=0;o<i;o++)t.matrix.push([...n.matrix[o]]);return}const s=t.matrix[0].length,a=i>0?n.matrix[0].length:0;if(s!==a&&i>0){console.error(`matrix.concat: Column count mismatch ${s} vs ${a}`);return}for(let o=0;o<i;o++)t.matrix.push([...n.matrix[o]])}}function kn(e){return t=>{const n=t.matrix.length,r=n>0?t.matrix[0].length:0,i=new M(n,r,NaN,e);return i.matrix=t.matrix.map(s=>[...s]),i}}function Tn(e){const t=e.length;if(t===0)return 0;if(t===1)return e[0][0];if(t===2)return e[0][0]*e[1][1]-e[0][1]*e[1][0];const n=e.map(i=>[...i]);let r=1;for(let i=0;i<t;i++){let s=i;for(;s<t&&n[s][i]===0;)s++;if(s===t)return 0;s!==i&&([n[i],n[s]]=[n[s],n[i]],r*=-1),r*=n[i][i];for(let a=i+1;a<t;a++){const o=n[a][i]/n[i][i];for(let c=i;c<t;c++)n[a][c]-=o*n[i][c]}}return r}function Vn(e){return t=>{const n=t.matrix.length,r=n>0?t.matrix[0].length:0;return n!==r?NaN:Tn(t.matrix)}}function Pn(e){return(t,n)=>{const r=t.matrix.length;if(r===0)return new M(0,0,NaN,e);const i=t.matrix[0].length,s=new M(r,i,NaN,e);if(n instanceof M)for(let a=0;a<r;a++)for(let o=0;o<i;o++){const c=t.matrix[a][o],l=n.matrix[a]&&n.matrix[a][o]!==void 0?n.matrix[a][o]:NaN;s.matrix[a][o]=c-l}else{const a=n;for(let o=0;o<r;o++)for(let c=0;c<i;c++)s.matrix[o][c]=t.matrix[o][c]-a}return s}}function Bn(e){const t=e.length;if(t!==2)return Array(t).fill(NaN);const n=e[0][0],r=e[0][1],i=e[1][0],s=e[1][1],a=n+s,o=n*s-r*i,c=a*a-4*o;if(c<0)return[NaN,NaN];const l=(a+Math.sqrt(c))/2,u=(a-Math.sqrt(c))/2;return[l,u]}function Dn(e){return t=>{const n=t.matrix.length,r=n>0?t.matrix[0].length:0;if(n!==r){const a=q(t.matrix[0][0]);return new $([],a,e)}const i=Bn(t.matrix),s=q(i[0]);return new $(i,s,e)}}function Ln(e){return t=>{const n=t.matrix.length,r=n>0?t.matrix[0].length:0;if(n!==r)return new M(0,0,NaN,e);const i=new M(n,r,0,e);for(let s=0;s<n;s++)i.matrix[s][s]=1;return i}}function Wn(e){return t=>{const n=t.matrix.length;return n===0?0:n*t.matrix[0].length}}function On(e){return(t,n,r,i,s,a)=>{const o=t.matrix.length;if(o===0)return;const c=t.matrix[0].length,l=r!==void 0?r:0,u=i!==void 0?i:o,p=s!==void 0?s:0,f=a!==void 0?a:c;for(let h=l;h<u&&!(h>=o);h++)for(let d=p;d<f&&!(d>=c);d++)t.matrix[h][d]=n}}function Rn(e){return(t,n,r)=>{if(!t.matrix[n])return NaN;const i=t.matrix[n][r];return i===void 0?NaN:i}}function Fn(e){if(e.length!==2)return e.map(n=>n.map(()=>NaN));const t=e[0][0]*e[1][1]-e[0][1]*e[1][0];return t===0?[[NaN,NaN],[NaN,NaN]]:[[e[1][1]/t,-e[0][1]/t],[-e[1][0]/t,e[0][0]/t]]}function zn(e){return t=>{const n=t.matrix.length,r=n>0?t.matrix[0].length:0;if(n!==r)return new M(n,r,NaN,e);const i=Fn(t.matrix),s=new M(n,r,NaN,e);return s.matrix=i,s}}function Hn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i+s!==n-1&&t.matrix[i][s]!==0)return!1;return!0}}function qn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(t.matrix[s][i]!==-t.matrix[i][s])return!1;return!0}}function Un(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;for(let i=0;i<n;i++)for(let s=0;s<r;s++){const a=t.matrix[i][s];if(a!==0&&a!==1)return!1}return!0}}function Gn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i!==s&&t.matrix[i][s]!==0)return!1;return!0}}function Kn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i===s){if(t.matrix[i][s]!==1)return!1}else if(t.matrix[i][s]!==0)return!1;return!0}}function Xn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;return n===r}}function Yn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;for(let i=0;i<n;i++){let s=0;for(let a=0;a<r;a++){const o=t.matrix[i][a];if(o<0)return!1;s+=o}if(Math.abs(s-1)>1e-10)return!1}return!0}}function Zn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<i;s++)if(t.matrix[i][s]!==t.matrix[s][i])return!1;return!0}}function Jn(e){return t=>{const n=t.matrix.length;if(n===0)return!1;const r=t.matrix[0].length;if(n!==r)return!1;let i=!0,s=!0;for(let a=0;a<n;a++)for(let o=0;o<r;o++)a>o&&t.matrix[a][o]!==0&&(i=!1),a<o&&t.matrix[a][o]!==0&&(s=!1);return i||s}}function Qn(e){return t=>{const n=t.matrix.length;if(n===0)return!0;const r=t.matrix[0].length;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(t.matrix[i][s]!==0)return!1;return!0}}function tr(e){return(t,n)=>{const r=t.matrix.length,i=r>0?t.matrix[0].length:0,s=n.matrix.length,a=s>0?n.matrix[0].length:0,o=r*s,c=i*a,l=new M(o,c,NaN,e);for(let u=0;u<r;u++)for(let p=0;p<i;p++){const f=t.matrix[u][p];for(let h=0;h<s;h++)for(let d=0;d<a;d++){const g=n.matrix[h][d];l.matrix[u*s+h][p*a+d]=f*g}}return l}}function er(e){return t=>{const n=t.matrix.length;if(n===0)return NaN;const r=t.matrix[0].length;let i=-1/0,s=!1;for(let a=0;a<n;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||(c>i&&(i=c),s=!0)}return s?i:NaN}}function nr(e){return t=>{const n=t.matrix.length;if(n===0)return NaN;const r=t.matrix[0].length,i=[];for(let a=0;a<n;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||i.push(c)}if(i.length===0)return NaN;i.sort((a,o)=>a-o);const s=Math.floor(i.length/2);return i.length%2!==0?i[s]:(i[s-1]+i[s])/2}}function rr(e){return t=>{const n=t.matrix.length;if(n===0)return NaN;const r=t.matrix[0].length;let i=1/0,s=!1;for(let a=0;a<n;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||(c<i&&(i=c),s=!0)}return s?i:NaN}}function ir(e){return t=>{const n=t.matrix.length;if(n===0)return NaN;const r=t.matrix[0].length,i=new Map;let s=0,a=NaN;for(let o=0;o<n;o++)for(let c=0;c<r;c++){const l=t.matrix[o][c];if(!isNaN(l)){const u=(i.get(l)||0)+1;i.set(l,u),u>s?(s=u,a=l):u===s&&l<a&&(a=l)}}return a}}function ar(e){return(t,n)=>{const r=t.matrix.length,i=r>0?t.matrix[0].length:0;if(n instanceof M){const s=n.matrix.length,a=s>0?n.matrix[0].length:0;if(i!==s)return new M(0,0,NaN,e);const o=new M(r,a,0,e);for(let c=0;c<r;c++)for(let l=0;l<a;l++){let u=0;for(let p=0;p<i;p++)u+=t.matrix[c][p]*n.matrix[p][l];o.matrix[c][l]=u}return o}else if(n instanceof $||Array.isArray(n.array||n)){const s=n.array||n;if(i!==s.length)return new M(0,0,NaN,e);const a=new M(r,1,0,e);for(let o=0;o<r;o++){let c=0;for(let l=0;l<i;l++)c+=t.matrix[o][l]*s[l];a.matrix[o][0]=c}return a}else{const s=n,a=new M(r,i,NaN,e);for(let o=0;o<r;o++)for(let c=0;c<i;c++)a.matrix[o][c]=t.matrix[o][c]*s;return a}}}function sr(e){return t=>{const n=t.matrix.length,r=n>0?t.matrix[0].length:0;return n===r?new M(n,r,NaN,e):new M(r,n,NaN,e)}}function or(e){return(t,n)=>{const r=t.matrix.length,i=r>0?t.matrix[0].length:0;if(r!==i)return new M(0,0,NaN,e);let s=new M(r,i,0,e);for(let c=0;c<r;c++)s.matrix[c][c]=1;let a=new M(r,i,NaN,e);for(let c=0;c<r;c++)a.matrix[c]=[...t.matrix[c]];let o=Math.floor(n);if(o<0)return new M(r,i,NaN,e);for(;o>0;){if(o%2===1){const l=new M(r,i,0,e);for(let u=0;u<r;u++)for(let p=0;p<i;p++){let f=0;for(let h=0;h<r;h++)f+=s.matrix[u][h]*a.matrix[h][p];l.matrix[u][p]=f}s=l}const c=new M(r,i,0,e);for(let l=0;l<r;l++)for(let u=0;u<i;u++){let p=0;for(let f=0;f<r;f++)p+=a.matrix[l][f]*a.matrix[f][u];c.matrix[l][u]=p}a=c,o=Math.floor(o/2)}return s}}function cr(e){return t=>{const n=t.matrix.length;if(n===0)return 0;const r=t.matrix[0].length,i=t.matrix.map(a=>[...a]);let s=0;for(let a=0;a<r&&s<n;a++){let o=s;for(;o<n&&Math.abs(i[o][a])<1e-10;)o++;if(o<n){[i[s],i[o]]=[i[o],i[s]];const c=i[s][a];for(let l=a;l<r;l++)i[s][l]/=c;for(let l=0;l<n;l++)if(l!==s){const u=i[l][a];for(let p=a;p<r;p++)i[l][p]-=u*i[s][p]}s++}}return s}}function lr(e){return(t,n)=>{const r=t.matrix.length;if(r===0){const a=q(t.matrix[0][0]);return new $([],a,e)}const i=[];for(let a=0;a<r;a++){const o=t.matrix[a].splice(n,1);i.push(o[0])}const s=q(i[0]);return new $(i,s,e)}}function ur(e){return(t,n)=>{const r=t.matrix.splice(n,1),i=q(r[0][0]);return new $(r[0]||[],i,e)}}function hr(e){return(t,n,r)=>{const i=t.matrix.length,s=i>0?t.matrix[0].length:0,a=n*r,o=[];for(let u=0;u<i;u++)for(let p=0;p<s;p++)o.push(t.matrix[u][p]);for(;o.length<a;)o.push(NaN);o.length>a&&(o.length=a);const c=[];let l=0;for(let u=0;u<n;u++){const p=[];for(let f=0;f<r;f++)p.push(o[l++]);c.push(p)}t.matrix=c}}function pr(e){return t=>{t.matrix.reverse();for(const n of t.matrix)n.reverse()}}function mr(e){return(t,n)=>{if(!t.matrix[n]){const i=q(t.matrix[0][0]);return new $([],i,e)}const r=q(t.matrix[n][0]);return new $([...t.matrix[n]],r,e)}}function fr(e){return t=>t.matrix.length}function dr(e){return(t,n,r,i)=>{t.matrix[n]&&(t.matrix[n][r]=i)}}function gr(e){return(t,n=0,r="asc")=>{t.matrix.length!==0&&t.matrix.sort((i,s)=>{const a=i[n],o=s[n];return a<o?r==="asc"?-1:1:a>o?r==="asc"?1:-1:0})}}function yr(e){return(t,n,r,i,s)=>{const a=r-n,o=s-i,c=new M(a,o,NaN,e);for(let l=0;l<a;l++){const u=n+l;if(u>=t.matrix.length)break;for(let p=0;p<o;p++){const f=i+p;if(f>=t.matrix[u].length)break;c.matrix[l][p]=t.matrix[u][f]}}return c}}function _r(e){return(t,n)=>{const r=t.matrix.length;if(r===0)return new M(0,0,NaN,e);const i=t.matrix[0].length,s=new M(r,i,NaN,e);if(n instanceof M)for(let a=0;a<r;a++)for(let o=0;o<i;o++){const c=t.matrix[a][o],l=n.matrix[a]&&n.matrix[a][o]!==void 0?n.matrix[a][o]:NaN;s.matrix[a][o]=c+l}else{const a=n;for(let o=0;o<r;o++)for(let c=0;c<i;c++)s.matrix[o][c]=t.matrix[o][c]+a}return s}}function xr(e){return(t,n,r)=>{const i=t.matrix.length;for(let s=0;s<i;s++){const a=t.matrix[s][n];t.matrix[s][n]=t.matrix[s][r],t.matrix[s][r]=a}}}function Nr(e){return(t,n,r)=>{const i=t.matrix[n];t.matrix[n]=t.matrix[r],t.matrix[r]=i}}function wr(e){return t=>{const n=t.matrix.length;if(n===0)return 0;const r=t.matrix[0].length,i=Math.min(n,r);let s=0;for(let a=0;a<i;a++)s+=t.matrix[a][a];return s}}function br(e){return t=>{const n=t.matrix.length;if(n===0)return new M(0,0,NaN,e);const r=t.matrix[0].length,i=new M(r,n,NaN,e);for(let s=0;s<n;s++)for(let a=0;a<r;a++)i.matrix[a][s]=t.matrix[s][a];return i}}var vr=Object.defineProperty,Sr=(e,t,n)=>t in e?vr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t,n)=>Sr(e,typeof t!="symbol"?t+"":t,n);class M{constructor(t=0,n=0,r=NaN,i){if(this.context=i,v(this,"matrix"),v(this,"_add_col"),v(this,"_add_row"),v(this,"_avg"),v(this,"_col"),v(this,"_columns"),v(this,"_concat"),v(this,"_copy"),v(this,"_det"),v(this,"_diff"),v(this,"_eigenvalues"),v(this,"_eigenvectors"),v(this,"_elements_count"),v(this,"_fill"),v(this,"_get"),v(this,"_inv"),v(this,"_is_antidiagonal"),v(this,"_is_antisymmetric"),v(this,"_is_binary"),v(this,"_is_diagonal"),v(this,"_is_identity"),v(this,"_is_square"),v(this,"_is_stochastic"),v(this,"_is_symmetric"),v(this,"_is_triangular"),v(this,"_is_zero"),v(this,"_kron"),v(this,"_max"),v(this,"_median"),v(this,"_min"),v(this,"_mode"),v(this,"_mult"),v(this,"_pinv"),v(this,"_pow"),v(this,"_rank"),v(this,"_remove_col"),v(this,"_remove_row"),v(this,"_reshape"),v(this,"_reverse"),v(this,"_row"),v(this,"_rows"),v(this,"_set"),v(this,"_sort"),v(this,"_submatrix"),v(this,"_sum"),v(this,"_swap_columns"),v(this,"_swap_rows"),v(this,"_trace"),v(this,"_transpose"),this.matrix=[],t>0&&n>0)for(let s=0;s<t;s++)this.matrix.push(Array(n).fill(r));this._add_col=En(this.context),this._add_row=In(this.context),this._avg=Mn(this.context),this._col=$n(this.context),this._columns=jn(this.context),this._concat=An(this.context),this._copy=kn(this.context),this._det=Vn(this.context),this._diff=Pn(this.context),this._eigenvalues=Dn(this.context),this._eigenvectors=Ln(this.context),this._elements_count=Wn(this.context),this._fill=On(this.context),this._get=Rn(this.context),this._inv=zn(this.context),this._is_antidiagonal=Hn(this.context),this._is_antisymmetric=qn(this.context),this._is_binary=Un(this.context),this._is_diagonal=Gn(this.context),this._is_identity=Kn(this.context),this._is_square=Xn(this.context),this._is_stochastic=Yn(this.context),this._is_symmetric=Zn(this.context),this._is_triangular=Jn(this.context),this._is_zero=Qn(this.context),this._kron=tr(this.context),this._max=er(this.context),this._median=nr(this.context),this._min=rr(this.context),this._mode=ir(this.context),this._mult=ar(this.context),this._pinv=sr(this.context),this._pow=or(this.context),this._rank=cr(this.context),this._remove_col=lr(this.context),this._remove_row=ur(this.context),this._reshape=hr(this.context),this._reverse=pr(this.context),this._row=mr(this.context),this._rows=fr(this.context),this._set=dr(this.context),this._sort=gr(this.context),this._submatrix=yr(this.context),this._sum=_r(this.context),this._swap_columns=xr(this.context),this._swap_rows=Nr(this.context),this._trace=wr(this.context),this._transpose=br(this.context)}toString(){let t="";for(let n=0;n<this.matrix.length;n++)t+=t===""?"":`
|
|
23
|
+
`,t+="["+this.matrix[n].join(", ")+"]";return t}add_col(...t){return this._add_col(this,...t)}add_row(...t){return this._add_row(this,...t)}avg(...t){return this._avg(this,...t)}col(...t){return this._col(this,...t)}columns(...t){return this._columns(this,...t)}concat(...t){return this._concat(this,...t)}copy(...t){return this._copy(this,...t)}det(...t){return this._det(this,...t)}diff(...t){return this._diff(this,...t)}eigenvalues(...t){return this._eigenvalues(this,...t)}eigenvectors(...t){return this._eigenvectors(this,...t)}elements_count(...t){return this._elements_count(this,...t)}fill(...t){return this._fill(this,...t)}get(...t){return this._get(this,...t)}inv(...t){return this._inv(this,...t)}is_antidiagonal(...t){return this._is_antidiagonal(this,...t)}is_antisymmetric(...t){return this._is_antisymmetric(this,...t)}is_binary(...t){return this._is_binary(this,...t)}is_diagonal(...t){return this._is_diagonal(this,...t)}is_identity(...t){return this._is_identity(this,...t)}is_square(...t){return this._is_square(this,...t)}is_stochastic(...t){return this._is_stochastic(this,...t)}is_symmetric(...t){return this._is_symmetric(this,...t)}is_triangular(...t){return this._is_triangular(this,...t)}is_zero(...t){return this._is_zero(this,...t)}kron(...t){return this._kron(this,...t)}max(...t){return this._max(this,...t)}median(...t){return this._median(this,...t)}min(...t){return this._min(this,...t)}mode(...t){return this._mode(this,...t)}mult(...t){return this._mult(this,...t)}pinv(...t){return this._pinv(this,...t)}pow(...t){return this._pow(this,...t)}rank(...t){return this._rank(this,...t)}remove_col(...t){return this._remove_col(this,...t)}remove_row(...t){return this._remove_row(this,...t)}reshape(...t){return this._reshape(this,...t)}reverse(...t){return this._reverse(this,...t)}row(...t){return this._row(this,...t)}rows(...t){return this._rows(this,...t)}set(...t){return this._set(this,...t)}sort(...t){return this._sort(this,...t)}submatrix(...t){return this._submatrix(this,...t)}sum(...t){return this._sum(this,...t)}swap_columns(...t){return this._swap_columns(this,...t)}swap_rows(...t){return this._swap_rows(this,...t)}trace(...t){return this._trace(this,...t)}transpose(...t){return this._transpose(this,...t)}}function Cr(e){return(t,n,r)=>new M(t,n,r,e)}function Er(e){return(t,n=0)=>m.from(t).get(n)}class Ir{constructor(t){this.context=t,this.add_col=(n,...r)=>n.add_col(...r),this.add_row=(n,...r)=>n.add_row(...r),this.avg=(n,...r)=>n.avg(...r),this.col=(n,...r)=>n.col(...r),this.columns=(n,...r)=>n.columns(...r),this.concat=(n,...r)=>n.concat(...r),this.copy=(n,...r)=>n.copy(...r),this.det=(n,...r)=>n.det(...r),this.diff=(n,...r)=>n.diff(...r),this.eigenvalues=(n,...r)=>n.eigenvalues(...r),this.eigenvectors=(n,...r)=>n.eigenvectors(...r),this.elements_count=(n,...r)=>n.elements_count(...r),this.fill=(n,...r)=>n.fill(...r),this.get=(n,...r)=>n.get(...r),this.inv=(n,...r)=>n.inv(...r),this.is_antidiagonal=(n,...r)=>n.is_antidiagonal(...r),this.is_antisymmetric=(n,...r)=>n.is_antisymmetric(...r),this.is_binary=(n,...r)=>n.is_binary(...r),this.is_diagonal=(n,...r)=>n.is_diagonal(...r),this.is_identity=(n,...r)=>n.is_identity(...r),this.is_square=(n,...r)=>n.is_square(...r),this.is_stochastic=(n,...r)=>n.is_stochastic(...r),this.is_symmetric=(n,...r)=>n.is_symmetric(...r),this.is_triangular=(n,...r)=>n.is_triangular(...r),this.is_zero=(n,...r)=>n.is_zero(...r),this.kron=(n,...r)=>n.kron(...r),this.max=(n,...r)=>n.max(...r),this.median=(n,...r)=>n.median(...r),this.min=(n,...r)=>n.min(...r),this.mode=(n,...r)=>n.mode(...r),this.mult=(n,...r)=>n.mult(...r),this.new=Cr(t),this.param=Er(),this.pinv=(n,...r)=>n.pinv(...r),this.pow=(n,...r)=>n.pow(...r),this.rank=(n,...r)=>n.rank(...r),this.remove_col=(n,...r)=>n.remove_col(...r),this.remove_row=(n,...r)=>n.remove_row(...r),this.reshape=(n,...r)=>n.reshape(...r),this.reverse=(n,...r)=>n.reverse(...r),this.row=(n,...r)=>n.row(...r),this.rows=(n,...r)=>n.rows(...r),this.set=(n,...r)=>n.set(...r),this.sort=(n,...r)=>n.sort(...r),this.submatrix=(n,...r)=>n.submatrix(...r),this.sum=(n,...r)=>n.sum(...r),this.swap_columns=(n,...r)=>n.swap_columns(...r),this.swap_rows=(n,...r)=>n.swap_rows(...r),this.trace=(n,...r)=>n.trace(...r),this.transpose=(n,...r)=>n.transpose(...r)}}var Mr=Object.defineProperty,$r=(e,t,n)=>t in e?Mr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jr=(e,t,n)=>$r(e,typeof t!="symbol"?t+"":t,n);class Ar{constructor(t){this.context=t,jr(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.data.close.data.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.data.close.data.length-1}get isrealtime(){return this.context.idx===this.context.data.close.data.length-1}get isconfirmed(){return this.context.data.closeTime[this.context.data.closeTime.length-1]<=new Date().getTime()}get islastconfirmedhistory(){return this.context.data.closeTime[this.context.data.closeTime.length-1]<=new Date().getTime()}}var kr=Object.defineProperty,Tr=(e,t,n)=>t in e?kr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Vr=(e,t,n)=>Tr(e,typeof t!="symbol"?t+"":t,n);class Pr{constructor(t){this.context=t,Vr(this,"color",{param:(n,r=0)=>m.from(n).get(r),rgb:(n,r,i,s)=>s?`rgba(${n}, ${r}, ${i}, ${s})`:`rgb(${n}, ${r}, ${i})`,new:(n,r)=>{if(n&&n.startsWith("#")){const i=n.slice(1),s=parseInt(i.slice(0,2),16),a=parseInt(i.slice(2,4),16),o=parseInt(i.slice(4,6),16);return r?`rgba(${s}, ${a}, ${o}, ${r})`:`rgb(${s}, ${a}, ${o})`}return r?`rgba(${n}, ${r})`:n},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue",yellow:"yellow",orange:"orange",purple:"purple",pink:"pink",brown:"brown",teal:"teal",cyan:"cyan",navy:"navy",indigo:"indigo",violet:"violet",magenta:"magenta",rose:"rose",gold:"gold",silver:"silver",bronze:"bronze"})}extractPlotOptions(t){const n={};for(let r in t)n[r]=m.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=m.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=m.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(m.from(t).get(0))}nz(t,n=0){const r=m.from(t).get(0),i=m.from(n).get(0);return isNaN(r)?i:r}}const xt=[["defval","title","tooltip","inline","group","display"],["defval","title","tooltip","group","confirm","display"],["defval","title","tooltip","inline","group","confirm","display"],["defval","title","options","tooltip","inline","group","confirm","display"],["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display"]],Br={defval:e=>typeof e!="object",title:e=>typeof e=="string",tooltip:e=>typeof e=="string",inline:e=>typeof e=="string",group:e=>typeof e=="string",display:e=>typeof e=="string",confirm:e=>typeof e=="boolean",options:e=>Array.isArray(e),minval:e=>typeof e=="number",maxval:e=>typeof e=="number",step:e=>typeof e=="number"};function R(e){const t={};let n={};const r=new Array(xt.length).fill(!0);for(let i=0;i<e.length;i++){const s=e[i];if(typeof s=="object"){n=s;break}const a=xt.map((o,c)=>r[c]?o[i]:void 0);for(let o=0;o<a.length;o++){const c=a[o];if(c===void 0){r[o]=!1;continue}Br[c](s)?t[c]=s:r[o]=!1}}return{...n,...t}}function Dr(e){return(...t)=>R(t).defval}function Lr(e){return(...t)=>R(t).defval}function Wr(e){return(...t)=>R(t).defval}function Or(e){return(...t)=>R(t).defval}function Rr(e){return(...t)=>R(t).defval}function Fr(e){return(...t)=>R(t).defval}function zr(e){return(t,n=0)=>m.from(t).get(n)}function Hr(e){return(...t)=>R(t).defval}function qr(e){return(...t)=>R(t).defval}function Ur(e){return(...t)=>R(t).defval}function Gr(e){return(...t)=>R(t).defval}function Kr(e){return(...t)=>R(t).defval}function Xr(e){return(...t)=>R(t).defval}function Yr(e){return(...t)=>R(t).defval}function Zr(e){return(...t)=>R(t).defval}var Jr=Object.defineProperty,Qr=(e,t,n)=>t in e?Jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,W=(e,t,n)=>Qr(e,typeof t!="symbol"?t+"":t,n);const ti={any:Dr,bool:Lr,color:Wr,enum:Or,float:Rr,int:Fr,param:zr,price:Hr,session:qr,source:Ur,string:Gr,symbol:Kr,text_area:Xr,time:Yr,timeframe:Zr};class ei{constructor(t){this.context=t,W(this,"any"),W(this,"bool"),W(this,"color"),W(this,"enum"),W(this,"float"),W(this,"int"),W(this,"param"),W(this,"price"),W(this,"session"),W(this,"source"),W(this,"string"),W(this,"symbol"),W(this,"text_area"),W(this,"time"),W(this,"timeframe"),Object.entries(ti).forEach(([n,r])=>{this[n]=r(t)})}}function ni(e){return t=>Math.abs(m.from(t).get(0))}function ri(e){return t=>Math.acos(m.from(t).get(0))}function ii(e){return t=>Math.asin(m.from(t).get(0))}function ai(e){return t=>Math.atan(m.from(t).get(0))}function si(e){return(...t)=>{const n=t.map(r=>m.from(r).get(0));return n.reduce((r,i)=>r+i,0)/n.length}}function oi(e){return t=>Math.ceil(m.from(t).get(0))}function ci(e){return t=>Math.cos(m.from(t).get(0))}function li(e){return()=>Math.E}function ui(e){return t=>Math.exp(m.from(t).get(0))}function hi(e){return t=>Math.floor(m.from(t).get(0))}function pi(e){return t=>Math.log(m.from(t).get(0))}function mi(e){return t=>Math.log(m.from(t).get(0))}function fi(e){return t=>Math.log10(m.from(t).get(0))}function di(e){return(...t)=>{const n=t.map(r=>m.from(r).get(0));return Math.max(...n)}}function gi(e){return(...t)=>{const n=t.map(r=>m.from(r).get(0));return Math.min(...n)}}function yi(e){return(t,n,r)=>typeof t=="string"?t:t instanceof m?n?new m(t.data,t.offset+n):t:!Array.isArray(t)&&typeof t=="object"?t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new m(t,n||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new m(e.params[r],0)))}function _i(e){return()=>1.618033988749895}function xi(e){return()=>Math.PI}function Ni(e){return(t,n)=>Math.pow(m.from(t).get(0),m.from(n).get(0))}function wi(e){return()=>Math.random()}function bi(e){return t=>Math.round(m.from(t).get(0))}function vi(e){return t=>e.precision(Math.round(m.from(t).get(0)/e.pine.syminfo.mintick)*e.pine.syminfo.mintick)}function Si(e){return()=>.6180339887498948}function Ci(e){return t=>Math.sign(m.from(t).get(0))}function Ei(e){return t=>Math.sin(m.from(t).get(0))}function Ii(e){return t=>Math.sqrt(m.from(t).get(0))}function Mi(e){return(t,n)=>{const r=m.from(n).get(0),i=m.from(t);let s=0;for(let a=0;a<r;a++){const o=i.get(a);s+=o}return s}}function $i(e){return t=>Math.tan(m.from(t).get(0))}function ji(e){return(t,n)=>{const r=m.from(t).get(0),i=m.from(n).get(0);return isNaN(r)&&isNaN(i)?!0:isNaN(r)||isNaN(i)?!1:Math.abs(r-i)<1e-8}}var Ai=Object.defineProperty,ki=(e,t,n)=>t in e?Ai(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t,n)=>ki(e,typeof t!="symbol"?t+"":t,n);const Ti={abs:ni,acos:ri,asin:ii,atan:ai,avg:si,ceil:oi,cos:ci,e:li,exp:ui,floor:hi,ln:pi,log:mi,log10:fi,max:di,min:gi,param:yi,phi:_i,pi:xi,pow:Ni,random:wi,round:bi,round_to_mintick:vi,rphi:Si,sign:Ci,sin:Ei,sqrt:Ii,sum:Mi,tan:$i,__eq:ji};class Vi{constructor(t){this.context=t,I(this,"_cache",{}),I(this,"abs"),I(this,"acos"),I(this,"asin"),I(this,"atan"),I(this,"avg"),I(this,"ceil"),I(this,"cos"),I(this,"e"),I(this,"exp"),I(this,"floor"),I(this,"ln"),I(this,"log"),I(this,"log10"),I(this,"max"),I(this,"min"),I(this,"param"),I(this,"phi"),I(this,"pi"),I(this,"pow"),I(this,"random"),I(this,"round"),I(this,"round_to_mintick"),I(this,"rphi"),I(this,"sign"),I(this,"sin"),I(this,"sqrt"),I(this,"sum"),I(this,"tan"),I(this,"__eq"),Object.entries(Ti).forEach(([n,r])=>{this[n]=r(t)})}}function Pi(e){return(t,n,r)=>{e.params[r]||(e.params[r]=[]);let i;if(t instanceof m)i=t.get(n||0);else if(Array.isArray(t)){const s=t.every(o=>o instanceof m),a=t.every(o=>!(o instanceof m)&&!Array.isArray(o));(s||a)&&t.length>=1?s?i=t.map(o=>o.get(0)):i=t:i=m.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 ot=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function Nt(e,t,n,r,i=!1){for(let s=0;s<n.length;s++)if(n[s]<=e&&t<=r[s])return i||t>=r[s]?s:s-1;return-1}function wt(e,t,n,r,i=!1,s,a=!1){for(let o=n.length-1;o>=0;o--){if(r[o]<=t&&n[o]>=e){const c=s&&t>s;if(a&&i)for(let l=0;l<n.length;l++){if(n[l]>=e&&n[l]<t)return l;if(n[l]>=t)break}if(c&&i&&!a)for(let l=0;l<n.length;l++){if(n[l]>=e&&n[l]<t)return l;if(n[l]>=t)break}return o}if(r[o]<e)break}return-1}function Bi(e){return async(t,n,r,i=!1,s=!1,a=!1,o=null,c=null)=>{const l=t[0],u=n[0],p=r[0],f=r[1],h=Array.isArray(i)?i[0]:i,d=Array.isArray(s)?s[0]:s;if(e.isSecondaryContext)return p;const g=ot.indexOf(e.timeframe),y=ot.indexOf(u);if(g==-1||y==-1)throw new Error("Invalid timeframe");if(g===y)return p;const w=g>y,S=m.from(e.data.openTime).get(0),b=m.from(e.data.closeTime).get(0),C=`${l}_${u}_${f}`,N=`${C}_prevIdx`;if(e.cache[C]){const tt=e.cache[C],at=w?wt(S,b,tt.data.openTime.data,tt.data.closeTime.data,d,e.eDate,h):Nt(S,b,tt.data.openTime.data,tt.data.closeTime.data,d);if(at==-1)return NaN;const Y=tt.params[f][at];if(!w&&h){const yt=e.cache[N];return yt!==void 0&&yt===at?NaN:(e.cache[N]=at,Array.isArray(Y)?[Y]:Y)}return Array.isArray(Y)?[Y]:Y}const L=1e3*60*60*24*30,B=e.sDate?e.sDate-L:void 0,P=e.sDate&&e.eDate?void 0:e.limit||1e3,Q=new Pt(e.source,l,u,P,B,void 0);Q.markAsSecondary();const G=await Q.run(e.pineTSCode);e.cache[C]=G;const ut=w?wt(S,b,G.data.openTime.data,G.data.closeTime.data,d,e.eDate,h):Nt(S,b,G.data.openTime.data,G.data.closeTime.data,d);if(ut==-1)return NaN;const ht=G.params[f][ut];return!w&&h?(e.cache[N]=ut,NaN):Array.isArray(ht)?[ht]:ht}}function Di(e){return async(t,n,r,i=!1,s=null,a=!1,o=0)=>{const c=t[0],l=n[0],u=r[0],p=r[1];Array.isArray(i)&&i[0];const f=Array.isArray(a)?a[0]:a;if(e.isSecondaryContext)return Array.isArray(u)?[u]:u;const h=ot.indexOf(e.timeframe),d=ot.indexOf(l);if(h===-1||d===-1){if(f)return NaN;throw new Error("Invalid timeframe")}if(d>h){if(f)return NaN;throw new Error(`Timeframe ${l} is not lower than or equal to chart timeframe ${e.timeframe}`)}if(d===h)return[[u]];const g=`${c}_${l}_${p}_lower`;if(!e.cache[g]){const B=e.sDate?e.sDate-2592e6:void 0,P=e.sDate&&e.eDate?void 0:e.limit||1e3,Q=new Pt(e.source,c,l,P,B,e.eDate);Q.markAsSecondary();const G=await Q.run(e.pineTSCode);e.cache[g]=G}const y=e.cache[g],w=m.from(e.data.openTime).get(0),S=m.from(e.data.closeTime).get(0),b=y.data.openTime.data,C=y.data.closeTime.data,N=y.params[p];if(!N)return[];const L=[];for(let B=0;B<b.length;B++){const P=b[B];if(!(C[B]<=w)){if(P>=S)break;P>=w&&P<S&&L.push(N[B])}}return[L]}}var Li=Object.defineProperty,Wi=(e,t,n)=>t in e?Li(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,st=(e,t,n)=>Wi(e,typeof t!="symbol"?t+"":t,n);const Oi={param:Pi,security:Bi,security_lower_tf:Di};class Ri{constructor(t){this.context=t,st(this,"_cache",{}),st(this,"param"),st(this,"security"),st(this,"security_lower_tf"),Object.entries(Oi).forEach(([n,r])=>{this[n]=r(t)})}}function Fi(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),s=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.volume,0);if(isNaN(i)||isNaN(s)||isNaN(a)||isNaN(o))return e.precision(r.cumulativeSum);const c=s-a;let l=0;return c!==0&&(l=(i-a-(s-i))/c*o),r.cumulativeSum+=l,e.precision(r.cumulativeSum)}}function zi(e){return(t,n,r,i,s)=>{const a=m.from(n).get(0),o=m.from(r).get(0),c=m.from(i).get(0);e.taState||(e.taState={});const l=s||`alma_${a}_${o}_${c}`;if(!e.taState[l]){const h=o*(a-1),d=a/c,g=[];let y=0;for(let w=0;w<a;w++){const S=Math.exp(-Math.pow(w-h,2)/(2*d*d));g.push(S),y+=S}for(let w=0;w<g.length;w++)g[w]/=y;e.taState[l]={window:[],weights:g}}const u=e.taState[l],p=m.from(t).get(0);if(u.window.unshift(p),u.window.length<a)return NaN;u.window.length>a&&u.window.pop();let f=0;for(let h=0;h<a;h++)f+=u.weights[h]*u.window[a-1-h];return e.precision(f)}}function Hi(e){return(t,n)=>{const r=m.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 s=e.taState[i],a=e.get(e.data.high,0),o=e.get(e.data.low,0),c=e.get(e.data.close,0);let l;if(s.prevClose!==null){const p=a-o,f=Math.abs(a-s.prevClose),h=Math.abs(o-s.prevClose);l=Math.max(p,f,h)}else l=a-o;if(s.prevClose=c,s.initCount<r)return s.initSum+=l,s.initCount++,s.initCount===r?(s.prevAtr=s.initSum/r,e.precision(s.prevAtr)):NaN;const u=(s.prevAtr*(r-1)+l)/r;return s.prevAtr=u,e.precision(u)}}function qi(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 m.from(t).get(0)?(i.lastTrueIndex=e.idx,0):i.lastTrueIndex===null?NaN:e.idx-i.lastTrueIndex}}function Ui(e){return(t,n,r,i)=>{const s=m.from(n).get(0),a=m.from(r).get(0);e.taState||(e.taState={});const o=i||`bb_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],l=m.from(t).get(0);if(isNaN(l))return[[NaN,NaN,NaN]];if(c.window.unshift(l),c.sum+=l,c.window.length<s)return[[NaN,NaN,NaN]];if(c.window.length>s){const g=c.window.pop();c.sum-=g}const u=c.sum/s;let p=0;for(let g=0;g<s;g++)p+=Math.pow(c.window[g]-u,2);const f=Math.sqrt(p/s),h=u+a*f,d=u-a*f;return[[e.precision(h),e.precision(u),e.precision(d)]]}}function Gi(e){return(t,n,r,i)=>{const s=m.from(n).get(0),a=m.from(r).get(0);e.taState||(e.taState={});const o=i||`bbw_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],l=m.from(t).get(0);if(isNaN(l))return NaN;if(c.window.unshift(l),c.sum+=l,c.window.length<s)return NaN;if(c.window.length>s){const y=c.window.pop();c.sum-=y}const u=c.sum/s;let p=0;for(let y=0;y<s;y++){const w=c.window[y]-u;p+=w*w}const f=p/s,h=Math.sqrt(f),d=a*h;if(u===0)return e.precision(0);const g=2*d/u*100;return e.precision(g)}}function Ki(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`cci_${i}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=m.from(t).get(0);if(isNaN(o))return NaN;if(a.window.unshift(o),a.sum+=o,a.window.length<i)return NaN;if(a.window.length>i){const f=a.window.pop();a.sum-=f}const c=a.sum/i;let l=0;for(let f=0;f<i;f++)l+=Math.abs(a.window[f]-c);const u=l/i;if(u===0)return 0;const p=(o-c)/(.015*u);return e.precision(p)}}function Xi(e){return(t,n=1,r)=>{typeof n=="string"&&(r=n,n=1);const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`change_${i}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<=i)return NaN;a.window.length>i+1&&a.window.pop();const c=o-a.window[i];return e.precision(c)}}function Yi(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`cmo_${i}`;e.taState[s]||(e.taState[s]={gainsWindow:[],lossesWindow:[],gainsSum:0,lossesSum:0});const a=e.taState[s],o=m.from(t).get(0),c=m.from(t).get(1);if(isNaN(o)||isNaN(c))return NaN;const l=o-c,u=l>=0?l:0,p=l>=0?0:-l;if(a.gainsWindow.unshift(u),a.lossesWindow.unshift(p),a.gainsSum+=u,a.lossesSum+=p,a.gainsWindow.length<i)return NaN;if(a.gainsWindow.length>i){const d=a.gainsWindow.pop(),g=a.lossesWindow.pop();a.gainsSum-=d,a.lossesSum-=g}const f=a.gainsSum+a.lossesSum;if(f===0)return e.precision(0);const h=100*(a.gainsSum-a.lossesSum)/f;return e.precision(h)}}function Zi(e){return(t,n,r)=>{const i=m.from(n).get(0),s=m.from(t);let a=0,o=!1;for(let u=0;u<i;u++){const p=s.get(u);if(isNaN(p)){o=!0;break}a+=p}if(o)return NaN;let c=0;for(let u=0;u<i;u++){const p=s.get(u);c+=p*(u+1)}if(a===0)return NaN;const l=-c/a;return e.precision(l)}}function Ji(e){return(t,n,r,i)=>{const s=m.from(r).get(0),a=m.from(t),o=m.from(n);if(e.idx<s-1)return NaN;let c=0,l=0,u=0,p=0,f=0,h=0;for(let S=0;S<s;S++){const b=a.get(S),C=o.get(S);isNaN(b)||isNaN(C)||(c+=b,l+=C,u+=b*C,p+=b*b,f+=C*C,h++)}if(h<2)return NaN;const d=h*u-c*l,g=h*p-c*c,y=h*f-l*l;if(g<=0||y<=0)return e.precision(0);const w=d/Math.sqrt(g*y);return e.precision(w)}}function Qi(e){return(t,n,r)=>{const i=m.from(t),s=m.from(n),a=i.get(0),o=s.get(0),c=i.get(1),l=s.get(1);if(isNaN(a)||isNaN(o)||isNaN(c)||isNaN(l))return!1;const u=a>o&&c<=l,p=a<o&&c>=l;return u||p}}function ta(e){return(t,n)=>{const r=m.from(t),i=m.from(n),s=r.get(0),a=i.get(0),o=r.get(1),c=i.get(1);return o<c&&s>a}}function ea(e){return(t,n)=>{const r=m.from(t),i=m.from(n),s=r.get(0),a=i.get(0),o=r.get(1),c=i.get(1);return o>c&&s<a}}function na(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],s=m.from(t).get(0);return isNaN(s)||(i.cumulativeSum+=s),e.precision(i.cumulativeSum)}}function ra(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`dev_${i}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=m.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<i)return NaN;if(a.window.length>i){const p=a.window.pop();a.sum-=p}const c=a.sum/i;let l=0;for(let p=0;p<i;p++)l+=Math.abs(a.window[p]-c);const u=l/i;return e.precision(u)}}function ia(e){return(t,n,r)=>{const i=m.from(t).get(0),s=m.from(n).get(0);e.taState||(e.taState={});const a=r||`dmi_${i}_${s}`;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 o=e.taState[a],c=e.get(e.data.high,0),l=e.get(e.data.low,0),u=e.get(e.data.close,0);if(isNaN(c)||isNaN(l)||isNaN(u))return[[NaN,NaN,NaN]];if(isNaN(o.prevHigh))return o.prevHigh=c,o.prevLow=l,o.prevClose=u,[[NaN,NaN,NaN]];const p=Math.max(c-l,Math.abs(c-o.prevClose),Math.abs(l-o.prevClose)),f=c-o.prevHigh,h=o.prevLow-l,d=f>h&&f>0?f:0,g=h>f&&h>0?h:0;o.prevHigh=c,o.prevLow=l,o.prevClose=u;let y,w,S;if(o.initCount++,o.initCount<=i)o.trInitSum+=p,o.plusInitSum+=d,o.minusInitSum+=g,o.initCount===i&&(o.prevSmoothedTR=o.trInitSum/i,o.prevSmoothedPlus=o.plusInitSum/i,o.prevSmoothedMinus=o.minusInitSum/i);else{const P=1/i;o.prevSmoothedTR=P*p+(1-P)*o.prevSmoothedTR,o.prevSmoothedPlus=P*d+(1-P)*o.prevSmoothedPlus,o.prevSmoothedMinus=P*g+(1-P)*o.prevSmoothedMinus}if(y=o.prevSmoothedTR,w=o.prevSmoothedPlus,S=o.prevSmoothedMinus,o.initCount<i)return[[NaN,NaN,NaN]];const b=y===0?0:100*w/y,C=y===0?0:100*S/y,N=b+C,L=N===0?0:100*Math.abs(b-C)/N;let B=NaN;if(o.adxInitCount++,o.adxInitCount<=s)o.dxInitSum+=L,o.adxInitCount===s&&(o.prevADX=o.dxInitSum/s,B=o.prevADX);else{const P=1/s;o.prevADX=P*L+(1-P)*o.prevADX,B=o.prevADX}return[[e.precision(b),e.precision(C),e.precision(B)]]}}function aa(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`ema_${i}`;e.taState[s]||(e.taState[s]={prevEma:null,initSum:0,initCount:0});const a=e.taState[s],o=m.from(t).get(0);if(a.initCount<i)return a.initSum+=o,a.initCount++,a.initCount===i?(a.prevEma=a.initSum/i,e.precision(a.prevEma)):NaN;const c=2/(i+1),l=o*c+a.prevEma*(1-c);return a.prevEma=l,e.precision(l)}}function sa(e){return(t,n,r)=>{const i=m.from(n).get(0),s=m.from(t);for(let a=0;a<i;a++){const o=s.get(a),c=s.get(a+1);if(isNaN(o)||isNaN(c)||o>=c)return!1}return!0}}function oa(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`highest_${i}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();const c=Math.max(...a.window.filter(l=>!isNaN(l)));return e.precision(c)}}function ca(e){return(t,n,r)=>{const i=m.from(n).get(0),s=m.from(t);if(e.idx<i-1)return NaN;let a=-1/0,o=NaN;for(let c=0;c<i;c++){const l=s.get(c);isNaN(l)||(isNaN(o)||l>a)&&(a=l,o=-c)}return o}}function la(e){return(t,n,r)=>{const i=m.from(n).get(0),s=Math.floor(i/2),a=Math.floor(Math.sqrt(i)),o=e.ta.wma,c=o(t,s,r?`${r}_wma1`:void 0),l=o(t,i,r?`${r}_wma2`:void 0);if(isNaN(c)||isNaN(l))return NaN;e.taState||(e.taState={});const u=r||`hma_raw_${i}`;e.taState[u]||(e.taState[u]=[]);const p=2*c-l;e.taState[u].unshift(p);const f=r?`${r}_hma_final`:`hma_final_${i}`;e.taState[f]||(e.taState[f]={window:[]});const h=e.taState[f];if(h.window.unshift(p),h.window.length<a)return NaN;h.window.length>a&&h.window.pop();let d=0,g=0;for(let w=0;w<a;w++){const S=a-w;d+=h.window[w]*S,g+=S}const y=d/g;return e.precision(y)}}function ua(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),s=e.get(e.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(s))return NaN;const a=(r-i)*s;if(a===0)return e.precision(0);const o=(2*n-r-i)/a;return e.precision(o)}}function ha(e){return(t,n,r,i,s)=>{const a=m.from(n).get(0),o=m.from(r).get(0);let c=!0;typeof i=="string"?s=i:i!==void 0&&(c=m.from(i).get(0));let l;const u=e.get(e.data.high,0),p=e.get(e.data.low,0);if(c){const C=e.get(e.data.close,1);isNaN(C)?l=NaN:l=Math.max(u-p,Math.abs(u-C),Math.abs(p-C))}else l=u-p;const f=m.from(t).get(0);e.taState||(e.taState={});const h=s||`kc_${a}_${o}_${c}`;e.taState[h]||(e.taState[h]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const d=e.taState[h],g=(C,N,L)=>{if(isNaN(N))return NaN;if(C.initCount<L)return C.initSum+=N,C.initCount++,C.initCount===L?(C.prevEma=C.initSum/L,C.prevEma):NaN;const B=2/(L+1);return C.prevEma=N*B+C.prevEma*(1-B),C.prevEma},y=g(d.basisState,f,a),w=g(d.rangeState,l,a);if(isNaN(y)||isNaN(w))return[[NaN,NaN,NaN]];const S=y+w*o,b=y-w*o;return[[e.precision(y),e.precision(S),e.precision(b)]]}}function pa(e){return(t,n,r,i,s)=>{const a=m.from(n).get(0),o=m.from(r).get(0);let c=!0;typeof i=="string"?s=i:i!==void 0&&(c=m.from(i).get(0)),e.taState||(e.taState={});const l=s||`kcw_${a}_${o}_${c}`;e.taState[l]||(e.taState[l]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const u=e.taState[l],p=(b,C,N)=>{if(isNaN(C))return NaN;if(b.initCount<N)return b.initSum+=C,b.initCount++,b.initCount===N?(b.prevEma=b.initSum/N,b.prevEma):NaN;const L=2/(N+1);return b.prevEma=C*L+b.prevEma*(1-L),b.prevEma};let f;const h=e.get(e.data.high,0),d=e.get(e.data.low,0);if(c){const b=e.get(e.data.close,1);isNaN(b)?f=NaN:f=Math.max(h-d,Math.abs(h-b),Math.abs(d-b))}else f=h-d;const g=m.from(t).get(0),y=p(u.basisState,g,a),w=p(u.rangeState,f,a);if(isNaN(y)||isNaN(w))return NaN;if(y===0)return e.precision(0);const S=2*w*o/y;return e.precision(S)}}function ma(e){return(t,n,r,i)=>{const s=m.from(n).get(0),a=m.from(r).get(0);e.taState||(e.taState={});const o=i||`linreg_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[]});const c=e.taState[o],l=m.from(t).get(0);if(c.window.unshift(l),c.window.length<s)return NaN;c.window.length>s&&c.window.pop();let u=0,p=0,f=0,h=0;const d=s;for(let S=0;S<s;S++){const b=s-1-S,C=c.window[S];u+=b,p+=C,f+=b*C,h+=b*b}const g=d*h-u*u;if(g===0)return NaN;const y=(d*f-u*p)/g,w=(p-y*u)/d+y*(s-1-a);return e.precision(w)}}function fa(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`lowest_${i}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();const c=a.window.filter(u=>!isNaN(u)&&u!==void 0),l=c.length>0?Math.min(...c):NaN;return e.precision(l)}}function da(e){return(t,n,r)=>{const i=m.from(n).get(0),s=m.from(t);if(e.idx<i-1)return NaN;let a=1/0,o=NaN;for(let c=0;c<i;c++){const l=s.get(c);isNaN(l)||(isNaN(o)||l<a)&&(a=l,o=-c)}return o}}function ga(e){return(t,n,r,i,s)=>{const a=m.from(n).get(0),o=m.from(r).get(0),c=m.from(i).get(0),l=s||`macd_${a}_${o}_${c}`,u=`${l}_fast`,p=`${l}_slow`,f=`${l}_signal`,h=e.ta.ema(t,a,u),d=e.ta.ema(t,o,p);let g=NaN;!isNaN(h)&&!isNaN(d)&&(g=h-d);let y=NaN;isNaN(g)||(y=e.ta.ema(g,c,f));let w=NaN;return!isNaN(g)&&!isNaN(y)&&(w=g-y),[[e.precision(g),e.precision(y),e.precision(w)]]}}function ya(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`median_${i}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();const c=a.window.slice().sort((p,f)=>p-f),l=Math.floor(i/2),u=i%2===0?(c[l-1]+c[l])/2:c[l];return e.precision(u)}}function _a(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`mfi_${i}`;e.taState[s]||(e.taState[s]={upperWindow:[],lowerWindow:[],upperSum:0,lowerSum:0});const a=e.taState[s],o=m.from(t).get(0),c=m.from(t).get(1),l=e.get(e.data.volume,0);if(isNaN(o)||isNaN(l))return NaN;const u=isNaN(c)?NaN:o-c;let p=0,f=0;if(p=l*(u<=0?0:o),f=l*(u>=0?0:o),a.upperWindow.unshift(p),a.lowerWindow.unshift(f),a.upperSum+=p,a.lowerSum+=f,a.upperWindow.length<i)return NaN;if(a.upperWindow.length>i){const d=a.upperWindow.pop(),g=a.lowerWindow.pop();a.upperSum-=d,a.lowerSum-=g}if(a.lowerSum===0)return a.upperSum,e.precision(100);if(a.upperSum===0)return e.precision(0);const h=100-100/(1+a.upperSum/a.lowerSum);return e.precision(h)}}function xa(e){return(t,n,r)=>{const i=m.from(n).get(0),s=m.from(t);if(e.idx<i-1)return NaN;const a=new Map;for(let l=0;l<i;l++){const u=s.get(l);isNaN(u)||a.set(u,(a.get(u)||0)+1)}if(a.size===0)return NaN;let o=NaN,c=-1;for(const[l,u]of a.entries())u>c?(c=u,o=l):u===c&&l<o&&(o=l);return o}}function Na(e){return(t,n,r)=>{const i=m.from(n).get(0);return e.ta.change(t,i)}}function wa(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),s=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),c=isNaN(i)?0:i,l=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o;if(!(c===0||l===0)&&u<p){const f=(c-l)/l;r.nvi=r.nvi+f*r.nvi}return e.precision(r.nvi)}}function ba(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),s=e.get(e.data.close,1);if(isNaN(s))return n.prevOBV=0,e.precision(0);let a;return r>s?a=n.prevOBV+i:r<s?a=n.prevOBV-i:a=n.prevOBV,n.prevOBV=a,e.precision(a)}}function va(e){return(t,n,r)=>t instanceof m?n?new m(t.data,t.offset+n):t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new m(t,n||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new m(e.params[r],0)))}function Sa(e){return(t,n,r,i)=>{const s=m.from(n).get(0),a=m.from(r).get(0),o=m.from(t);if(e.idx<s-1)return NaN;const c=[];for(let d=0;d<s;d++){const g=o.get(d);if(isNaN(g))return NaN;c.push(g)}c.sort((d,g)=>d-g);let l=a/100*s-.5;l<0&&(l=0),l>s-1&&(l=s-1);const u=Math.floor(l),p=Math.ceil(l);if(u===p)return e.precision(c[u]);const f=l-u,h=c[u]+f*(c[p]-c[u]);return e.precision(h)}}function Ca(e){return(t,n,r,i)=>{const s=m.from(n).get(0),a=m.from(r).get(0),o=m.from(t);if(e.idx<s-1)return NaN;const c=[];for(let u=0;u<s;u++){const p=o.get(u);isNaN(p)||c.push(p)}if(c.length===0)return NaN;c.sort((u,p)=>u-p);let l=Math.ceil(a/100*c.length)-1;return l<0&&(l=0),l>=c.length&&(l=c.length-1),e.precision(c[l])}}function Ea(e){return(t,n,r)=>{const i=m.from(n).get(0),s=m.from(t);if(e.idx<i)return NaN;const a=s.get(0);if(isNaN(a))return NaN;let o=0,c=0;for(let l=1;l<=i;l++){const u=s.get(l);isNaN(u)||(c++,u<=a&&o++)}return c===0?NaN:e.precision(o/c*100)}}function Ia(e,t,n){const r=new Array(e.length).fill(NaN);for(let i=t+n;i<e.length;i++){const s=e[i-n];let a=!0;for(let o=1;o<=t;o++)if(e[i-n-o]>=s){a=!1;break}if(a){for(let o=1;o<=n;o++)if(e[i-n+o]>=s){a=!1;break}}a&&(r[i]=s)}return r}function Ma(e){return(t,n,r)=>{r==null&&(r=n,n=t,t=e.data.high);const i=m.from(n).get(0),s=m.from(r).get(0),a=m.from(t).toArray(),o=Ia(a,i,s),c=e.idx;return e.precision(o[c])}}function $a(e,t,n){const r=new Array(e.length).fill(NaN);for(let i=t+n;i<e.length;i++){const s=e[i-n];let a=!0;for(let o=1;o<=t;o++)if(e[i-n-o]<=s){a=!1;break}if(a){for(let o=1;o<=n;o++)if(e[i-n+o]<=s){a=!1;break}}a&&(r[i]=s)}return r}function ja(e){return(t,n,r)=>{r==null&&(r=n,n=t,t=e.data.low);const i=m.from(n).get(0),s=m.from(r).get(0),a=m.from(t).toArray(),o=$a(a,i,s),c=e.idx;return e.precision(o[c])}}function Aa(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),s=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),c=isNaN(i)?0:i,l=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o;if(!(c===0||l===0)&&u>p){const f=(c-l)/l;r.pvi=r.pvi+f*r.pvi}return e.precision(r.pvi)}}function ka(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),s=e.get(e.data.close,1),a=e.get(e.data.volume,0);if(!isNaN(i)&&!isNaN(s)&&!isNaN(a)&&s!==0){const o=(i-s)/s*a;r.cumulativeSum+=o}return e.precision(r.cumulativeSum)}}function Ta(e){return(t,n,r)=>{const i=e.pine.ta.highest(t,n,(r||"range")+"_h"),s=e.pine.ta.lowest(t,n,(r||"range")+"_l");return isNaN(i)||isNaN(s)?NaN:e.precision(i-s)}}function Va(e){return(t,n,r)=>{const i=m.from(n).get(0),s=m.from(t);for(let a=0;a<i;a++){const o=s.get(a),c=s.get(a+1);if(isNaN(o)||isNaN(c)||o<=c)return!1}return!0}}function Pa(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`rma_${i}`;e.taState[s]||(e.taState[s]={prevRma:null,initSum:0,initCount:0});const a=e.taState[s],o=m.from(t).get(0)||0;if(a.initCount<i)return a.initSum+=o,a.initCount++,a.initCount===i?(a.prevRma=a.initSum/i,e.precision(a.prevRma)):NaN;const c=1/i,l=o*c+a.prevRma*(1-c);return a.prevRma=l,e.precision(l)}}function Ba(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`roc_${i}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<=i)return NaN;a.window.length>i+1&&a.window.pop();const c=a.window[i],l=(o-c)/c*100;return e.precision(l)}}function Da(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`rsi_${i}`;e.taState[s]||(e.taState[s]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.prevValue!==null){const c=o-a.prevValue,l=c>0?c:0,u=c<0?-c:0;if(a.initGains.length<i){if(a.initGains.push(l),a.initLosses.push(u),a.initGains.length===i){a.avgGain=a.initGains.reduce((h,d)=>h+d,0)/i,a.avgLoss=a.initLosses.reduce((h,d)=>h+d,0)/i,a.prevValue=o;const f=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return e.precision(f)}return a.prevValue=o,NaN}a.avgGain=(a.avgGain*(i-1)+l)/i,a.avgLoss=(a.avgLoss*(i-1)+u)/i;const p=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return a.prevValue=o,e.precision(p)}return a.prevValue=o,NaN}}function La(e){return(t,n,r,i)=>{const s=m.from(t).get(0),a=m.from(n).get(0),o=m.from(r).get(0);e.taState||(e.taState={});const c=i||`sar_${s}_${a}_${o}`;e.taState[c]||(e.taState[c]={result:NaN,maxMin:NaN,acceleration:NaN,isBelow:!1,barIndex:0});const l=e.taState[c],u=e.get(e.data.high,0),p=e.get(e.data.low,0),f=e.get(e.data.close,0),h=e.get(e.data.close,1),d=e.get(e.data.high,1),g=e.get(e.data.low,1),y=e.get(e.data.high,2),w=e.get(e.data.low,2);if(isNaN(u)||isNaN(p)||isNaN(f))return NaN;let S=!1;return l.barIndex===1&&(f>h?(l.isBelow=!0,l.maxMin=u,l.result=g):(l.isBelow=!1,l.maxMin=p,l.result=d),S=!0,l.acceleration=s),l.barIndex>=1&&(l.result=l.result+l.acceleration*(l.maxMin-l.result),l.isBelow?l.result>p&&(S=!0,l.isBelow=!1,l.result=Math.max(u,l.maxMin),l.maxMin=p,l.acceleration=s):l.result<u&&(S=!0,l.isBelow=!0,l.result=Math.min(p,l.maxMin),l.maxMin=u,l.acceleration=s),S||(l.isBelow?u>l.maxMin&&(l.maxMin=u,l.acceleration=Math.min(l.acceleration+a,o)):p<l.maxMin&&(l.maxMin=p,l.acceleration=Math.min(l.acceleration+a,o))),l.isBelow?(l.result=Math.min(l.result,g),l.barIndex>1&&(l.result=Math.min(l.result,w))):(l.result=Math.max(l.result,d),l.barIndex>1&&(l.result=Math.max(l.result,y)))),l.barIndex++,l.barIndex<=1?NaN:e.precision(l.result)}}function Wa(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`sma_${i}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=m.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<i)return NaN;if(a.window.length>i){const l=a.window.pop();a.sum-=l}const c=a.sum/i;return e.precision(c)}}function Oa(e){return(t,n,r=!0,i)=>{const s=m.from(n).get(0),a=m.from(r).get(0);e.taState||(e.taState={});const o=i||`stdev_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],l=m.from(t).get(0);if(c.window.unshift(l),c.sum+=l,c.window.length<s)return NaN;if(c.window.length>s){const d=c.window.pop();c.sum-=d}const u=c.sum/s;let p=0;for(let d=0;d<s;d++)p+=Math.pow(c.window[d]-u,2);const f=a?s:s-1,h=Math.sqrt(p/f);return e.precision(h)}}function Ra(e){return(t,n,r,i,s)=>{const a=m.from(i).get(0);e.taState||(e.taState={});const o=s||`stoch_${a}`;e.taState[o]||(e.taState[o]={highWindow:[],lowWindow:[]});const c=e.taState[o],l=m.from(t).get(0),u=m.from(n).get(0),p=m.from(r).get(0);if(isNaN(l)||isNaN(u)||isNaN(p))return NaN;if(c.highWindow.unshift(u),c.lowWindow.unshift(p),c.highWindow.length<a)return NaN;c.highWindow.length>a&&(c.highWindow.pop(),c.lowWindow.pop());let f=c.highWindow[0],h=c.lowWindow[0];for(let y=1;y<a;y++)c.highWindow[y]>f&&(f=c.highWindow[y]),c.lowWindow[y]<h&&(h=c.lowWindow[y]);const d=f-h;if(d===0)return NaN;const g=100*(l-h)/d;return e.precision(g)}}function Fa(e){return(t,n,r)=>{const i=m.from(t).get(0),s=m.from(n).get(0);e.taState||(e.taState={});const a=r||`supertrend_${i}_${s}`;e.taState[a]||(e.taState[a]={trWindow:[],trSum:0,atrValue:NaN,atrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,prevClose:NaN});const o=e.taState[a],c=e.get(e.data.high,0),l=e.get(e.data.low,0),u=e.get(e.data.close,0);if(isNaN(c)||isNaN(l)||isNaN(u))return[[NaN,NaN]];const p=(c+l)/2;let f;isNaN(o.prevClose)?f=c-l:f=Math.max(c-l,Math.abs(c-o.prevClose),Math.abs(l-o.prevClose)),o.atrCount++,o.atrCount<=s?(o.trWindow.push(f),o.trSum+=f,o.atrCount===s&&(o.atrValue=o.trSum/s)):o.atrValue=(o.atrValue*(s-1)+f)/s;const h=o.atrValue,d=o.prevClose;if(o.prevClose=u,isNaN(h))return[[NaN,NaN]];let g=p+i*h,y=p-i*h;const w=isNaN(o.prevLowerBand)?0:o.prevLowerBand,S=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||y>w||d<w||(y=w),isNaN(o.prevUpperBand)||g<S||d>S||(g=S);let b,C;const N=o.prevSuperTrend;return o.atrCount===s?b=1:N===o.prevUpperBand?b=u>g?-1:1:b=u<y?1:-1,C=b===-1?y:g,o.prevLowerBand=y,o.prevUpperBand=g,o.prevSuperTrend=C,o.prevDirection=b,[[e.precision(C),b]]}}function za(e){return(t,n)=>{const r=[1,2,2,1],i=6;e.taState||(e.taState={});const s=n||"swma";e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<4)return NaN;a.window.length>4&&a.window.pop();let c=0;for(let l=0;l<4;l++)c+=r[l]*a.window[3-l];return c/=i,e.precision(c)}}function Ha(e){return(t,n)=>{let r=!0;typeof t=="string"||t!==void 0&&(r=m.from(t).get(0));const i=e.get(e.data.high,0),s=e.get(e.data.low,0),a=e.get(e.data.close,1);if(isNaN(a))return r?e.precision(i-s):NaN;const o=Math.max(i-s,Math.abs(i-a),Math.abs(s-a));return e.precision(o)}}function qa(e){return(t,n,r,i)=>{const s=m.from(n).get(0),a=m.from(r).get(0);e.taState||(e.taState={});const o=i||`tsi_${s}_${a}`;e.taState[o]||(e.taState[o]={prevSource:NaN,ema1_pc_multiplier:2/(a+1),ema1_pc_value:NaN,ema1_pc_count:0,ema1_pc_sum:0,ema2_pc_multiplier:2/(s+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/(s+1),ema2_abs_value:NaN,ema2_abs_count:0,ema2_abs_sum:0});const c=e.taState[o],l=m.from(t).get(0);if(isNaN(l))return NaN;const u=isNaN(c.prevSource)?NaN:l-c.prevSource;if(c.prevSource=l,isNaN(u))return NaN;const p=Math.abs(u);if(c.ema1_pc_count++,c.ema1_pc_count<=a?(c.ema1_pc_sum+=u,c.ema1_pc_count===a&&(c.ema1_pc_value=c.ema1_pc_sum/a)):c.ema1_pc_value=u*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+=p,c.ema1_abs_count===a&&(c.ema1_abs_value=c.ema1_abs_sum/a)):c.ema1_abs_value=p*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<=s?(c.ema2_pc_sum+=c.ema1_pc_value,c.ema2_pc_count===s&&(c.ema2_pc_value=c.ema2_pc_sum/s)):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<=s?(c.ema2_abs_sum+=c.ema1_abs_value,c.ema2_abs_count===s&&(c.ema2_abs_value=c.ema2_abs_sum/s)):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 f=c.ema2_pc_value/c.ema2_abs_value;return e.precision(f)}}function Ua(e){return(t,n,r,i)=>{e.taState||(e.taState={});const s=i||"valuewhen";e.taState[s]||(e.taState[s]={values:[]});const a=e.taState[s],o=m.from(t).get(0),c=m.from(n).get(0),l=m.from(r).get(0);if(o&&a.values.push(c),isNaN(l)||l<0)return NaN;const u=a.values.length-1-l;if(u<0)return NaN;const p=a.values[u];return typeof p=="number"?e.precision(p):p}}function Ga(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`variance_${i}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();let c=0,l=0;for(let f=0;f<i;f++)c+=a.window[f],l+=a.window[f]*a.window[f];const u=c/i,p=l/i-u*u;return e.precision(p)}}function Ka(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],s=m.from(t).get(0),a=m.from(e.data.volume).get(0),o=m.from(e.data.openTime).get(0),c=new Date(o).toISOString().slice(0,10);if(i.lastSessionDate!==c&&(i.cumulativePV=0,i.cumulativeVolume=0,i.lastSessionDate=c),i.cumulativePV+=s*a,i.cumulativeVolume+=a,i.cumulativeVolume===0)return NaN;const l=i.cumulativePV/i.cumulativeVolume;return e.precision(l)}}function Xa(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`vwma_${i}`;e.taState[s]||(e.taState[s]={window:[],volumeWindow:[]});const a=e.taState[s],o=m.from(t).get(0),c=e.get(e.data.volume,0);if(a.window.unshift(o),a.volumeWindow.unshift(c),a.window.length<i)return NaN;a.window.length>i&&(a.window.pop(),a.volumeWindow.pop());let l=0,u=0;for(let f=0;f<i;f++)l+=a.window[f]*a.volumeWindow[f],u+=a.volumeWindow[f];const p=l/u;return e.precision(p)}}function Ya(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),s=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.close,1);if(isNaN(i)||isNaN(s)||isNaN(a))return e.precision(r.cumulativeSum);let c=0;if(!isNaN(o)){const l=Math.max(s,o),u=Math.min(a,o),p=i-o;p>0?c=i-u:p<0&&(c=i-l)}return r.cumulativeSum+=c,e.precision(r.cumulativeSum)}}function Za(e){return(t,n,r)=>{const i=m.from(n).get(0);e.taState||(e.taState={});const s=r||`wma_${i}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=m.from(t).get(0);if(a.window.unshift(o),a.window.length<i)return NaN;a.window.length>i&&a.window.pop();let c=0,l=0;for(let p=0;p<i;p++){const f=i-p;c+=a.window[p]*f,l+=f}const u=c/l;return e.precision(u)}}function Ja(e){return(t,n)=>{const r=m.from(t).get(0);e.taState||(e.taState={});const i=n||`wpr_${r}`;e.taState[i]||(e.taState[i]={highWindow:[],lowWindow:[]});const s=e.taState[i],a=e.get(e.data.high,0),o=e.get(e.data.low,0),c=e.get(e.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(c))return NaN;if(s.highWindow.unshift(a),s.lowWindow.unshift(o),s.highWindow.length<r)return NaN;s.highWindow.length>r&&(s.highWindow.pop(),s.lowWindow.pop());let l=s.highWindow[0],u=s.lowWindow[0];for(let h=1;h<r;h++)s.highWindow[h]>l&&(l=s.highWindow[h]),s.lowWindow[h]<u&&(u=s.lowWindow[h]);const p=l-u;if(p===0)return e.precision(0);const f=(l-c)/p*-100;return e.precision(f)}}function Qa(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),s=e.get(e.data.low,0),a=e.get(e.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(s)||isNaN(a))return NaN;const o=i-s;if(o===0)return e.precision(0);const c=(n-r)/o*a;return e.precision(c)}}var ts=Object.defineProperty,es=(e,t,n)=>t in e?ts(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,x=(e,t,n)=>es(e,typeof t!="symbol"?t+"":t,n);const ns={accdist:Fi,alma:zi,atr:Hi,barssince:qi,bb:Ui,bbw:Gi,cci:Ki,change:Xi,cmo:Yi,cog:Zi,correlation:Ji,cross:Qi,crossover:ta,crossunder:ea,cum:na,dev:ra,dmi:ia,ema:aa,falling:sa,highest:oa,highestbars:ca,hma:la,iii:ua,kc:ha,kcw:pa,linreg:ma,lowest:fa,lowestbars:da,macd:ga,median:ya,mfi:_a,mode:xa,mom:Na,nvi:wa,obv:ba,param:va,percentile_linear_interpolation:Sa,percentile_nearest_rank:Ca,percentrank:Ea,pivothigh:Ma,pivotlow:ja,pvi:Aa,pvt:ka,range:Ta,rising:Va,rma:Pa,roc:Ba,rsi:Da,sar:La,sma:Wa,stdev:Oa,stoch:Ra,supertrend:Fa,swma:za,tr:Ha,tsi:qa,valuewhen:Ua,variance:Ga,vwap:Ka,vwma:Xa,wad:Ya,wma:Za,wpr:Ja,wvad:Qa};class rs{constructor(t){this.context=t,x(this,"accdist"),x(this,"alma"),x(this,"atr"),x(this,"barssince"),x(this,"bb"),x(this,"bbw"),x(this,"cci"),x(this,"change"),x(this,"cmo"),x(this,"cog"),x(this,"correlation"),x(this,"cross"),x(this,"crossover"),x(this,"crossunder"),x(this,"cum"),x(this,"dev"),x(this,"dmi"),x(this,"ema"),x(this,"falling"),x(this,"highest"),x(this,"highestbars"),x(this,"hma"),x(this,"iii"),x(this,"kc"),x(this,"kcw"),x(this,"linreg"),x(this,"lowest"),x(this,"lowestbars"),x(this,"macd"),x(this,"median"),x(this,"mfi"),x(this,"mode"),x(this,"mom"),x(this,"nvi"),x(this,"obv"),x(this,"param"),x(this,"percentile_linear_interpolation"),x(this,"percentile_nearest_rank"),x(this,"percentrank"),x(this,"pivothigh"),x(this,"pivotlow"),x(this,"pvi"),x(this,"pvt"),x(this,"range"),x(this,"rising"),x(this,"rma"),x(this,"roc"),x(this,"rsi"),x(this,"sar"),x(this,"sma"),x(this,"stdev"),x(this,"stoch"),x(this,"supertrend"),x(this,"swma"),x(this,"tr"),x(this,"tsi"),x(this,"valuewhen"),x(this,"variance"),x(this,"vwap"),x(this,"vwma"),x(this,"wad"),x(this,"wma"),x(this,"wpr"),x(this,"wvad"),Object.entries(ns).forEach(([n,r])=>{this[n]=r(t)})}}class is{constructor(t){this.context=t}logFormat(t,...n){return t.replace(/{(\d+)}/g,(r,i)=>n[i])}param(t,n=0,r){return m.from(t).get(n)}warning(t,...n){console.warn(this.logFormat(t,...n))}error(t,...n){console.error(this.logFormat(t,...n))}info(t,...n){console.log(this.logFormat(t,...n))}}class as{constructor(t){this.context=t}param(t,n=0,r){return m.from(t).get(n)}tostring(t){return String(t)}tonumber(t){return Number(t)}lower(t){return String(t).toLowerCase()}upper(t){return String(t).toUpperCase()}trim(t){return String(t).trim()}repeat(t,n,r=""){return Array(n).fill(t).join(r||"")}replace_all(t,n,r){return String(t).replaceAll(n,r)}replace(t,n,r,i=0){const s=String(t),a=String(n),o=String(r),c=Math.floor(Number(i))||0;if(a==="")return s;let l=0,u=0;for(;;){const p=s.indexOf(a,l);if(p===-1)return s;if(u===c)return s.substring(0,p)+o+s.substring(p+a.length);u++,l=p+a.length}}contains(t,n){return String(t).includes(n)}endswith(t,n){return String(t).endsWith(n)}startswith(t,n){return String(t).startsWith(n)}pos(t,n){const r=String(t).indexOf(n);return r===-1?NaN:r}length(t){return String(t).length}match(t,n){return String(t).match(new RegExp(n))}split(t,n){return[String(t).split(n)]}substring(t,n,r){return String(t).substring(n,r)}format(t,...n){return t.replace(/{(\d+)}/g,(r,i)=>n[i])}}class ss{constructor(t){this.context=t}param(t,n=0,r){return m.from(t).get(n)}get main_period(){return this.context.timeframe}get period(){return this.context.timeframe}get multiplier(){const t=parseInt(this.context.timeframe);return isNaN(t)?1:t}get isdwm(){return["D","W","M"].includes(this.context.timeframe.slice(-1))}get isdaily(){return this.context.timeframe.slice(-1)==="D"}get isweekly(){return this.context.timeframe.slice(-1)==="W"}get ismonthly(){return this.context.timeframe.slice(-1)==="M"}get isseconds(){return this.context.timeframe.slice(-1)==="S"}get isminutes(){return parseInt(this.context.timeframe).toString()==this.context.timeframe.trim()}get isintraday(){return!this.isdwm}from_seconds(t){return t<60?Math.ceil(t/5)*5+"S":t<60*60*24?Math.ceil(t/60):t<=60*60*24*7*52?t%(60*60*24*7)===0?Math.ceil(t/604800)+"W":Math.ceil(t/(60*60*24))+"D":"12M"}in_seconds(t){const n=parseInt(t),r=t.slice(-1);return r==="S"?n:r==="D"?n*60*60*24:r==="W"?n*60*60*24*7:r==="M"?n*60*60*24*30:isNaN(n)?0:n*60}}var os=Object.defineProperty,cs=(e,t,n)=>t in e?os(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,j=(e,t,n)=>cs(e,typeof t!="symbol"?t+"":t,n);const Vt=class dt{constructor({marketData:t,source:n,tickerId:r,timeframe:i,limit:s,sDate:a,eDate:o,fullContext:c}){j(this,"data",{open:new m([]),high:new m([]),low:new m([]),close:new m([]),volume:new m([]),hl2:new m([]),hlc3:new m([]),ohlc4:new m([]),hlcc4:new m([])}),j(this,"cache",{}),j(this,"taState",{}),j(this,"isSecondaryContext",!1),j(this,"NA",NaN),j(this,"lang"),j(this,"pine"),j(this,"idx",0),j(this,"params",{}),j(this,"const",{}),j(this,"var",{}),j(this,"let",{}),j(this,"result"),j(this,"plots",{}),j(this,"marketData"),j(this,"source"),j(this,"tickerId"),j(this,"timeframe",""),j(this,"limit"),j(this,"sDate"),j(this,"eDate"),j(this,"fullContext"),j(this,"pineTSCode"),this.marketData=t,this.source=n,this.tickerId=r,this.timeframe=i,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=c||this;const l=new Pr(this),u={plotchar:l.plotchar.bind(l),na:l.na.bind(l),color:l.color,plot:l.plot.bind(l),nz:l.nz.bind(l)},p=this;this.pine={input:new ei(this),ta:new rs(this),math:new Vi(this),request:new Ri(this),array:new un(this),map:new Cn(this),matrix:new Ir(this),na:u.na,plotchar:u.plotchar,color:u.color,plot:u.plot,nz:u.nz,syminfo:null,timeframe:new ss(this),barstate:new Ar(this),get bar_index(){return p.idx},get last_bar_index(){return p.data.close.length-1},get last_bar_time(){return p.data.openTime.get(p.data.openTime.length-1)},get timenow(){return new Date().getTime()},log:new is(this),str:new as(this),...Ue}}init(t,n,r=0){let i;return n instanceof m?i=n.get(0):Array.isArray(n)?Array.isArray(n[0])?i=n[0]:i=n[n.length-1+r]:i=n,t?t instanceof m?(t.data[t.data.length-1]=i,t):Array.isArray(t)?(t[t.length-1]=i,new m(t)):new m([i]):new m([i])}initVar(t,n){if(t)return t;let r;return n instanceof m?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 m([r])}precision(t,n=10){const r=10**n;return typeof t=="number"?Math.round(t*r)/r:t}param(t,n,r){return typeof t=="string"?t:t instanceof m?n?new m(t.data,t.offset+n):t:!Array.isArray(t)&&typeof t=="object"?t:(this.params[r]||(this.params[r]=[]),Array.isArray(t)?new m(t,n||0):(this.params[r].length===0?this.params[r].push(t):this.params[r][this.params[r].length-1]=t,new m(this.params[r],0)))}get(t,n){if(t instanceof m)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 m){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}`;dt._deprecationWarningsShown.has(r)||(dt._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`))}};j(Vt,"_deprecationWarningsShown",new Set);let bt=Vt;var ls=Object.defineProperty,us=(e,t,n)=>t in e?ls(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,V=(e,t,n)=>us(e,typeof t!="symbol"?t+"":t,n);class Pt{constructor(t,n,r,i,s,a){this.source=t,this.tickerId=n,this.timeframe=r,this.limit=i,this.sDate=s,this.eDate=a,V(this,"data",[]),V(this,"open",[]),V(this,"high",[]),V(this,"low",[]),V(this,"close",[]),V(this,"volume",[]),V(this,"hl2",[]),V(this,"hlc3",[]),V(this,"ohlc4",[]),V(this,"hlcc4",[]),V(this,"openTime",[]),V(this,"closeTime",[]),V(this,"_readyPromise",null),V(this,"_ready",!1),V(this,"_debugSettings",{ln:!1,debug:!1}),V(this,"_transpiledCode",null),V(this,"_isSecondaryContext",!1),V(this,"_syminfo"),this._readyPromise=new Promise(o=>{this.loadMarketData(t,n,r,i,s,a).then(c=>{const l=c;this.data=l;const u=l.map(N=>N.open),p=l.map(N=>N.close),f=l.map(N=>N.high),h=l.map(N=>N.low),d=l.map(N=>N.volume),g=l.map(N=>(N.high+N.low+N.close)/3),y=l.map(N=>(N.high+N.low)/2),w=l.map(N=>(N.high+N.low+N.open+N.close)/4),S=l.map(N=>(N.high+N.low+N.close+N.close)/4),b=l.map(N=>N.openTime),C=l.map(N=>N.closeTime);this.open=u,this.close=p,this.high=f,this.low=h,this.volume=d,this.hl2=y,this.hlc3=g,this.ohlc4=w,this.hlcc4=S,this.openTime=b,this.closeTime=C,t&&t.getSymbolInfo?t.getSymbolInfo(n).then(N=>{this._syminfo=N,this._ready=!0,o(!0)}).catch(N=>{console.warn("Failed to get symbol info, using default values:",N),this._ready=!0,o(!0)}):(this._ready=!0,o(!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,s,a){return Array.isArray(t)?t:t.getMarketData(n,r,i,s,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 s=this._initializeContext(t,this._isSecondaryContext);this._transpiledCode=this._transpileCode(t);let a=this.data.length-n;for(;;){const o=this.data.length-a;if(o>0){const u=Math.min(o,r),p=this._getResultLength(s.result);await this._executeIterations(s,this._transpiledCode,a,a+u),a+=u,yield this._createPageContext(s,p);continue}if(!i||Array.isArray(this.source))break;const{newCandles:c,updatedLastCandle:l}=await this._updateMarketData();if(c===0&&!l){yield null;continue}this._removeLastResult(s),a=this.data.length-(c+1),s.pine.barstate.setLive()}}_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 bt({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:t});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 s=await n.getMarketData(this.tickerId,this.timeframe,void 0,i,t);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let c=0;c<s.length;c++){const l=s[c];l.openTime===i?(this._replaceCandle(r,l),a=!0):l.openTime>i&&(this._appendCandle(l),o++)}return{newCandles:o,updatedLastCandle:a}}catch(s){return console.error("Error updating market data:",s),{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.hlcc4[t]=(n.high+n.low+n.close+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.hlcc4.push((t.high+t.low+t.close+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.hlcc4.data.pop(),t.data.openTime.data.pop(),t.data.closeTime&&t.data.closeTime.data.pop()}_initializeContext(t,n=!1){const r=new bt({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});return r.pine.syminfo=this._syminfo,r.pineTSCode=t,r.isSecondaryContext=n,r.data.close=new m([]),r.data.open=new m([]),r.data.high=new m([]),r.data.low=new m([]),r.data.volume=new m([]),r.data.hl2=new m([]),r.data.hlc3=new m([]),r.data.ohlc4=new m([]),r.data.hlcc4=new m([]),r.data.openTime=new m([]),r.data.closeTime=new m([]),r}_transpileCode(t){return oe.bind(this)(t,this._debugSettings)}async _executeIterations(t,n,r,i){const s=["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.hlcc4.data.push(this.hlcc4[a]),t.data.openTime.data.push(this.openTime[a]),t.data.closeTime.data.push(this.closeTime[a]);const o=await n(t);if(typeof o=="object"){typeof t.result!="object"&&(t.result={});for(let c in o){t.result[c]===void 0&&(t.result[c]=[]);let l;o[c]instanceof m?l=o[c].get(0):Array.isArray(o[c])?l=o[c][o[c].length-1]:l=o[c],t.result[c].push(l)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(o);for(let c of s)for(let l in t[c]){const u=t[c][l];if(u instanceof m){const p=u.get(0);u.data.push(p)}else if(Array.isArray(u)){const p=u[u.length-1];u.push(p)}}}}}var hs=Object.defineProperty,ps=(e,t,n)=>t in e?hs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gt=(e,t,n)=>ps(e,typeof t!="symbol"?t+"":t,n);const vt="https://api.binance.com/api/v3",pt={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 ms{constructor(t=5*60*1e3){gt(this,"cache"),gt(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 fs{constructor(){gt(this,"cacheManager"),this.cacheManager=new ms(5*60*1e3)}async getMarketDataInterval(t,n,r,i){try{const s=pt[n.toUpperCase()];if(!s)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 o=[],c=r;const l=i,u=a[s];if(!u)return console.error(`Duration not defined for interval: ${s}`),[];for(;c<l;){const p=Math.min(c+1e3*u,l),f=await this.getMarketData(t,n,1e3,c,p);if(f.length===0)break;o=o.concat(f),c=f[f.length-1].closeTime+1}return o}catch(s){return console.error("Error in getMarketDataInterval:",s),[]}}async getMarketData(t,n,r,i,s){try{const a=s!==void 0,o={tickerId:t,timeframe:n,limit:r,sDate:i,eDate:s};if(a){const f=this.cacheManager.get(o);if(f)return f}const c=pt[n.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${n}`),[];if(this.shouldPaginate(n,r,i,s)&&i&&s){const f=await this.getMarketDataInterval(t,n,i,s),h=r?f.slice(0,r):f;return this.cacheManager.set(o,h),h}let l=`${vt}/klines?symbol=${t}&interval=${c}`;r&&(l+=`&limit=${Math.min(r,1e3)}`),i&&(l+=`&startTime=${i}`),s&&(l+=`&endTime=${s}`);const u=await fetch(l);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);const p=(await u.json()).map(f=>({openTime:parseInt(f[0]),open:parseFloat(f[1]),high:parseFloat(f[2]),low:parseFloat(f[3]),close:parseFloat(f[4]),volume:parseFloat(f[5]),closeTime:parseInt(f[6]),quoteAssetVolume:parseFloat(f[7]),numberOfTrades:parseInt(f[8]),takerBuyBaseAssetVolume:parseFloat(f[9]),takerBuyQuoteAssetVolume:parseFloat(f[10]),ignore:f[11]}));return a&&this.cacheManager.set(o,p),p}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 s=pt[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}[s];if(a)return Math.ceil((i-r)/a)>1e3}return!1}async getSymbolInfo(t){try{let n="crypto",r=vt,i=t,s="";t.endsWith(".P")?(n="futures",i=t.replace(".P",""),r="https://fapi.binance.com/fapi/v1",s="Perpetual"):t.includes("_")&&(n="futures",i=t,r="https://dapi.binance.com/dapi/v1",s="Delivery");const a=n==="crypto"?`${r}/exchangeInfo?symbol=${i}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const c=(await o.json()).symbols;if(!c||c.length===0)return console.error(`Symbol ${t} not found`),null;const l=n==="futures"?c.find(b=>b.symbol===i):c[0];if(!l)return console.error(`Symbol ${i} not found in exchange info`),null;const u=l.filters?.find(b=>b.filterType==="PRICE_FILTER"),p=l.filters?.find(b=>b.filterType==="LOT_SIZE"),f=u?parseFloat(u.tickSize):.01,h=p?parseFloat(p.minQty):0,d=Math.round(1/f),g=l.baseAsset,y=l.quoteAsset,w=s?` ${s}`:"",S=`${g} / ${y}${w}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:g,description:S,type:n,main_tickerid:`BINANCE:${t}`,current_contract:s,isin:"",basecurrency:g,currency:y,timezone:"Etc/UTC",country:"",mintick:f,pricescale:d,minmove:1,pointvalue:l.contractSize||1,mincontract:h,session:"24x7",volumetype:"base",expiration_date:l.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(n){return console.error("Error in binance.exchangeInfo:",n),null}}}var ds=Object.defineProperty,gs=(e,t,n)=>t in e?ds(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mt=(e,t,n)=>gs(e,typeof t!="symbol"?t+"":t,n);const ys=Bt(import.meta.url),_s=nt.dirname(ys);class xs{constructor(t){if(mt(this,"dataCache",new Map),mt(this,"exchangeInfoCache",{}),mt(this,"dataDirectory"),t)this.dataDirectory=t;else{const n=nt.resolve(_s,"../../../");this.dataDirectory=nt.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=nt.join(this.dataDirectory,t);if(!Z.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const i=Z.readFileSync(r,"utf-8"),s=JSON.parse(i);return this.dataCache.set(n,s),s}findDataFile(t,n,r,i){if(!Z.existsSync(this.dataDirectory))return null;const s=Z.readdirSync(this.dataDirectory).filter(c=>c.endsWith(".json"));if(r&&i){const c=`${t}-${n}-${r}-${i}.json`;if(s.includes(c))return c}const a=new RegExp(`^${t}-${n}-(\\d+)-(\\d+)\\.json$`),o=s.filter(c=>a.test(c)).map(c=>{const l=c.match(a);return{file:c,startTime:parseInt(l[1]),endTime:parseInt(l[2])}}).sort((c,l)=>l.endTime-c.endTime);if(o.length===0)return null;if(r&&i){const c=o.find(l=>l.startTime<=r&&l.endTime>=i);if(c)return c.file}return o[0].file}filterData(t,n,r,i){let s=t;return(n||r)&&(s=t.filter(a=>{const o=!n||a.openTime>=n,c=!r||a.openTime<=r;return o&&c})),s.sort((a,o)=>a.openTime-o.openTime),i&&i>0&&(s=s.slice(0,i)),s}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,s){try{const a=this.normalizeTimeframe(n),o=this.findDataFile(t,a,i,s);if(!o)return console.warn(`No mock data file found for ${t} ${a}. Searched in: ${this.dataDirectory}`),[];const c=this.loadDataFromFile(o);return this.filterData(c,i,s,r)}catch(a){return console.error("Error in MockProvider.getMarketData:",a),[]}}loadExchangeInfo(t){if(this.exchangeInfoCache[t])return this.exchangeInfoCache[t];const n=t==="spot"?"api-exchangeInfo.json":"fapi-exchangeInfo.json",r=nt.join(this.dataDirectory,n);if(!Z.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const i=Z.readFileSync(r,"utf-8"),s=JSON.parse(i);return this.exchangeInfoCache[t]=s,s}catch(i){return console.error(`Error loading exchange info from ${n}:`,i),null}}async getSymbolInfo(t){try{let n="crypto",r=t,i="";t.endsWith(".P")?(n="futures",r=t.replace(".P",""),i="Perpetual"):t.includes("_")&&(n="futures",r=t,i="Delivery");const s=this.loadExchangeInfo(n==="futures"?"futures":"spot");if(!s||!s.symbols)return console.error(`Exchange info not available for ${n}`),null;const a=s.symbols.find(y=>y.symbol===r);if(!a)return console.error(`Symbol ${r} not found in ${n} exchange info`),null;const o=a.filters?.find(y=>y.filterType==="PRICE_FILTER"),c=a.filters?.find(y=>y.filterType==="LOT_SIZE"),l=o?parseFloat(o.tickSize):.01,u=c?parseFloat(c.minQty):0,p=Math.round(1/l),f=a.baseAsset,h=a.quoteAsset,d=i?` ${i}`:"",g=`${f} / ${h}${d}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:f,description:g,type:n,main_tickerid:`BINANCE:${t}`,current_contract:i,isin:"",basecurrency:f,currency:h,timezone:"Etc/UTC",country:"",mintick:l,pricescale:p,minmove:1,pointvalue:a.contractSize||1,mincontract:u,session:"24x7",volumetype:"base",expiration_date:a.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(n){return console.error("Error in MockProvider.getSymbolInfo:",n),null}}clearCache(){this.dataCache.clear(),this.exchangeInfoCache={}}setDataDirectory(t){this.dataDirectory=t,this.clearCache()}}const Ns=typeof process<"u"&&process.versions&&process.versions.node;let ct=null;if(Ns)try{ct=new xs}catch{ct=null}const bs={Binance:new fs,...ct?{Mock:ct}:{}};export{bt as Context,Pt as PineTS,bs as Provider};
|