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.
@@ -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 fr(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 ln(e,t={}){const i=fr(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 Us(e).tokenize(),s=new on(r).parse(),n={...t,sourceCode:e},a=new un(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 pn(e){if(typeof e=="function")return e.toString();{const t=fr(e);if(t===null)return e;if(t>=5){const i=ln(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 fn(e,t={debug:!1,ln:!1}){typeof t=="boolean"&&(t={debug:t,ln:!0});const{debug:i}=t;let r=pn(e);r=Cs(r);const s=i?r.split(`
114
114
  `):[],n=ar(r,{ecmaVersion:"latest",sourceType:"module",locations:i});ks(n),Ss(n),_s(n);const a=new xs;Is(n,a);const o=Ps(n,a)||"";Bs(n,a,o,t,s),Ls(n);const h=ls||Ht||void 0,c=Object.assign({},h,{LineComment(f,g){g.write("//"+f.value)}}),l=hr(n,{generator:c,comments:i});return new Function("",`var _r = ${l}
115
115
  ; return _r;`)(this)}function mn(e){return t=>new F(t.array.map(i=>Math.abs(i)),t.type,e)}function dn(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 gn(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 xn(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 yn(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 wn(e){return t=>{t.array.length=0}}function bn(e){return(t,i)=>(t.array.push(...i.array),t)}function vn(e){return t=>new F([...t.array],t.type,e)}function _n(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 c=[];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++,c.push(x))}if(h===0)return NaN;const l=a/h,f=o/h;let g=0;for(const x of c){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 Sn(e){return t=>t.array.every(i=>!isNaN(i)&&i)}function En(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 xe(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 nt(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 Nn(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(!nt(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 Cn(e){return t=>t.array.length>0?t.array[0]:e.NA}function kn(e){return(t,i)=>t.array[i]}function In(e){return(t,i)=>t.array.includes(i)}function An(e){return(t,i)=>t.array.indexOf(i)}function Tn(e){return(t,i,r)=>{if(!nt(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 Pn(e){return(t,i=",")=>t.array.join(i)}function Rn(e){return t=>t.array.length>0?t.array[t.array.length-1]:e.NA}function Dn(e){return(t,i)=>t.array.lastIndexOf(i)}function Mn(e){return(t,i=0)=>[...t.array].sort((r,s)=>s-r)[i]??e.NA}function On(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 Vn(e){return(t,i=0)=>[...t.array].sort((r,s)=>r-s)[i]??e.NA}function Ln(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 Bn(e){return(t,i)=>{const r=t.array;if(r.length===0)return NaN;const s=[];for(const h of r){const c=Number(h);if(isNaN(c)||c===null||c===void 0)return NaN;s.push(c)}s.sort((h,c)=>h-c),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 Fn(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 jn(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 $n(e){return t=>t.array.pop()}function Wn(e){return(t,i)=>{if(!nt(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 qn(e){return t=>e.precision(e.pine.array.max(t)-e.pine.array.min(t))}function Un(e){return(t,i)=>i>=0&&i<t.array.length?t.array.splice(i,1)[0]:e.NA}function Kn(e){return t=>{t.array.reverse()}}function zn(e){return(t,i,r)=>{if(!nt(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 Hn(e){return t=>t.array.shift()}function Gn(e){return t=>t.array.length}function Yn(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 Qn(e){return t=>t.array.some(i=>!isNaN(i)&&i)}var qe=(e=>(e[e.ascending=1]="ascending",e[e.descending=0]="descending",e))(qe||{}),mr=(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))(mr||{}),dr=(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))(dr||{}),gr=(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))(gr||{});const Xn={order:qe,currency:mr,dayofweek:dr,display:gr};function Zn(e){return(t,i=qe.ascending)=>{t.array.sort((r,s)=>{let n=isNaN(r)?1/0:r,a=isNaN(s)?1/0:s;return i===qe.ascending?n-a:a-n})}}function Jn(e){return(t,i=qe.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===qe.ascending?a-o:o-a}),new F(r,W.int,e)}}function ea(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 ta(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 c=a/o-h*h;return c<0?NaN:(!i&&o>1&&(c=c*o/(o-1)),!i&&o===1?0:e.precision(Math.sqrt(c)))}}function ia(e){return t=>e.precision(t.array.reduce((i,r)=>{const s=Number(r);return isNaN(s)?i:i+s},0))}function ra(e){return(t,i)=>{if(!nt(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 sa(e){return(t,i=!0)=>{let r=0,s=0;for(const h of t.array){const c=Number(h);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,s++)}if(s===0)return NaN;const n=r/s;let a=0;for(const h of t.array){const c=Number(h);!isNaN(c)&&c!==null&&c!==void 0&&(a+=(c-n)*(c-n))}const o=i?s:s-1;return o<=0?NaN:e.precision(a/o)}}var na=Object.defineProperty,aa=(e,t,i)=>t in e?na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,R=(e,t,i)=>aa(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=mn(this.context),this._avg=dn(this.context),this._binary_search=gn(this.context),this._binary_search_leftmost=xn(this.context),this._binary_search_rightmost=yn(this.context),this._clear=wn(this.context),this._concat=bn(this.context),this._copy=vn(this.context),this._covariance=_n(this.context),this._every=Sn(this.context),this._fill=Nn(this.context),this._first=Cn(this.context),this._get=kn(this.context),this._includes=In(this.context),this._indexof=An(this.context),this._insert=Tn(this.context),this._join=Pn(this.context),this._last=Rn(this.context),this._lastindexof=Dn(this.context),this._max=Mn(this.context),this._median=On(this.context),this._min=Vn(this.context),this._mode=Ln(this.context),this._percentile_linear_interpolation=Bn(this.context),this._percentile_nearest_rank=Fn(this.context),this._percentrank=jn(this.context),this._pop=$n(this.context),this._push=Wn(this.context),this._range=qn(this.context),this._remove=Un(this.context),this._reverse=Kn(this.context),this._set=zn(this.context),this._shift=Hn(this.context),this._size=Gn(this.context),this._slice=Yn(this.context),this._some=Qn(this.context),this._sort=Zn(this.context),this._sort_indices=Jn(this.context),this._standardize=ea(this.context),this._stdev=ta(this.context),this._sum=ia(this.context),this._unshift=ra(this.context),this._variance=sa(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 oa(e){return(...t)=>new F([...t],En(t),e)}function ha(e){return(t,i)=>new F(Array(t).fill(e.precision(i||0)),xe(i||0),e)}function ca(e){return(t,i=!1)=>new F(Array(t).fill(i),W.bool,e)}function ua(e){return(t,i=NaN)=>new F(Array(t).fill(e.precision(i)),W.float,e)}function la(e){return(t,i=0)=>new F(Array(t).fill(e.precision(i)),W.int,e)}function pa(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 fa(e){return(t,i=0)=>d.from(t).get(i)}class ma{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=oa(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=ha(t),this.new_bool=ca(t),this.new_float=ua(t),this.new_int=la(t),this.new_string=pa(t),this.param=fa(),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 da(e){return t=>{t.map.clear()}}function ga(e){return(t,i)=>t.map.has(i)}function xa(e){return t=>{const i=new xr(e);return i.map=new Map(t.map),i}}function ya(e){return(t,i)=>{const r=t.map.get(i);return r===void 0?NaN:r}}function wa(e){return t=>{const i=Array.from(t.map.keys()),r=xe(i[0]);return new F(i,r,e)}}function ba(e){return(t,i,r)=>{const s=t.map.get(i);return t.map.set(i,r),s===void 0?NaN:s}}function va(e){return(t,i)=>{for(const[r,s]of i.map)t.map.set(r,s)}}function _a(e){return(t,i)=>{const r=t.map.get(i);return t.map.delete(i)?r:NaN}}function Sa(e){return t=>t.map.size}function Ea(e){return t=>{const i=Array.from(t.map.values()),r=xe(i[0]);return new F(i,r,e)}}var Na=Object.defineProperty,Ca=(e,t,i)=>t in e?Na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,me=(e,t,i)=>Ca(e,typeof t!="symbol"?t+"":t,i);class xr{constructor(t){this.context=t,me(this,"map"),me(this,"_clear"),me(this,"_contains"),me(this,"_copy"),me(this,"_get"),me(this,"_keys"),me(this,"_put"),me(this,"_put_all"),me(this,"_remove"),me(this,"_size"),me(this,"_values"),this.map=new Map,this._clear=da(this.context),this._contains=ga(this.context),this._copy=xa(this.context),this._get=ya(this.context),this._keys=wa(this.context),this._put=ba(this.context),this._put_all=va(this.context),this._remove=_a(this.context),this._size=Sa(this.context),this._values=Ea(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 ka(e){return()=>new xr(e)}function Ia(e){return(t,i=0)=>d.from(t).get(i)}class Aa{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=ka(t),this.param=Ia(),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 Ta(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 c=n[h];c instanceof d&&(c=c.get(0)),t.matrix.push([c])}return}const a=t.matrix[0].length,o=i!==void 0?i:a;for(let h=0;h<s;h++){let c=h<n.length?n[h]:NaN;c instanceof d&&(c=c.get(0)),t.matrix[h].splice(o,0,c)}}}function Pa(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 c=r.get(0);Array.isArray(c)?n=c:n=[c]}else n=[r];const a=s>0?t.matrix[0].length:n.length,o=i!==void 0?i:s,h=[];for(let c=0;c<a;c++)if(c<n.length){let l=n[c];l instanceof d&&(l=l.get(0)),h.push(l)}else h.push(NaN);t.matrix.splice(o,0,h)}}function Ra(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 Da(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=xe(s[0]);return new F(s,n,e)}}function Ma(e){return t=>t.matrix.length===0?0:t.matrix[0].length}function Oa(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 Va(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0,s=new L(i,r,NaN,e);return s.matrix=t.matrix.map(n=>[...n]),s}}function La(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 Ba(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;return i!==r?NaN:La(t.matrix)}}function Fa(e){return(t,i)=>{const r=t.matrix.length;if(r===0)return new L(0,0,NaN,e);const s=t.matrix[0].length,n=new L(r,s,NaN,e);if(i instanceof L)for(let a=0;a<r;a++)for(let o=0;o<s;o++){const h=t.matrix[a][o],c=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;n.matrix[a][o]=h-c}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 ja(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 c=(a+Math.sqrt(h))/2,l=(a-Math.sqrt(h))/2;return[c,l]}function $a(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r){const a=xe(t.matrix[0][0]);return new F([],a,e)}const s=ja(t.matrix),n=xe(s[0]);return new F(s,n,e)}}function Wa(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r)return new L(0,0,NaN,e);const s=new L(i,r,0,e);for(let n=0;n<i;n++)s.matrix[n][n]=1;return s}}function qa(e){return t=>{const i=t.matrix.length;return i===0?0:i*t.matrix[0].length}}function Ua(e){return(t,i,r,s,n,a)=>{const o=t.matrix.length;if(o===0)return;const h=t.matrix[0].length,c=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=c;p<l&&!(p>=o);p++)for(let x=f;x<g&&!(x>=h);x++)t.matrix[p][x]=i}}function Ka(e){return(t,i,r)=>{if(!t.matrix[i])return NaN;const s=t.matrix[i][r];return s===void 0?NaN:s}}function za(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 Ha(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r)return new L(i,r,NaN,e);const s=za(t.matrix),n=new L(i,r,NaN,e);return n.matrix=s,n}}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!==i-1&&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(t.matrix[n][s]!==-t.matrix[s][n])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;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 Xa(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 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(s===n){if(t.matrix[s][n]!==1)return!1}else if(t.matrix[s][n]!==0)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;return i===r}}function eo(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 to(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 io(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 ro(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 so(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,c=new L(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];c.matrix[l*n+p][f*a+x]=g*y}}return c}}function no(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 ao(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 oo(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 ho(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 c=t.matrix[o][h];if(!isNaN(c)){const l=(s.get(c)||0)+1;s.set(c,l),l>n?(n=l,a=c):l===n&&c<a&&(a=c)}}return a}}function co(e){return(t,i)=>{const r=t.matrix.length,s=r>0?t.matrix[0].length:0;if(i instanceof L){const n=i.matrix.length,a=n>0?i.matrix[0].length:0;if(s!==n)return new L(0,0,NaN,e);const o=new L(r,a,0,e);for(let h=0;h<r;h++)for(let c=0;c<a;c++){let l=0;for(let f=0;f<s;f++)l+=t.matrix[h][f]*i.matrix[f][c];o.matrix[h][c]=l}return o}else if(i instanceof F||Array.isArray(i.array||i)){const n=i.array||i;if(s!==n.length)return new L(0,0,NaN,e);const a=new L(r,1,0,e);for(let o=0;o<r;o++){let h=0;for(let c=0;c<s;c++)h+=t.matrix[o][c]*n[c];a.matrix[o][0]=h}return a}else{const n=i,a=new L(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 uo(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;return i===r?new L(i,r,NaN,e):new L(r,i,NaN,e)}}function lo(e){return(t,i)=>{const r=t.matrix.length,s=r>0?t.matrix[0].length:0;if(r!==s)return new L(0,0,NaN,e);let n=new L(r,s,0,e);for(let h=0;h<r;h++)n.matrix[h][h]=1;let a=new L(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 L(r,s,NaN,e);for(;o>0;){if(o%2===1){const c=new L(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];c.matrix[l][f]=g}n=c}const h=new L(r,s,0,e);for(let c=0;c<r;c++)for(let l=0;l<s;l++){let f=0;for(let g=0;g<r;g++)f+=a.matrix[c][g]*a.matrix[g][l];h.matrix[c][l]=f}a=h,o=Math.floor(o/2)}return n}}function po(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 c=a;c<r;c++)s[n][c]/=h;for(let c=0;c<i;c++)if(c!==n){const l=s[c][a];for(let f=a;f<r;f++)s[c][f]-=l*s[n][f]}n++}}return n}}function fo(e){return(t,i)=>{const r=t.matrix.length;if(r===0){const a=xe(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=xe(s[0]);return new F(s,n,e)}}function mo(e){return(t,i)=>{const r=t.matrix.splice(i,1),s=xe(r[0][0]);return new F(r[0]||[],s,e)}}function go(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 c=0;for(let l=0;l<i;l++){const f=[];for(let g=0;g<r;g++)f.push(o[c++]);h.push(f)}t.matrix=h}}function xo(e){return t=>{t.matrix.reverse();for(const i of t.matrix)i.reverse()}}function yo(e){return(t,i)=>{if(!t.matrix[i]){const s=xe(t.matrix[0][0]);return new F([],s,e)}const r=xe(t.matrix[i][0]);return new F([...t.matrix[i]],r,e)}}function wo(e){return t=>t.matrix.length}function bo(e){return(t,i,r,s)=>{t.matrix[i]&&(t.matrix[i][r]=s)}}function vo(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 _o(e){return(t,i,r,s,n)=>{const a=r-i,o=n-s,h=new L(a,o,NaN,e);for(let c=0;c<a;c++){const l=i+c;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[c][f]=t.matrix[l][g]}}return h}}function So(e){return(t,i)=>{const r=t.matrix.length;if(r===0)return new L(0,0,NaN,e);const s=t.matrix[0].length,n=new L(r,s,NaN,e);if(i instanceof L)for(let a=0;a<r;a++)for(let o=0;o<s;o++){const h=t.matrix[a][o],c=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;n.matrix[a][o]=h+c}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 Eo(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 No(e){return(t,i,r)=>{const s=t.matrix[i];t.matrix[i]=t.matrix[r],t.matrix[r]=s}}function Co(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 ko(e){return t=>{const i=t.matrix.length;if(i===0)return new L(0,0,NaN,e);const r=t.matrix[0].length,s=new L(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 Io=Object.defineProperty,Ao=(e,t,i)=>t in e?Io(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,I=(e,t,i)=>Ao(e,typeof t!="symbol"?t+"":t,i);class L{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=Ta(this.context),this._add_row=Pa(this.context),this._avg=Ra(this.context),this._col=Da(this.context),this._columns=Ma(this.context),this._concat=Oa(this.context),this._copy=Va(this.context),this._det=Ba(this.context),this._diff=Fa(this.context),this._eigenvalues=$a(this.context),this._eigenvectors=Wa(this.context),this._elements_count=qa(this.context),this._fill=Ua(this.context),this._get=Ka(this.context),this._inv=Ha(this.context),this._is_antidiagonal=Ga(this.context),this._is_antisymmetric=Ya(this.context),this._is_binary=Qa(this.context),this._is_diagonal=Xa(this.context),this._is_identity=Za(this.context),this._is_square=Ja(this.context),this._is_stochastic=eo(this.context),this._is_symmetric=to(this.context),this._is_triangular=io(this.context),this._is_zero=ro(this.context),this._kron=so(this.context),this._max=no(this.context),this._median=ao(this.context),this._min=oo(this.context),this._mode=ho(this.context),this._mult=co(this.context),this._pinv=uo(this.context),this._pow=lo(this.context),this._rank=po(this.context),this._remove_col=fo(this.context),this._remove_row=mo(this.context),this._reshape=go(this.context),this._reverse=xo(this.context),this._row=yo(this.context),this._rows=wo(this.context),this._set=bo(this.context),this._sort=vo(this.context),this._submatrix=_o(this.context),this._sum=So(this.context),this._swap_columns=Eo(this.context),this._swap_rows=No(this.context),this._trace=Co(this.context),this._transpose=ko(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 To(e){return(t,i,r)=>new L(t,i,r,e)}function Po(e){return(t,i=0)=>d.from(t).get(i)}class Ro{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=To(t),this.param=Po(),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 Do=Object.defineProperty,Mo=(e,t,i)=>t in e?Do(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Oo=(e,t,i)=>Mo(e,typeof t!="symbol"?t+"":t,i);class Vo{constructor(t){this.context=t,Oo(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 wi={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 Qt(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(wi.remaining_options(o)){s=o;break}const h=t.map((c,l)=>n[l]?c[a]:void 0);for(let c=0;c<h.length;c++){const l=h[c];if(l===void 0){n[c]=!1;continue}const f=wi[i[l]];typeof f=="function"&&f(o)?r[l]=o:n[c]=!1}}return{...s,...r}}var Lo=Object.defineProperty,Bo=(e,t,i)=>t in e?Lo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Fo=(e,t,i)=>Bo(e,typeof t!="symbol"?t+"":t,i);const jo=["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"],$o={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 Wo(e){return Qt(e,jo,$o)}class qo{constructor(t){this.context=t,Fo(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=Wo(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 Uo=[["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"]],Ko={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 Qt(e,Uo,Ko)}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)=>re(t).defval}function Qo(e){return(...t)=>re(t).defval}function Xo(e){return(...t)=>re(t).defval}function Zo(e){return(t,i=0)=>d.from(t).get(i)}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}function sh(e){return(...t)=>re(t).defval}function nh(e){return(...t)=>re(t).defval}function ah(e){return(...t)=>re(t).defval}var oh=Object.defineProperty,hh=(e,t,i)=>t in e?oh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t,i)=>hh(e,typeof t!="symbol"?t+"":t,i);const ch={any:zo,bool:Ho,color:Go,enum:Yo,float:Qo,int:Xo,param:Zo,price:Jo,session:eh,source:th,string:ih,symbol:rh,text_area:sh,time:nh,timeframe:ah};class uh{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(ch).forEach(([i,r])=>{this[i]=r(t)})}}function lh(e){return t=>Math.abs(d.from(t).get(0))}function ph(e){return t=>Math.acos(d.from(t).get(0))}function fh(e){return t=>Math.asin(d.from(t).get(0))}function mh(e){return t=>Math.atan(d.from(t).get(0))}function dh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return i.reduce((r,s)=>r+s,0)/i.length}}function gh(e){return t=>Math.ceil(d.from(t).get(0))}function xh(e){return t=>Math.cos(d.from(t).get(0))}function yh(e){return()=>Math.E}function wh(e){return t=>Math.exp(d.from(t).get(0))}function bh(e){return t=>Math.floor(d.from(t).get(0))}function vh(e){return t=>Math.log(d.from(t).get(0))}function _h(e){return t=>Math.log(d.from(t).get(0))}function Sh(e){return t=>Math.log10(d.from(t).get(0))}function Eh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.max(...i)}}function Nh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.min(...i)}}function Ch(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 kh(e){return()=>1.618033988749895}function Ih(e){return()=>Math.PI}function Ah(e){return(t,i)=>Math.pow(d.from(t).get(0),d.from(i).get(0))}function Th(e){return()=>Math.random()}function Ph(e){return t=>Math.round(d.from(t).get(0))}function Rh(e){return t=>e.precision(Math.round(d.from(t).get(0)/e.pine.syminfo.mintick)*e.pine.syminfo.mintick)}function Dh(e){return()=>.6180339887498948}function Mh(e){return t=>Math.sign(d.from(t).get(0))}function Oh(e){return t=>Math.sin(d.from(t).get(0))}function Vh(e){return t=>Math.sqrt(d.from(t).get(0))}function Lh(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 Bh(e){return t=>Math.tan(d.from(t).get(0))}function Fh(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 jh=Object.defineProperty,$h=(e,t,i)=>t in e?jh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,V=(e,t,i)=>$h(e,typeof t!="symbol"?t+"":t,i);const Wh={abs:lh,acos:ph,asin:fh,atan:mh,avg:dh,ceil:gh,cos:xh,e:yh,exp:wh,floor:bh,ln:vh,log:_h,log10:Sh,max:Eh,min:Nh,param:Ch,phi:kh,pi:Ih,pow:Ah,random:Th,round:Ph,round_to_mintick:Rh,rphi:Dh,sign:Mh,sin:Oh,sqrt:Vh,sum:Lh,tan:Bh,__eq:Fh};class qh{constructor(t){this.context=t,V(this,"_cache",{}),V(this,"abs"),V(this,"acos"),V(this,"asin"),V(this,"atan"),V(this,"avg"),V(this,"ceil"),V(this,"cos"),V(this,"e"),V(this,"exp"),V(this,"floor"),V(this,"ln"),V(this,"log"),V(this,"log10"),V(this,"max"),V(this,"min"),V(this,"param"),V(this,"phi"),V(this,"pi"),V(this,"pow"),V(this,"random"),V(this,"round"),V(this,"round_to_mintick"),V(this,"rphi"),V(this,"sign"),V(this,"sin"),V(this,"sqrt"),V(this,"sum"),V(this,"tan"),V(this,"__eq"),Object.entries(Wh).forEach(([i,r])=>{this[i]=r(t)})}}function Uh(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 mt=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function bi(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 vi(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 c=0;c<i.length;c++){if(i[c]>=e&&i[c]<t)return c;if(i[c]>=t)break}if(h&&s&&!a)for(let c=0;c<i.length;c++){if(i[c]>=e&&i[c]<t)return c;if(i[c]>=t)break}return o}if(r[o]<e)break}return-1}function Kh(e){return async(t,i,r,s=!1,n=!1,a=!1,o=null,h=null)=>{const c=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=mt.indexOf(e.timeframe),w=mt.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),P=`${c}_${l}_${g}`,C=`${P}_prevIdx`;if(e.cache[P]){const Ye=e.cache[P],at=E?vi(A,k,Ye.data.openTime.data,Ye.data.closeTime.data,x,e.eDate,p):bi(A,k,Ye.data.openTime.data,Ye.data.closeTime.data,x);if(at==-1)return NaN;const Be=Ye.params[g][at];if(!E&&p){const Xt=e.cache[C];return Xt!==void 0&&Xt===at?NaN:(e.cache[C]=at,Array.isArray(Be)?[Be]:Be)}return Array.isArray(Be)?[Be]:Be}const Q=1e3*60*60*24*30,G=e.sDate?e.sDate-Q:void 0,z=e.sDate&&e.eDate?void 0:e.limit||1e3,Ge=new wr(e.source,c,l,z,G,void 0);Ge.markAsSecondary();const Ce=await Ge.run(e.pineTSCode);e.cache[P]=Ce;const bt=E?vi(A,k,Ce.data.openTime.data,Ce.data.closeTime.data,x,e.eDate,p):bi(A,k,Ce.data.openTime.data,Ce.data.closeTime.data,x);if(bt==-1)return NaN;const vt=Ce.params[g][bt];return!E&&p?(e.cache[C]=bt,NaN):Array.isArray(vt)?[vt]:vt}}function zh(e){return async(t,i,r,s=!1,n=null,a=!1,o=0)=>{const h=t[0],c=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=mt.indexOf(e.timeframe),x=mt.indexOf(c);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 ${c} is not lower than or equal to chart timeframe ${e.timeframe}`)}if(x===p)return[[l]];const y=`${h}_${c}_${f}_lower`;if(!e.cache[y]){const G=e.sDate?e.sDate-2592e6:void 0,z=e.sDate&&e.eDate?void 0:e.limit||1e3,Ge=new wr(e.source,h,c,z,G,e.eDate);Ge.markAsSecondary();const Ce=await Ge.run(e.pineTSCode);e.cache[y]=Ce}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,P=w.data.closeTime.data,C=w.params[f];if(!C)return[];const Q=[];for(let G=0;G<k.length;G++){const z=k[G];if(!(P[G]<=E)){if(z>=A)break;z>=E&&z<A&&Q.push(C[G])}}return[Q]}}var Hh=Object.defineProperty,Gh=(e,t,i)=>t in e?Hh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ct=(e,t,i)=>Gh(e,typeof t!="symbol"?t+"":t,i);const Yh={param:Uh,security:Kh,security_lower_tf:zh};class Qh{constructor(t){this.context=t,ct(this,"_cache",{}),ct(this,"param"),ct(this,"security"),ct(this,"security_lower_tf"),Object.entries(Yh).forEach(([i,r])=>{this[i]=r(t)})}}function Xh(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 c=0;return h!==0&&(c=(s-a-(n-s))/h*o),r.cumulativeSum+=c,e.precision(r.cumulativeSum)}}function Zh(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 c=n||`alma_${a}_${o}_${h}`;if(!e.taState[c]){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[c]={window:[],weights:y}}const l=e.taState[c],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 Jh(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 c;if(n.prevClose!==null){const f=a-o,g=Math.abs(a-n.prevClose),p=Math.abs(o-n.prevClose);c=Math.max(f,g,p)}else c=a-o;if(n.prevClose=h,n.initCount<r)return n.initSum+=c,n.initCount++,n.initCount===r?(n.prevAtr=n.initSum/r,e.precision(n.prevAtr)):NaN;const l=(n.prevAtr*(r-1)+c)/r;return n.prevAtr=l,e.precision(l)}}function ec(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 tc(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],c=d.from(t).get(0);if(isNaN(c))return[[NaN,NaN,NaN]];if(h.window.unshift(c),h.sum+=c,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 ic(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],c=d.from(t).get(0);if(isNaN(c))return NaN;if(h.window.unshift(c),h.sum+=c,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 rc(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 c=0;for(let g=0;g<s;g++)c+=Math.abs(a.window[g]-h);const l=c/s;if(l===0)return 0;const f=(o-h)/(.015*l);return e.precision(f)}}function sc(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 nc(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 c=o-h,l=c>=0?c:0,f=c>=0?0:-c;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 ac(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 c=-h/a;return e.precision(c)}}function oc(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,c=0,l=0,f=0,g=0,p=0;for(let A=0;A<n;A++){const k=a.get(A),P=o.get(A);isNaN(k)||isNaN(P)||(h+=k,c+=P,l+=k*P,f+=k*k,g+=P*P,p++)}if(p<2)return NaN;const x=p*l-h*c,y=p*f-h*h,w=p*g-c*c;if(y<=0||w<=0)return e.precision(0);const E=x/Math.sqrt(y*w);return e.precision(E)}}function hc(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),c=n.get(1);if(isNaN(a)||isNaN(o)||isNaN(h)||isNaN(c))return!1;const l=a>o&&h<=c,f=a<o&&h>=c;return l||f}}function cc(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 uc(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 lc(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 pc(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 c=0;for(let f=0;f<s;f++)c+=Math.abs(a.window[f]-h);const l=c/s;return e.precision(l)}}function fc(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),c=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(c)||isNaN(l))return[[NaN,NaN,NaN]];if(isNaN(o.prevHigh))return o.prevHigh=h,o.prevLow=c,o.prevClose=l,[[NaN,NaN,NaN]];const f=Math.max(h-c,Math.abs(h-o.prevClose),Math.abs(c-o.prevClose)),g=h-o.prevHigh,p=o.prevLow-c,x=g>p&&g>0?g:0,y=p>g&&p>0?p:0;o.prevHigh=h,o.prevLow=c,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 z=1/s;o.prevSmoothedTR=z*f+(1-z)*o.prevSmoothedTR,o.prevSmoothedPlus=z*x+(1-z)*o.prevSmoothedPlus,o.prevSmoothedMinus=z*y+(1-z)*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,P=w===0?0:100*A/w,C=k+P,Q=C===0?0:100*Math.abs(k-P)/C;let G=NaN;if(o.adxInitCount++,o.adxInitCount<=n)o.dxInitSum+=Q,o.adxInitCount===n&&(o.prevADX=o.dxInitSum/n,G=o.prevADX);else{const z=1/n;o.prevADX=z*Q+(1-z)*o.prevADX,G=o.prevADX}return[[e.precision(k),e.precision(P),e.precision(G)]]}}function mc(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),c=o*h+a.prevEma*(1-h);return a.prevEma=c,e.precision(c)}}function dc(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 gc(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(c=>!isNaN(c)));return e.precision(h)}}function xc(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 c=n.get(h);isNaN(c)||(isNaN(o)||c>a)&&(a=c,o=-h)}return o}}function yc(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),c=o(t,s,r?`${r}_wma2`:void 0);if(isNaN(h)||isNaN(c))return NaN;e.taState||(e.taState={});const l=r||`hma_raw_${s}`;e.taState[l]||(e.taState[l]=[]);const f=2*h-c;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 wc(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 bc(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 c;const l=e.get(e.data.high,0),f=e.get(e.data.low,0);if(h){const P=e.get(e.data.close,1);isNaN(P)?c=NaN:c=Math.max(l-f,Math.abs(l-P),Math.abs(f-P))}else c=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=(P,C,Q)=>{if(isNaN(C))return NaN;if(P.initCount<Q)return P.initSum+=C,P.initCount++,P.initCount===Q?(P.prevEma=P.initSum/Q,P.prevEma):NaN;const G=2/(Q+1);return P.prevEma=C*G+P.prevEma*(1-G),P.prevEma},w=y(x.basisState,g,a),E=y(x.rangeState,c,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 vc(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 c=n||`kcw_${a}_${o}_${h}`;e.taState[c]||(e.taState[c]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const l=e.taState[c],f=(k,P,C)=>{if(isNaN(P))return NaN;if(k.initCount<C)return k.initSum+=P,k.initCount++,k.initCount===C?(k.prevEma=k.initSum/C,k.prevEma):NaN;const Q=2/(C+1);return k.prevEma=P*Q+k.prevEma*(1-Q),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 _c(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],c=d.from(t).get(0);if(h.window.unshift(c),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,P=h.window[A];l+=k,f+=P,g+=k*P,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 Sc(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),c=h.length>0?Math.min(...h):NaN;return e.precision(c)}}function Ec(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 c=n.get(h);isNaN(c)||(isNaN(o)||c<a)&&(a=c,o=-h)}return o}}function Nc(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),c=n||`macd_${a}_${o}_${h}`,l=`${c}_fast`,f=`${c}_slow`,g=`${c}_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 Cc(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),c=Math.floor(s/2),l=s%2===0?(h[c-1]+h[c])/2:h[c];return e.precision(l)}}function kc(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),c=e.get(e.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;const l=isNaN(h)?NaN:o-h;let f=0,g=0;if(f=c*(l<=0?0:o),g=c*(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 Ic(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 c=0;c<s;c++){const l=n.get(c);isNaN(l)||a.set(l,(a.get(l)||0)+1)}if(a.size===0)return NaN;let o=NaN,h=-1;for(const[c,l]of a.entries())l>h?(h=l,o=c):l===h&&c<o&&(o=c);return o}}function Ac(e){return(t,i,r)=>{const s=d.from(i).get(0);return e.ta.change(t,s)}}function Tc(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,c=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||c===0)&&l<f){const g=(h-c)/c;r.nvi=r.nvi+g*r.nvi}return e.precision(r.nvi)}}function Pc(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 Rc(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 Dc(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 c=a/100*n-.5;c<0&&(c=0),c>n-1&&(c=n-1);const l=Math.floor(c),f=Math.ceil(c);if(l===f)return e.precision(h[l]);const g=c-l,p=h[l]+g*(h[f]-h[l]);return e.precision(p)}}function Mc(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 c=Math.ceil(a/100*h.length)-1;return c<0&&(c=0),c>=h.length&&(c=h.length-1),e.precision(h[c])}}function Oc(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 c=1;c<=s;c++){const l=n.get(c);isNaN(l)||(h++,l<=a&&o++)}return h===0?NaN:e.precision(o/h*100)}}function Vc(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 Lc(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=Vc(o,n,a),c=e.idx;return e.precision(h[c])}}function Bc(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 Fc(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=Bc(o,n,a),c=e.idx;return e.precision(h[c])}}function jc(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,c=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||c===0)&&l>f){const g=(h-c)/c;r.pvi=r.pvi+g*r.pvi}return e.precision(r.pvi)}}function $c(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 Wc(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 qc(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 Uc(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,c=o*h+a.prevRma*(1-h);return a.prevRma=c,e.precision(c)}}function Kc(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],c=(o-h)/h*100;return e.precision(c)}}function zc(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,c=h>0?h:0,l=h<0?-h:0;if(a.initGains.length<s){if(a.initGains.push(c),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)+c)/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 Hc(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 c=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 c.barIndex===1&&(g>p?(c.isBelow=!0,c.maxMin=l,c.result=y):(c.isBelow=!1,c.maxMin=f,c.result=x),A=!0,c.acceleration=n),c.barIndex>=1&&(c.result=c.result+c.acceleration*(c.maxMin-c.result),c.isBelow?c.result>f&&(A=!0,c.isBelow=!1,c.result=Math.max(l,c.maxMin),c.maxMin=f,c.acceleration=n):c.result<l&&(A=!0,c.isBelow=!0,c.result=Math.min(f,c.maxMin),c.maxMin=l,c.acceleration=n),A||(c.isBelow?l>c.maxMin&&(c.maxMin=l,c.acceleration=Math.min(c.acceleration+a,o)):f<c.maxMin&&(c.maxMin=f,c.acceleration=Math.min(c.acceleration+a,o))),c.isBelow?(c.result=Math.min(c.result,y),c.barIndex>1&&(c.result=Math.min(c.result,E))):(c.result=Math.max(c.result,x),c.barIndex>1&&(c.result=Math.max(c.result,w)))),c.barIndex++,c.barIndex<=1?NaN:e.precision(c.result)}}function Gc(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 c=a.window.pop();a.sum-=c}const h=a.sum/s;return e.precision(h)}}function Yc(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],c=d.from(t).get(0);if(h.window.unshift(c),h.sum+=c,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 Qc(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],c=d.from(t).get(0),l=d.from(i).get(0),f=d.from(r).get(0);if(isNaN(c)||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*(c-p)/x;return e.precision(y)}}function Xc(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),c=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(c)||isNaN(l))return[[NaN,NaN]];const f=(h+c)/2;let g;isNaN(o.prevClose)?g=h-c:g=Math.max(h-c,Math.abs(h-o.prevClose),Math.abs(c-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,P;const C=o.prevSuperTrend;return o.atrCount===n?k=1:C===o.prevUpperBand?k=l>y?-1:1:k=l<w?1:-1,P=k===-1?w:y,o.prevLowerBand=w,o.prevUpperBand=y,o.prevSuperTrend=P,o.prevDirection=k,[[e.precision(P),k]]}}function Zc(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 c=0;c<4;c++)h+=r[c]*a.window[3-c];return h/=s,e.precision(h)}}function Jc(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 eu(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],c=d.from(t).get(0);if(isNaN(c))return NaN;const l=isNaN(h.prevSource)?NaN:c-h.prevSource;if(h.prevSource=c,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 tu(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),c=d.from(r).get(0);if(o&&a.values.push(h),isNaN(c)||c<0)return NaN;const l=a.values.length-1-c;if(l<0)return NaN;const f=a.values[l];return typeof f=="number"?e.precision(f):f}}function iu(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,c=0;for(let g=0;g<s;g++)h+=a.window[g],c+=a.window[g]*a.window[g];const l=h/s,f=c/s-l*l;return e.precision(f)}}function ru(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 c=s.cumulativePV/s.cumulativeVolume;return e.precision(c)}}function su(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 c=0,l=0;for(let g=0;g<s;g++)c+=a.window[g]*a.volumeWindow[g],l+=a.volumeWindow[g];const f=c/l;return e.precision(f)}}function nu(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 c=Math.max(n,o),l=Math.min(a,o),f=s-o;f>0?h=s-l:f<0&&(h=s-c)}return r.cumulativeSum+=h,e.precision(r.cumulativeSum)}}function au(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,c=0;for(let f=0;f<s;f++){const g=s-f;h+=a.window[f]*g,c+=g}const l=h/c;return e.precision(l)}}function ou(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 c=n.highWindow[0],l=n.lowWindow[0];for(let p=1;p<r;p++)n.highWindow[p]>c&&(c=n.highWindow[p]),n.lowWindow[p]<l&&(l=n.lowWindow[p]);const f=c-l;if(f===0)return e.precision(0);const g=(c-h)/f*-100;return e.precision(g)}}function hu(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 cu=Object.defineProperty,uu=(e,t,i)=>t in e?cu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,_=(e,t,i)=>uu(e,typeof t!="symbol"?t+"":t,i);const lu={accdist:Xh,alma:Zh,atr:Jh,barssince:ec,bb:tc,bbw:ic,cci:rc,change:sc,cmo:nc,cog:ac,correlation:oc,cross:hc,crossover:cc,crossunder:uc,cum:lc,dev:pc,dmi:fc,ema:mc,falling:dc,highest:gc,highestbars:xc,hma:yc,iii:wc,kc:bc,kcw:vc,linreg:_c,lowest:Sc,lowestbars:Ec,macd:Nc,median:Cc,mfi:kc,mode:Ic,mom:Ac,nvi:Tc,obv:Pc,param:Rc,percentile_linear_interpolation:Dc,percentile_nearest_rank:Mc,percentrank:Oc,pivothigh:Lc,pivotlow:Fc,pvi:jc,pvt:$c,range:Wc,rising:qc,rma:Uc,roc:Kc,rsi:zc,sar:Hc,sma:Gc,stdev:Yc,stoch:Qc,supertrend:Xc,swma:Zc,tr:Jc,tsi:eu,valuewhen:tu,variance:iu,vwap:ru,vwma:su,wad:nu,wma:au,wpr:ou,wvad:hu};class pu{constructor(t){this.context=t,_(this,"accdist"),_(this,"alma"),_(this,"atr"),_(this,"barssince"),_(this,"bb"),_(this,"bbw"),_(this,"cci"),_(this,"change"),_(this,"cmo"),_(this,"cog"),_(this,"correlation"),_(this,"cross"),_(this,"crossover"),_(this,"crossunder"),_(this,"cum"),_(this,"dev"),_(this,"dmi"),_(this,"ema"),_(this,"falling"),_(this,"highest"),_(this,"highestbars"),_(this,"hma"),_(this,"iii"),_(this,"kc"),_(this,"kcw"),_(this,"linreg"),_(this,"lowest"),_(this,"lowestbars"),_(this,"macd"),_(this,"median"),_(this,"mfi"),_(this,"mode"),_(this,"mom"),_(this,"nvi"),_(this,"obv"),_(this,"param"),_(this,"percentile_linear_interpolation"),_(this,"percentile_nearest_rank"),_(this,"percentrank"),_(this,"pivothigh"),_(this,"pivotlow"),_(this,"pvi"),_(this,"pvt"),_(this,"range"),_(this,"rising"),_(this,"rma"),_(this,"roc"),_(this,"rsi"),_(this,"sar"),_(this,"sma"),_(this,"stdev"),_(this,"stoch"),_(this,"supertrend"),_(this,"swma"),_(this,"tr"),_(this,"tsi"),_(this,"valuewhen"),_(this,"variance"),_(this,"vwap"),_(this,"vwma"),_(this,"wad"),_(this,"wma"),_(this,"wpr"),_(this,"wvad"),Object.entries(lu).forEach(([i,r])=>{this[i]=r(t)})}}class fu{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 mu{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 c=0,l=0;for(;;){const f=n.indexOf(a,c);if(f===-1)return n;if(l===h)return n.substring(0,f)+o+n.substring(f+a.length);l++,c=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 du{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 gu=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],xu={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 yu{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=Qt(t,gu,xu),{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 wu{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 bu=Object.defineProperty,vu=(e,t,i)=>t in e?bu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,j=(e,t,i)=>vu(e,typeof t!="symbol"?t+"":t,i);const yr=class Lt{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 c=new qo(this),l={na:c.na.bind(c),color:c.color,nz:c.nz.bind(c),indicator:c.indicator.bind(c),fixnan:c.fixnan.bind(c),alertcondition:c.alertcondition.bind(c),bool:c.bool.bind(c)},f=this;this.pine={input:new uh(this),ta:new pu(this),math:new qh(this),request:new Qh(this),array:new ma(this),map:new Aa(this),matrix:new Ro(this),syminfo:null,timeframe:new du(this),barstate:new Vo(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 fu(this),str:new mu(this),...l,...Xn};const g=new yu(this),p=new wu(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}`;Lt._deprecationWarningsShown.has(r)||(Lt._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(yr,"_deprecationWarningsShown",new Set);let _i=yr;var _u=Object.defineProperty,Su=(e,t,i)=>t in e?_u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,K=(e,t,i)=>Su(e,typeof t!="symbol"?t+"":t,i);class wr{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 c=h;this.data=c;const l=c.map(C=>C.open),f=c.map(C=>C.close),g=c.map(C=>C.high),p=c.map(C=>C.low),x=c.map(C=>C.volume),y=c.map(C=>(C.high+C.low+C.close)/3),w=c.map(C=>(C.high+C.low)/2),E=c.map(C=>(C.high+C.low+C.open+C.close)/4),A=c.map(C=>(C.high+C.low+C.close+C.close)/4),k=c.map(C=>C.openTime),P=c.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=P,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:c}=await this._updateMarketData();if(h===0&&!c){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 _i({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 c=n[h];c.openTime===s?(this._replaceCandle(r,c),a=!0):c.openTime>s&&(this._appendCandle(c),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 _i({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 fn.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 c;o[h]instanceof d?c=o[h].get(0):Array.isArray(o[h])?c=o[h][o[h].length-1]:c=o[h],t.result[h].push(c)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(o);for(let h of n)for(let c in t[h]){const l=t[h][c];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 Eu=Object.defineProperty,Nu=(e,t,i)=>t in e?Eu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Bt=(e,t,i)=>Nu(e,typeof t!="symbol"?t+"":t,i);const Si="https://api.binance.com/api/v3",kt={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 Cu{constructor(t=5*60*1e3){Bt(this,"cache"),Bt(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 ku{constructor(){Bt(this,"cacheManager"),this.cacheManager=new Cu(5*60*1e3)}async getMarketDataInterval(t,i,r,s){try{const n=kt[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 c=s,l=a[n];if(!l)return console.error(`Duration not defined for interval: ${n}`),[];for(;h<c;){const f=Math.min(h+1e3*l,c),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=kt[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 c=`${Si}/klines?symbol=${t}&interval=${h}`;r&&(c+=`&limit=${Math.min(r,1e3)}`),s&&(c+=`&startTime=${s}`),n&&(c+=`&endTime=${n}`);const l=await fetch(c);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=kt[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=Si,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 c=i==="futures"?h.find(k=>k.symbol===s):h[0];if(!c)return console.error(`Symbol ${s} not found in exchange info`),null;const l=c.filters?.find(k=>k.filterType==="PRICE_FILTER"),f=c.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=c.baseAsset,w=c.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:c.contractSize||1,mincontract:p,session:"24x7",volumetype:"base",expiration_date:c.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}}}var Iu=Object.defineProperty,Au=(e,t,i)=>t in e?Iu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,It=(e,t,i)=>Au(e,typeof t!="symbol"?t+"":t,i);const Tu=br(import.meta.url),Pu=Xe.dirname(Tu);class Ru{constructor(t){if(It(this,"dataCache",new Map),It(this,"exchangeInfoCache",{}),It(this,"dataDirectory"),t)this.dataDirectory=t;else{const i=Xe.resolve(Pu,"../../../");this.dataDirectory=Xe.join(i,"tests","compatibility","_data")}}getDataFileName(t,i,r,s){return r&&s?`${t}-${i}-${r}-${s}.json`:null}loadDataFromFile(t){const i=`file:${t}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=Xe.join(this.dataDirectory,t);if(!Fe.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const s=Fe.readFileSync(r,"utf-8"),n=JSON.parse(s);return this.dataCache.set(i,n),n}findDataFile(t,i,r,s){if(!Fe.existsSync(this.dataDirectory))return null;const n=Fe.readdirSync(this.dataDirectory).filter(h=>h.endsWith(".json"));if(r&&s){const h=`${t}-${i}-${r}-${s}.json`;if(n.includes(h))return h}const a=new RegExp(`^${t}-${i}-(\\d+)-(\\d+)\\.json$`),o=n.filter(h=>a.test(h)).map(h=>{const c=h.match(a);return{file:h,startTime:parseInt(c[1]),endTime:parseInt(c[2])}}).sort((h,c)=>c.endTime-h.endTime);if(o.length===0)return null;if(r&&s){const h=o.find(c=>c.startTime<=r&&c.endTime>=s);if(h)return h.file}return o[0].file}filterData(t,i,r,s){let n=t;return(i||r)&&(n=t.filter(a=>{const o=!i||a.openTime>=i,h=!r||a.openTime<=r;return o&&h})),n.sort((a,o)=>a.openTime-o.openTime),s&&s>0&&(n=n.slice(0,s)),n}normalizeTimeframe(t){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[t.toUpperCase()]||t.toLowerCase()}async getMarketData(t,i,r,s,n){try{const a=this.normalizeTimeframe(i),o=this.findDataFile(t,a,s,n);if(!o)return console.warn(`No mock data file found for ${t} ${a}. Searched in: ${this.dataDirectory}`),[];const h=this.loadDataFromFile(o);return this.filterData(h,s,n,r)}catch(a){return console.error("Error in MockProvider.getMarketData:",a),[]}}loadExchangeInfo(t){if(this.exchangeInfoCache[t])return this.exchangeInfoCache[t];const i=t==="spot"?"api-exchangeInfo.json":"fapi-exchangeInfo.json",r=Xe.join(this.dataDirectory,i);if(!Fe.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const s=Fe.readFileSync(r,"utf-8"),n=JSON.parse(s);return this.exchangeInfoCache[t]=n,n}catch(s){return console.error(`Error loading exchange info from ${i}:`,s),null}}async getSymbolInfo(t){try{let i="crypto",r=t,s="";t.endsWith(".P")?(i="futures",r=t.replace(".P",""),s="Perpetual"):t.includes("_")&&(i="futures",r=t,s="Delivery");const n=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!n||!n.symbols)return console.error(`Exchange info not available for ${i}`),null;const a=n.symbols.find(w=>w.symbol===r);if(!a)return console.error(`Symbol ${r} not found in ${i} exchange info`),null;const o=a.filters?.find(w=>w.filterType==="PRICE_FILTER"),h=a.filters?.find(w=>w.filterType==="LOT_SIZE"),c=o?parseFloat(o.tickSize):.01,l=h?parseFloat(h.minQty):0,f=Math.round(1/c),g=a.baseAsset,p=a.quoteAsset,x=s?` ${s}`:"",y=`${g} / ${p}${x}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:g,description:y,type:i,main_tickerid:`BINANCE:${t}`,current_contract:s,isin:"",basecurrency:g,currency:p,timezone:"Etc/UTC",country:"",mintick:c,pricescale:f,minmove:1,pointvalue:a.contractSize||1,mincontract:l,session:"24x7",volumetype:"base",expiration_date:a.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in MockProvider.getSymbolInfo:",i),null}}clearCache(){this.dataCache.clear(),this.exchangeInfoCache={}}setDataDirectory(t){this.dataDirectory=t,this.clearCache()}}const Du=typeof process<"u"&&process.versions&&process.versions.node;let dt=null;if(Du)try{dt=new Ru}catch{dt=null}const Ou={Binance:new ku,...dt?{Mock:dt}:{}};export{_i as Context,wr as PineTS,Ou as Provider};
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 To(e){return(t,i,r)=>new L(t,i,r,e)}function Po(e){return(t,i=0)=>d.from(t).get(i)}class Ro{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=To(t),this.param=Po(),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 Do=Object.defineProperty,Mo=(e,t,i)=>t in e?Do(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Oo=(e,t,i)=>Mo(e,typeof t!="symbol"?t+"":t,i);class Vo{constructor(t){this.context=t,Oo(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 wi={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 Qt(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(wi.remaining_options(o)){s=o;break}const h=t.map((c,l)=>n[l]?c[a]:void 0);for(let c=0;c<h.length;c++){const l=h[c];if(l===void 0){n[c]=!1;continue}const f=wi[i[l]];typeof f=="function"&&f(o)?r[l]=o:n[c]=!1}}return{...s,...r}}var Lo=Object.defineProperty,Bo=(e,t,i)=>t in e?Lo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Fo=(e,t,i)=>Bo(e,typeof t!="symbol"?t+"":t,i);const jo=["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"],$o={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 Wo(e){return Qt(e,jo,$o)}class qo{constructor(t){this.context=t,Fo(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=Wo(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 Uo=[["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"]],Ko={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 Qt(e,Uo,Ko)}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)=>re(t).defval}function Qo(e){return(...t)=>re(t).defval}function Xo(e){return(...t)=>re(t).defval}function Zo(e){return(t,i=0)=>d.from(t).get(i)}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}function sh(e){return(...t)=>re(t).defval}function nh(e){return(...t)=>re(t).defval}function ah(e){return(...t)=>re(t).defval}var oh=Object.defineProperty,hh=(e,t,i)=>t in e?oh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t,i)=>hh(e,typeof t!="symbol"?t+"":t,i);const ch={any:zo,bool:Ho,color:Go,enum:Yo,float:Qo,int:Xo,param:Zo,price:Jo,session:eh,source:th,string:ih,symbol:rh,text_area:sh,time:nh,timeframe:ah};class uh{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(ch).forEach(([i,r])=>{this[i]=r(t)})}}function lh(e){return t=>Math.abs(d.from(t).get(0))}function ph(e){return t=>Math.acos(d.from(t).get(0))}function fh(e){return t=>Math.asin(d.from(t).get(0))}function mh(e){return t=>Math.atan(d.from(t).get(0))}function dh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return i.reduce((r,s)=>r+s,0)/i.length}}function gh(e){return t=>Math.ceil(d.from(t).get(0))}function xh(e){return t=>Math.cos(d.from(t).get(0))}function yh(e){return()=>Math.E}function wh(e){return t=>Math.exp(d.from(t).get(0))}function bh(e){return t=>Math.floor(d.from(t).get(0))}function vh(e){return t=>Math.log(d.from(t).get(0))}function _h(e){return t=>Math.log(d.from(t).get(0))}function Sh(e){return t=>Math.log10(d.from(t).get(0))}function Eh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.max(...i)}}function Nh(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.min(...i)}}function Ch(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 kh(e){return()=>1.618033988749895}function Ih(e){return()=>Math.PI}function Ah(e){return(t,i)=>Math.pow(d.from(t).get(0),d.from(i).get(0))}function Th(e){return()=>Math.random()}function Ph(e){return t=>Math.round(d.from(t).get(0))}function Rh(e){return t=>e.precision(Math.round(d.from(t).get(0)/e.pine.syminfo.mintick)*e.pine.syminfo.mintick)}function Dh(e){return()=>.6180339887498948}function Mh(e){return t=>Math.sign(d.from(t).get(0))}function Oh(e){return t=>Math.sin(d.from(t).get(0))}function Vh(e){return t=>Math.sqrt(d.from(t).get(0))}function Lh(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 Bh(e){return t=>Math.tan(d.from(t).get(0))}function Fh(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 jh=Object.defineProperty,$h=(e,t,i)=>t in e?jh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,V=(e,t,i)=>$h(e,typeof t!="symbol"?t+"":t,i);const Wh={abs:lh,acos:ph,asin:fh,atan:mh,avg:dh,ceil:gh,cos:xh,e:yh,exp:wh,floor:bh,ln:vh,log:_h,log10:Sh,max:Eh,min:Nh,param:Ch,phi:kh,pi:Ih,pow:Ah,random:Th,round:Ph,round_to_mintick:Rh,rphi:Dh,sign:Mh,sin:Oh,sqrt:Vh,sum:Lh,tan:Bh,__eq:Fh};class qh{constructor(t){this.context=t,V(this,"_cache",{}),V(this,"abs"),V(this,"acos"),V(this,"asin"),V(this,"atan"),V(this,"avg"),V(this,"ceil"),V(this,"cos"),V(this,"e"),V(this,"exp"),V(this,"floor"),V(this,"ln"),V(this,"log"),V(this,"log10"),V(this,"max"),V(this,"min"),V(this,"param"),V(this,"phi"),V(this,"pi"),V(this,"pow"),V(this,"random"),V(this,"round"),V(this,"round_to_mintick"),V(this,"rphi"),V(this,"sign"),V(this,"sin"),V(this,"sqrt"),V(this,"sum"),V(this,"tan"),V(this,"__eq"),Object.entries(Wh).forEach(([i,r])=>{this[i]=r(t)})}}function Uh(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 mt=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function bi(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 vi(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 c=0;c<i.length;c++){if(i[c]>=e&&i[c]<t)return c;if(i[c]>=t)break}if(h&&s&&!a)for(let c=0;c<i.length;c++){if(i[c]>=e&&i[c]<t)return c;if(i[c]>=t)break}return o}if(r[o]<e)break}return-1}function Kh(e){return async(t,i,r,s=!1,n=!1,a=!1,o=null,h=null)=>{const c=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=mt.indexOf(e.timeframe),w=mt.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),P=`${c}_${l}_${g}`,C=`${P}_prevIdx`;if(e.cache[P]){const Ye=e.cache[P],at=E?vi(A,k,Ye.data.openTime.data,Ye.data.closeTime.data,x,e.eDate,p):bi(A,k,Ye.data.openTime.data,Ye.data.closeTime.data,x);if(at==-1)return NaN;const Be=Ye.params[g][at];if(!E&&p){const Xt=e.cache[C];return Xt!==void 0&&Xt===at?NaN:(e.cache[C]=at,Array.isArray(Be)?[Be]:Be)}return Array.isArray(Be)?[Be]:Be}const Q=1e3*60*60*24*30,G=e.sDate?e.sDate-Q:void 0,z=e.sDate&&e.eDate?void 0:e.limit||1e3,Ge=new wr(e.source,c,l,z,G,void 0);Ge.markAsSecondary();const Ce=await Ge.run(e.pineTSCode);e.cache[P]=Ce;const bt=E?vi(A,k,Ce.data.openTime.data,Ce.data.closeTime.data,x,e.eDate,p):bi(A,k,Ce.data.openTime.data,Ce.data.closeTime.data,x);if(bt==-1)return NaN;const vt=Ce.params[g][bt];return!E&&p?(e.cache[C]=bt,NaN):Array.isArray(vt)?[vt]:vt}}function zh(e){return async(t,i,r,s=!1,n=null,a=!1,o=0)=>{const h=t[0],c=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=mt.indexOf(e.timeframe),x=mt.indexOf(c);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 ${c} is not lower than or equal to chart timeframe ${e.timeframe}`)}if(x===p)return[[l]];const y=`${h}_${c}_${f}_lower`;if(!e.cache[y]){const G=e.sDate?e.sDate-2592e6:void 0,z=e.sDate&&e.eDate?void 0:e.limit||1e3,Ge=new wr(e.source,h,c,z,G,e.eDate);Ge.markAsSecondary();const Ce=await Ge.run(e.pineTSCode);e.cache[y]=Ce}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,P=w.data.closeTime.data,C=w.params[f];if(!C)return[];const Q=[];for(let G=0;G<k.length;G++){const z=k[G];if(!(P[G]<=E)){if(z>=A)break;z>=E&&z<A&&Q.push(C[G])}}return[Q]}}var Hh=Object.defineProperty,Gh=(e,t,i)=>t in e?Hh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ct=(e,t,i)=>Gh(e,typeof t!="symbol"?t+"":t,i);const Yh={param:Uh,security:Kh,security_lower_tf:zh};class Qh{constructor(t){this.context=t,ct(this,"_cache",{}),ct(this,"param"),ct(this,"security"),ct(this,"security_lower_tf"),Object.entries(Yh).forEach(([i,r])=>{this[i]=r(t)})}}function Xh(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 c=0;return h!==0&&(c=(s-a-(n-s))/h*o),r.cumulativeSum+=c,e.precision(r.cumulativeSum)}}function Zh(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 c=n||`alma_${a}_${o}_${h}`;if(!e.taState[c]){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[c]={window:[],weights:y}}const l=e.taState[c],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 Jh(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 c;if(n.prevClose!==null){const f=a-o,g=Math.abs(a-n.prevClose),p=Math.abs(o-n.prevClose);c=Math.max(f,g,p)}else c=a-o;if(n.prevClose=h,n.initCount<r)return n.initSum+=c,n.initCount++,n.initCount===r?(n.prevAtr=n.initSum/r,e.precision(n.prevAtr)):NaN;const l=(n.prevAtr*(r-1)+c)/r;return n.prevAtr=l,e.precision(l)}}function ec(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 tc(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],c=d.from(t).get(0);if(isNaN(c))return[[NaN,NaN,NaN]];if(h.window.unshift(c),h.sum+=c,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 ic(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],c=d.from(t).get(0);if(isNaN(c))return NaN;if(h.window.unshift(c),h.sum+=c,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 rc(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 c=0;for(let g=0;g<s;g++)c+=Math.abs(a.window[g]-h);const l=c/s;if(l===0)return 0;const f=(o-h)/(.015*l);return e.precision(f)}}function sc(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 nc(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 c=o-h,l=c>=0?c:0,f=c>=0?0:-c;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 ac(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 c=-h/a;return e.precision(c)}}function oc(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,c=0,l=0,f=0,g=0,p=0;for(let A=0;A<n;A++){const k=a.get(A),P=o.get(A);isNaN(k)||isNaN(P)||(h+=k,c+=P,l+=k*P,f+=k*k,g+=P*P,p++)}if(p<2)return NaN;const x=p*l-h*c,y=p*f-h*h,w=p*g-c*c;if(y<=0||w<=0)return e.precision(0);const E=x/Math.sqrt(y*w);return e.precision(E)}}function hc(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),c=n.get(1);if(isNaN(a)||isNaN(o)||isNaN(h)||isNaN(c))return!1;const l=a>o&&h<=c,f=a<o&&h>=c;return l||f}}function cc(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 uc(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 lc(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 pc(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 c=0;for(let f=0;f<s;f++)c+=Math.abs(a.window[f]-h);const l=c/s;return e.precision(l)}}function fc(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),c=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(c)||isNaN(l))return[[NaN,NaN,NaN]];if(isNaN(o.prevHigh))return o.prevHigh=h,o.prevLow=c,o.prevClose=l,[[NaN,NaN,NaN]];const f=Math.max(h-c,Math.abs(h-o.prevClose),Math.abs(c-o.prevClose)),g=h-o.prevHigh,p=o.prevLow-c,x=g>p&&g>0?g:0,y=p>g&&p>0?p:0;o.prevHigh=h,o.prevLow=c,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 z=1/s;o.prevSmoothedTR=z*f+(1-z)*o.prevSmoothedTR,o.prevSmoothedPlus=z*x+(1-z)*o.prevSmoothedPlus,o.prevSmoothedMinus=z*y+(1-z)*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,P=w===0?0:100*A/w,C=k+P,Q=C===0?0:100*Math.abs(k-P)/C;let G=NaN;if(o.adxInitCount++,o.adxInitCount<=n)o.dxInitSum+=Q,o.adxInitCount===n&&(o.prevADX=o.dxInitSum/n,G=o.prevADX);else{const z=1/n;o.prevADX=z*Q+(1-z)*o.prevADX,G=o.prevADX}return[[e.precision(k),e.precision(P),e.precision(G)]]}}function mc(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),c=o*h+a.prevEma*(1-h);return a.prevEma=c,e.precision(c)}}function dc(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 gc(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(c=>!isNaN(c)));return e.precision(h)}}function xc(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 c=n.get(h);isNaN(c)||(isNaN(o)||c>a)&&(a=c,o=-h)}return o}}function yc(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),c=o(t,s,r?`${r}_wma2`:void 0);if(isNaN(h)||isNaN(c))return NaN;e.taState||(e.taState={});const l=r||`hma_raw_${s}`;e.taState[l]||(e.taState[l]=[]);const f=2*h-c;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 wc(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 bc(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 c;const l=e.get(e.data.high,0),f=e.get(e.data.low,0);if(h){const P=e.get(e.data.close,1);isNaN(P)?c=NaN:c=Math.max(l-f,Math.abs(l-P),Math.abs(f-P))}else c=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=(P,C,Q)=>{if(isNaN(C))return NaN;if(P.initCount<Q)return P.initSum+=C,P.initCount++,P.initCount===Q?(P.prevEma=P.initSum/Q,P.prevEma):NaN;const G=2/(Q+1);return P.prevEma=C*G+P.prevEma*(1-G),P.prevEma},w=y(x.basisState,g,a),E=y(x.rangeState,c,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 vc(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 c=n||`kcw_${a}_${o}_${h}`;e.taState[c]||(e.taState[c]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const l=e.taState[c],f=(k,P,C)=>{if(isNaN(P))return NaN;if(k.initCount<C)return k.initSum+=P,k.initCount++,k.initCount===C?(k.prevEma=k.initSum/C,k.prevEma):NaN;const Q=2/(C+1);return k.prevEma=P*Q+k.prevEma*(1-Q),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 _c(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],c=d.from(t).get(0);if(h.window.unshift(c),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,P=h.window[A];l+=k,f+=P,g+=k*P,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 Sc(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),c=h.length>0?Math.min(...h):NaN;return e.precision(c)}}function Ec(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 c=n.get(h);isNaN(c)||(isNaN(o)||c<a)&&(a=c,o=-h)}return o}}function Nc(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),c=n||`macd_${a}_${o}_${h}`,l=`${c}_fast`,f=`${c}_slow`,g=`${c}_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 Cc(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),c=Math.floor(s/2),l=s%2===0?(h[c-1]+h[c])/2:h[c];return e.precision(l)}}function kc(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),c=e.get(e.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;const l=isNaN(h)?NaN:o-h;let f=0,g=0;if(f=c*(l<=0?0:o),g=c*(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 Ic(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 c=0;c<s;c++){const l=n.get(c);isNaN(l)||a.set(l,(a.get(l)||0)+1)}if(a.size===0)return NaN;let o=NaN,h=-1;for(const[c,l]of a.entries())l>h?(h=l,o=c):l===h&&c<o&&(o=c);return o}}function Ac(e){return(t,i,r)=>{const s=d.from(i).get(0);return e.ta.change(t,s)}}function Tc(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,c=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||c===0)&&l<f){const g=(h-c)/c;r.nvi=r.nvi+g*r.nvi}return e.precision(r.nvi)}}function Pc(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 Rc(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 Dc(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 c=a/100*n-.5;c<0&&(c=0),c>n-1&&(c=n-1);const l=Math.floor(c),f=Math.ceil(c);if(l===f)return e.precision(h[l]);const g=c-l,p=h[l]+g*(h[f]-h[l]);return e.precision(p)}}function Mc(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 c=Math.ceil(a/100*h.length)-1;return c<0&&(c=0),c>=h.length&&(c=h.length-1),e.precision(h[c])}}function Oc(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 c=1;c<=s;c++){const l=n.get(c);isNaN(l)||(h++,l<=a&&o++)}return h===0?NaN:e.precision(o/h*100)}}function Vc(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 Lc(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=Vc(o,n,a),c=e.idx;return e.precision(h[c])}}function Bc(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 Fc(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=Bc(o,n,a),c=e.idx;return e.precision(h[c])}}function jc(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,c=isNaN(n)?0:n,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(h===0||c===0)&&l>f){const g=(h-c)/c;r.pvi=r.pvi+g*r.pvi}return e.precision(r.pvi)}}function $c(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 Wc(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 qc(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 Uc(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,c=o*h+a.prevRma*(1-h);return a.prevRma=c,e.precision(c)}}function Kc(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],c=(o-h)/h*100;return e.precision(c)}}function zc(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,c=h>0?h:0,l=h<0?-h:0;if(a.initGains.length<s){if(a.initGains.push(c),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)+c)/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 Hc(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 c=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 c.barIndex===1&&(g>p?(c.isBelow=!0,c.maxMin=l,c.result=y):(c.isBelow=!1,c.maxMin=f,c.result=x),A=!0,c.acceleration=n),c.barIndex>=1&&(c.result=c.result+c.acceleration*(c.maxMin-c.result),c.isBelow?c.result>f&&(A=!0,c.isBelow=!1,c.result=Math.max(l,c.maxMin),c.maxMin=f,c.acceleration=n):c.result<l&&(A=!0,c.isBelow=!0,c.result=Math.min(f,c.maxMin),c.maxMin=l,c.acceleration=n),A||(c.isBelow?l>c.maxMin&&(c.maxMin=l,c.acceleration=Math.min(c.acceleration+a,o)):f<c.maxMin&&(c.maxMin=f,c.acceleration=Math.min(c.acceleration+a,o))),c.isBelow?(c.result=Math.min(c.result,y),c.barIndex>1&&(c.result=Math.min(c.result,E))):(c.result=Math.max(c.result,x),c.barIndex>1&&(c.result=Math.max(c.result,w)))),c.barIndex++,c.barIndex<=1?NaN:e.precision(c.result)}}function Gc(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 c=a.window.pop();a.sum-=c}const h=a.sum/s;return e.precision(h)}}function Yc(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],c=d.from(t).get(0);if(c==null||isNaN(c))return NaN;if(h.window.unshift(c),h.sum+=c,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 Qc(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],c=d.from(t).get(0),l=d.from(i).get(0),f=d.from(r).get(0);if(isNaN(c)||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*(c-p)/x;return e.precision(y)}}function Xc(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),c=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(h)||isNaN(c)||isNaN(l))return[[NaN,NaN]];const f=(h+c)/2;let g;isNaN(o.prevClose)?g=h-c:g=Math.max(h-c,Math.abs(h-o.prevClose),Math.abs(c-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,P;const C=o.prevSuperTrend;return o.atrCount===n?k=1:C===o.prevUpperBand?k=l>y?-1:1:k=l<w?1:-1,P=k===-1?w:y,o.prevLowerBand=w,o.prevUpperBand=y,o.prevSuperTrend=P,o.prevDirection=k,[[e.precision(P),k]]}}function Zc(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 c=0;c<4;c++)h+=r[c]*a.window[3-c];return h/=s,e.precision(h)}}function Jc(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 eu(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],c=d.from(t).get(0);if(isNaN(c))return NaN;const l=isNaN(h.prevSource)?NaN:c-h.prevSource;if(h.prevSource=c,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 tu(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),c=d.from(r).get(0);if(o&&a.values.push(h),isNaN(c)||c<0)return NaN;const l=a.values.length-1-c;if(l<0)return NaN;const f=a.values[l];return typeof f=="number"?e.precision(f):f}}function iu(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,c=0;for(let g=0;g<s;g++)h+=a.window[g],c+=a.window[g]*a.window[g];const l=h/s,f=c/s-l*l;return e.precision(f)}}function ru(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 c=s.cumulativePV/s.cumulativeVolume;return e.precision(c)}}function su(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 c=0,l=0;for(let g=0;g<s;g++)c+=a.window[g]*a.volumeWindow[g],l+=a.volumeWindow[g];const f=c/l;return e.precision(f)}}function nu(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 c=Math.max(n,o),l=Math.min(a,o),f=s-o;f>0?h=s-l:f<0&&(h=s-c)}return r.cumulativeSum+=h,e.precision(r.cumulativeSum)}}function au(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,c=0;for(let f=0;f<s;f++){const g=s-f;h+=a.window[f]*g,c+=g}const l=h/c;return e.precision(l)}}function ou(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 c=n.highWindow[0],l=n.lowWindow[0];for(let p=1;p<r;p++)n.highWindow[p]>c&&(c=n.highWindow[p]),n.lowWindow[p]<l&&(l=n.lowWindow[p]);const f=c-l;if(f===0)return e.precision(0);const g=(c-h)/f*-100;return e.precision(g)}}function hu(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 cu=Object.defineProperty,uu=(e,t,i)=>t in e?cu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,_=(e,t,i)=>uu(e,typeof t!="symbol"?t+"":t,i);const lu={accdist:Xh,alma:Zh,atr:Jh,barssince:ec,bb:tc,bbw:ic,cci:rc,change:sc,cmo:nc,cog:ac,correlation:oc,cross:hc,crossover:cc,crossunder:uc,cum:lc,dev:pc,dmi:fc,ema:mc,falling:dc,highest:gc,highestbars:xc,hma:yc,iii:wc,kc:bc,kcw:vc,linreg:_c,lowest:Sc,lowestbars:Ec,macd:Nc,median:Cc,mfi:kc,mode:Ic,mom:Ac,nvi:Tc,obv:Pc,param:Rc,percentile_linear_interpolation:Dc,percentile_nearest_rank:Mc,percentrank:Oc,pivothigh:Lc,pivotlow:Fc,pvi:jc,pvt:$c,range:Wc,rising:qc,rma:Uc,roc:Kc,rsi:zc,sar:Hc,sma:Gc,stdev:Yc,stoch:Qc,supertrend:Xc,swma:Zc,tr:Jc,tsi:eu,valuewhen:tu,variance:iu,vwap:ru,vwma:su,wad:nu,wma:au,wpr:ou,wvad:hu};class pu{constructor(t){this.context=t,_(this,"accdist"),_(this,"alma"),_(this,"atr"),_(this,"barssince"),_(this,"bb"),_(this,"bbw"),_(this,"cci"),_(this,"change"),_(this,"cmo"),_(this,"cog"),_(this,"correlation"),_(this,"cross"),_(this,"crossover"),_(this,"crossunder"),_(this,"cum"),_(this,"dev"),_(this,"dmi"),_(this,"ema"),_(this,"falling"),_(this,"highest"),_(this,"highestbars"),_(this,"hma"),_(this,"iii"),_(this,"kc"),_(this,"kcw"),_(this,"linreg"),_(this,"lowest"),_(this,"lowestbars"),_(this,"macd"),_(this,"median"),_(this,"mfi"),_(this,"mode"),_(this,"mom"),_(this,"nvi"),_(this,"obv"),_(this,"param"),_(this,"percentile_linear_interpolation"),_(this,"percentile_nearest_rank"),_(this,"percentrank"),_(this,"pivothigh"),_(this,"pivotlow"),_(this,"pvi"),_(this,"pvt"),_(this,"range"),_(this,"rising"),_(this,"rma"),_(this,"roc"),_(this,"rsi"),_(this,"sar"),_(this,"sma"),_(this,"stdev"),_(this,"stoch"),_(this,"supertrend"),_(this,"swma"),_(this,"tr"),_(this,"tsi"),_(this,"valuewhen"),_(this,"variance"),_(this,"vwap"),_(this,"vwma"),_(this,"wad"),_(this,"wma"),_(this,"wpr"),_(this,"wvad"),Object.entries(lu).forEach(([i,r])=>{this[i]=r(t)})}}class fu{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 mu{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 c=0,l=0;for(;;){const f=n.indexOf(a,c);if(f===-1)return n;if(l===h)return n.substring(0,f)+o+n.substring(f+a.length);l++,c=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 du{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 gu=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],xu={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 yu{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=Qt(t,gu,xu),{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 wu{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 bu=Object.defineProperty,vu=(e,t,i)=>t in e?bu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,j=(e,t,i)=>vu(e,typeof t!="symbol"?t+"":t,i);const yr=class Lt{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 c=new qo(this),l={na:c.na.bind(c),color:c.color,nz:c.nz.bind(c),indicator:c.indicator.bind(c),fixnan:c.fixnan.bind(c),alertcondition:c.alertcondition.bind(c),bool:c.bool.bind(c)},f=this;this.pine={input:new uh(this),ta:new pu(this),math:new qh(this),request:new Qh(this),array:new ma(this),map:new Aa(this),matrix:new Ro(this),syminfo:null,timeframe:new du(this),barstate:new Vo(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 fu(this),str:new mu(this),...l,...Xn};const g=new yu(this),p=new wu(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}`;Lt._deprecationWarningsShown.has(r)||(Lt._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(yr,"_deprecationWarningsShown",new Set);let _i=yr;var _u=Object.defineProperty,Su=(e,t,i)=>t in e?_u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,K=(e,t,i)=>Su(e,typeof t!="symbol"?t+"":t,i);class wr{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 c=h;this.data=c;const l=c.map(C=>C.open),f=c.map(C=>C.close),g=c.map(C=>C.high),p=c.map(C=>C.low),x=c.map(C=>C.volume),y=c.map(C=>(C.high+C.low+C.close)/3),w=c.map(C=>(C.high+C.low)/2),E=c.map(C=>(C.high+C.low+C.open+C.close)/4),A=c.map(C=>(C.high+C.low+C.close+C.close)/4),k=c.map(C=>C.openTime),P=c.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=P,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:c}=await this._updateMarketData();if(h===0&&!c){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 _i({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 c=n[h];c.openTime===s?(this._replaceCandle(r,c),a=!0):c.openTime>s&&(this._appendCandle(c),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 _i({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 fn.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 c;o[h]instanceof d?c=o[h].get(0):Array.isArray(o[h])?c=o[h][o[h].length-1]:c=o[h],t.result[h].push(c)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(o);for(let h of n)for(let c in t[h]){const l=t[h][c];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 Eu=Object.defineProperty,Nu=(e,t,i)=>t in e?Eu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Bt=(e,t,i)=>Nu(e,typeof t!="symbol"?t+"":t,i);const Si="https://api.binance.com/api/v3",kt={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 Cu{constructor(t=5*60*1e3){Bt(this,"cache"),Bt(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 ku{constructor(){Bt(this,"cacheManager"),this.cacheManager=new Cu(5*60*1e3)}async getMarketDataInterval(t,i,r,s){try{const n=kt[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 c=s,l=a[n];if(!l)return console.error(`Duration not defined for interval: ${n}`),[];for(;h<c;){const f=Math.min(h+1e3*l,c),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=kt[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 c=`${Si}/klines?symbol=${t}&interval=${h}`;r&&(c+=`&limit=${Math.min(r,1e3)}`),s&&(c+=`&startTime=${s}`),n&&(c+=`&endTime=${n}`);const l=await fetch(c);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=kt[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=Si,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 c=i==="futures"?h.find(k=>k.symbol===s):h[0];if(!c)return console.error(`Symbol ${s} not found in exchange info`),null;const l=c.filters?.find(k=>k.filterType==="PRICE_FILTER"),f=c.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=c.baseAsset,w=c.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:c.contractSize||1,mincontract:p,session:"24x7",volumetype:"base",expiration_date:c.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}}}var Iu=Object.defineProperty,Au=(e,t,i)=>t in e?Iu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,It=(e,t,i)=>Au(e,typeof t!="symbol"?t+"":t,i);const Tu=br(import.meta.url),Pu=Xe.dirname(Tu);class Ru{constructor(t){if(It(this,"dataCache",new Map),It(this,"exchangeInfoCache",{}),It(this,"dataDirectory"),t)this.dataDirectory=t;else{const i=Xe.resolve(Pu,"../../../");this.dataDirectory=Xe.join(i,"tests","compatibility","_data")}}getDataFileName(t,i,r,s){return r&&s?`${t}-${i}-${r}-${s}.json`:null}loadDataFromFile(t){const i=`file:${t}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=Xe.join(this.dataDirectory,t);if(!Fe.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const s=Fe.readFileSync(r,"utf-8"),n=JSON.parse(s);return this.dataCache.set(i,n),n}findDataFile(t,i,r,s){if(!Fe.existsSync(this.dataDirectory))return null;const n=Fe.readdirSync(this.dataDirectory).filter(h=>h.endsWith(".json"));if(r&&s){const h=`${t}-${i}-${r}-${s}.json`;if(n.includes(h))return h}const a=new RegExp(`^${t}-${i}-(\\d+)-(\\d+)\\.json$`),o=n.filter(h=>a.test(h)).map(h=>{const c=h.match(a);return{file:h,startTime:parseInt(c[1]),endTime:parseInt(c[2])}}).sort((h,c)=>c.endTime-h.endTime);if(o.length===0)return null;if(r&&s){const h=o.find(c=>c.startTime<=r&&c.endTime>=s);if(h)return h.file}return o[0].file}filterData(t,i,r,s){let n=t;return(i||r)&&(n=t.filter(a=>{const o=!i||a.openTime>=i,h=!r||a.openTime<=r;return o&&h})),n.sort((a,o)=>a.openTime-o.openTime),s&&s>0&&(n=n.slice(0,s)),n}normalizeTimeframe(t){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[t.toUpperCase()]||t.toLowerCase()}async getMarketData(t,i,r,s,n){try{const a=this.normalizeTimeframe(i),o=this.findDataFile(t,a,s,n);if(!o)return console.warn(`No mock data file found for ${t} ${a}. Searched in: ${this.dataDirectory}`),[];const h=this.loadDataFromFile(o);return this.filterData(h,s,n,r)}catch(a){return console.error("Error in MockProvider.getMarketData:",a),[]}}loadExchangeInfo(t){if(this.exchangeInfoCache[t])return this.exchangeInfoCache[t];const i=t==="spot"?"api-exchangeInfo.json":"fapi-exchangeInfo.json",r=Xe.join(this.dataDirectory,i);if(!Fe.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const s=Fe.readFileSync(r,"utf-8"),n=JSON.parse(s);return this.exchangeInfoCache[t]=n,n}catch(s){return console.error(`Error loading exchange info from ${i}:`,s),null}}async getSymbolInfo(t){try{let i="crypto",r=t,s="";t.endsWith(".P")?(i="futures",r=t.replace(".P",""),s="Perpetual"):t.includes("_")&&(i="futures",r=t,s="Delivery");const n=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!n||!n.symbols)return console.error(`Exchange info not available for ${i}`),null;const a=n.symbols.find(w=>w.symbol===r);if(!a)return console.error(`Symbol ${r} not found in ${i} exchange info`),null;const o=a.filters?.find(w=>w.filterType==="PRICE_FILTER"),h=a.filters?.find(w=>w.filterType==="LOT_SIZE"),c=o?parseFloat(o.tickSize):.01,l=h?parseFloat(h.minQty):0,f=Math.round(1/c),g=a.baseAsset,p=a.quoteAsset,x=s?` ${s}`:"",y=`${g} / ${p}${x}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:g,description:y,type:i,main_tickerid:`BINANCE:${t}`,current_contract:s,isin:"",basecurrency:g,currency:p,timezone:"Etc/UTC",country:"",mintick:c,pricescale:f,minmove:1,pointvalue:a.contractSize||1,mincontract:l,session:"24x7",volumetype:"base",expiration_date:a.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in MockProvider.getSymbolInfo:",i),null}}clearCache(){this.dataCache.clear(),this.exchangeInfoCache={}}setDataDirectory(t){this.dataDirectory=t,this.clearCache()}}const Du=typeof process<"u"&&process.versions&&process.versions.node;let dt=null;if(Du)try{dt=new Ru}catch{dt=null}const Ou={Binance:new ku,...dt?{Mock:dt}:{}};export{_i as Context,wr as PineTS,Ou as Provider};
117
117
  //# sourceMappingURL=pinets.min.es.js.map