pinets 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/pinets.min.browser.es.js +14 -14
- package/dist/pinets.min.browser.es.js.map +1 -1
- package/dist/pinets.min.browser.js +1 -1
- package/dist/pinets.min.browser.js.map +1 -1
- package/dist/pinets.min.cjs +1 -1
- package/dist/pinets.min.cjs.map +1 -1
- package/dist/pinets.min.es.js +1 -1
- package/dist/pinets.min.es.js.map +1 -1
- package/package.json +1 -1
package/dist/pinets.min.cjs
CHANGED
|
@@ -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 Zi(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 jn(e,t={}){const i=Zi(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 Cn(e).tokenize(),n=new Bn(r).parse(),s={...t,sourceCode:e},a=new Fn(s).generate(n);return{success:!0,version:i,code:a,ast:n,tokens:r}}catch(r){return{success:!1,version:i,error:r.message,stack:r.stack}}}function $n(e){if(typeof e=="function")return e.toString();{const t=Zi(e);if(t===null)return e;if(t>=5){const i=jn(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 Wn(e,t={debug:!1,ln:!1}){typeof t=="boolean"&&(t={debug:t,ln:!0});const{debug:i}=t;let r=$n(e);r=un(r);const n=i?r.split(`
|
|
114
114
|
`):[],s=Ki(r,{ecmaVersion:"latest",sourceType:"module",locations:i});ln(s),on(s),an(s);const a=new en;pn(s,a);const o=dn(s,a)||"";_n(s,a,o,t,n),vn(s);const c=Qr||Rt||void 0,h=Object.assign({},c,{LineComment(f,g){g.write("//"+f.value)}}),l=Hi(s,{generator:h,comments:i});return new Function("",`var _r = ${l}
|
|
115
115
|
; return _r;`)(this)}function qn(e){return t=>new V(t.array.map(i=>Math.abs(i)),t.type,e)}function Un(e){return t=>{let i=0,r=0;for(const n of t.array){const s=Number(n);isNaN(s)||(r++,i+=(s-i)/r)}return r===0?NaN:e.precision(i)}}function Kn(e){return(t,i)=>{const r=t.array;let n=0,s=r.length-1;for(;n<=s;){const a=Math.floor((n+s)/2),o=r[a];if(o===i)return a;o<i?n=a+1:s=a-1}return-1}}function zn(e){return(t,i)=>{const r=t.array;let n=0,s=r.length;for(;n<s;){const a=Math.floor((n+s)/2);r[a]<i?n=a+1:s=a}return n<r.length&&r[n]===i?n:n-1}}function Hn(e){return(t,i)=>{const r=t.array;let n=0,s=r.length;for(;n<s;){const a=Math.floor((n+s)/2);r[a]<=i?n=a+1:s=a}return n>0&&r[n-1]===i?n-1:n}}function Gn(e){return t=>{t.array.length=0}}function Yn(e){return(t,i)=>(t.array.push(...i.array),t)}function Qn(e){return t=>new V([...t.array],t.type,e)}function Xn(e){return(t,i,r=!0)=>{const n=t.array,s=i.array;if(n.length!==s.length)return NaN;let a=0,o=0,c=0;const h=[];for(let x=0;x<n.length;x++){const y=Number(n[x]),w=Number(s[x]);!isNaN(y)&&y!==null&&y!==void 0&&!isNaN(w)&&w!==null&&w!==void 0&&(a+=y,o+=w,c++,h.push(x))}if(c===0)return NaN;const l=a/c,f=o/c;let g=0;for(const x of h){const y=Number(n[x]),w=Number(s[x]);g+=(y-l)*(w-f)}const p=r?c:c-1;return p<=0?NaN:e.precision(g/p)}}function Zn(e){return t=>t.array.every(i=>!isNaN(i)&&i)}function Jn(e){if(e.every(t=>typeof t=="number"))return e.every(t=>(t|0)===t)?L.int:L.float;if(e.every(t=>typeof t=="string"))return L.string;if(e.every(t=>typeof t=="boolean"))return L.bool;throw new Error("Cannot infer type from values")}function oe(e){if(typeof e=="number")return(e|0)===e?L.int:L.float;if(typeof e=="string")return L.string;if(typeof e=="boolean")return L.bool;throw new Error("Cannot infer type from value")}function Ge(e,t){switch(t){case L.int:return typeof e=="number"&&(e|0)===e||isNaN(e);case L.float:return typeof e=="number"||isNaN(e);case L.string:return typeof e=="string";case L.bool:return typeof e=="boolean"}return!1}function es(e){return(t,i,r=0,n)=>{const s=t.array.length,a=n!==void 0?Math.min(n,s):s;for(let o=r;o<a;o++){if(!Ge(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 ts(e){return t=>t.array.length>0?t.array[0]:e.NA}function is(e){return(t,i)=>t.array[i]}function rs(e){return(t,i)=>t.array.includes(i)}function ns(e){return(t,i)=>t.array.indexOf(i)}function ss(e){return(t,i,r)=>{if(!Ge(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 as(e){return(t,i=",")=>t.array.join(i)}function os(e){return t=>t.array.length>0?t.array[t.array.length-1]:e.NA}function cs(e){return(t,i)=>t.array.lastIndexOf(i)}function hs(e){return(t,i=0)=>[...t.array].sort((r,n)=>n-r)[i]??e.NA}function us(e){return t=>{if(t.array.length===0)return NaN;const i=[...t.array].sort((n,s)=>typeof n=="number"&&typeof s=="number"?n-s:0),r=Math.floor(i.length/2);return i.length%2!==0?i[r]:(i[r-1]+i[r])/2}}function ls(e){return(t,i=0)=>[...t.array].sort((r,n)=>r-n)[i]??e.NA}function ps(e){return t=>{if(t.array.length===0)return NaN;const i=new Map;let r=0;for(const s of t.array){const a=(i.get(s)||0)+1;i.set(s,a),a>r&&(r=a)}const n=[];for(const[s,a]of i)a===r&&n.push(s);return n.sort((s,a)=>typeof s=="number"&&typeof a=="number"?s-a:typeof s=="string"&&typeof a=="string"?s<a?-1:s>a?1:0:0),n[0]}}function fs(e){return(t,i)=>{const r=t.array;if(r.length===0)return NaN;const n=[];for(const c of r){const h=Number(c);if(isNaN(h)||h===null||h===void 0)return NaN;n.push(h)}n.sort((c,h)=>c-h),i<0&&(i=0),i>100&&(i=100);const s=i/100*n.length-.5;if(s<=0)return e.precision(n[0]);if(s>=n.length-1)return e.precision(n[n.length-1]);const a=Math.floor(s),o=s-a;return e.precision(n[a]*(1-o)+n[a+1]*o)}}function ms(e){return(t,i)=>{const r=t.array;if(r.length===0)return NaN;const n=[];for(const o of r){const c=Number(o);!isNaN(c)&&c!==null&&c!==void 0&&n.push(c)}if(n.length===0)return NaN;n.sort((o,c)=>o-c),i<0&&(i=0),i>100&&(i=100);const s=r.length,a=Math.ceil(i/100*s);return a<=0?n[0]:a>n.length?NaN:n[a-1]}}function ds(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 n=Number(t.array[r]);if(isNaN(n)||n===null||n===void 0)return NaN;let s=0;for(const o of t.array){const c=Number(o);!isNaN(c)&&c!==null&&c!==void 0&&c<n&&s++}const a=t.array.length-1;return a<=0?NaN:s/a*100}}function gs(e){return t=>t.array.pop()}function xs(e){return(t,i)=>{if(!Ge(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 ys(e){return t=>e.precision(e.pine.array.max(t)-e.pine.array.min(t))}function ws(e){return(t,i)=>i>=0&&i<t.array.length?t.array.splice(i,1)[0]:e.NA}function bs(e){return t=>{t.array.reverse()}}function vs(e){return(t,i,r)=>{if(!Ge(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 _s(e){return t=>t.array.shift()}function Ss(e){return t=>t.array.length}function Es(e){return(t,i,r)=>{const n=r!==void 0?r:void 0;return new V(t.array.slice(i,n),t.type,e)}}function Ns(e){return t=>t.array.some(i=>!isNaN(i)&&i)}var Pe=(e=>(e[e.ascending=1]="ascending",e[e.descending=0]="descending",e))(Pe||{}),Ji=(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))(Ji||{}),er=(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))(er||{}),tr=(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))(tr||{});const Cs={order:Pe,currency:Ji,dayofweek:er,display:tr};function ks(e){return(t,i=Pe.ascending)=>{t.array.sort((r,n)=>{let s=isNaN(r)?1/0:r,a=isNaN(n)?1/0:n;return i===Pe.ascending?s-a:a-s})}}function Is(e){return(t,i=Pe.ascending)=>{const r=t.array.map((n,s)=>s);return r.sort((n,s)=>{const a=isNaN(t.array[n])?1/0:t.array[n],o=isNaN(t.array[s])?1/0:t.array[s];return i===Pe.ascending?a-o:o-a}),new V(r,L.int,e)}}function As(e){return t=>{const i=e.array.avg(t),r=e.array.stdev(t);return isNaN(r)?new V(t.array.map(()=>NaN),L.int,e):r===0?new V(t.array.map(()=>1),L.int,e):new V(t.array.map(n=>(n-i)/r),L.int,e)}}function Ts(e){return(t,i=!0)=>{const r=t.array,n=r.length;if(n===0)return NaN;let s=0,a=0,o=0;for(let l=0;l<n;l++){const f=Number(r[l]);!isNaN(f)&&f!==null&&f!==void 0&&(s+=f,a+=f*f,o++)}if(o===0)return NaN;const c=s/o;let h=a/o-c*c;return h<0?NaN:(!i&&o>1&&(h=h*o/(o-1)),!i&&o===1?0:e.precision(Math.sqrt(h)))}}function Ps(e){return t=>e.precision(t.array.reduce((i,r)=>{const n=Number(r);return isNaN(n)?i:i+n},0))}function Rs(e){return(t,i)=>{if(!Ge(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 Ds(e){return(t,i=!0)=>{let r=0,n=0;for(const c of t.array){const h=Number(c);!isNaN(h)&&h!==null&&h!==void 0&&(r+=h,n++)}if(n===0)return NaN;const s=r/n;let a=0;for(const c of t.array){const h=Number(c);!isNaN(h)&&h!==null&&h!==void 0&&(a+=(h-s)*(h-s))}const o=i?n:n-1;return o<=0?NaN:e.precision(a/o)}}var L=(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))(L||{});class V{constructor(t,i,r){this.array=t,this.type=i,this.context=r,this._abs=qn(this.context),this._avg=Un(this.context),this._binary_search=Kn(this.context),this._binary_search_leftmost=zn(this.context),this._binary_search_rightmost=Hn(this.context),this._clear=Gn(this.context),this._concat=Yn(this.context),this._copy=Qn(this.context),this._covariance=Xn(this.context),this._every=Zn(this.context),this._fill=es(this.context),this._first=ts(this.context),this._get=is(this.context),this._includes=rs(this.context),this._indexof=ns(this.context),this._insert=ss(this.context),this._join=as(this.context),this._last=os(this.context),this._lastindexof=cs(this.context),this._max=hs(this.context),this._median=us(this.context),this._min=ls(this.context),this._mode=ps(this.context),this._percentile_linear_interpolation=fs(this.context),this._percentile_nearest_rank=ms(this.context),this._percentrank=ds(this.context),this._pop=gs(this.context),this._push=xs(this.context),this._range=ys(this.context),this._remove=ws(this.context),this._reverse=bs(this.context),this._set=vs(this.context),this._shift=_s(this.context),this._size=Ss(this.context),this._slice=Es(this.context),this._some=Ns(this.context),this._sort=ks(this.context),this._sort_indices=Is(this.context),this._standardize=As(this.context),this._stdev=Ts(this.context),this._sum=Ps(this.context),this._unshift=Rs(this.context),this._variance=Ds(this.context)}_abs;_avg;_binary_search;_binary_search_leftmost;_binary_search_rightmost;_clear;_concat;_copy;_covariance;_every;_fill;_first;_get;_includes;_indexof;_insert;_join;_last;_lastindexof;_max;_median;_min;_mode;_percentile_linear_interpolation;_percentile_nearest_rank;_percentrank;_pop;_push;_range;_remove;_reverse;_set;_shift;_size;_slice;_some;_sort;_sort_indices;_standardize;_stdev;_sum;_unshift;_variance;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 Ms(e){return(...t)=>new V([...t],Jn(t),e)}function Vs(e){return(t,i)=>new V(Array(t).fill(e.precision(i||0)),oe(i||0),e)}function Os(e){return(t,i=!1)=>new V(Array(t).fill(i),L.bool,e)}function Ls(e){return(t,i=NaN)=>new V(Array(t).fill(e.precision(i)),L.float,e)}function Bs(e){return(t,i=0)=>new V(Array(t).fill(e.precision(i)),L.int,e)}function Fs(e){return(t,i="")=>new V(Array(t).fill(i),L.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 js(e){return(t,i=0)=>d.from(t).get(i)}class $s{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=Ms(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=Vs(t),this.new_bool=Os(t),this.new_float=Ls(t),this.new_int=Bs(t),this.new_string=Fs(t),this.param=js(),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 Ws(e){return t=>{t.map.clear()}}function qs(e){return(t,i)=>t.map.has(i)}function Us(e){return t=>{const i=new ir(e);return i.map=new Map(t.map),i}}function Ks(e){return(t,i)=>{const r=t.map.get(i);return r===void 0?NaN:r}}function zs(e){return t=>{const i=Array.from(t.map.keys()),r=oe(i[0]);return new V(i,r,e)}}function Hs(e){return(t,i,r)=>{const n=t.map.get(i);return t.map.set(i,r),n===void 0?NaN:n}}function Gs(e){return(t,i)=>{for(const[r,n]of i.map)t.map.set(r,n)}}function Ys(e){return(t,i)=>{const r=t.map.get(i);return t.map.delete(i)?r:NaN}}function Qs(e){return t=>t.map.size}function Xs(e){return t=>{const i=Array.from(t.map.values()),r=oe(i[0]);return new V(i,r,e)}}class ir{constructor(t){this.context=t,this.map=new Map,this._clear=Ws(this.context),this._contains=qs(this.context),this._copy=Us(this.context),this._get=Ks(this.context),this._keys=zs(this.context),this._put=Hs(this.context),this._put_all=Gs(this.context),this._remove=Ys(this.context),this._size=Qs(this.context),this._values=Xs(this.context)}map;_clear;_contains;_copy;_get;_keys;_put;_put_all;_remove;_size;_values;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 Zs(e){return()=>new ir(e)}function Js(e){return(t,i=0)=>d.from(t).get(i)}class ea{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=Zs(t),this.param=Js(),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 n=t.matrix.length;let s=[];if(r&&(r instanceof V?s=r.array:Array.isArray(r)?s=r:s=[r]),n===0){for(let c=0;c<s.length;c++){let h=s[c];h instanceof d&&(h=h.get(0)),t.matrix.push([h])}return}const a=t.matrix[0].length,o=i!==void 0?i:a;for(let c=0;c<n;c++){let h=c<s.length?s[c]:NaN;h instanceof d&&(h=h.get(0)),t.matrix[c].splice(o,0,h)}}}function ia(e){return(t,i,r)=>{const n=t.matrix.length;let s=[];if(r)if(r instanceof V)s=r.array;else if(Array.isArray(r))s=r;else if(r instanceof d){const h=r.get(0);Array.isArray(h)?s=h:s=[h]}else s=[r];const a=n>0?t.matrix[0].length:s.length,o=i!==void 0?i:n,c=[];for(let h=0;h<a;h++)if(h<s.length){let l=s[h];l instanceof d&&(l=l.get(0)),c.push(l)}else c.push(NaN);t.matrix.splice(o,0,c)}}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 n=0,s=0;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||(n+=c,s++)}return s===0?NaN:n/s}}function na(e){return(t,i)=>{const r=t.matrix.length,n=[];for(let a=0;a<r;a++)n.push(t.matrix[a][i]);const s=oe(n[0]);return new V(n,s,e)}}function sa(e){return t=>t.matrix.length===0?0:t.matrix[0].length}function aa(e){return(t,i)=>{const r=t.matrix.length,n=i.matrix.length;if(r===0){for(let o=0;o<n;o++)t.matrix.push([...i.matrix[o]]);return}const s=t.matrix[0].length,a=n>0?i.matrix[0].length:0;if(s!==a&&n>0){console.error(`matrix.concat: Column count mismatch ${s} vs ${a}`);return}for(let o=0;o<n;o++)t.matrix.push([...i.matrix[o]])}}function oa(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0,n=new D(i,r,NaN,e);return n.matrix=t.matrix.map(s=>[...s]),n}}function ca(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(n=>[...n]);let r=1;for(let n=0;n<t;n++){let s=n;for(;s<t&&i[s][n]===0;)s++;if(s===t)return 0;s!==n&&([i[n],i[s]]=[i[s],i[n]],r*=-1),r*=i[n][n];for(let a=n+1;a<t;a++){const o=i[a][n]/i[n][n];for(let c=n;c<t;c++)i[a][c]-=o*i[n][c]}}return r}function ha(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;return i!==r?NaN:ca(t.matrix)}}function ua(e){return(t,i)=>{const r=t.matrix.length;if(r===0)return new D(0,0,NaN,e);const n=t.matrix[0].length,s=new D(r,n,NaN,e);if(i instanceof D)for(let a=0;a<r;a++)for(let o=0;o<n;o++){const c=t.matrix[a][o],h=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;s.matrix[a][o]=c-h}else{const a=i;for(let o=0;o<r;o++)for(let c=0;c<n;c++)s.matrix[o][c]=t.matrix[o][c]-a}return s}}function la(e){const t=e.length;if(t!==2)return Array(t).fill(NaN);const i=e[0][0],r=e[0][1],n=e[1][0],s=e[1][1],a=i+s,o=i*s-r*n,c=a*a-4*o;if(c<0)return[NaN,NaN];const h=(a+Math.sqrt(c))/2,l=(a-Math.sqrt(c))/2;return[h,l]}function pa(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r){const a=oe(t.matrix[0][0]);return new V([],a,e)}const n=la(t.matrix),s=oe(n[0]);return new V(n,s,e)}}function fa(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r)return new D(0,0,NaN,e);const n=new D(i,r,0,e);for(let s=0;s<i;s++)n.matrix[s][s]=1;return n}}function ma(e){return t=>{const i=t.matrix.length;return i===0?0:i*t.matrix[0].length}}function da(e){return(t,i,r,n,s,a)=>{const o=t.matrix.length;if(o===0)return;const c=t.matrix[0].length,h=r!==void 0?r:0,l=n!==void 0?n:o,f=s!==void 0?s:0,g=a!==void 0?a:c;for(let p=h;p<l&&!(p>=o);p++)for(let x=f;x<g&&!(x>=c);x++)t.matrix[p][x]=i}}function ga(e){return(t,i,r)=>{if(!t.matrix[i])return NaN;const n=t.matrix[i][r];return n===void 0?NaN:n}}function xa(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 ya(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;if(i!==r)return new D(i,r,NaN,e);const n=xa(t.matrix),s=new D(i,r,NaN,e);return s.matrix=n,s}}function wa(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 n=0;n<i;n++)for(let s=0;s<r;s++)if(n+s!==i-1&&t.matrix[n][s]!==0)return!1;return!0}}function ba(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 n=0;n<i;n++)for(let s=0;s<r;s++)if(t.matrix[s][n]!==-t.matrix[n][s])return!1;return!0}}function va(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;for(let n=0;n<i;n++)for(let s=0;s<r;s++){const a=t.matrix[n][s];if(a!==0&&a!==1)return!1}return!0}}function _a(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 n=0;n<i;n++)for(let s=0;s<r;s++)if(n!==s&&t.matrix[n][s]!==0)return!1;return!0}}function Sa(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 n=0;n<i;n++)for(let s=0;s<r;s++)if(n===s){if(t.matrix[n][s]!==1)return!1}else if(t.matrix[n][s]!==0)return!1;return!0}}function Ea(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;return i===r}}function Na(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;for(let n=0;n<i;n++){let s=0;for(let a=0;a<r;a++){const o=t.matrix[n][a];if(o<0)return!1;s+=o}if(Math.abs(s-1)>1e-10)return!1}return!0}}function Ca(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 n=0;n<i;n++)for(let s=0;s<n;s++)if(t.matrix[n][s]!==t.matrix[s][n])return!1;return!0}}function ka(e){return t=>{const i=t.matrix.length;if(i===0)return!1;const r=t.matrix[0].length;if(i!==r)return!1;let n=!0,s=!0;for(let a=0;a<i;a++)for(let o=0;o<r;o++)a>o&&t.matrix[a][o]!==0&&(n=!1),a<o&&t.matrix[a][o]!==0&&(s=!1);return n||s}}function Ia(e){return t=>{const i=t.matrix.length;if(i===0)return!0;const r=t.matrix[0].length;for(let n=0;n<i;n++)for(let s=0;s<r;s++)if(t.matrix[n][s]!==0)return!1;return!0}}function Aa(e){return(t,i)=>{const r=t.matrix.length,n=r>0?t.matrix[0].length:0,s=i.matrix.length,a=s>0?i.matrix[0].length:0,o=r*s,c=n*a,h=new D(o,c,NaN,e);for(let l=0;l<r;l++)for(let f=0;f<n;f++){const g=t.matrix[l][f];for(let p=0;p<s;p++)for(let x=0;x<a;x++){const y=i.matrix[p][x];h.matrix[l*s+p][f*a+x]=g*y}}return h}}function Ta(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length;let n=-1/0,s=!1;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||(c>n&&(n=c),s=!0)}return s?n:NaN}}function Pa(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length,n=[];for(let a=0;a<i;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||n.push(c)}if(n.length===0)return NaN;n.sort((a,o)=>a-o);const s=Math.floor(n.length/2);return n.length%2!==0?n[s]:(n[s-1]+n[s])/2}}function Ra(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length;let n=1/0,s=!1;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const c=t.matrix[a][o];isNaN(c)||(c<n&&(n=c),s=!0)}return s?n:NaN}}function Da(e){return t=>{const i=t.matrix.length;if(i===0)return NaN;const r=t.matrix[0].length,n=new Map;let s=0,a=NaN;for(let o=0;o<i;o++)for(let c=0;c<r;c++){const h=t.matrix[o][c];if(!isNaN(h)){const l=(n.get(h)||0)+1;n.set(h,l),l>s?(s=l,a=h):l===s&&h<a&&(a=h)}}return a}}function Ma(e){return(t,i)=>{const r=t.matrix.length,n=r>0?t.matrix[0].length:0;if(i instanceof D){const s=i.matrix.length,a=s>0?i.matrix[0].length:0;if(n!==s)return new D(0,0,NaN,e);const o=new D(r,a,0,e);for(let c=0;c<r;c++)for(let h=0;h<a;h++){let l=0;for(let f=0;f<n;f++)l+=t.matrix[c][f]*i.matrix[f][h];o.matrix[c][h]=l}return o}else if(i instanceof V||Array.isArray(i.array||i)){const s=i.array||i;if(n!==s.length)return new D(0,0,NaN,e);const a=new D(r,1,0,e);for(let o=0;o<r;o++){let c=0;for(let h=0;h<n;h++)c+=t.matrix[o][h]*s[h];a.matrix[o][0]=c}return a}else{const s=i,a=new D(r,n,NaN,e);for(let o=0;o<r;o++)for(let c=0;c<n;c++)a.matrix[o][c]=t.matrix[o][c]*s;return a}}}function Va(e){return t=>{const i=t.matrix.length,r=i>0?t.matrix[0].length:0;return i===r?new D(i,r,NaN,e):new D(r,i,NaN,e)}}function Oa(e){return(t,i)=>{const r=t.matrix.length,n=r>0?t.matrix[0].length:0;if(r!==n)return new D(0,0,NaN,e);let s=new D(r,n,0,e);for(let c=0;c<r;c++)s.matrix[c][c]=1;let a=new D(r,n,NaN,e);for(let c=0;c<r;c++)a.matrix[c]=[...t.matrix[c]];let o=Math.floor(i);if(o<0)return new D(r,n,NaN,e);for(;o>0;){if(o%2===1){const h=new D(r,n,0,e);for(let l=0;l<r;l++)for(let f=0;f<n;f++){let g=0;for(let p=0;p<r;p++)g+=s.matrix[l][p]*a.matrix[p][f];h.matrix[l][f]=g}s=h}const c=new D(r,n,0,e);for(let h=0;h<r;h++)for(let l=0;l<n;l++){let f=0;for(let g=0;g<r;g++)f+=a.matrix[h][g]*a.matrix[g][l];c.matrix[h][l]=f}a=c,o=Math.floor(o/2)}return s}}function La(e){return t=>{const i=t.matrix.length;if(i===0)return 0;const r=t.matrix[0].length,n=t.matrix.map(a=>[...a]);let s=0;for(let a=0;a<r&&s<i;a++){let o=s;for(;o<i&&Math.abs(n[o][a])<1e-10;)o++;if(o<i){[n[s],n[o]]=[n[o],n[s]];const c=n[s][a];for(let h=a;h<r;h++)n[s][h]/=c;for(let h=0;h<i;h++)if(h!==s){const l=n[h][a];for(let f=a;f<r;f++)n[h][f]-=l*n[s][f]}s++}}return s}}function Ba(e){return(t,i)=>{const r=t.matrix.length;if(r===0){const a=oe(t.matrix[0][0]);return new V([],a,e)}const n=[];for(let a=0;a<r;a++){const o=t.matrix[a].splice(i,1);n.push(o[0])}const s=oe(n[0]);return new V(n,s,e)}}function Fa(e){return(t,i)=>{const r=t.matrix.splice(i,1),n=oe(r[0][0]);return new V(r[0]||[],n,e)}}function ja(e){return(t,i,r)=>{const n=t.matrix.length,s=n>0?t.matrix[0].length:0,a=i*r,o=[];for(let l=0;l<n;l++)for(let f=0;f<s;f++)o.push(t.matrix[l][f]);for(;o.length<a;)o.push(NaN);o.length>a&&(o.length=a);const c=[];let h=0;for(let l=0;l<i;l++){const f=[];for(let g=0;g<r;g++)f.push(o[h++]);c.push(f)}t.matrix=c}}function $a(e){return t=>{t.matrix.reverse();for(const i of t.matrix)i.reverse()}}function Wa(e){return(t,i)=>{if(!t.matrix[i]){const n=oe(t.matrix[0][0]);return new V([],n,e)}const r=oe(t.matrix[i][0]);return new V([...t.matrix[i]],r,e)}}function qa(e){return t=>t.matrix.length}function Ua(e){return(t,i,r,n)=>{t.matrix[i]&&(t.matrix[i][r]=n)}}function Ka(e){return(t,i=0,r="asc")=>{t.matrix.length!==0&&t.matrix.sort((n,s)=>{const a=n[i],o=s[i];return a<o?r==="asc"?-1:1:a>o?r==="asc"?1:-1:0})}}function za(e){return(t,i,r,n,s)=>{const a=r-i,o=s-n,c=new D(a,o,NaN,e);for(let h=0;h<a;h++){const l=i+h;if(l>=t.matrix.length)break;for(let f=0;f<o;f++){const g=n+f;if(g>=t.matrix[l].length)break;c.matrix[h][f]=t.matrix[l][g]}}return c}}function Ha(e){return(t,i)=>{const r=t.matrix.length;if(r===0)return new D(0,0,NaN,e);const n=t.matrix[0].length,s=new D(r,n,NaN,e);if(i instanceof D)for(let a=0;a<r;a++)for(let o=0;o<n;o++){const c=t.matrix[a][o],h=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;s.matrix[a][o]=c+h}else{const a=i;for(let o=0;o<r;o++)for(let c=0;c<n;c++)s.matrix[o][c]=t.matrix[o][c]+a}return s}}function Ga(e){return(t,i,r)=>{const n=t.matrix.length;for(let s=0;s<n;s++){const a=t.matrix[s][i];t.matrix[s][i]=t.matrix[s][r],t.matrix[s][r]=a}}}function Ya(e){return(t,i,r)=>{const n=t.matrix[i];t.matrix[i]=t.matrix[r],t.matrix[r]=n}}function Qa(e){return t=>{const i=t.matrix.length;if(i===0)return 0;const r=t.matrix[0].length,n=Math.min(i,r);let s=0;for(let a=0;a<n;a++)s+=t.matrix[a][a];return s}}function Xa(e){return t=>{const i=t.matrix.length;if(i===0)return new D(0,0,NaN,e);const r=t.matrix[0].length,n=new D(r,i,NaN,e);for(let s=0;s<i;s++)for(let a=0;a<r;a++)n.matrix[a][s]=t.matrix[s][a];return n}}class D{constructor(t=0,i=0,r=NaN,n){if(this.context=n,this.matrix=[],t>0&&i>0)for(let s=0;s<t;s++)this.matrix.push(Array(i).fill(r));this._add_col=ta(this.context),this._add_row=ia(this.context),this._avg=ra(this.context),this._col=na(this.context),this._columns=sa(this.context),this._concat=aa(this.context),this._copy=oa(this.context),this._det=ha(this.context),this._diff=ua(this.context),this._eigenvalues=pa(this.context),this._eigenvectors=fa(this.context),this._elements_count=ma(this.context),this._fill=da(this.context),this._get=ga(this.context),this._inv=ya(this.context),this._is_antidiagonal=wa(this.context),this._is_antisymmetric=ba(this.context),this._is_binary=va(this.context),this._is_diagonal=_a(this.context),this._is_identity=Sa(this.context),this._is_square=Ea(this.context),this._is_stochastic=Na(this.context),this._is_symmetric=Ca(this.context),this._is_triangular=ka(this.context),this._is_zero=Ia(this.context),this._kron=Aa(this.context),this._max=Ta(this.context),this._median=Pa(this.context),this._min=Ra(this.context),this._mode=Da(this.context),this._mult=Ma(this.context),this._pinv=Va(this.context),this._pow=Oa(this.context),this._rank=La(this.context),this._remove_col=Ba(this.context),this._remove_row=Fa(this.context),this._reshape=ja(this.context),this._reverse=$a(this.context),this._row=Wa(this.context),this._rows=qa(this.context),this._set=Ua(this.context),this._sort=Ka(this.context),this._submatrix=za(this.context),this._sum=Ha(this.context),this._swap_columns=Ga(this.context),this._swap_rows=Ya(this.context),this._trace=Qa(this.context),this._transpose=Xa(this.context)}matrix;_add_col;_add_row;_avg;_col;_columns;_concat;_copy;_det;_diff;_eigenvalues;_eigenvectors;_elements_count;_fill;_get;_inv;_is_antidiagonal;_is_antisymmetric;_is_binary;_is_diagonal;_is_identity;_is_square;_is_stochastic;_is_symmetric;_is_triangular;_is_zero;_kron;_max;_median;_min;_mode;_mult;_pinv;_pow;_rank;_remove_col;_remove_row;_reshape;_reverse;_row;_rows;_set;_sort;_submatrix;_sum;_swap_columns;_swap_rows;_trace;_transpose;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 Za(e){return(t,i,r)=>new D(t,i,r,e)}function Ja(e){return(t,i=0)=>d.from(t).get(i)}class eo{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=Za(t),this.param=Ja(),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)}}class to{constructor(t){this.context=t}_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 ni={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 Vt(e,t,i){Array.isArray(t)&&typeof t[0]=="string"&&(t=[t]);const r={};let n={};const s=new Array(t.length).fill(!0);for(let a=0;a<e.length;a++){const o=e[a];if(ni.remaining_options(o)){n=o;break}const c=t.map((h,l)=>s[l]?h[a]:void 0);for(let h=0;h<c.length;h++){const l=c[h];if(l===void 0){s[h]=!1;continue}const f=ni[i[l]];typeof f=="function"&&f(o)?r[l]=o:s[h]=!1}}return{...n,...r}}const io=["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"],ro={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 no(e){return Vt(e,io,ro)}class so{constructor(t){this.context=t}color={param:(t,i=0)=>d.from(t).get(i),rgb:(t,i,r,n)=>n?`rgba(${t}, ${i}, ${r}, ${n})`:`rgb(${t}, ${i}, ${r})`,new:(t,i)=>{if(t&&t.startsWith("#")){const r=t.slice(1),n=parseInt(r.slice(0,2),16),s=parseInt(r.slice(2,4),16),a=parseInt(r.slice(4,6),16);return i?`rgba(${n}, ${s}, ${a}, ${i})`:`rgb(${n}, ${s}, ${a})`}return i?`rgba(${t}, ${i})`:t},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=no(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),n=d.from(i).get(0);return isNaN(r)?n:r}fixnan(t){const i=d.from(t);for(let r=0;r<i.length;r++){const n=i.get(r);if(!isNaN(n))return n}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 ao=[["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"]],oo={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function Y(e){return Vt(e,ao,oo)}function co(e){return(...t)=>Y(t).defval}function ho(e){return(...t)=>Y(t).defval}function uo(e){return(...t)=>Y(t).defval}function lo(e){return(...t)=>Y(t).defval}function po(e){return(...t)=>Y(t).defval}function fo(e){return(...t)=>Y(t).defval}function mo(e){return(t,i=0)=>d.from(t).get(i)}function go(e){return(...t)=>Y(t).defval}function xo(e){return(...t)=>Y(t).defval}function yo(e){return(...t)=>Y(t).defval}function wo(e){return(...t)=>Y(t).defval}function bo(e){return(...t)=>Y(t).defval}function vo(e){return(...t)=>Y(t).defval}function _o(e){return(...t)=>Y(t).defval}function So(e){return(...t)=>Y(t).defval}const Eo={any:co,bool:ho,color:uo,enum:lo,float:po,int:fo,param:mo,price:go,session:xo,source:yo,string:wo,symbol:bo,text_area:vo,time:_o,timeframe:So};class No{constructor(t){this.context=t,Object.entries(Eo).forEach(([i,r])=>{this[i]=r(t)})}any;bool;color;enum;float;int;param;price;session;source;string;symbol;text_area;time;timeframe}function Co(e){return t=>Math.abs(d.from(t).get(0))}function ko(e){return t=>Math.acos(d.from(t).get(0))}function Io(e){return t=>Math.asin(d.from(t).get(0))}function Ao(e){return t=>Math.atan(d.from(t).get(0))}function To(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return i.reduce((r,n)=>r+n,0)/i.length}}function Po(e){return t=>Math.ceil(d.from(t).get(0))}function Ro(e){return t=>Math.cos(d.from(t).get(0))}function Do(e){return()=>Math.E}function Mo(e){return t=>Math.exp(d.from(t).get(0))}function Vo(e){return t=>Math.floor(d.from(t).get(0))}function Oo(e){return t=>Math.log(d.from(t).get(0))}function Lo(e){return t=>Math.log(d.from(t).get(0))}function Bo(e){return t=>Math.log10(d.from(t).get(0))}function Fo(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.max(...i)}}function jo(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.min(...i)}}function $o(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 Wo(e){return()=>1.618033988749895}function qo(e){return()=>Math.PI}function Uo(e){return(t,i)=>Math.pow(d.from(t).get(0),d.from(i).get(0))}function Ko(e){return()=>Math.random()}function zo(e){return t=>Math.round(d.from(t).get(0))}function Ho(e){return t=>e.precision(Math.round(d.from(t).get(0)/e.pine.syminfo.mintick)*e.pine.syminfo.mintick)}function Go(e){return()=>.6180339887498948}function Yo(e){return t=>Math.sign(d.from(t).get(0))}function Qo(e){return t=>Math.sin(d.from(t).get(0))}function Xo(e){return t=>Math.sqrt(d.from(t).get(0))}function Zo(e){return(t,i)=>{const r=d.from(i).get(0),n=d.from(t);let s=0;for(let a=0;a<r;a++){const o=n.get(a);s+=o}return s}}function Jo(e){return t=>Math.tan(d.from(t).get(0))}function ec(e){return(t,i)=>{const r=d.from(t).get(0),n=d.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)&&isNaN(n)?!0:isNaN(r)||isNaN(n)?!1:Math.abs(r-n)<1e-8:r===n}}const tc={abs:Co,acos:ko,asin:Io,atan:Ao,avg:To,ceil:Po,cos:Ro,e:Do,exp:Mo,floor:Vo,ln:Oo,log:Lo,log10:Bo,max:Fo,min:jo,param:$o,phi:Wo,pi:qo,pow:Uo,random:Ko,round:zo,round_to_mintick:Ho,rphi:Go,sign:Yo,sin:Qo,sqrt:Xo,sum:Zo,tan:Jo,__eq:ec};class ic{constructor(t){this.context=t,Object.entries(tc).forEach(([i,r])=>{this[i]=r(t)})}_cache={};abs;acos;asin;atan;avg;ceil;cos;e;exp;floor;ln;log;log10;max;min;param;phi;pi;pow;random;round;round_to_mintick;rphi;sign;sin;sqrt;sum;tan;__eq}function rc(e){return(t,i,r)=>{e.params[r]||(e.params[r]=[]);let n;if(t instanceof d)n=t.get(i||0);else if(Array.isArray(t)){const s=t.every(o=>o instanceof d),a=t.every(o=>!(o instanceof d)&&!Array.isArray(o));(s||a)&&t.length>=1?s?n=t.map(o=>o.get(0)):n=t:n=d.from(t).get(i||0)}else n=t;return e.params[r].length===0?e.params[r].push(n):e.params[r][e.params[r].length-1]=n,[n,r]}}const it=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function si(e,t,i,r,n=!1){for(let s=0;s<i.length;s++)if(i[s]<=e&&t<=r[s])return n||t>=r[s]?s:s-1;return-1}function ai(e,t,i,r,n=!1,s,a=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=t&&i[o]>=e){const c=s&&t>s;if(a&&n)for(let h=0;h<i.length;h++){if(i[h]>=e&&i[h]<t)return h;if(i[h]>=t)break}if(c&&n&&!a)for(let h=0;h<i.length;h++){if(i[h]>=e&&i[h]<t)return h;if(i[h]>=t)break}return o}if(r[o]<e)break}return-1}function nc(e){return async(t,i,r,n=!1,s=!1,a=!1,o=null,c=null)=>{const h=t[0],l=i[0],f=r[0],g=r[1],p=Array.isArray(n)?n[0]:n,x=Array.isArray(s)?s[0]:s;if(e.isSecondaryContext)return f;const y=it.indexOf(e.timeframe),w=it.indexOf(l);if(y==-1||w==-1)throw new Error("Invalid timeframe");if(y===w)return f;const S=y>w,k=d.from(e.data.openTime).get(0),C=d.from(e.data.closeTime).get(0),A=`${h}_${l}_${g}`,N=`${A}_prevIdx`;if(e.cache[A]){const Be=e.cache[A],Ye=S?ai(k,C,Be.data.openTime.data,Be.data.closeTime.data,x,e.eDate,p):si(k,C,Be.data.openTime.data,Be.data.closeTime.data,x);if(Ye==-1)return NaN;const Ce=Be.params[g][Ye];if(!S&&p){const Lt=e.cache[N];return Lt!==void 0&&Lt===Ye?NaN:(e.cache[N]=Ye,Array.isArray(Ce)?[Ce]:Ce)}return Array.isArray(Ce)?[Ce]:Ce}const q=1e3*60*60*24*30,W=e.sDate?e.sDate-q:void 0,j=e.sDate&&e.eDate?void 0:e.limit||1e3,Le=new Ot(e.source,h,l,j,W,void 0);Le.markAsSecondary();const de=await Le.run(e.pineTSCode);e.cache[A]=de;const ct=S?ai(k,C,de.data.openTime.data,de.data.closeTime.data,x,e.eDate,p):si(k,C,de.data.openTime.data,de.data.closeTime.data,x);if(ct==-1)return NaN;const ht=de.params[g][ct];return!S&&p?(e.cache[N]=ct,NaN):Array.isArray(ht)?[ht]:ht}}function sc(e){return async(t,i,r,n=!1,s=null,a=!1,o=0)=>{const c=t[0],h=i[0],l=r[0],f=r[1];Array.isArray(n)&&n[0];const g=Array.isArray(a)?a[0]:a;if(e.isSecondaryContext)return Array.isArray(l)?[l]:l;const p=it.indexOf(e.timeframe),x=it.indexOf(h);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 ${h} is not lower than or equal to chart timeframe ${e.timeframe}`)}if(x===p)return[[l]];const y=`${c}_${h}_${f}_lower`;if(!e.cache[y]){const W=e.sDate?e.sDate-2592e6:void 0,j=e.sDate&&e.eDate?void 0:e.limit||1e3,Le=new Ot(e.source,c,h,j,W,e.eDate);Le.markAsSecondary();const de=await Le.run(e.pineTSCode);e.cache[y]=de}const w=e.cache[y],S=d.from(e.data.openTime).get(0),k=d.from(e.data.closeTime).get(0),C=w.data.openTime.data,A=w.data.closeTime.data,N=w.params[f];if(!N)return[];const q=[];for(let W=0;W<C.length;W++){const j=C[W];if(!(A[W]<=S)){if(j>=k)break;j>=S&&j<k&&q.push(N[W])}}return[q]}}const ac={param:rc,security:nc,security_lower_tf:sc};class oc{constructor(t){this.context=t,Object.entries(ac).forEach(([i,r])=>{this[i]=r(t)})}_cache={};param;security;security_lower_tf}function cc(e){return t=>{e.taState||(e.taState={});const i=t||"accdist";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.volume,0);if(isNaN(n)||isNaN(s)||isNaN(a)||isNaN(o))return e.precision(r.cumulativeSum);const c=s-a;let h=0;return c!==0&&(h=(n-a-(s-n))/c*o),r.cumulativeSum+=h,e.precision(r.cumulativeSum)}}function hc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0),c=d.from(n).get(0);e.taState||(e.taState={});const h=s||`alma_${a}_${o}_${c}`;if(!e.taState[h]){const p=o*(a-1),x=a/c,y=[];let w=0;for(let S=0;S<a;S++){const k=Math.exp(-Math.pow(S-p,2)/(2*x*x));y.push(k),w+=k}for(let S=0;S<y.length;S++)y[S]/=w;e.taState[h]={window:[],weights:y}}const l=e.taState[h],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 uc(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const n=i||`atr_${r}`;e.taState[n]||(e.taState[n]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const s=e.taState[n],a=e.get(e.data.high,0),o=e.get(e.data.low,0),c=e.get(e.data.close,0);let h;if(s.prevClose!==null){const f=a-o,g=Math.abs(a-s.prevClose),p=Math.abs(o-s.prevClose);h=Math.max(f,g,p)}else h=a-o;if(s.prevClose=c,s.initCount<r)return s.initSum+=h,s.initCount++,s.initCount===r?(s.prevAtr=s.initSum/r,e.precision(s.prevAtr)):NaN;const l=(s.prevAtr*(r-1)+h)/r;return s.prevAtr=l,e.precision(l)}}function lc(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"barssince";e.taState[r]||(e.taState[r]={lastTrueIndex:null});const n=e.taState[r];return d.from(t).get(0)?(n.lastTrueIndex=e.idx,0):n.lastTrueIndex===null?NaN:e.idx-n.lastTrueIndex}}function pc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`bb_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],h=d.from(t).get(0);if(isNaN(h))return[[NaN,NaN,NaN]];if(c.window.unshift(h),c.sum+=h,c.window.length<s)return[[NaN,NaN,NaN]];if(c.window.length>s){const y=c.window.pop();c.sum-=y}const l=c.sum/s;let f=0;for(let y=0;y<s;y++)f+=Math.pow(c.window[y]-l,2);const g=Math.sqrt(f/s),p=l+a*g,x=l-a*g;return[[e.precision(p),e.precision(l),e.precision(x)]]}}function fc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`bbw_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],h=d.from(t).get(0);if(isNaN(h))return NaN;if(c.window.unshift(h),c.sum+=h,c.window.length<s)return NaN;if(c.window.length>s){const w=c.window.pop();c.sum-=w}const l=c.sum/s;let f=0;for(let w=0;w<s;w++){const S=c.window[w]-l;f+=S*S}const g=f/s,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 mc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`cci_${n}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=d.from(t).get(0);if(isNaN(o))return NaN;if(a.window.unshift(o),a.sum+=o,a.window.length<n)return NaN;if(a.window.length>n){const g=a.window.pop();a.sum-=g}const c=a.sum/n;let h=0;for(let g=0;g<n;g++)h+=Math.abs(a.window[g]-c);const l=h/n;if(l===0)return 0;const f=(o-c)/(.015*l);return e.precision(f)}}function dc(e){return(t,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`change_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=n)return NaN;a.window.length>n+1&&a.window.pop();const c=o-a.window[n];return e.precision(c)}}function gc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`cmo_${n}`;e.taState[s]||(e.taState[s]={gainsWindow:[],lossesWindow:[],gainsSum:0,lossesSum:0});const a=e.taState[s],o=d.from(t).get(0),c=d.from(t).get(1);if(isNaN(o)||isNaN(c))return NaN;const h=o-c,l=h>=0?h:0,f=h>=0?0:-h;if(a.gainsWindow.unshift(l),a.lossesWindow.unshift(f),a.gainsSum+=l,a.lossesSum+=f,a.gainsWindow.length<n)return NaN;if(a.gainsWindow.length>n){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 xc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);let a=0,o=!1;for(let l=0;l<n;l++){const f=s.get(l);if(isNaN(f)){o=!0;break}a+=f}if(o)return NaN;let c=0;for(let l=0;l<n;l++){const f=s.get(l);c+=f*(l+1)}if(a===0)return NaN;const h=-c/a;return e.precision(h)}}function yc(e){return(t,i,r,n)=>{const s=d.from(r).get(0),a=d.from(t),o=d.from(i);if(e.idx<s-1)return NaN;let c=0,h=0,l=0,f=0,g=0,p=0;for(let k=0;k<s;k++){const C=a.get(k),A=o.get(k);isNaN(C)||isNaN(A)||(c+=C,h+=A,l+=C*A,f+=C*C,g+=A*A,p++)}if(p<2)return NaN;const x=p*l-c*h,y=p*f-c*c,w=p*g-h*h;if(y<=0||w<=0)return e.precision(0);const S=x/Math.sqrt(y*w);return e.precision(S)}}function wc(e){return(t,i,r)=>{const n=d.from(t),s=d.from(i),a=n.get(0),o=s.get(0),c=n.get(1),h=s.get(1);if(isNaN(a)||isNaN(o)||isNaN(c)||isNaN(h))return!1;const l=a>o&&c<=h,f=a<o&&c>=h;return l||f}}function bc(e){return(t,i)=>{const r=d.from(t),n=d.from(i),s=r.get(0),a=n.get(0),o=r.get(1),c=n.get(1);return o<c&&s>a}}function vc(e){return(t,i)=>{const r=d.from(t),n=d.from(i),s=r.get(0),a=n.get(0),o=r.get(1),c=n.get(1);return o>c&&s<a}}function _c(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"cum";e.taState[r]||(e.taState[r]={cumulativeSum:0});const n=e.taState[r],s=d.from(t).get(0);return isNaN(s)||(n.cumulativeSum+=s),e.precision(n.cumulativeSum)}}function Sc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`dev_${n}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<n)return NaN;if(a.window.length>n){const f=a.window.pop();a.sum-=f}const c=a.sum/n;let h=0;for(let f=0;f<n;f++)h+=Math.abs(a.window[f]-c);const l=h/n;return e.precision(l)}}function Ec(e){return(t,i,r)=>{const n=d.from(t).get(0),s=d.from(i).get(0);e.taState||(e.taState={});const a=r||`dmi_${n}_${s}`;e.taState[a]||(e.taState[a]={prevHigh:NaN,prevLow:NaN,prevClose:NaN,trInitSum:0,plusInitSum:0,minusInitSum:0,initCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,dxInitSum:0,adxInitCount:0,prevADX:NaN});const o=e.taState[a],c=e.get(e.data.high,0),h=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(c)||isNaN(h)||isNaN(l))return[[NaN,NaN,NaN]];if(isNaN(o.prevHigh))return o.prevHigh=c,o.prevLow=h,o.prevClose=l,[[NaN,NaN,NaN]];const f=Math.max(c-h,Math.abs(c-o.prevClose),Math.abs(h-o.prevClose)),g=c-o.prevHigh,p=o.prevLow-h,x=g>p&&g>0?g:0,y=p>g&&p>0?p:0;o.prevHigh=c,o.prevLow=h,o.prevClose=l;let w,S,k;if(o.initCount++,o.initCount<=n)o.trInitSum+=f,o.plusInitSum+=x,o.minusInitSum+=y,o.initCount===n&&(o.prevSmoothedTR=o.trInitSum/n,o.prevSmoothedPlus=o.plusInitSum/n,o.prevSmoothedMinus=o.minusInitSum/n);else{const j=1/n;o.prevSmoothedTR=j*f+(1-j)*o.prevSmoothedTR,o.prevSmoothedPlus=j*x+(1-j)*o.prevSmoothedPlus,o.prevSmoothedMinus=j*y+(1-j)*o.prevSmoothedMinus}if(w=o.prevSmoothedTR,S=o.prevSmoothedPlus,k=o.prevSmoothedMinus,o.initCount<n)return[[NaN,NaN,NaN]];const C=w===0?0:100*S/w,A=w===0?0:100*k/w,N=C+A,q=N===0?0:100*Math.abs(C-A)/N;let W=NaN;if(o.adxInitCount++,o.adxInitCount<=s)o.dxInitSum+=q,o.adxInitCount===s&&(o.prevADX=o.dxInitSum/s,W=o.prevADX);else{const j=1/s;o.prevADX=j*q+(1-j)*o.prevADX,W=o.prevADX}return[[e.precision(C),e.precision(A),e.precision(W)]]}}function Nc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`ema_${n}`;e.taState[s]||(e.taState[s]={prevEma:null,initSum:0,initCount:0});const a=e.taState[s],o=d.from(t).get(0);if(a.initCount<n)return a.initSum+=o,a.initCount++,a.initCount===n?(a.prevEma=a.initSum/n,e.precision(a.prevEma)):NaN;const c=2/(n+1),h=o*c+a.prevEma*(1-c);return a.prevEma=h,e.precision(h)}}function Cc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);for(let a=0;a<n;a++){const o=s.get(a),c=s.get(a+1);if(isNaN(o)||isNaN(c)||o>=c)return!1}return!0}}function kc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`highest_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();const c=Math.max(...a.window.filter(h=>!isNaN(h)));return e.precision(c)}}function Ic(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n-1)return NaN;let a=-1/0,o=NaN;for(let c=0;c<n;c++){const h=s.get(c);isNaN(h)||(isNaN(o)||h>a)&&(a=h,o=-c)}return o}}function Ac(e){return(t,i,r)=>{const n=d.from(i).get(0),s=Math.floor(n/2),a=Math.floor(Math.sqrt(n)),o=e.ta.wma,c=o(t,s,r?`${r}_wma1`:void 0),h=o(t,n,r?`${r}_wma2`:void 0);if(isNaN(c)||isNaN(h))return NaN;e.taState||(e.taState={});const l=r||`hma_raw_${n}`;e.taState[l]||(e.taState[l]=[]);const f=2*c-h;e.taState[l].unshift(f);const g=r?`${r}_hma_final`:`hma_final_${n}`;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 S=0;S<a;S++){const k=a-S;x+=p.window[S]*k,y+=k}const w=x/y;return e.precision(w)}}function Tc(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.high,0),n=e.get(e.data.low,0),s=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(s))return NaN;const a=(r-n)*s;if(a===0)return e.precision(0);const o=(2*i-r-n)/a;return e.precision(o)}}function Pc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let c=!0;typeof n=="string"?s=n:n!==void 0&&(c=d.from(n).get(0));let h;const l=e.get(e.data.high,0),f=e.get(e.data.low,0);if(c){const A=e.get(e.data.close,1);isNaN(A)?h=NaN:h=Math.max(l-f,Math.abs(l-A),Math.abs(f-A))}else h=l-f;const g=d.from(t).get(0);e.taState||(e.taState={});const p=s||`kc_${a}_${o}_${c}`;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=(A,N,q)=>{if(isNaN(N))return NaN;if(A.initCount<q)return A.initSum+=N,A.initCount++,A.initCount===q?(A.prevEma=A.initSum/q,A.prevEma):NaN;const W=2/(q+1);return A.prevEma=N*W+A.prevEma*(1-W),A.prevEma},w=y(x.basisState,g,a),S=y(x.rangeState,h,a);if(isNaN(w)||isNaN(S))return[[NaN,NaN,NaN]];const k=w+S*o,C=w-S*o;return[[e.precision(w),e.precision(k),e.precision(C)]]}}function Rc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let c=!0;typeof n=="string"?s=n:n!==void 0&&(c=d.from(n).get(0)),e.taState||(e.taState={});const h=s||`kcw_${a}_${o}_${c}`;e.taState[h]||(e.taState[h]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const l=e.taState[h],f=(C,A,N)=>{if(isNaN(A))return NaN;if(C.initCount<N)return C.initSum+=A,C.initCount++,C.initCount===N?(C.prevEma=C.initSum/N,C.prevEma):NaN;const q=2/(N+1);return C.prevEma=A*q+C.prevEma*(1-q),C.prevEma};let g;const p=e.get(e.data.high,0),x=e.get(e.data.low,0);if(c){const C=e.get(e.data.close,1);isNaN(C)?g=NaN:g=Math.max(p-x,Math.abs(p-C),Math.abs(x-C))}else g=p-x;const y=d.from(t).get(0),w=f(l.basisState,y,a),S=f(l.rangeState,g,a);if(isNaN(w)||isNaN(S))return NaN;if(w===0)return e.precision(0);const k=2*S*o/w;return e.precision(k)}}function Dc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`linreg_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[]});const c=e.taState[o],h=d.from(t).get(0);if(c.window.unshift(h),c.window.length<s)return NaN;c.window.length>s&&c.window.pop();let l=0,f=0,g=0,p=0;const x=s;for(let k=0;k<s;k++){const C=s-1-k,A=c.window[k];l+=C,f+=A,g+=C*A,p+=C*C}const y=x*p-l*l;if(y===0)return NaN;const w=(x*g-l*f)/y,S=(f-w*l)/x+w*(s-1-a);return e.precision(S)}}function Mc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`lowest_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();const c=a.window.filter(l=>!isNaN(l)&&l!==void 0),h=c.length>0?Math.min(...c):NaN;return e.precision(h)}}function Vc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n-1)return NaN;let a=1/0,o=NaN;for(let c=0;c<n;c++){const h=s.get(c);isNaN(h)||(isNaN(o)||h<a)&&(a=h,o=-c)}return o}}function Oc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0),c=d.from(n).get(0),h=s||`macd_${a}_${o}_${c}`,l=`${h}_fast`,f=`${h}_slow`,g=`${h}_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,c,g));let S=NaN;return!isNaN(y)&&!isNaN(w)&&(S=y-w),[[e.precision(y),e.precision(w),e.precision(S)]]}}function Lc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`median_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();const c=a.window.slice().sort((f,g)=>f-g),h=Math.floor(n/2),l=n%2===0?(c[h-1]+c[h])/2:c[h];return e.precision(l)}}function Bc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`mfi_${n}`;e.taState[s]||(e.taState[s]={upperWindow:[],lowerWindow:[],upperSum:0,lowerSum:0});const a=e.taState[s],o=d.from(t).get(0),c=d.from(t).get(1),h=e.get(e.data.volume,0);if(isNaN(o)||isNaN(h))return NaN;const l=isNaN(c)?NaN:o-c;let f=0,g=0;if(f=h*(l<=0?0:o),g=h*(l>=0?0:o),a.upperWindow.unshift(f),a.lowerWindow.unshift(g),a.upperSum+=f,a.lowerSum+=g,a.upperWindow.length<n)return NaN;if(a.upperWindow.length>n){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 Fc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n-1)return NaN;const a=new Map;for(let h=0;h<n;h++){const l=s.get(h);isNaN(l)||a.set(l,(a.get(l)||0)+1)}if(a.size===0)return NaN;let o=NaN,c=-1;for(const[h,l]of a.entries())l>c?(c=l,o=h):l===c&&h<o&&(o=h);return o}}function jc(e){return(t,i,r)=>{const n=d.from(i).get(0);return e.ta.change(t,n)}}function $c(e){return t=>{e.taState||(e.taState={});const i=t||"nvi";e.taState[i]||(e.taState[i]={nvi:1});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),c=isNaN(n)?0:n,h=isNaN(s)?0:s,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(c===0||h===0)&&l<f){const g=(c-h)/h;r.nvi=r.nvi+g*r.nvi}return e.precision(r.nvi)}}function Wc(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),n=e.get(e.data.volume,0),s=e.get(e.data.close,1);if(isNaN(s))return i.prevOBV=0,e.precision(0);let a;return r>s?a=i.prevOBV+n:r<s?a=i.prevOBV-n:a=i.prevOBV,i.prevOBV=a,e.precision(a)}}function qc(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 Uc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<s-1)return NaN;const c=[];for(let x=0;x<s;x++){const y=o.get(x);if(isNaN(y))return NaN;c.push(y)}c.sort((x,y)=>x-y);let h=a/100*s-.5;h<0&&(h=0),h>s-1&&(h=s-1);const l=Math.floor(h),f=Math.ceil(h);if(l===f)return e.precision(c[l]);const g=h-l,p=c[l]+g*(c[f]-c[l]);return e.precision(p)}}function Kc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<s-1)return NaN;const c=[];for(let l=0;l<s;l++){const f=o.get(l);isNaN(f)||c.push(f)}if(c.length===0)return NaN;c.sort((l,f)=>l-f);let h=Math.ceil(a/100*c.length)-1;return h<0&&(h=0),h>=c.length&&(h=c.length-1),e.precision(c[h])}}function zc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n)return NaN;const a=s.get(0);if(isNaN(a))return NaN;let o=0,c=0;for(let h=1;h<=n;h++){const l=s.get(h);isNaN(l)||(c++,l<=a&&o++)}return c===0?NaN:e.precision(o/c*100)}}function Hc(e,t,i){const r=new Array(e.length).fill(NaN);for(let n=t+i;n<e.length;n++){const s=e[n-i];let a=!0;for(let o=1;o<=t;o++)if(e[n-i-o]>=s){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[n-i+o]>=s){a=!1;break}}a&&(r[n]=s)}return r}function Gc(e){return(t,i,r,n)=>{typeof r=="string"&&(r=i,i=t,t=e.data.high);const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),c=Hc(o,s,a),h=e.idx;return e.precision(c[h])}}function Yc(e,t,i){const r=new Array(e.length).fill(NaN);for(let n=t+i;n<e.length;n++){const s=e[n-i];let a=!0;for(let o=1;o<=t;o++)if(e[n-i-o]<=s){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[n-i+o]<=s){a=!1;break}}a&&(r[n]=s)}return r}function Qc(e){return(t,i,r,n)=>{typeof r=="string"&&(r=i,i=t,t=e.data.low);const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),c=Yc(o,s,a),h=e.idx;return e.precision(c[h])}}function Xc(e){return t=>{e.taState||(e.taState={});const i=t||"pvi";e.taState[i]||(e.taState[i]={pvi:1});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),c=isNaN(n)?0:n,h=isNaN(s)?0:s,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(c===0||h===0)&&l>f){const g=(c-h)/h;r.pvi=r.pvi+g*r.pvi}return e.precision(r.pvi)}}function Zc(e){return t=>{e.taState||(e.taState={});const i=t||"pvt";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.close,1),a=e.get(e.data.volume,0);if(!isNaN(n)&&!isNaN(s)&&!isNaN(a)&&s!==0){const o=(n-s)/s*a;r.cumulativeSum+=o}return e.precision(r.cumulativeSum)}}function Jc(e){return(t,i,r)=>{const n=e.pine.ta.highest(t,i,(r||"range")+"_h"),s=e.pine.ta.lowest(t,i,(r||"range")+"_l");return isNaN(n)||isNaN(s)?NaN:e.precision(n-s)}}function eh(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);for(let a=0;a<n;a++){const o=s.get(a),c=s.get(a+1);if(isNaN(o)||isNaN(c)||o<=c)return!1}return!0}}function th(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`rma_${n}`;e.taState[s]||(e.taState[s]={prevRma:null,initSum:0,initCount:0});const a=e.taState[s],o=d.from(t).get(0)||0;if(a.initCount<n)return a.initSum+=o,a.initCount++,a.initCount===n?(a.prevRma=a.initSum/n,e.precision(a.prevRma)):NaN;const c=1/n,h=o*c+a.prevRma*(1-c);return a.prevRma=h,e.precision(h)}}function ih(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`roc_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=n)return NaN;a.window.length>n+1&&a.window.pop();const c=a.window[n],h=(o-c)/c*100;return e.precision(h)}}function rh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`rsi_${n}`;e.taState[s]||(e.taState[s]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.prevValue!==null){const c=o-a.prevValue,h=c>0?c:0,l=c<0?-c:0;if(a.initGains.length<n){if(a.initGains.push(h),a.initLosses.push(l),a.initGains.length===n){a.avgGain=a.initGains.reduce((p,x)=>p+x,0)/n,a.avgLoss=a.initLosses.reduce((p,x)=>p+x,0)/n,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*(n-1)+h)/n,a.avgLoss=(a.avgLoss*(n-1)+l)/n;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 nh(e){return(t,i,r,n)=>{const s=d.from(t).get(0),a=d.from(i).get(0),o=d.from(r).get(0);e.taState||(e.taState={});const c=n||`sar_${s}_${a}_${o}`;e.taState[c]||(e.taState[c]={result:NaN,maxMin:NaN,acceleration:NaN,isBelow:!1,barIndex:0});const h=e.taState[c],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),S=e.get(e.data.low,2);if(isNaN(l)||isNaN(f)||isNaN(g))return NaN;let k=!1;return h.barIndex===1&&(g>p?(h.isBelow=!0,h.maxMin=l,h.result=y):(h.isBelow=!1,h.maxMin=f,h.result=x),k=!0,h.acceleration=s),h.barIndex>=1&&(h.result=h.result+h.acceleration*(h.maxMin-h.result),h.isBelow?h.result>f&&(k=!0,h.isBelow=!1,h.result=Math.max(l,h.maxMin),h.maxMin=f,h.acceleration=s):h.result<l&&(k=!0,h.isBelow=!0,h.result=Math.min(f,h.maxMin),h.maxMin=l,h.acceleration=s),k||(h.isBelow?l>h.maxMin&&(h.maxMin=l,h.acceleration=Math.min(h.acceleration+a,o)):f<h.maxMin&&(h.maxMin=f,h.acceleration=Math.min(h.acceleration+a,o))),h.isBelow?(h.result=Math.min(h.result,y),h.barIndex>1&&(h.result=Math.min(h.result,S))):(h.result=Math.max(h.result,x),h.barIndex>1&&(h.result=Math.max(h.result,w)))),h.barIndex++,h.barIndex<=1?NaN:e.precision(h.result)}}function sh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`sma_${n}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<n)return NaN;if(a.window.length>n){const h=a.window.pop();a.sum-=h}const c=a.sum/n;return e.precision(c)}}function ah(e){return(t,i,r=!0,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`stdev_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],h=d.from(t).get(0);if(c.window.unshift(h),c.sum+=h,c.window.length<s)return NaN;if(c.window.length>s){const x=c.window.pop();c.sum-=x}const l=c.sum/s;let f=0;for(let x=0;x<s;x++)f+=Math.pow(c.window[x]-l,2);const g=a?s:s-1,p=Math.sqrt(f/g);return e.precision(p)}}function oh(e){return(t,i,r,n,s)=>{const a=d.from(n).get(0);e.taState||(e.taState={});const o=s||`stoch_${a}`;e.taState[o]||(e.taState[o]={highWindow:[],lowWindow:[]});const c=e.taState[o],h=d.from(t).get(0),l=d.from(i).get(0),f=d.from(r).get(0);if(isNaN(h)||isNaN(l)||isNaN(f))return NaN;if(c.highWindow.unshift(l),c.lowWindow.unshift(f),c.highWindow.length<a)return NaN;c.highWindow.length>a&&(c.highWindow.pop(),c.lowWindow.pop());let g=c.highWindow[0],p=c.lowWindow[0];for(let w=1;w<a;w++)c.highWindow[w]>g&&(g=c.highWindow[w]),c.lowWindow[w]<p&&(p=c.lowWindow[w]);const x=g-p;if(x===0)return NaN;const y=100*(h-p)/x;return e.precision(y)}}function ch(e){return(t,i,r)=>{const n=d.from(t).get(0),s=d.from(i).get(0);e.taState||(e.taState={});const a=r||`supertrend_${n}_${s}`;e.taState[a]||(e.taState[a]={trWindow:[],trSum:0,atrValue:NaN,atrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,prevClose:NaN});const o=e.taState[a],c=e.get(e.data.high,0),h=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(c)||isNaN(h)||isNaN(l))return[[NaN,NaN]];const f=(c+h)/2;let g;isNaN(o.prevClose)?g=c-h:g=Math.max(c-h,Math.abs(c-o.prevClose),Math.abs(h-o.prevClose)),o.atrCount++,o.atrCount<=s?(o.trWindow.push(g),o.trSum+=g,o.atrCount===s&&(o.atrValue=o.trSum/s)):o.atrValue=(o.atrValue*(s-1)+g)/s;const p=o.atrValue,x=o.prevClose;if(o.prevClose=l,isNaN(p))return[[NaN,NaN]];let y=f+n*p,w=f-n*p;const S=isNaN(o.prevLowerBand)?0:o.prevLowerBand,k=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>S||x<S||(w=S),isNaN(o.prevUpperBand)||y<k||x>k||(y=k);let C,A;const N=o.prevSuperTrend;return o.atrCount===s?C=1:N===o.prevUpperBand?C=l>y?-1:1:C=l<w?1:-1,A=C===-1?w:y,o.prevLowerBand=w,o.prevUpperBand=y,o.prevSuperTrend=A,o.prevDirection=C,[[e.precision(A),C]]}}function hh(e){return(t,i)=>{const r=[1,2,2,1],n=6;e.taState||(e.taState={});const s=i||"swma";e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],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 c=0;for(let h=0;h<4;h++)c+=r[h]*a.window[3-h];return c/=n,e.precision(c)}}function uh(e){return(t,i)=>{let r=!0;typeof t=="string"||t!==void 0&&(r=d.from(t).get(0));const n=e.get(e.data.high,0),s=e.get(e.data.low,0),a=e.get(e.data.close,1);if(isNaN(a))return r?e.precision(n-s):NaN;const o=Math.max(n-s,Math.abs(n-a),Math.abs(s-a));return e.precision(o)}}function lh(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`tsi_${s}_${a}`;e.taState[o]||(e.taState[o]={prevSource:NaN,ema1_pc_multiplier:2/(a+1),ema1_pc_value:NaN,ema1_pc_count:0,ema1_pc_sum:0,ema2_pc_multiplier:2/(s+1),ema2_pc_value:NaN,ema2_pc_count:0,ema2_pc_sum:0,ema1_abs_multiplier:2/(a+1),ema1_abs_value:NaN,ema1_abs_count:0,ema1_abs_sum:0,ema2_abs_multiplier:2/(s+1),ema2_abs_value:NaN,ema2_abs_count:0,ema2_abs_sum:0});const c=e.taState[o],h=d.from(t).get(0);if(isNaN(h))return NaN;const l=isNaN(c.prevSource)?NaN:h-c.prevSource;if(c.prevSource=h,isNaN(l))return NaN;const f=Math.abs(l);if(c.ema1_pc_count++,c.ema1_pc_count<=a?(c.ema1_pc_sum+=l,c.ema1_pc_count===a&&(c.ema1_pc_value=c.ema1_pc_sum/a)):c.ema1_pc_value=l*c.ema1_pc_multiplier+c.ema1_pc_value*(1-c.ema1_pc_multiplier),c.ema1_abs_count++,c.ema1_abs_count<=a?(c.ema1_abs_sum+=f,c.ema1_abs_count===a&&(c.ema1_abs_value=c.ema1_abs_sum/a)):c.ema1_abs_value=f*c.ema1_abs_multiplier+c.ema1_abs_value*(1-c.ema1_abs_multiplier),isNaN(c.ema1_pc_value)||isNaN(c.ema1_abs_value))return NaN;if(c.ema2_pc_count++,c.ema2_pc_count<=s?(c.ema2_pc_sum+=c.ema1_pc_value,c.ema2_pc_count===s&&(c.ema2_pc_value=c.ema2_pc_sum/s)):c.ema2_pc_value=c.ema1_pc_value*c.ema2_pc_multiplier+c.ema2_pc_value*(1-c.ema2_pc_multiplier),c.ema2_abs_count++,c.ema2_abs_count<=s?(c.ema2_abs_sum+=c.ema1_abs_value,c.ema2_abs_count===s&&(c.ema2_abs_value=c.ema2_abs_sum/s)):c.ema2_abs_value=c.ema1_abs_value*c.ema2_abs_multiplier+c.ema2_abs_value*(1-c.ema2_abs_multiplier),isNaN(c.ema2_pc_value)||isNaN(c.ema2_abs_value))return NaN;if(c.ema2_abs_value===0)return e.precision(0);const g=c.ema2_pc_value/c.ema2_abs_value;return e.precision(g)}}function ph(e){return(t,i,r,n)=>{e.taState||(e.taState={});const s=n||"valuewhen";e.taState[s]||(e.taState[s]={values:[]});const a=e.taState[s],o=d.from(t).get(0),c=d.from(i).get(0),h=d.from(r).get(0);if(o&&a.values.push(c),isNaN(h)||h<0)return NaN;const l=a.values.length-1-h;if(l<0)return NaN;const f=a.values[l];return typeof f=="number"?e.precision(f):f}}function fh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`variance_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();let c=0,h=0;for(let g=0;g<n;g++)c+=a.window[g],h+=a.window[g]*a.window[g];const l=c/n,f=h/n-l*l;return e.precision(f)}}function mh(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 n=e.taState[r],s=d.from(t).get(0),a=d.from(e.data.volume).get(0),o=d.from(e.data.openTime).get(0),c=new Date(o).toISOString().slice(0,10);if(n.lastSessionDate!==c&&(n.cumulativePV=0,n.cumulativeVolume=0,n.lastSessionDate=c),n.cumulativePV+=s*a,n.cumulativeVolume+=a,n.cumulativeVolume===0)return NaN;const h=n.cumulativePV/n.cumulativeVolume;return e.precision(h)}}function dh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`vwma_${n}`;e.taState[s]||(e.taState[s]={window:[],volumeWindow:[]});const a=e.taState[s],o=d.from(t).get(0),c=e.get(e.data.volume,0);if(a.window.unshift(o),a.volumeWindow.unshift(c),a.window.length<n)return NaN;a.window.length>n&&(a.window.pop(),a.volumeWindow.pop());let h=0,l=0;for(let g=0;g<n;g++)h+=a.window[g]*a.volumeWindow[g],l+=a.volumeWindow[g];const f=h/l;return e.precision(f)}}function gh(e){return t=>{e.taState||(e.taState={});const i=t||"wad";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.close,1);if(isNaN(n)||isNaN(s)||isNaN(a))return e.precision(r.cumulativeSum);let c=0;if(!isNaN(o)){const h=Math.max(s,o),l=Math.min(a,o),f=n-o;f>0?c=n-l:f<0&&(c=n-h)}return r.cumulativeSum+=c,e.precision(r.cumulativeSum)}}function xh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`wma_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();let c=0,h=0;for(let f=0;f<n;f++){const g=n-f;c+=a.window[f]*g,h+=g}const l=c/h;return e.precision(l)}}function yh(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const n=i||`wpr_${r}`;e.taState[n]||(e.taState[n]={highWindow:[],lowWindow:[]});const s=e.taState[n],a=e.get(e.data.high,0),o=e.get(e.data.low,0),c=e.get(e.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(c))return NaN;if(s.highWindow.unshift(a),s.lowWindow.unshift(o),s.highWindow.length<r)return NaN;s.highWindow.length>r&&(s.highWindow.pop(),s.lowWindow.pop());let h=s.highWindow[0],l=s.lowWindow[0];for(let p=1;p<r;p++)s.highWindow[p]>h&&(h=s.highWindow[p]),s.lowWindow[p]<l&&(l=s.lowWindow[p]);const f=h-l;if(f===0)return e.precision(0);const g=(h-c)/f*-100;return e.precision(g)}}function wh(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.open,0),n=e.get(e.data.high,0),s=e.get(e.data.low,0),a=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(s)||isNaN(a))return NaN;const o=n-s;if(o===0)return e.precision(0);const c=(i-r)/o*a;return e.precision(c)}}const bh={accdist:cc,alma:hc,atr:uc,barssince:lc,bb:pc,bbw:fc,cci:mc,change:dc,cmo:gc,cog:xc,correlation:yc,cross:wc,crossover:bc,crossunder:vc,cum:_c,dev:Sc,dmi:Ec,ema:Nc,falling:Cc,highest:kc,highestbars:Ic,hma:Ac,iii:Tc,kc:Pc,kcw:Rc,linreg:Dc,lowest:Mc,lowestbars:Vc,macd:Oc,median:Lc,mfi:Bc,mode:Fc,mom:jc,nvi:$c,obv:Wc,param:qc,percentile_linear_interpolation:Uc,percentile_nearest_rank:Kc,percentrank:zc,pivothigh:Gc,pivotlow:Qc,pvi:Xc,pvt:Zc,range:Jc,rising:eh,rma:th,roc:ih,rsi:rh,sar:nh,sma:sh,stdev:ah,stoch:oh,supertrend:ch,swma:hh,tr:uh,tsi:lh,valuewhen:ph,variance:fh,vwap:mh,vwma:dh,wad:gh,wma:xh,wpr:yh,wvad:wh};class vh{constructor(t){this.context=t,Object.entries(bh).forEach(([i,r])=>{this[i]=r(t)})}accdist;alma;atr;barssince;bb;bbw;cci;change;cmo;cog;correlation;cross;crossover;crossunder;cum;dev;dmi;ema;falling;highest;highestbars;hma;iii;kc;kcw;linreg;lowest;lowestbars;macd;median;mfi;mode;mom;nvi;obv;param;percentile_linear_interpolation;percentile_nearest_rank;percentrank;pivothigh;pivotlow;pvi;pvt;range;rising;rma;roc;rsi;sar;sma;stdev;stoch;supertrend;swma;tr;tsi;valuewhen;variance;vwap;vwma;wad;wma;wpr;wvad}class _h{constructor(t){this.context=t}logFormat(t,...i){return t.replace(/{(\d+)}/g,(r,n)=>i[n])}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 Sh{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,n=0){const s=String(t),a=String(i),o=String(r),c=Math.floor(Number(n))||0;if(a==="")return s;let h=0,l=0;for(;;){const f=s.indexOf(a,h);if(f===-1)return s;if(l===c)return s.substring(0,f)+o+s.substring(f+a.length);l++,h=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,n)=>i[n])}}class Eh{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 Nh=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],Ch={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 kh{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 n=d.from(t).get(0);this.context.plots[i].data.push({time:this.context.marketData[this.context.idx].openTime,value:n,options:{...this.extractPlotOptions(r),style:"char"}})}plot(...t){const i=Vt(t,Nh,Ch),{series:r,title:n,...s}=i,a=this.extractPlotOptions(s);this.context.plots[n]||(this.context.plots[n]={data:[],options:a,title:n});const o=d.from(r).get(0);this.context.plots[n].data.push({time:this.context.marketData[this.context.idx].openTime,value:o,options:{color:a.color,offset:a.offset}})}}class Ih{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,n,s,a,o){return this.context.pine.plot(t,{title:i,color:r,linestyle:n,linewidth:s,editable:a,display:o})}}class Re{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([])};indicator;cache={};taState={};isSecondaryContext=!1;NA=NaN;lang;pine;static _deprecationWarningsShown=new Set;idx=0;params={};const={};var={};let={};result=void 0;plots={};marketData;source;tickerId;timeframe="";limit;sDate;eDate;fullContext;pineTSCode;constructor({marketData:t,source:i,tickerId:r,timeframe:n,limit:s,sDate:a,eDate:o,fullContext:c}){this.marketData=t,this.source=i,this.tickerId=r,this.timeframe=n,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=c||this;const h=new so(this),l={na:h.na.bind(h),color:h.color,nz:h.nz.bind(h),indicator:h.indicator.bind(h),fixnan:h.fixnan.bind(h),alertcondition:h.alertcondition.bind(h),bool:h.bool.bind(h)},f=this;this.pine={input:new No(this),ta:new vh(this),math:new ic(this),request:new oc(this),array:new $s(this),map:new ea(this),matrix:new eo(this),syminfo:null,timeframe:new Eh(this),barstate:new to(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 _h(this),str:new Sh(this),...l,...Cs};const g=new kh(this),p=new Ih(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 n=r?this.pine[r]:this.pine;for(const s of i)typeof t[s]=="function"?n[s]=t[s].bind(t):n[s]=t[s]}init(t,i,r=0){let n;return i instanceof d?n=i.get(0):Array.isArray(i)?Array.isArray(i[0])?n=i[0]:n=i[i.length-1+r]:n=i,t?t instanceof d?(t.data[t.data.length-1]=n,t):Array.isArray(t)?(t[t.length-1]=n,new d(t)):new d([n]):new d([n])}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}`;Re._deprecationWarningsShown.has(r)||(Re._deprecationWarningsShown.add(r),typeof window<"u"?console.warn("%c[WARNING]%c %s syntax is deprecated. Use %s instead. This will be removed in a future version.","color: #FFA500; font-weight: bold;","color: #FFA500;",t,i):console.warn(`\x1B[33m[WARNING] ${t} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}}class Ot{constructor(t,i,r,n,s,a){this.source=t,this.tickerId=i,this.timeframe=r,this.limit=n,this.sDate=s,this.eDate=a,this._readyPromise=new Promise(o=>{this.loadMarketData(t,i,r,n,s,a).then(c=>{const h=c;this.data=h;const l=h.map(N=>N.open),f=h.map(N=>N.close),g=h.map(N=>N.high),p=h.map(N=>N.low),x=h.map(N=>N.volume),y=h.map(N=>(N.high+N.low+N.close)/3),w=h.map(N=>(N.high+N.low)/2),S=h.map(N=>(N.high+N.low+N.open+N.close)/4),k=h.map(N=>(N.high+N.low+N.close+N.close)/4),C=h.map(N=>N.openTime),A=h.map(N=>N.closeTime);this.open=l,this.close=f,this.high=g,this.low=p,this.volume=x,this.hl2=w,this.hlc3=y,this.ohlc4=S,this.hlcc4=k,this.openTime=C,this.closeTime=A,t&&t.getSymbolInfo?t.getSymbolInfo(i).then(N=>{this._syminfo=N,this._ready=!0,o(!0)}).catch(N=>{console.warn("Failed to get symbol info, using default values:",N),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}data=[];open=[];high=[];low=[];close=[];volume=[];hl2=[];hlc3=[];ohlc4=[];hlcc4=[];openTime=[];closeTime=[];_readyPromise=null;_ready=!1;_debugSettings={ln:!1,debug:!1};_transpiledCode=null;get transpiledCode(){return this._transpiledCode}_isSecondaryContext=!1;markAsSecondary(){this._isSecondaryContext=!0}_syminfo;setDebugSettings({ln:t,debug:i}){this._debugSettings.ln=t,this._debugSettings.debug=i}async loadMarketData(t,i,r,n,s,a){return Array.isArray(t)?t:t.getMarketData(i,r,n,s,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 n=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(t,i,r,n)}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,n=!1){await this.ready(),i||(i=this.data.length);const s=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(s.result);await this._executeIterations(s,this._transpiledCode,a,a+l),a+=l,yield this._createPageContext(s,f);continue}if(!n||Array.isArray(this.source))break;const{newCandles:c,updatedLastCandle:h}=await this._updateMarketData();if(c===0&&!h){yield null;continue}this._removeLastResult(s),a=this.data.length-(c+1),s.pine.barstate.setLive()}}_getResultLength(t){if(Array.isArray(t))return t.length;if(typeof t=="object"&&t!==null){const 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 Re({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 n in t.result)Array.isArray(t.result[n])?r.result[n]=t.result[n].slice(i):r.result[n]=t.result[n]}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,n=this.data[r].openTime;try{const s=await i.getMarketData(this.tickerId,this.timeframe,void 0,n,t);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let c=0;c<s.length;c++){const h=s[c];h.openTime===n?(this._replaceCandle(r,h),a=!0):h.openTime>n&&(this._appendCandle(h),o++)}return{newCandles:o,updatedLastCandle:a}}catch(s){return console.error("Error updating market data:",s),{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 Re({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 Wn.bind(this)(t,this._debugSettings)}async _executeIterations(t,i,r,n){const s=["const","var","let","params"];for(let a=r;a<n;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 c in o){t.result[c]===void 0&&(t.result[c]=[]);let h;o[c]instanceof d?h=o[c].get(0):Array.isArray(o[c])?h=o[c][o[c].length-1]:h=o[c],t.result[c].push(h)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(o);for(let c of s)for(let h in t[c]){const l=t[c][h];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)}}}}}const oi="https://api.binance.com/api/v3",dt={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 Ah{cache;cacheDuration;constructor(t=5*60*1e3){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 Th{cacheManager;constructor(){this.cacheManager=new Ah(5*60*1e3)}async getMarketDataInterval(t,i,r,n){try{const s=dt[i.toUpperCase()];if(!s)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=[],c=r;const h=n,l=a[s];if(!l)return console.error(`Duration not defined for interval: ${s}`),[];for(;c<h;){const f=Math.min(c+1e3*l,h),g=await this.getMarketData(t,i,1e3,c,f);if(g.length===0)break;o=o.concat(g),c=g[g.length-1].closeTime+1}return o}catch(s){return console.error("Error in getMarketDataInterval:",s),[]}}async getMarketData(t,i,r,n,s){try{const a=s!==void 0,o={tickerId:t,timeframe:i,limit:r,sDate:n,eDate:s};if(a){const g=this.cacheManager.get(o);if(g)return g}const c=dt[i.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,n,s)&&n&&s){const g=await this.getMarketDataInterval(t,i,n,s),p=r?g.slice(0,r):g;return this.cacheManager.set(o,p),p}let h=`${oi}/klines?symbol=${t}&interval=${c}`;r&&(h+=`&limit=${Math.min(r,1e3)}`),n&&(h+=`&startTime=${n}`),s&&(h+=`&endTime=${s}`);const l=await fetch(h);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,n){if(i&&i>1e3)return!0;if(r&&n){const s=dt[t.toUpperCase()],a={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3}[s];if(a)return Math.ceil((n-r)/a)>1e3}return!1}async getSymbolInfo(t){try{let i="crypto",r=oi,n=t,s="";t.endsWith(".P")?(i="futures",n=t.replace(".P",""),r="https://fapi.binance.com/fapi/v1",s="Perpetual"):t.includes("_")&&(i="futures",n=t,r="https://dapi.binance.com/dapi/v1",s="Delivery");const a=i==="crypto"?`${r}/exchangeInfo?symbol=${n}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const c=(await o.json()).symbols;if(!c||c.length===0)return console.error(`Symbol ${t} not found`),null;const h=i==="futures"?c.find(C=>C.symbol===n):c[0];if(!h)return console.error(`Symbol ${n} not found in exchange info`),null;const l=h.filters?.find(C=>C.filterType==="PRICE_FILTER"),f=h.filters?.find(C=>C.filterType==="LOT_SIZE"),g=l?parseFloat(l.tickSize):.01,p=f?parseFloat(f.minQty):0,x=Math.round(1/g),y=h.baseAsset,w=h.quoteAsset,S=s?` ${s}`:"",k=`${y} / ${w}${S}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:y,description:k,type:i,main_tickerid:`BINANCE:${t}`,current_contract:s,isin:"",basecurrency:y,currency:w,timezone:"Etc/UTC",country:"",mintick:g,pricescale:x,minmove:1,pointvalue:h.contractSize||1,mincontract:p,session:"24x7",volumetype:"base",expiration_date:h.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}}}const Ph=sr.fileURLToPath(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||new URL("pinets.min.cjs",document.baseURI).href),Rh=je.dirname(Ph);class Dh{dataCache=new Map;exchangeInfoCache={};dataDirectory;constructor(t){if(t)this.dataDirectory=t;else{const i=je.resolve(Rh,"../../../");this.dataDirectory=je.join(i,"tests","compatibility","_data")}}getDataFileName(t,i,r,n){return r&&n?`${t}-${i}-${r}-${n}.json`:null}loadDataFromFile(t){const i=`file:${t}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=je.join(this.dataDirectory,t);if(!ke.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const n=ke.readFileSync(r,"utf-8"),s=JSON.parse(n);return this.dataCache.set(i,s),s}findDataFile(t,i,r,n){if(!ke.existsSync(this.dataDirectory))return null;const s=ke.readdirSync(this.dataDirectory).filter(c=>c.endsWith(".json"));if(r&&n){const c=`${t}-${i}-${r}-${n}.json`;if(s.includes(c))return c}const a=new RegExp(`^${t}-${i}-(\\d+)-(\\d+)\\.json$`),o=s.filter(c=>a.test(c)).map(c=>{const h=c.match(a);return{file:c,startTime:parseInt(h[1]),endTime:parseInt(h[2])}}).sort((c,h)=>h.endTime-c.endTime);if(o.length===0)return null;if(r&&n){const c=o.find(h=>h.startTime<=r&&h.endTime>=n);if(c)return c.file}return o[0].file}filterData(t,i,r,n){let s=t;return(i||r)&&(s=t.filter(a=>{const o=!i||a.openTime>=i,c=!r||a.openTime<=r;return o&&c})),s.sort((a,o)=>a.openTime-o.openTime),n&&n>0&&(s=s.slice(0,n)),s}normalizeTimeframe(t){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[t.toUpperCase()]||t.toLowerCase()}async getMarketData(t,i,r,n,s){try{const a=this.normalizeTimeframe(i),o=this.findDataFile(t,a,n,s);if(!o)return console.warn(`No mock data file found for ${t} ${a}. Searched in: ${this.dataDirectory}`),[];const c=this.loadDataFromFile(o);return this.filterData(c,n,s,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=je.join(this.dataDirectory,i);if(!ke.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const n=ke.readFileSync(r,"utf-8"),s=JSON.parse(n);return this.exchangeInfoCache[t]=s,s}catch(n){return console.error(`Error loading exchange info from ${i}:`,n),null}}async getSymbolInfo(t){try{let i="crypto",r=t,n="";t.endsWith(".P")?(i="futures",r=t.replace(".P",""),n="Perpetual"):t.includes("_")&&(i="futures",r=t,n="Delivery");const s=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!s||!s.symbols)return console.error(`Exchange info not available for ${i}`),null;const a=s.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"),c=a.filters?.find(w=>w.filterType==="LOT_SIZE"),h=o?parseFloat(o.tickSize):.01,l=c?parseFloat(c.minQty):0,f=Math.round(1/h),g=a.baseAsset,p=a.quoteAsset,x=n?` ${n}`:"",y=`${g} / ${p}${x}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:g,description:y,type:i,main_tickerid:`BINANCE:${t}`,current_contract:n,isin:"",basecurrency:g,currency:p,timezone:"Etc/UTC",country:"",mintick:h,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 Mh=typeof process<"u"&&process.versions&&process.versions.node;let rt=null;if(Mh)try{rt=new Dh}catch{rt=null}const Vh={Binance:new Th,...rt?{Mock:rt}:{}};exports.Context=Re;exports.PineTS=Ot;exports.Provider=Vh;
|
|
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 Za(e){return(t,i,r)=>new D(t,i,r,e)}function Ja(e){return(t,i=0)=>d.from(t).get(i)}class eo{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=Za(t),this.param=Ja(),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)}}class to{constructor(t){this.context=t}_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 ni={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 Vt(e,t,i){Array.isArray(t)&&typeof t[0]=="string"&&(t=[t]);const r={};let n={};const s=new Array(t.length).fill(!0);for(let a=0;a<e.length;a++){const o=e[a];if(ni.remaining_options(o)){n=o;break}const c=t.map((h,l)=>s[l]?h[a]:void 0);for(let h=0;h<c.length;h++){const l=c[h];if(l===void 0){s[h]=!1;continue}const f=ni[i[l]];typeof f=="function"&&f(o)?r[l]=o:s[h]=!1}}return{...n,...r}}const io=["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"],ro={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 no(e){return Vt(e,io,ro)}class so{constructor(t){this.context=t}color={param:(t,i=0)=>d.from(t).get(i),rgb:(t,i,r,n)=>n?`rgba(${t}, ${i}, ${r}, ${n})`:`rgb(${t}, ${i}, ${r})`,new:(t,i)=>{if(t&&t.startsWith("#")){const r=t.slice(1),n=parseInt(r.slice(0,2),16),s=parseInt(r.slice(2,4),16),a=parseInt(r.slice(4,6),16);return i?`rgba(${n}, ${s}, ${a}, ${i})`:`rgb(${n}, ${s}, ${a})`}return i?`rgba(${t}, ${i})`:t},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=no(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),n=d.from(i).get(0);return isNaN(r)?n:r}fixnan(t){const i=d.from(t);for(let r=0;r<i.length;r++){const n=i.get(r);if(!isNaN(n))return n}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 ao=[["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"]],oo={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function Y(e){return Vt(e,ao,oo)}function co(e){return(...t)=>Y(t).defval}function ho(e){return(...t)=>Y(t).defval}function uo(e){return(...t)=>Y(t).defval}function lo(e){return(...t)=>Y(t).defval}function po(e){return(...t)=>Y(t).defval}function fo(e){return(...t)=>Y(t).defval}function mo(e){return(t,i=0)=>d.from(t).get(i)}function go(e){return(...t)=>Y(t).defval}function xo(e){return(...t)=>Y(t).defval}function yo(e){return(...t)=>Y(t).defval}function wo(e){return(...t)=>Y(t).defval}function bo(e){return(...t)=>Y(t).defval}function vo(e){return(...t)=>Y(t).defval}function _o(e){return(...t)=>Y(t).defval}function So(e){return(...t)=>Y(t).defval}const Eo={any:co,bool:ho,color:uo,enum:lo,float:po,int:fo,param:mo,price:go,session:xo,source:yo,string:wo,symbol:bo,text_area:vo,time:_o,timeframe:So};class No{constructor(t){this.context=t,Object.entries(Eo).forEach(([i,r])=>{this[i]=r(t)})}any;bool;color;enum;float;int;param;price;session;source;string;symbol;text_area;time;timeframe}function Co(e){return t=>Math.abs(d.from(t).get(0))}function ko(e){return t=>Math.acos(d.from(t).get(0))}function Io(e){return t=>Math.asin(d.from(t).get(0))}function Ao(e){return t=>Math.atan(d.from(t).get(0))}function To(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return i.reduce((r,n)=>r+n,0)/i.length}}function Po(e){return t=>Math.ceil(d.from(t).get(0))}function Ro(e){return t=>Math.cos(d.from(t).get(0))}function Do(e){return()=>Math.E}function Mo(e){return t=>Math.exp(d.from(t).get(0))}function Vo(e){return t=>Math.floor(d.from(t).get(0))}function Oo(e){return t=>Math.log(d.from(t).get(0))}function Lo(e){return t=>Math.log(d.from(t).get(0))}function Bo(e){return t=>Math.log10(d.from(t).get(0))}function Fo(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.max(...i)}}function jo(e){return(...t)=>{const i=t.map(r=>d.from(r).get(0));return Math.min(...i)}}function $o(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 Wo(e){return()=>1.618033988749895}function qo(e){return()=>Math.PI}function Uo(e){return(t,i)=>Math.pow(d.from(t).get(0),d.from(i).get(0))}function Ko(e){return()=>Math.random()}function zo(e){return t=>Math.round(d.from(t).get(0))}function Ho(e){return t=>e.precision(Math.round(d.from(t).get(0)/e.pine.syminfo.mintick)*e.pine.syminfo.mintick)}function Go(e){return()=>.6180339887498948}function Yo(e){return t=>Math.sign(d.from(t).get(0))}function Qo(e){return t=>Math.sin(d.from(t).get(0))}function Xo(e){return t=>Math.sqrt(d.from(t).get(0))}function Zo(e){return(t,i)=>{const r=d.from(i).get(0),n=d.from(t);let s=0;for(let a=0;a<r;a++){const o=n.get(a);s+=o}return s}}function Jo(e){return t=>Math.tan(d.from(t).get(0))}function ec(e){return(t,i)=>{const r=d.from(t).get(0),n=d.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)&&isNaN(n)?!0:isNaN(r)||isNaN(n)?!1:Math.abs(r-n)<1e-8:r===n}}const tc={abs:Co,acos:ko,asin:Io,atan:Ao,avg:To,ceil:Po,cos:Ro,e:Do,exp:Mo,floor:Vo,ln:Oo,log:Lo,log10:Bo,max:Fo,min:jo,param:$o,phi:Wo,pi:qo,pow:Uo,random:Ko,round:zo,round_to_mintick:Ho,rphi:Go,sign:Yo,sin:Qo,sqrt:Xo,sum:Zo,tan:Jo,__eq:ec};class ic{constructor(t){this.context=t,Object.entries(tc).forEach(([i,r])=>{this[i]=r(t)})}_cache={};abs;acos;asin;atan;avg;ceil;cos;e;exp;floor;ln;log;log10;max;min;param;phi;pi;pow;random;round;round_to_mintick;rphi;sign;sin;sqrt;sum;tan;__eq}function rc(e){return(t,i,r)=>{e.params[r]||(e.params[r]=[]);let n;if(t instanceof d)n=t.get(i||0);else if(Array.isArray(t)){const s=t.every(o=>o instanceof d),a=t.every(o=>!(o instanceof d)&&!Array.isArray(o));(s||a)&&t.length>=1?s?n=t.map(o=>o.get(0)):n=t:n=d.from(t).get(i||0)}else n=t;return e.params[r].length===0?e.params[r].push(n):e.params[r][e.params[r].length-1]=n,[n,r]}}const it=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function si(e,t,i,r,n=!1){for(let s=0;s<i.length;s++)if(i[s]<=e&&t<=r[s])return n||t>=r[s]?s:s-1;return-1}function ai(e,t,i,r,n=!1,s,a=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=t&&i[o]>=e){const c=s&&t>s;if(a&&n)for(let h=0;h<i.length;h++){if(i[h]>=e&&i[h]<t)return h;if(i[h]>=t)break}if(c&&n&&!a)for(let h=0;h<i.length;h++){if(i[h]>=e&&i[h]<t)return h;if(i[h]>=t)break}return o}if(r[o]<e)break}return-1}function nc(e){return async(t,i,r,n=!1,s=!1,a=!1,o=null,c=null)=>{const h=t[0],l=i[0],f=r[0],g=r[1],p=Array.isArray(n)?n[0]:n,x=Array.isArray(s)?s[0]:s;if(e.isSecondaryContext)return f;const y=it.indexOf(e.timeframe),w=it.indexOf(l);if(y==-1||w==-1)throw new Error("Invalid timeframe");if(y===w)return f;const S=y>w,k=d.from(e.data.openTime).get(0),C=d.from(e.data.closeTime).get(0),A=`${h}_${l}_${g}`,N=`${A}_prevIdx`;if(e.cache[A]){const Be=e.cache[A],Ye=S?ai(k,C,Be.data.openTime.data,Be.data.closeTime.data,x,e.eDate,p):si(k,C,Be.data.openTime.data,Be.data.closeTime.data,x);if(Ye==-1)return NaN;const Ce=Be.params[g][Ye];if(!S&&p){const Lt=e.cache[N];return Lt!==void 0&&Lt===Ye?NaN:(e.cache[N]=Ye,Array.isArray(Ce)?[Ce]:Ce)}return Array.isArray(Ce)?[Ce]:Ce}const q=1e3*60*60*24*30,W=e.sDate?e.sDate-q:void 0,j=e.sDate&&e.eDate?void 0:e.limit||1e3,Le=new Ot(e.source,h,l,j,W,void 0);Le.markAsSecondary();const de=await Le.run(e.pineTSCode);e.cache[A]=de;const ct=S?ai(k,C,de.data.openTime.data,de.data.closeTime.data,x,e.eDate,p):si(k,C,de.data.openTime.data,de.data.closeTime.data,x);if(ct==-1)return NaN;const ht=de.params[g][ct];return!S&&p?(e.cache[N]=ct,NaN):Array.isArray(ht)?[ht]:ht}}function sc(e){return async(t,i,r,n=!1,s=null,a=!1,o=0)=>{const c=t[0],h=i[0],l=r[0],f=r[1];Array.isArray(n)&&n[0];const g=Array.isArray(a)?a[0]:a;if(e.isSecondaryContext)return Array.isArray(l)?[l]:l;const p=it.indexOf(e.timeframe),x=it.indexOf(h);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 ${h} is not lower than or equal to chart timeframe ${e.timeframe}`)}if(x===p)return[[l]];const y=`${c}_${h}_${f}_lower`;if(!e.cache[y]){const W=e.sDate?e.sDate-2592e6:void 0,j=e.sDate&&e.eDate?void 0:e.limit||1e3,Le=new Ot(e.source,c,h,j,W,e.eDate);Le.markAsSecondary();const de=await Le.run(e.pineTSCode);e.cache[y]=de}const w=e.cache[y],S=d.from(e.data.openTime).get(0),k=d.from(e.data.closeTime).get(0),C=w.data.openTime.data,A=w.data.closeTime.data,N=w.params[f];if(!N)return[];const q=[];for(let W=0;W<C.length;W++){const j=C[W];if(!(A[W]<=S)){if(j>=k)break;j>=S&&j<k&&q.push(N[W])}}return[q]}}const ac={param:rc,security:nc,security_lower_tf:sc};class oc{constructor(t){this.context=t,Object.entries(ac).forEach(([i,r])=>{this[i]=r(t)})}_cache={};param;security;security_lower_tf}function cc(e){return t=>{e.taState||(e.taState={});const i=t||"accdist";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.volume,0);if(isNaN(n)||isNaN(s)||isNaN(a)||isNaN(o))return e.precision(r.cumulativeSum);const c=s-a;let h=0;return c!==0&&(h=(n-a-(s-n))/c*o),r.cumulativeSum+=h,e.precision(r.cumulativeSum)}}function hc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0),c=d.from(n).get(0);e.taState||(e.taState={});const h=s||`alma_${a}_${o}_${c}`;if(!e.taState[h]){const p=o*(a-1),x=a/c,y=[];let w=0;for(let S=0;S<a;S++){const k=Math.exp(-Math.pow(S-p,2)/(2*x*x));y.push(k),w+=k}for(let S=0;S<y.length;S++)y[S]/=w;e.taState[h]={window:[],weights:y}}const l=e.taState[h],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 uc(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const n=i||`atr_${r}`;e.taState[n]||(e.taState[n]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const s=e.taState[n],a=e.get(e.data.high,0),o=e.get(e.data.low,0),c=e.get(e.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(c))return NaN;let h;if(s.prevClose!==null){const f=a-o,g=Math.abs(a-s.prevClose),p=Math.abs(o-s.prevClose);h=Math.max(f,g,p)}else h=a-o;if(s.prevClose=c,s.initCount<r)return s.initSum+=h,s.initCount++,s.initCount===r?(s.prevAtr=s.initSum/r,e.precision(s.prevAtr)):NaN;const l=(s.prevAtr*(r-1)+h)/r;return s.prevAtr=l,e.precision(l)}}function lc(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"barssince";e.taState[r]||(e.taState[r]={lastTrueIndex:null});const n=e.taState[r];return d.from(t).get(0)?(n.lastTrueIndex=e.idx,0):n.lastTrueIndex===null?NaN:e.idx-n.lastTrueIndex}}function pc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`bb_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],h=d.from(t).get(0);if(isNaN(h))return[[NaN,NaN,NaN]];if(c.window.unshift(h),c.sum+=h,c.window.length<s)return[[NaN,NaN,NaN]];if(c.window.length>s){const y=c.window.pop();c.sum-=y}const l=c.sum/s;let f=0;for(let y=0;y<s;y++)f+=Math.pow(c.window[y]-l,2);const g=Math.sqrt(f/s),p=l+a*g,x=l-a*g;return[[e.precision(p),e.precision(l),e.precision(x)]]}}function fc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`bbw_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],h=d.from(t).get(0);if(isNaN(h))return NaN;if(c.window.unshift(h),c.sum+=h,c.window.length<s)return NaN;if(c.window.length>s){const w=c.window.pop();c.sum-=w}const l=c.sum/s;let f=0;for(let w=0;w<s;w++){const S=c.window[w]-l;f+=S*S}const g=f/s,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 mc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`cci_${n}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=d.from(t).get(0);if(isNaN(o))return NaN;if(a.window.unshift(o),a.sum+=o,a.window.length<n)return NaN;if(a.window.length>n){const g=a.window.pop();a.sum-=g}const c=a.sum/n;let h=0;for(let g=0;g<n;g++)h+=Math.abs(a.window[g]-c);const l=h/n;if(l===0)return 0;const f=(o-c)/(.015*l);return e.precision(f)}}function dc(e){return(t,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`change_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=n)return NaN;a.window.length>n+1&&a.window.pop();const c=o-a.window[n];return e.precision(c)}}function gc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`cmo_${n}`;e.taState[s]||(e.taState[s]={gainsWindow:[],lossesWindow:[],gainsSum:0,lossesSum:0});const a=e.taState[s],o=d.from(t).get(0),c=d.from(t).get(1);if(isNaN(o)||isNaN(c))return NaN;const h=o-c,l=h>=0?h:0,f=h>=0?0:-h;if(a.gainsWindow.unshift(l),a.lossesWindow.unshift(f),a.gainsSum+=l,a.lossesSum+=f,a.gainsWindow.length<n)return NaN;if(a.gainsWindow.length>n){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 xc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);let a=0,o=!1;for(let l=0;l<n;l++){const f=s.get(l);if(isNaN(f)){o=!0;break}a+=f}if(o)return NaN;let c=0;for(let l=0;l<n;l++){const f=s.get(l);c+=f*(l+1)}if(a===0)return NaN;const h=-c/a;return e.precision(h)}}function yc(e){return(t,i,r,n)=>{const s=d.from(r).get(0),a=d.from(t),o=d.from(i);if(e.idx<s-1)return NaN;let c=0,h=0,l=0,f=0,g=0,p=0;for(let k=0;k<s;k++){const C=a.get(k),A=o.get(k);isNaN(C)||isNaN(A)||(c+=C,h+=A,l+=C*A,f+=C*C,g+=A*A,p++)}if(p<2)return NaN;const x=p*l-c*h,y=p*f-c*c,w=p*g-h*h;if(y<=0||w<=0)return e.precision(0);const S=x/Math.sqrt(y*w);return e.precision(S)}}function wc(e){return(t,i,r)=>{const n=d.from(t),s=d.from(i),a=n.get(0),o=s.get(0),c=n.get(1),h=s.get(1);if(isNaN(a)||isNaN(o)||isNaN(c)||isNaN(h))return!1;const l=a>o&&c<=h,f=a<o&&c>=h;return l||f}}function bc(e){return(t,i)=>{const r=d.from(t),n=d.from(i),s=r.get(0),a=n.get(0),o=r.get(1),c=n.get(1);return o<c&&s>a}}function vc(e){return(t,i)=>{const r=d.from(t),n=d.from(i),s=r.get(0),a=n.get(0),o=r.get(1),c=n.get(1);return o>c&&s<a}}function _c(e){return(t,i)=>{e.taState||(e.taState={});const r=i||"cum";e.taState[r]||(e.taState[r]={cumulativeSum:0});const n=e.taState[r],s=d.from(t).get(0);return isNaN(s)||(n.cumulativeSum+=s),e.precision(n.cumulativeSum)}}function Sc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`dev_${n}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<n)return NaN;if(a.window.length>n){const f=a.window.pop();a.sum-=f}const c=a.sum/n;let h=0;for(let f=0;f<n;f++)h+=Math.abs(a.window[f]-c);const l=h/n;return e.precision(l)}}function Ec(e){return(t,i,r)=>{const n=d.from(t).get(0),s=d.from(i).get(0);e.taState||(e.taState={});const a=r||`dmi_${n}_${s}`;e.taState[a]||(e.taState[a]={prevHigh:NaN,prevLow:NaN,prevClose:NaN,trInitSum:0,plusInitSum:0,minusInitSum:0,initCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,dxInitSum:0,adxInitCount:0,prevADX:NaN});const o=e.taState[a],c=e.get(e.data.high,0),h=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(c)||isNaN(h)||isNaN(l))return[[NaN,NaN,NaN]];if(isNaN(o.prevHigh))return o.prevHigh=c,o.prevLow=h,o.prevClose=l,[[NaN,NaN,NaN]];const f=Math.max(c-h,Math.abs(c-o.prevClose),Math.abs(h-o.prevClose)),g=c-o.prevHigh,p=o.prevLow-h,x=g>p&&g>0?g:0,y=p>g&&p>0?p:0;o.prevHigh=c,o.prevLow=h,o.prevClose=l;let w,S,k;if(o.initCount++,o.initCount<=n)o.trInitSum+=f,o.plusInitSum+=x,o.minusInitSum+=y,o.initCount===n&&(o.prevSmoothedTR=o.trInitSum/n,o.prevSmoothedPlus=o.plusInitSum/n,o.prevSmoothedMinus=o.minusInitSum/n);else{const j=1/n;o.prevSmoothedTR=j*f+(1-j)*o.prevSmoothedTR,o.prevSmoothedPlus=j*x+(1-j)*o.prevSmoothedPlus,o.prevSmoothedMinus=j*y+(1-j)*o.prevSmoothedMinus}if(w=o.prevSmoothedTR,S=o.prevSmoothedPlus,k=o.prevSmoothedMinus,o.initCount<n)return[[NaN,NaN,NaN]];const C=w===0?0:100*S/w,A=w===0?0:100*k/w,N=C+A,q=N===0?0:100*Math.abs(C-A)/N;let W=NaN;if(o.adxInitCount++,o.adxInitCount<=s)o.dxInitSum+=q,o.adxInitCount===s&&(o.prevADX=o.dxInitSum/s,W=o.prevADX);else{const j=1/s;o.prevADX=j*q+(1-j)*o.prevADX,W=o.prevADX}return[[e.precision(C),e.precision(A),e.precision(W)]]}}function Nc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`ema_${n}`;e.taState[s]||(e.taState[s]={prevEma:null,initSum:0,initCount:0});const a=e.taState[s],o=d.from(t).get(0);if(o==null||isNaN(o))return NaN;if(a.initCount<n)return a.initSum+=o,a.initCount++,a.initCount===n?(a.prevEma=a.initSum/n,e.precision(a.prevEma)):NaN;const c=2/(n+1),h=o*c+a.prevEma*(1-c);return a.prevEma=h,e.precision(h)}}function Cc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);for(let a=0;a<n;a++){const o=s.get(a),c=s.get(a+1);if(isNaN(o)||isNaN(c)||o>=c)return!1}return!0}}function kc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`highest_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();const c=Math.max(...a.window.filter(h=>!isNaN(h)));return e.precision(c)}}function Ic(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n-1)return NaN;let a=-1/0,o=NaN;for(let c=0;c<n;c++){const h=s.get(c);isNaN(h)||(isNaN(o)||h>a)&&(a=h,o=-c)}return o}}function Ac(e){return(t,i,r)=>{const n=d.from(i).get(0),s=Math.floor(n/2),a=Math.floor(Math.sqrt(n)),o=e.ta.wma,c=o(t,s,r?`${r}_wma1`:void 0),h=o(t,n,r?`${r}_wma2`:void 0);if(isNaN(c)||isNaN(h))return NaN;e.taState||(e.taState={});const l=r||`hma_raw_${n}`;e.taState[l]||(e.taState[l]=[]);const f=2*c-h;e.taState[l].unshift(f);const g=r?`${r}_hma_final`:`hma_final_${n}`;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 S=0;S<a;S++){const k=a-S;x+=p.window[S]*k,y+=k}const w=x/y;return e.precision(w)}}function Tc(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.high,0),n=e.get(e.data.low,0),s=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(s))return NaN;const a=(r-n)*s;if(a===0)return e.precision(0);const o=(2*i-r-n)/a;return e.precision(o)}}function Pc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let c=!0;typeof n=="string"?s=n:n!==void 0&&(c=d.from(n).get(0));let h;const l=e.get(e.data.high,0),f=e.get(e.data.low,0);if(c){const A=e.get(e.data.close,1);isNaN(A)?h=NaN:h=Math.max(l-f,Math.abs(l-A),Math.abs(f-A))}else h=l-f;const g=d.from(t).get(0);e.taState||(e.taState={});const p=s||`kc_${a}_${o}_${c}`;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=(A,N,q)=>{if(isNaN(N))return NaN;if(A.initCount<q)return A.initSum+=N,A.initCount++,A.initCount===q?(A.prevEma=A.initSum/q,A.prevEma):NaN;const W=2/(q+1);return A.prevEma=N*W+A.prevEma*(1-W),A.prevEma},w=y(x.basisState,g,a),S=y(x.rangeState,h,a);if(isNaN(w)||isNaN(S))return[[NaN,NaN,NaN]];const k=w+S*o,C=w-S*o;return[[e.precision(w),e.precision(k),e.precision(C)]]}}function Rc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0);let c=!0;typeof n=="string"?s=n:n!==void 0&&(c=d.from(n).get(0)),e.taState||(e.taState={});const h=s||`kcw_${a}_${o}_${c}`;e.taState[h]||(e.taState[h]={basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0}});const l=e.taState[h],f=(C,A,N)=>{if(isNaN(A))return NaN;if(C.initCount<N)return C.initSum+=A,C.initCount++,C.initCount===N?(C.prevEma=C.initSum/N,C.prevEma):NaN;const q=2/(N+1);return C.prevEma=A*q+C.prevEma*(1-q),C.prevEma};let g;const p=e.get(e.data.high,0),x=e.get(e.data.low,0);if(c){const C=e.get(e.data.close,1);isNaN(C)?g=NaN:g=Math.max(p-x,Math.abs(p-C),Math.abs(x-C))}else g=p-x;const y=d.from(t).get(0),w=f(l.basisState,y,a),S=f(l.rangeState,g,a);if(isNaN(w)||isNaN(S))return NaN;if(w===0)return e.precision(0);const k=2*S*o/w;return e.precision(k)}}function Dc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`linreg_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[]});const c=e.taState[o],h=d.from(t).get(0);if(c.window.unshift(h),c.window.length<s)return NaN;c.window.length>s&&c.window.pop();let l=0,f=0,g=0,p=0;const x=s;for(let k=0;k<s;k++){const C=s-1-k,A=c.window[k];l+=C,f+=A,g+=C*A,p+=C*C}const y=x*p-l*l;if(y===0)return NaN;const w=(x*g-l*f)/y,S=(f-w*l)/x+w*(s-1-a);return e.precision(S)}}function Mc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`lowest_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();const c=a.window.filter(l=>!isNaN(l)&&l!==void 0),h=c.length>0?Math.min(...c):NaN;return e.precision(h)}}function Vc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n-1)return NaN;let a=1/0,o=NaN;for(let c=0;c<n;c++){const h=s.get(c);isNaN(h)||(isNaN(o)||h<a)&&(a=h,o=-c)}return o}}function Oc(e){return(t,i,r,n,s)=>{const a=d.from(i).get(0),o=d.from(r).get(0),c=d.from(n).get(0),h=s||`macd_${a}_${o}_${c}`,l=`${h}_fast`,f=`${h}_slow`,g=`${h}_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,c,g));let S=NaN;return!isNaN(y)&&!isNaN(w)&&(S=y-w),[[e.precision(y),e.precision(w),e.precision(S)]]}}function Lc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`median_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();const c=a.window.slice().sort((f,g)=>f-g),h=Math.floor(n/2),l=n%2===0?(c[h-1]+c[h])/2:c[h];return e.precision(l)}}function Bc(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`mfi_${n}`;e.taState[s]||(e.taState[s]={upperWindow:[],lowerWindow:[],upperSum:0,lowerSum:0});const a=e.taState[s],o=d.from(t).get(0),c=d.from(t).get(1),h=e.get(e.data.volume,0);if(isNaN(o)||isNaN(h))return NaN;const l=isNaN(c)?NaN:o-c;let f=0,g=0;if(f=h*(l<=0?0:o),g=h*(l>=0?0:o),a.upperWindow.unshift(f),a.lowerWindow.unshift(g),a.upperSum+=f,a.lowerSum+=g,a.upperWindow.length<n)return NaN;if(a.upperWindow.length>n){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 Fc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n-1)return NaN;const a=new Map;for(let h=0;h<n;h++){const l=s.get(h);isNaN(l)||a.set(l,(a.get(l)||0)+1)}if(a.size===0)return NaN;let o=NaN,c=-1;for(const[h,l]of a.entries())l>c?(c=l,o=h):l===c&&h<o&&(o=h);return o}}function jc(e){return(t,i,r)=>{const n=d.from(i).get(0);return e.ta.change(t,n)}}function $c(e){return t=>{e.taState||(e.taState={});const i=t||"nvi";e.taState[i]||(e.taState[i]={nvi:1});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),c=isNaN(n)?0:n,h=isNaN(s)?0:s,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(c===0||h===0)&&l<f){const g=(c-h)/h;r.nvi=r.nvi+g*r.nvi}return e.precision(r.nvi)}}function Wc(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),n=e.get(e.data.volume,0),s=e.get(e.data.close,1);if(isNaN(s))return i.prevOBV=0,e.precision(0);let a;return r>s?a=i.prevOBV+n:r<s?a=i.prevOBV-n:a=i.prevOBV,i.prevOBV=a,e.precision(a)}}function qc(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 Uc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<s-1)return NaN;const c=[];for(let x=0;x<s;x++){const y=o.get(x);if(isNaN(y))return NaN;c.push(y)}c.sort((x,y)=>x-y);let h=a/100*s-.5;h<0&&(h=0),h>s-1&&(h=s-1);const l=Math.floor(h),f=Math.ceil(h);if(l===f)return e.precision(c[l]);const g=h-l,p=c[l]+g*(c[f]-c[l]);return e.precision(p)}}function Kc(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t);if(e.idx<s-1)return NaN;const c=[];for(let l=0;l<s;l++){const f=o.get(l);isNaN(f)||c.push(f)}if(c.length===0)return NaN;c.sort((l,f)=>l-f);let h=Math.ceil(a/100*c.length)-1;return h<0&&(h=0),h>=c.length&&(h=c.length-1),e.precision(c[h])}}function zc(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);if(e.idx<n)return NaN;const a=s.get(0);if(isNaN(a))return NaN;let o=0,c=0;for(let h=1;h<=n;h++){const l=s.get(h);isNaN(l)||(c++,l<=a&&o++)}return c===0?NaN:e.precision(o/c*100)}}function Hc(e,t,i){const r=new Array(e.length).fill(NaN);for(let n=t+i;n<e.length;n++){const s=e[n-i];let a=!0;for(let o=1;o<=t;o++)if(e[n-i-o]>=s){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[n-i+o]>=s){a=!1;break}}a&&(r[n]=s)}return r}function Gc(e){return(t,i,r,n)=>{typeof r=="string"&&(r=i,i=t,t=e.data.high);const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),c=Hc(o,s,a),h=e.idx;return e.precision(c[h])}}function Yc(e,t,i){const r=new Array(e.length).fill(NaN);for(let n=t+i;n<e.length;n++){const s=e[n-i];let a=!0;for(let o=1;o<=t;o++)if(e[n-i-o]<=s){a=!1;break}if(a){for(let o=1;o<=i;o++)if(e[n-i+o]<=s){a=!1;break}}a&&(r[n]=s)}return r}function Qc(e){return(t,i,r,n)=>{typeof r=="string"&&(r=i,i=t,t=e.data.low);const s=d.from(i).get(0),a=d.from(r).get(0),o=d.from(t).toArray(),c=Yc(o,s,a),h=e.idx;return e.precision(c[h])}}function Xc(e){return t=>{e.taState||(e.taState={});const i=t||"pvi";e.taState[i]||(e.taState[i]={pvi:1});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.close,1),a=e.get(e.data.volume,0),o=e.get(e.data.volume,1),c=isNaN(n)?0:n,h=isNaN(s)?0:s,l=isNaN(a)?0:a,f=isNaN(o)?0:o;if(!(c===0||h===0)&&l>f){const g=(c-h)/h;r.pvi=r.pvi+g*r.pvi}return e.precision(r.pvi)}}function Zc(e){return t=>{e.taState||(e.taState={});const i=t||"pvt";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.close,1),a=e.get(e.data.volume,0);if(!isNaN(n)&&!isNaN(s)&&!isNaN(a)&&s!==0){const o=(n-s)/s*a;r.cumulativeSum+=o}return e.precision(r.cumulativeSum)}}function Jc(e){return(t,i,r)=>{const n=e.pine.ta.highest(t,i,(r||"range")+"_h"),s=e.pine.ta.lowest(t,i,(r||"range")+"_l");return isNaN(n)||isNaN(s)?NaN:e.precision(n-s)}}function eh(e){return(t,i,r)=>{const n=d.from(i).get(0),s=d.from(t);for(let a=0;a<n;a++){const o=s.get(a),c=s.get(a+1);if(isNaN(o)||isNaN(c)||o<=c)return!1}return!0}}function th(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`rma_${n}`;e.taState[s]||(e.taState[s]={prevRma:null,initSum:0,initCount:0});const a=e.taState[s],o=d.from(t).get(0)||0;if(a.initCount<n)return a.initSum+=o,a.initCount++,a.initCount===n?(a.prevRma=a.initSum/n,e.precision(a.prevRma)):NaN;const c=1/n,h=o*c+a.prevRma*(1-c);return a.prevRma=h,e.precision(h)}}function ih(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`roc_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<=n)return NaN;a.window.length>n+1&&a.window.pop();const c=a.window[n],h=(o-c)/c*100;return e.precision(h)}}function rh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`rsi_${n}`;e.taState[s]||(e.taState[s]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.prevValue!==null){const c=o-a.prevValue,h=c>0?c:0,l=c<0?-c:0;if(a.initGains.length<n){if(a.initGains.push(h),a.initLosses.push(l),a.initGains.length===n){a.avgGain=a.initGains.reduce((p,x)=>p+x,0)/n,a.avgLoss=a.initLosses.reduce((p,x)=>p+x,0)/n,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*(n-1)+h)/n,a.avgLoss=(a.avgLoss*(n-1)+l)/n;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 nh(e){return(t,i,r,n)=>{const s=d.from(t).get(0),a=d.from(i).get(0),o=d.from(r).get(0);e.taState||(e.taState={});const c=n||`sar_${s}_${a}_${o}`;e.taState[c]||(e.taState[c]={result:NaN,maxMin:NaN,acceleration:NaN,isBelow:!1,barIndex:0});const h=e.taState[c],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),S=e.get(e.data.low,2);if(isNaN(l)||isNaN(f)||isNaN(g))return NaN;let k=!1;return h.barIndex===1&&(g>p?(h.isBelow=!0,h.maxMin=l,h.result=y):(h.isBelow=!1,h.maxMin=f,h.result=x),k=!0,h.acceleration=s),h.barIndex>=1&&(h.result=h.result+h.acceleration*(h.maxMin-h.result),h.isBelow?h.result>f&&(k=!0,h.isBelow=!1,h.result=Math.max(l,h.maxMin),h.maxMin=f,h.acceleration=s):h.result<l&&(k=!0,h.isBelow=!0,h.result=Math.min(f,h.maxMin),h.maxMin=l,h.acceleration=s),k||(h.isBelow?l>h.maxMin&&(h.maxMin=l,h.acceleration=Math.min(h.acceleration+a,o)):f<h.maxMin&&(h.maxMin=f,h.acceleration=Math.min(h.acceleration+a,o))),h.isBelow?(h.result=Math.min(h.result,y),h.barIndex>1&&(h.result=Math.min(h.result,S))):(h.result=Math.max(h.result,x),h.barIndex>1&&(h.result=Math.max(h.result,w)))),h.barIndex++,h.barIndex<=1?NaN:e.precision(h.result)}}function sh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`sma_${n}`;e.taState[s]||(e.taState[s]={window:[],sum:0});const a=e.taState[s],o=d.from(t).get(0)||0;if(a.window.unshift(o),a.sum+=o,a.window.length<n)return NaN;if(a.window.length>n){const h=a.window.pop();a.sum-=h}const c=a.sum/n;return e.precision(c)}}function ah(e){return(t,i,r=!0,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`stdev_${s}_${a}`;e.taState[o]||(e.taState[o]={window:[],sum:0});const c=e.taState[o],h=d.from(t).get(0);if(h==null||isNaN(h))return NaN;if(c.window.unshift(h),c.sum+=h,c.window.length<s)return NaN;if(c.window.length>s){const x=c.window.pop();c.sum-=x}const l=c.sum/s;let f=0;for(let x=0;x<s;x++)f+=Math.pow(c.window[x]-l,2);const g=a?s:s-1,p=Math.sqrt(f/g);return e.precision(p)}}function oh(e){return(t,i,r,n,s)=>{const a=d.from(n).get(0);e.taState||(e.taState={});const o=s||`stoch_${a}`;e.taState[o]||(e.taState[o]={highWindow:[],lowWindow:[]});const c=e.taState[o],h=d.from(t).get(0),l=d.from(i).get(0),f=d.from(r).get(0);if(isNaN(h)||isNaN(l)||isNaN(f))return NaN;if(c.highWindow.unshift(l),c.lowWindow.unshift(f),c.highWindow.length<a)return NaN;c.highWindow.length>a&&(c.highWindow.pop(),c.lowWindow.pop());let g=c.highWindow[0],p=c.lowWindow[0];for(let w=1;w<a;w++)c.highWindow[w]>g&&(g=c.highWindow[w]),c.lowWindow[w]<p&&(p=c.lowWindow[w]);const x=g-p;if(x===0)return NaN;const y=100*(h-p)/x;return e.precision(y)}}function ch(e){return(t,i,r)=>{const n=d.from(t).get(0),s=d.from(i).get(0);e.taState||(e.taState={});const a=r||`supertrend_${n}_${s}`;e.taState[a]||(e.taState[a]={trWindow:[],trSum:0,atrValue:NaN,atrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,prevClose:NaN});const o=e.taState[a],c=e.get(e.data.high,0),h=e.get(e.data.low,0),l=e.get(e.data.close,0);if(isNaN(c)||isNaN(h)||isNaN(l))return[[NaN,NaN]];const f=(c+h)/2;let g;isNaN(o.prevClose)?g=c-h:g=Math.max(c-h,Math.abs(c-o.prevClose),Math.abs(h-o.prevClose)),o.atrCount++,o.atrCount<=s?(o.trWindow.push(g),o.trSum+=g,o.atrCount===s&&(o.atrValue=o.trSum/s)):o.atrValue=(o.atrValue*(s-1)+g)/s;const p=o.atrValue,x=o.prevClose;if(o.prevClose=l,isNaN(p))return[[NaN,NaN]];let y=f+n*p,w=f-n*p;const S=isNaN(o.prevLowerBand)?0:o.prevLowerBand,k=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>S||x<S||(w=S),isNaN(o.prevUpperBand)||y<k||x>k||(y=k);let C,A;const N=o.prevSuperTrend;return o.atrCount===s?C=1:N===o.prevUpperBand?C=l>y?-1:1:C=l<w?1:-1,A=C===-1?w:y,o.prevLowerBand=w,o.prevUpperBand=y,o.prevSuperTrend=A,o.prevDirection=C,[[e.precision(A),C]]}}function hh(e){return(t,i)=>{const r=[1,2,2,1],n=6;e.taState||(e.taState={});const s=i||"swma";e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],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 c=0;for(let h=0;h<4;h++)c+=r[h]*a.window[3-h];return c/=n,e.precision(c)}}function uh(e){return(t,i)=>{let r=!0;typeof t=="string"||t!==void 0&&(r=d.from(t).get(0));const n=e.get(e.data.high,0),s=e.get(e.data.low,0),a=e.get(e.data.close,1);if(isNaN(a))return r?e.precision(n-s):NaN;const o=Math.max(n-s,Math.abs(n-a),Math.abs(s-a));return e.precision(o)}}function lh(e){return(t,i,r,n)=>{const s=d.from(i).get(0),a=d.from(r).get(0);e.taState||(e.taState={});const o=n||`tsi_${s}_${a}`;e.taState[o]||(e.taState[o]={prevSource:NaN,ema1_pc_multiplier:2/(a+1),ema1_pc_value:NaN,ema1_pc_count:0,ema1_pc_sum:0,ema2_pc_multiplier:2/(s+1),ema2_pc_value:NaN,ema2_pc_count:0,ema2_pc_sum:0,ema1_abs_multiplier:2/(a+1),ema1_abs_value:NaN,ema1_abs_count:0,ema1_abs_sum:0,ema2_abs_multiplier:2/(s+1),ema2_abs_value:NaN,ema2_abs_count:0,ema2_abs_sum:0});const c=e.taState[o],h=d.from(t).get(0);if(isNaN(h))return NaN;const l=isNaN(c.prevSource)?NaN:h-c.prevSource;if(c.prevSource=h,isNaN(l))return NaN;const f=Math.abs(l);if(c.ema1_pc_count++,c.ema1_pc_count<=a?(c.ema1_pc_sum+=l,c.ema1_pc_count===a&&(c.ema1_pc_value=c.ema1_pc_sum/a)):c.ema1_pc_value=l*c.ema1_pc_multiplier+c.ema1_pc_value*(1-c.ema1_pc_multiplier),c.ema1_abs_count++,c.ema1_abs_count<=a?(c.ema1_abs_sum+=f,c.ema1_abs_count===a&&(c.ema1_abs_value=c.ema1_abs_sum/a)):c.ema1_abs_value=f*c.ema1_abs_multiplier+c.ema1_abs_value*(1-c.ema1_abs_multiplier),isNaN(c.ema1_pc_value)||isNaN(c.ema1_abs_value))return NaN;if(c.ema2_pc_count++,c.ema2_pc_count<=s?(c.ema2_pc_sum+=c.ema1_pc_value,c.ema2_pc_count===s&&(c.ema2_pc_value=c.ema2_pc_sum/s)):c.ema2_pc_value=c.ema1_pc_value*c.ema2_pc_multiplier+c.ema2_pc_value*(1-c.ema2_pc_multiplier),c.ema2_abs_count++,c.ema2_abs_count<=s?(c.ema2_abs_sum+=c.ema1_abs_value,c.ema2_abs_count===s&&(c.ema2_abs_value=c.ema2_abs_sum/s)):c.ema2_abs_value=c.ema1_abs_value*c.ema2_abs_multiplier+c.ema2_abs_value*(1-c.ema2_abs_multiplier),isNaN(c.ema2_pc_value)||isNaN(c.ema2_abs_value))return NaN;if(c.ema2_abs_value===0)return e.precision(0);const g=c.ema2_pc_value/c.ema2_abs_value;return e.precision(g)}}function ph(e){return(t,i,r,n)=>{e.taState||(e.taState={});const s=n||"valuewhen";e.taState[s]||(e.taState[s]={values:[]});const a=e.taState[s],o=d.from(t).get(0),c=d.from(i).get(0),h=d.from(r).get(0);if(o&&a.values.push(c),isNaN(h)||h<0)return NaN;const l=a.values.length-1-h;if(l<0)return NaN;const f=a.values[l];return typeof f=="number"?e.precision(f):f}}function fh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`variance_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();let c=0,h=0;for(let g=0;g<n;g++)c+=a.window[g],h+=a.window[g]*a.window[g];const l=c/n,f=h/n-l*l;return e.precision(f)}}function mh(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 n=e.taState[r],s=d.from(t).get(0),a=d.from(e.data.volume).get(0),o=d.from(e.data.openTime).get(0),c=new Date(o).toISOString().slice(0,10);if(n.lastSessionDate!==c&&(n.cumulativePV=0,n.cumulativeVolume=0,n.lastSessionDate=c),n.cumulativePV+=s*a,n.cumulativeVolume+=a,n.cumulativeVolume===0)return NaN;const h=n.cumulativePV/n.cumulativeVolume;return e.precision(h)}}function dh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`vwma_${n}`;e.taState[s]||(e.taState[s]={window:[],volumeWindow:[]});const a=e.taState[s],o=d.from(t).get(0),c=e.get(e.data.volume,0);if(a.window.unshift(o),a.volumeWindow.unshift(c),a.window.length<n)return NaN;a.window.length>n&&(a.window.pop(),a.volumeWindow.pop());let h=0,l=0;for(let g=0;g<n;g++)h+=a.window[g]*a.volumeWindow[g],l+=a.volumeWindow[g];const f=h/l;return e.precision(f)}}function gh(e){return t=>{e.taState||(e.taState={});const i=t||"wad";e.taState[i]||(e.taState[i]={cumulativeSum:0});const r=e.taState[i],n=e.get(e.data.close,0),s=e.get(e.data.high,0),a=e.get(e.data.low,0),o=e.get(e.data.close,1);if(isNaN(n)||isNaN(s)||isNaN(a))return e.precision(r.cumulativeSum);let c=0;if(!isNaN(o)){const h=Math.max(s,o),l=Math.min(a,o),f=n-o;f>0?c=n-l:f<0&&(c=n-h)}return r.cumulativeSum+=c,e.precision(r.cumulativeSum)}}function xh(e){return(t,i,r)=>{const n=d.from(i).get(0);e.taState||(e.taState={});const s=r||`wma_${n}`;e.taState[s]||(e.taState[s]={window:[]});const a=e.taState[s],o=d.from(t).get(0);if(a.window.unshift(o),a.window.length<n)return NaN;a.window.length>n&&a.window.pop();let c=0,h=0;for(let f=0;f<n;f++){const g=n-f;c+=a.window[f]*g,h+=g}const l=c/h;return e.precision(l)}}function yh(e){return(t,i)=>{const r=d.from(t).get(0);e.taState||(e.taState={});const n=i||`wpr_${r}`;e.taState[n]||(e.taState[n]={highWindow:[],lowWindow:[]});const s=e.taState[n],a=e.get(e.data.high,0),o=e.get(e.data.low,0),c=e.get(e.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(c))return NaN;if(s.highWindow.unshift(a),s.lowWindow.unshift(o),s.highWindow.length<r)return NaN;s.highWindow.length>r&&(s.highWindow.pop(),s.lowWindow.pop());let h=s.highWindow[0],l=s.lowWindow[0];for(let p=1;p<r;p++)s.highWindow[p]>h&&(h=s.highWindow[p]),s.lowWindow[p]<l&&(l=s.lowWindow[p]);const f=h-l;if(f===0)return e.precision(0);const g=(h-c)/f*-100;return e.precision(g)}}function wh(e){return t=>{const i=e.get(e.data.close,0),r=e.get(e.data.open,0),n=e.get(e.data.high,0),s=e.get(e.data.low,0),a=e.get(e.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(s)||isNaN(a))return NaN;const o=n-s;if(o===0)return e.precision(0);const c=(i-r)/o*a;return e.precision(c)}}const bh={accdist:cc,alma:hc,atr:uc,barssince:lc,bb:pc,bbw:fc,cci:mc,change:dc,cmo:gc,cog:xc,correlation:yc,cross:wc,crossover:bc,crossunder:vc,cum:_c,dev:Sc,dmi:Ec,ema:Nc,falling:Cc,highest:kc,highestbars:Ic,hma:Ac,iii:Tc,kc:Pc,kcw:Rc,linreg:Dc,lowest:Mc,lowestbars:Vc,macd:Oc,median:Lc,mfi:Bc,mode:Fc,mom:jc,nvi:$c,obv:Wc,param:qc,percentile_linear_interpolation:Uc,percentile_nearest_rank:Kc,percentrank:zc,pivothigh:Gc,pivotlow:Qc,pvi:Xc,pvt:Zc,range:Jc,rising:eh,rma:th,roc:ih,rsi:rh,sar:nh,sma:sh,stdev:ah,stoch:oh,supertrend:ch,swma:hh,tr:uh,tsi:lh,valuewhen:ph,variance:fh,vwap:mh,vwma:dh,wad:gh,wma:xh,wpr:yh,wvad:wh};class vh{constructor(t){this.context=t,Object.entries(bh).forEach(([i,r])=>{this[i]=r(t)})}accdist;alma;atr;barssince;bb;bbw;cci;change;cmo;cog;correlation;cross;crossover;crossunder;cum;dev;dmi;ema;falling;highest;highestbars;hma;iii;kc;kcw;linreg;lowest;lowestbars;macd;median;mfi;mode;mom;nvi;obv;param;percentile_linear_interpolation;percentile_nearest_rank;percentrank;pivothigh;pivotlow;pvi;pvt;range;rising;rma;roc;rsi;sar;sma;stdev;stoch;supertrend;swma;tr;tsi;valuewhen;variance;vwap;vwma;wad;wma;wpr;wvad}class _h{constructor(t){this.context=t}logFormat(t,...i){return t.replace(/{(\d+)}/g,(r,n)=>i[n])}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 Sh{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,n=0){const s=String(t),a=String(i),o=String(r),c=Math.floor(Number(n))||0;if(a==="")return s;let h=0,l=0;for(;;){const f=s.indexOf(a,h);if(f===-1)return s;if(l===c)return s.substring(0,f)+o+s.substring(f+a.length);l++,h=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,n)=>i[n])}}class Eh{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 Nh=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],Ch={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 kh{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 n=d.from(t).get(0);this.context.plots[i].data.push({time:this.context.marketData[this.context.idx].openTime,value:n,options:{...this.extractPlotOptions(r),style:"char"}})}plot(...t){const i=Vt(t,Nh,Ch),{series:r,title:n,...s}=i,a=this.extractPlotOptions(s);this.context.plots[n]||(this.context.plots[n]={data:[],options:a,title:n});const o=d.from(r).get(0);this.context.plots[n].data.push({time:this.context.marketData[this.context.idx].openTime,value:o,options:{color:a.color,offset:a.offset}})}}class Ih{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,n,s,a,o){return this.context.pine.plot(t,{title:i,color:r,linestyle:n,linewidth:s,editable:a,display:o})}}class Re{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([])};indicator;cache={};taState={};isSecondaryContext=!1;NA=NaN;lang;pine;static _deprecationWarningsShown=new Set;idx=0;params={};const={};var={};let={};result=void 0;plots={};marketData;source;tickerId;timeframe="";limit;sDate;eDate;fullContext;pineTSCode;constructor({marketData:t,source:i,tickerId:r,timeframe:n,limit:s,sDate:a,eDate:o,fullContext:c}){this.marketData=t,this.source=i,this.tickerId=r,this.timeframe=n,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=c||this;const h=new so(this),l={na:h.na.bind(h),color:h.color,nz:h.nz.bind(h),indicator:h.indicator.bind(h),fixnan:h.fixnan.bind(h),alertcondition:h.alertcondition.bind(h),bool:h.bool.bind(h)},f=this;this.pine={input:new No(this),ta:new vh(this),math:new ic(this),request:new oc(this),array:new $s(this),map:new ea(this),matrix:new eo(this),syminfo:null,timeframe:new Eh(this),barstate:new to(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 _h(this),str:new Sh(this),...l,...Cs};const g=new kh(this),p=new Ih(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 n=r?this.pine[r]:this.pine;for(const s of i)typeof t[s]=="function"?n[s]=t[s].bind(t):n[s]=t[s]}init(t,i,r=0){let n;return i instanceof d?n=i.get(0):Array.isArray(i)?Array.isArray(i[0])?n=i[0]:n=i[i.length-1+r]:n=i,t?t instanceof d?(t.data[t.data.length-1]=n,t):Array.isArray(t)?(t[t.length-1]=n,new d(t)):new d([n]):new d([n])}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}`;Re._deprecationWarningsShown.has(r)||(Re._deprecationWarningsShown.add(r),typeof window<"u"?console.warn("%c[WARNING]%c %s syntax is deprecated. Use %s instead. This will be removed in a future version.","color: #FFA500; font-weight: bold;","color: #FFA500;",t,i):console.warn(`\x1B[33m[WARNING] ${t} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}}class Ot{constructor(t,i,r,n,s,a){this.source=t,this.tickerId=i,this.timeframe=r,this.limit=n,this.sDate=s,this.eDate=a,this._readyPromise=new Promise(o=>{this.loadMarketData(t,i,r,n,s,a).then(c=>{const h=c;this.data=h;const l=h.map(N=>N.open),f=h.map(N=>N.close),g=h.map(N=>N.high),p=h.map(N=>N.low),x=h.map(N=>N.volume),y=h.map(N=>(N.high+N.low+N.close)/3),w=h.map(N=>(N.high+N.low)/2),S=h.map(N=>(N.high+N.low+N.open+N.close)/4),k=h.map(N=>(N.high+N.low+N.close+N.close)/4),C=h.map(N=>N.openTime),A=h.map(N=>N.closeTime);this.open=l,this.close=f,this.high=g,this.low=p,this.volume=x,this.hl2=w,this.hlc3=y,this.ohlc4=S,this.hlcc4=k,this.openTime=C,this.closeTime=A,t&&t.getSymbolInfo?t.getSymbolInfo(i).then(N=>{this._syminfo=N,this._ready=!0,o(!0)}).catch(N=>{console.warn("Failed to get symbol info, using default values:",N),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}data=[];open=[];high=[];low=[];close=[];volume=[];hl2=[];hlc3=[];ohlc4=[];hlcc4=[];openTime=[];closeTime=[];_readyPromise=null;_ready=!1;_debugSettings={ln:!1,debug:!1};_transpiledCode=null;get transpiledCode(){return this._transpiledCode}_isSecondaryContext=!1;markAsSecondary(){this._isSecondaryContext=!0}_syminfo;setDebugSettings({ln:t,debug:i}){this._debugSettings.ln=t,this._debugSettings.debug=i}async loadMarketData(t,i,r,n,s,a){return Array.isArray(t)?t:t.getMarketData(i,r,n,s,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 n=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(t,i,r,n)}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,n=!1){await this.ready(),i||(i=this.data.length);const s=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(s.result);await this._executeIterations(s,this._transpiledCode,a,a+l),a+=l,yield this._createPageContext(s,f);continue}if(!n||Array.isArray(this.source))break;const{newCandles:c,updatedLastCandle:h}=await this._updateMarketData();if(c===0&&!h){yield null;continue}this._removeLastResult(s),a=this.data.length-(c+1),s.pine.barstate.setLive()}}_getResultLength(t){if(Array.isArray(t))return t.length;if(typeof t=="object"&&t!==null){const 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 Re({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 n in t.result)Array.isArray(t.result[n])?r.result[n]=t.result[n].slice(i):r.result[n]=t.result[n]}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,n=this.data[r].openTime;try{const s=await i.getMarketData(this.tickerId,this.timeframe,void 0,n,t);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let c=0;c<s.length;c++){const h=s[c];h.openTime===n?(this._replaceCandle(r,h),a=!0):h.openTime>n&&(this._appendCandle(h),o++)}return{newCandles:o,updatedLastCandle:a}}catch(s){return console.error("Error updating market data:",s),{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 Re({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 Wn.bind(this)(t,this._debugSettings)}async _executeIterations(t,i,r,n){const s=["const","var","let","params"];for(let a=r;a<n;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 c in o){t.result[c]===void 0&&(t.result[c]=[]);let h;o[c]instanceof d?h=o[c].get(0):Array.isArray(o[c])?h=o[c][o[c].length-1]:h=o[c],t.result[c].push(h)}}else Array.isArray(t.result)||(t.result=[]),t.result.push(o);for(let c of s)for(let h in t[c]){const l=t[c][h];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)}}}}}const oi="https://api.binance.com/api/v3",dt={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 Ah{cache;cacheDuration;constructor(t=5*60*1e3){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 Th{cacheManager;constructor(){this.cacheManager=new Ah(5*60*1e3)}async getMarketDataInterval(t,i,r,n){try{const s=dt[i.toUpperCase()];if(!s)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=[],c=r;const h=n,l=a[s];if(!l)return console.error(`Duration not defined for interval: ${s}`),[];for(;c<h;){const f=Math.min(c+1e3*l,h),g=await this.getMarketData(t,i,1e3,c,f);if(g.length===0)break;o=o.concat(g),c=g[g.length-1].closeTime+1}return o}catch(s){return console.error("Error in getMarketDataInterval:",s),[]}}async getMarketData(t,i,r,n,s){try{const a=s!==void 0,o={tickerId:t,timeframe:i,limit:r,sDate:n,eDate:s};if(a){const g=this.cacheManager.get(o);if(g)return g}const c=dt[i.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,n,s)&&n&&s){const g=await this.getMarketDataInterval(t,i,n,s),p=r?g.slice(0,r):g;return this.cacheManager.set(o,p),p}let h=`${oi}/klines?symbol=${t}&interval=${c}`;r&&(h+=`&limit=${Math.min(r,1e3)}`),n&&(h+=`&startTime=${n}`),s&&(h+=`&endTime=${s}`);const l=await fetch(h);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,n){if(i&&i>1e3)return!0;if(r&&n){const s=dt[t.toUpperCase()],a={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3}[s];if(a)return Math.ceil((n-r)/a)>1e3}return!1}async getSymbolInfo(t){try{let i="crypto",r=oi,n=t,s="";t.endsWith(".P")?(i="futures",n=t.replace(".P",""),r="https://fapi.binance.com/fapi/v1",s="Perpetual"):t.includes("_")&&(i="futures",n=t,r="https://dapi.binance.com/dapi/v1",s="Delivery");const a=i==="crypto"?`${r}/exchangeInfo?symbol=${n}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const c=(await o.json()).symbols;if(!c||c.length===0)return console.error(`Symbol ${t} not found`),null;const h=i==="futures"?c.find(C=>C.symbol===n):c[0];if(!h)return console.error(`Symbol ${n} not found in exchange info`),null;const l=h.filters?.find(C=>C.filterType==="PRICE_FILTER"),f=h.filters?.find(C=>C.filterType==="LOT_SIZE"),g=l?parseFloat(l.tickSize):.01,p=f?parseFloat(f.minQty):0,x=Math.round(1/g),y=h.baseAsset,w=h.quoteAsset,S=s?` ${s}`:"",k=`${y} / ${w}${S}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:y,description:k,type:i,main_tickerid:`BINANCE:${t}`,current_contract:s,isin:"",basecurrency:y,currency:w,timezone:"Etc/UTC",country:"",mintick:g,pricescale:x,minmove:1,pointvalue:h.contractSize||1,mincontract:p,session:"24x7",volumetype:"base",expiration_date:h.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}}}const Ph=sr.fileURLToPath(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||new URL("pinets.min.cjs",document.baseURI).href),Rh=je.dirname(Ph);class Dh{dataCache=new Map;exchangeInfoCache={};dataDirectory;constructor(t){if(t)this.dataDirectory=t;else{const i=je.resolve(Rh,"../../../");this.dataDirectory=je.join(i,"tests","compatibility","_data")}}getDataFileName(t,i,r,n){return r&&n?`${t}-${i}-${r}-${n}.json`:null}loadDataFromFile(t){const i=`file:${t}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=je.join(this.dataDirectory,t);if(!ke.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const n=ke.readFileSync(r,"utf-8"),s=JSON.parse(n);return this.dataCache.set(i,s),s}findDataFile(t,i,r,n){if(!ke.existsSync(this.dataDirectory))return null;const s=ke.readdirSync(this.dataDirectory).filter(c=>c.endsWith(".json"));if(r&&n){const c=`${t}-${i}-${r}-${n}.json`;if(s.includes(c))return c}const a=new RegExp(`^${t}-${i}-(\\d+)-(\\d+)\\.json$`),o=s.filter(c=>a.test(c)).map(c=>{const h=c.match(a);return{file:c,startTime:parseInt(h[1]),endTime:parseInt(h[2])}}).sort((c,h)=>h.endTime-c.endTime);if(o.length===0)return null;if(r&&n){const c=o.find(h=>h.startTime<=r&&h.endTime>=n);if(c)return c.file}return o[0].file}filterData(t,i,r,n){let s=t;return(i||r)&&(s=t.filter(a=>{const o=!i||a.openTime>=i,c=!r||a.openTime<=r;return o&&c})),s.sort((a,o)=>a.openTime-o.openTime),n&&n>0&&(s=s.slice(0,n)),s}normalizeTimeframe(t){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[t.toUpperCase()]||t.toLowerCase()}async getMarketData(t,i,r,n,s){try{const a=this.normalizeTimeframe(i),o=this.findDataFile(t,a,n,s);if(!o)return console.warn(`No mock data file found for ${t} ${a}. Searched in: ${this.dataDirectory}`),[];const c=this.loadDataFromFile(o);return this.filterData(c,n,s,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=je.join(this.dataDirectory,i);if(!ke.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const n=ke.readFileSync(r,"utf-8"),s=JSON.parse(n);return this.exchangeInfoCache[t]=s,s}catch(n){return console.error(`Error loading exchange info from ${i}:`,n),null}}async getSymbolInfo(t){try{let i="crypto",r=t,n="";t.endsWith(".P")?(i="futures",r=t.replace(".P",""),n="Perpetual"):t.includes("_")&&(i="futures",r=t,n="Delivery");const s=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!s||!s.symbols)return console.error(`Exchange info not available for ${i}`),null;const a=s.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"),c=a.filters?.find(w=>w.filterType==="LOT_SIZE"),h=o?parseFloat(o.tickSize):.01,l=c?parseFloat(c.minQty):0,f=Math.round(1/h),g=a.baseAsset,p=a.quoteAsset,x=n?` ${n}`:"",y=`${g} / ${p}${x}`;return{ticker:t,tickerid:`BINANCE:${t}`,prefix:"BINANCE",root:g,description:y,type:i,main_tickerid:`BINANCE:${t}`,current_contract:n,isin:"",basecurrency:g,currency:p,timezone:"Etc/UTC",country:"",mintick:h,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 Mh=typeof process<"u"&&process.versions&&process.versions.node;let rt=null;if(Mh)try{rt=new Dh}catch{rt=null}const Vh={Binance:new Th,...rt?{Mock:rt}:{}};exports.Context=Re;exports.PineTS=Ot;exports.Provider=Vh;
|
|
117
117
|
//# sourceMappingURL=pinets.min.cjs.map
|