pinets 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/pinets.min.browser.es.js +14 -14
- package/dist/pinets.min.browser.es.js.map +1 -1
- package/dist/pinets.min.browser.js +1 -1
- package/dist/pinets.min.browser.js.map +1 -1
- package/dist/pinets.min.cjs +1 -1
- package/dist/pinets.min.cjs.map +1 -1
- package/dist/pinets.min.es.js +1 -1
- package/dist/pinets.min.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -113,5 +113,5 @@ ${e}
|
|
|
113
113
|
`)}generateNestedIfAsExpression(t){if(t.type==="IfStatement"){if(this.write("("),this.generateExpression(t.test),this.write(" ? "),t.consequent.type==="BlockStatement"&&t.consequent.body.length>0){const i=t.consequent.body[t.consequent.body.length-1];i.type==="ExpressionStatement"?this.generateExpression(i.expression):i.type==="IfStatement"&&this.generateNestedIfAsExpression(i)}if(this.write(" : "),t.alternate)if(t.alternate.type==="IfStatement")this.generateNestedIfAsExpression(t.alternate);else if(t.alternate.type==="BlockStatement"&&t.alternate.body.length>0){const i=t.alternate.body[t.alternate.body.length-1];i.type==="ExpressionStatement"&&this.generateExpression(i.expression)}else this.write("false");else this.write("false");this.write(")")}}generateArrayExpression(t){this.write("[");for(let i=0;i<t.elements.length;i++)this.generateExpression(t.elements[i]),i<t.elements.length-1&&this.write(", ");this.write("]")}generateObjectExpression(t){this.write("{");for(let i=0;i<t.properties.length;i++){const r=t.properties[i];r.key.type==="Identifier"?this.write(r.key.name):this.generateExpression(r.key),this.write(": "),this.generateExpression(r.value),i<t.properties.length-1&&this.write(", ")}this.write("}")}generateSwitchExpression(t){this.write("(");for(let i=0;i<t.cases.length;i++){const r=t.cases[i];r.test?(this.generateExpression(t.discriminant),this.write(" == "),this.generateExpression(r.test),this.write(" ? "),this.generateExpression(r.consequent),this.write(" : ")):this.generateExpression(r.consequent)}t.cases.some(i=>!i.test)||this.write("undefined"),this.write(")")}generateSequenceExpression(t){this.write("(");for(let i=0;i<t.expressions.length;i++)this.generateExpression(t.expressions[i]),i<t.expressions.length-1&&this.write(", ");this.write(")")}needsParentheses(t){return!1}}function hr(e){const t=/^\s*\/\/\s*@version\s*=\s*(\d+)\s*$/im,i=e.match(t);return i&&i[1]?parseInt(i[1],10):null}function hn(e,t={}){const i=hr(e);if(i===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(i<5)return{success:!1,version:i,error:`Pine Script version ${i} is not supported. Only version 5 and above are supported.`};try{const r=new $s(e).tokenize(),s=new sn(r).parse(),n={...t,sourceCode:e},a=new on(n).generate(s);return{success:!0,version:i,code:a,ast:s,tokens:r}}catch(r){return{success:!1,version:i,error:r.message,stack:r.stack}}}function un(e){if(typeof e=="function")return e.toString();{const t=hr(e);if(t===null)return e;if(t>=5){const i=hn(e);if(i.success)return i.code;throw new Error(`Failed to transpile Pine Script version ${t}: ${i.error}`)}else throw new Error(`Unsupported Pine Script version ${t}. Only version 5 and above are supported.`)}}function cn(e,t={debug:!1,ln:!1}){typeof t=="boolean"&&(t={debug:t,ln:!0});const{debug:i}=t;let r=un(e);r=Ss(r);const s=i?r.split(`
|
|
114
114
|
`):[],n=Fi(r,{ecmaVersion:"latest",sourceType:"module",locations:i});Es(n),bs(n),ws(n);const a=new ms;Ns(n,a);const o=Is(n,a)||"";Os(n,a,o,t,s),Vs(n);const h=hs||Mt||void 0,u=Object.assign({},h,{LineComment(f,g){g.write("//"+f.value)}}),l=Hi(n,{generator:u,comments:i});return new Function("",`var _r = ${l}
|
|
115
115
|
; return _r;`)(this)}function ln(e){return t=>new F(t.array.map(i=>Math.abs(i)),t.type,e)}function pn(e){return t=>{let i=0,r=0;for(const s of t.array){const n=Number(s);isNaN(n)||(r++,i+=(n-i)/r)}return r===0?NaN:e.precision(i)}}function fn(e){return(t,i)=>{const r=t.array;let s=0,n=r.length-1;for(;s<=n;){const a=Math.floor((s+n)/2),o=r[a];if(o===i)return a;o<i?s=a+1:n=a-1}return-1}}function mn(e){return(t,i)=>{const r=t.array;let s=0,n=r.length;for(;s<n;){const a=Math.floor((s+n)/2);r[a]<i?s=a+1:n=a}return s<r.length&&r[s]===i?s:s-1}}function dn(e){return(t,i)=>{const r=t.array;let s=0,n=r.length;for(;s<n;){const a=Math.floor((s+n)/2);r[a]<=i?s=a+1:n=a}return s>0&&r[s-1]===i?s-1:s}}function gn(e){return t=>{t.array.length=0}}function xn(e){return(t,i)=>(t.array.push(...i.array),t)}function yn(e){return t=>new F([...t.array],t.type,e)}function wn(e){return(t,i,r=!0)=>{const s=t.array,n=i.array;if(s.length!==n.length)return NaN;let a=0,o=0,h=0;const u=[];for(let x=0;x<s.length;x++){const y=Number(s[x]),w=Number(n[x]);!isNaN(y)&&y!==null&&y!==void 0&&!isNaN(w)&&w!==null&&w!==void 0&&(a+=y,o+=w,h++,u.push(x))}if(h===0)return NaN;const l=a/h,f=o/h;let g=0;for(const x of u){const y=Number(s[x]),w=Number(n[x]);g+=(y-l)*(w-f)}const p=r?h:h-1;return p<=0?NaN:e.precision(g/p)}}function bn(e){return t=>t.array.every(i=>!isNaN(i)&&i)}function vn(e){if(e.every(t=>typeof t=="number"))return e.every(t=>(t|0)===t)?W.int:W.float;if(e.every(t=>typeof t=="string"))return W.string;if(e.every(t=>typeof t=="boolean"))return W.bool;throw new Error("Cannot infer type from values")}function ge(e){if(typeof e=="number")return(e|0)===e?W.int:W.float;if(typeof e=="string")return W.string;if(typeof e=="boolean")return W.bool;throw new Error("Cannot infer type from value")}function rt(e,t){switch(t){case W.int:return typeof e=="number"&&(e|0)===e||isNaN(e);case W.float:return typeof e=="number"||isNaN(e);case W.string:return typeof e=="string";case W.bool:return typeof e=="boolean"}return!1}function _n(e){return(t,i,r=0,s)=>{const n=t.array.length,a=s!==void 0?Math.min(s,n):n;for(let o=r;o<a;o++){if(!rt(i,t.type))throw new Error(`Cannot call 'array.fill' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${t.type}' is expected.`);t.array[o]=e.precision(i)}}}function Sn(e){return t=>t.array.length>0?t.array[0]:e.NA}function En(e){return(t,i)=>t.array[i]}function Nn(e){return(t,i)=>t.array.includes(i)}function Cn(e){return(t,i)=>t.array.indexOf(i)}function kn(e){return(t,i,r)=>{if(!rt(r,t.type))throw new Error(`Cannot call 'array.insert' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${t.type}' is expected.`);t.array.splice(i,0,r)}}function In(e){return(t,i=",")=>t.array.join(i)}function An(e){return t=>t.array.length>0?t.array[t.array.length-1]:e.NA}function Pn(e){return(t,i)=>t.array.lastIndexOf(i)}function Tn(e){return(t,i=0)=>[...t.array].sort((r,s)=>s-r)[i]??e.NA}function Rn(e){return t=>{if(t.array.length===0)return NaN;const i=[...t.array].sort((s,n)=>typeof s=="number"&&typeof n=="number"?s-n:0),r=Math.floor(i.length/2);return i.length%2!==0?i[r]:(i[r-1]+i[r])/2}}function Dn(e){return(t,i=0)=>[...t.array].sort((r,s)=>r-s)[i]??e.NA}function Vn(e){return t=>{if(t.array.length===0)return NaN;const i=new Map;let r=0;for(const n of t.array){const a=(i.get(n)||0)+1;i.set(n,a),a>r&&(r=a)}const s=[];for(const[n,a]of i)a===r&&s.push(n);return s.sort((n,a)=>typeof n=="number"&&typeof a=="number"?n-a:typeof n=="string"&&typeof a=="string"?n<a?-1:n>a?1:0:0),s[0]}}function On(e){return(t,i)=>{const r=t.array;if(r.length===0)return NaN;const s=[];for(const h of r){const u=Number(h);if(isNaN(u)||u===null||u===void 0)return NaN;s.push(u)}s.sort((h,u)=>h-u),i<0&&(i=0),i>100&&(i=100);const n=i/100*s.length-.5;if(n<=0)return e.precision(s[0]);if(n>=s.length-1)return e.precision(s[s.length-1]);const a=Math.floor(n),o=n-a;return e.precision(s[a]*(1-o)+s[a+1]*o)}}function Mn(e){return(t,i)=>{const r=t.array;if(r.length===0)return NaN;const s=[];for(const o of r){const h=Number(o);!isNaN(h)&&h!==null&&h!==void 0&&s.push(h)}if(s.length===0)return NaN;s.sort((o,h)=>o-h),i<0&&(i=0),i>100&&(i=100);const n=r.length,a=Math.ceil(i/100*n);return a<=0?s[0]:a>s.length?NaN:s[a-1]}}function Ln(e){return(t,i)=>{if(t.array.length===0)return NaN;const r=Math.floor(i);if(r<0||r>=t.array.length)return NaN;const s=Number(t.array[r]);if(isNaN(s)||s===null||s===void 0)return NaN;let n=0;for(const o of t.array){const h=Number(o);!isNaN(h)&&h!==null&&h!==void 0&&h<s&&n++}const a=t.array.length-1;return a<=0?NaN:n/a*100}}function Bn(e){return t=>t.array.pop()}function Fn(e){return(t,i)=>{if(!rt(i,t.type))throw new Error(`Cannot call 'array.push' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${t.type}' is expected.`);t.array.push(e.precision(i))}}function jn(e){return t=>e.precision(e.pine.array.max(t)-e.pine.array.min(t))}function $n(e){return(t,i)=>i>=0&&i<t.array.length?t.array.splice(i,1)[0]:e.NA}function Wn(e){return t=>{t.array.reverse()}}function qn(e){return(t,i,r)=>{if(!rt(r,t.type))throw new Error(`Cannot call 'array.set' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${t.type}' is expected.`);t.array[i]=e.precision(r)}}function Un(e){return t=>t.array.shift()}function Kn(e){return t=>t.array.length}function zn(e){return(t,i,r)=>{const s=r!==void 0?r:void 0;return new F(t.array.slice(i,s),t.type,e)}}function Hn(e){return t=>t.array.some(i=>!isNaN(i)&&i)}var ze=(e=>(e[e.ascending=1]="ascending",e[e.descending=0]="descending",e))(ze||{}),ur=(e=>(e.AED="AED",e.ARS="ARS",e.AUD="AUD",e.BDT="BDT",e.BHD="BHD",e.BRL="BRL",e.BTC="BTC",e.CAD="CAD",e.CHF="CHF",e.CLP="CLP",e.CNY="CNY",e.COP="COP",e.CZK="CZK",e.DKK="DKK",e.EGP="EGP",e.ETH="ETH",e.EUR="EUR",e.GBP="GBP",e.HKD="HKD",e.HUF="HUF",e.IDR="IDR",e.ILS="ILS",e.INR="INR",e.ISK="ISK",e.JPY="JPY",e.KES="KES",e.KRW="KRW",e.KWD="KWD",e.LKR="LKR",e.MAD="MAD",e.MXN="MXN",e.MYR="MYR",e.NGN="NGN",e.NOK="NOK",e.NONE="NONE",e.NZD="NZD",e.PEN="PEN",e.PHP="PHP",e.PKR="PKR",e.PLN="PLN",e.QAR="QAR",e.RON="RON",e.RSD="RSD",e.RUB="RUB",e.SAR="SAR",e.SEK="SEK",e.SGD="SGD",e.THB="THB",e.TND="TND",e.TRY="TRY",e.TWD="TWD",e.USD="USD",e.USDT="USDT",e.VES="VES",e.VND="VND",e.ZAR="ZAR",e))(ur||{}),cr=(e=>(e[e.sunday=1]="sunday",e[e.monday=2]="monday",e[e.tuesday=3]="tuesday",e[e.wednesday=4]="wednesday",e[e.thursday=5]="thursday",e[e.friday=6]="friday",e[e.saturday=7]="saturday",e))(cr||{}),lr=(e=>(e.all="all",e.data_window="data_window",e.none="none",e.pane="pane",e.price_scale="price_scale",e.status_line="status_line",e))(lr||{});const Gn={order:ze,currency:ur,dayofweek:cr,display:lr};function Yn(e){return(t,i=ze.ascending)=>{t.array.sort((r,s)=>{let n=isNaN(r)?1/0:r,a=isNaN(s)?1/0:s;return i===ze.ascending?n-a:a-n})}}function Qn(e){return(t,i=ze.ascending)=>{const r=t.array.map((s,n)=>n);return r.sort((s,n)=>{const a=isNaN(t.array[s])?1/0:t.array[s],o=isNaN(t.array[n])?1/0:t.array[n];return i===ze.ascending?a-o:o-a}),new F(r,W.int,e)}}function Xn(e){return t=>{const i=e.array.avg(t),r=e.array.stdev(t);return isNaN(r)?new F(t.array.map(()=>NaN),W.int,e):r===0?new F(t.array.map(()=>1),W.int,e):new F(t.array.map(s=>(s-i)/r),W.int,e)}}function Zn(e){return(t,i=!0)=>{const r=t.array,s=r.length;if(s===0)return NaN;let n=0,a=0,o=0;for(let l=0;l<s;l++){const f=Number(r[l]);!isNaN(f)&&f!==null&&f!==void 0&&(n+=f,a+=f*f,o++)}if(o===0)return NaN;const h=n/o;let u=a/o-h*h;return u<0?NaN:(!i&&o>1&&(u=u*o/(o-1)),!i&&o===1?0:e.precision(Math.sqrt(u)))}}function Jn(e){return t=>e.precision(t.array.reduce((i,r)=>{const s=Number(r);return isNaN(s)?i:i+s},0))}function ea(e){return(t,i)=>{if(!rt(i,t.type))throw new Error(`Cannot call 'array.unshift' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${t.type}' is expected.`);t.array.unshift(e.precision(i))}}function ta(e){return(t,i=!0)=>{let r=0,s=0;for(const h of t.array){const u=Number(h);!isNaN(u)&&u!==null&&u!==void 0&&(r+=u,s++)}if(s===0)return NaN;const n=r/s;let a=0;for(const h of t.array){const u=Number(h);!isNaN(u)&&u!==null&&u!==void 0&&(a+=(u-n)*(u-n))}const o=i?s:s-1;return o<=0?NaN:e.precision(a/o)}}var ia=Object.defineProperty,ra=(e,t,i)=>t in e?ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,R=(e,t,i)=>ra(e,typeof t!="symbol"?t+"":t,i),W=(e=>(e.any="",e.box="box",e.bool="bool",e.color="color",e.float="float",e.int="int",e.label="label",e.line="line",e.linefill="linefill",e.string="string",e.table="table",e))(W||{});class F{constructor(t,i,r){this.array=t,this.type=i,this.context=r,R(this,"_abs"),R(this,"_avg"),R(this,"_binary_search"),R(this,"_binary_search_leftmost"),R(this,"_binary_search_rightmost"),R(this,"_clear"),R(this,"_concat"),R(this,"_copy"),R(this,"_covariance"),R(this,"_every"),R(this,"_fill"),R(this,"_first"),R(this,"_get"),R(this,"_includes"),R(this,"_indexof"),R(this,"_insert"),R(this,"_join"),R(this,"_last"),R(this,"_lastindexof"),R(this,"_max"),R(this,"_median"),R(this,"_min"),R(this,"_mode"),R(this,"_percentile_linear_interpolation"),R(this,"_percentile_nearest_rank"),R(this,"_percentrank"),R(this,"_pop"),R(this,"_push"),R(this,"_range"),R(this,"_remove"),R(this,"_reverse"),R(this,"_set"),R(this,"_shift"),R(this,"_size"),R(this,"_slice"),R(this,"_some"),R(this,"_sort"),R(this,"_sort_indices"),R(this,"_standardize"),R(this,"_stdev"),R(this,"_sum"),R(this,"_unshift"),R(this,"_variance"),this._abs=ln(this.context),this._avg=pn(this.context),this._binary_search=fn(this.context),this._binary_search_leftmost=mn(this.context),this._binary_search_rightmost=dn(this.context),this._clear=gn(this.context),this._concat=xn(this.context),this._copy=yn(this.context),this._covariance=wn(this.context),this._every=bn(this.context),this._fill=_n(this.context),this._first=Sn(this.context),this._get=En(this.context),this._includes=Nn(this.context),this._indexof=Cn(this.context),this._insert=kn(this.context),this._join=In(this.context),this._last=An(this.context),this._lastindexof=Pn(this.context),this._max=Tn(this.context),this._median=Rn(this.context),this._min=Dn(this.context),this._mode=Vn(this.context),this._percentile_linear_interpolation=On(this.context),this._percentile_nearest_rank=Mn(this.context),this._percentrank=Ln(this.context),this._pop=Bn(this.context),this._push=Fn(this.context),this._range=jn(this.context),this._remove=$n(this.context),this._reverse=Wn(this.context),this._set=qn(this.context),this._shift=Un(this.context),this._size=Kn(this.context),this._slice=zn(this.context),this._some=Hn(this.context),this._sort=Yn(this.context),this._sort_indices=Qn(this.context),this._standardize=Xn(this.context),this._stdev=Zn(this.context),this._sum=Jn(this.context),this._unshift=ea(this.context),this._variance=ta(this.context)}toString(){return"["+this.array.toString().replace(/,/g,", ")+"]"}abs(...t){return this._abs(this,...t)}avg(...t){return this._avg(this,...t)}binary_search(...t){return this._binary_search(this,...t)}binary_search_leftmost(...t){return this._binary_search_leftmost(this,...t)}binary_search_rightmost(...t){return this._binary_search_rightmost(this,...t)}clear(...t){return this._clear(this,...t)}concat(...t){return this._concat(this,...t)}copy(...t){return this._copy(this,...t)}covariance(...t){return this._covariance(this,...t)}every(...t){return this._every(this,...t)}fill(...t){return this._fill(this,...t)}first(...t){return this._first(this,...t)}get(...t){return this._get(this,...t)}includes(...t){return this._includes(this,...t)}indexof(...t){return this._indexof(this,...t)}insert(...t){return this._insert(this,...t)}join(...t){return this._join(this,...t)}last(...t){return this._last(this,...t)}lastindexof(...t){return this._lastindexof(this,...t)}max(...t){return this._max(this,...t)}median(...t){return this._median(this,...t)}min(...t){return this._min(this,...t)}mode(...t){return this._mode(this,...t)}percentile_linear_interpolation(...t){return this._percentile_linear_interpolation(this,...t)}percentile_nearest_rank(...t){return this._percentile_nearest_rank(this,...t)}percentrank(...t){return this._percentrank(this,...t)}pop(...t){return this._pop(this,...t)}push(...t){return this._push(this,...t)}range(...t){return this._range(this,...t)}remove(...t){return this._remove(this,...t)}reverse(...t){return this._reverse(this,...t)}set(...t){return this._set(this,...t)}shift(...t){return this._shift(this,...t)}size(...t){return this._size(this,...t)}slice(...t){return this._slice(this,...t)}some(...t){return this._some(this,...t)}sort(...t){return this._sort(this,...t)}sort_indices(...t){return this._sort_indices(this,...t)}standardize(...t){return this._standardize(this,...t)}stdev(...t){return this._stdev(this,...t)}sum(...t){return this._sum(this,...t)}unshift(...t){return this._unshift(this,...t)}variance(...t){return this._variance(this,...t)}}function sa(e){return(...t)=>new F([...t],vn(t),e)}function na(e){return(t,i)=>new F(Array(t).fill(e.precision(i||0)),ge(i||0),e)}function aa(e){return(t,i=!1)=>new F(Array(t).fill(i),W.bool,e)}function oa(e){return(t,i=NaN)=>new F(Array(t).fill(e.precision(i)),W.float,e)}function ha(e){return(t,i=0)=>new F(Array(t).fill(e.precision(i)),W.int,e)}function ua(e){return(t,i="")=>new F(Array(t).fill(i),W.string,e)}class d{constructor(t,i=0){this.data=t,this.offset=i}get(t){const i=this.data.length-1-(this.offset+t);return i<0||i>=this.data.length?NaN:this.data[i]}set(t,i){const r=this.data.length-1-(this.offset+t);r>=0&&r<this.data.length&&(this.data[r]=i)}get length(){return this.data.length}toArray(){return this.data}static from(t){return t instanceof d?t:Array.isArray(t)?new d(t):new d([t])}}function ca(e){return(t,i=0)=>d.from(t).get(i)}class la{constructor(t){this.context=t,this.abs=(i,...r)=>i.abs(...r),this.avg=(i,...r)=>i.avg(...r),this.binary_search=(i,...r)=>i.binary_search(...r),this.binary_search_leftmost=(i,...r)=>i.binary_search_leftmost(...r),this.binary_search_rightmost=(i,...r)=>i.binary_search_rightmost(...r),this.clear=(i,...r)=>i.clear(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.covariance=(i,...r)=>i.covariance(...r),this.every=(i,...r)=>i.every(...r),this.fill=(i,...r)=>i.fill(...r),this.first=(i,...r)=>i.first(...r),this.from=sa(t),this.get=(i,...r)=>i.get(...r),this.includes=(i,...r)=>i.includes(...r),this.indexof=(i,...r)=>i.indexof(...r),this.insert=(i,...r)=>i.insert(...r),this.join=(i,...r)=>i.join(...r),this.last=(i,...r)=>i.last(...r),this.lastindexof=(i,...r)=>i.lastindexof(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.new=na(t),this.new_bool=aa(t),this.new_float=oa(t),this.new_int=ha(t),this.new_string=ua(t),this.param=ca(),this.percentile_linear_interpolation=(i,...r)=>i.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(i,...r)=>i.percentile_nearest_rank(...r),this.percentrank=(i,...r)=>i.percentrank(...r),this.pop=(i,...r)=>i.pop(...r),this.push=(i,...r)=>i.push(...r),this.range=(i,...r)=>i.range(...r),this.remove=(i,...r)=>i.remove(...r),this.reverse=(i,...r)=>i.reverse(...r),this.set=(i,...r)=>i.set(...r),this.shift=(i,...r)=>i.shift(...r),this.size=(i,...r)=>i.size(...r),this.slice=(i,...r)=>i.slice(...r),this.some=(i,...r)=>i.some(...r),this.sort=(i,...r)=>i.sort(...r),this.sort_indices=(i,...r)=>i.sort_indices(...r),this.standardize=(i,...r)=>i.standardize(...r),this.stdev=(i,...r)=>i.stdev(...r),this.sum=(i,...r)=>i.sum(...r),this.unshift=(i,...r)=>i.unshift(...r),this.variance=(i,...r)=>i.variance(...r)}}function pa(e){return t=>{t.map.clear()}}function fa(e){return(t,i)=>t.map.has(i)}function ma(e){return t=>{const i=new pr(e);return i.map=new Map(t.map),i}}function da(e){return(t,i)=>{const r=t.map.get(i);return r===void 0?NaN:r}}function ga(e){return t=>{const i=Array.from(t.map.keys()),r=ge(i[0]);return new F(i,r,e)}}function xa(e){return(t,i,r)=>{const s=t.map.get(i);return t.map.set(i,r),s===void 0?NaN:s}}function ya(e){return(t,i)=>{for(const[r,s]of i.map)t.map.set(r,s)}}function wa(e){return(t,i)=>{const r=t.map.get(i);return t.map.delete(i)?r:NaN}}function ba(e){return t=>t.map.size}function va(e){return t=>{const i=Array.from(t.map.values()),r=ge(i[0]);return new F(i,r,e)}}var _a=Object.defineProperty,Sa=(e,t,i)=>t in e?_a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,xe=(e,t,i)=>Sa(e,typeof t!="symbol"?t+"":t,i);class pr{constructor(t){this.context=t,xe(this,"map"),xe(this,"_clear"),xe(this,"_contains"),xe(this,"_copy"),xe(this,"_get"),xe(this,"_keys"),xe(this,"_put"),xe(this,"_put_all"),xe(this,"_remove"),xe(this,"_size"),xe(this,"_values"),this.map=new Map,this._clear=pa(this.context),this._contains=fa(this.context),this._copy=ma(this.context),this._get=da(this.context),this._keys=ga(this.context),this._put=xa(this.context),this._put_all=ya(this.context),this._remove=wa(this.context),this._size=ba(this.context),this._values=va(this.context)}toString(){return`PineMapObject(${this.map.size})`}clear(...t){return this._clear(this,...t)}contains(...t){return this._contains(this,...t)}copy(...t){return this._copy(this,...t)}get(...t){return this._get(this,...t)}keys(...t){return this._keys(this,...t)}put(...t){return this._put(this,...t)}put_all(...t){return this._put_all(this,...t)}remove(...t){return this._remove(this,...t)}size(...t){return this._size(this,...t)}values(...t){return this._values(this,...t)}}function Ea(e){return()=>new pr(e)}function Na(e){return(t,i=0)=>d.from(t).get(i)}class Ca{constructor(t){this.context=t,this.clear=(i,...r)=>i.clear(...r),this.contains=(i,...r)=>i.contains(...r),this.copy=(i,...r)=>i.copy(...r),this.get=(i,...r)=>i.get(...r),this.keys=(i,...r)=>i.keys(...r),this.new=Ea(t),this.param=Na(),this.put=(i,...r)=>i.put(...r),this.put_all=(i,...r)=>i.put_all(...r),this.remove=(i,...r)=>i.remove(...r),this.size=(i,...r)=>i.size(...r),this.values=(i,...r)=>i.values(...r)}}function ka(e){return(t,i,r)=>{const s=t.matrix.length;let n=[];if(r&&(r instanceof F?n=r.array:Array.isArray(r)?n=r:n=[r]),s===0){for(let h=0;h<n.length;h++){let u=n[h];u instanceof d&&(u=u.get(0)),t.matrix.push([u])}return}const a=t.matrix[0].length,o=i!==void 0?i:a;for(let h=0;h<s;h++){let u=h<n.length?n[h]:NaN;u instanceof d&&(u=u.get(0)),t.matrix[h].splice(o,0,u)}}}function Ia(e){return(t,i,r)=>{const s=t.matrix.length;let n=[];if(r)if(r instanceof F)n=r.array;else if(Array.isArray(r))n=r;else if(r instanceof d){const u=r.get(0);Array.isArray(u)?n=u:n=[u]}else n=[r];const a=s>0?t.matrix[0].length:n.length,o=i!==void 0?i:s,h=[];for(let u=0;u<a;u++)if(u<n.length){let l=n[u];l instanceof d&&(l=l.get(0)),h.push(l)}else h.push(NaN);t.matrix.splice(o,0,h)}}function Aa(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length;if(r===0)return NaN;let s=0,n=0;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const h=t.matrix[a][o];isNaN(h)||(s+=h,n++)}return n===0?NaN:s/n}}function Pa(e){return(t,i)=>{const r=t.matrix.length,s=[];for(let a=0;a<r;a++)s.push(t.matrix[a][i]);const n=ge(s[0]);return new F(s,n,e)}}function Ta(e){return t=>t.matrix.length===0?0:t.matrix[0].length}function Ra(e){return(t,i)=>{const r=t.matrix.length,s=i.matrix.length;if(r===0){for(let o=0;o<s;o++)t.matrix.push([...i.matrix[o]]);return}const n=t.matrix[0].length,a=s>0?i.matrix[0].length:0;if(n!==a&&s>0){console.error(`matrix.concat: Column count mismatch ${n} vs ${a}`);return}for(let o=0;o<s;o++)t.matrix.push([...i.matrix[o]])}}function Da(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0,s=new M(i,r,NaN,e);return s.matrix=t.matrix.map(n=>[...n]),s}}function Va(e){const t=e.length;if(t===0)return 0;if(t===1)return e[0][0];if(t===2)return e[0][0]*e[1][1]-e[0][1]*e[1][0];const i=e.map(s=>[...s]);let r=1;for(let s=0;s<t;s++){let n=s;for(;n<t&&i[n][s]===0;)n++;if(n===t)return 0;n!==s&&([i[s],i[n]]=[i[n],i[s]],r*=-1),r*=i[s][s];for(let a=s+1;a<t;a++){const o=i[a][s]/i[s][s];for(let h=s;h<t;h++)i[a][h]-=o*i[s][h]}}return r}function Oa(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;return i!==r?NaN:Va(t.matrix)}}function Ma(e){return(t,i)=>{const r=t.matrix.length;if(r===0)return new M(0,0,NaN,e);const s=t.matrix[0].length,n=new M(r,s,NaN,e);if(i instanceof M)for(let a=0;a<r;a++)for(let o=0;o<s;o++){const h=t.matrix[a][o],u=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;n.matrix[a][o]=h-u}else{const a=i;for(let o=0;o<r;o++)for(let h=0;h<s;h++)n.matrix[o][h]=t.matrix[o][h]-a}return n}}function La(e){const t=e.length;if(t!==2)return Array(t).fill(NaN);const i=e[0][0],r=e[0][1],s=e[1][0],n=e[1][1],a=i+n,o=i*n-r*s,h=a*a-4*o;if(h<0)return[NaN,NaN];const u=(a+Math.sqrt(h))/2,l=(a-Math.sqrt(h))/2;return[u,l]}function Ba(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r){const a=ge(t.matrix[0][0]);return new F([],a,e)}const s=La(t.matrix),n=ge(s[0]);return new F(s,n,e)}}function Fa(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r)return new M(0,0,NaN,e);const s=new M(i,r,0,e);for(let n=0;n<i;n++)s.matrix[n][n]=1;return s}}function ja(e){return t=>{const i=t.matrix.length;return i===0?0:i*t.matrix[0].length}}function $a(e){return(t,i,r,s,n,a)=>{const o=t.matrix.length;if(o===0)return;const h=t.matrix[0].length,u=r!==void 0?r:0,l=s!==void 0?s:o,f=n!==void 0?n:0,g=a!==void 0?a:h;for(let p=u;p<l&&!(p>=o);p++)for(let x=f;x<g&&!(x>=h);x++)t.matrix[p][x]=i}}function Wa(e){return(t,i,r)=>{if(!t.matrix[i])return NaN;const s=t.matrix[i][r];return s===void 0?NaN:s}}function qa(e){if(e.length!==2)return e.map(i=>i.map(()=>NaN));const t=e[0][0]*e[1][1]-e[0][1]*e[1][0];return t===0?[[NaN,NaN],[NaN,NaN]]:[[e[1][1]/t,-e[0][1]/t],[-e[1][0]/t,e[0][0]/t]]}function Ua(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r)return new M(i,r,NaN,e);const s=qa(t.matrix),n=new M(i,r,NaN,e);return n.matrix=s,n}}function Ka(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let n=0;n<r;n++)if(s+n!==i-1&&t.matrix[s][n]!==0)return!1;return!0}}function za(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let n=0;n<r;n++)if(t.matrix[n][s]!==-t.matrix[s][n])return!1;return!0}}function Ha(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;for(let s=0;s<i;s++)for(let n=0;n<r;n++){const a=t.matrix[s][n];if(a!==0&&a!==1)return!1}return!0}}function Ga(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let n=0;n<r;n++)if(s!==n&&t.matrix[s][n]!==0)return!1;return!0}}function Ya(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let n=0;n<r;n++)if(s===n){if(t.matrix[s][n]!==1)return!1}else if(t.matrix[s][n]!==0)return!1;return!0}}function Qa(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;return i===r}}function Xa(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;for(let s=0;s<i;s++){let n=0;for(let a=0;a<r;a++){const o=t.matrix[s][a];if(o<0)return!1;n+=o}if(Math.abs(n-1)>1e-10)return!1}return!0}}function Za(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let n=0;n<s;n++)if(t.matrix[s][n]!==t.matrix[n][s])return!1;return!0}}function Ja(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;if(i!==r)return!1;let s=!0,n=!0;for(let a=0;a<i;a++)for(let o=0;o<r;o++)a>o&&t.matrix[a][o]!==0&&(s=!1),a<o&&t.matrix[a][o]!==0&&(n=!1);return s||n}}function eo(e){return t=>{const i=t.matrix.length;if(i===0)return!0;const r=t.matrix[0].length;for(let s=0;s<i;s++)for(let n=0;n<r;n++)if(t.matrix[s][n]!==0)return!1;return!0}}function to(e){return(t,i)=>{const r=t.matrix.length,s=r>0?t.matrix[0].length:0,n=i.matrix.length,a=n>0?i.matrix[0].length:0,o=r*n,h=s*a,u=new M(o,h,NaN,e);for(let l=0;l<r;l++)for(let f=0;f<s;f++){const g=t.matrix[l][f];for(let p=0;p<n;p++)for(let x=0;x<a;x++){const y=i.matrix[p][x];u.matrix[l*n+p][f*a+x]=g*y}}return u}}function io(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length;let s=-1/0,n=!1;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const h=t.matrix[a][o];isNaN(h)||(h>s&&(s=h),n=!0)}return n?s:NaN}}function ro(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length,s=[];for(let a=0;a<i;a++)for(let o=0;o<r;o++){const h=t.matrix[a][o];isNaN(h)||s.push(h)}if(s.length===0)return NaN;s.sort((a,o)=>a-o);const n=Math.floor(s.length/2);return s.length%2!==0?s[n]:(s[n-1]+s[n])/2}}function so(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length;let s=1/0,n=!1;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const h=t.matrix[a][o];isNaN(h)||(h<s&&(s=h),n=!0)}return n?s:NaN}}function no(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length,s=new Map;let n=0,a=NaN;for(let o=0;o<i;o++)for(let h=0;h<r;h++){const u=t.matrix[o][h];if(!isNaN(u)){const l=(s.get(u)||0)+1;s.set(u,l),l>n?(n=l,a=u):l===n&&u<a&&(a=u)}}return a}}function ao(e){return(t,i)=>{const r=t.matrix.length,s=r>0?t.matrix[0].length:0;if(i instanceof M){const n=i.matrix.length,a=n>0?i.matrix[0].length:0;if(s!==n)return new M(0,0,NaN,e);const o=new M(r,a,0,e);for(let h=0;h<r;h++)for(let u=0;u<a;u++){let l=0;for(let f=0;f<s;f++)l+=t.matrix[h][f]*i.matrix[f][u];o.matrix[h][u]=l}return o}else if(i instanceof F||Array.isArray(i.array||i)){const n=i.array||i;if(s!==n.length)return new M(0,0,NaN,e);const a=new M(r,1,0,e);for(let o=0;o<r;o++){let h=0;for(let u=0;u<s;u++)h+=t.matrix[o][u]*n[u];a.matrix[o][0]=h}return a}else{const n=i,a=new M(r,s,NaN,e);for(let o=0;o<r;o++)for(let h=0;h<s;h++)a.matrix[o][h]=t.matrix[o][h]*n;return a}}}function oo(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;return i===r?new M(i,r,NaN,e):new M(r,i,NaN,e)}}function ho(e){return(t,i)=>{const r=t.matrix.length,s=r>0?t.matrix[0].length:0;if(r!==s)return new M(0,0,NaN,e);let n=new M(r,s,0,e);for(let h=0;h<r;h++)n.matrix[h][h]=1;let a=new M(r,s,NaN,e);for(let h=0;h<r;h++)a.matrix[h]=[...t.matrix[h]];let o=Math.floor(i);if(o<0)return new M(r,s,NaN,e);for(;o>0;){if(o%2===1){const u=new M(r,s,0,e);for(let l=0;l<r;l++)for(let f=0;f<s;f++){let g=0;for(let p=0;p<r;p++)g+=n.matrix[l][p]*a.matrix[p][f];u.matrix[l][f]=g}n=u}const h=new M(r,s,0,e);for(let u=0;u<r;u++)for(let l=0;l<s;l++){let f=0;for(let g=0;g<r;g++)f+=a.matrix[u][g]*a.matrix[g][l];h.matrix[u][l]=f}a=h,o=Math.floor(o/2)}return n}}function uo(e){return t=>{const i=t.matrix.length;if(i===0)return 0;const r=t.matrix[0].length,s=t.matrix.map(a=>[...a]);let n=0;for(let a=0;a<r&&n<i;a++){let o=n;for(;o<i&&Math.abs(s[o][a])<1e-10;)o++;if(o<i){[s[n],s[o]]=[s[o],s[n]];const h=s[n][a];for(let u=a;u<r;u++)s[n][u]/=h;for(let u=0;u<i;u++)if(u!==n){const l=s[u][a];for(let f=a;f<r;f++)s[u][f]-=l*s[n][f]}n++}}return n}}function co(e){return(t,i)=>{const r=t.matrix.length;if(r===0){const a=ge(t.matrix[0][0]);return new F([],a,e)}const s=[];for(let a=0;a<r;a++){const o=t.matrix[a].splice(i,1);s.push(o[0])}const n=ge(s[0]);return new F(s,n,e)}}function lo(e){return(t,i)=>{const r=t.matrix.splice(i,1),s=ge(r[0][0]);return new F(r[0]||[],s,e)}}function po(e){return(t,i,r)=>{const s=t.matrix.length,n=s>0?t.matrix[0].length:0,a=i*r,o=[];for(let l=0;l<s;l++)for(let f=0;f<n;f++)o.push(t.matrix[l][f]);for(;o.length<a;)o.push(NaN);o.length>a&&(o.length=a);const h=[];let u=0;for(let l=0;l<i;l++){const f=[];for(let g=0;g<r;g++)f.push(o[u++]);h.push(f)}t.matrix=h}}function fo(e){return t=>{t.matrix.reverse();for(const i of t.matrix)i.reverse()}}function mo(e){return(t,i)=>{if(!t.matrix[i]){const s=ge(t.matrix[0][0]);return new F([],s,e)}const r=ge(t.matrix[i][0]);return new F([...t.matrix[i]],r,e)}}function go(e){return t=>t.matrix.length}function xo(e){return(t,i,r,s)=>{t.matrix[i]&&(t.matrix[i][r]=s)}}function yo(e){return(t,i=0,r="asc")=>{t.matrix.length!==0&&t.matrix.sort((s,n)=>{const a=s[i],o=n[i];return a<o?r==="asc"?-1:1:a>o?r==="asc"?1:-1:0})}}function wo(e){return(t,i,r,s,n)=>{const a=r-i,o=n-s,h=new M(a,o,NaN,e);for(let u=0;u<a;u++){const l=i+u;if(l>=t.matrix.length)break;for(let f=0;f<o;f++){const g=s+f;if(g>=t.matrix[l].length)break;h.matrix[u][f]=t.matrix[l][g]}}return h}}function bo(e){return(t,i)=>{const r=t.matrix.length;if(r===0)return new M(0,0,NaN,e);const s=t.matrix[0].length,n=new M(r,s,NaN,e);if(i instanceof M)for(let a=0;a<r;a++)for(let o=0;o<s;o++){const h=t.matrix[a][o],u=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;n.matrix[a][o]=h+u}else{const a=i;for(let o=0;o<r;o++)for(let h=0;h<s;h++)n.matrix[o][h]=t.matrix[o][h]+a}return n}}function vo(e){return(t,i,r)=>{const s=t.matrix.length;for(let n=0;n<s;n++){const a=t.matrix[n][i];t.matrix[n][i]=t.matrix[n][r],t.matrix[n][r]=a}}}function _o(e){return(t,i,r)=>{const s=t.matrix[i];t.matrix[i]=t.matrix[r],t.matrix[r]=s}}function So(e){return t=>{const i=t.matrix.length;if(i===0)return 0;const r=t.matrix[0].length,s=Math.min(i,r);let n=0;for(let a=0;a<s;a++)n+=t.matrix[a][a];return n}}function Eo(e){return t=>{const i=t.matrix.length;if(i===0)return new M(0,0,NaN,e);const r=t.matrix[0].length,s=new M(r,i,NaN,e);for(let n=0;n<i;n++)for(let a=0;a<r;a++)s.matrix[a][n]=t.matrix[n][a];return s}}var No=Object.defineProperty,Co=(e,t,i)=>t in e?No(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,I=(e,t,i)=>Co(e,typeof t!="symbol"?t+"":t,i);class M{constructor(t=0,i=0,r=NaN,s){if(this.context=s,I(this,"matrix"),I(this,"_add_col"),I(this,"_add_row"),I(this,"_avg"),I(this,"_col"),I(this,"_columns"),I(this,"_concat"),I(this,"_copy"),I(this,"_det"),I(this,"_diff"),I(this,"_eigenvalues"),I(this,"_eigenvectors"),I(this,"_elements_count"),I(this,"_fill"),I(this,"_get"),I(this,"_inv"),I(this,"_is_antidiagonal"),I(this,"_is_antisymmetric"),I(this,"_is_binary"),I(this,"_is_diagonal"),I(this,"_is_identity"),I(this,"_is_square"),I(this,"_is_stochastic"),I(this,"_is_symmetric"),I(this,"_is_triangular"),I(this,"_is_zero"),I(this,"_kron"),I(this,"_max"),I(this,"_median"),I(this,"_min"),I(this,"_mode"),I(this,"_mult"),I(this,"_pinv"),I(this,"_pow"),I(this,"_rank"),I(this,"_remove_col"),I(this,"_remove_row"),I(this,"_reshape"),I(this,"_reverse"),I(this,"_row"),I(this,"_rows"),I(this,"_set"),I(this,"_sort"),I(this,"_submatrix"),I(this,"_sum"),I(this,"_swap_columns"),I(this,"_swap_rows"),I(this,"_trace"),I(this,"_transpose"),this.matrix=[],t>0&&i>0)for(let n=0;n<t;n++)this.matrix.push(Array(i).fill(r));this._add_col=ka(this.context),this._add_row=Ia(this.context),this._avg=Aa(this.context),this._col=Pa(this.context),this._columns=Ta(this.context),this._concat=Ra(this.context),this._copy=Da(this.context),this._det=Oa(this.context),this._diff=Ma(this.context),this._eigenvalues=Ba(this.context),this._eigenvectors=Fa(this.context),this._elements_count=ja(this.context),this._fill=$a(this.context),this._get=Wa(this.context),this._inv=Ua(this.context),this._is_antidiagonal=Ka(this.context),this._is_antisymmetric=za(this.context),this._is_binary=Ha(this.context),this._is_diagonal=Ga(this.context),this._is_identity=Ya(this.context),this._is_square=Qa(this.context),this._is_stochastic=Xa(this.context),this._is_symmetric=Za(this.context),this._is_triangular=Ja(this.context),this._is_zero=eo(this.context),this._kron=to(this.context),this._max=io(this.context),this._median=ro(this.context),this._min=so(this.context),this._mode=no(this.context),this._mult=ao(this.context),this._pinv=oo(this.context),this._pow=ho(this.context),this._rank=uo(this.context),this._remove_col=co(this.context),this._remove_row=lo(this.context),this._reshape=po(this.context),this._reverse=fo(this.context),this._row=mo(this.context),this._rows=go(this.context),this._set=xo(this.context),this._sort=yo(this.context),this._submatrix=wo(this.context),this._sum=bo(this.context),this._swap_columns=vo(this.context),this._swap_rows=_o(this.context),this._trace=So(this.context),this._transpose=Eo(this.context)}toString(){let t="";for(let i=0;i<this.matrix.length;i++)t+=t===""?"":`
|
|
116
|
-
`,t+="["+this.matrix[i].join(", ")+"]";return t}add_col(...t){return this._add_col(this,...t)}add_row(...t){return this._add_row(this,...t)}avg(...t){return this._avg(this,...t)}col(...t){return this._col(this,...t)}columns(...t){return this._columns(this,...t)}concat(...t){return this._concat(this,...t)}copy(...t){return this._copy(this,...t)}det(...t){return this._det(this,...t)}diff(...t){return this._diff(this,...t)}eigenvalues(...t){return this._eigenvalues(this,...t)}eigenvectors(...t){return this._eigenvectors(this,...t)}elements_count(...t){return this._elements_count(this,...t)}fill(...t){return this._fill(this,...t)}get(...t){return this._get(this,...t)}inv(...t){return this._inv(this,...t)}is_antidiagonal(...t){return this._is_antidiagonal(this,...t)}is_antisymmetric(...t){return this._is_antisymmetric(this,...t)}is_binary(...t){return this._is_binary(this,...t)}is_diagonal(...t){return this._is_diagonal(this,...t)}is_identity(...t){return this._is_identity(this,...t)}is_square(...t){return this._is_square(this,...t)}is_stochastic(...t){return this._is_stochastic(this,...t)}is_symmetric(...t){return this._is_symmetric(this,...t)}is_triangular(...t){return this._is_triangular(this,...t)}is_zero(...t){return this._is_zero(this,...t)}kron(...t){return this._kron(this,...t)}max(...t){return this._max(this,...t)}median(...t){return this._median(this,...t)}min(...t){return this._min(this,...t)}mode(...t){return this._mode(this,...t)}mult(...t){return this._mult(this,...t)}pinv(...t){return this._pinv(this,...t)}pow(...t){return this._pow(this,...t)}rank(...t){return this._rank(this,...t)}remove_col(...t){return this._remove_col(this,...t)}remove_row(...t){return this._remove_row(this,...t)}reshape(...t){return this._reshape(this,...t)}reverse(...t){return this._reverse(this,...t)}row(...t){return this._row(this,...t)}rows(...t){return this._rows(this,...t)}set(...t){return this._set(this,...t)}sort(...t){return this._sort(this,...t)}submatrix(...t){return this._submatrix(this,...t)}sum(...t){return this._sum(this,...t)}swap_columns(...t){return this._swap_columns(this,...t)}swap_rows(...t){return this._swap_rows(this,...t)}trace(...t){return this._trace(this,...t)}transpose(...t){return this._transpose(this,...t)}}function ko(e){return(t,i,r)=>new M(t,i,r,e)}function Io(e){return(t,i=0)=>d.from(t).get(i)}class Ao{constructor(t){this.context=t,this.add_col=(i,...r)=>i.add_col(...r),this.add_row=(i,...r)=>i.add_row(...r),this.avg=(i,...r)=>i.avg(...r),this.col=(i,...r)=>i.col(...r),this.columns=(i,...r)=>i.columns(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.det=(i,...r)=>i.det(...r),this.diff=(i,...r)=>i.diff(...r),this.eigenvalues=(i,...r)=>i.eigenvalues(...r),this.eigenvectors=(i,...r)=>i.eigenvectors(...r),this.elements_count=(i,...r)=>i.elements_count(...r),this.fill=(i,...r)=>i.fill(...r),this.get=(i,...r)=>i.get(...r),this.inv=(i,...r)=>i.inv(...r),this.is_antidiagonal=(i,...r)=>i.is_antidiagonal(...r),this.is_antisymmetric=(i,...r)=>i.is_antisymmetric(...r),this.is_binary=(i,...r)=>i.is_binary(...r),this.is_diagonal=(i,...r)=>i.is_diagonal(...r),this.is_identity=(i,...r)=>i.is_identity(...r),this.is_square=(i,...r)=>i.is_square(...r),this.is_stochastic=(i,...r)=>i.is_stochastic(...r),this.is_symmetric=(i,...r)=>i.is_symmetric(...r),this.is_triangular=(i,...r)=>i.is_triangular(...r),this.is_zero=(i,...r)=>i.is_zero(...r),this.kron=(i,...r)=>i.kron(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.mult=(i,...r)=>i.mult(...r),this.new=ko(t),this.param=Io(),this.pinv=(i,...r)=>i.pinv(...r),this.pow=(i,...r)=>i.pow(...r),this.rank=(i,...r)=>i.rank(...r),this.remove_col=(i,...r)=>i.remove_col(...r),this.remove_row=(i,...r)=>i.remove_row(...r),this.reshape=(i,...r)=>i.reshape(...r),this.reverse=(i,...r)=>i.reverse(...r),this.row=(i,...r)=>i.row(...r),this.rows=(i,...r)=>i.rows(...r),this.set=(i,...r)=>i.set(...r),this.sort=(i,...r)=>i.sort(...r),this.submatrix=(i,...r)=>i.submatrix(...r),this.sum=(i,...r)=>i.sum(...r),this.swap_columns=(i,...r)=>i.swap_columns(...r),this.swap_rows=(i,...r)=>i.swap_rows(...r),this.trace=(i,...r)=>i.trace(...r),this.transpose=(i,...r)=>i.transpose(...r)}}var Po=Object.defineProperty,To=(e,t,i)=>t in e?Po(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ro=(e,t,i)=>To(e,typeof t!="symbol"?t+"":t,i);class Do{constructor(t){this.context=t,Ro(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.data.close.data.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.data.close.data.length-1}get isrealtime(){return this.context.idx===this.context.data.close.data.length-1}get isconfirmed(){return this.context.data.closeTime[this.context.data.closeTime.length-1]<=new Date().getTime()}get islastconfirmedhistory(){return this.context.data.closeTime[this.context.data.closeTime.length-1]<=new Date().getTime()}}const fr={series:e=>e instanceof d||typeof e=="number",string:e=>typeof e=="string",number:e=>typeof e=="number",boolean:e=>typeof e=="boolean",array:e=>Array.isArray(e),object:e=>typeof e=="object",primitive:e=>typeof e===null||typeof e!="object"&&typeof e!="function",function:e=>typeof e=="function",undefined:e=>e===void 0,null:e=>e===null,NaN:e=>isNaN(e),remaining_options:e=>typeof e=="object"&&!(e instanceof d)};function Ut(e,t,i){Array.isArray(t)&&typeof t[0]=="string"&&(t=[t]);const r={};let s={};const n=new Array(t.length).fill(!0);for(let a=0;a<e.length;a++){const o=e[a];if(fr.remaining_options(o)){s=o;break}const h=t.map((u,l)=>n[l]?u[a]:void 0);for(let u=0;u<h.length;u++){const l=h[u];if(l===void 0){n[u]=!1;continue}const f=fr[i[l]];typeof f=="function"&&f(o)?r[l]=o:n[u]=!1}}return{...s,...r}}var Vo=Object.defineProperty,Oo=(e,t,i)=>t in e?Vo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Mo=(e,t,i)=>Oo(e,typeof t!="symbol"?t+"":t,i);const Lo=["title","shorttitle","overlay","format","precision","scale","max_bars_back","timeframe","timeframe_gaps","explicit_plot_zorder","max_lines_count","max_labels_count","max_boxes_count","calc_bars_count","max_polylines_count","dynamic_requests","behind_chart"],Bo={title:"string",shorttitle:"string",overlay:"boolean",format:"string",precision:"number",scale:"string",max_bars_back:"number",timeframe:"string",timeframe_gaps:"boolean",explicit_plot_zorder:"boolean",max_lines_count:"number",max_labels_count:"number",max_boxes_count:"number",calc_bars_count:"number",max_polylines_count:"number",dynamic_requests:"boolean",behind_chart:"boolean"};function Fo(e){return Ut(e,Lo,Bo)}class jo{constructor(t){this.context=t,Mo(this,"color",{param:(i,r=0)=>d.from(i).get(r),rgb:(i,r,s,n)=>n?`rgba(${i}, ${r}, ${s}, ${n})`:`rgb(${i}, ${r}, ${s})`,new:(i,r)=>{if(i&&i.startsWith("#")){const s=i.slice(1),n=parseInt(s.slice(0,2),16),a=parseInt(s.slice(2,4),16),o=parseInt(s.slice(4,6),16);return r?`rgba(${n}, ${a}, ${o}, ${r})`:`rgb(${n}, ${a}, ${o})`}return r?`rgba(${i}, ${r})`:i},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue",yellow:"yellow",orange:"orange",purple:"purple",pink:"pink",brown:"brown",teal:"teal",cyan:"cyan",navy:"navy",indigo:"indigo",violet:"violet",magenta:"magenta",rose:"rose",gold:"gold",silver:"silver",bronze:"bronze"})}extractPlotOptions(t){const i={};for(let r in t)i[r]=d.from(t[r]).get(0);return i}indicator(...t){const i=Fo(t),r={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...r,...i},this.context.indicator}get bar_index(){return this.context.idx}na(t){return isNaN(d.from(t).get(0))}nz(t,i=0){const r=d.from(t).get(0),s=d.from(i).get(0);return isNaN(r)?s:r}fixnan(t){const i=d.from(t);for(let r=0;r<i.length;r++){const s=i.get(r);if(!isNaN(s))return s}return NaN}alertcondition(t,i,r){}bool(t){const i=d.from(t).get(0);return!isNaN(i)&&i!==0}int(t){const i=d.from(t).get(0);if(typeof i!="number")throw new Error(`Cannot call "int" with argument "x"="${i}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.floor(i)}float(t){const i=d.from(t).get(0);if(typeof i!="number")throw new Error(`Cannot call "float" with argument "x"="${i}". An argument of "literal string" type was used but a "const float" is expected.`);return i}string(t){return d.from(t).get(0).toString()}}const $o=[["defval","title","tooltip","inline","group","display"],["defval","title","tooltip","group","confirm","display"],["defval","title","tooltip","inline","group","confirm","display"],["defval","title","options","tooltip","inline","group","confirm","display"],["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display"]],Wo={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function re(e){return Ut(e,$o,Wo)}function qo(e){return(...t)=>re(t).defval}function Uo(e){return(...t)=>re(t).defval}function Ko(e){return(...t)=>re(t).defval}function zo(e){return(...t)=>re(t).defval}function Ho(e){return(...t)=>re(t).defval}function Go(e){return(...t)=>re(t).defval}function Yo(e){return(t,i=0)=>d.from(t).get(i)}function Qo(e){return(...t)=>re(t).defval}function Xo(e){return(...t)=>re(t).defval}function Zo(e){return(...t)=>re(t).defval}function Jo(e){return(...t)=>re(t).defval}function eh(e){return(...t)=>re(t).defval}function th(e){return(...t)=>re(t).defval}function ih(e){return(...t)=>re(t).defval}function rh(e){return(...t)=>re(t).defval}var sh=Object.defineProperty,nh=(e,t,i)=>t in e?sh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t,i)=>nh(e,typeof t!="symbol"?t+"":t,i);const ah={any:qo,bool:Uo,color:Ko,enum:zo,float:Ho,int:Go,param:Yo,price:Qo,session:Xo,source:Zo,string:Jo,symbol:eh,text_area:th,time:ih,timeframe:rh};class oh{constructor(t){this.context=t,Z(this,"any"),Z(this,"bool"),Z(this,"color"),Z(this,"enum"),Z(this,"float"),Z(this,"int"),Z(this,"param"),Z(this,"price"),Z(this,"session"),Z(this,"source"),Z(this,"string"),Z(this,"symbol"),Z(this,"text_area"),Z(this,"time"),Z(this,"timeframe"),Object.entries(ah).forEach(([i,r])=>{this[i]=r(t)})}}function hh(e){return t=>Math.abs(d.from(t).get(0))}function uh(e){return t=>Math.acos(d.from(t).get(0))}function ch(e){return t=>Math.asin(d.from(t).get(0))}function lh(e){return t=>Math.atan(d.from(t).get(0))}function ph(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return i.reduce((r,s)=>r+s,0)/i.length}}function fh(e){return t=>Math.ceil(d.from(t).get(0))}function mh(e){return t=>Math.cos(d.from(t).get(0))}function dh(e){return()=>Math.E}function gh(e){return t=>Math.exp(d.from(t).get(0))}function xh(e){return t=>Math.floor(d.from(t).get(0))}function yh(e){return t=>Math.log(d.from(t).get(0))}function wh(e){return t=>Math.log(d.from(t).get(0))}function bh(e){return t=>Math.log10(d.from(t).get(0))}function vh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.max(...i)}}function _h(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.min(...i)}}function Sh(e){return(t,i,r)=>typeof t=="string"?t:t instanceof d?i?new d(t.data,t.offset+i):t:!Array.isArray(t)&&typeof t=="object"?t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new d(t,i||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new d(e.params[r],0)))}function Eh(e){return()=>1.618033988749895}function Nh(e){return()=>Math.PI}function Ch(e){return(t,i)=>Math.pow(d.from(t).get(0),d.from(i).get(0))}function kh(e){return()=>Math.random()}function Ih(e){return t=>Math.round(d.from(t).get(0))}function Ah(e){return t=>e.precision(Math.round(d.from(t).get(0)/e.pine.syminfo.mintick)*e.pine.syminfo.mintick)}function Ph(e){return()=>.6180339887498948}function Th(e){return t=>Math.sign(d.from(t).get(0))}function Rh(e){return t=>Math.sin(d.from(t).get(0))}function Dh(e){return t=>Math.sqrt(d.from(t).get(0))}function Vh(e){return(t,i)=>{const r=d.from(i).get(0),s=d.from(t);let n=0;for(let a=0;a<r;a++){const o=s.get(a);n+=o}return n}}function Oh(e){return t=>Math.tan(d.from(t).get(0))}function Mh(e){return(t,i)=>{const r=d.from(t).get(0),s=d.from(i).get(0);return typeof r=="number"&&typeof s=="number"?isNaN(r)&&isNaN(s)?!0:isNaN(r)||isNaN(s)?!1:Math.abs(r-s)<1e-8:r===s}}var Lh=Object.defineProperty,Bh=(e,t,i)=>t in e?Lh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,L=(e,t,i)=>Bh(e,typeof t!="symbol"?t+"":t,i);const Fh={abs:hh,acos:uh,asin:ch,atan:lh,avg:ph,ceil:fh,cos:mh,e:dh,exp:gh,floor:xh,ln:yh,log:wh,log10:bh,max:vh,min:_h,param:Sh,phi:Eh,pi:Nh,pow:Ch,random:kh,round:Ih,round_to_mintick:Ah,rphi:Ph,sign:Th,sin:Rh,sqrt:Dh,sum:Vh,tan:Oh,__eq:Mh};class jh{constructor(t){this.context=t,L(this,"_cache",{}),L(this,"abs"),L(this,"acos"),L(this,"asin"),L(this,"atan"),L(this,"avg"),L(this,"ceil"),L(this,"cos"),L(this,"e"),L(this,"exp"),L(this,"floor"),L(this,"ln"),L(this,"log"),L(this,"log10"),L(this,"max"),L(this,"min"),L(this,"param"),L(this,"phi"),L(this,"pi"),L(this,"pow"),L(this,"random"),L(this,"round"),L(this,"round_to_mintick"),L(this,"rphi"),L(this,"sign"),L(this,"sin"),L(this,"sqrt"),L(this,"sum"),L(this,"tan"),L(this,"__eq"),Object.entries(Fh).forEach(([i,r])=>{this[i]=r(t)})}}function $h(e){return(t,i,r)=>{e.params[r]||(e.params[r]=[]);let s;if(t instanceof d)s=t.get(i||0);else if(Array.isArray(t)){const n=t.every(o=>o instanceof d),a=t.every(o=>!(o instanceof d)&&!Array.isArray(o));(n||a)&&t.length>=1?n?s=t.map(o=>o.get(0)):s=t:s=d.from(t).get(i||0)}else s=t;return e.params[r].length===0?e.params[r].push(s):e.params[r][e.params[r].length-1]=s,[s,r]}}const gt=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function mr(e,t,i,r,s=!1){for(let n=0;n<i.length;n++)if(i[n]<=e&&t<=r[n])return s||t>=r[n]?n:n-1;return-1}function dr(e,t,i,r,s=!1,n,a=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=t&&i[o]>=e){const h=n&&t>n;if(a&&s)for(let u=0;u<i.length;u++){if(i[u]>=e&&i[u]<t)return u;if(i[u]>=t)break}if(h&&s&&!a)for(let u=0;u<i.length;u++){if(i[u]>=e&&i[u]<t)return u;if(i[u]>=t)break}return o}if(r[o]<e)break}return-1}function Wh(e){return async(t,i,r,s=!1,n=!1,a=!1,o=null,h=null)=>{const u=t[0],l=i[0],f=r[0],g=r[1],p=Array.isArray(s)?s[0]:s,x=Array.isArray(n)?n[0]:n;if(e.isSecondaryContext)return f;const y=gt.indexOf(e.timeframe),w=gt.indexOf(l);if(y==-1||w==-1)throw new Error("Invalid timeframe");if(y===w)return f;const E=y>w,A=d.from(e.data.openTime).get(0),k=d.from(e.data.closeTime).get(0),T=`${u}_${l}_${g}`,C=`${T}_prevIdx`;if(e.cache[T]){const nt=e.cache[T],wt=E?dr(A,k,nt.data.openTime.data,nt.data.closeTime.data,x,e.eDate,p):mr(A,k,nt.data.openTime.data,nt.data.closeTime.data,x);if(wt==-1)return NaN;const He=nt.params[g][wt];if(!E&&p){const yr=e.cache[C];return yr!==void 0&&yr===wt?NaN:(e.cache[C]=wt,Array.isArray(He)?[He]:He)}return Array.isArray(He)?[He]:He}const J=1e3*60*60*24*30,Y=e.sDate?e.sDate-J:void 0,H=e.sDate&&e.eDate?void 0:e.limit||1e3,st=new zt(e.source,u,l,H,Y,void 0);st.markAsSecondary();const Te=await st.run(e.pineTSCode);e.cache[T]=Te;const Yt=E?dr(A,k,Te.data.openTime.data,Te.data.closeTime.data,x,e.eDate,p):mr(A,k,Te.data.openTime.data,Te.data.closeTime.data,x);if(Yt==-1)return NaN;const Qt=Te.params[g][Yt];return!E&&p?(e.cache[C]=Yt,NaN):Array.isArray(Qt)?[Qt]:Qt}}function qh(e){return async(t,i,r,s=!1,n=null,a=!1,o=0)=>{const h=t[0],u=i[0],l=r[0],f=r[1];Array.isArray(s)&&s[0];const g=Array.isArray(a)?a[0]:a;if(e.isSecondaryContext)return Array.isArray(l)?[l]:l;const p=gt.indexOf(e.timeframe),x=gt.indexOf(u);if(p===-1||x===-1){if(g)return NaN;throw new Error("Invalid timeframe")}if(x>p){if(g)return NaN;throw new Error(`Timeframe ${u} is not lower than or equal to chart timeframe ${e.timeframe}`)}if(x===p)return[[l]];const y=`${h}_${u}_${f}_lower`;if(!e.cache[y]){const Y=e.sDate?e.sDate-2592e6:void 0,H=e.sDate&&e.eDate?void 0:e.limit||1e3,st=new zt(e.source,h,u,H,Y,e.eDate);st.markAsSecondary();const Te=await st.run(e.pineTSCode);e.cache[y]=Te}const w=e.cache[y],E=d.from(e.data.openTime).get(0),A=d.from(e.data.closeTime).get(0),k=w.data.openTime.data,T=w.data.closeTime.data,C=w.params[f];if(!C)return[];const J=[];for(let Y=0;Y<k.length;Y++){const H=k[Y];if(!(T[Y]<=E)){if(H>=A)break;H>=E&&H<A&&J.push(C[Y])}}return[J]}}var Uh=Object.defineProperty,Kh=(e,t,i)=>t in e?Uh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,xt=(e,t,i)=>Kh(e,typeof t!="symbol"?t+"":t,i);const zh={param:$h,security:Wh,security_lower_tf:qh};class Hh{constructor(t){this.context=t,xt(this,"_cache",{}),xt(this,"param"),xt(this,"security"),xt(this,"security_lower_tf"),Object.entries(zh).forEach(([i,r])=>{this[i]=r(t)})}}function Gh(e){return t=>{e.taState||(e.taState={});const i=t||"accdist";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.volume,0);if(isNaN(s)||isNaN(n)||isNaN(a)||isNaN(o))return e.precision(r.cumulativeSum);const h=n-a;let u=0;return h!==0&&(u=(s-a-(n-s))/h*o),r.cumulativeSum+=u,e.precision(r.cumulativeSum)}}function Yh(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0),h=d.from(s).get(0);e.taState||(e.taState={});const u=n||`alma_${a}_${o}_${h}`;if(!e.taState[u]){const p=o*(a-1),x=a/h,y=[];let w=0;for(let E=0;E<a;E++){const A=Math.exp(-Math.pow(E-p,2)/(2*x*x));y.push(A),w+=A}for(let E=0;E<y.length;E++)y[E]/=w;e.taState[u]={window:[],weights:y}}const l=e.taState[u],f=d.from(t).get(0);if(l.window.unshift(f),l.window.length<a)return NaN;l.window.length>a&&l.window.pop();let g=0;for(let p=0;p<a;p++)g+=l.weights[p]*l.window[a-1-p];return e.precision(g)}}function Qh(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const s=i||`atr_${r}`;e.taState[s]||(e.taState[s]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const n=e.taState[s],a=e.get(e.data.high,0),o=e.get(e.data.low,0),h=e.get(e.data.close,0);let u;if(n.prevClose!==null){const f=a-o,g=Math.abs(a-n.prevClose),p=Math.abs(o-n.prevClose);u=Math.max(f,g,p)}else u=a-o;if(n.prevClose=h,n.initCount<r)return n.initSum+=u,n.initCount++,n.initCount===r?(n.prevAtr=n.initSum/r,e.precision(n.prevAtr)):NaN;const l=(n.prevAtr*(r-1)+u)/r;return n.prevAtr=l,e.precision(l)}}function Xh(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"barssince";e.taState[r]||(e.taState[r]={lastTrueIndex:null});const s=e.taState[r];return d.from(t).get(0)?(s.lastTrueIndex=e.idx,0):s.lastTrueIndex===null?NaN:e.idx-s.lastTrueIndex}}function Zh(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`bb_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const h=e.taState[o],u=d.from(t).get(0);if(isNaN(u))return[[NaN,NaN,NaN]];if(h.window.unshift(u),h.sum+=u,h.window.length<n)return[[NaN,NaN,NaN]];if(h.window.length>n){const y=h.window.pop();h.sum-=y}const l=h.sum/n;let f=0;for(let y=0;y<n;y++)f+=Math.pow(h.window[y]-l,2);const g=Math.sqrt(f/n),p=l+a*g,x=l-a*g;return[[e.precision(p),e.precision(l),e.precision(x)]]}}function Jh(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`bbw_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const h=e.taState[o],u=d.from(t).get(0);if(isNaN(u))return NaN;if(h.window.unshift(u),h.sum+=u,h.window.length<n)return NaN;if(h.window.length>n){const w=h.window.pop();h.sum-=w}const l=h.sum/n;let f=0;for(let w=0;w<n;w++){const E=h.window[w]-l;f+=E*E}const g=f/n,p=Math.sqrt(g),x=a*p;if(l===0)return e.precision(0);const y=2*x/l*100;return e.precision(y)}}function eu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`cci_${s}`;e.taState[n]||(e.taState[n]={window:[],sum:0});const a=e.taState[n],o=d.from(t).get(0);if(isNaN(o))return NaN;if(a.window.unshift(o),a.sum+=o,a.window.length<s)return NaN;if(a.window.length>s){const g=a.window.pop();a.sum-=g}const h=a.sum/s;let u=0;for(let g=0;g<s;g++)u+=Math.abs(a.window[g]-h);const l=u/s;if(l===0)return 0;const f=(o-h)/(.015*l);return e.precision(f)}}function tu(e){return(t,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`change_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=s)return NaN;a.window.length>s+1&&a.window.pop();const h=o-a.window[s];return e.precision(h)}}function iu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`cmo_${s}`;e.taState[n]||(e.taState[n]={gainsWindow:[],lossesWindow:[],gainsSum:0,lossesSum:0});const a=e.taState[n],o=d.from(t).get(0),h=d.from(t).get(1);if(isNaN(o)||isNaN(h))return NaN;const u=o-h,l=u>=0?u:0,f=u>=0?0:-u;if(a.gainsWindow.unshift(l),a.lossesWindow.unshift(f),a.gainsSum+=l,a.lossesSum+=f,a.gainsWindow.length<s)return NaN;if(a.gainsWindow.length>s){const x=a.gainsWindow.pop(),y=a.lossesWindow.pop();a.gainsSum-=x,a.lossesSum-=y}const g=a.gainsSum+a.lossesSum;if(g===0)return e.precision(0);const p=100*(a.gainsSum-a.lossesSum)/g;return e.precision(p)}}function ru(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);let a=0,o=!1;for(let l=0;l<s;l++){const f=n.get(l);if(isNaN(f)){o=!0;break}a+=f}if(o)return NaN;let h=0;for(let l=0;l<s;l++){const f=n.get(l);h+=f*(l+1)}if(a===0)return NaN;const u=-h/a;return e.precision(u)}}function su(e){return(t,i,r,s)=>{const n=d.from(r).get(0),a=d.from(t),o=d.from(i);if(e.idx<n-1)return NaN;let h=0,u=0,l=0,f=0,g=0,p=0;for(let A=0;A<n;A++){const k=a.get(A),T=o.get(A);isNaN(k)||isNaN(T)||(h+=k,u+=T,l+=k*T,f+=k*k,g+=T*T,p++)}if(p<2)return NaN;const x=p*l-h*u,y=p*f-h*h,w=p*g-u*u;if(y<=0||w<=0)return e.precision(0);const E=x/Math.sqrt(y*w);return e.precision(E)}}function nu(e){return(t,i,r)=>{const s=d.from(t),n=d.from(i),a=s.get(0),o=n.get(0),h=s.get(1),u=n.get(1);if(isNaN(a)||isNaN(o)||isNaN(h)||isNaN(u))return!1;const l=a>o&&h<=u,f=a<o&&h>=u;return l||f}}function au(e){return(t,i)=>{const r=d.from(t),s=d.from(i),n=r.get(0),a=s.get(0),o=r.get(1),h=s.get(1);return o<h&&n>a}}function ou(e){return(t,i)=>{const r=d.from(t),s=d.from(i),n=r.get(0),a=s.get(0),o=r.get(1),h=s.get(1);return o>h&&n<a}}function hu(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"cum";e.taState[r]||(e.taState[r]={cumulativeSum:0});const s=e.taState[r],n=d.from(t).get(0);return isNaN(n)||(s.cumulativeSum+=n),e.precision(s.cumulativeSum)}}function uu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`dev_${s}`;e.taState[n]||(e.taState[n]={window:[],sum:0});const a=e.taState[n],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<s)return NaN;if(a.window.length>s){const f=a.window.pop();a.sum-=f}const h=a.sum/s;let u=0;for(let f=0;f<s;f++)u+=Math.abs(a.window[f]-h);const l=u/s;return e.precision(l)}}function cu(e){return(t,i,r)=>{const s=d.from(t).get(0),n=d.from(i).get(0);e.taState||(e.taState={});const a=r||`dmi_${s}_${n}`;e.taState[a]||(e.taState[a]={prevHigh:NaN,prevLow:NaN,prevClose:NaN,trInitSum:0,plusInitSum:0,minusInitSum:0,initCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,dxInitSum:0,adxInitCount:0,prevADX:NaN});const o=e.taState[a],h=e.get(e.data.high,0),u=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(u)||isNaN(l))return[[NaN,NaN,NaN]];if(isNaN(o.prevHigh))return o.prevHigh=h,o.prevLow=u,o.prevClose=l,[[NaN,NaN,NaN]];const f=Math.max(h-u,Math.abs(h-o.prevClose),Math.abs(u-o.prevClose)),g=h-o.prevHigh,p=o.prevLow-u,x=g>p&&g>0?g:0,y=p>g&&p>0?p:0;o.prevHigh=h,o.prevLow=u,o.prevClose=l;let w,E,A;if(o.initCount++,o.initCount<=s)o.trInitSum+=f,o.plusInitSum+=x,o.minusInitSum+=y,o.initCount===s&&(o.prevSmoothedTR=o.trInitSum/s,o.prevSmoothedPlus=o.plusInitSum/s,o.prevSmoothedMinus=o.minusInitSum/s);else{const H=1/s;o.prevSmoothedTR=H*f+(1-H)*o.prevSmoothedTR,o.prevSmoothedPlus=H*x+(1-H)*o.prevSmoothedPlus,o.prevSmoothedMinus=H*y+(1-H)*o.prevSmoothedMinus}if(w=o.prevSmoothedTR,E=o.prevSmoothedPlus,A=o.prevSmoothedMinus,o.initCount<s)return[[NaN,NaN,NaN]];const k=w===0?0:100*E/w,T=w===0?0:100*A/w,C=k+T,J=C===0?0:100*Math.abs(k-T)/C;let Y=NaN;if(o.adxInitCount++,o.adxInitCount<=n)o.dxInitSum+=J,o.adxInitCount===n&&(o.prevADX=o.dxInitSum/n,Y=o.prevADX);else{const H=1/n;o.prevADX=H*J+(1-H)*o.prevADX,Y=o.prevADX}return[[e.precision(k),e.precision(T),e.precision(Y)]]}}function lu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`ema_${s}`;e.taState[n]||(e.taState[n]={prevEma:null,initSum:0,initCount:0});const a=e.taState[n],o=d.from(t).get(0);if(a.initCount<s)return a.initSum+=o,a.initCount++,a.initCount===s?(a.prevEma=a.initSum/s,e.precision(a.prevEma)):NaN;const h=2/(s+1),u=o*h+a.prevEma*(1-h);return a.prevEma=u,e.precision(u)}}function pu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);for(let a=0;a<s;a++){const o=n.get(a),h=n.get(a+1);if(isNaN(o)||isNaN(h)||o>=h)return!1}return!0}}function fu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`highest_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();const h=Math.max(...a.window.filter(u=>!isNaN(u)));return e.precision(h)}}function mu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s-1)return NaN;let a=-1/0,o=NaN;for(let h=0;h<s;h++){const u=n.get(h);isNaN(u)||(isNaN(o)||u>a)&&(a=u,o=-h)}return o}}function du(e){return(t,i,r)=>{const s=d.from(i).get(0),n=Math.floor(s/2),a=Math.floor(Math.sqrt(s)),o=e.ta.wma,h=o(t,n,r?`${r}_wma1`:void 0),u=o(t,s,r?`${r}_wma2`:void 0);if(isNaN(h)||isNaN(u))return NaN;e.taState||(e.taState={});const l=r||`hma_raw_${s}`;e.taState[l]||(e.taState[l]=[]);const f=2*h-u;e.taState[l].unshift(f);const g=r?`${r}_hma_final`:`hma_final_${s}`;e.taState[g]||(e.taState[g]={window:[]});const p=e.taState[g];if(p.window.unshift(f),p.window.length<a)return NaN;p.window.length>a&&p.window.pop();let x=0,y=0;for(let E=0;E<a;E++){const A=a-E;x+=p.window[E]*A,y+=A}const w=x/y;return e.precision(w)}}function gu(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.high,0),s=e.get(e.data.low,0),n=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(n))return NaN;const a=(r-s)*n;if(a===0)return e.precision(0);const o=(2*i-r-s)/a;return e.precision(o)}}function xu(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let h=!0;typeof s=="string"?n=s:s!==void 0&&(h=d.from(s).get(0));let u;const l=e.get(e.data.high,0),f=e.get(e.data.low,0);if(h){const T=e.get(e.data.close,1);isNaN(T)?u=NaN:u=Math.max(l-f,Math.abs(l-T),Math.abs(f-T))}else u=l-f;const g=d.from(t).get(0);e.taState||(e.taState={});const p=n||`kc_${a}_${o}_${h}`;e.taState[p]||(e.taState[p]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const x=e.taState[p],y=(T,C,J)=>{if(isNaN(C))return NaN;if(T.initCount<J)return T.initSum+=C,T.initCount++,T.initCount===J?(T.prevEma=T.initSum/J,T.prevEma):NaN;const Y=2/(J+1);return T.prevEma=C*Y+T.prevEma*(1-Y),T.prevEma},w=y(x.basisState,g,a),E=y(x.rangeState,u,a);if(isNaN(w)||isNaN(E))return[[NaN,NaN,NaN]];const A=w+E*o,k=w-E*o;return[[e.precision(w),e.precision(A),e.precision(k)]]}}function yu(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let h=!0;typeof s=="string"?n=s:s!==void 0&&(h=d.from(s).get(0)),e.taState||(e.taState={});const u=n||`kcw_${a}_${o}_${h}`;e.taState[u]||(e.taState[u]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const l=e.taState[u],f=(k,T,C)=>{if(isNaN(T))return NaN;if(k.initCount<C)return k.initSum+=T,k.initCount++,k.initCount===C?(k.prevEma=k.initSum/C,k.prevEma):NaN;const J=2/(C+1);return k.prevEma=T*J+k.prevEma*(1-J),k.prevEma};let g;const p=e.get(e.data.high,0),x=e.get(e.data.low,0);if(h){const k=e.get(e.data.close,1);isNaN(k)?g=NaN:g=Math.max(p-x,Math.abs(p-k),Math.abs(x-k))}else g=p-x;const y=d.from(t).get(0),w=f(l.basisState,y,a),E=f(l.rangeState,g,a);if(isNaN(w)||isNaN(E))return NaN;if(w===0)return e.precision(0);const A=2*E*o/w;return e.precision(A)}}function wu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`linreg_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[]});const h=e.taState[o],u=d.from(t).get(0);if(h.window.unshift(u),h.window.length<n)return NaN;h.window.length>n&&h.window.pop();let l=0,f=0,g=0,p=0;const x=n;for(let A=0;A<n;A++){const k=n-1-A,T=h.window[A];l+=k,f+=T,g+=k*T,p+=k*k}const y=x*p-l*l;if(y===0)return NaN;const w=(x*g-l*f)/y,E=(f-w*l)/x+w*(n-1-a);return e.precision(E)}}function bu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`lowest_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();const h=a.window.filter(l=>!isNaN(l)&&l!==void 0),u=h.length>0?Math.min(...h):NaN;return e.precision(u)}}function vu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s-1)return NaN;let a=1/0,o=NaN;for(let h=0;h<s;h++){const u=n.get(h);isNaN(u)||(isNaN(o)||u<a)&&(a=u,o=-h)}return o}}function _u(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0),h=d.from(s).get(0),u=n||`macd_${a}_${o}_${h}`,l=`${u}_fast`,f=`${u}_slow`,g=`${u}_signal`,p=e.ta.ema(t,a,l),x=e.ta.ema(t,o,f);let y=NaN;!isNaN(p)&&!isNaN(x)&&(y=p-x);let w=NaN;isNaN(y)||(w=e.ta.ema(y,h,g));let E=NaN;return!isNaN(y)&&!isNaN(w)&&(E=y-w),[[e.precision(y),e.precision(w),e.precision(E)]]}}function Su(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`median_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();const h=a.window.slice().sort((f,g)=>f-g),u=Math.floor(s/2),l=s%2===0?(h[u-1]+h[u])/2:h[u];return e.precision(l)}}function Eu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`mfi_${s}`;e.taState[n]||(e.taState[n]={upperWindow:[],lowerWindow:[],upperSum:0,lowerSum:0});const a=e.taState[n],o=d.from(t).get(0),h=d.from(t).get(1),u=e.get(e.data.volume,0);if(isNaN(o)||isNaN(u))return NaN;const l=isNaN(h)?NaN:o-h;let f=0,g=0;if(f=u*(l<=0?0:o),g=u*(l>=0?0:o),a.upperWindow.unshift(f),a.lowerWindow.unshift(g),a.upperSum+=f,a.lowerSum+=g,a.upperWindow.length<s)return NaN;if(a.upperWindow.length>s){const x=a.upperWindow.pop(),y=a.lowerWindow.pop();a.upperSum-=x,a.lowerSum-=y}if(a.lowerSum===0)return a.upperSum,e.precision(100);if(a.upperSum===0)return e.precision(0);const p=100-100/(1+a.upperSum/a.lowerSum);return e.precision(p)}}function Nu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s-1)return NaN;const a=new Map;for(let u=0;u<s;u++){const l=n.get(u);isNaN(l)||a.set(l,(a.get(l)||0)+1)}if(a.size===0)return NaN;let o=NaN,h=-1;for(const[u,l]of a.entries())l>h?(h=l,o=u):l===h&&u<o&&(o=u);return o}}function Cu(e){return(t,i,r)=>{const s=d.from(i).get(0);return e.ta.change(t,s)}}function ku(e){return t=>{e.taState||(e.taState={});const i=t||"nvi";e.taState[i]||(e.taState[i]={nvi:1});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),h=isNaN(s)?0:s,u=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||u===0)&&l<f){const g=(h-u)/u;r.nvi=r.nvi+g*r.nvi}return e.precision(r.nvi)}}function Iu(e){return()=>{e.taState||(e.taState={});const t="obv";e.taState[t]||(e.taState[t]={prevOBV:0});const i=e.taState[t],r=e.get(e.data.close,0),s=e.get(e.data.volume,0),n=e.get(e.data.close,1);if(isNaN(n))return i.prevOBV=0,e.precision(0);let a;return r>n?a=i.prevOBV+s:r<n?a=i.prevOBV-s:a=i.prevOBV,i.prevOBV=a,e.precision(a)}}function Au(e){return(t,i,r)=>t instanceof d?i?new d(t.data,t.offset+i):t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new d(t,i||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new d(e.params[r],0)))}function Pu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<n-1)return NaN;const h=[];for(let x=0;x<n;x++){const y=o.get(x);if(isNaN(y))return NaN;h.push(y)}h.sort((x,y)=>x-y);let u=a/100*n-.5;u<0&&(u=0),u>n-1&&(u=n-1);const l=Math.floor(u),f=Math.ceil(u);if(l===f)return e.precision(h[l]);const g=u-l,p=h[l]+g*(h[f]-h[l]);return e.precision(p)}}function Tu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<n-1)return NaN;const h=[];for(let l=0;l<n;l++){const f=o.get(l);isNaN(f)||h.push(f)}if(h.length===0)return NaN;h.sort((l,f)=>l-f);let u=Math.ceil(a/100*h.length)-1;return u<0&&(u=0),u>=h.length&&(u=h.length-1),e.precision(h[u])}}function Ru(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s)return NaN;const a=n.get(0);if(isNaN(a))return NaN;let o=0,h=0;for(let u=1;u<=s;u++){const l=n.get(u);isNaN(l)||(h++,l<=a&&o++)}return h===0?NaN:e.precision(o/h*100)}}function Du(e,t,i){const r=new Array(e.length).fill(NaN);for(let s=t+i;s<e.length;s++){const n=e[s-i];let a=!0;for(let o=1;o<=t;o++)if(e[s-i-o]>=n){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[s-i+o]>=n){a=!1;break}}a&&(r[s]=n)}return r}function Vu(e){return(t,i,r,s)=>{typeof r=="string"&&(r=i,i=t,t=e.data.high);const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),h=Du(o,n,a),u=e.idx;return e.precision(h[u])}}function Ou(e,t,i){const r=new Array(e.length).fill(NaN);for(let s=t+i;s<e.length;s++){const n=e[s-i];let a=!0;for(let o=1;o<=t;o++)if(e[s-i-o]<=n){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[s-i+o]<=n){a=!1;break}}a&&(r[s]=n)}return r}function Mu(e){return(t,i,r,s)=>{typeof r=="string"&&(r=i,i=t,t=e.data.low);const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),h=Ou(o,n,a),u=e.idx;return e.precision(h[u])}}function Lu(e){return t=>{e.taState||(e.taState={});const i=t||"pvi";e.taState[i]||(e.taState[i]={pvi:1});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),h=isNaN(s)?0:s,u=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||u===0)&&l>f){const g=(h-u)/u;r.pvi=r.pvi+g*r.pvi}return e.precision(r.pvi)}}function Bu(e){return t=>{e.taState||(e.taState={});const i=t||"pvt";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.close,1),a=e.get(e.data.volume,0);if(!isNaN(s)&&!isNaN(n)&&!isNaN(a)&&n!==0){const o=(s-n)/n*a;r.cumulativeSum+=o}return e.precision(r.cumulativeSum)}}function Fu(e){return(t,i,r)=>{const s=e.pine.ta.highest(t,i,(r||"range")+"_h"),n=e.pine.ta.lowest(t,i,(r||"range")+"_l");return isNaN(s)||isNaN(n)?NaN:e.precision(s-n)}}function ju(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);for(let a=0;a<s;a++){const o=n.get(a),h=n.get(a+1);if(isNaN(o)||isNaN(h)||o<=h)return!1}return!0}}function $u(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`rma_${s}`;e.taState[n]||(e.taState[n]={prevRma:null,initSum:0,initCount:0});const a=e.taState[n],o=d.from(t).get(0)||0;if(a.initCount<s)return a.initSum+=o,a.initCount++,a.initCount===s?(a.prevRma=a.initSum/s,e.precision(a.prevRma)):NaN;const h=1/s,u=o*h+a.prevRma*(1-h);return a.prevRma=u,e.precision(u)}}function Wu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`roc_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=s)return NaN;a.window.length>s+1&&a.window.pop();const h=a.window[s],u=(o-h)/h*100;return e.precision(u)}}function qu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`rsi_${s}`;e.taState[n]||(e.taState[n]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.prevValue!==null){const h=o-a.prevValue,u=h>0?h:0,l=h<0?-h:0;if(a.initGains.length<s){if(a.initGains.push(u),a.initLosses.push(l),a.initGains.length===s){a.avgGain=a.initGains.reduce((p,x)=>p+x,0)/s,a.avgLoss=a.initLosses.reduce((p,x)=>p+x,0)/s,a.prevValue=o;const g=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return e.precision(g)}return a.prevValue=o,NaN}a.avgGain=(a.avgGain*(s-1)+u)/s,a.avgLoss=(a.avgLoss*(s-1)+l)/s;const f=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return a.prevValue=o,e.precision(f)}return a.prevValue=o,NaN}}function Uu(e){return(t,i,r,s)=>{const n=d.from(t).get(0),a=d.from(i).get(0),o=d.from(r).get(0);e.taState||(e.taState={});const h=s||`sar_${n}_${a}_${o}`;e.taState[h]||(e.taState[h]={result:NaN,maxMin:NaN,acceleration:NaN,isBelow:!1,barIndex:0});const u=e.taState[h],l=e.get(e.data.high,0),f=e.get(e.data.low,0),g=e.get(e.data.close,0),p=e.get(e.data.close,1),x=e.get(e.data.high,1),y=e.get(e.data.low,1),w=e.get(e.data.high,2),E=e.get(e.data.low,2);if(isNaN(l)||isNaN(f)||isNaN(g))return NaN;let A=!1;return u.barIndex===1&&(g>p?(u.isBelow=!0,u.maxMin=l,u.result=y):(u.isBelow=!1,u.maxMin=f,u.result=x),A=!0,u.acceleration=n),u.barIndex>=1&&(u.result=u.result+u.acceleration*(u.maxMin-u.result),u.isBelow?u.result>f&&(A=!0,u.isBelow=!1,u.result=Math.max(l,u.maxMin),u.maxMin=f,u.acceleration=n):u.result<l&&(A=!0,u.isBelow=!0,u.result=Math.min(f,u.maxMin),u.maxMin=l,u.acceleration=n),A||(u.isBelow?l>u.maxMin&&(u.maxMin=l,u.acceleration=Math.min(u.acceleration+a,o)):f<u.maxMin&&(u.maxMin=f,u.acceleration=Math.min(u.acceleration+a,o))),u.isBelow?(u.result=Math.min(u.result,y),u.barIndex>1&&(u.result=Math.min(u.result,E))):(u.result=Math.max(u.result,x),u.barIndex>1&&(u.result=Math.max(u.result,w)))),u.barIndex++,u.barIndex<=1?NaN:e.precision(u.result)}}function Ku(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`sma_${s}`;e.taState[n]||(e.taState[n]={window:[],sum:0});const a=e.taState[n],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<s)return NaN;if(a.window.length>s){const u=a.window.pop();a.sum-=u}const h=a.sum/s;return e.precision(h)}}function zu(e){return(t,i,r=!0,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`stdev_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const h=e.taState[o],u=d.from(t).get(0);if(h.window.unshift(u),h.sum+=u,h.window.length<n)return NaN;if(h.window.length>n){const x=h.window.pop();h.sum-=x}const l=h.sum/n;let f=0;for(let x=0;x<n;x++)f+=Math.pow(h.window[x]-l,2);const g=a?n:n-1,p=Math.sqrt(f/g);return e.precision(p)}}function Hu(e){return(t,i,r,s,n)=>{const a=d.from(s).get(0);e.taState||(e.taState={});const o=n||`stoch_${a}`;e.taState[o]||(e.taState[o]={highWindow:[],lowWindow:[]});const h=e.taState[o],u=d.from(t).get(0),l=d.from(i).get(0),f=d.from(r).get(0);if(isNaN(u)||isNaN(l)||isNaN(f))return NaN;if(h.highWindow.unshift(l),h.lowWindow.unshift(f),h.highWindow.length<a)return NaN;h.highWindow.length>a&&(h.highWindow.pop(),h.lowWindow.pop());let g=h.highWindow[0],p=h.lowWindow[0];for(let w=1;w<a;w++)h.highWindow[w]>g&&(g=h.highWindow[w]),h.lowWindow[w]<p&&(p=h.lowWindow[w]);const x=g-p;if(x===0)return NaN;const y=100*(u-p)/x;return e.precision(y)}}function Gu(e){return(t,i,r)=>{const s=d.from(t).get(0),n=d.from(i).get(0);e.taState||(e.taState={});const a=r||`supertrend_${s}_${n}`;e.taState[a]||(e.taState[a]={trWindow:[],trSum:0,atrValue:NaN,atrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,prevClose:NaN});const o=e.taState[a],h=e.get(e.data.high,0),u=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(u)||isNaN(l))return[[NaN,NaN]];const f=(h+u)/2;let g;isNaN(o.prevClose)?g=h-u:g=Math.max(h-u,Math.abs(h-o.prevClose),Math.abs(u-o.prevClose)),o.atrCount++,o.atrCount<=n?(o.trWindow.push(g),o.trSum+=g,o.atrCount===n&&(o.atrValue=o.trSum/n)):o.atrValue=(o.atrValue*(n-1)+g)/n;const p=o.atrValue,x=o.prevClose;if(o.prevClose=l,isNaN(p))return[[NaN,NaN]];let y=f+s*p,w=f-s*p;const E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,A=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>E||x<E||(w=E),isNaN(o.prevUpperBand)||y<A||x>A||(y=A);let k,T;const C=o.prevSuperTrend;return o.atrCount===n?k=1:C===o.prevUpperBand?k=l>y?-1:1:k=l<w?1:-1,T=k===-1?w:y,o.prevLowerBand=w,o.prevUpperBand=y,o.prevSuperTrend=T,o.prevDirection=k,[[e.precision(T),k]]}}function Yu(e){return(t,i)=>{const r=[1,2,2,1],s=6;e.taState||(e.taState={});const n=i||"swma";e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<4)return NaN;a.window.length>4&&a.window.pop();let h=0;for(let u=0;u<4;u++)h+=r[u]*a.window[3-u];return h/=s,e.precision(h)}}function Qu(e){return(t,i)=>{let r=!0;typeof t=="string"||t!==void 0&&(r=d.from(t).get(0));const s=e.get(e.data.high,0),n=e.get(e.data.low,0),a=e.get(e.data.close,1);if(isNaN(a))return r?e.precision(s-n):NaN;const o=Math.max(s-n,Math.abs(s-a),Math.abs(n-a));return e.precision(o)}}function Xu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`tsi_${n}_${a}`;e.taState[o]||(e.taState[o]={prevSource:NaN,ema1_pc_multiplier:2/(a+1),ema1_pc_value:NaN,ema1_pc_count:0,ema1_pc_sum:0,ema2_pc_multiplier:2/(n+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/(n+1),ema2_abs_value:NaN,ema2_abs_count:0,ema2_abs_sum:0});const h=e.taState[o],u=d.from(t).get(0);if(isNaN(u))return NaN;const l=isNaN(h.prevSource)?NaN:u-h.prevSource;if(h.prevSource=u,isNaN(l))return NaN;const f=Math.abs(l);if(h.ema1_pc_count++,h.ema1_pc_count<=a?(h.ema1_pc_sum+=l,h.ema1_pc_count===a&&(h.ema1_pc_value=h.ema1_pc_sum/a)):h.ema1_pc_value=l*h.ema1_pc_multiplier+h.ema1_pc_value*(1-h.ema1_pc_multiplier),h.ema1_abs_count++,h.ema1_abs_count<=a?(h.ema1_abs_sum+=f,h.ema1_abs_count===a&&(h.ema1_abs_value=h.ema1_abs_sum/a)):h.ema1_abs_value=f*h.ema1_abs_multiplier+h.ema1_abs_value*(1-h.ema1_abs_multiplier),isNaN(h.ema1_pc_value)||isNaN(h.ema1_abs_value))return NaN;if(h.ema2_pc_count++,h.ema2_pc_count<=n?(h.ema2_pc_sum+=h.ema1_pc_value,h.ema2_pc_count===n&&(h.ema2_pc_value=h.ema2_pc_sum/n)):h.ema2_pc_value=h.ema1_pc_value*h.ema2_pc_multiplier+h.ema2_pc_value*(1-h.ema2_pc_multiplier),h.ema2_abs_count++,h.ema2_abs_count<=n?(h.ema2_abs_sum+=h.ema1_abs_value,h.ema2_abs_count===n&&(h.ema2_abs_value=h.ema2_abs_sum/n)):h.ema2_abs_value=h.ema1_abs_value*h.ema2_abs_multiplier+h.ema2_abs_value*(1-h.ema2_abs_multiplier),isNaN(h.ema2_pc_value)||isNaN(h.ema2_abs_value))return NaN;if(h.ema2_abs_value===0)return e.precision(0);const g=h.ema2_pc_value/h.ema2_abs_value;return e.precision(g)}}function Zu(e){return(t,i,r,s)=>{e.taState||(e.taState={});const n=s||"valuewhen";e.taState[n]||(e.taState[n]={values:[]});const a=e.taState[n],o=d.from(t).get(0),h=d.from(i).get(0),u=d.from(r).get(0);if(o&&a.values.push(h),isNaN(u)||u<0)return NaN;const l=a.values.length-1-u;if(l<0)return NaN;const f=a.values[l];return typeof f=="number"?e.precision(f):f}}function Ju(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`variance_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();let h=0,u=0;for(let g=0;g<s;g++)h+=a.window[g],u+=a.window[g]*a.window[g];const l=h/s,f=u/s-l*l;return e.precision(f)}}function ec(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"vwap";e.taState[r]||(e.taState[r]={cumulativePV:0,cumulativeVolume:0,lastSessionDate:null});const s=e.taState[r],n=d.from(t).get(0),a=d.from(e.data.volume).get(0),o=d.from(e.data.openTime).get(0),h=new Date(o).toISOString().slice(0,10);if(s.lastSessionDate!==h&&(s.cumulativePV=0,s.cumulativeVolume=0,s.lastSessionDate=h),s.cumulativePV+=n*a,s.cumulativeVolume+=a,s.cumulativeVolume===0)return NaN;const u=s.cumulativePV/s.cumulativeVolume;return e.precision(u)}}function tc(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`vwma_${s}`;e.taState[n]||(e.taState[n]={window:[],volumeWindow:[]});const a=e.taState[n],o=d.from(t).get(0),h=e.get(e.data.volume,0);if(a.window.unshift(o),a.volumeWindow.unshift(h),a.window.length<s)return NaN;a.window.length>s&&(a.window.pop(),a.volumeWindow.pop());let u=0,l=0;for(let g=0;g<s;g++)u+=a.window[g]*a.volumeWindow[g],l+=a.volumeWindow[g];const f=u/l;return e.precision(f)}}function ic(e){return t=>{e.taState||(e.taState={});const i=t||"wad";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.close,1);if(isNaN(s)||isNaN(n)||isNaN(a))return e.precision(r.cumulativeSum);let h=0;if(!isNaN(o)){const u=Math.max(n,o),l=Math.min(a,o),f=s-o;f>0?h=s-l:f<0&&(h=s-u)}return r.cumulativeSum+=h,e.precision(r.cumulativeSum)}}function rc(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`wma_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();let h=0,u=0;for(let f=0;f<s;f++){const g=s-f;h+=a.window[f]*g,u+=g}const l=h/u;return e.precision(l)}}function sc(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const s=i||`wpr_${r}`;e.taState[s]||(e.taState[s]={highWindow:[],lowWindow:[]});const n=e.taState[s],a=e.get(e.data.high,0),o=e.get(e.data.low,0),h=e.get(e.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(h))return NaN;if(n.highWindow.unshift(a),n.lowWindow.unshift(o),n.highWindow.length<r)return NaN;n.highWindow.length>r&&(n.highWindow.pop(),n.lowWindow.pop());let u=n.highWindow[0],l=n.lowWindow[0];for(let p=1;p<r;p++)n.highWindow[p]>u&&(u=n.highWindow[p]),n.lowWindow[p]<l&&(l=n.lowWindow[p]);const f=u-l;if(f===0)return e.precision(0);const g=(u-h)/f*-100;return e.precision(g)}}function nc(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.open,0),s=e.get(e.data.high,0),n=e.get(e.data.low,0),a=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(n)||isNaN(a))return NaN;const o=s-n;if(o===0)return e.precision(0);const h=(i-r)/o*a;return e.precision(h)}}var ac=Object.defineProperty,oc=(e,t,i)=>t in e?ac(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,S=(e,t,i)=>oc(e,typeof t!="symbol"?t+"":t,i);const hc={accdist:Gh,alma:Yh,atr:Qh,barssince:Xh,bb:Zh,bbw:Jh,cci:eu,change:tu,cmo:iu,cog:ru,correlation:su,cross:nu,crossover:au,crossunder:ou,cum:hu,dev:uu,dmi:cu,ema:lu,falling:pu,highest:fu,highestbars:mu,hma:du,iii:gu,kc:xu,kcw:yu,linreg:wu,lowest:bu,lowestbars:vu,macd:_u,median:Su,mfi:Eu,mode:Nu,mom:Cu,nvi:ku,obv:Iu,param:Au,percentile_linear_interpolation:Pu,percentile_nearest_rank:Tu,percentrank:Ru,pivothigh:Vu,pivotlow:Mu,pvi:Lu,pvt:Bu,range:Fu,rising:ju,rma:$u,roc:Wu,rsi:qu,sar:Uu,sma:Ku,stdev:zu,stoch:Hu,supertrend:Gu,swma:Yu,tr:Qu,tsi:Xu,valuewhen:Zu,variance:Ju,vwap:ec,vwma:tc,wad:ic,wma:rc,wpr:sc,wvad:nc};class uc{constructor(t){this.context=t,S(this,"accdist"),S(this,"alma"),S(this,"atr"),S(this,"barssince"),S(this,"bb"),S(this,"bbw"),S(this,"cci"),S(this,"change"),S(this,"cmo"),S(this,"cog"),S(this,"correlation"),S(this,"cross"),S(this,"crossover"),S(this,"crossunder"),S(this,"cum"),S(this,"dev"),S(this,"dmi"),S(this,"ema"),S(this,"falling"),S(this,"highest"),S(this,"highestbars"),S(this,"hma"),S(this,"iii"),S(this,"kc"),S(this,"kcw"),S(this,"linreg"),S(this,"lowest"),S(this,"lowestbars"),S(this,"macd"),S(this,"median"),S(this,"mfi"),S(this,"mode"),S(this,"mom"),S(this,"nvi"),S(this,"obv"),S(this,"param"),S(this,"percentile_linear_interpolation"),S(this,"percentile_nearest_rank"),S(this,"percentrank"),S(this,"pivothigh"),S(this,"pivotlow"),S(this,"pvi"),S(this,"pvt"),S(this,"range"),S(this,"rising"),S(this,"rma"),S(this,"roc"),S(this,"rsi"),S(this,"sar"),S(this,"sma"),S(this,"stdev"),S(this,"stoch"),S(this,"supertrend"),S(this,"swma"),S(this,"tr"),S(this,"tsi"),S(this,"valuewhen"),S(this,"variance"),S(this,"vwap"),S(this,"vwma"),S(this,"wad"),S(this,"wma"),S(this,"wpr"),S(this,"wvad"),Object.entries(hc).forEach(([i,r])=>{this[i]=r(t)})}}class cc{constructor(t){this.context=t}logFormat(t,...i){return t.replace(/{(\d+)}/g,(r,s)=>i[s])}param(t,i=0,r){return d.from(t).get(i)}warning(t,...i){console.warn(this.logFormat(t,...i))}error(t,...i){console.error(this.logFormat(t,...i))}info(t,...i){console.log(this.logFormat(t,...i))}}class lc{constructor(t){this.context=t}param(t,i=0,r){return d.from(t).get(i)}tostring(t){return String(t)}tonumber(t){return Number(t)}lower(t){return String(t).toLowerCase()}upper(t){return String(t).toUpperCase()}trim(t){return String(t).trim()}repeat(t,i,r=""){return Array(i).fill(t).join(r||"")}replace_all(t,i,r){return String(t).replaceAll(i,r)}replace(t,i,r,s=0){const n=String(t),a=String(i),o=String(r),h=Math.floor(Number(s))||0;if(a==="")return n;let u=0,l=0;for(;;){const f=n.indexOf(a,u);if(f===-1)return n;if(l===h)return n.substring(0,f)+o+n.substring(f+a.length);l++,u=f+a.length}}contains(t,i){return String(t).includes(i)}endswith(t,i){return String(t).endsWith(i)}startswith(t,i){return String(t).startsWith(i)}pos(t,i){const r=String(t).indexOf(i);return r===-1?NaN:r}length(t){return String(t).length}match(t,i){return String(t).match(new RegExp(i))}split(t,i){return[String(t).split(i)]}substring(t,i,r){return String(t).substring(i,r)}format(t,...i){return t.replace(/{(\d+)}/g,(r,s)=>i[s])}}class pc{constructor(t){this.context=t}param(t,i=0,r){return d.from(t).get(i)}get main_period(){return this.context.timeframe}get period(){return this.context.timeframe}get multiplier(){const t=parseInt(this.context.timeframe);return isNaN(t)?1:t}get isdwm(){return["D","W","M"].includes(this.context.timeframe.slice(-1))}get isdaily(){return this.context.timeframe.slice(-1)==="D"}get isweekly(){return this.context.timeframe.slice(-1)==="W"}get ismonthly(){return this.context.timeframe.slice(-1)==="M"}get isseconds(){return this.context.timeframe.slice(-1)==="S"}get isminutes(){return parseInt(this.context.timeframe).toString()==this.context.timeframe.trim()}get isintraday(){return!this.isdwm}from_seconds(t){return t<60?Math.ceil(t/5)*5+"S":t<60*60*24?Math.ceil(t/60):t<=60*60*24*7*52?t%(60*60*24*7)===0?Math.ceil(t/604800)+"W":Math.ceil(t/(60*60*24))+"D":"12M"}in_seconds(t){const i=parseInt(t),r=t.slice(-1);return r==="S"?i:r==="D"?i*60*60*24:r==="W"?i*60*60*24*7:r==="M"?i*60*60*24*30:isNaN(i)?0:i*60}}const fc=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],mc={series:"series",title:"string",color:"string",linewidth:"number",style:"string",trackprice:"boolean",histbase:"number",offset:"number",join:"bool",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"};class dc{constructor(t){this.context=t}extractPlotOptions(t){const i={};for(let r in t)i[r]=d.from(t[r]).get(0);return i}plotchar(t,i,r){this.context.plots[i]||(this.context.plots[i]={data:[],options:this.extractPlotOptions(r),title:i});const s=d.from(t).get(0);this.context.plots[i].data.push({time:this.context.marketData[this.context.idx].openTime,value:s,options:{...this.extractPlotOptions(r),style:"char"}})}plot(...t){const i=Ut(t,fc,mc),{series:r,title:s,...n}=i,a=this.extractPlotOptions(n);this.context.plots[s]||(this.context.plots[s]={data:[],options:a,title:s});const o=d.from(r).get(0);this.context.plots[s].data.push({time:this.context.marketData[this.context.idx].openTime,value:o,options:{color:a.color,offset:a.offset}})}}class gc{constructor(t){this.context=t}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(t,i=0,r){return d.from(t).get(i)}any(t,i,r,s,n,a,o){return this.context.pine.plot(t,{title:i,color:r,linestyle:s,linewidth:n,editable:a,display:o})}}var xc=Object.defineProperty,yc=(e,t,i)=>t in e?xc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,j=(e,t,i)=>yc(e,typeof t!="symbol"?t+"":t,i);const gr=class Xt{constructor({marketData:t,source:i,tickerId:r,timeframe:s,limit:n,sDate:a,eDate:o,fullContext:h}){j(this,"data",{open:new d([]),high:new d([]),low:new d([]),close:new d([]),volume:new d([]),hl2:new d([]),hlc3:new d([]),ohlc4:new d([]),hlcc4:new d([])}),j(this,"indicator"),j(this,"cache",{}),j(this,"taState",{}),j(this,"isSecondaryContext",!1),j(this,"NA",NaN),j(this,"lang"),j(this,"pine"),j(this,"idx",0),j(this,"params",{}),j(this,"const",{}),j(this,"var",{}),j(this,"let",{}),j(this,"result"),j(this,"plots",{}),j(this,"marketData"),j(this,"source"),j(this,"tickerId"),j(this,"timeframe",""),j(this,"limit"),j(this,"sDate"),j(this,"eDate"),j(this,"fullContext"),j(this,"pineTSCode"),this.marketData=t,this.source=i,this.tickerId=r,this.timeframe=s,this.limit=n,this.sDate=a,this.eDate=o,this.fullContext=h||this;const u=new jo(this),l={na:u.na.bind(u),color:u.color,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),bool:u.bool.bind(u)},f=this;this.pine={input:new oh(this),ta:new uc(this),math:new jh(this),request:new Hh(this),array:new la(this),map:new Ca(this),matrix:new Ao(this),syminfo:null,timeframe:new pc(this),barstate:new Do(this),get bar_index(){return f.idx},get last_bar_index(){return f.data.close.length-1},get last_bar_time(){return f.data.openTime.get(f.data.openTime.length-1)},get timenow(){return new Date().getTime()},log:new cc(this),str:new lc(this),...l,...Gn};const g=new dc(this),p=new gc(this);this.bindContextObject(g,["plot","plotchar"]),this.bindContextObject(p,["any","style_dashed","style_solid","style_dotted","param"],"hline")}bindContextObject(t,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const s=r?this.pine[r]:this.pine;for(const n of i)typeof t[n]=="function"?s[n]=t[n].bind(t):s[n]=t[n]}init(t,i,r=0){let s;return i instanceof d?s=i.get(0):Array.isArray(i)?Array.isArray(i[0])?s=i[0]:s=i[i.length-1+r]:s=i,t?t instanceof d?(t.data[t.data.length-1]=s,t):Array.isArray(t)?(t[t.length-1]=s,new d(t)):new d([s]):new d([s])}initVar(t,i){if(t)return t;let r;return i instanceof d?r=i.get(0):Array.isArray(i)?Array.isArray(i[0])?r=i[0]:r=this.precision(i[i.length-1]):r=this.precision(i),new d([r])}precision(t,i=10){const r=10**i;return typeof t=="number"?Math.round(t*r)/r:t}param(t,i,r){return typeof t=="string"?t:t instanceof d?i?new d(t.data,t.offset+i):t:!Array.isArray(t)&&typeof t=="object"?t:(this.params[r]||(this.params[r]=[]),Array.isArray(t)?new d(t,i||0):(this.params[r].length===0?this.params[r].push(t):this.params[r][this.params[r].length-1]=t,new d(this.params[r],0)))}get(t,i){if(t instanceof d)return t.get(i);if(Array.isArray(t)){const r=t.length-1-i;return r<0||r>=t.length?NaN:t[r]}return t}set(t,i){if(t instanceof d){t.set(0,i);return}if(Array.isArray(t)){t.length>0?t[t.length-1]=i:t.push(i);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,i){const r=`${t}->${i}`;Xt._deprecationWarningsShown.has(r)||(Xt._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,i):console.warn(`\x1B[33m[WARNING] ${t} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}};j(gr,"_deprecationWarningsShown",new Set);let Kt=gr;var wc=Object.defineProperty,bc=(e,t,i)=>t in e?wc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,K=(e,t,i)=>bc(e,typeof t!="symbol"?t+"":t,i);class zt{constructor(t,i,r,s,n,a){this.source=t,this.tickerId=i,this.timeframe=r,this.limit=s,this.sDate=n,this.eDate=a,K(this,"data",[]),K(this,"open",[]),K(this,"high",[]),K(this,"low",[]),K(this,"close",[]),K(this,"volume",[]),K(this,"hl2",[]),K(this,"hlc3",[]),K(this,"ohlc4",[]),K(this,"hlcc4",[]),K(this,"openTime",[]),K(this,"closeTime",[]),K(this,"_readyPromise",null),K(this,"_ready",!1),K(this,"_debugSettings",{ln:!1,debug:!1}),K(this,"_transpiledCode",null),K(this,"_isSecondaryContext",!1),K(this,"_syminfo"),this._readyPromise=new Promise(o=>{this.loadMarketData(t,i,r,s,n,a).then(h=>{const u=h;this.data=u;const l=u.map(C=>C.open),f=u.map(C=>C.close),g=u.map(C=>C.high),p=u.map(C=>C.low),x=u.map(C=>C.volume),y=u.map(C=>(C.high+C.low+C.close)/3),w=u.map(C=>(C.high+C.low)/2),E=u.map(C=>(C.high+C.low+C.open+C.close)/4),A=u.map(C=>(C.high+C.low+C.close+C.close)/4),k=u.map(C=>C.openTime),T=u.map(C=>C.closeTime);this.open=l,this.close=f,this.high=g,this.low=p,this.volume=x,this.hl2=w,this.hlc3=y,this.ohlc4=E,this.hlcc4=A,this.openTime=k,this.closeTime=T,t&&t.getSymbolInfo?t.getSymbolInfo(i).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setDebugSettings({ln:t,debug:i}){this._debugSettings.ln=t,this._debugSettings.debug=i}async loadMarketData(t,i,r,s,n,a){return Array.isArray(t)?t:t.getMarketData(i,r,s,n,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(t,i,r){if(r&&r>0){const s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(t,i,r,s)}else return this._runComplete(t,i)}async _runComplete(t,i){await this.ready(),i||(i=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-i,this.data.length),r}async*_runPaginated(t,i,r,s=!1){await this.ready(),i||(i=this.data.length);const n=this._initializeContext(t,this._isSecondaryContext);this._transpiledCode=this._transpileCode(t);let a=this.data.length-i;for(;;){const o=this.data.length-a;if(o>0){const l=Math.min(o,r),f=this._getResultLength(n.result);await this._executeIterations(n,this._transpiledCode,a,a+l),a+=l,yield this._createPageContext(n,f);continue}if(!s||Array.isArray(this.source))break;const{newCandles:h,updatedLastCandle:u}=await this._updateMarketData();if(h===0&&!u){yield null;continue}this._removeLastResult(n),a=this.data.length-(h+1),n.pine.barstate.setLive()}}_getResultLength(t){if(Array.isArray(t))return t.length;if(typeof t=="object"&&t!==null){const i=Object.keys(t);if(i.length>0&&Array.isArray(t[i[0]]))return t[i[0]].length}return 0}_createPageContext(t,i){const r=new Kt({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:t});if(r.pineTSCode=t.pineTSCode,r.idx=t.idx,Array.isArray(t.result))r.result=t.result.slice(i);else if(typeof t.result=="object"&&t.result!==null){r.result={};for(let s in t.result)Array.isArray(t.result[s])?r.result[s]=t.result[s].slice(i):r.result[s]=t.result[s]}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 i=this.source,r=this.data.length-1,s=this.data[r].openTime;try{const n=await i.getMarketData(this.tickerId,this.timeframe,void 0,s,t);if(!n||n.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let h=0;h<n.length;h++){const u=n[h];u.openTime===s?(this._replaceCandle(r,u),a=!0):u.openTime>s&&(this._appendCandle(u),o++)}return{newCandles:o,updatedLastCandle:a}}catch(n){return console.error("Error updating market data:",n),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(t,i){this.data[t]=i,this.open[t]=i.open,this.close[t]=i.close,this.high[t]=i.high,this.low[t]=i.low,this.volume[t]=i.volume,this.hl2[t]=(i.high+i.low)/2,this.hlc3[t]=(i.high+i.low+i.close)/3,this.ohlc4[t]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[t]=(i.high+i.low+i.close+i.close)/4,this.openTime[t]=i.openTime,this.closeTime[t]=i.closeTime}_appendCandle(t){this.data.push(t),this.open.push(t.open),this.close.push(t.close),this.high.push(t.high),this.low.push(t.low),this.volume.push(t.volume),this.hl2.push((t.high+t.low)/2),this.hlc3.push((t.high+t.low+t.close)/3),this.ohlc4.push((t.high+t.low+t.open+t.close)/4),this.hlcc4.push((t.high+t.low+t.close+t.close)/4),this.openTime.push(t.openTime),this.closeTime.push(t.closeTime)}_removeLastResult(t){if(Array.isArray(t.result))t.result.pop();else if(typeof t.result=="object"&&t.result!==null)for(let i in t.result)Array.isArray(t.result[i])&&t.result[i].pop();t.data.close.data.pop(),t.data.open.data.pop(),t.data.high.data.pop(),t.data.low.data.pop(),t.data.volume.data.pop(),t.data.hl2.data.pop(),t.data.hlc3.data.pop(),t.data.ohlc4.data.pop(),t.data.hlcc4.data.pop(),t.data.openTime.data.pop(),t.data.closeTime&&t.data.closeTime.data.pop()}_initializeContext(t,i=!1){const r=new Kt({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});return r.pine.syminfo=this._syminfo,r.pineTSCode=t,r.isSecondaryContext=i,r.data.close=new d([]),r.data.open=new d([]),r.data.high=new d([]),r.data.low=new d([]),r.data.volume=new d([]),r.data.hl2=new d([]),r.data.hlc3=new d([]),r.data.ohlc4=new d([]),r.data.hlcc4=new d([]),r.data.openTime=new d([]),r.data.closeTime=new d([]),r}_transpileCode(t){return cn.bind(this)(t,this._debugSettings)}async _executeIterations(t,i,r,s){const n=["const","var","let","params"];for(let a=r;a<s;a++){t.idx=a,t.data.close.data.push(this.close[a]),t.data.open.data.push(this.open[a]),t.data.high.data.push(this.high[a]),t.data.low.data.push(this.low[a]),t.data.volume.data.push(this.volume[a]),t.data.hl2.data.push(this.hl2[a]),t.data.hlc3.data.push(this.hlc3[a]),t.data.ohlc4.data.push(this.ohlc4[a]),t.data.hlcc4.data.push(this.hlcc4[a]),t.data.openTime.data.push(this.openTime[a]),t.data.closeTime.data.push(this.closeTime[a]);const o=await i(t);if(typeof o=="object"){typeof t.result!="object"&&(t.result={});for(let h in o){t.result[h]===void 0&&(t.result[h]=[]);let u;o[h]instanceof d?u=o[h].get(0):Array.isArray(o[h])?u=o[h][o[h].length-1]:u=o[h],t.result[h].push(u)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(o);for(let h of n)for(let u in t[h]){const l=t[h][u];if(l instanceof d){const f=l.get(0);l.data.push(f)}else if(Array.isArray(l)){const f=l[l.length-1];l.push(f)}}}}}var vc=Object.defineProperty,_c=(e,t,i)=>t in e?vc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ht=(e,t,i)=>_c(e,typeof t!="symbol"?t+"":t,i);const xr="https://api.binance.com/api/v3",Gt={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 Sc{constructor(t=5*60*1e3){Ht(this,"cache"),Ht(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=t}generateKey(t){return Object.entries(t).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(t){const i=this.generateKey(t),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(t,i){const r=this.generateKey(t);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const t=Date.now();for(const[i,r]of this.cache.entries())t-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class Ec{constructor(){Ht(this,"cacheManager"),this.cacheManager=new Sc(5*60*1e3)}async getMarketDataInterval(t,i,r,s){try{const n=Gt[i.toUpperCase()];if(!n)return console.error(`Unsupported timeframe: ${i}`),[];const a={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3};let o=[],h=r;const u=s,l=a[n];if(!l)return console.error(`Duration not defined for interval: ${n}`),[];for(;h<u;){const f=Math.min(h+1e3*l,u),g=await this.getMarketData(t,i,1e3,h,f);if(g.length===0)break;o=o.concat(g),h=g[g.length-1].closeTime+1}return o}catch(n){return console.error("Error in getMarketDataInterval:",n),[]}}async getMarketData(t,i,r,s,n){try{const a=n!==void 0,o={tickerId:t,timeframe:i,limit:r,sDate:s,eDate:n};if(a){const g=this.cacheManager.get(o);if(g)return g}const h=Gt[i.toUpperCase()];if(!h)return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,s,n)&&s&&n){const g=await this.getMarketDataInterval(t,i,s,n),p=r?g.slice(0,r):g;return this.cacheManager.set(o,p),p}let u=`${xr}/klines?symbol=${t}&interval=${h}`;r&&(u+=`&limit=${Math.min(r,1e3)}`),s&&(u+=`&startTime=${s}`),n&&(u+=`&endTime=${n}`);const l=await fetch(u);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const f=(await l.json()).map(g=>({openTime:parseInt(g[0]),open:parseFloat(g[1]),high:parseFloat(g[2]),low:parseFloat(g[3]),close:parseFloat(g[4]),volume:parseFloat(g[5]),closeTime:parseInt(g[6]),quoteAssetVolume:parseFloat(g[7]),numberOfTrades:parseInt(g[8]),takerBuyBaseAssetVolume:parseFloat(g[9]),takerBuyQuoteAssetVolume:parseFloat(g[10]),ignore:g[11]}));return a&&this.cacheManager.set(o,f),f}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(t,i,r,s){if(i&&i>1e3)return!0;if(r&&s){const n=Gt[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}[n];if(a)return Math.ceil((s-r)/a)>1e3}return!1}async getSymbolInfo(t){try{let i="crypto",r=xr,s=t,n="";t.endsWith(".P")?(i="futures",s=t.replace(".P",""),r="https://fapi.binance.com/fapi/v1",n="Perpetual"):t.includes("_")&&(i="futures",s=t,r="https://dapi.binance.com/dapi/v1",n="Delivery");const a=i==="crypto"?`${r}/exchangeInfo?symbol=${s}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const h=(await o.json()).symbols;if(!h||h.length===0)return console.error(`Symbol ${t} not found`),null;const u=i==="futures"?h.find(k=>k.symbol===s):h[0];if(!u)return console.error(`Symbol ${s} not found in exchange info`),null;const l=u.filters?.find(k=>k.filterType==="PRICE_FILTER"),f=u.filters?.find(k=>k.filterType==="LOT_SIZE"),g=l?parseFloat(l.tickSize):.01,p=f?parseFloat(f.minQty):0,x=Math.round(1/g),y=u.baseAsset,w=u.quoteAsset,E=n?` ${n}`:"",A=`${y} / ${w}${E}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:y,description:A,type:i,main_tickerid:`BINANCE:${t}`,current_contract:n,isin:"",basecurrency:y,currency:w,timezone:"Etc/UTC",country:"",mintick:g,pricescale:x,minmove:1,pointvalue:u.contractSize||1,mincontract:p,session:"24x7",volumetype:"base",expiration_date:u.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in binance.exchangeInfo:",i),null}}}class Nc{async getMarketData(){return[]}}const Cc=typeof process<"u"&&process.versions&&process.versions.node;let yt=null;if(Cc)try{yt=new Nc}catch{yt=null}const kc={Binance:new Ec,...yt?{Mock:yt}:{}};Ce.Context=Kt,Ce.PineTS=zt,Ce.Provider=kc,Object.defineProperty(Ce,"__esModule",{value:!0})});
|
|
116
|
+
`,t+="["+this.matrix[i].join(", ")+"]";return t}add_col(...t){return this._add_col(this,...t)}add_row(...t){return this._add_row(this,...t)}avg(...t){return this._avg(this,...t)}col(...t){return this._col(this,...t)}columns(...t){return this._columns(this,...t)}concat(...t){return this._concat(this,...t)}copy(...t){return this._copy(this,...t)}det(...t){return this._det(this,...t)}diff(...t){return this._diff(this,...t)}eigenvalues(...t){return this._eigenvalues(this,...t)}eigenvectors(...t){return this._eigenvectors(this,...t)}elements_count(...t){return this._elements_count(this,...t)}fill(...t){return this._fill(this,...t)}get(...t){return this._get(this,...t)}inv(...t){return this._inv(this,...t)}is_antidiagonal(...t){return this._is_antidiagonal(this,...t)}is_antisymmetric(...t){return this._is_antisymmetric(this,...t)}is_binary(...t){return this._is_binary(this,...t)}is_diagonal(...t){return this._is_diagonal(this,...t)}is_identity(...t){return this._is_identity(this,...t)}is_square(...t){return this._is_square(this,...t)}is_stochastic(...t){return this._is_stochastic(this,...t)}is_symmetric(...t){return this._is_symmetric(this,...t)}is_triangular(...t){return this._is_triangular(this,...t)}is_zero(...t){return this._is_zero(this,...t)}kron(...t){return this._kron(this,...t)}max(...t){return this._max(this,...t)}median(...t){return this._median(this,...t)}min(...t){return this._min(this,...t)}mode(...t){return this._mode(this,...t)}mult(...t){return this._mult(this,...t)}pinv(...t){return this._pinv(this,...t)}pow(...t){return this._pow(this,...t)}rank(...t){return this._rank(this,...t)}remove_col(...t){return this._remove_col(this,...t)}remove_row(...t){return this._remove_row(this,...t)}reshape(...t){return this._reshape(this,...t)}reverse(...t){return this._reverse(this,...t)}row(...t){return this._row(this,...t)}rows(...t){return this._rows(this,...t)}set(...t){return this._set(this,...t)}sort(...t){return this._sort(this,...t)}submatrix(...t){return this._submatrix(this,...t)}sum(...t){return this._sum(this,...t)}swap_columns(...t){return this._swap_columns(this,...t)}swap_rows(...t){return this._swap_rows(this,...t)}trace(...t){return this._trace(this,...t)}transpose(...t){return this._transpose(this,...t)}}function ko(e){return(t,i,r)=>new M(t,i,r,e)}function Io(e){return(t,i=0)=>d.from(t).get(i)}class Ao{constructor(t){this.context=t,this.add_col=(i,...r)=>i.add_col(...r),this.add_row=(i,...r)=>i.add_row(...r),this.avg=(i,...r)=>i.avg(...r),this.col=(i,...r)=>i.col(...r),this.columns=(i,...r)=>i.columns(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.det=(i,...r)=>i.det(...r),this.diff=(i,...r)=>i.diff(...r),this.eigenvalues=(i,...r)=>i.eigenvalues(...r),this.eigenvectors=(i,...r)=>i.eigenvectors(...r),this.elements_count=(i,...r)=>i.elements_count(...r),this.fill=(i,...r)=>i.fill(...r),this.get=(i,...r)=>i.get(...r),this.inv=(i,...r)=>i.inv(...r),this.is_antidiagonal=(i,...r)=>i.is_antidiagonal(...r),this.is_antisymmetric=(i,...r)=>i.is_antisymmetric(...r),this.is_binary=(i,...r)=>i.is_binary(...r),this.is_diagonal=(i,...r)=>i.is_diagonal(...r),this.is_identity=(i,...r)=>i.is_identity(...r),this.is_square=(i,...r)=>i.is_square(...r),this.is_stochastic=(i,...r)=>i.is_stochastic(...r),this.is_symmetric=(i,...r)=>i.is_symmetric(...r),this.is_triangular=(i,...r)=>i.is_triangular(...r),this.is_zero=(i,...r)=>i.is_zero(...r),this.kron=(i,...r)=>i.kron(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.mult=(i,...r)=>i.mult(...r),this.new=ko(t),this.param=Io(),this.pinv=(i,...r)=>i.pinv(...r),this.pow=(i,...r)=>i.pow(...r),this.rank=(i,...r)=>i.rank(...r),this.remove_col=(i,...r)=>i.remove_col(...r),this.remove_row=(i,...r)=>i.remove_row(...r),this.reshape=(i,...r)=>i.reshape(...r),this.reverse=(i,...r)=>i.reverse(...r),this.row=(i,...r)=>i.row(...r),this.rows=(i,...r)=>i.rows(...r),this.set=(i,...r)=>i.set(...r),this.sort=(i,...r)=>i.sort(...r),this.submatrix=(i,...r)=>i.submatrix(...r),this.sum=(i,...r)=>i.sum(...r),this.swap_columns=(i,...r)=>i.swap_columns(...r),this.swap_rows=(i,...r)=>i.swap_rows(...r),this.trace=(i,...r)=>i.trace(...r),this.transpose=(i,...r)=>i.transpose(...r)}}var Po=Object.defineProperty,To=(e,t,i)=>t in e?Po(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ro=(e,t,i)=>To(e,typeof t!="symbol"?t+"":t,i);class Do{constructor(t){this.context=t,Ro(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.data.close.data.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.data.close.data.length-1}get isrealtime(){return this.context.idx===this.context.data.close.data.length-1}get isconfirmed(){return this.context.data.closeTime[this.context.data.closeTime.length-1]<=new Date().getTime()}get islastconfirmedhistory(){return this.context.data.closeTime[this.context.data.closeTime.length-1]<=new Date().getTime()}}const fr={series:e=>e instanceof d||typeof e=="number",string:e=>typeof e=="string",number:e=>typeof e=="number",boolean:e=>typeof e=="boolean",array:e=>Array.isArray(e),object:e=>typeof e=="object",primitive:e=>typeof e===null||typeof e!="object"&&typeof e!="function",function:e=>typeof e=="function",undefined:e=>e===void 0,null:e=>e===null,NaN:e=>isNaN(e),remaining_options:e=>typeof e=="object"&&!(e instanceof d)};function Ut(e,t,i){Array.isArray(t)&&typeof t[0]=="string"&&(t=[t]);const r={};let s={};const n=new Array(t.length).fill(!0);for(let a=0;a<e.length;a++){const o=e[a];if(fr.remaining_options(o)){s=o;break}const h=t.map((u,l)=>n[l]?u[a]:void 0);for(let u=0;u<h.length;u++){const l=h[u];if(l===void 0){n[u]=!1;continue}const f=fr[i[l]];typeof f=="function"&&f(o)?r[l]=o:n[u]=!1}}return{...s,...r}}var Vo=Object.defineProperty,Oo=(e,t,i)=>t in e?Vo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Mo=(e,t,i)=>Oo(e,typeof t!="symbol"?t+"":t,i);const Lo=["title","shorttitle","overlay","format","precision","scale","max_bars_back","timeframe","timeframe_gaps","explicit_plot_zorder","max_lines_count","max_labels_count","max_boxes_count","calc_bars_count","max_polylines_count","dynamic_requests","behind_chart"],Bo={title:"string",shorttitle:"string",overlay:"boolean",format:"string",precision:"number",scale:"string",max_bars_back:"number",timeframe:"string",timeframe_gaps:"boolean",explicit_plot_zorder:"boolean",max_lines_count:"number",max_labels_count:"number",max_boxes_count:"number",calc_bars_count:"number",max_polylines_count:"number",dynamic_requests:"boolean",behind_chart:"boolean"};function Fo(e){return Ut(e,Lo,Bo)}class jo{constructor(t){this.context=t,Mo(this,"color",{param:(i,r=0)=>d.from(i).get(r),rgb:(i,r,s,n)=>n?`rgba(${i}, ${r}, ${s}, ${n})`:`rgb(${i}, ${r}, ${s})`,new:(i,r)=>{if(i&&i.startsWith("#")){const s=i.slice(1),n=parseInt(s.slice(0,2),16),a=parseInt(s.slice(2,4),16),o=parseInt(s.slice(4,6),16);return r?`rgba(${n}, ${a}, ${o}, ${r})`:`rgb(${n}, ${a}, ${o})`}return r?`rgba(${i}, ${r})`:i},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue",yellow:"yellow",orange:"orange",purple:"purple",pink:"pink",brown:"brown",teal:"teal",cyan:"cyan",navy:"navy",indigo:"indigo",violet:"violet",magenta:"magenta",rose:"rose",gold:"gold",silver:"silver",bronze:"bronze"})}extractPlotOptions(t){const i={};for(let r in t)i[r]=d.from(t[r]).get(0);return i}indicator(...t){const i=Fo(t),r={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...r,...i},this.context.indicator}get bar_index(){return this.context.idx}na(t){return isNaN(d.from(t).get(0))}nz(t,i=0){const r=d.from(t).get(0),s=d.from(i).get(0);return isNaN(r)?s:r}fixnan(t){const i=d.from(t);for(let r=0;r<i.length;r++){const s=i.get(r);if(!isNaN(s))return s}return NaN}alertcondition(t,i,r){}bool(t){const i=d.from(t).get(0);return!isNaN(i)&&i!==0}int(t){const i=d.from(t).get(0);if(typeof i!="number")throw new Error(`Cannot call "int" with argument "x"="${i}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.floor(i)}float(t){const i=d.from(t).get(0);if(typeof i!="number")throw new Error(`Cannot call "float" with argument "x"="${i}". An argument of "literal string" type was used but a "const float" is expected.`);return i}string(t){return d.from(t).get(0).toString()}}const $o=[["defval","title","tooltip","inline","group","display"],["defval","title","tooltip","group","confirm","display"],["defval","title","tooltip","inline","group","confirm","display"],["defval","title","options","tooltip","inline","group","confirm","display"],["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display"]],Wo={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function re(e){return Ut(e,$o,Wo)}function qo(e){return(...t)=>re(t).defval}function Uo(e){return(...t)=>re(t).defval}function Ko(e){return(...t)=>re(t).defval}function zo(e){return(...t)=>re(t).defval}function Ho(e){return(...t)=>re(t).defval}function Go(e){return(...t)=>re(t).defval}function Yo(e){return(t,i=0)=>d.from(t).get(i)}function Qo(e){return(...t)=>re(t).defval}function Xo(e){return(...t)=>re(t).defval}function Zo(e){return(...t)=>re(t).defval}function Jo(e){return(...t)=>re(t).defval}function eh(e){return(...t)=>re(t).defval}function th(e){return(...t)=>re(t).defval}function ih(e){return(...t)=>re(t).defval}function rh(e){return(...t)=>re(t).defval}var sh=Object.defineProperty,nh=(e,t,i)=>t in e?sh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t,i)=>nh(e,typeof t!="symbol"?t+"":t,i);const ah={any:qo,bool:Uo,color:Ko,enum:zo,float:Ho,int:Go,param:Yo,price:Qo,session:Xo,source:Zo,string:Jo,symbol:eh,text_area:th,time:ih,timeframe:rh};class oh{constructor(t){this.context=t,Z(this,"any"),Z(this,"bool"),Z(this,"color"),Z(this,"enum"),Z(this,"float"),Z(this,"int"),Z(this,"param"),Z(this,"price"),Z(this,"session"),Z(this,"source"),Z(this,"string"),Z(this,"symbol"),Z(this,"text_area"),Z(this,"time"),Z(this,"timeframe"),Object.entries(ah).forEach(([i,r])=>{this[i]=r(t)})}}function hh(e){return t=>Math.abs(d.from(t).get(0))}function uh(e){return t=>Math.acos(d.from(t).get(0))}function ch(e){return t=>Math.asin(d.from(t).get(0))}function lh(e){return t=>Math.atan(d.from(t).get(0))}function ph(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return i.reduce((r,s)=>r+s,0)/i.length}}function fh(e){return t=>Math.ceil(d.from(t).get(0))}function mh(e){return t=>Math.cos(d.from(t).get(0))}function dh(e){return()=>Math.E}function gh(e){return t=>Math.exp(d.from(t).get(0))}function xh(e){return t=>Math.floor(d.from(t).get(0))}function yh(e){return t=>Math.log(d.from(t).get(0))}function wh(e){return t=>Math.log(d.from(t).get(0))}function bh(e){return t=>Math.log10(d.from(t).get(0))}function vh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.max(...i)}}function _h(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.min(...i)}}function Sh(e){return(t,i,r)=>typeof t=="string"?t:t instanceof d?i?new d(t.data,t.offset+i):t:!Array.isArray(t)&&typeof t=="object"?t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new d(t,i||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new d(e.params[r],0)))}function Eh(e){return()=>1.618033988749895}function Nh(e){return()=>Math.PI}function Ch(e){return(t,i)=>Math.pow(d.from(t).get(0),d.from(i).get(0))}function kh(e){return()=>Math.random()}function Ih(e){return t=>Math.round(d.from(t).get(0))}function Ah(e){return t=>e.precision(Math.round(d.from(t).get(0)/e.pine.syminfo.mintick)*e.pine.syminfo.mintick)}function Ph(e){return()=>.6180339887498948}function Th(e){return t=>Math.sign(d.from(t).get(0))}function Rh(e){return t=>Math.sin(d.from(t).get(0))}function Dh(e){return t=>Math.sqrt(d.from(t).get(0))}function Vh(e){return(t,i)=>{const r=d.from(i).get(0),s=d.from(t);let n=0;for(let a=0;a<r;a++){const o=s.get(a);n+=o}return n}}function Oh(e){return t=>Math.tan(d.from(t).get(0))}function Mh(e){return(t,i)=>{const r=d.from(t).get(0),s=d.from(i).get(0);return typeof r=="number"&&typeof s=="number"?isNaN(r)&&isNaN(s)?!0:isNaN(r)||isNaN(s)?!1:Math.abs(r-s)<1e-8:r===s}}var Lh=Object.defineProperty,Bh=(e,t,i)=>t in e?Lh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,L=(e,t,i)=>Bh(e,typeof t!="symbol"?t+"":t,i);const Fh={abs:hh,acos:uh,asin:ch,atan:lh,avg:ph,ceil:fh,cos:mh,e:dh,exp:gh,floor:xh,ln:yh,log:wh,log10:bh,max:vh,min:_h,param:Sh,phi:Eh,pi:Nh,pow:Ch,random:kh,round:Ih,round_to_mintick:Ah,rphi:Ph,sign:Th,sin:Rh,sqrt:Dh,sum:Vh,tan:Oh,__eq:Mh};class jh{constructor(t){this.context=t,L(this,"_cache",{}),L(this,"abs"),L(this,"acos"),L(this,"asin"),L(this,"atan"),L(this,"avg"),L(this,"ceil"),L(this,"cos"),L(this,"e"),L(this,"exp"),L(this,"floor"),L(this,"ln"),L(this,"log"),L(this,"log10"),L(this,"max"),L(this,"min"),L(this,"param"),L(this,"phi"),L(this,"pi"),L(this,"pow"),L(this,"random"),L(this,"round"),L(this,"round_to_mintick"),L(this,"rphi"),L(this,"sign"),L(this,"sin"),L(this,"sqrt"),L(this,"sum"),L(this,"tan"),L(this,"__eq"),Object.entries(Fh).forEach(([i,r])=>{this[i]=r(t)})}}function $h(e){return(t,i,r)=>{e.params[r]||(e.params[r]=[]);let s;if(t instanceof d)s=t.get(i||0);else if(Array.isArray(t)){const n=t.every(o=>o instanceof d),a=t.every(o=>!(o instanceof d)&&!Array.isArray(o));(n||a)&&t.length>=1?n?s=t.map(o=>o.get(0)):s=t:s=d.from(t).get(i||0)}else s=t;return e.params[r].length===0?e.params[r].push(s):e.params[r][e.params[r].length-1]=s,[s,r]}}const gt=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function mr(e,t,i,r,s=!1){for(let n=0;n<i.length;n++)if(i[n]<=e&&t<=r[n])return s||t>=r[n]?n:n-1;return-1}function dr(e,t,i,r,s=!1,n,a=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=t&&i[o]>=e){const h=n&&t>n;if(a&&s)for(let u=0;u<i.length;u++){if(i[u]>=e&&i[u]<t)return u;if(i[u]>=t)break}if(h&&s&&!a)for(let u=0;u<i.length;u++){if(i[u]>=e&&i[u]<t)return u;if(i[u]>=t)break}return o}if(r[o]<e)break}return-1}function Wh(e){return async(t,i,r,s=!1,n=!1,a=!1,o=null,h=null)=>{const u=t[0],l=i[0],f=r[0],g=r[1],p=Array.isArray(s)?s[0]:s,x=Array.isArray(n)?n[0]:n;if(e.isSecondaryContext)return f;const y=gt.indexOf(e.timeframe),w=gt.indexOf(l);if(y==-1||w==-1)throw new Error("Invalid timeframe");if(y===w)return f;const E=y>w,A=d.from(e.data.openTime).get(0),k=d.from(e.data.closeTime).get(0),T=`${u}_${l}_${g}`,C=`${T}_prevIdx`;if(e.cache[T]){const nt=e.cache[T],wt=E?dr(A,k,nt.data.openTime.data,nt.data.closeTime.data,x,e.eDate,p):mr(A,k,nt.data.openTime.data,nt.data.closeTime.data,x);if(wt==-1)return NaN;const He=nt.params[g][wt];if(!E&&p){const yr=e.cache[C];return yr!==void 0&&yr===wt?NaN:(e.cache[C]=wt,Array.isArray(He)?[He]:He)}return Array.isArray(He)?[He]:He}const J=1e3*60*60*24*30,Y=e.sDate?e.sDate-J:void 0,H=e.sDate&&e.eDate?void 0:e.limit||1e3,st=new zt(e.source,u,l,H,Y,void 0);st.markAsSecondary();const Te=await st.run(e.pineTSCode);e.cache[T]=Te;const Yt=E?dr(A,k,Te.data.openTime.data,Te.data.closeTime.data,x,e.eDate,p):mr(A,k,Te.data.openTime.data,Te.data.closeTime.data,x);if(Yt==-1)return NaN;const Qt=Te.params[g][Yt];return!E&&p?(e.cache[C]=Yt,NaN):Array.isArray(Qt)?[Qt]:Qt}}function qh(e){return async(t,i,r,s=!1,n=null,a=!1,o=0)=>{const h=t[0],u=i[0],l=r[0],f=r[1];Array.isArray(s)&&s[0];const g=Array.isArray(a)?a[0]:a;if(e.isSecondaryContext)return Array.isArray(l)?[l]:l;const p=gt.indexOf(e.timeframe),x=gt.indexOf(u);if(p===-1||x===-1){if(g)return NaN;throw new Error("Invalid timeframe")}if(x>p){if(g)return NaN;throw new Error(`Timeframe ${u} is not lower than or equal to chart timeframe ${e.timeframe}`)}if(x===p)return[[l]];const y=`${h}_${u}_${f}_lower`;if(!e.cache[y]){const Y=e.sDate?e.sDate-2592e6:void 0,H=e.sDate&&e.eDate?void 0:e.limit||1e3,st=new zt(e.source,h,u,H,Y,e.eDate);st.markAsSecondary();const Te=await st.run(e.pineTSCode);e.cache[y]=Te}const w=e.cache[y],E=d.from(e.data.openTime).get(0),A=d.from(e.data.closeTime).get(0),k=w.data.openTime.data,T=w.data.closeTime.data,C=w.params[f];if(!C)return[];const J=[];for(let Y=0;Y<k.length;Y++){const H=k[Y];if(!(T[Y]<=E)){if(H>=A)break;H>=E&&H<A&&J.push(C[Y])}}return[J]}}var Uh=Object.defineProperty,Kh=(e,t,i)=>t in e?Uh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,xt=(e,t,i)=>Kh(e,typeof t!="symbol"?t+"":t,i);const zh={param:$h,security:Wh,security_lower_tf:qh};class Hh{constructor(t){this.context=t,xt(this,"_cache",{}),xt(this,"param"),xt(this,"security"),xt(this,"security_lower_tf"),Object.entries(zh).forEach(([i,r])=>{this[i]=r(t)})}}function Gh(e){return t=>{e.taState||(e.taState={});const i=t||"accdist";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.volume,0);if(isNaN(s)||isNaN(n)||isNaN(a)||isNaN(o))return e.precision(r.cumulativeSum);const h=n-a;let u=0;return h!==0&&(u=(s-a-(n-s))/h*o),r.cumulativeSum+=u,e.precision(r.cumulativeSum)}}function Yh(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0),h=d.from(s).get(0);e.taState||(e.taState={});const u=n||`alma_${a}_${o}_${h}`;if(!e.taState[u]){const p=o*(a-1),x=a/h,y=[];let w=0;for(let E=0;E<a;E++){const A=Math.exp(-Math.pow(E-p,2)/(2*x*x));y.push(A),w+=A}for(let E=0;E<y.length;E++)y[E]/=w;e.taState[u]={window:[],weights:y}}const l=e.taState[u],f=d.from(t).get(0);if(l.window.unshift(f),l.window.length<a)return NaN;l.window.length>a&&l.window.pop();let g=0;for(let p=0;p<a;p++)g+=l.weights[p]*l.window[a-1-p];return e.precision(g)}}function Qh(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const s=i||`atr_${r}`;e.taState[s]||(e.taState[s]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const n=e.taState[s],a=e.get(e.data.high,0),o=e.get(e.data.low,0),h=e.get(e.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(h))return NaN;let u;if(n.prevClose!==null){const f=a-o,g=Math.abs(a-n.prevClose),p=Math.abs(o-n.prevClose);u=Math.max(f,g,p)}else u=a-o;if(n.prevClose=h,n.initCount<r)return n.initSum+=u,n.initCount++,n.initCount===r?(n.prevAtr=n.initSum/r,e.precision(n.prevAtr)):NaN;const l=(n.prevAtr*(r-1)+u)/r;return n.prevAtr=l,e.precision(l)}}function Xh(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"barssince";e.taState[r]||(e.taState[r]={lastTrueIndex:null});const s=e.taState[r];return d.from(t).get(0)?(s.lastTrueIndex=e.idx,0):s.lastTrueIndex===null?NaN:e.idx-s.lastTrueIndex}}function Zh(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`bb_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const h=e.taState[o],u=d.from(t).get(0);if(isNaN(u))return[[NaN,NaN,NaN]];if(h.window.unshift(u),h.sum+=u,h.window.length<n)return[[NaN,NaN,NaN]];if(h.window.length>n){const y=h.window.pop();h.sum-=y}const l=h.sum/n;let f=0;for(let y=0;y<n;y++)f+=Math.pow(h.window[y]-l,2);const g=Math.sqrt(f/n),p=l+a*g,x=l-a*g;return[[e.precision(p),e.precision(l),e.precision(x)]]}}function Jh(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`bbw_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const h=e.taState[o],u=d.from(t).get(0);if(isNaN(u))return NaN;if(h.window.unshift(u),h.sum+=u,h.window.length<n)return NaN;if(h.window.length>n){const w=h.window.pop();h.sum-=w}const l=h.sum/n;let f=0;for(let w=0;w<n;w++){const E=h.window[w]-l;f+=E*E}const g=f/n,p=Math.sqrt(g),x=a*p;if(l===0)return e.precision(0);const y=2*x/l*100;return e.precision(y)}}function eu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`cci_${s}`;e.taState[n]||(e.taState[n]={window:[],sum:0});const a=e.taState[n],o=d.from(t).get(0);if(isNaN(o))return NaN;if(a.window.unshift(o),a.sum+=o,a.window.length<s)return NaN;if(a.window.length>s){const g=a.window.pop();a.sum-=g}const h=a.sum/s;let u=0;for(let g=0;g<s;g++)u+=Math.abs(a.window[g]-h);const l=u/s;if(l===0)return 0;const f=(o-h)/(.015*l);return e.precision(f)}}function tu(e){return(t,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`change_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=s)return NaN;a.window.length>s+1&&a.window.pop();const h=o-a.window[s];return e.precision(h)}}function iu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`cmo_${s}`;e.taState[n]||(e.taState[n]={gainsWindow:[],lossesWindow:[],gainsSum:0,lossesSum:0});const a=e.taState[n],o=d.from(t).get(0),h=d.from(t).get(1);if(isNaN(o)||isNaN(h))return NaN;const u=o-h,l=u>=0?u:0,f=u>=0?0:-u;if(a.gainsWindow.unshift(l),a.lossesWindow.unshift(f),a.gainsSum+=l,a.lossesSum+=f,a.gainsWindow.length<s)return NaN;if(a.gainsWindow.length>s){const x=a.gainsWindow.pop(),y=a.lossesWindow.pop();a.gainsSum-=x,a.lossesSum-=y}const g=a.gainsSum+a.lossesSum;if(g===0)return e.precision(0);const p=100*(a.gainsSum-a.lossesSum)/g;return e.precision(p)}}function ru(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);let a=0,o=!1;for(let l=0;l<s;l++){const f=n.get(l);if(isNaN(f)){o=!0;break}a+=f}if(o)return NaN;let h=0;for(let l=0;l<s;l++){const f=n.get(l);h+=f*(l+1)}if(a===0)return NaN;const u=-h/a;return e.precision(u)}}function su(e){return(t,i,r,s)=>{const n=d.from(r).get(0),a=d.from(t),o=d.from(i);if(e.idx<n-1)return NaN;let h=0,u=0,l=0,f=0,g=0,p=0;for(let A=0;A<n;A++){const k=a.get(A),T=o.get(A);isNaN(k)||isNaN(T)||(h+=k,u+=T,l+=k*T,f+=k*k,g+=T*T,p++)}if(p<2)return NaN;const x=p*l-h*u,y=p*f-h*h,w=p*g-u*u;if(y<=0||w<=0)return e.precision(0);const E=x/Math.sqrt(y*w);return e.precision(E)}}function nu(e){return(t,i,r)=>{const s=d.from(t),n=d.from(i),a=s.get(0),o=n.get(0),h=s.get(1),u=n.get(1);if(isNaN(a)||isNaN(o)||isNaN(h)||isNaN(u))return!1;const l=a>o&&h<=u,f=a<o&&h>=u;return l||f}}function au(e){return(t,i)=>{const r=d.from(t),s=d.from(i),n=r.get(0),a=s.get(0),o=r.get(1),h=s.get(1);return o<h&&n>a}}function ou(e){return(t,i)=>{const r=d.from(t),s=d.from(i),n=r.get(0),a=s.get(0),o=r.get(1),h=s.get(1);return o>h&&n<a}}function hu(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"cum";e.taState[r]||(e.taState[r]={cumulativeSum:0});const s=e.taState[r],n=d.from(t).get(0);return isNaN(n)||(s.cumulativeSum+=n),e.precision(s.cumulativeSum)}}function uu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`dev_${s}`;e.taState[n]||(e.taState[n]={window:[],sum:0});const a=e.taState[n],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<s)return NaN;if(a.window.length>s){const f=a.window.pop();a.sum-=f}const h=a.sum/s;let u=0;for(let f=0;f<s;f++)u+=Math.abs(a.window[f]-h);const l=u/s;return e.precision(l)}}function cu(e){return(t,i,r)=>{const s=d.from(t).get(0),n=d.from(i).get(0);e.taState||(e.taState={});const a=r||`dmi_${s}_${n}`;e.taState[a]||(e.taState[a]={prevHigh:NaN,prevLow:NaN,prevClose:NaN,trInitSum:0,plusInitSum:0,minusInitSum:0,initCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,dxInitSum:0,adxInitCount:0,prevADX:NaN});const o=e.taState[a],h=e.get(e.data.high,0),u=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(u)||isNaN(l))return[[NaN,NaN,NaN]];if(isNaN(o.prevHigh))return o.prevHigh=h,o.prevLow=u,o.prevClose=l,[[NaN,NaN,NaN]];const f=Math.max(h-u,Math.abs(h-o.prevClose),Math.abs(u-o.prevClose)),g=h-o.prevHigh,p=o.prevLow-u,x=g>p&&g>0?g:0,y=p>g&&p>0?p:0;o.prevHigh=h,o.prevLow=u,o.prevClose=l;let w,E,A;if(o.initCount++,o.initCount<=s)o.trInitSum+=f,o.plusInitSum+=x,o.minusInitSum+=y,o.initCount===s&&(o.prevSmoothedTR=o.trInitSum/s,o.prevSmoothedPlus=o.plusInitSum/s,o.prevSmoothedMinus=o.minusInitSum/s);else{const H=1/s;o.prevSmoothedTR=H*f+(1-H)*o.prevSmoothedTR,o.prevSmoothedPlus=H*x+(1-H)*o.prevSmoothedPlus,o.prevSmoothedMinus=H*y+(1-H)*o.prevSmoothedMinus}if(w=o.prevSmoothedTR,E=o.prevSmoothedPlus,A=o.prevSmoothedMinus,o.initCount<s)return[[NaN,NaN,NaN]];const k=w===0?0:100*E/w,T=w===0?0:100*A/w,C=k+T,J=C===0?0:100*Math.abs(k-T)/C;let Y=NaN;if(o.adxInitCount++,o.adxInitCount<=n)o.dxInitSum+=J,o.adxInitCount===n&&(o.prevADX=o.dxInitSum/n,Y=o.prevADX);else{const H=1/n;o.prevADX=H*J+(1-H)*o.prevADX,Y=o.prevADX}return[[e.precision(k),e.precision(T),e.precision(Y)]]}}function lu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`ema_${s}`;e.taState[n]||(e.taState[n]={prevEma:null,initSum:0,initCount:0});const a=e.taState[n],o=d.from(t).get(0);if(o==null||isNaN(o))return NaN;if(a.initCount<s)return a.initSum+=o,a.initCount++,a.initCount===s?(a.prevEma=a.initSum/s,e.precision(a.prevEma)):NaN;const h=2/(s+1),u=o*h+a.prevEma*(1-h);return a.prevEma=u,e.precision(u)}}function pu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);for(let a=0;a<s;a++){const o=n.get(a),h=n.get(a+1);if(isNaN(o)||isNaN(h)||o>=h)return!1}return!0}}function fu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`highest_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();const h=Math.max(...a.window.filter(u=>!isNaN(u)));return e.precision(h)}}function mu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s-1)return NaN;let a=-1/0,o=NaN;for(let h=0;h<s;h++){const u=n.get(h);isNaN(u)||(isNaN(o)||u>a)&&(a=u,o=-h)}return o}}function du(e){return(t,i,r)=>{const s=d.from(i).get(0),n=Math.floor(s/2),a=Math.floor(Math.sqrt(s)),o=e.ta.wma,h=o(t,n,r?`${r}_wma1`:void 0),u=o(t,s,r?`${r}_wma2`:void 0);if(isNaN(h)||isNaN(u))return NaN;e.taState||(e.taState={});const l=r||`hma_raw_${s}`;e.taState[l]||(e.taState[l]=[]);const f=2*h-u;e.taState[l].unshift(f);const g=r?`${r}_hma_final`:`hma_final_${s}`;e.taState[g]||(e.taState[g]={window:[]});const p=e.taState[g];if(p.window.unshift(f),p.window.length<a)return NaN;p.window.length>a&&p.window.pop();let x=0,y=0;for(let E=0;E<a;E++){const A=a-E;x+=p.window[E]*A,y+=A}const w=x/y;return e.precision(w)}}function gu(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.high,0),s=e.get(e.data.low,0),n=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(n))return NaN;const a=(r-s)*n;if(a===0)return e.precision(0);const o=(2*i-r-s)/a;return e.precision(o)}}function xu(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let h=!0;typeof s=="string"?n=s:s!==void 0&&(h=d.from(s).get(0));let u;const l=e.get(e.data.high,0),f=e.get(e.data.low,0);if(h){const T=e.get(e.data.close,1);isNaN(T)?u=NaN:u=Math.max(l-f,Math.abs(l-T),Math.abs(f-T))}else u=l-f;const g=d.from(t).get(0);e.taState||(e.taState={});const p=n||`kc_${a}_${o}_${h}`;e.taState[p]||(e.taState[p]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const x=e.taState[p],y=(T,C,J)=>{if(isNaN(C))return NaN;if(T.initCount<J)return T.initSum+=C,T.initCount++,T.initCount===J?(T.prevEma=T.initSum/J,T.prevEma):NaN;const Y=2/(J+1);return T.prevEma=C*Y+T.prevEma*(1-Y),T.prevEma},w=y(x.basisState,g,a),E=y(x.rangeState,u,a);if(isNaN(w)||isNaN(E))return[[NaN,NaN,NaN]];const A=w+E*o,k=w-E*o;return[[e.precision(w),e.precision(A),e.precision(k)]]}}function yu(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let h=!0;typeof s=="string"?n=s:s!==void 0&&(h=d.from(s).get(0)),e.taState||(e.taState={});const u=n||`kcw_${a}_${o}_${h}`;e.taState[u]||(e.taState[u]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const l=e.taState[u],f=(k,T,C)=>{if(isNaN(T))return NaN;if(k.initCount<C)return k.initSum+=T,k.initCount++,k.initCount===C?(k.prevEma=k.initSum/C,k.prevEma):NaN;const J=2/(C+1);return k.prevEma=T*J+k.prevEma*(1-J),k.prevEma};let g;const p=e.get(e.data.high,0),x=e.get(e.data.low,0);if(h){const k=e.get(e.data.close,1);isNaN(k)?g=NaN:g=Math.max(p-x,Math.abs(p-k),Math.abs(x-k))}else g=p-x;const y=d.from(t).get(0),w=f(l.basisState,y,a),E=f(l.rangeState,g,a);if(isNaN(w)||isNaN(E))return NaN;if(w===0)return e.precision(0);const A=2*E*o/w;return e.precision(A)}}function wu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`linreg_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[]});const h=e.taState[o],u=d.from(t).get(0);if(h.window.unshift(u),h.window.length<n)return NaN;h.window.length>n&&h.window.pop();let l=0,f=0,g=0,p=0;const x=n;for(let A=0;A<n;A++){const k=n-1-A,T=h.window[A];l+=k,f+=T,g+=k*T,p+=k*k}const y=x*p-l*l;if(y===0)return NaN;const w=(x*g-l*f)/y,E=(f-w*l)/x+w*(n-1-a);return e.precision(E)}}function bu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`lowest_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();const h=a.window.filter(l=>!isNaN(l)&&l!==void 0),u=h.length>0?Math.min(...h):NaN;return e.precision(u)}}function vu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s-1)return NaN;let a=1/0,o=NaN;for(let h=0;h<s;h++){const u=n.get(h);isNaN(u)||(isNaN(o)||u<a)&&(a=u,o=-h)}return o}}function _u(e){return(t,i,r,s,n)=>{const a=d.from(i).get(0),o=d.from(r).get(0),h=d.from(s).get(0),u=n||`macd_${a}_${o}_${h}`,l=`${u}_fast`,f=`${u}_slow`,g=`${u}_signal`,p=e.ta.ema(t,a,l),x=e.ta.ema(t,o,f);let y=NaN;!isNaN(p)&&!isNaN(x)&&(y=p-x);let w=NaN;isNaN(y)||(w=e.ta.ema(y,h,g));let E=NaN;return!isNaN(y)&&!isNaN(w)&&(E=y-w),[[e.precision(y),e.precision(w),e.precision(E)]]}}function Su(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`median_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();const h=a.window.slice().sort((f,g)=>f-g),u=Math.floor(s/2),l=s%2===0?(h[u-1]+h[u])/2:h[u];return e.precision(l)}}function Eu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`mfi_${s}`;e.taState[n]||(e.taState[n]={upperWindow:[],lowerWindow:[],upperSum:0,lowerSum:0});const a=e.taState[n],o=d.from(t).get(0),h=d.from(t).get(1),u=e.get(e.data.volume,0);if(isNaN(o)||isNaN(u))return NaN;const l=isNaN(h)?NaN:o-h;let f=0,g=0;if(f=u*(l<=0?0:o),g=u*(l>=0?0:o),a.upperWindow.unshift(f),a.lowerWindow.unshift(g),a.upperSum+=f,a.lowerSum+=g,a.upperWindow.length<s)return NaN;if(a.upperWindow.length>s){const x=a.upperWindow.pop(),y=a.lowerWindow.pop();a.upperSum-=x,a.lowerSum-=y}if(a.lowerSum===0)return a.upperSum,e.precision(100);if(a.upperSum===0)return e.precision(0);const p=100-100/(1+a.upperSum/a.lowerSum);return e.precision(p)}}function Nu(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s-1)return NaN;const a=new Map;for(let u=0;u<s;u++){const l=n.get(u);isNaN(l)||a.set(l,(a.get(l)||0)+1)}if(a.size===0)return NaN;let o=NaN,h=-1;for(const[u,l]of a.entries())l>h?(h=l,o=u):l===h&&u<o&&(o=u);return o}}function Cu(e){return(t,i,r)=>{const s=d.from(i).get(0);return e.ta.change(t,s)}}function ku(e){return t=>{e.taState||(e.taState={});const i=t||"nvi";e.taState[i]||(e.taState[i]={nvi:1});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),h=isNaN(s)?0:s,u=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||u===0)&&l<f){const g=(h-u)/u;r.nvi=r.nvi+g*r.nvi}return e.precision(r.nvi)}}function Iu(e){return()=>{e.taState||(e.taState={});const t="obv";e.taState[t]||(e.taState[t]={prevOBV:0});const i=e.taState[t],r=e.get(e.data.close,0),s=e.get(e.data.volume,0),n=e.get(e.data.close,1);if(isNaN(n))return i.prevOBV=0,e.precision(0);let a;return r>n?a=i.prevOBV+s:r<n?a=i.prevOBV-s:a=i.prevOBV,i.prevOBV=a,e.precision(a)}}function Au(e){return(t,i,r)=>t instanceof d?i?new d(t.data,t.offset+i):t:(e.params[r]||(e.params[r]=[]),Array.isArray(t)?new d(t,i||0):(e.params[r].length===0?e.params[r].push(t):e.params[r][e.params[r].length-1]=t,new d(e.params[r],0)))}function Pu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<n-1)return NaN;const h=[];for(let x=0;x<n;x++){const y=o.get(x);if(isNaN(y))return NaN;h.push(y)}h.sort((x,y)=>x-y);let u=a/100*n-.5;u<0&&(u=0),u>n-1&&(u=n-1);const l=Math.floor(u),f=Math.ceil(u);if(l===f)return e.precision(h[l]);const g=u-l,p=h[l]+g*(h[f]-h[l]);return e.precision(p)}}function Tu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<n-1)return NaN;const h=[];for(let l=0;l<n;l++){const f=o.get(l);isNaN(f)||h.push(f)}if(h.length===0)return NaN;h.sort((l,f)=>l-f);let u=Math.ceil(a/100*h.length)-1;return u<0&&(u=0),u>=h.length&&(u=h.length-1),e.precision(h[u])}}function Ru(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);if(e.idx<s)return NaN;const a=n.get(0);if(isNaN(a))return NaN;let o=0,h=0;for(let u=1;u<=s;u++){const l=n.get(u);isNaN(l)||(h++,l<=a&&o++)}return h===0?NaN:e.precision(o/h*100)}}function Du(e,t,i){const r=new Array(e.length).fill(NaN);for(let s=t+i;s<e.length;s++){const n=e[s-i];let a=!0;for(let o=1;o<=t;o++)if(e[s-i-o]>=n){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[s-i+o]>=n){a=!1;break}}a&&(r[s]=n)}return r}function Vu(e){return(t,i,r,s)=>{typeof r=="string"&&(r=i,i=t,t=e.data.high);const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),h=Du(o,n,a),u=e.idx;return e.precision(h[u])}}function Ou(e,t,i){const r=new Array(e.length).fill(NaN);for(let s=t+i;s<e.length;s++){const n=e[s-i];let a=!0;for(let o=1;o<=t;o++)if(e[s-i-o]<=n){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[s-i+o]<=n){a=!1;break}}a&&(r[s]=n)}return r}function Mu(e){return(t,i,r,s)=>{typeof r=="string"&&(r=i,i=t,t=e.data.low);const n=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),h=Ou(o,n,a),u=e.idx;return e.precision(h[u])}}function Lu(e){return t=>{e.taState||(e.taState={});const i=t||"pvi";e.taState[i]||(e.taState[i]={pvi:1});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),h=isNaN(s)?0:s,u=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||u===0)&&l>f){const g=(h-u)/u;r.pvi=r.pvi+g*r.pvi}return e.precision(r.pvi)}}function Bu(e){return t=>{e.taState||(e.taState={});const i=t||"pvt";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.close,1),a=e.get(e.data.volume,0);if(!isNaN(s)&&!isNaN(n)&&!isNaN(a)&&n!==0){const o=(s-n)/n*a;r.cumulativeSum+=o}return e.precision(r.cumulativeSum)}}function Fu(e){return(t,i,r)=>{const s=e.pine.ta.highest(t,i,(r||"range")+"_h"),n=e.pine.ta.lowest(t,i,(r||"range")+"_l");return isNaN(s)||isNaN(n)?NaN:e.precision(s-n)}}function ju(e){return(t,i,r)=>{const s=d.from(i).get(0),n=d.from(t);for(let a=0;a<s;a++){const o=n.get(a),h=n.get(a+1);if(isNaN(o)||isNaN(h)||o<=h)return!1}return!0}}function $u(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`rma_${s}`;e.taState[n]||(e.taState[n]={prevRma:null,initSum:0,initCount:0});const a=e.taState[n],o=d.from(t).get(0)||0;if(a.initCount<s)return a.initSum+=o,a.initCount++,a.initCount===s?(a.prevRma=a.initSum/s,e.precision(a.prevRma)):NaN;const h=1/s,u=o*h+a.prevRma*(1-h);return a.prevRma=u,e.precision(u)}}function Wu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`roc_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=s)return NaN;a.window.length>s+1&&a.window.pop();const h=a.window[s],u=(o-h)/h*100;return e.precision(u)}}function qu(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`rsi_${s}`;e.taState[n]||(e.taState[n]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.prevValue!==null){const h=o-a.prevValue,u=h>0?h:0,l=h<0?-h:0;if(a.initGains.length<s){if(a.initGains.push(u),a.initLosses.push(l),a.initGains.length===s){a.avgGain=a.initGains.reduce((p,x)=>p+x,0)/s,a.avgLoss=a.initLosses.reduce((p,x)=>p+x,0)/s,a.prevValue=o;const g=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return e.precision(g)}return a.prevValue=o,NaN}a.avgGain=(a.avgGain*(s-1)+u)/s,a.avgLoss=(a.avgLoss*(s-1)+l)/s;const f=a.avgLoss===0?100:100-100/(1+a.avgGain/a.avgLoss);return a.prevValue=o,e.precision(f)}return a.prevValue=o,NaN}}function Uu(e){return(t,i,r,s)=>{const n=d.from(t).get(0),a=d.from(i).get(0),o=d.from(r).get(0);e.taState||(e.taState={});const h=s||`sar_${n}_${a}_${o}`;e.taState[h]||(e.taState[h]={result:NaN,maxMin:NaN,acceleration:NaN,isBelow:!1,barIndex:0});const u=e.taState[h],l=e.get(e.data.high,0),f=e.get(e.data.low,0),g=e.get(e.data.close,0),p=e.get(e.data.close,1),x=e.get(e.data.high,1),y=e.get(e.data.low,1),w=e.get(e.data.high,2),E=e.get(e.data.low,2);if(isNaN(l)||isNaN(f)||isNaN(g))return NaN;let A=!1;return u.barIndex===1&&(g>p?(u.isBelow=!0,u.maxMin=l,u.result=y):(u.isBelow=!1,u.maxMin=f,u.result=x),A=!0,u.acceleration=n),u.barIndex>=1&&(u.result=u.result+u.acceleration*(u.maxMin-u.result),u.isBelow?u.result>f&&(A=!0,u.isBelow=!1,u.result=Math.max(l,u.maxMin),u.maxMin=f,u.acceleration=n):u.result<l&&(A=!0,u.isBelow=!0,u.result=Math.min(f,u.maxMin),u.maxMin=l,u.acceleration=n),A||(u.isBelow?l>u.maxMin&&(u.maxMin=l,u.acceleration=Math.min(u.acceleration+a,o)):f<u.maxMin&&(u.maxMin=f,u.acceleration=Math.min(u.acceleration+a,o))),u.isBelow?(u.result=Math.min(u.result,y),u.barIndex>1&&(u.result=Math.min(u.result,E))):(u.result=Math.max(u.result,x),u.barIndex>1&&(u.result=Math.max(u.result,w)))),u.barIndex++,u.barIndex<=1?NaN:e.precision(u.result)}}function Ku(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`sma_${s}`;e.taState[n]||(e.taState[n]={window:[],sum:0});const a=e.taState[n],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<s)return NaN;if(a.window.length>s){const u=a.window.pop();a.sum-=u}const h=a.sum/s;return e.precision(h)}}function zu(e){return(t,i,r=!0,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`stdev_${n}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const h=e.taState[o],u=d.from(t).get(0);if(u==null||isNaN(u))return NaN;if(h.window.unshift(u),h.sum+=u,h.window.length<n)return NaN;if(h.window.length>n){const x=h.window.pop();h.sum-=x}const l=h.sum/n;let f=0;for(let x=0;x<n;x++)f+=Math.pow(h.window[x]-l,2);const g=a?n:n-1,p=Math.sqrt(f/g);return e.precision(p)}}function Hu(e){return(t,i,r,s,n)=>{const a=d.from(s).get(0);e.taState||(e.taState={});const o=n||`stoch_${a}`;e.taState[o]||(e.taState[o]={highWindow:[],lowWindow:[]});const h=e.taState[o],u=d.from(t).get(0),l=d.from(i).get(0),f=d.from(r).get(0);if(isNaN(u)||isNaN(l)||isNaN(f))return NaN;if(h.highWindow.unshift(l),h.lowWindow.unshift(f),h.highWindow.length<a)return NaN;h.highWindow.length>a&&(h.highWindow.pop(),h.lowWindow.pop());let g=h.highWindow[0],p=h.lowWindow[0];for(let w=1;w<a;w++)h.highWindow[w]>g&&(g=h.highWindow[w]),h.lowWindow[w]<p&&(p=h.lowWindow[w]);const x=g-p;if(x===0)return NaN;const y=100*(u-p)/x;return e.precision(y)}}function Gu(e){return(t,i,r)=>{const s=d.from(t).get(0),n=d.from(i).get(0);e.taState||(e.taState={});const a=r||`supertrend_${s}_${n}`;e.taState[a]||(e.taState[a]={trWindow:[],trSum:0,atrValue:NaN,atrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,prevClose:NaN});const o=e.taState[a],h=e.get(e.data.high,0),u=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(u)||isNaN(l))return[[NaN,NaN]];const f=(h+u)/2;let g;isNaN(o.prevClose)?g=h-u:g=Math.max(h-u,Math.abs(h-o.prevClose),Math.abs(u-o.prevClose)),o.atrCount++,o.atrCount<=n?(o.trWindow.push(g),o.trSum+=g,o.atrCount===n&&(o.atrValue=o.trSum/n)):o.atrValue=(o.atrValue*(n-1)+g)/n;const p=o.atrValue,x=o.prevClose;if(o.prevClose=l,isNaN(p))return[[NaN,NaN]];let y=f+s*p,w=f-s*p;const E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,A=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>E||x<E||(w=E),isNaN(o.prevUpperBand)||y<A||x>A||(y=A);let k,T;const C=o.prevSuperTrend;return o.atrCount===n?k=1:C===o.prevUpperBand?k=l>y?-1:1:k=l<w?1:-1,T=k===-1?w:y,o.prevLowerBand=w,o.prevUpperBand=y,o.prevSuperTrend=T,o.prevDirection=k,[[e.precision(T),k]]}}function Yu(e){return(t,i)=>{const r=[1,2,2,1],s=6;e.taState||(e.taState={});const n=i||"swma";e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<4)return NaN;a.window.length>4&&a.window.pop();let h=0;for(let u=0;u<4;u++)h+=r[u]*a.window[3-u];return h/=s,e.precision(h)}}function Qu(e){return(t,i)=>{let r=!0;typeof t=="string"||t!==void 0&&(r=d.from(t).get(0));const s=e.get(e.data.high,0),n=e.get(e.data.low,0),a=e.get(e.data.close,1);if(isNaN(a))return r?e.precision(s-n):NaN;const o=Math.max(s-n,Math.abs(s-a),Math.abs(n-a));return e.precision(o)}}function Xu(e){return(t,i,r,s)=>{const n=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=s||`tsi_${n}_${a}`;e.taState[o]||(e.taState[o]={prevSource:NaN,ema1_pc_multiplier:2/(a+1),ema1_pc_value:NaN,ema1_pc_count:0,ema1_pc_sum:0,ema2_pc_multiplier:2/(n+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/(n+1),ema2_abs_value:NaN,ema2_abs_count:0,ema2_abs_sum:0});const h=e.taState[o],u=d.from(t).get(0);if(isNaN(u))return NaN;const l=isNaN(h.prevSource)?NaN:u-h.prevSource;if(h.prevSource=u,isNaN(l))return NaN;const f=Math.abs(l);if(h.ema1_pc_count++,h.ema1_pc_count<=a?(h.ema1_pc_sum+=l,h.ema1_pc_count===a&&(h.ema1_pc_value=h.ema1_pc_sum/a)):h.ema1_pc_value=l*h.ema1_pc_multiplier+h.ema1_pc_value*(1-h.ema1_pc_multiplier),h.ema1_abs_count++,h.ema1_abs_count<=a?(h.ema1_abs_sum+=f,h.ema1_abs_count===a&&(h.ema1_abs_value=h.ema1_abs_sum/a)):h.ema1_abs_value=f*h.ema1_abs_multiplier+h.ema1_abs_value*(1-h.ema1_abs_multiplier),isNaN(h.ema1_pc_value)||isNaN(h.ema1_abs_value))return NaN;if(h.ema2_pc_count++,h.ema2_pc_count<=n?(h.ema2_pc_sum+=h.ema1_pc_value,h.ema2_pc_count===n&&(h.ema2_pc_value=h.ema2_pc_sum/n)):h.ema2_pc_value=h.ema1_pc_value*h.ema2_pc_multiplier+h.ema2_pc_value*(1-h.ema2_pc_multiplier),h.ema2_abs_count++,h.ema2_abs_count<=n?(h.ema2_abs_sum+=h.ema1_abs_value,h.ema2_abs_count===n&&(h.ema2_abs_value=h.ema2_abs_sum/n)):h.ema2_abs_value=h.ema1_abs_value*h.ema2_abs_multiplier+h.ema2_abs_value*(1-h.ema2_abs_multiplier),isNaN(h.ema2_pc_value)||isNaN(h.ema2_abs_value))return NaN;if(h.ema2_abs_value===0)return e.precision(0);const g=h.ema2_pc_value/h.ema2_abs_value;return e.precision(g)}}function Zu(e){return(t,i,r,s)=>{e.taState||(e.taState={});const n=s||"valuewhen";e.taState[n]||(e.taState[n]={values:[]});const a=e.taState[n],o=d.from(t).get(0),h=d.from(i).get(0),u=d.from(r).get(0);if(o&&a.values.push(h),isNaN(u)||u<0)return NaN;const l=a.values.length-1-u;if(l<0)return NaN;const f=a.values[l];return typeof f=="number"?e.precision(f):f}}function Ju(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`variance_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();let h=0,u=0;for(let g=0;g<s;g++)h+=a.window[g],u+=a.window[g]*a.window[g];const l=h/s,f=u/s-l*l;return e.precision(f)}}function ec(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"vwap";e.taState[r]||(e.taState[r]={cumulativePV:0,cumulativeVolume:0,lastSessionDate:null});const s=e.taState[r],n=d.from(t).get(0),a=d.from(e.data.volume).get(0),o=d.from(e.data.openTime).get(0),h=new Date(o).toISOString().slice(0,10);if(s.lastSessionDate!==h&&(s.cumulativePV=0,s.cumulativeVolume=0,s.lastSessionDate=h),s.cumulativePV+=n*a,s.cumulativeVolume+=a,s.cumulativeVolume===0)return NaN;const u=s.cumulativePV/s.cumulativeVolume;return e.precision(u)}}function tc(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`vwma_${s}`;e.taState[n]||(e.taState[n]={window:[],volumeWindow:[]});const a=e.taState[n],o=d.from(t).get(0),h=e.get(e.data.volume,0);if(a.window.unshift(o),a.volumeWindow.unshift(h),a.window.length<s)return NaN;a.window.length>s&&(a.window.pop(),a.volumeWindow.pop());let u=0,l=0;for(let g=0;g<s;g++)u+=a.window[g]*a.volumeWindow[g],l+=a.volumeWindow[g];const f=u/l;return e.precision(f)}}function ic(e){return t=>{e.taState||(e.taState={});const i=t||"wad";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],s=e.get(e.data.close,0),n=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.close,1);if(isNaN(s)||isNaN(n)||isNaN(a))return e.precision(r.cumulativeSum);let h=0;if(!isNaN(o)){const u=Math.max(n,o),l=Math.min(a,o),f=s-o;f>0?h=s-l:f<0&&(h=s-u)}return r.cumulativeSum+=h,e.precision(r.cumulativeSum)}}function rc(e){return(t,i,r)=>{const s=d.from(i).get(0);e.taState||(e.taState={});const n=r||`wma_${s}`;e.taState[n]||(e.taState[n]={window:[]});const a=e.taState[n],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<s)return NaN;a.window.length>s&&a.window.pop();let h=0,u=0;for(let f=0;f<s;f++){const g=s-f;h+=a.window[f]*g,u+=g}const l=h/u;return e.precision(l)}}function sc(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const s=i||`wpr_${r}`;e.taState[s]||(e.taState[s]={highWindow:[],lowWindow:[]});const n=e.taState[s],a=e.get(e.data.high,0),o=e.get(e.data.low,0),h=e.get(e.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(h))return NaN;if(n.highWindow.unshift(a),n.lowWindow.unshift(o),n.highWindow.length<r)return NaN;n.highWindow.length>r&&(n.highWindow.pop(),n.lowWindow.pop());let u=n.highWindow[0],l=n.lowWindow[0];for(let p=1;p<r;p++)n.highWindow[p]>u&&(u=n.highWindow[p]),n.lowWindow[p]<l&&(l=n.lowWindow[p]);const f=u-l;if(f===0)return e.precision(0);const g=(u-h)/f*-100;return e.precision(g)}}function nc(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.open,0),s=e.get(e.data.high,0),n=e.get(e.data.low,0),a=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(n)||isNaN(a))return NaN;const o=s-n;if(o===0)return e.precision(0);const h=(i-r)/o*a;return e.precision(h)}}var ac=Object.defineProperty,oc=(e,t,i)=>t in e?ac(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,S=(e,t,i)=>oc(e,typeof t!="symbol"?t+"":t,i);const hc={accdist:Gh,alma:Yh,atr:Qh,barssince:Xh,bb:Zh,bbw:Jh,cci:eu,change:tu,cmo:iu,cog:ru,correlation:su,cross:nu,crossover:au,crossunder:ou,cum:hu,dev:uu,dmi:cu,ema:lu,falling:pu,highest:fu,highestbars:mu,hma:du,iii:gu,kc:xu,kcw:yu,linreg:wu,lowest:bu,lowestbars:vu,macd:_u,median:Su,mfi:Eu,mode:Nu,mom:Cu,nvi:ku,obv:Iu,param:Au,percentile_linear_interpolation:Pu,percentile_nearest_rank:Tu,percentrank:Ru,pivothigh:Vu,pivotlow:Mu,pvi:Lu,pvt:Bu,range:Fu,rising:ju,rma:$u,roc:Wu,rsi:qu,sar:Uu,sma:Ku,stdev:zu,stoch:Hu,supertrend:Gu,swma:Yu,tr:Qu,tsi:Xu,valuewhen:Zu,variance:Ju,vwap:ec,vwma:tc,wad:ic,wma:rc,wpr:sc,wvad:nc};class uc{constructor(t){this.context=t,S(this,"accdist"),S(this,"alma"),S(this,"atr"),S(this,"barssince"),S(this,"bb"),S(this,"bbw"),S(this,"cci"),S(this,"change"),S(this,"cmo"),S(this,"cog"),S(this,"correlation"),S(this,"cross"),S(this,"crossover"),S(this,"crossunder"),S(this,"cum"),S(this,"dev"),S(this,"dmi"),S(this,"ema"),S(this,"falling"),S(this,"highest"),S(this,"highestbars"),S(this,"hma"),S(this,"iii"),S(this,"kc"),S(this,"kcw"),S(this,"linreg"),S(this,"lowest"),S(this,"lowestbars"),S(this,"macd"),S(this,"median"),S(this,"mfi"),S(this,"mode"),S(this,"mom"),S(this,"nvi"),S(this,"obv"),S(this,"param"),S(this,"percentile_linear_interpolation"),S(this,"percentile_nearest_rank"),S(this,"percentrank"),S(this,"pivothigh"),S(this,"pivotlow"),S(this,"pvi"),S(this,"pvt"),S(this,"range"),S(this,"rising"),S(this,"rma"),S(this,"roc"),S(this,"rsi"),S(this,"sar"),S(this,"sma"),S(this,"stdev"),S(this,"stoch"),S(this,"supertrend"),S(this,"swma"),S(this,"tr"),S(this,"tsi"),S(this,"valuewhen"),S(this,"variance"),S(this,"vwap"),S(this,"vwma"),S(this,"wad"),S(this,"wma"),S(this,"wpr"),S(this,"wvad"),Object.entries(hc).forEach(([i,r])=>{this[i]=r(t)})}}class cc{constructor(t){this.context=t}logFormat(t,...i){return t.replace(/{(\d+)}/g,(r,s)=>i[s])}param(t,i=0,r){return d.from(t).get(i)}warning(t,...i){console.warn(this.logFormat(t,...i))}error(t,...i){console.error(this.logFormat(t,...i))}info(t,...i){console.log(this.logFormat(t,...i))}}class lc{constructor(t){this.context=t}param(t,i=0,r){return d.from(t).get(i)}tostring(t){return String(t)}tonumber(t){return Number(t)}lower(t){return String(t).toLowerCase()}upper(t){return String(t).toUpperCase()}trim(t){return String(t).trim()}repeat(t,i,r=""){return Array(i).fill(t).join(r||"")}replace_all(t,i,r){return String(t).replaceAll(i,r)}replace(t,i,r,s=0){const n=String(t),a=String(i),o=String(r),h=Math.floor(Number(s))||0;if(a==="")return n;let u=0,l=0;for(;;){const f=n.indexOf(a,u);if(f===-1)return n;if(l===h)return n.substring(0,f)+o+n.substring(f+a.length);l++,u=f+a.length}}contains(t,i){return String(t).includes(i)}endswith(t,i){return String(t).endsWith(i)}startswith(t,i){return String(t).startsWith(i)}pos(t,i){const r=String(t).indexOf(i);return r===-1?NaN:r}length(t){return String(t).length}match(t,i){return String(t).match(new RegExp(i))}split(t,i){return[String(t).split(i)]}substring(t,i,r){return String(t).substring(i,r)}format(t,...i){return t.replace(/{(\d+)}/g,(r,s)=>i[s])}}class pc{constructor(t){this.context=t}param(t,i=0,r){return d.from(t).get(i)}get main_period(){return this.context.timeframe}get period(){return this.context.timeframe}get multiplier(){const t=parseInt(this.context.timeframe);return isNaN(t)?1:t}get isdwm(){return["D","W","M"].includes(this.context.timeframe.slice(-1))}get isdaily(){return this.context.timeframe.slice(-1)==="D"}get isweekly(){return this.context.timeframe.slice(-1)==="W"}get ismonthly(){return this.context.timeframe.slice(-1)==="M"}get isseconds(){return this.context.timeframe.slice(-1)==="S"}get isminutes(){return parseInt(this.context.timeframe).toString()==this.context.timeframe.trim()}get isintraday(){return!this.isdwm}from_seconds(t){return t<60?Math.ceil(t/5)*5+"S":t<60*60*24?Math.ceil(t/60):t<=60*60*24*7*52?t%(60*60*24*7)===0?Math.ceil(t/604800)+"W":Math.ceil(t/(60*60*24))+"D":"12M"}in_seconds(t){const i=parseInt(t),r=t.slice(-1);return r==="S"?i:r==="D"?i*60*60*24:r==="W"?i*60*60*24*7:r==="M"?i*60*60*24*30:isNaN(i)?0:i*60}}const fc=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],mc={series:"series",title:"string",color:"string",linewidth:"number",style:"string",trackprice:"boolean",histbase:"number",offset:"number",join:"bool",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"};class dc{constructor(t){this.context=t}extractPlotOptions(t){const i={};for(let r in t)i[r]=d.from(t[r]).get(0);return i}plotchar(t,i,r){this.context.plots[i]||(this.context.plots[i]={data:[],options:this.extractPlotOptions(r),title:i});const s=d.from(t).get(0);this.context.plots[i].data.push({time:this.context.marketData[this.context.idx].openTime,value:s,options:{...this.extractPlotOptions(r),style:"char"}})}plot(...t){const i=Ut(t,fc,mc),{series:r,title:s,...n}=i,a=this.extractPlotOptions(n);this.context.plots[s]||(this.context.plots[s]={data:[],options:a,title:s});const o=d.from(r).get(0);this.context.plots[s].data.push({time:this.context.marketData[this.context.idx].openTime,value:o,options:{color:a.color,offset:a.offset}})}}class gc{constructor(t){this.context=t}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(t,i=0,r){return d.from(t).get(i)}any(t,i,r,s,n,a,o){return this.context.pine.plot(t,{title:i,color:r,linestyle:s,linewidth:n,editable:a,display:o})}}var xc=Object.defineProperty,yc=(e,t,i)=>t in e?xc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,j=(e,t,i)=>yc(e,typeof t!="symbol"?t+"":t,i);const gr=class Xt{constructor({marketData:t,source:i,tickerId:r,timeframe:s,limit:n,sDate:a,eDate:o,fullContext:h}){j(this,"data",{open:new d([]),high:new d([]),low:new d([]),close:new d([]),volume:new d([]),hl2:new d([]),hlc3:new d([]),ohlc4:new d([]),hlcc4:new d([])}),j(this,"indicator"),j(this,"cache",{}),j(this,"taState",{}),j(this,"isSecondaryContext",!1),j(this,"NA",NaN),j(this,"lang"),j(this,"pine"),j(this,"idx",0),j(this,"params",{}),j(this,"const",{}),j(this,"var",{}),j(this,"let",{}),j(this,"result"),j(this,"plots",{}),j(this,"marketData"),j(this,"source"),j(this,"tickerId"),j(this,"timeframe",""),j(this,"limit"),j(this,"sDate"),j(this,"eDate"),j(this,"fullContext"),j(this,"pineTSCode"),this.marketData=t,this.source=i,this.tickerId=r,this.timeframe=s,this.limit=n,this.sDate=a,this.eDate=o,this.fullContext=h||this;const u=new jo(this),l={na:u.na.bind(u),color:u.color,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),bool:u.bool.bind(u)},f=this;this.pine={input:new oh(this),ta:new uc(this),math:new jh(this),request:new Hh(this),array:new la(this),map:new Ca(this),matrix:new Ao(this),syminfo:null,timeframe:new pc(this),barstate:new Do(this),get bar_index(){return f.idx},get last_bar_index(){return f.data.close.length-1},get last_bar_time(){return f.data.openTime.get(f.data.openTime.length-1)},get timenow(){return new Date().getTime()},log:new cc(this),str:new lc(this),...l,...Gn};const g=new dc(this),p=new gc(this);this.bindContextObject(g,["plot","plotchar"]),this.bindContextObject(p,["any","style_dashed","style_solid","style_dotted","param"],"hline")}bindContextObject(t,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const s=r?this.pine[r]:this.pine;for(const n of i)typeof t[n]=="function"?s[n]=t[n].bind(t):s[n]=t[n]}init(t,i,r=0){let s;return i instanceof d?s=i.get(0):Array.isArray(i)?Array.isArray(i[0])?s=i[0]:s=i[i.length-1+r]:s=i,t?t instanceof d?(t.data[t.data.length-1]=s,t):Array.isArray(t)?(t[t.length-1]=s,new d(t)):new d([s]):new d([s])}initVar(t,i){if(t)return t;let r;return i instanceof d?r=i.get(0):Array.isArray(i)?Array.isArray(i[0])?r=i[0]:r=this.precision(i[i.length-1]):r=this.precision(i),new d([r])}precision(t,i=10){const r=10**i;return typeof t=="number"?Math.round(t*r)/r:t}param(t,i,r){return typeof t=="string"?t:t instanceof d?i?new d(t.data,t.offset+i):t:!Array.isArray(t)&&typeof t=="object"?t:(this.params[r]||(this.params[r]=[]),Array.isArray(t)?new d(t,i||0):(this.params[r].length===0?this.params[r].push(t):this.params[r][this.params[r].length-1]=t,new d(this.params[r],0)))}get(t,i){if(t instanceof d)return t.get(i);if(Array.isArray(t)){const r=t.length-1-i;return r<0||r>=t.length?NaN:t[r]}return t}set(t,i){if(t instanceof d){t.set(0,i);return}if(Array.isArray(t)){t.length>0?t[t.length-1]=i:t.push(i);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,i){const r=`${t}->${i}`;Xt._deprecationWarningsShown.has(r)||(Xt._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,i):console.warn(`\x1B[33m[WARNING] ${t} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}};j(gr,"_deprecationWarningsShown",new Set);let Kt=gr;var wc=Object.defineProperty,bc=(e,t,i)=>t in e?wc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,K=(e,t,i)=>bc(e,typeof t!="symbol"?t+"":t,i);class zt{constructor(t,i,r,s,n,a){this.source=t,this.tickerId=i,this.timeframe=r,this.limit=s,this.sDate=n,this.eDate=a,K(this,"data",[]),K(this,"open",[]),K(this,"high",[]),K(this,"low",[]),K(this,"close",[]),K(this,"volume",[]),K(this,"hl2",[]),K(this,"hlc3",[]),K(this,"ohlc4",[]),K(this,"hlcc4",[]),K(this,"openTime",[]),K(this,"closeTime",[]),K(this,"_readyPromise",null),K(this,"_ready",!1),K(this,"_debugSettings",{ln:!1,debug:!1}),K(this,"_transpiledCode",null),K(this,"_isSecondaryContext",!1),K(this,"_syminfo"),this._readyPromise=new Promise(o=>{this.loadMarketData(t,i,r,s,n,a).then(h=>{const u=h;this.data=u;const l=u.map(C=>C.open),f=u.map(C=>C.close),g=u.map(C=>C.high),p=u.map(C=>C.low),x=u.map(C=>C.volume),y=u.map(C=>(C.high+C.low+C.close)/3),w=u.map(C=>(C.high+C.low)/2),E=u.map(C=>(C.high+C.low+C.open+C.close)/4),A=u.map(C=>(C.high+C.low+C.close+C.close)/4),k=u.map(C=>C.openTime),T=u.map(C=>C.closeTime);this.open=l,this.close=f,this.high=g,this.low=p,this.volume=x,this.hl2=w,this.hlc3=y,this.ohlc4=E,this.hlcc4=A,this.openTime=k,this.closeTime=T,t&&t.getSymbolInfo?t.getSymbolInfo(i).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setDebugSettings({ln:t,debug:i}){this._debugSettings.ln=t,this._debugSettings.debug=i}async loadMarketData(t,i,r,s,n,a){return Array.isArray(t)?t:t.getMarketData(i,r,s,n,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(t,i,r){if(r&&r>0){const s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(t,i,r,s)}else return this._runComplete(t,i)}async _runComplete(t,i){await this.ready(),i||(i=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-i,this.data.length),r}async*_runPaginated(t,i,r,s=!1){await this.ready(),i||(i=this.data.length);const n=this._initializeContext(t,this._isSecondaryContext);this._transpiledCode=this._transpileCode(t);let a=this.data.length-i;for(;;){const o=this.data.length-a;if(o>0){const l=Math.min(o,r),f=this._getResultLength(n.result);await this._executeIterations(n,this._transpiledCode,a,a+l),a+=l,yield this._createPageContext(n,f);continue}if(!s||Array.isArray(this.source))break;const{newCandles:h,updatedLastCandle:u}=await this._updateMarketData();if(h===0&&!u){yield null;continue}this._removeLastResult(n),a=this.data.length-(h+1),n.pine.barstate.setLive()}}_getResultLength(t){if(Array.isArray(t))return t.length;if(typeof t=="object"&&t!==null){const i=Object.keys(t);if(i.length>0&&Array.isArray(t[i[0]]))return t[i[0]].length}return 0}_createPageContext(t,i){const r=new Kt({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:t});if(r.pineTSCode=t.pineTSCode,r.idx=t.idx,Array.isArray(t.result))r.result=t.result.slice(i);else if(typeof t.result=="object"&&t.result!==null){r.result={};for(let s in t.result)Array.isArray(t.result[s])?r.result[s]=t.result[s].slice(i):r.result[s]=t.result[s]}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 i=this.source,r=this.data.length-1,s=this.data[r].openTime;try{const n=await i.getMarketData(this.tickerId,this.timeframe,void 0,s,t);if(!n||n.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let h=0;h<n.length;h++){const u=n[h];u.openTime===s?(this._replaceCandle(r,u),a=!0):u.openTime>s&&(this._appendCandle(u),o++)}return{newCandles:o,updatedLastCandle:a}}catch(n){return console.error("Error updating market data:",n),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(t,i){this.data[t]=i,this.open[t]=i.open,this.close[t]=i.close,this.high[t]=i.high,this.low[t]=i.low,this.volume[t]=i.volume,this.hl2[t]=(i.high+i.low)/2,this.hlc3[t]=(i.high+i.low+i.close)/3,this.ohlc4[t]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[t]=(i.high+i.low+i.close+i.close)/4,this.openTime[t]=i.openTime,this.closeTime[t]=i.closeTime}_appendCandle(t){this.data.push(t),this.open.push(t.open),this.close.push(t.close),this.high.push(t.high),this.low.push(t.low),this.volume.push(t.volume),this.hl2.push((t.high+t.low)/2),this.hlc3.push((t.high+t.low+t.close)/3),this.ohlc4.push((t.high+t.low+t.open+t.close)/4),this.hlcc4.push((t.high+t.low+t.close+t.close)/4),this.openTime.push(t.openTime),this.closeTime.push(t.closeTime)}_removeLastResult(t){if(Array.isArray(t.result))t.result.pop();else if(typeof t.result=="object"&&t.result!==null)for(let i in t.result)Array.isArray(t.result[i])&&t.result[i].pop();t.data.close.data.pop(),t.data.open.data.pop(),t.data.high.data.pop(),t.data.low.data.pop(),t.data.volume.data.pop(),t.data.hl2.data.pop(),t.data.hlc3.data.pop(),t.data.ohlc4.data.pop(),t.data.hlcc4.data.pop(),t.data.openTime.data.pop(),t.data.closeTime&&t.data.closeTime.data.pop()}_initializeContext(t,i=!1){const r=new Kt({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});return r.pine.syminfo=this._syminfo,r.pineTSCode=t,r.isSecondaryContext=i,r.data.close=new d([]),r.data.open=new d([]),r.data.high=new d([]),r.data.low=new d([]),r.data.volume=new d([]),r.data.hl2=new d([]),r.data.hlc3=new d([]),r.data.ohlc4=new d([]),r.data.hlcc4=new d([]),r.data.openTime=new d([]),r.data.closeTime=new d([]),r}_transpileCode(t){return cn.bind(this)(t,this._debugSettings)}async _executeIterations(t,i,r,s){const n=["const","var","let","params"];for(let a=r;a<s;a++){t.idx=a,t.data.close.data.push(this.close[a]),t.data.open.data.push(this.open[a]),t.data.high.data.push(this.high[a]),t.data.low.data.push(this.low[a]),t.data.volume.data.push(this.volume[a]),t.data.hl2.data.push(this.hl2[a]),t.data.hlc3.data.push(this.hlc3[a]),t.data.ohlc4.data.push(this.ohlc4[a]),t.data.hlcc4.data.push(this.hlcc4[a]),t.data.openTime.data.push(this.openTime[a]),t.data.closeTime.data.push(this.closeTime[a]);const o=await i(t);if(typeof o=="object"){typeof t.result!="object"&&(t.result={});for(let h in o){t.result[h]===void 0&&(t.result[h]=[]);let u;o[h]instanceof d?u=o[h].get(0):Array.isArray(o[h])?u=o[h][o[h].length-1]:u=o[h],t.result[h].push(u)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(o);for(let h of n)for(let u in t[h]){const l=t[h][u];if(l instanceof d){const f=l.get(0);l.data.push(f)}else if(Array.isArray(l)){const f=l[l.length-1];l.push(f)}}}}}var vc=Object.defineProperty,_c=(e,t,i)=>t in e?vc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ht=(e,t,i)=>_c(e,typeof t!="symbol"?t+"":t,i);const xr="https://api.binance.com/api/v3",Gt={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 Sc{constructor(t=5*60*1e3){Ht(this,"cache"),Ht(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=t}generateKey(t){return Object.entries(t).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(t){const i=this.generateKey(t),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(t,i){const r=this.generateKey(t);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const t=Date.now();for(const[i,r]of this.cache.entries())t-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class Ec{constructor(){Ht(this,"cacheManager"),this.cacheManager=new Sc(5*60*1e3)}async getMarketDataInterval(t,i,r,s){try{const n=Gt[i.toUpperCase()];if(!n)return console.error(`Unsupported timeframe: ${i}`),[];const a={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3};let o=[],h=r;const u=s,l=a[n];if(!l)return console.error(`Duration not defined for interval: ${n}`),[];for(;h<u;){const f=Math.min(h+1e3*l,u),g=await this.getMarketData(t,i,1e3,h,f);if(g.length===0)break;o=o.concat(g),h=g[g.length-1].closeTime+1}return o}catch(n){return console.error("Error in getMarketDataInterval:",n),[]}}async getMarketData(t,i,r,s,n){try{const a=n!==void 0,o={tickerId:t,timeframe:i,limit:r,sDate:s,eDate:n};if(a){const g=this.cacheManager.get(o);if(g)return g}const h=Gt[i.toUpperCase()];if(!h)return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,s,n)&&s&&n){const g=await this.getMarketDataInterval(t,i,s,n),p=r?g.slice(0,r):g;return this.cacheManager.set(o,p),p}let u=`${xr}/klines?symbol=${t}&interval=${h}`;r&&(u+=`&limit=${Math.min(r,1e3)}`),s&&(u+=`&startTime=${s}`),n&&(u+=`&endTime=${n}`);const l=await fetch(u);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const f=(await l.json()).map(g=>({openTime:parseInt(g[0]),open:parseFloat(g[1]),high:parseFloat(g[2]),low:parseFloat(g[3]),close:parseFloat(g[4]),volume:parseFloat(g[5]),closeTime:parseInt(g[6]),quoteAssetVolume:parseFloat(g[7]),numberOfTrades:parseInt(g[8]),takerBuyBaseAssetVolume:parseFloat(g[9]),takerBuyQuoteAssetVolume:parseFloat(g[10]),ignore:g[11]}));return a&&this.cacheManager.set(o,f),f}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(t,i,r,s){if(i&&i>1e3)return!0;if(r&&s){const n=Gt[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}[n];if(a)return Math.ceil((s-r)/a)>1e3}return!1}async getSymbolInfo(t){try{let i="crypto",r=xr,s=t,n="";t.endsWith(".P")?(i="futures",s=t.replace(".P",""),r="https://fapi.binance.com/fapi/v1",n="Perpetual"):t.includes("_")&&(i="futures",s=t,r="https://dapi.binance.com/dapi/v1",n="Delivery");const a=i==="crypto"?`${r}/exchangeInfo?symbol=${s}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const h=(await o.json()).symbols;if(!h||h.length===0)return console.error(`Symbol ${t} not found`),null;const u=i==="futures"?h.find(k=>k.symbol===s):h[0];if(!u)return console.error(`Symbol ${s} not found in exchange info`),null;const l=u.filters?.find(k=>k.filterType==="PRICE_FILTER"),f=u.filters?.find(k=>k.filterType==="LOT_SIZE"),g=l?parseFloat(l.tickSize):.01,p=f?parseFloat(f.minQty):0,x=Math.round(1/g),y=u.baseAsset,w=u.quoteAsset,E=n?` ${n}`:"",A=`${y} / ${w}${E}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:y,description:A,type:i,main_tickerid:`BINANCE:${t}`,current_contract:n,isin:"",basecurrency:y,currency:w,timezone:"Etc/UTC",country:"",mintick:g,pricescale:x,minmove:1,pointvalue:u.contractSize||1,mincontract:p,session:"24x7",volumetype:"base",expiration_date:u.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in binance.exchangeInfo:",i),null}}}class Nc{async getMarketData(){return[]}}const Cc=typeof process<"u"&&process.versions&&process.versions.node;let yt=null;if(Cc)try{yt=new Nc}catch{yt=null}const kc={Binance:new Ec,...yt?{Mock:yt}:{}};Ce.Context=Kt,Ce.PineTS=zt,Ce.Provider=kc,Object.defineProperty(Ce,"__esModule",{value:!0})});
|
|
117
117
|
;var PineTS = PineTSLib.PineTS;PineTS.Provider = PineTSLib.Provider;PineTS.Context = PineTSLib.Context;//# sourceMappingURL=pinets.min.browser.js.map
|