pinets 0.2.1 → 0.5.0

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