pinets 0.3.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 +50 -3
- package/dist/pinets.dev.browser.js +6429 -1434
- package/dist/pinets.dev.cjs +6525 -1418
- package/dist/pinets.dev.cjs.map +1 -1
- package/dist/pinets.dev.es.js +6527 -1415
- package/dist/pinets.dev.es.js.map +1 -1
- package/dist/pinets.min.browser.js +16 -11
- package/dist/pinets.min.cjs +16 -11
- package/dist/pinets.min.es.js +6 -1
- package/dist/types/Context.class.d.ts +79 -17
- package/dist/types/PineTS.class.d.ts +13 -1
- 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 +16 -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/from.d.ts +1 -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.d.ts +1 -1
- 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/request/types/barmerge.type.d.ts +7 -0
- package/dist/types/namespaces/request/utils/findLTFContextIdx.d.ts +1 -0
- package/dist/types/namespaces/ta/getters/obv.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/accdist.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/alma.d.ts +18 -0
- package/dist/types/namespaces/ta/methods/atr.d.ts +2 -1
- package/dist/types/namespaces/ta/methods/barssince.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/bb.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/bbw.d.ts +9 -0
- package/dist/types/namespaces/ta/methods/cci.d.ts +20 -0
- package/dist/types/namespaces/ta/methods/cmo.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/cog.d.ts +18 -0
- package/dist/types/namespaces/ta/methods/correlation.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/cross.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/cum.d.ts +14 -0
- package/dist/types/namespaces/ta/methods/dmi.d.ts +24 -0
- package/dist/types/namespaces/ta/methods/falling.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/highestbars.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/iii.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/kc.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/kcw.d.ts +11 -0
- package/dist/types/namespaces/ta/methods/lowestbars.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/macd.d.ts +18 -0
- package/dist/types/namespaces/ta/methods/mfi.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/mode.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/nvi.d.ts +10 -0
- package/dist/types/namespaces/ta/methods/obv.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/percentile_linear_interpolation.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/percentile_nearest_rank.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/percentrank.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/pvi.d.ts +10 -0
- package/dist/types/namespaces/ta/methods/pvt.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/range.d.ts +7 -0
- package/dist/types/namespaces/ta/methods/rising.d.ts +15 -0
- package/dist/types/namespaces/ta/methods/sar.d.ts +12 -0
- package/dist/types/namespaces/ta/methods/stoch.d.ts +21 -0
- package/dist/types/namespaces/ta/methods/supertrend.d.ts +23 -0
- package/dist/types/namespaces/ta/methods/swma.d.ts +14 -0
- package/dist/types/namespaces/ta/methods/tr.d.ts +2 -0
- package/dist/types/namespaces/ta/methods/tsi.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/valuewhen.d.ts +6 -0
- package/dist/types/namespaces/ta/methods/vwap.d.ts +14 -0
- package/dist/types/namespaces/ta/methods/wad.d.ts +11 -0
- package/dist/types/namespaces/ta/methods/wpr.d.ts +17 -0
- package/dist/types/namespaces/ta/methods/wvad.d.ts +7 -0
- package/dist/types/namespaces/ta/ta.index.d.ts +120 -5
- package/dist/types/transpiler/analysis/ScopeManager.d.ts +11 -0
- package/dist/types/transpiler/index.d.ts +4 -1
- package/dist/types/transpiler/settings.d.ts +4 -0
- package/dist/types/transpiler/transformers/InjectionTransformer.d.ts +6 -0
- package/dist/types/transpiler/transformers/MainTransformer.d.ts +4 -1
- package/dist/types/transpiler/transformers/NormalizationTransformer.d.ts +15 -0
- package/dist/types/transpiler/transformers/WrapperTransformer.d.ts +9 -0
- package/dist/types/transpiler/utils/ASTFactory.d.ts +2 -0
- package/dist/types/types/PineTypes.d.ts +11 -0
- package/package.json +6 -4
package/dist/pinets.min.es.js
CHANGED
|
@@ -15,4 +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 re from"acorn";import*as ne from"astring";import*as j from"acorn-walk";import*as R from"fs";import*as F from"path";import{fileURLToPath as ae}from"url";var ie=Object.defineProperty,oe=(t,e,r)=>e in t?ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_=(t,e,r)=>oe(t,typeof e!="symbol"?e+"":e,r);class se{constructor(){_(this,"scopes",[]),_(this,"scopeTypes",[]),_(this,"scopeCounts",new Map),_(this,"contextBoundVars",new Set),_(this,"arrayPatternElements",new Set),_(this,"rootParams",new Set),_(this,"varKinds",new Map),_(this,"loopVars",new Set),_(this,"loopVarNames",new Map),_(this,"paramIdCounter",0),_(this,"cacheIdCounter",0),_(this,"tempVarCounter",0),_(this,"taCallIdCounter",0),this.pushScope("glb")}get nextParamIdArg(){return{type:"Identifier",name:`'p${this.paramIdCounter++}'`}}get nextCacheIdArg(){return{type:"Identifier",name:`'cache_${this.cacheIdCounter++}'`}}getNextTACallId(){return{type:"Literal",value:`_ta${this.taCallIdCounter++}`}}pushScope(e){this.scopes.push(new Map),this.scopeTypes.push(e),this.scopeCounts.set(e,(this.scopeCounts.get(e)||0)+1)}popScope(){this.scopes.pop(),this.scopeTypes.pop()}getCurrentScopeType(){return this.scopeTypes[this.scopeTypes.length-1]}getCurrentScopeCount(){return this.scopeCounts.get(this.getCurrentScopeType())||1}addContextBoundVar(e,r=!1){this.contextBoundVars.add(e),r&&this.rootParams.add(e)}removeContextBoundVar(e){this.contextBoundVars.has(e)&&(this.contextBoundVars.delete(e),this.rootParams.has(e)&&this.rootParams.delete(e))}addArrayPatternElement(e){this.arrayPatternElements.add(e)}isContextBound(e){return this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,r){this.loopVars.add(e),this.loopVarNames.set(e,r)}getLoopVariableName(e){return this.loopVarNames.get(e)}isLoopVariable(e){return this.loopVars.has(e)}addVariable(e,r){if(this.isContextBound(e))return e;const n=this.scopes[this.scopes.length-1],a=this.scopeTypes[this.scopeTypes.length-1],o=this.scopeCounts.get(a)||1,i=`${a}${o}_${e}`;return n.set(e,i),this.varKinds.set(i,r),i}getVariable(e){if(this.loopVars.has(e)){const r=this.loopVarNames.get(e);if(r)return[r,"let"]}if(this.isContextBound(e))return[e,"let"];for(let r=this.scopes.length-1;r>=0;r--){const n=this.scopes[r];if(n.has(e)){const a=n.get(e),o=this.varKinds.get(a)||"let";return[a,o]}}return[e,"let"]}generateTempVar(){return`temp_${++this.tempVarCounter}`}}const A="$",y={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,r=!1){return{type:"MemberExpression",object:t,property:e,computed:r}},createContextIdentifier(){return this.createIdentifier(A)},createContextVariableReference(t,e){const r=this.createContextIdentifier(),n=this.createIdentifier(t),a=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(r,n,!1),a,!1)},createContextVariableAccess0(t,e){const r=this.createContextVariableReference(t,e);return this.createArrayAccess(r,0)},createArrayAccess(t,e){const r=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,r,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,r="="){return{type:"AssignmentExpression",operator:r,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,r){const n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),a=[t,e];return r&&a.push(r),this.createCallExpression(n,a)},createGetCall(t,e){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),n=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(r,[t,n])},createSetCall(t,e){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(r,[t,e])},createMathEqCall(t,e){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__eq"),!1);return this.createCallExpression(n,[t,e])},createWrapperFunction(t){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:t}]}}}};function ce(t){j.recursive(t,null,{VariableDeclaration(e,r,n){e.declarations&&e.declarations.length>0&&e.declarations.forEach(a=>{if(a.init&&a.init.type==="ArrowFunctionExpression"&&a.init.start!==0){const o={type:"FunctionDeclaration",id:a.id,params:a.init.params,body:a.init.body.type==="BlockStatement"?a.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:a.init.body}]},async:a.init.async,generator:!1};Object.assign(e,o)}}),e.body&&e.body.body&&e.body.body.forEach(a=>n(a,r))}})}function pe(t,e){j.simple(t,{VariableDeclaration(r){r.declarations.forEach(n=>{const a=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===A||n.init.object.name==="context2"),o=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===A||n.init.object.object.name==="context2");(a||o)&&(n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(i=>{i.key.name&&e.addContextBoundVar(i.key.name)}))})}})}function le(t,e,r=!1){t.params.forEach(n=>{n.type==="Identifier"&&e.addContextBoundVar(n.name,r)})}function ue(t,e){t.params.forEach(r=>{r.type==="Identifier"&&e.addContextBoundVar(r.name,!1)})}function me(t,e){let r;return j.simple(t,{FunctionDeclaration(n){ue(n,e)},ArrowFunctionExpression(n){const a=n.start===0;a&&n.params&&n.params.length>0&&(r=n.params[0].name,n.params[0].name=A),le(n,e,a)},VariableDeclaration(n){n.declarations.forEach(a=>{if(a.id.type==="ArrayPattern"){const o=e.generateTempVar(),i={type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:o},init:a.init}]};a.id.elements?.forEach(c=>{c.type==="Identifier"&&e.addArrayPatternElement(c.name)});const s=a.id.elements.map((c,u)=>({type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:c,init:{type:"MemberExpression",object:{type:"Identifier",name:o},property:{type:"Literal",value:u},computed:!0}}]}));Object.assign(n,{type:"BlockStatement",body:[i,...s]})}})},ForStatement(n){}}),r}const U={type:"Identifier",name:"undefined"};function k(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name))return;if(!e.isContextBound(t.property.name)){const[r,n]=e.getVariable(t.property.name);t.property=y.createContextVariableReference(n,r),t.property=y.createGetCall(t.property,0)}}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(!e.isContextBound(t.object.name)){const[r,n]=e.getVariable(t.object.name);t.object=y.createContextVariableReference(n,r)}if(t.property.type==="MemberExpression"){const r=t.property;r._indexTransformed||(k(r,e),r._indexTransformed=!0)}}}function B(t,e){const r=y.createGetCall(y.createIdentifier(t.name),0);t.start!==void 0&&(r.start=t.start),t.end!==void 0&&(r.end=t.end),r._indexTransformed=!0,Object.assign(t,r)}function $(t,e){if(t.name!==A){if(t.name==="Math"||t.name==="NaN"||t.name==="undefined"||t.name==="Infinity"||t.name==="null"||t.name.startsWith("'")&&t.name.endsWith("'")||t.name.startsWith('"')&&t.name.endsWith('"')||t.name.startsWith("`")&&t.name.endsWith("`")||e.isLoopVariable(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;const r=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),n=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.property.name==="param";t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left;const a=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.callee.object.name),o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed,i=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.property===t&&t.parent.parent&&t.parent.parent.type==="CallExpression"&&t.parent.parent.callee&&t.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.parent.callee.object.name),s=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t;if(r||n||a||i||s){if(s)return;const[f,m]=e.getVariable(t.name),p=y.createContextVariableReference(m,f);Object.assign(t,p);return}const[c,u]=e.getVariable(t.name),h=y.createContextVariableReference(u,c);if(!(t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t)&&!o){const f=y.createGetCall(h,0);Object.assign(t,f)}else Object.assign(t,h)}}function T(t,e,r){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;const n=r.getCurrentScopeType()=="if",a=r.getCurrentScopeType()=="els",o=r.getCurrentScopeType()=="for";if(!n&&!a&&!o&&t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(k(t,r),t._indexTransformed=!0);const i=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&t.object.object.object.name===A,s=t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name);if(t.computed&&(i||s)){if(t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left===t)return;const c=y.createGetCall(t.object,t.property);t.start&&(c.start=t.start),t.end&&(c.end=t.end),Object.assign(t,c)}}function L(t,e){if(t.type==="Identifier"){if(t.name==="na")return t.name="NaN",t;if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){const[a,o]=e.getVariable(t.name);return y.createContextVariableReference(o,a)}if(e.isContextBound(t.name))return t;const[r,n]=e.getVariable(t.name);return y.createContextVariableReference(n,r)}return t}function O(t,e,r=""){switch(t.type){case"BinaryExpression":return Y(t,e,r);case"MemberExpression":return{type:"MemberExpression",object:t.object.type==="Identifier"?L(t.object,e):t.object,property:t.property,computed:t.computed};case"Identifier":{if(e.isLoopVariable(t.name)||t.parent&&t.parent.type==="MemberExpression"&&t.parent.property===t)return t;const n=L(t,e);return y.createGetCall(n,0)}case"UnaryExpression":return Z(t,e,r)}return t}function Y(t,e,r){const n=O(t.left,e,r),a=O(t.right,e,r),o={type:"BinaryExpression",operator:t.operator,left:n,right:a,start:t.start,end:t.end};return j.recursive(o,e,{CallExpression(i,s){i._transformed||D(i,s)},MemberExpression(i){T(i,"",e)}}),o}function he(t,e,r){const n=O(t.left,e,r),a=O(t.right,e,r),o={type:"LogicalExpression",operator:t.operator,left:n,right:a,start:t.start,end:t.end};return j.recursive(o,e,{CallExpression(i,s){i._transformed||D(i,s)}}),o}function fe(t,e,r){return j.recursive(t,{parent:t,inNamespaceCall:!1},{Identifier(n,a,o){if(n.name=="NaN")return;if(n.name=="na"){n.name="NaN";return}n.parent=a.parent,$(n,e);const i=n.parent&&n.parent.type==="BinaryExpression";(n.parent&&n.parent.type==="ConditionalExpression"||i)&&(n.type==="MemberExpression"?k(n,e):n.type==="Identifier"&&(n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.object&&n.parent.callee.object.name===A&&n.parent.callee.property.name==="get"||B(n)))},MemberExpression(n,a,o){k(n,e),n.object&&o(n.object,{parent:n,inNamespaceCall:a.inNamespaceCall})},CallExpression(n,a,o){const i=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&e.isContextBound(n.callee.object.name);D(n,e),n.arguments.forEach(s=>o(s,{parent:n,inNamespaceCall:i||a.inNamespaceCall}))}}),{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(r),y.createIdentifier("param")),arguments:[t,U,e.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function Z(t,e,r){const n=O(t.argument,e,r);return{type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:n,start:t.start,end:t.end}}function K(t,e,r){switch(t?.type){case"BinaryExpression":t=Y(t,r,e);break;case"LogicalExpression":t=he(t,r,e);break;case"ConditionalExpression":return fe(t,r,e);case"UnaryExpression":t=Z(t,r,e);break}if(t.type==="MemberExpression"&&t.computed&&t.property){const n=t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)?t.object:L(t.object,r),a=t.property.type==="Identifier"&&!r.isContextBound(t.property.name)&&!r.isLoopVariable(t.property.name)?L(t.property,r):t.property;return{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(e),y.createIdentifier("param")),arguments:[n,a,r.nextParamIdArg],_transformed:!0,_isParamCall:!0}}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(n=>{if(n.value.name){const[a,o]=r.getVariable(n.value.name);return{type:"Property",key:{type:"Identifier",name:n.key.name},value:y.createContextVariableReference(o,a),kind:"init",method:!1,shorthand:!1,computed:!1}}return n})),t.type==="Identifier"){if(t.name==="na")return t.name="NaN",t;if(r.isContextBound(t.name)&&!r.isRootParam(t.name))return{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(e),y.createIdentifier("param")),arguments:[t,U,r.nextParamIdArg],_transformed:!0,_isParamCall:!0}}return t?.type==="CallExpression"&&D(t,r),{type:"CallExpression",callee:y.createMemberExpression(y.createIdentifier(e),y.createIdentifier("param")),arguments:[t.type==="Identifier"?L(t,r):t,U,r.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function D(t,e,r){if(!t._transformed){if(t.callee&&t.callee.type==="MemberExpression"&&t.callee.object&&t.callee.object.type==="Identifier"&&(e.isContextBound(t.callee.object.name)||t.callee.object.name==="math"||t.callee.object.name==="ta")){if(t.callee.object.name===A&&["get","init","param"].includes(t.callee.property.name))return;const n=t.callee.object.name;t.arguments=t.arguments.map(a=>a._isParamCall?a:K(a,n,e)),n==="ta"&&t.arguments.push(e.getNextTACallId()),t._transformed=!0}else t.callee&&t.callee.type==="Identifier"&&(t.arguments=t.arguments.map(n=>n._isParamCall?n:K(n,A,e)),t._transformed=!0);t.arguments.forEach(n=>{j.recursive(n,e,{Identifier(a,o,i){a.parent=o.parent,$(a,e);const s=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||s)&&(a.type==="MemberExpression"?k(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===A&&a.parent.callee.property.name==="get"||B(a)))},CallExpression(a,o,i){a._transformed||D(a,o)},MemberExpression(a,o,i){T(a,"",e),a.object&&i(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})}})})}}function ee(t,e){let r=null;if(t.left.type==="Identifier"){const[n,a]=e.getVariable(t.left.name);r=y.createContextVariableReference(a,n)}else if(t.left.type==="MemberExpression"&&t.left.computed&&t.left.object.type==="Identifier"){const n=t.left.object.name,[a,o]=e.getVariable(n),i=a!==n,s=e.isContextBound(n);(i||s)&&!e.isLoopVariable(n)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(r=y.createContextVariableReference(o,a))}if(j.recursive(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(n,a,o){n.name=="na"&&(n.name="NaN"),n.parent=a.parent,$(n,e);const i=n.parent&&n.parent.type==="BinaryExpression",s=n.parent&&n.parent.type==="ConditionalExpression",c=e.isContextBound(n.name)&&!e.isRootParam(n.name),u=n.parent&&n.parent.type==="MemberExpression"&&n.parent.computed&&n.parent.object===n,h=n.parent&&n.parent._isParamCall,f=n.parent&&n.parent.type==="MemberExpression",m=n.name==="NaN",p=n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.object&&n.parent.callee.object.name===A&&n.parent.callee.property.name==="get";(c||s||i)&&(n.type==="MemberExpression"?k(n,e):n.type==="Identifier"&&!f&&!u&&!h&&!m&&!p&&B(n))},MemberExpression(n,a,o){T(n,"",e),n.type==="CallExpression"?n.arguments.forEach(i=>o(i,{parent:n,inNamespaceCall:a.inNamespaceCall})):n.object&&o(n.object,{parent:n,inNamespaceCall:a.inNamespaceCall})},CallExpression(n,a,o){const i=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&e.isContextBound(n.callee.object.name);D(n,e),n.arguments.forEach(s=>o(s,{parent:n,inNamespaceCall:i||a.inNamespaceCall}))}}),r){let n=t.right;if(t.operator!=="="){const o=t.operator.replace("=",""),i=y.createGetCall(r,0);n={type:"BinaryExpression",operator:o,left:i,right:t.right,start:t.start,end:t.end}}const a=y.createSetCall(r,n);t.start&&(a.start=t.start),t.end&&(a.end=t.end),Object.assign(t,a)}}function te(t,e){t.declarations.forEach(r=>{r.init.name=="na"&&(r.init.name="NaN");const n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===A||r.init.object.name==="context2"),a=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===A||r.init.object.object.name==="context2"),o=r.init&&r.init.type==="ArrowFunctionExpression";if(n){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.name=A;return}if(a){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.object.name=A;return}o&&r.init.params.forEach(p=>{p.type==="Identifier"&&e.addContextBoundVar(p.name)});const i=e.addVariable(r.id.name,t.kind),s=t.kind;r.init&&!o&&(r.init.type==="CallExpression"&&r.init.callee.type==="MemberExpression"&&r.init.callee.object&&r.init.callee.object.type==="Identifier"&&e.isContextBound(r.init.callee.object.name)?D(r.init,e):j.recursive(r.init,{parent:r.init},{Identifier(p,d){p.parent=d.parent,$(p,e);const b=p.parent&&p.parent.type==="BinaryExpression",x=p.parent&&p.parent.type==="ConditionalExpression",S=p.parent&&p.parent.type==="CallExpression"&&p.parent.callee&&p.parent.callee.object&&p.parent.callee.object.name===A&&p.parent.callee.property.name==="get";p.type==="Identifier"&&(b||x)&&!S&&B(p)},CallExpression(p,d,b){p.callee.type==="Identifier"&&(p.callee.parent=p),p.arguments.forEach(x=>{x.type==="Identifier"&&(x.parent=p)}),D(p,e),p.arguments.forEach(x=>b(x,{parent:p}))},BinaryExpression(p,d,b){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),b(p.left,{parent:p}),b(p.right,{parent:p})},MemberExpression(p,d,b){p.object&&p.object.type==="Identifier"&&(p.object.parent=p),p.property&&p.property.type==="Identifier"&&(p.property.parent=p),T(p,"",e),p.type==="CallExpression"?p.arguments.forEach(x=>b(x,{parent:p})):p.object&&b(p.object,{parent:p})}}));const c=y.createContextVariableReference(s,i),u=e.isArrayPatternElement(r.id.name),h=!u&&r.init&&r.init.type==="MemberExpression"&&r.init.computed&&r.init.property&&(r.init.property.type==="Literal"||r.init.property.type==="MemberExpression");r.init?.property?.type==="MemberExpression"&&(r.init.property._indexTransformed||(k(r.init.property,e),r.init.property._indexTransformed=!0));let f;r.init?o||u?f=r.init:f=y.createInitCall(c,h?r.init.object:r.init,h?r.init.property:void 0):f=y.createIdentifier("undefined");const m=y.createExpressionStatement(y.createAssignmentExpression(c,f));if(u){m.expression.right.object.property.name+=`?.[0][${r.init.property.value}]`;const p=m.expression.right.object;m.expression.right=y.createCallExpression(y.createMemberExpression(y.createContextIdentifier(),y.createIdentifier("init")),[c,p])}o&&(e.pushScope("fn"),j.recursive(r.init.body,e,{BlockStatement(p,d,b){p.body.forEach(x=>b(x,d))},IfStatement(p,d,b){d.pushScope("if"),b(p.consequent,d),p.alternate&&(d.pushScope("els"),b(p.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(p,d){te(p,d)},Identifier(p,d){$(p,d)},AssignmentExpression(p,d){ee(p,d)}}),e.popScope()),Object.assign(t,m)})}function de(t,e,r){if(t.init&&t.init.type==="VariableDeclaration"){const n=t.init.declarations[0],a=n.id.name;e.addLoopVariable(a,a),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:n.init}]},n.init&&j.recursive(n.init,e,{Identifier(o,i){e.isLoopVariable(o.name)||(e.pushScope("for"),$(o,i),e.popScope())},MemberExpression(o){e.pushScope("for"),T(o,"",e),e.popScope()}})}t.test&&j.recursive(t.test,e,{Identifier(n,a){!e.isLoopVariable(n.name)&&!n.computed&&(e.pushScope("for"),$(n,a),n.type==="Identifier"&&(n.computed=!0,B(n)),e.popScope())},MemberExpression(n){e.pushScope("for"),T(n,"",e),e.popScope()}}),t.update&&j.recursive(t.update,e,{Identifier(n,a){e.isLoopVariable(n.name)||(e.pushScope("for"),$(n,a),e.popScope())}}),e.pushScope("for"),r(t.body,e),e.popScope()}function ye(t,e){j.recursive(t,e,{MemberExpression(r){T(r,"",e)},CallExpression(r,n){D(r,n)},Identifier(r,n){$(r,n);const a=e.getCurrentScopeType()==="if";e.isContextBound(r.name)&&!e.isRootParam(r.name)&&a&&B(r)}})}function ge(t,e,r){t.test&&(e.pushScope("if"),ye(t.test,e),e.popScope()),e.pushScope("if"),r(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),r(t.alternate,e),e.popScope())}function be(t,e){const r=e.getCurrentScopeType();if(t.argument&&(t.argument.type==="ArrayExpression"?(t.argument.elements=t.argument.elements.map(n=>{if(n.type==="Identifier"){if(e.isContextBound(n.name)&&!e.isRootParam(n.name))return y.createArrayAccess(n,0);const[a,o]=e.getVariable(n.name);return y.createContextVariableAccess0(o,a)}else if(n.type==="MemberExpression")return n.computed&&n.object.type==="Identifier"&&e.isContextBound(n.object.name)&&!e.isRootParam(n.object.name)||T(n,"",e),n;return n}),t.argument={type:"ArrayExpression",elements:[t.argument]}):t.argument.type==="BinaryExpression"?j.recursive(t.argument,e,{Identifier(n,a){$(n,a),n.type==="Identifier"&&B(n)},MemberExpression(n){T(n,"",e)}}):t.argument.type==="ObjectExpression"?t.argument.properties=t.argument.properties.map(n=>{if(n.shorthand){const[a,o]=e.getVariable(n.value.name);return{type:"Property",key:y.createIdentifier(n.key.name),value:y.createContextVariableReference(o,a),kind:"init",method:!1,shorthand:!1,computed:!1}}return n}):t.argument.type==="Identifier"&&($(t.argument,e),t.argument.type==="Identifier"&&B(t.argument)),r==="fn")){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=y.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)&&(t.argument._indexTransformed||(k(t.argument,e),t.argument._indexTransformed=!0)):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression")&&j.recursive(t.argument,e,{Identifier(a,o){$(a,o),a.type==="Identifier"&&!a._arrayAccessed&&(B(a),a._arrayAccessed=!0)},MemberExpression(a){T(a,"",e)},CallExpression(a,o){D(a,o)}});const n=y.createCallExpression(y.createMemberExpression(y.createContextIdentifier(),y.createIdentifier("precision")),[t.argument]);t.argument=n}}function we(t,e,r){t.body&&t.body.type==="BlockStatement"&&(e.pushScope("fn"),r(t.body,e),e.popScope())}function xe(t){j.simple(t,{BinaryExpression(e){if(e.operator==="=="||e.operator==="==="){const r=e.left,n=e.right,a=y.createMathEqCall(r,n);a._transformed=!0,Object.assign(e,a)}}})}function ve(t,e,r){j.recursive(t,e,{BlockStatement(n,a,o){n.body.forEach(i=>o(i,a))},ReturnStatement(n,a){be(n,a)},VariableDeclaration(n,a){te(n,a)},Identifier(n,a){$(n,a)},CallExpression(n,a){D(n,a)},MemberExpression(n,a){T(n,r,a)},AssignmentExpression(n,a){ee(n,a)},FunctionDeclaration(n,a,o){we(n,a,o)},ForStatement(n,a,o){de(n,a,o)},IfStatement(n,a,o){ge(n,a,o)}})}function Ce(t){let e=typeof t=="function"?t.toString():t;const r=re.parse(e.trim(),{ecmaVersion:"latest",sourceType:"module"});ce(r);const n=new se;pe(r,n);const a=me(r,n)||"";ve(r,n,a),xe(r);const o=ne.generate(r);return new Function("",`return ${o}`)(this)}class l{constructor(e,r=0){this.data=e,this.offset=r}get(e){const r=this.data.length-1-(this.offset+e);return r<0||r>=this.data.length?NaN:this.data[r]}set(e,r){const n=this.data.length-1-(this.offset+e);n>=0&&n<this.data.length&&(this.data[n]=r)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof l?e:Array.isArray(e)?new l(e):new l([e])}}var Ee=Object.defineProperty,Se=(t,e,r)=>e in t?Ee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,je=(t,e,r)=>Se(t,typeof e!="symbol"?e+"":e,r);class Ae{constructor(e){this.context=e,je(this,"color",{param:(r,n=0)=>l.from(r).get(n),rgb:(r,n,a,o)=>o?`rgba(${r}, ${n}, ${a}, ${o})`:`rgb(${r}, ${n}, ${a})`,new:(r,n)=>{if(r&&r.startsWith("#")){const a=r.slice(1),o=parseInt(a.slice(0,2),16),i=parseInt(a.slice(2,4),16),s=parseInt(a.slice(4,6),16);return n?`rgba(${o}, ${i}, ${s}, ${n})`:`rgb(${o}, ${i}, ${s})`}return n?`rgba(${r}, ${n})`:r},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue"})}extractPlotOptions(e){const r={};for(let n in e)r[n]=l.from(e[n]).get(0);return r}indicator(e,r,n){}plotchar(e,r,n){this.context.plots[r]||(this.context.plots[r]={data:[],options:this.extractPlotOptions(n),title:r});const a=l.from(e).get(0);this.context.plots[r].data.push({time:this.context.marketData[this.context.idx].openTime,value:a,options:{...this.extractPlotOptions(n),style:"char"}})}plot(e,r,n){this.context.plots[r]||(this.context.plots[r]={data:[],options:this.extractPlotOptions(n),title:r});const a=l.from(e).get(0);this.context.plots[r].data.push({time:this.context.marketData[this.context.idx].openTime,value:a,options:this.extractPlotOptions(n)})}na(e){return isNaN(l.from(e).get(0))}nz(e,r=0){const n=l.from(e).get(0),a=l.from(r).get(0);return isNaN(n)?a:n}}function Me(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Ie(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Ne(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function _e(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function $e(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Ve(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Te(t){return(e,r=0)=>[l.from(e).get(r)]}function De(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Pe(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Be(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function ke(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Le(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Oe(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Re(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}function Fe(t){return(e,{title:r,group:n}={})=>Array.isArray(e)?e[0]:e}var qe=Object.defineProperty,We=(t,e,r)=>e in t?qe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,M=(t,e,r)=>We(t,typeof e!="symbol"?e+"":e,r);const Ge={any:Me,bool:Ie,color:Ne,enum:_e,float:$e,int:Ve,param:Te,price:De,session:Pe,source:Be,string:ke,symbol:Le,text_area:Oe,time:Re,timeframe:Fe};class Ue{constructor(e){this.context=e,M(this,"any"),M(this,"bool"),M(this,"color"),M(this,"enum"),M(this,"float"),M(this,"int"),M(this,"param"),M(this,"price"),M(this,"session"),M(this,"source"),M(this,"string"),M(this,"symbol"),M(this,"text_area"),M(this,"time"),M(this,"timeframe"),Object.entries(Ge).forEach(([r,n])=>{this[r]=n(e)})}}function ze(t){return e=>Math.abs(l.from(e).get(0))}function Ke(t){return e=>Math.acos(l.from(e).get(0))}function He(t){return e=>Math.asin(l.from(e).get(0))}function Xe(t){return e=>Math.atan(l.from(e).get(0))}function Je(t){return(...e)=>{const r=e.map(n=>l.from(n).get(0));return r.reduce((n,a)=>n+a,0)/r.length}}function Qe(t){return e=>Math.ceil(l.from(e).get(0))}function Ye(t){return e=>Math.cos(l.from(e).get(0))}function Ze(t){return e=>Math.exp(l.from(e).get(0))}function et(t){return e=>Math.floor(l.from(e).get(0))}function tt(t){return e=>Math.log(l.from(e).get(0))}function rt(t){return e=>Math.log(l.from(e).get(0))}function nt(t){return e=>Math.log10(l.from(e).get(0))}function at(t){return(...e)=>{const r=e.map(n=>l.from(n).get(0));return Math.max(...r)}}function it(t){return(...e)=>{const r=e.map(n=>l.from(n).get(0));return Math.min(...r)}}function ot(t){return(e,r,n)=>typeof e=="string"?e:e instanceof l?r?new l(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new l(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new l(t.params[n],0)))}function st(t){return(e,r)=>Math.pow(l.from(e).get(0),l.from(r).get(0))}function ct(t){return()=>Math.random()}function pt(t){return e=>Math.round(l.from(e).get(0))}function lt(t){return e=>Math.sin(l.from(e).get(0))}function ut(t){return e=>Math.sqrt(l.from(e).get(0))}function mt(t){return(e,r)=>{const n=l.from(r).get(0),a=l.from(e);let o=0;for(let i=0;i<n;i++){const s=a.get(i);isNaN(s)||(o+=s)}return o}}function ht(t){return e=>Math.tan(l.from(e).get(0))}function ft(t){return(e,r)=>{const n=l.from(e).get(0),a=l.from(r).get(0);return isNaN(n)&&isNaN(a)?!0:isNaN(n)||isNaN(a)?!1:Math.abs(n-a)<1e-8}}var dt=Object.defineProperty,yt=(t,e,r)=>e in t?dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,E=(t,e,r)=>yt(t,typeof e!="symbol"?e+"":e,r);const gt={abs:ze,acos:Ke,asin:He,atan:Xe,avg:Je,ceil:Qe,cos:Ye,exp:Ze,floor:et,ln:tt,log:rt,log10:nt,max:at,min:it,param:ot,pow:st,random:ct,round:pt,sin:lt,sqrt:ut,sum:mt,tan:ht,__eq:ft};class bt{constructor(e){this.context=e,E(this,"_cache",{}),E(this,"abs"),E(this,"acos"),E(this,"asin"),E(this,"atan"),E(this,"avg"),E(this,"ceil"),E(this,"cos"),E(this,"exp"),E(this,"floor"),E(this,"ln"),E(this,"log"),E(this,"log10"),E(this,"max"),E(this,"min"),E(this,"param"),E(this,"pow"),E(this,"random"),E(this,"round"),E(this,"sin"),E(this,"sqrt"),E(this,"sum"),E(this,"tan"),E(this,"__eq"),Object.entries(gt).forEach(([r,n])=>{this[r]=n(e)})}}function wt(t){return(e,r,n)=>(t.params[n]||(t.params[n]=[]),e instanceof l||Array.isArray(e)?[l.from(e).get(r||0),n]:(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,[e,n]))}const H=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function X(t,e,r,n,a=!1){for(let o=0;o<r.length;o++)if(r[o]<=t&&e<=n[o])return o+(a?1:2);return-1}function xt(t){return async(e,r,n,a=!1,o=!1,i=!1,s=null,c=null)=>{const u=e[0],h=r[0],f=n[0],m=n[1],p=H.indexOf(t.timeframe),d=H.indexOf(h);if(p==-1||d==-1)throw new Error("Invalid timeframe");if(p>d)throw new Error("Only higher timeframes are supported for now");if(p===d)return f;const b=t.data.openTime[0],x=t.data.closeTime[0];if(t.cache[m]){const P=t.cache[m],w=X(b,x,P.data.openTime,P.data.closeTime,o);return w==-1?NaN:P.params[m][w]}const S=await new Zr(t.source,u,h,t.limit||1e3,t.sDate,t.eDate).run(t.pineTSCode);t.cache[m]=S;const V=X(b,x,S.data.openTime,S.data.closeTime,o);return V==-1?NaN:S.params[m][V]}}var vt=Object.defineProperty,Ct=(t,e,r)=>e in t?vt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,W=(t,e,r)=>Ct(t,typeof e!="symbol"?e+"":e,r);const Et={param:wt,security:xt};class St{constructor(e){this.context=e,W(this,"_cache",{}),W(this,"param"),W(this,"security"),Object.entries(Et).forEach(([r,n])=>{this[r]=n(e)})}}function jt(t){return()=>{const e=t.get(t.data.high,0),r=t.get(t.data.low,0),n=t.get(t.data.close,1);return isNaN(n)?e-r:Math.max(e-r,Math.abs(e-n),Math.abs(r-n))}}function At(t){return(e,r)=>{const n=l.from(e).get(0);t.taState||(t.taState={});const a=r||`atr_${n}`;t.taState[a]||(t.taState[a]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const o=t.taState[a],i=t.get(t.data.high,0),s=t.get(t.data.low,0),c=t.get(t.data.close,0);let u;if(o.prevClose!==null){const f=i-s,m=Math.abs(i-o.prevClose),p=Math.abs(s-o.prevClose);u=Math.max(f,m,p)}else u=i-s;if(o.prevClose=c,o.initCount<n)return o.initSum+=u,o.initCount++,o.initCount===n?(o.prevAtr=o.initSum/n,t.precision(o.prevAtr)):NaN;const h=(o.prevAtr*(n-1)+u)/n;return o.prevAtr=h,t.precision(h)}}function Mt(t){return(e,r=1,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`change_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<=a)return NaN;i.window.length>a+1&&i.window.pop();const c=s-i.window[a];return t.precision(c)}}function It(t){return(e,r)=>{const n=l.from(e),a=l.from(r),o=n.get(0),i=a.get(0),s=n.get(1),c=a.get(1);return s<c&&o>i}}function Nt(t){return(e,r)=>{const n=l.from(e),a=l.from(r),o=n.get(0),i=a.get(0),s=n.get(1),c=a.get(1);return s>c&&o<i}}function _t(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`dev_${a}`;t.taState[o]||(t.taState[o]={window:[],sum:0});const i=t.taState[o],s=l.from(e).get(0)||0;if(i.window.unshift(s),i.sum+=s,i.window.length<a)return NaN;if(i.window.length>a){const f=i.window.pop();i.sum-=f}const c=i.sum/a;let u=0;for(let f=0;f<a;f++)u+=Math.abs(i.window[f]-c);const h=u/a;return t.precision(h)}}function $t(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`ema_${a}`;t.taState[o]||(t.taState[o]={prevEma:null,initSum:0,initCount:0});const i=t.taState[o],s=l.from(e).get(0);if(i.initCount<a)return i.initSum+=s,i.initCount++,i.initCount===a?(i.prevEma=i.initSum/a,t.precision(i.prevEma)):NaN;const c=2/(a+1),u=s*c+i.prevEma*(1-c);return i.prevEma=u,t.precision(u)}}function Vt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`highest_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=Math.max(...i.window.filter(u=>!isNaN(u)));return t.precision(c)}}function Tt(t){return(e,r,n)=>{const a=l.from(r).get(0),o=Math.floor(a/2),i=Math.floor(Math.sqrt(a)),s=t.ta.wma,c=s(e,o,n?`${n}_wma1`:void 0),u=s(e,a,n?`${n}_wma2`:void 0);if(isNaN(c)||isNaN(u))return NaN;t.taState||(t.taState={});const h=n||`hma_raw_${a}`;t.taState[h]||(t.taState[h]=[]);const f=2*c-u;t.taState[h].unshift(f);const m=n?`${n}_hma_final`:`hma_final_${a}`;t.taState[m]||(t.taState[m]={window:[]});const p=t.taState[m];if(p.window.unshift(f),p.window.length<i)return NaN;p.window.length>i&&p.window.pop();let d=0,b=0;for(let S=0;S<i;S++){const V=i-S;d+=p.window[S]*V,b+=V}const x=d/b;return t.precision(x)}}function Dt(t){return(e,r,n,a)=>{const o=l.from(r).get(0),i=l.from(n).get(0);t.taState||(t.taState={});const s=a||`linreg_${o}_${i}`;t.taState[s]||(t.taState[s]={window:[]});const c=t.taState[s],u=l.from(e).get(0);if(c.window.unshift(u),c.window.length<o)return NaN;c.window.length>o&&c.window.pop();let h=0,f=0,m=0,p=0;const d=o;for(let V=0;V<o;V++){const P=o-1-V,w=c.window[V];h+=P,f+=w,m+=P*w,p+=P*P}const b=d*p-h*h;if(b===0)return NaN;const x=(d*m-h*f)/b,S=(f-x*h)/d+x*(o-1-i);return t.precision(S)}}function Pt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`lowest_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=i.window.filter(h=>!isNaN(h)&&h!==void 0),u=c.length>0?Math.min(...c):NaN;return t.precision(u)}}function Bt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`median_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=i.window.slice().sort((f,m)=>f-m),u=Math.floor(a/2),h=a%2===0?(c[u-1]+c[u])/2:c[u];return t.precision(h)}}function kt(t){return(e,r,n)=>{const a=l.from(r).get(0);return t.ta.change(e,a)}}function Lt(t){return(e,r,n)=>e instanceof l?r?new l(e.data,e.offset+r):e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new l(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new l(t.params[n],0)))}function Ot(t,e,r){const n=new Array(t.length).fill(NaN);for(let a=e+r;a<t.length;a++){const o=t[a-r];let i=!0;for(let s=1;s<=e;s++)if(t[a-r-s]>=o){i=!1;break}if(i){for(let s=1;s<=r;s++)if(t[a-r+s]>=o){i=!1;break}}i&&(n[a]=o)}return n}function Rt(t){return(e,r,n)=>{n==null&&(n=r,r=e,e=t.data.high);const a=l.from(r).get(0),o=l.from(n).get(0),i=l.from(e).toArray(),s=Ot(i,a,o),c=t.idx;return t.precision(s[c])}}function Ft(t,e,r){const n=new Array(t.length).fill(NaN);for(let a=e+r;a<t.length;a++){const o=t[a-r];let i=!0;for(let s=1;s<=e;s++)if(t[a-r-s]<=o){i=!1;break}if(i){for(let s=1;s<=r;s++)if(t[a-r+s]<=o){i=!1;break}}i&&(n[a]=o)}return n}function qt(t){return(e,r,n)=>{n==null&&(n=r,r=e,e=t.data.low);const a=l.from(r).get(0),o=l.from(n).get(0),i=l.from(e).toArray(),s=Ft(i,a,o),c=t.idx;return t.precision(s[c])}}function Wt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`rma_${a}`;t.taState[o]||(t.taState[o]={prevRma:null,initSum:0,initCount:0});const i=t.taState[o],s=l.from(e).get(0)||0;if(i.initCount<a)return i.initSum+=s,i.initCount++,i.initCount===a?(i.prevRma=i.initSum/a,t.precision(i.prevRma)):NaN;const c=1/a,u=s*c+i.prevRma*(1-c);return i.prevRma=u,t.precision(u)}}function Gt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`roc_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<=a)return NaN;i.window.length>a+1&&i.window.pop();const c=i.window[a],u=(s-c)/c*100;return t.precision(u)}}function Ut(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`rsi_${a}`;t.taState[o]||(t.taState[o]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.prevValue!==null){const c=s-i.prevValue,u=c>0?c:0,h=c<0?-c:0;if(i.initGains.length<a){if(i.initGains.push(u),i.initLosses.push(h),i.initGains.length===a){i.avgGain=i.initGains.reduce((p,d)=>p+d,0)/a,i.avgLoss=i.initLosses.reduce((p,d)=>p+d,0)/a,i.prevValue=s;const m=i.avgLoss===0?100:100-100/(1+i.avgGain/i.avgLoss);return t.precision(m)}return i.prevValue=s,NaN}i.avgGain=(i.avgGain*(a-1)+u)/a,i.avgLoss=(i.avgLoss*(a-1)+h)/a;const f=i.avgLoss===0?100:100-100/(1+i.avgGain/i.avgLoss);return i.prevValue=s,t.precision(f)}return i.prevValue=s,NaN}}function zt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`sma_${a}`;t.taState[o]||(t.taState[o]={window:[],sum:0});const i=t.taState[o],s=l.from(e).get(0)||0;if(i.window.unshift(s),i.sum+=s,i.window.length<a)return NaN;if(i.window.length>a){const u=i.window.pop();i.sum-=u}const c=i.sum/a;return t.precision(c)}}function Kt(t){return(e,r,n=!0,a)=>{const o=l.from(r).get(0),i=l.from(n).get(0);t.taState||(t.taState={});const s=a||`stdev_${o}_${i}`;t.taState[s]||(t.taState[s]={window:[],sum:0});const c=t.taState[s],u=l.from(e).get(0);if(c.window.unshift(u),c.sum+=u,c.window.length<o)return NaN;if(c.window.length>o){const d=c.window.pop();c.sum-=d}const h=c.sum/o;let f=0;for(let d=0;d<o;d++)f+=Math.pow(c.window[d]-h,2);const m=i?o:o-1,p=Math.sqrt(f/m);return t.precision(p)}}function Ht(t){return(e,r,n)=>{const a=l.from(e).get(0),o=l.from(r).get(0);t.taState||(t.taState={});const i=`supertrend_${a}_${o}`;t.taState[i]||(t.taState[i]={prevUpperBand:null,prevLowerBand:null,prevSupertrend:null,prevDirection:null});const s=t.taState[i],c=t.get(t.data.high,0),u=t.get(t.data.low,0),h=t.get(t.data.close,0),f=t.get(t.data.close,1),m=t.ta.atr(o,n?`${n}_atr`:void 0);if(isNaN(m))return[[NaN,0]];const p=(c+u)/2;let d=p+a*m,b=p-a*m;s.prevUpperBand!==null&&(d<s.prevUpperBand||f>s.prevUpperBand?d=d:d=s.prevUpperBand,b>s.prevLowerBand||f<s.prevLowerBand?b=b:b=s.prevLowerBand);let x,S;return s.prevSupertrend===null?(x=h<=d?-1:1,S=x===-1?d:b):s.prevSupertrend===s.prevUpperBand?h>d?(x=1,S=b):(x=-1,S=d):h<b?(x=-1,S=d):(x=1,S=b),s.prevUpperBand=d,s.prevLowerBand=b,s.prevSupertrend=S,s.prevDirection=x,[[t.precision(S),x]]}}function Xt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`variance_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();let c=0,u=0;for(let m=0;m<a;m++)c+=i.window[m],u+=i.window[m]*i.window[m];const h=c/a,f=u/a-h*h;return t.precision(f)}}function Jt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`vwma_${a}`;t.taState[o]||(t.taState[o]={window:[],volumeWindow:[]});const i=t.taState[o],s=l.from(e).get(0),c=t.get(t.data.volume,0);if(i.window.unshift(s),i.volumeWindow.unshift(c),i.window.length<a)return NaN;i.window.length>a&&(i.window.pop(),i.volumeWindow.pop());let u=0,h=0;for(let m=0;m<a;m++)u+=i.window[m]*i.volumeWindow[m],h+=i.volumeWindow[m];const f=u/h;return t.precision(f)}}function Qt(t){return(e,r,n)=>{const a=l.from(r).get(0);t.taState||(t.taState={});const o=n||`wma_${a}`;t.taState[o]||(t.taState[o]={window:[]});const i=t.taState[o],s=l.from(e).get(0);if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();let c=0,u=0;for(let f=0;f<a;f++){const m=a-f;c+=i.window[f]*m,u+=m}const h=c/u;return t.precision(h)}}var Yt=Object.defineProperty,Zt=(t,e,r)=>e in t?Yt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,C=(t,e,r)=>Zt(t,typeof e!="symbol"?e+"":e,r);const er={tr:jt},tr={atr:At,change:Mt,crossover:It,crossunder:Nt,dev:_t,ema:$t,highest:Vt,hma:Tt,linreg:Dt,lowest:Pt,median:Bt,mom:kt,param:Lt,pivothigh:Rt,pivotlow:qt,rma:Wt,roc:Gt,rsi:Ut,sma:zt,stdev:Kt,supertrend:Ht,variance:Xt,vwma:Jt,wma:Qt};class rr{constructor(e){this.context=e,C(this,"tr"),C(this,"atr"),C(this,"change"),C(this,"crossover"),C(this,"crossunder"),C(this,"dev"),C(this,"ema"),C(this,"highest"),C(this,"hma"),C(this,"linreg"),C(this,"lowest"),C(this,"median"),C(this,"mom"),C(this,"param"),C(this,"pivothigh"),C(this,"pivotlow"),C(this,"rma"),C(this,"roc"),C(this,"rsi"),C(this,"sma"),C(this,"stdev"),C(this,"supertrend"),C(this,"variance"),C(this,"vwma"),C(this,"wma"),Object.entries(er).forEach(([r,n])=>{Object.defineProperty(this,r,{get:n(e),enumerable:!0})}),Object.entries(tr).forEach(([r,n])=>{this[r]=n(e)})}}class N{constructor(e){this.array=e}toString(){return"PineArrayObject:"+this.array.toString()}}function nr(t){return e=>new N(e.array.map(r=>Math.abs(r)))}function ar(t){return e=>t.array.sum(e)/e.array.length}function ir(t){return e=>{e.array.length=0}}function or(t){return(e,r)=>(e.array.push(...r.array),e)}function sr(t){return e=>new N([...e.array])}function cr(t){return(e,r,n=!0)=>{if(e.array.length!==r.array.length||e.array.length<2)return NaN;const a=n?e.array.length:e.array.length-1,o=t.array.avg(e),i=t.array.avg(r);let s=0;for(let c=0;c<e.array.length;c++)s+=(e.array[c]-o)*(r.array[c]-i);return s/a}}function pr(t){return(e,r)=>e.array.every(r)}function lr(t){return(e,r,n=0,a)=>{const o=e.array.length,i=a!==void 0?Math.min(a,o):o;for(let s=n;s<i;s++)e.array[s]=r}}function ur(t){return e=>e.array.length>0?e.array[0]:t.NA}function mr(t){return e=>new N([...e])}function hr(t){return(e,r)=>e.array[r]}function fr(t){return(e,r)=>e.array.includes(r)}function dr(t){return(e,r)=>e.array.indexOf(r)}function yr(t){return(e,r,n)=>{e.array.splice(r,0,n)}}function gr(t){return(e,r=",")=>e.array.join(r)}function br(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function wr(t){return(e,r)=>e.array.lastIndexOf(r)}function xr(t){return(e,r=0)=>[...e.array].sort((n,a)=>a-n)[r]??t.NA}function vr(t){return(e,r=0)=>[...e.array].sort((n,a)=>n-a)[r]??t.NA}function Cr(t){return(e,r)=>new N(Array(e).fill(r))}function Er(t){return(e,r=!1)=>new N(Array(e).fill(r))}function Sr(t){return(e,r=NaN)=>new N(Array(e).fill(r))}function jr(t){return(e,r=0)=>new N(Array(e).fill(Math.round(r)))}function Ar(t){return(e,r="")=>new N(Array(e).fill(r))}function Mr(t){return(e,r=0)=>l.from(e).get(r)}function Ir(t){return e=>e.array.pop()}function Nr(t){return(e,r)=>{e.array.push(r)}}function _r(t){return e=>t.array.max(e)-t.array.min(e)}function $r(t){return(e,r)=>r>=0&&r<e.array.length?e.array.splice(r,1)[0]:t.NA}function Vr(t){return e=>{e.array.reverse()}}function Tr(t){return(e,r,n)=>{e.array[r]=n}}function Dr(t){return e=>e.array.shift()}function Pr(t){return e=>e.array.length}function Br(t){return(e,r,n)=>{const a=n!==void 0?n+1:void 0;return new N(e.array.slice(r,a))}}function kr(t){return(e,r)=>e.array.some(r)}function Lr(t){return(e,r="asc")=>{e.array.sort((n,a)=>r==="asc"?n-a:a-n)}}function Or(t){return(e,r)=>{const n=e.array.map((a,o)=>o);return n.sort((a,o)=>{const i=e.array[a],s=e.array[o];return r?r(i,s):i-s}),new N(n)}}function Rr(t){return e=>{const r=t.array.avg(e),n=t.array.stdev(e);return n===0?new N(e.array.map(()=>0)):new N(e.array.map(a=>(a-r)/n))}}function Fr(t){return(e,r=!0)=>{const n=t.array.avg(e),a=e.array.map(i=>Math.pow(i-n,2)),o=r?e.array.length:e.array.length-1;return Math.sqrt(t.array.sum(new N(a))/o)}}function qr(t){return e=>e.array.reduce((r,n)=>r+(isNaN(n)?0:n),0)}function Wr(t){return(e,r)=>{e.array.unshift(r)}}function Gr(t){return(e,r=!0)=>{const n=t.array.avg(e),a=e.array.map(i=>Math.pow(i-n,2)),o=r?e.array.length:e.array.length-1;return t.array.sum(new N(a))/o}}var Ur=Object.defineProperty,zr=(t,e,r)=>e in t?Ur(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,g=(t,e,r)=>zr(t,typeof e!="symbol"?e+"":e,r);const Kr={abs:nr,avg:ar,clear:ir,concat:or,copy:sr,covariance:cr,every:pr,fill:lr,first:ur,from:mr,get:hr,includes:fr,indexof:dr,insert:yr,join:gr,last:br,lastindexof:wr,max:xr,min:vr,new:Cr,new_bool:Er,new_float:Sr,new_int:jr,new_string:Ar,param:Mr,pop:Ir,push:Nr,range:_r,remove:$r,reverse:Vr,set:Tr,shift:Dr,size:Pr,slice:Br,some:kr,sort:Lr,sort_indices:Or,standardize:Rr,stdev:Fr,sum:qr,unshift:Wr,variance:Gr};class Hr{constructor(e){this.context=e,g(this,"_cache",{}),g(this,"abs"),g(this,"avg"),g(this,"clear"),g(this,"concat"),g(this,"copy"),g(this,"covariance"),g(this,"every"),g(this,"fill"),g(this,"first"),g(this,"from"),g(this,"get"),g(this,"includes"),g(this,"indexof"),g(this,"insert"),g(this,"join"),g(this,"last"),g(this,"lastindexof"),g(this,"max"),g(this,"min"),g(this,"new"),g(this,"new_bool"),g(this,"new_float"),g(this,"new_int"),g(this,"new_string"),g(this,"param"),g(this,"pop"),g(this,"push"),g(this,"range"),g(this,"remove"),g(this,"reverse"),g(this,"set"),g(this,"shift"),g(this,"size"),g(this,"slice"),g(this,"some"),g(this,"sort"),g(this,"sort_indices"),g(this,"standardize"),g(this,"stdev"),g(this,"sum"),g(this,"unshift"),g(this,"variance"),Object.entries(Kr).forEach(([r,n])=>{this[r]=n(e)})}}var Xr=Object.defineProperty,Jr=(t,e,r)=>e in t?Xr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>Jr(t,typeof e!="symbol"?e+"":e,r);class J{constructor({marketData:e,source:r,tickerId:n,timeframe:a,limit:o,sDate:i,eDate:s}){v(this,"data",{open:[],high:[],low:[],close:[],volume:[],hl2:[],hlc3:[],ohlc4:[]}),v(this,"cache",{}),v(this,"taState",{}),v(this,"NA",NaN),v(this,"math"),v(this,"ta"),v(this,"input"),v(this,"request"),v(this,"array"),v(this,"core"),v(this,"lang"),v(this,"idx",0),v(this,"params",{}),v(this,"const",{}),v(this,"var",{}),v(this,"let",{}),v(this,"result"),v(this,"plots",{}),v(this,"marketData"),v(this,"source"),v(this,"tickerId"),v(this,"timeframe",""),v(this,"limit"),v(this,"sDate"),v(this,"eDate"),v(this,"pineTSCode"),this.marketData=e,this.source=r,this.tickerId=n,this.timeframe=a,this.limit=o,this.sDate=i,this.eDate=s,this.math=new bt(this),this.ta=new rr(this),this.input=new Ue(this),this.request=new St(this),this.array=new Hr(this);const c=new Ae(this);this.core={plotchar:c.plotchar.bind(c),na:c.na.bind(c),color:c.color,plot:c.plot.bind(c),nz:c.nz.bind(c)}}init(e,r,n=0){return r instanceof l&&(r=r.get(0)),e?!Array.isArray(r)||Array.isArray(r[0])?e[e.length-1]=Array.isArray(r?.[0])?r[0]:this.precision(r):e[e.length-1]=this.precision(r[r.length-1+n]):Array.isArray(r)?e=[this.precision(r[r.length-1+n])]:e=[this.precision(r)],e}precision(e,r=10){return typeof e!="number"||isNaN(e)?e:Number(e.toFixed(r))}param(e,r,n){return typeof e=="string"?e:e instanceof l?r?new l(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[n]||(this.params[n]=[]),Array.isArray(e)?new l(e,r||0):(this.params[n].length===0?this.params[n].push(e):this.params[n][this.params[n].length-1]=e,new l(this.params[n],0)))}get(e,r){if(e instanceof l)return e.get(r);if(Array.isArray(e)){const n=e.length-1-r;return n<0||n>=e.length?NaN:e[n]}return e}set(e,r){if(e instanceof l){e.set(0,r);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=r:e.push(r);return}}}var Qr=Object.defineProperty,Yr=(t,e,r)=>e in t?Qr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,I=(t,e,r)=>Yr(t,typeof e!="symbol"?e+"":e,r);class Zr{constructor(e,r,n,a,o,i){this.source=e,this.tickerId=r,this.timeframe=n,this.limit=a,this.sDate=o,this.eDate=i,I(this,"data",[]),I(this,"open",[]),I(this,"high",[]),I(this,"low",[]),I(this,"close",[]),I(this,"volume",[]),I(this,"hl2",[]),I(this,"hlc3",[]),I(this,"ohlc4",[]),I(this,"openTime",[]),I(this,"closeTime",[]),I(this,"_readyPromise",null),I(this,"_ready",!1),I(this,"_transpiledCode",null),this._readyPromise=new Promise(s=>{this.loadMarketData(e,r,n,a,o,i).then(c=>{const u=c;this.data=u;const h=u.map(w=>w.open),f=u.map(w=>w.close),m=u.map(w=>w.high),p=u.map(w=>w.low),d=u.map(w=>w.volume),b=u.map(w=>(w.high+w.low+w.close)/3),x=u.map(w=>(w.high+w.low)/2),S=u.map(w=>(w.high+w.low+w.open+w.close)/4),V=u.map(w=>w.openTime),P=u.map(w=>w.closeTime);this.open=h,this.close=f,this.high=m,this.low=p,this.volume=d,this.hl2=x,this.hlc3=b,this.ohlc4=S,this.openTime=V,this.closeTime=P,this._ready=!0,s(!0)})})}get transpiledCode(){return this._transpiledCode}async loadMarketData(e,r,n,a,o,i){return Array.isArray(e)?e:e.getMarketData(r,n,a,o,i)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,r,n){if(n&&n>0){const a=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(e,r,n,a)}else return this._runComplete(e,r)}async _runComplete(e,r){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(e);return this._transpiledCode=this._transpileCode(e),await this._executeIterations(n,this._transpiledCode,this.data.length-r,this.data.length),n}async*_runPaginated(e,r,n,a=!1){await this.ready(),r||(r=this.data.length);const o=this._initializeContext(e);this._transpiledCode=this._transpileCode(e);let i=this.data.length-r;for(;;){const s=this.data.length-i;if(s>0){const h=Math.min(s,n),f=this._getResultLength(o.result);await this._executeIterations(o,this._transpiledCode,i,i+h),i+=h,yield this._createPageContext(o,f);continue}if(!a||Array.isArray(this.source))break;const{newCandles:c,updatedLastCandle:u}=await this._updateMarketData();if(c===0&&!u){yield null;continue}this._removeLastResult(o),i=this.data.length-(c+1)}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const r=Object.keys(e);if(r.length>0&&Array.isArray(e[r[0]]))return e[r[0]].length}return 0}_createPageContext(e,r){const n=new J({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});if(n.pineTSCode=e.pineTSCode,n.idx=e.idx,Array.isArray(e.result))n.result=e.result.slice(r);else if(typeof e.result=="object"&&e.result!==null){n.result={};for(let a in e.result)Array.isArray(e.result[a])?n.result[a]=e.result[a].slice(r):n.result[a]=e.result[a]}else n.result=e.result;return n.plots={...e.plots},n}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const r=this.source,n=this.data.length-1,a=this.data[n].openTime;try{const o=await r.getMarketData(this.tickerId,this.timeframe,void 0,a,e);if(!o||o.length===0)return{newCandles:0,updatedLastCandle:!1};let i=!1,s=0;for(let c=0;c<o.length;c++){const u=o[c];u.openTime===a?(this._replaceCandle(n,u),i=!0):u.openTime>a&&(this._appendCandle(u),s++)}return{newCandles:s,updatedLastCandle:i}}catch(o){return console.error("Error updating market data:",o),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,r){this.data[e]=r,this.open[e]=r.open,this.close[e]=r.close,this.high[e]=r.high,this.low[e]=r.low,this.volume[e]=r.volume,this.hl2[e]=(r.high+r.low)/2,this.hlc3[e]=(r.high+r.low+r.close)/3,this.ohlc4[e]=(r.high+r.low+r.open+r.close)/4,this.openTime[e]=r.openTime,this.closeTime[e]=r.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let r in e.result)Array.isArray(e.result[r])&&e.result[r].pop();e.data.close.pop(),e.data.open.pop(),e.data.high.pop(),e.data.low.pop(),e.data.volume.pop(),e.data.hl2.pop(),e.data.hlc3.pop(),e.data.ohlc4.pop(),e.data.openTime.pop(),e.data.closeTime&&e.data.closeTime.pop()}_initializeContext(e){const r=new J({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});return r.pineTSCode=e,r.data.close=[],r.data.open=[],r.data.high=[],r.data.low=[],r.data.volume=[],r.data.hl2=[],r.data.hlc3=[],r.data.ohlc4=[],r.data.openTime=[],r.data.closeTime=[],r}_transpileCode(e){return Ce.bind(this)(e)}async _executeIterations(e,r,n,a){const o=["const","var","let","params"];for(let i=n;i<a;i++){e.idx=i,e.data.close.push(this.close[i]),e.data.open.push(this.open[i]),e.data.high.push(this.high[i]),e.data.low.push(this.low[i]),e.data.volume.push(this.volume[i]),e.data.hl2.push(this.hl2[i]),e.data.hlc3.push(this.hlc3[i]),e.data.ohlc4.push(this.ohlc4[i]),e.data.openTime.push(this.openTime[i]);const s=await r(e);if(typeof s=="object"){typeof e.result!="object"&&(e.result={});for(let c in s){e.result[c]===void 0&&(e.result[c]=[]);const u=Array.isArray(s[c])?s[c][s[c].length-1]:s[c];e.result[c].push(u)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(s);for(let c of o)for(let u in e[c])if(Array.isArray(e[c][u])){const h=e[c][u],f=h[h.length-1];h.push(f)}}}}var en=Object.defineProperty,tn=(t,e,r)=>e in t?en(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,z=(t,e,r)=>tn(t,typeof e!="symbol"?e+"":e,r);const rn="https://api.binance.com/api/v3",G={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",45:null,60:"1h",120:"2h",180:null,240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"};class nn{constructor(e=5*60*1e3){z(this,"cache"),z(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([r,n])=>n!==void 0).map(([r,n])=>`${r}:${n}`).join("|")}get(e){const r=this.generateKey(e),n=this.cache.get(r);return n?Date.now()-n.timestamp>this.cacheDuration?(this.cache.delete(r),null):n.data:null}set(e,r){const n=this.generateKey(e);this.cache.set(n,{data:r,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[r,n]of this.cache.entries())e-n.timestamp>this.cacheDuration&&this.cache.delete(r)}}class an{constructor(){z(this,"cacheManager"),this.cacheManager=new nn(5*60*1e3)}async getMarketDataInterval(e,r,n,a){try{const o=G[r.toUpperCase()];if(!o)return console.error(`Unsupported timeframe: ${r}`),[];const i={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3};let s=[],c=n;const u=a,h=i[o];if(!h)return console.error(`Duration not defined for interval: ${o}`),[];for(;c<u;){const f=Math.min(c+1e3*h,u),m=await this.getMarketData(e,r,1e3,c,f);if(m.length===0)break;s=s.concat(m),c=m[m.length-1].closeTime+1}return s}catch(o){return console.error("Error in getMarketDataInterval:",o),[]}}async getMarketData(e,r,n,a,o){try{const i={tickerId:e,timeframe:r,limit:n,sDate:a,eDate:o},s=this.cacheManager.get(i);if(s)return console.log("cache hit",e,r,n,a,o),s;const c=G[r.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${r}`),[];if(this.shouldPaginate(r,n,a,o)&&a&&o){const m=await this.getMarketDataInterval(e,r,a,o),p=n?m.slice(0,n):m;return this.cacheManager.set(i,p),p}let u=`${rn}/klines?symbol=${e}&interval=${c}`;n&&(u+=`&limit=${Math.min(n,1e3)}`),a&&(u+=`&startTime=${a}`),o&&(u+=`&endTime=${o}`);const h=await fetch(u);if(!h.ok)throw new Error(`HTTP error! status: ${h.status}`);const f=(await h.json()).map(m=>({openTime:parseInt(m[0]),open:parseFloat(m[1]),high:parseFloat(m[2]),low:parseFloat(m[3]),close:parseFloat(m[4]),volume:parseFloat(m[5]),closeTime:parseInt(m[6]),quoteAssetVolume:parseFloat(m[7]),numberOfTrades:parseInt(m[8]),takerBuyBaseAssetVolume:parseFloat(m[9]),takerBuyQuoteAssetVolume:parseFloat(m[10]),ignore:m[11]}));return this.cacheManager.set(i,f),f}catch(i){return console.error("Error in binance.klines:",i),[]}}shouldPaginate(e,r,n,a){if(r&&r>1e3)return!0;if(n&&a){const o=G[e.toUpperCase()],i={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3}[o];if(i)return Math.ceil((a-n)/i)>1e3}return!1}}var on=Object.defineProperty,sn=(t,e,r)=>e in t?on(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Q=(t,e,r)=>sn(t,typeof e!="symbol"?e+"":e,r);const cn=ae(import.meta.url),pn=F.dirname(cn);class ln{constructor(e){if(Q(this,"dataCache",new Map),Q(this,"dataDirectory"),e)this.dataDirectory=e;else{const r=F.resolve(pn,"../../../");this.dataDirectory=F.join(r,"tests","compatibility","_data")}}getDataFileName(e,r,n,a){return n&&a?`${e}-${r}-${n}-${a}.json`:null}loadDataFromFile(e){const r=`file:${e}`;if(this.dataCache.has(r))return this.dataCache.get(r);const n=F.join(this.dataDirectory,e);if(!R.existsSync(n))throw new Error(`Mock data file not found: ${n}`);const a=R.readFileSync(n,"utf-8"),o=JSON.parse(a);return this.dataCache.set(r,o),o}findDataFile(e,r,n,a){if(!R.existsSync(this.dataDirectory))return null;const o=R.readdirSync(this.dataDirectory).filter(c=>c.endsWith(".json"));if(n&&a){const c=`${e}-${r}-${n}-${a}.json`;if(o.includes(c))return c}const i=new RegExp(`^${e}-${r}-(\\d+)-(\\d+)\\.json$`),s=o.filter(c=>i.test(c)).map(c=>{const u=c.match(i);return{file:c,startTime:parseInt(u[1]),endTime:parseInt(u[2])}}).sort((c,u)=>u.endTime-c.endTime);if(s.length===0)return null;if(n&&a){const c=s.find(u=>u.startTime<=n&&u.endTime>=a);if(c)return c.file}return s[0].file}filterData(e,r,n,a){let o=e;return(r||n)&&(o=e.filter(i=>{const s=!r||i.openTime>=r,c=!n||i.openTime<=n;return s&&c})),o.sort((i,s)=>i.openTime-s.openTime),a&&a>0&&(o=o.slice(0,a)),o}normalizeTimeframe(e){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[e.toUpperCase()]||e.toLowerCase()}async getMarketData(e,r,n,a,o){try{const i=this.normalizeTimeframe(r),s=this.findDataFile(e,i,a,o);if(!s)return console.warn(`No mock data file found for ${e} ${i}. Searched in: ${this.dataDirectory}`),[];const c=this.loadDataFromFile(s);return this.filterData(c,a,o,n)}catch(i){return console.error("Error in MockProvider.getMarketData:",i),[]}}clearCache(){this.dataCache.clear()}setDataDirectory(e){this.dataDirectory=e,this.clearCache()}}const un=typeof process<"u"&&process.versions&&process.versions.node;let q=null;if(un)try{q=new ln}catch{q=null}const hn={Binance:new an,...q?{Mock:q}:{}};export{J as Context,Zr as PineTS,hn as Provider};
|
|
18
|
+
import*as 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
|
+
${e}
|
|
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};
|