pinets 0.9.12 → 0.9.13
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/dist/pinets.min.browser.es.js +1 -1
- 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.es.js
CHANGED
|
@@ -118,5 +118,5 @@ ${t}
|
|
|
118
118
|
`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let i=0;i<e.expressions.length;i++)this.generateExpression(e.expressions[i]),i<e.expressions.length-1&&this.write(", ");this.write(")")}getPrecedence(e){switch(e.type){case"Literal":case"Identifier":case"ArrayExpression":case"ObjectExpression":return 20;case"CallExpression":case"MemberExpression":return 19;case"UnaryExpression":case"UpdateExpression":return 15;case"BinaryExpression":case"LogicalExpression":switch(e.operator){case"*":case"/":case"%":return 13;case"+":case"-":return 12;case"<":case"<=":case">":case">=":return 10;case"==":case"!=":return 9;case"and":case"&&":return 5;case"or":case"||":return 4;default:return 0}case"ConditionalExpression":return 3;case"AssignmentExpression":case"AssignmentPattern":return 2;case"SequenceExpression":return 1;default:return 0}}}function qs(t){const e=/^\s*\/\/\s*@version\s*=\s*(\d+)\s*$/im,i=t.match(e);return i&&i[1]?parseInt(i[1],10):null}function no(t,e={}){const i=qs(t);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 Fa(t).tokenize(),s=new eo(r).parse(),a={...e,sourceCode:t},n=new so(a).generate(s);return{success:!0,version:i,code:n,ast:s,tokens:r}}catch(r){return{success:!1,version:i,error:r.message,stack:r.stack}}}function ao(t){if(typeof t=="function")return t.toString();{const e=qs(t);if(e===null)return t;if(e>=5){const i=no(t);if(i.success)return i.code;throw new Error(`Failed to transpile Pine Script version ${e}: ${i.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function oo(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});const{debug:i}=e;let r=ao(t);r=wa(r);const s=i?r.split(`
|
|
119
119
|
`):[],a=Vs(r,{ecmaVersion:"latest",sourceType:"module",locations:i});Sa(a),_a(a),xa(a);const n=new pa;Ea(a,n);const o=Ca(a,n)||"";if(Oa(a,n,o,e,s),Ra(a),Ma(a),a.type==="Program"&&a.body.length>0){const p=a.body[0],u=p?.expression||p;u.body?.type==="BlockStatement"&&u.body.body.unshift({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"__maxLoops"},init:{type:"LogicalExpression",operator:"||",left:{type:"MemberExpression",object:{type:"Identifier",name:"$"},property:{type:"Identifier",name:"__maxLoops"},computed:!1},right:{type:"Literal",value:5e5}}}]})}const l=aa||rr||void 0,c=Object.assign({},l,{LineComment(p,u){u.write("//"+p.value)}}),h=$s(a,{generator:c,comments:i});return new Function("",`var _r = ${h}
|
|
120
120
|
; return _r;`)(this)}function lo(t){return e=>new R(e.array.map(i=>Math.abs(i)),e.type,t)}function co(t){return e=>{let i=0,r=0;for(const s of e.array){const a=Number(s);isNaN(a)||(r++,i+=(a-i)/r)}return r===0?NaN:t.precision(i)}}function ho(t){return(e,i)=>{const r=e.array;let s=0,a=r.length-1;for(;s<=a;){const n=Math.floor((s+a)/2),o=r[n];if(o===i)return n;o<i?s=n+1:a=n-1}return-1}}function uo(t){return(e,i)=>{const r=e.array;let s=0,a=r.length;for(;s<a;){const n=Math.floor((s+a)/2);r[n]<i?s=n+1:a=n}return s<r.length&&r[s]===i?s:s-1}}function po(t){return(e,i)=>{const r=e.array;let s=0,a=r.length;for(;s<a;){const n=Math.floor((s+a)/2);r[n]<=i?s=n+1:a=n}return s>0&&r[s-1]===i?s-1:s}}function fo(t){return e=>{e.array.length=0}}function mo(t){return(e,i)=>(e.array.push(...i.array),e)}function go(t){return e=>new R([...e.array],e.type,t)}function yo(t){return(e,i,r=!0)=>{const s=e.array,a=i.array;if(s.length!==a.length)return NaN;let n=0,o=0,l=0;const c=[];for(let m=0;m<s.length;m++){const x=Number(s[m]),_=Number(a[m]);!isNaN(x)&&x!==null&&x!==void 0&&!isNaN(_)&&_!==null&&_!==void 0&&(n+=x,o+=_,l++,c.push(m))}if(l===0)return NaN;const h=n/l,p=o/l;let u=0;for(const m of c){const x=Number(s[m]),_=Number(a[m]);u+=(x-h)*(_-p)}const f=r?l:l-1;return f<=0?NaN:t.precision(u/f)}}function xo(t){return e=>e.array.every(i=>!isNaN(i)&&i)}function _o(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?D.int:D.float:t.every(e=>typeof e=="string")?D.string:t.every(e=>typeof e=="boolean")?D.bool:D.any}function Re(t){return typeof t=="number"?Number.isInteger(t)?D.int:D.float:typeof t=="string"?D.string:typeof t=="boolean"?D.bool:D.any}function Yt(t,e){if(typeof t=="number"&&isNaN(t)||e===D.any)return!0;switch(e){case D.int:return Number.isInteger(t)||isNaN(t);case D.float:return typeof t=="number";case D.string:return typeof t=="string";case D.bool:return typeof t=="boolean";case D.box:case D.label:case D.line:case D.linefill:case D.table:case D.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function bo(t){return(e,i,r=0,s)=>{const a=e.array.length,n=s!==void 0?Math.min(s,a):a;for(let o=r;o<n;o++){if(!Yt(i,e.type))throw new Error(`Cannot call 'array.fill' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array[o]=typeof i=="number"?t.precision(i):i}}}function vo(t){return e=>e.array.length>0?e.array[0]:t.NA}function wo(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[i])}function So(t){return(e,i)=>e.array.includes(i)}function Eo(t){return(e,i)=>typeof i=="number"&&i!==i?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(i)}function No(t){return(e,i,r)=>{if(!Yt(r,e.type))throw new Error(`Cannot call 'array.insert' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(i,0,r)}}function Co(t){return(e,i=",")=>e.array.join(i)}function Io(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function ko(t){return(e,i)=>e.array.lastIndexOf(i)}function Ao(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let s=r[0];for(let a=1;a<r.length;a++)r[a]>s&&(s=r[a]);return s??t.NA}return[...r].sort((s,a)=>a-s)[i]??t.NA}}function To(t){return e=>{const i=e.array;if(i.length===0)return NaN;const r=new Array(i.length);for(let a=0;a<i.length;a++)r[a]=i[a];r.sort((a,n)=>a-n);const s=Math.floor(r.length/2);return r.length%2!==0?r[s]:(r[s-1]+r[s])/2}}function Po(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let s=r[0];for(let a=1;a<r.length;a++)r[a]<s&&(s=r[a]);return s??t.NA}return[...r].sort((s,a)=>s-a)[i]??t.NA}}function Do(t){return e=>{if(e.array.length===0)return NaN;const i=new Map;let r=0;for(const a of e.array){const n=(i.get(a)||0)+1;i.set(a,n),n>r&&(r=n)}const s=[];for(const[a,n]of i)n===r&&s.push(a);return s.sort((a,n)=>typeof a=="number"&&typeof n=="number"?a-n:typeof a=="string"&&typeof n=="string"?a<n?-1:a>n?1:0:0),s[0]}}function Mo(t){return(e,i)=>{const r=e.array,s=r.length;if(s===0)return NaN;const a=new Array(s);for(let c=0;c<s;c++){const h=Number(r[c]);if(isNaN(h)||h===null||h===void 0)return NaN;a[c]=h}a.sort((c,h)=>c-h),i<0&&(i=0),i>100&&(i=100);const n=i/100*s-.5;if(n<=0)return t.precision(a[0]);if(n>=s-1)return t.precision(a[s-1]);const o=Math.floor(n),l=n-o;return t.precision(a[o]*(1-l)+a[o+1]*l)}}function Ro(t){return(e,i)=>{const r=e.array,s=r.length;if(s===0)return NaN;const a=new Array;for(let o=0;o<s;o++){const l=Number(r[o]);!isNaN(l)&&l!==null&&l!==void 0&&a.push(l)}if(a.length===0)return NaN;a.sort((o,l)=>o-l),i<0&&(i=0),i>100&&(i=100);const n=Math.ceil(i/100*s);return n<=0?a[0]:n>a.length?NaN:a[n-1]}}function Oo(t){return(e,i)=>{if(e.array.length===0)return NaN;const r=Math.floor(i);if(r<0||r>=e.array.length)return NaN;const s=Number(e.array[r]);if(isNaN(s)||s===null||s===void 0)return NaN;let a=0;for(const o of e.array){const l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<s&&a++}const n=e.array.length-1;return n<=0?NaN:a/n*100}}function Vo(t){return e=>e.array.pop()}function Lo(t){return(e,i)=>{if(!Yt(i,e.type))throw new Error(`Cannot call 'array.push' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.push(typeof i=="number"?t.precision(i):i)}}function $o(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function jo(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(i,1)[0])}function Bo(t){return e=>{e.array.reverse()}}function Fo(t){return(e,i,r)=>{if(!Yt(r,e.type))throw new Error(`Cannot call 'array.set' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>=e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[i]=typeof r=="number"?t.precision(r):r}}function Wo(t){return e=>e.array.shift()}function Uo(t){return e=>e.array.length}function qo(t){return(e,i,r)=>{const s=r!==void 0?r:void 0;return new R(e.array.slice(i,s),e.type,t)}}function Ko(t){return e=>e.array.some(i=>!isNaN(i)&&i)}var Tt=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(Tt||{}),Ks=(t=>(t.AED="AED",t.ARS="ARS",t.AUD="AUD",t.BDT="BDT",t.BHD="BHD",t.BRL="BRL",t.BTC="BTC",t.CAD="CAD",t.CHF="CHF",t.CLP="CLP",t.CNY="CNY",t.COP="COP",t.CZK="CZK",t.DKK="DKK",t.EGP="EGP",t.ETH="ETH",t.EUR="EUR",t.GBP="GBP",t.HKD="HKD",t.HUF="HUF",t.IDR="IDR",t.ILS="ILS",t.INR="INR",t.ISK="ISK",t.JPY="JPY",t.KES="KES",t.KRW="KRW",t.KWD="KWD",t.LKR="LKR",t.MAD="MAD",t.MXN="MXN",t.MYR="MYR",t.NGN="NGN",t.NOK="NOK",t.NONE="NONE",t.NZD="NZD",t.PEN="PEN",t.PHP="PHP",t.PKR="PKR",t.PLN="PLN",t.QAR="QAR",t.RON="RON",t.RSD="RSD",t.RUB="RUB",t.SAR="SAR",t.SEK="SEK",t.SGD="SGD",t.THB="THB",t.TND="TND",t.TRY="TRY",t.TWD="TWD",t.USD="USD",t.USDT="USDT",t.VES="VES",t.VND="VND",t.ZAR="ZAR",t))(Ks||{}),zs=(t=>(t[t.sunday=1]="sunday",t[t.monday=2]="monday",t[t.tuesday=3]="tuesday",t[t.wednesday=4]="wednesday",t[t.thursday=5]="thursday",t[t.friday=6]="friday",t[t.saturday=7]="saturday",t))(zs||{}),Hs=(t=>(t.all="all",t.data_window="data_window",t.none="none",t.pane="pane",t.price_scale="price_scale",t.status_line="status_line",t))(Hs||{}),Gs=(t=>(t.flag="shape_flag",t.arrowdown="shape_arrow_down",t.arrowup="shape_arrow_up",t.circle="shape_circle",t.cross="shape_cross",t.diamond="shape_diamond",t.labeldown="shape_label_down",t.labelup="shape_label_up",t.square="shape_square",t.triangledown="shape_triangle_down",t.triangleup="shape_triangle_up",t.xcross="shape_xcross",t))(Gs||{}),Ys=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(Ys||{}),Xs=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(Xs||{}),Qs=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(Qs||{}),zo=(t=>(t.linestyle_dashed="linestyle_dashed",t.linestyle_dotted="linestyle_dotted",t.linestyle_solid="linestyle_solid",t.style_area="style_area",t.style_areabr="style_areabr",t.style_circles="style_circles",t.style_columns="style_columns",t.style_cross="style_cross",t.style_histogram="style_histogram",t.style_line="style_line",t.style_linebr="style_linebr",t.style_stepline="style_stepline",t.style_stepline_diamond="style_stepline_diamond",t.style_steplinebr="style_steplinebr",t))(zo||{}),Zs=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(Zs||{}),Js=(t=>(t.bar_index="bi",t.bar_time="bt",t))(Js||{}),en=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(en||{}),tn=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(tn||{}),rn=(t=>(t.align_bottom="bottom",t.align_top="top",t.align_left="left",t.align_center="center",t.align_right="right",t.wrap_auto="auto",t.wrap_none="none",t.format_bold="bold",t.format_italic="italic",t.format_none="none",t))(rn||{}),sn=(t=>(t.family_default="default",t.family_monospace="monospace",t))(sn||{}),nn=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(nn||{}),an=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(an||{}),on=(t=>(t.actual="earnings_actual",t.estimate="earnings_estimate",t.standardized="earnings_standardized",t.future_eps="earnings_future_eps",t.future_period_end_time="earnings_future_period_end_time",t.future_revenue="earnings_future_revenue",t.future_time="earnings_future_time",t))(on||{}),ln=(t=>(t.gross="dividends_gross",t.net="dividends_net",t.future_amount="dividends_future_amount",t.future_ex_date="dividends_future_ex_date",t.future_pay_date="dividends_future_pay_date",t))(ln||{}),cn=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(cn||{}),hn=(t=>(t.top_left="top_left",t.top_center="top_center",t.top_right="top_right",t.middle_left="middle_left",t.middle_center="middle_center",t.middle_right="middle_right",t.bottom_left="bottom_left",t.bottom_center="bottom_center",t.bottom_right="bottom_right",t))(hn||{}),un=(t=>(t.left="left",t.none="none",t.right="right",t))(un||{}),pn=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(pn||{});const Ho={order:Tt,currency:Ks,dayofweek:zs,display:Hs,shape:Gs,location:Ys,size:Xs,format:Qs,barmerge:Zs,xloc:Js,yloc:en,extend:tn,text:rn,font:sn,adjustment:nn,backadjustment:an,earnings:on,dividends:ln,splits:cn,position:hn,scale:un,settlement_as_close:pn};function Go(t){return(e,i=Tt.ascending)=>{e.array.sort((r,s)=>{let a=isNaN(r)?1/0:r,n=isNaN(s)?1/0:s;return i===Tt.ascending?a-n:n-a})}}function Yo(t){return(e,i=Tt.ascending)=>{const r=e.array.map((s,a)=>a);return r.sort((s,a)=>{const n=isNaN(e.array[s])?1/0:e.array[s],o=isNaN(e.array[a])?1/0:e.array[a];return i===Tt.ascending?n-o:o-n}),new R(r,D.int,t)}}function Xo(t){return e=>{const i=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new R(e.array.map(()=>NaN),D.int,t):r===0?new R(e.array.map(()=>1),D.int,t):new R(e.array.map(s=>(s-i)/r),D.int,t)}}function Qo(t){return(e,i=!0)=>{const r=e.array,s=r.length;if(s===0)return NaN;let a=0,n=0,o=0;for(let h=0;h<s;h++){const p=Number(r[h]);!isNaN(p)&&p!==null&&p!==void 0&&(a+=p,n+=p*p,o++)}if(o===0)return NaN;const l=a/o;let c=n/o-l*l;return c<0?NaN:(!i&&o>1&&(c=c*o/(o-1)),!i&&o===1?0:t.precision(Math.sqrt(c)))}}function Zo(t){return e=>t.precision(e.array.reduce((i,r)=>{const s=Number(r);return isNaN(s)?i:i+s},0))}function Jo(t){return(e,i)=>{if(!Yt(i,e.type))throw new Error(`Cannot call 'array.unshift' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.unshift(typeof i=="number"?t.precision(i):i)}}function el(t){return(e,i=!0)=>{let r=0,s=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,s++)}if(s===0)return NaN;const a=r/s;let n=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(n+=(c-a)*(c-a))}const o=i?s:s-1;return o<=0?NaN:t.precision(n/o)}}var tl=Object.defineProperty,il=(t,e,i)=>e in t?tl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,L=(t,e,i)=>il(t,typeof e!="symbol"?e+"":e,i),D=(t=>(t.any="",t.box="box",t.bool="bool",t.color="color",t.float="float",t.int="int",t.label="label",t.line="line",t.linefill="linefill",t.string="string",t.table="table",t))(D||{});class R{constructor(e,i,r){this.array=e,this.type=i,this.context=r,L(this,"_abs"),L(this,"_avg"),L(this,"_binary_search"),L(this,"_binary_search_leftmost"),L(this,"_binary_search_rightmost"),L(this,"_clear"),L(this,"_concat"),L(this,"_copy"),L(this,"_covariance"),L(this,"_every"),L(this,"_fill"),L(this,"_first"),L(this,"_get"),L(this,"_includes"),L(this,"_indexof"),L(this,"_insert"),L(this,"_join"),L(this,"_last"),L(this,"_lastindexof"),L(this,"_max"),L(this,"_median"),L(this,"_min"),L(this,"_mode"),L(this,"_percentile_linear_interpolation"),L(this,"_percentile_nearest_rank"),L(this,"_percentrank"),L(this,"_pop"),L(this,"_push"),L(this,"_range"),L(this,"_remove"),L(this,"_reverse"),L(this,"_set"),L(this,"_shift"),L(this,"_size"),L(this,"_slice"),L(this,"_some"),L(this,"_sort"),L(this,"_sort_indices"),L(this,"_standardize"),L(this,"_stdev"),L(this,"_sum"),L(this,"_unshift"),L(this,"_variance"),this._abs=lo(this.context),this._avg=co(this.context),this._binary_search=ho(this.context),this._binary_search_leftmost=uo(this.context),this._binary_search_rightmost=po(this.context),this._clear=fo(this.context),this._concat=mo(this.context),this._copy=go(this.context),this._covariance=yo(this.context),this._every=xo(this.context),this._fill=bo(this.context),this._first=vo(this.context),this._get=wo(this.context),this._includes=So(this.context),this._indexof=Eo(this.context),this._insert=No(this.context),this._join=Co(this.context),this._last=Io(this.context),this._lastindexof=ko(this.context),this._max=Ao(this.context),this._median=To(this.context),this._min=Po(this.context),this._mode=Do(this.context),this._percentile_linear_interpolation=Mo(this.context),this._percentile_nearest_rank=Ro(this.context),this._percentrank=Oo(this.context),this._pop=Vo(this.context),this._push=Lo(this.context),this._range=$o(this.context),this._remove=jo(this.context),this._reverse=Bo(this.context),this._set=Fo(this.context),this._shift=Wo(this.context),this._size=Uo(this.context),this._slice=qo(this.context),this._some=Ko(this.context),this._sort=Go(this.context),this._sort_indices=Yo(this.context),this._standardize=Xo(this.context),this._stdev=Qo(this.context),this._sum=Zo(this.context),this._unshift=Jo(this.context),this._variance=el(this.context)}toString(){return"["+this.array.toString().replace(/,/g,", ")+"]"}[Symbol.iterator](){return this.array[Symbol.iterator]()}abs(...e){return this._abs(this,...e)}avg(...e){return this._avg(this,...e)}binary_search(...e){return this._binary_search(this,...e)}binary_search_leftmost(...e){return this._binary_search_leftmost(this,...e)}binary_search_rightmost(...e){return this._binary_search_rightmost(this,...e)}clear(...e){return this._clear(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}covariance(...e){return this._covariance(this,...e)}every(...e){return this._every(this,...e)}fill(...e){return this._fill(this,...e)}first(...e){return this._first(this,...e)}get(...e){return this._get(this,...e)}includes(...e){return this._includes(this,...e)}indexof(...e){return this._indexof(this,...e)}insert(...e){return this._insert(this,...e)}join(...e){return this._join(this,...e)}last(...e){return this._last(this,...e)}lastindexof(...e){return this._lastindexof(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}percentile_linear_interpolation(...e){return this._percentile_linear_interpolation(this,...e)}percentile_nearest_rank(...e){return this._percentile_nearest_rank(this,...e)}percentrank(...e){return this._percentrank(this,...e)}pop(...e){return this._pop(this,...e)}push(...e){return this._push(this,...e)}range(...e){return this._range(this,...e)}remove(...e){return this._remove(this,...e)}reverse(...e){return this._reverse(this,...e)}set(...e){return this._set(this,...e)}shift(...e){return this._shift(this,...e)}size(...e){return this._size(this,...e)}slice(...e){return this._slice(this,...e)}some(...e){return this._some(this,...e)}sort(...e){return this._sort(this,...e)}sort_indices(...e){return this._sort_indices(this,...e)}standardize(...e){return this._standardize(this,...e)}stdev(...e){return this._stdev(this,...e)}sum(...e){return this._sum(this,...e)}unshift(...e){return this._unshift(this,...e)}variance(...e){return this._variance(this,...e)}}function rl(t){return(...e)=>new R([...e],_o(e),t)}function sl(t){return(e,i)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(i===void 0){const s=r?Array(r).fill(0):[];return new R(s,D.any,t)}return new R(Array(r).fill(t.precision(i||0)),Re(i||0),t)}}function nl(t){return(e=0,i=!1)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.bool,t)}}function al(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.box,t)}}function ol(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.color,t)}}function ll(t){return(e=0,i=NaN)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(t.precision(i)),D.float,t)}}function cl(t){return(e=0,i=0)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(t.precision(i)),D.int,t)}}function hl(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.label,t)}}function ul(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.line,t)}}function pl(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.linefill,t)}}function fl(t){return(e=0,i="")=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.string,t)}}function dl(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new R(Array(r).fill(i),D.table,t)}}class g{constructor(e,i=0){this.data=e,this.offset=i}get(e){const i=this.data.length-1-(this.offset+e);return i<0||i>=this.data.length?NaN:this.data[i]}set(e,i){const r=this.data.length-1-(this.offset+e);r>=0&&r<this.data.length&&(this.data[r]=i)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof g?e:Array.isArray(e)?new g(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof g?e.__value:new g([e])}}function ml(t){return(e,i=0)=>g.from(e).get(i)}class gl{constructor(e){this.context=e,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=rl(e),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=sl(e),this.new_bool=nl(e),this.new_box=al(e),this.new_color=ol(e),this.new_float=ll(e),this.new_int=cl(e),this.new_label=hl(e),this.new_line=ul(e),this.new_linefill=pl(e),this.new_string=fl(e),this.new_table=dl(e),this.param=ml(),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 yl(t){return e=>{e.map.clear()}}function xl(t){return(e,i)=>e.map.has(i)}function _l(t){return e=>{const i=new fn(t);return i.map=new Map(e.map),i}}function bl(t){return(e,i)=>{const r=e.map.get(i);return r===void 0?NaN:r}}function vl(t){return e=>{const i=Array.from(e.map.keys()),r=Re(i[0]);return new R(i,r,t)}}function wl(t){return(e,i,r)=>{const s=e.map.get(i);return e.map.set(i,r),s===void 0?NaN:s}}function Sl(t){return(e,i)=>{for(const[r,s]of i.map)e.map.set(r,s)}}function El(t){return(e,i)=>{const r=e.map.get(i);return e.map.delete(i)?r:NaN}}function Nl(t){return e=>e.map.size}function Cl(t){return e=>{const i=Array.from(e.map.values()),r=Re(i[0]);return new R(i,r,t)}}var Il=Object.defineProperty,kl=(t,e,i)=>e in t?Il(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Le=(t,e,i)=>kl(t,typeof e!="symbol"?e+"":e,i);class fn{constructor(e){this.context=e,Le(this,"map"),Le(this,"_clear"),Le(this,"_contains"),Le(this,"_copy"),Le(this,"_get"),Le(this,"_keys"),Le(this,"_put"),Le(this,"_put_all"),Le(this,"_remove"),Le(this,"_size"),Le(this,"_values"),this.map=new Map,this._clear=yl(this.context),this._contains=xl(this.context),this._copy=_l(this.context),this._get=bl(this.context),this._keys=vl(this.context),this._put=wl(this.context),this._put_all=Sl(this.context),this._remove=El(this.context),this._size=Nl(this.context),this._values=Cl(this.context)}toString(){return`PineMapObject(${this.map.size})`}clear(...e){return this._clear(this,...e)}contains(...e){return this._contains(this,...e)}copy(...e){return this._copy(this,...e)}get(...e){return this._get(this,...e)}keys(...e){return this._keys(this,...e)}put(...e){return this._put(this,...e)}put_all(...e){return this._put_all(this,...e)}remove(...e){return this._remove(this,...e)}size(...e){return this._size(this,...e)}values(...e){return this._values(this,...e)}}function Al(t){return()=>new fn(t)}function Tl(t){return(e,i=0)=>g.from(e).get(i)}class Pl{constructor(e){this.context=e,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=Al(e),this.param=Tl(),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 Dl(t){return(e,i,r)=>{const s=e.matrix.length;let a=[];if(r&&(r instanceof R?a=r.array:Array.isArray(r)?a=r:a=[r]),s===0){for(let l=0;l<a.length;l++){let c=a[l];c instanceof g&&(c=c.get(0)),e.matrix.push([c])}return}const n=e.matrix[0].length,o=i!==void 0?i:n;for(let l=0;l<s;l++){let c=l<a.length?a[l]:NaN;c instanceof g&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function Ml(t){return(e,i,r)=>{const s=e.matrix.length;let a=[];if(r)if(r instanceof R)a=r.array;else if(Array.isArray(r))a=r;else if(r instanceof g){const c=r.get(0);Array.isArray(c)?a=c:a=[c]}else a=[r];const n=s>0?e.matrix[0].length:a.length,o=i!==void 0?i:s,l=[];for(let c=0;c<n;c++)if(c<a.length){let h=a[c];h instanceof g&&(h=h.get(0)),l.push(h)}else l.push(NaN);e.matrix.splice(o,0,l)}}function Rl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;if(r===0)return NaN;let s=0,a=0;for(let n=0;n<i;n++)for(let o=0;o<r;o++){const l=e.matrix[n][o];isNaN(l)||(s+=l,a++)}return a===0?NaN:s/a}}function Ol(t){return(e,i)=>{const r=e.matrix.length,s=r>0?e.matrix[0].length:0;if(i<0||i>=s){t.warn(`Column index ${i} is out of bounds, matrix has ${s} columns.`,"matrix.col");const o=r>0?Re(e.matrix[0][0]):"float";return new R([],o,t)}const a=[];for(let o=0;o<r;o++)a.push(e.matrix[o][i]);const n=Re(a[0]);return new R(a,n,t)}}function Vl(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function Ll(t){return(e,i)=>{const r=e.matrix.length,s=i.matrix.length;if(r===0){for(let o=0;o<s;o++)e.matrix.push([...i.matrix[o]]);return}const a=e.matrix[0].length,n=s>0?i.matrix[0].length:0;if(a!==n&&s>0){console.error(`matrix.concat: Column count mismatch ${a} vs ${n}`);return}for(let o=0;o<s;o++)e.matrix.push([...i.matrix[o]])}}function $l(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0,s=new K(i,r,NaN,t);return s.matrix=e.matrix.map(a=>[...a]),s}}function jl(t){const e=t.length;if(e===0)return 0;if(e===1)return t[0][0];if(e===2)return t[0][0]*t[1][1]-t[0][1]*t[1][0];const i=t.map(s=>[...s]);let r=1;for(let s=0;s<e;s++){let a=s;for(;a<e&&i[a][s]===0;)a++;if(a===e)return 0;a!==s&&([i[s],i[a]]=[i[a],i[s]],r*=-1),r*=i[s][s];for(let n=s+1;n<e;n++){const o=i[n][s]/i[s][s];for(let l=s;l<e;l++)i[n][l]-=o*i[s][l]}}return r}function Bl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;return i!==r?NaN:jl(e.matrix)}}function Fl(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new K(0,0,NaN,t);const s=e.matrix[0].length,a=new K(r,s,NaN,t);if(i instanceof K)for(let n=0;n<r;n++)for(let o=0;o<s;o++){const l=e.matrix[n][o],c=i.matrix[n]&&i.matrix[n][o]!==void 0?i.matrix[n][o]:NaN;a.matrix[n][o]=l-c}else{const n=i;for(let o=0;o<r;o++)for(let l=0;l<s;l++)a.matrix[o][l]=e.matrix[o][l]-n}return a}}function Wl(t){const e=t.length;if(e!==2)return Array(e).fill(NaN);const i=t[0][0],r=t[0][1],s=t[1][0],a=t[1][1],n=i+a,o=i*a-r*s,l=n*n-4*o;if(l<0)return[NaN,NaN];const c=(n+Math.sqrt(l))/2,h=(n-Math.sqrt(l))/2;return[c,h]}function Ul(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r){const n=Re(e.matrix[0][0]);return new R([],n,t)}const s=Wl(e.matrix),a=Re(s[0]);return new R(s,a,t)}}function ql(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new K(0,0,NaN,t);const s=new K(i,r,0,t);for(let a=0;a<i;a++)s.matrix[a][a]=1;return s}}function Kl(t){return e=>{const i=e.matrix.length;return i===0?0:i*e.matrix[0].length}}function zl(t){return(e,i,r,s,a,n)=>{const o=e.matrix.length;if(o===0)return;const l=e.matrix[0].length,c=r!==void 0?r:0,h=s!==void 0?s:o,p=a!==void 0?a:0,u=n!==void 0?n:l;for(let f=c;f<h&&!(f>=o);f++)for(let m=p;m<u&&!(m>=l);m++)e.matrix[f][m]=i}}function Hl(t){return(e,i,r)=>{const s=e.matrix.length,a=s>0?e.matrix[0].length:0;if(i<0||i>=s)return t.warn(`Row index ${i} is out of bounds, matrix has ${s} rows.`,"matrix.get"),NaN;if(r<0||r>=a)return t.warn(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.get"),NaN;const n=e.matrix[i][r];return n===void 0?NaN:n}}function ai(t){const e=t.length;if(e===0)return[];const i=new Array(e);for(let s=0;s<e;s++){i[s]=new Array(2*e);for(let a=0;a<e;a++)i[s][a]=t[s][a];for(let a=0;a<e;a++)i[s][e+a]=s===a?1:0}for(let s=0;s<e;s++){let a=Math.abs(i[s][s]),n=s;for(let l=s+1;l<e;l++){const c=Math.abs(i[l][s]);c>a&&(a=c,n=l)}if(a<1e-14)return t.map(l=>l.map(()=>NaN));if(n!==s){const l=i[s];i[s]=i[n],i[n]=l}const o=i[s][s];for(let l=s;l<2*e;l++)i[s][l]/=o;for(let l=0;l<e;l++){if(l===s)continue;const c=i[l][s];if(c!==0)for(let h=s;h<2*e;h++)i[l][h]-=c*i[s][h]}}const r=new Array(e);for(let s=0;s<e;s++){r[s]=new Array(e);for(let a=0;a<e;a++)r[s][a]=i[s][e+a]}return r}function Gl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new K(i,r,NaN,t);const s=ai(e.matrix),a=new K(i,r,NaN,t);return a.matrix=s,a}}function Yl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let a=0;a<r;a++)if(s+a!==i-1&&e.matrix[s][a]!==0)return!1;return!0}}function Xl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let a=0;a<r;a++)if(e.matrix[a][s]!==-e.matrix[s][a])return!1;return!0}}function Ql(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let s=0;s<i;s++)for(let a=0;a<r;a++){const n=e.matrix[s][a];if(n!==0&&n!==1)return!1}return!0}}function Zl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let a=0;a<r;a++)if(s!==a&&e.matrix[s][a]!==0)return!1;return!0}}function Jl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let a=0;a<r;a++)if(s===a){if(e.matrix[s][a]!==1)return!1}else if(e.matrix[s][a]!==0)return!1;return!0}}function ec(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;return i===r}}function tc(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let s=0;s<i;s++){let a=0;for(let n=0;n<r;n++){const o=e.matrix[s][n];if(o<0)return!1;a+=o}if(Math.abs(a-1)>1e-10)return!1}return!0}}function ic(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let s=0;s<i;s++)for(let a=0;a<s;a++)if(e.matrix[s][a]!==e.matrix[a][s])return!1;return!0}}function rc(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;let s=!0,a=!0;for(let n=0;n<i;n++)for(let o=0;o<r;o++)n>o&&e.matrix[n][o]!==0&&(s=!1),n<o&&e.matrix[n][o]!==0&&(a=!1);return s||a}}function sc(t){return e=>{const i=e.matrix.length;if(i===0)return!0;const r=e.matrix[0].length;for(let s=0;s<i;s++)for(let a=0;a<r;a++)if(e.matrix[s][a]!==0)return!1;return!0}}function nc(t){return(e,i)=>{const r=e.matrix.length,s=r>0?e.matrix[0].length:0,a=i.matrix.length,n=a>0?i.matrix[0].length:0,o=r*a,l=s*n,c=new K(o,l,NaN,t);for(let h=0;h<r;h++)for(let p=0;p<s;p++){const u=e.matrix[h][p];for(let f=0;f<a;f++)for(let m=0;m<n;m++){const x=i.matrix[f][m];c.matrix[h*a+f][p*n+m]=u*x}}return c}}function ac(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let s=-1/0,a=!1;for(let n=0;n<i;n++)for(let o=0;o<r;o++){const l=e.matrix[n][o];isNaN(l)||(l>s&&(s=l),a=!0)}return a?s:NaN}}function oc(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,s=[];for(let n=0;n<i;n++)for(let o=0;o<r;o++){const l=e.matrix[n][o];isNaN(l)||s.push(l)}if(s.length===0)return NaN;s.sort((n,o)=>n-o);const a=Math.floor(s.length/2);return s.length%2!==0?s[a]:(s[a-1]+s[a])/2}}function lc(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let s=1/0,a=!1;for(let n=0;n<i;n++)for(let o=0;o<r;o++){const l=e.matrix[n][o];isNaN(l)||(l<s&&(s=l),a=!0)}return a?s:NaN}}function cc(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,s=new Map;let a=0,n=NaN;for(let o=0;o<i;o++)for(let l=0;l<r;l++){const c=e.matrix[o][l];if(!isNaN(c)){const h=(s.get(c)||0)+1;s.set(c,h),h>a?(a=h,n=c):h===a&&c<n&&(n=c)}}return n}}function hc(t){return(e,i)=>{const r=e.matrix.length,s=r>0?e.matrix[0].length:0;if(i instanceof K){const a=i.matrix.length,n=a>0?i.matrix[0].length:0;if(s!==a)return new K(0,0,NaN,t);const o=new K(r,n,0,t);for(let l=0;l<r;l++)for(let c=0;c<n;c++){let h=0;for(let p=0;p<s;p++)h+=e.matrix[l][p]*i.matrix[p][c];o.matrix[l][c]=h}return o}else if(i instanceof R||Array.isArray(i.array||i)){const a=i.array||i;if(s!==a.length)return new R([],"float",t);const n=[];for(let o=0;o<r;o++){let l=0;for(let c=0;c<s;c++)l+=e.matrix[o][c]*a[c];n.push(l)}return new R(n,"float",t)}else{const a=i,n=new K(r,s,NaN,t);for(let o=0;o<r;o++)for(let l=0;l<s;l++)n.matrix[o][l]=e.matrix[o][l]*a;return n}}}function uc(t){return e=>{const i=e.matrix.length;if(i===0)return new K(0,0,NaN,t);const r=e.matrix[0].length;if(i===r){const h=ai(e.matrix),p=new K(i,r,NaN,t);return p.matrix=h,p}const s=h=>{const p=h.length,u=h[0].length,f=new Array(u);for(let m=0;m<u;m++){f[m]=new Array(p);for(let x=0;x<p;x++)f[m][x]=h[x][m]}return f},a=(h,p)=>{const u=h.length,f=h[0].length,m=p[0].length,x=new Array(u);for(let _=0;_<u;_++){x[_]=new Array(m).fill(0);for(let b=0;b<f;b++){const w=h[_][b];if(w!==0)for(let v=0;v<m;v++)x[_][v]+=w*p[b][v]}}return x},n=e.matrix,o=s(n);let l;if(i>r){const h=a(o,n),p=ai(h);l=a(p,o)}else{const h=a(n,o),p=ai(h);l=a(o,p)}const c=new K(r,i,NaN,t);return c.matrix=l,c}}function pc(t){return(e,i)=>{const r=e.matrix.length,s=r>0?e.matrix[0].length:0;if(r!==s)return new K(0,0,NaN,t);let a=new K(r,s,0,t);for(let l=0;l<r;l++)a.matrix[l][l]=1;let n=new K(r,s,NaN,t);for(let l=0;l<r;l++)n.matrix[l]=[...e.matrix[l]];let o=Math.floor(i);if(o<0)return new K(r,s,NaN,t);for(;o>0;){if(o%2===1){const c=new K(r,s,0,t);for(let h=0;h<r;h++)for(let p=0;p<s;p++){let u=0;for(let f=0;f<r;f++)u+=a.matrix[h][f]*n.matrix[f][p];c.matrix[h][p]=u}a=c}const l=new K(r,s,0,t);for(let c=0;c<r;c++)for(let h=0;h<s;h++){let p=0;for(let u=0;u<r;u++)p+=n.matrix[c][u]*n.matrix[u][h];l.matrix[c][h]=p}n=l,o=Math.floor(o/2)}return a}}function fc(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,s=e.matrix.map(n=>[...n]);let a=0;for(let n=0;n<r&&a<i;n++){let o=a;for(;o<i&&Math.abs(s[o][n])<1e-10;)o++;if(o<i){[s[a],s[o]]=[s[o],s[a]];const l=s[a][n];for(let c=n;c<r;c++)s[a][c]/=l;for(let c=0;c<i;c++)if(c!==a){const h=s[c][n];for(let p=n;p<r;p++)s[c][p]-=h*s[a][p]}a++}}return a}}function dc(t){return(e,i)=>{const r=e.matrix.length;if(r===0){const n=Re(e.matrix[0][0]);return new R([],n,t)}const s=[];for(let n=0;n<r;n++){const o=e.matrix[n].splice(i,1);s.push(o[0])}const a=Re(s[0]);return new R(s,a,t)}}function mc(t){return(e,i)=>{const r=e.matrix.splice(i,1),s=Re(r[0][0]);return new R(r[0]||[],s,t)}}function gc(t){return(e,i,r)=>{const s=e.matrix.length,a=s>0?e.matrix[0].length:0,n=i*r,o=[];for(let h=0;h<s;h++)for(let p=0;p<a;p++)o.push(e.matrix[h][p]);for(;o.length<n;)o.push(NaN);o.length>n&&(o.length=n);const l=[];let c=0;for(let h=0;h<i;h++){const p=[];for(let u=0;u<r;u++)p.push(o[c++]);l.push(p)}e.matrix=l}}function yc(t){return e=>{e.matrix.reverse();for(const i of e.matrix)i.reverse()}}function xc(t){return(e,i)=>{const r=e.matrix.length;if(i<0||i>=r){t.warn(`Row index ${i} is out of bounds, matrix has ${r} rows.`,"matrix.row");const a=r>0?Re(e.matrix[0][0]):"float";return new R([],a,t)}const s=Re(e.matrix[i][0]);return new R([...e.matrix[i]],s,t)}}function _c(t){return e=>e.matrix.length}function bc(t){return(e,i,r,s)=>{const a=e.matrix.length,n=a>0?e.matrix[0].length:0;if(i<0||i>=a){t.warn(`Row index ${i} is out of bounds, matrix has ${a} rows.`,"matrix.set");return}if(r<0||r>=n){t.warn(`Column index ${r} is out of bounds, matrix has ${n} columns.`,"matrix.set");return}e.matrix[i][r]=s}}function vc(t){return(e,i=0,r="asc")=>{e.matrix.length!==0&&e.matrix.sort((s,a)=>{const n=s[i],o=a[i];return n<o?r==="asc"?-1:1:n>o?r==="asc"?1:-1:0})}}function wc(t){return(e,i,r,s,a)=>{const n=r-i,o=a-s,l=new K(n,o,NaN,t);for(let c=0;c<n;c++){const h=i+c;if(h>=e.matrix.length)break;for(let p=0;p<o;p++){const u=s+p;if(u>=e.matrix[h].length)break;l.matrix[c][p]=e.matrix[h][u]}}return l}}function Sc(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new K(0,0,NaN,t);const s=e.matrix[0].length,a=new K(r,s,NaN,t);if(i instanceof K)for(let n=0;n<r;n++)for(let o=0;o<s;o++){const l=e.matrix[n][o],c=i.matrix[n]&&i.matrix[n][o]!==void 0?i.matrix[n][o]:NaN;a.matrix[n][o]=l+c}else{const n=i;for(let o=0;o<r;o++)for(let l=0;l<s;l++)a.matrix[o][l]=e.matrix[o][l]+n}return a}}function Ec(t){return(e,i,r)=>{const s=e.matrix.length;for(let a=0;a<s;a++){const n=e.matrix[a][i];e.matrix[a][i]=e.matrix[a][r],e.matrix[a][r]=n}}}function Nc(t){return(e,i,r)=>{const s=e.matrix[i];e.matrix[i]=e.matrix[r],e.matrix[r]=s}}function Cc(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,s=Math.min(i,r);let a=0;for(let n=0;n<s;n++)a+=e.matrix[n][n];return a}}function Ic(t){return e=>{const i=e.matrix.length;if(i===0)return new K(0,0,NaN,t);const r=e.matrix[0].length,s=new K(r,i,NaN,t);for(let a=0;a<i;a++)for(let n=0;n<r;n++)s.matrix[n][a]=e.matrix[a][n];return s}}var kc=Object.defineProperty,Ac=(t,e,i)=>e in t?kc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,P=(t,e,i)=>Ac(t,typeof e!="symbol"?e+"":e,i);class K{constructor(e=0,i=0,r=NaN,s){if(this.context=s,P(this,"matrix"),P(this,"_add_col"),P(this,"_add_row"),P(this,"_avg"),P(this,"_col"),P(this,"_columns"),P(this,"_concat"),P(this,"_copy"),P(this,"_det"),P(this,"_diff"),P(this,"_eigenvalues"),P(this,"_eigenvectors"),P(this,"_elements_count"),P(this,"_fill"),P(this,"_get"),P(this,"_inv"),P(this,"_is_antidiagonal"),P(this,"_is_antisymmetric"),P(this,"_is_binary"),P(this,"_is_diagonal"),P(this,"_is_identity"),P(this,"_is_square"),P(this,"_is_stochastic"),P(this,"_is_symmetric"),P(this,"_is_triangular"),P(this,"_is_zero"),P(this,"_kron"),P(this,"_max"),P(this,"_median"),P(this,"_min"),P(this,"_mode"),P(this,"_mult"),P(this,"_pinv"),P(this,"_pow"),P(this,"_rank"),P(this,"_remove_col"),P(this,"_remove_row"),P(this,"_reshape"),P(this,"_reverse"),P(this,"_row"),P(this,"_rows"),P(this,"_set"),P(this,"_sort"),P(this,"_submatrix"),P(this,"_sum"),P(this,"_swap_columns"),P(this,"_swap_rows"),P(this,"_trace"),P(this,"_transpose"),this.matrix=[],e>0&&i>0)for(let a=0;a<e;a++)this.matrix.push(Array(i).fill(r));this._add_col=Dl(this.context),this._add_row=Ml(this.context),this._avg=Rl(this.context),this._col=Ol(this.context),this._columns=Vl(this.context),this._concat=Ll(this.context),this._copy=$l(this.context),this._det=Bl(this.context),this._diff=Fl(this.context),this._eigenvalues=Ul(this.context),this._eigenvectors=ql(this.context),this._elements_count=Kl(this.context),this._fill=zl(this.context),this._get=Hl(this.context),this._inv=Gl(this.context),this._is_antidiagonal=Yl(this.context),this._is_antisymmetric=Xl(this.context),this._is_binary=Ql(this.context),this._is_diagonal=Zl(this.context),this._is_identity=Jl(this.context),this._is_square=ec(this.context),this._is_stochastic=tc(this.context),this._is_symmetric=ic(this.context),this._is_triangular=rc(this.context),this._is_zero=sc(this.context),this._kron=nc(this.context),this._max=ac(this.context),this._median=oc(this.context),this._min=lc(this.context),this._mode=cc(this.context),this._mult=hc(this.context),this._pinv=uc(this.context),this._pow=pc(this.context),this._rank=fc(this.context),this._remove_col=dc(this.context),this._remove_row=mc(this.context),this._reshape=gc(this.context),this._reverse=yc(this.context),this._row=xc(this.context),this._rows=_c(this.context),this._set=bc(this.context),this._sort=vc(this.context),this._submatrix=wc(this.context),this._sum=Sc(this.context),this._swap_columns=Ec(this.context),this._swap_rows=Nc(this.context),this._trace=Cc(this.context),this._transpose=Ic(this.context)}toString(){let e="";for(let i=0;i<this.matrix.length;i++)e+=e===""?"":`
|
|
121
|
-
`,e+="["+this.matrix[i].join(", ")+"]";return e}add_col(...e){return this._add_col(this,...e)}add_row(...e){return this._add_row(this,...e)}avg(...e){return this._avg(this,...e)}col(...e){return this._col(this,...e)}columns(...e){return this._columns(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}det(...e){return this._det(this,...e)}diff(...e){return this._diff(this,...e)}eigenvalues(...e){return this._eigenvalues(this,...e)}eigenvectors(...e){return this._eigenvectors(this,...e)}elements_count(...e){return this._elements_count(this,...e)}fill(...e){return this._fill(this,...e)}get(...e){return this._get(this,...e)}inv(...e){return this._inv(this,...e)}is_antidiagonal(...e){return this._is_antidiagonal(this,...e)}is_antisymmetric(...e){return this._is_antisymmetric(this,...e)}is_binary(...e){return this._is_binary(this,...e)}is_diagonal(...e){return this._is_diagonal(this,...e)}is_identity(...e){return this._is_identity(this,...e)}is_square(...e){return this._is_square(this,...e)}is_stochastic(...e){return this._is_stochastic(this,...e)}is_symmetric(...e){return this._is_symmetric(this,...e)}is_triangular(...e){return this._is_triangular(this,...e)}is_zero(...e){return this._is_zero(this,...e)}kron(...e){return this._kron(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}mult(...e){return this._mult(this,...e)}pinv(...e){return this._pinv(this,...e)}pow(...e){return this._pow(this,...e)}rank(...e){return this._rank(this,...e)}remove_col(...e){return this._remove_col(this,...e)}remove_row(...e){return this._remove_row(this,...e)}reshape(...e){return this._reshape(this,...e)}reverse(...e){return this._reverse(this,...e)}row(...e){return this._row(this,...e)}rows(...e){return this._rows(this,...e)}set(...e){return this._set(this,...e)}sort(...e){return this._sort(this,...e)}submatrix(...e){return this._submatrix(this,...e)}sum(...e){return this._sum(this,...e)}swap_columns(...e){return this._swap_columns(this,...e)}swap_rows(...e){return this._swap_rows(this,...e)}trace(...e){return this._trace(this,...e)}transpose(...e){return this._transpose(this,...e)}}function $e(t){return(e,i,r)=>new K(e,i,r,t)}function Tc(t){return(e,i=0)=>g.from(e).get(i)}class Pc{constructor(e){this.context=e,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=$e(e),this.param=Tc(),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),this.new_float=$e(e),this.new_int=$e(e),this.new_string=$e(e),this.new_bool=$e(e),this.new_color=$e(e),this.new_line=$e(e),this.new_label=$e(e),this.new_box=$e(e),this.new_linefill=$e(e),this.new_table=$e(e)}}var Dc=Object.defineProperty,Mc=(t,e,i)=>e in t?Dc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Rc=(t,e,i)=>Mc(t,typeof e!="symbol"?e+"":e,i);class Oc{constructor(e){this.context=e,Rc(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){const e=this.context.idx,i=this.context.length;if(e===i-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===i-2){const r=this.context.marketData?.[i-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}}class kt{constructor(e,i){this._definition=e,this.context=i;for(let r in e)this[r]=e[r]}get __def__(){return this._definition}copy(){return new kt(this.__def__,this.context)}toString(){const e={};for(let i in this.__def__){const r=this[i];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[i]=r.toString():e[i]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(i=>`"${i}":${String(e[i])}`).join(",")+"}"}}}var Vc=Object.defineProperty,Lc=(t,e,i)=>e in t?Vc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Pi=(t,e,i)=>Lc(t,typeof e!="symbol"?e+"":e,i);class me{constructor(e,i,r){Pi(this,"time"),Pi(this,"index"),Pi(this,"price"),this.time=e,this.index=i,this.price=r}copy(){return new me(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}}function $c(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}const Mr={series:t=>t instanceof g||typeof t=="number"||typeof t=="string"||typeof t=="boolean",string:t=>typeof t=="string",color:t=>typeof t=="string"||t===null||typeof t=="number"&&isNaN(t)||t instanceof g,number:t=>typeof t=="number",boolean:t=>typeof t=="boolean",array:t=>Array.isArray(t),object:t=>typeof t=="object",point:t=>t instanceof me,primitive:t=>typeof t===null||typeof t!="object"&&typeof t!="function",function:t=>typeof t=="function",undefined:t=>t===void 0,null:t=>t===null,NaN:t=>isNaN(t),remaining_options:t=>t!==null&&typeof t=="object"&&!(t instanceof g)&&!(t instanceof me)&&!$c(t)};function Ue(t){const e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function se(t,e,i,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);const s={};let a={};const n=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){const l=t[o];if(Mr.remaining_options(l)){a=l;break}const c=e.map((h,p)=>n[p]?h[o]:void 0);for(let h=0;h<c.length;h++){const p=c[h];if(p===void 0){n[h]=!1;continue}const u=i[p];if(typeof l=="number"&&isNaN(l)&&(u==="number"||u==="series"))s[p]=l;else{const f=Mr[i[p]];typeof f=="function"&&f(l)?s[p]=l:n[h]=!1}}}return{...s,...a,...r}}var jc=Object.defineProperty,Bc=(t,e,i)=>e in t?jc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,At=(t,e,i)=>Bc(t,typeof e!="symbol"?e+"":e,i);const Fc=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Wc={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Uc=["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"],qc={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 Kc(t){return se(t,Uc,qc)}class Vt{get __value(){return NaN}param(e,i=0){return g.from(e).get(i)}any(e){const i=g.from(e).get(0);return i==null?!0:typeof i=="number"?i!==i:!1}}const Et={freq_all:"alert.freq_all",freq_once_per_bar:"alert.freq_once_per_bar",freq_once_per_bar_close:"alert.freq_once_per_bar_close"};class zc{constructor(e){this.context=e,At(this,"_firedKeys",new Set),At(this,"_fallbackCounter",0),At(this,"_fallbackLastExecTick",-1)}get freq_all(){return Et.freq_all}get freq_once_per_bar(){return Et.freq_once_per_bar}get freq_once_per_bar_close(){return Et.freq_once_per_bar_close}param(e,i,r){return g.from(e).get(0)}any(e,i,r){const s=g.from(e).get(0),a=i?g.from(i).get(0):Et.freq_once_per_bar;let n;if(r&&typeof r=="object"&&r.__callsiteId)n=r.__callsiteId;else{const h=this.context._execTick||0;h!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=h),n=`alert_${this._fallbackCounter++}`}const o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${n}:${o}`;if(a===Et.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(a===Et.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(c))return;this._firedKeys.add(c)}this.context.alerts.push({type:"alert",id:n,message:s,freq:a,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}}class Hc{constructor(e){this.context=e,At(this,"_acCounter",0),At(this,"_acLastExecTick",-1),At(this,"_acFiredKeys",new Set)}extractPlotOptions(e){const i={};for(let r in e)i[r]=g.from(e[r]).get(0);return i}indicator(...e){const i=Kc(e),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(e){const i=g.from(e).get(0);return i==null||typeof i=="number"&&isNaN(i)}nz(e,i=0){const r=g.from(e).get(0),s=g.from(i).get(0);return r==null||typeof r=="number"&&isNaN(r)?s:r}fixnan(e){const i=g.from(e);for(let r=0;r<i.length;r++){const s=i.get(r);if(!isNaN(s))return s}return NaN}alertcondition(e,i,r){const s=g.from(e).get(0),a=this.context.idx,n=this.context._execTick||0;n!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=n);const o=`alertcondition_${this._acCounter++}`;if(!s)return;const l=this.context.pine?.barstate?.isrealtime??a===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${o}:${a}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);const h=i?g.from(i).get(0):"",p=r?g.from(r).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:h,message:p,bar_index:a,time:this.context.data.openTime?.data?.[a]??0})}error(...e){console.error("error called but is currently not implemented",e)}max_bars_back(e,i){}timestamp(...e){const i=e.map(s=>s instanceof g?s.get(0):s),r=se(i,Fc,Wc);if(r.year!==void 0){const s=r.year,a=r.month,n=r.day,o=r.hour||0,l=r.minute||0,c=r.second||0,h=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(h,s,a,n,o,l,c)}if(r.dateString!==void 0){const s=r.dateString.trim();if(/[Zz]$/.test(s)||/[+-]\d{2}:?\d{2}$/.test(s))return new Date(s).getTime();const a=s.includes("T")?s+"Z":s.replace(/\s+/,"T")+"Z",n=new Date(a);if(!isNaN(n.getTime())){const o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,n.getUTCFullYear(),n.getUTCMonth()+1,n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds())}return new Date(s).getTime()}return NaN}_timestampFromComponents(e,i,r,s,a,n,o){const l=new Date(Date.UTC(i,r-1,s,a,n,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();const h=c.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(h){const p=h[1]==="+"?1:-1,u=parseInt(h[2],10),f=parseInt(h[3]||"0",10),m=p*(u*60+f)*60*1e3;return l.getTime()-m}try{return this._timestampFromIANA(e,i,r,s,a,n,o)}catch{return l.getTime()}}_timestampFromIANA(e,i,r,s,a,n,o){const l=new Date(Date.UTC(i,r-1,s,a,n,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),h=v=>parseInt(c.find(E=>E.type===v)?.value||"0",10),p=h("year"),u=h("month"),f=h("day");let m=h("hour");m===24&&(m=0);const x=h("minute"),_=h("second"),b=new Date(Date.UTC(p,u-1,f,m,x,_));p>=0&&p<100&&b.setUTCFullYear(p);const w=b.getTime()-l.getTime();return l.getTime()-w}bool(e){const i=g.from(e).get(0);return!isNaN(i)&&i!==0}int(e){const i=g.from(e).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.trunc(i)}float(e){const i=g.from(e).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(e){return g.from(e).get(0).toString()}Type(e){const i=Object.keys(e),r={};for(const s of i){let a=e[s];a instanceof g&&(a=a.data),Array.isArray(a)&&(a[0],r[s]=a[1])}return{new:function(...s){const a={};let n=null;if(s.length===1&&s[0]&&typeof s[0]=="object"&&!(s[0]instanceof g)&&!Array.isArray(s[0])&&!(s[0]instanceof kt)){const o=Object.keys(s[0]);o.length>0&&o.some(l=>i.includes(l))&&(n=s[0],s=[])}for(let o=0;o<i.length;o++){const l=i[o];n&&l in n?a[l]=n[l]:o<s.length?a[l]=s[o]:l in r&&(a[l]=g.from(r[l]).get(0))}return new kt(a,this.context)},copy:function(s){return new kt(s.__def__,this.context)}}}}function Nt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){const i=t.slice(1);return i.length===6?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),1]:i.length===8?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),parseInt(i.slice(6,8),16)/255]:null}const e=t.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function Gc(t,e,i,r){const s=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),n=Math.round(Math.max(0,Math.min(255,i))).toString(16).padStart(2,"0");if(r>=1)return`#${s}${a}${n}`.toUpperCase();const o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${s}${a}${n}${o}`.toUpperCase()}const re={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function We(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}class Yc{constructor(e){this.context=e}any(e){const i=g.from(e).get(0);return typeof i=="number"&&isNaN(i)?null:i}param(e,i=0){return g.from(e).get(i)}new(e,i){if(e=We(e),!e||typeof e!="string")return e;if(typeof i=="number"&&isNaN(i)&&(i=void 0),e.startsWith("#")){const r=e.slice(1),s=r.length===8?r.slice(0,6):r;return i!=null?`#${s}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:`#${r}`}else{const r=re[e];if(r)return i!=null?`#${r.slice(1)}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:r;const s=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);if(s){const a=s[1],n=s[2],o=s[3];if(i!=null){const l=parseInt(a).toString(16).padStart(2,"0"),c=parseInt(n).toString(16).padStart(2,"0"),h=parseInt(o).toString(16).padStart(2,"0"),p=Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${h}${p}`}return e}return i!=null?`rgba(${e}, ${(100-i)/100})`:e}}rgb(e,i,r,s){return typeof s=="number"&&isNaN(s)&&(s=void 0),s!=null?`rgba(${e}, ${i}, ${r}, ${(100-s)/100})`:`rgb(${e}, ${i}, ${r})`}from_gradient(e,i,r,s,a){if(e=We(e),i=We(i),r=We(r),s=We(s),a=We(a),e==null||typeof e=="number"&&isNaN(e)||i==null||typeof i=="number"&&isNaN(i)||r==null||typeof r=="number"&&isNaN(r)||s==null||typeof s=="number"&&isNaN(s)||a==null||typeof a=="number"&&isNaN(a))return;let n=0;r!==i&&(n=(e-i)/(r-i)),n=Math.max(0,Math.min(1,n));const o=Nt(typeof s=="string"?s:"#000000")||[0,0,0,1],l=Nt(typeof a=="string"?a:"#FFFFFF")||[255,255,255,1],c=o[0]+(l[0]-o[0])*n,h=o[1]+(l[1]-o[1])*n,p=o[2]+(l[2]-o[2])*n,u=o[3]+(l[3]-o[3])*n;return Gc(c,h,p,u)}r(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?i[0]:NaN}g(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?i[1]:NaN}b(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?i[2]:NaN}t(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?Math.round(100-i[3]*100):NaN}aqua(){return re.aqua}black(){return re.black}blue(){return re.blue}fuchsia(){return re.fuchsia}gray(){return re.gray}green(){return re.green}lime(){return re.lime}maroon(){return re.maroon}navy(){return re.navy}olive(){return re.olive}orange(){return re.orange}purple(){return re.purple}red(){return re.red}silver(){return re.silver}teal(){return re.teal}white(){return re.white}yellow(){return re.yellow}}var Xc=Object.defineProperty,Qc=(t,e,i)=>e in t?Xc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,pi=(t,e,i)=>Qc(t,typeof e!="symbol"?e+"":e,i);function zi(t){if(!t)return"";const e=t.trim().toUpperCase();return e==="1D"||e==="D"?"D":e==="1W"||e==="W"?"W":e==="1M"||e==="M"?"M":e}function Hi(t,e){const i=Zc(e);if(e==="M"){const o=new Date(t);return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),1)}if(e==="W"){const o=new Date(t),l=o.getUTCDay(),c=l===0?6:l-1;return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate()-c)}if(e==="D"||i>=1440)return Math.floor(t/864e5)*864e5;const r=i*6e4,s=Math.floor(t/864e5)*864e5,a=t-s,n=Math.floor(a/r)*r;return s+n}function Zc(t){if(t==="D")return 1440;if(t==="W")return 10080;if(t==="M")return 43200;const e=parseInt(t,10);return isNaN(e)?1440:e}function Pt(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC"){const s=new Date(t);return{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate(),hour:s.getUTCHours(),minute:s.getUTCMinutes(),second:s.getUTCSeconds(),dayOfWeek:s.getUTCDay()}}const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const s=r[1]==="+"?1:-1,a=parseInt(r[2],10),n=parseInt(r[3]||"0",10),o=s*(a*60+n)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{const s=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),a=c=>parseInt(s.find(h=>h.type===c)?.value||"0",10);let n=a("hour");n===24&&(n=0);const o=s.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:a("year"),month:a("month"),day:a("day"),hour:n,minute:a("minute"),second:a("second"),dayOfWeek:l[o]??0}}catch{const s=new Date(t);return{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate(),hour:s.getUTCHours(),minute:s.getUTCMinutes(),second:s.getUTCSeconds(),dayOfWeek:s.getUTCDay()}}}function Jc(t,e,i){const r=new Date(Date.UTC(t,e-1,i)),s=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-s);const a=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-a.getTime())/864e5+1)/7)}const eh=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],th={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"};class Rr{constructor(e,i="openTime"){pi(this,"context"),pi(this,"dataField"),this.context=e,this.dataField=i}get __value(){return this.context.data[this.dataField]}param(e,i=0){return g.from(e).get(i)}any(...e){const i=e.map(u=>u instanceof g?u.get(0):u),r=se(i,eh,th),s=r.bars_back??0,a=r.timeframe||"",n=this.context.data[this.dataField],o=g.from(n).get(s);if(isNaN(o)||o==null)return NaN;const l=this.context.timeframe||"",c=zi(a),h=zi(l);let p;if(!c||c===h?p=o:p=Hi(o,c),r.session!==void 0&&r.session!==""){const u=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(p,r.session,u)?p:NaN}return p}_isInSession(e,i,r){const s=i.match(/^(\d{2})(\d{2})-(\d{2})(\d{2})$/);if(!s)return!0;const a=parseInt(s[1],10),n=parseInt(s[2],10),o=parseInt(s[3],10),l=parseInt(s[4],10),c=Pt(e,r),h=c.hour,p=c.minute,u=h*60+p,f=a*60+n,m=o*60+l;return f<=m?u>=f&&u<m:u>=f||u<m}}const ih=[[],["time"],["time","timezone"]],rh={time:"number",timezone:"string"};class nt{constructor(e,i){pi(this,"context"),pi(this,"extractor"),this.context=e,this.extractor=i}get __value(){const e=g.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;const i=this.context.pine?.syminfo?.timezone||"UTC",r=Pt(e,i);return this.extractor(r)}param(e,i=0){return g.from(e).get(i)}any(...e){const i=e.map(o=>o instanceof g?o.get(0):o);if(i.length===0)return this.__value;const r=se(i,ih,rh),s=r.time;if(s===void 0||isNaN(s))return NaN;const a=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",n=Pt(s,a);return this.extractor(n)}}const at={dayofmonth:t=>t.day,dayofweek:t=>t.dayOfWeek===0?1:t.dayOfWeek+1,hour:t=>t.hour,minute:t=>t.minute,month:t=>t.month,second:t=>t.second,weekofyear:t=>Jc(t.year,t.month,t.day),year:t=>t.year},sh=[["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"]],nh={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function we(t){return se(t,sh,nh)}function Ne(t,e){return e.title&&t.inputs&&t.inputs[e.title]!==void 0?t.inputs[e.title]:e.defval}function ah(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function oh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function lh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function ch(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function hh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function uh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function ph(t){return(e,i=0)=>g.from(e).get(i)}function fh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function dh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function mh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function gh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function yh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function xh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function _h(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function bh(t){return(...e)=>we(e).defval}var vh=Object.defineProperty,wh=(t,e,i)=>e in t?vh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,de=(t,e,i)=>wh(t,typeof e!="symbol"?e+"":e,i);const Sh={any:ah,bool:oh,color:lh,enum:ch,float:hh,int:uh,param:ph,price:fh,session:dh,source:mh,string:gh,symbol:yh,text_area:xh,time:_h,timeframe:bh};class Eh{constructor(e){this.context=e,de(this,"any"),de(this,"bool"),de(this,"color"),de(this,"enum"),de(this,"float"),de(this,"int"),de(this,"param"),de(this,"price"),de(this,"session"),de(this,"source"),de(this,"string"),de(this,"symbol"),de(this,"text_area"),de(this,"time"),de(this,"timeframe"),Object.entries(Sh).forEach(([i,r])=>{this[i]=r(e)})}}function Nh(t){return e=>Math.abs(g.from(e).get(0))}function Ch(t){return e=>Math.acos(g.from(e).get(0))}function Ih(t){return e=>Math.asin(g.from(e).get(0))}function kh(t){return e=>Math.atan(g.from(e).get(0))}function Ah(t){return(...e)=>{const i=e.map(r=>g.from(r).get(0));return i.reduce((r,s)=>r+s,0)/i.length}}function Th(t){return e=>Math.ceil(g.from(e).get(0))}function Ph(t){return e=>Math.cos(g.from(e).get(0))}function Dh(t){return()=>Math.E}function Mh(t){return e=>Math.exp(g.from(e).get(0))}function Rh(t){return e=>Math.floor(g.from(e).get(0))}function Oh(t){return e=>Math.log(g.from(e).get(0))}function Vh(t){return e=>Math.log(g.from(e).get(0))}function Lh(t){return e=>Math.log10(g.from(e).get(0))}function $h(t){return(...e)=>{const i=e.map(r=>g.from(r).get(0));return Math.max(...i)}}function jh(t){return(...e)=>{const i=e.map(r=>g.from(r).get(0));return Math.min(...i)}}function Bh(t){return(e,i,r)=>typeof e=="string"?e:e instanceof g?i?new g(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new g(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new g(t.params[r],i||0)))}function Fh(t){return()=>1.618033988749895}function Wh(t){return()=>Math.PI}function Uh(t){return(e,i)=>Math.pow(g.from(e).get(0),g.from(i).get(0))}function qh(t){return()=>Math.random()}function Di(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function Kh(t){return(e,i)=>{const r=g.from(e).get(0);if(i==null)return Di(r);const s=g.from(i).get(0);if(s===0)return Di(r);const a=Math.pow(10,s);return Di(r*a)/a}}function zh(t){return e=>t.precision(Math.round(g.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Hh(t){return()=>.6180339887498948}function Gh(t){return e=>Math.sign(g.from(e).get(0))}function Yh(t){return e=>Math.sin(g.from(e).get(0))}function Xh(t){return e=>Math.sqrt(g.from(e).get(0))}function Qh(t){return(e,i)=>{const r=g.from(i).get(0),s=g.from(e);let a=0;for(let n=0;n<r;n++){const o=s.get(n);a+=o}return a}}function Zh(t){return e=>Math.tan(g.from(e).get(0))}function Jh(t){return e=>{const i=g.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(180/Math.PI)}}function eu(t){return e=>{const i=g.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(Math.PI/180)}}function tu(t){return(e,i)=>{const r=g.from(e).get(0),s=g.from(i).get(0);return typeof r=="number"&&typeof s=="number"?isNaN(r)||isNaN(s)?!1:Math.abs(r-s)<1e-9:r===s}}function iu(t){return(e,i)=>{const r=g.from(e).get(0),s=g.from(i).get(0);return typeof r=="number"&&typeof s=="number"?isNaN(r)||isNaN(s)?!1:Math.abs(r-s)>=1e-9:r!==s}}var ru=Object.defineProperty,su=(t,e,i)=>e in t?ru(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,W=(t,e,i)=>su(t,typeof e!="symbol"?e+"":e,i);const nu={abs:Nh,acos:Ch,asin:Ih,atan:kh,avg:Ah,ceil:Th,cos:Ph,e:Dh,exp:Mh,floor:Rh,ln:Oh,log:Vh,log10:Lh,max:$h,min:jh,param:Bh,phi:Fh,pi:Wh,pow:Uh,random:qh,round:Kh,round_to_mintick:zh,rphi:Hh,sign:Gh,sin:Yh,sqrt:Xh,sum:Qh,tan:Zh,todegrees:Jh,toradians:eu,__eq:tu,__neq:iu};class au{constructor(e){this.context=e,W(this,"_cache",{}),W(this,"abs"),W(this,"acos"),W(this,"asin"),W(this,"atan"),W(this,"avg"),W(this,"ceil"),W(this,"cos"),W(this,"e"),W(this,"exp"),W(this,"floor"),W(this,"ln"),W(this,"log"),W(this,"log10"),W(this,"max"),W(this,"min"),W(this,"param"),W(this,"phi"),W(this,"pi"),W(this,"pow"),W(this,"random"),W(this,"round"),W(this,"round_to_mintick"),W(this,"rphi"),W(this,"sign"),W(this,"sin"),W(this,"sqrt"),W(this,"sum"),W(this,"tan"),W(this,"todegrees"),W(this,"toradians"),W(this,"__eq"),W(this,"__neq"),Object.entries(nu).forEach(([i,r])=>{this[i]=r(e)})}}function ou(t){return(e,i,r)=>{t.params[r]||(t.params[r]=[]);let s;if(e instanceof g)s=e.get(i||0);else if(Array.isArray(e)){const a=e.some(o=>o instanceof g),n=e.every(o=>!(o instanceof g)&&!Array.isArray(o));(a||n)&&e.length>=1?s=e.map(o=>o instanceof g?o.get(0):o):s=g.from(e).get(i||0)}else s=e;return t.params[r].length===0?t.params[r].push(s):t.params[r][t.params[r].length-1]=s,[s,r]}}const Dt=["1","3","5","15","30","45","60","120","180","240","D","W","M"],ei={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function fi(t){if(Dt.includes(t))return t;if(ei[t])return ei[t];const e=t.toLowerCase();if(ei[e])return ei[e];const i=t.toUpperCase();return Dt.includes(i)?i:t}function Or(t,e,i,r,s=!1,a=!1){for(let n=0;n<i.length;n++)if(i[n]<=t&&t<r[n])return s||a||e>=r[n]?n:n-1;return-1}function Vr(t,e,i,r,s=!1,a,n=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=e&&i[o]>=t){const l=a&&e>a;if(n&&s)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}if(l&&s&&!n)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}return o}if(r[o]<t)break}return-1}function Gi(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof g?t.get(0):Array.isArray(t)?t.map(Gi):t}function lu(t){return async(e,i,r,s=!1,a=!1,n=!1,o=null,l=null)=>{const c=e[0]instanceof g?e[0].get(0):e[0],h=c===""?t.tickerId:c,p=typeof h=="string"&&h.includes(":")?h.split(":")[1]:h,u=i[0]instanceof g?i[0].get(0):i[0],f=u===""?t.timeframe:typeof u=="string"?u:String(u??""),m=r[0],x=r[1],_=Array.isArray(s)?s[0]:s,b=Array.isArray(a)?a[0]:a,w=_===!0||_==="gaps_on",v=b===!0||b==="lookahead_on";if(t.isSecondaryContext){const Se=Gi(m);return Array.isArray(Se)?[Se]:Se}const E=Dt.indexOf(fi(t.timeframe)),T=Dt.indexOf(fi(f));if(E==-1||T==-1)throw new Error("Invalid timeframe");if(E===T){const Se=Gi(m);return Array.isArray(Se)?[Se]:Se}const C=E>T,O=g.from(t.data.openTime).get(0),B=g.from(t.data.closeTime).get(0),z=t.idx===t.length-1&&B>Date.now(),q=`${p}_${f}_${x}`,V=`${q}_prevIdx`;if(t.cache[q]){const Se=t.cache[q];t.dataVersion>Se.dataVersion&&(await Se.pineTS.updateTail(Se.context),Se.dataVersion=t.dataVersion);const Lt=Se.context,Xt=C?Vr(O,B,Lt.data.openTime.data,Lt.data.closeTime.data,v,t.eDate,w):Or(O,B,Lt.data.openTime.data,Lt.data.closeTime.data,v,z);if(Xt==-1)return NaN;const vt=Lt.params[x][Xt];if(!C&&w){const hr=t.cache[V];return hr!==void 0&&hr===Xt?NaN:(t.cache[V]=Xt,Array.isArray(vt)?[vt]:vt)}return Array.isArray(vt)?[vt]:vt}const Q=1e3*60*60*24*30,pe=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),Ce=pe?pe-Q:void 0,Ie=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,ke=t.eDate?Math.max(t.eDate,Ie):(Ie||Date.now())+Q,ut=new dn(t.source,p,f,void 0,Ce,ke);ut.markAsSecondary();const ce=await ut.run(t.pineTSCode);t.cache[q]={pineTS:ut,context:ce,dataVersion:t.dataVersion};const Ei=C?Vr(O,B,ce.data.openTime.data,ce.data.closeTime.data,v,t.eDate,w):Or(O,B,ce.data.openTime.data,ce.data.closeTime.data,v,z);if(Ei==-1)return NaN;const Ni=ce.params[x][Ei];return!C&&w?(t.cache[V]=Ei,NaN):Array.isArray(Ni)?[Ni]:Ni}}function Ct(t){return typeof t=="number"?D.float:typeof t=="boolean"?D.bool:typeof t=="string"?D.string:D.any}function cu(t){return async(e,i,r,s=!1,a=null,n=!1,o=0)=>{const l=e[0]instanceof g?e[0].get(0):e[0],c=l===""?t.tickerId:l,h=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,p=i[0]instanceof g?i[0].get(0):i[0],u=p===""?t.timeframe:typeof p=="string"?p:String(p??""),f=r[0],m=r[1];Array.isArray(s)&&s[0];const x=Array.isArray(n)?n[0]:n;if(t.isSecondaryContext)return Array.isArray(f)?[f.map(V=>new R([V],Ct(V),t))]:new R([f],Ct(f),t);const _=Dt.indexOf(fi(t.timeframe)),b=Dt.indexOf(fi(u));if(_===-1||b===-1){if(x)return NaN;throw new Error("Invalid timeframe")}if(b>_){if(x)return NaN;throw new Error(`Timeframe ${u} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(b===_)return Array.isArray(f)?[f.map(V=>new R([V],Ct(V),t))]:new R([f],Ct(f),t);const w=`${h}_${u}_${m}_lower`;if(!t.cache[w]){const V=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),Q=V?V-2592e6:void 0,pe=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,Ce=t.eDate?Math.max(t.eDate,pe):(pe||Date.now())+2592e6,Ie=new dn(t.source,h,u,void 0,Q,Ce);Ie.markAsSecondary();const ke=await Ie.run(t.pineTSCode);t.cache[w]={pineTS:Ie,context:ke,dataVersion:t.dataVersion}}const v=t.cache[w];t.dataVersion>v.dataVersion&&(await v.pineTS.updateTail(v.context),v.dataVersion=t.dataVersion);const E=v.context,T=g.from(t.data.openTime).get(0),C=g.from(t.data.closeTime).get(0),O=E.data.openTime.data,B=E.data.closeTime.data,z=E.params[m];if(!z)return Array.isArray(f)?[f.map(()=>new R([],D.float,t))]:new R([],D.float,t);const q=[];for(let V=0;V<O.length;V++){const Q=O[V];if(!(B[V]<=T)){if(Q>=C)break;Q>=T&&Q<C&&q.push(z[V])}}if(q.length>0&&Array.isArray(q[0])){const V=q[0].length,Q=[];for(let pe=0;pe<V;pe++){const Ce=q.map(ke=>ke[pe]),Ie=Ce.length>0?Ct(Ce[0]):D.float;Q.push(new R(Ce,Ie,t))}return[Q]}else{const V=q.length>0?Ct(q[0]):D.float;return new R(q,V,t)}}}var hu=Object.defineProperty,uu=(t,e,i)=>e in t?hu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ti=(t,e,i)=>uu(t,typeof e!="symbol"?e+"":e,i);const pu={param:ou,security:lu,security_lower_tf:cu};class fu{constructor(e){this.context=e,ti(this,"_cache",{}),ti(this,"param"),ti(this,"security"),ti(this,"security_lower_tf"),Object.entries(pu).forEach(([i,r])=>{this[i]=r(e)})}}function du(t){return e=>{t.taState||(t.taState={});const i=e||"accdist";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.high,0),n=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(s)||isNaN(a)||isNaN(n)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);const l=a-n;let c=0;l!==0&&(c=(s-n-(a-s))/l*o);const h=r.prevCumulativeSum+c;return r.currentCumulativeSum=h,t.precision(h)}}function mu(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0),l=g.from(s).get(0);t.taState||(t.taState={});const c=a||`alma_${n}_${o}_${l}`;if(!t.taState[c]){const x=o*(n-1),_=n/l,b=[];let w=0;for(let v=0;v<n;v++){const E=Math.exp(-Math.pow(v-x,2)/(2*_*_));b.push(E),w+=E}for(let v=0;v<b.length;v++)b[v]/=w;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevWindow=[...h.currentWindow],h.prevCallCount=h.currentCallCount),h.lastIdx=t.idx);const p=g.from(e).get(0),u=[...h.prevWindow];for(u.unshift(p);u.length>n;)u.pop();const f=h.prevCallCount+1;if(u.length<n&&(f>=n||t.idx>=n-1)){const x=g.from(e);for(;u.length<n;)u.push(x.get(u.length))}if(h.currentWindow=u,h.currentCallCount=f,u.length<n)return NaN;let m=0;for(let x=0;x<n;x++)m+=h.weights[x]*u[n-1-x];return t.precision(m)}}function gu(t){return(e,i)=>{const r=g.from(e).get(0);t.taState||(t.taState={});const s=i||`atr_${r}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevAtr=a.currentAtr,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);const n=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(n)||isNaN(o)||isNaN(l))return NaN;const c=t.idx>0?t.get(t.data.close,1):null;let h;if(c!==null&&!isNaN(c)){const x=n-o,_=Math.abs(n-c),b=Math.abs(o-c);h=Math.max(x,_,b)}else h=n-o;let p=a.prevInitCount,u=a.prevInitSum,f=a.prevAtr;if(p<r){if(u+=h,p++,a.currentInitSum=u,a.currentInitCount=p,p===r){const x=u/r;return a.currentAtr=x,t.precision(x)}return NaN}const m=(f*(r-1)+h)/r;return a.currentAtr=m,t.precision(m)}}function yu(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});const s=t.taState[r];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevLastTrueIndex=s.currentLastTrueIndex),s.lastIdx=t.idx);const a=g.from(e).get(0);let n=s.prevLastTrueIndex;return a&&(n=t.idx),s.currentLastTrueIndex=n,n===null?NaN:t.idx-n}}function xu(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`bb_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=g.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}if(h.length<a&&t.idx>=a-1){const b=g.from(e);for(;h.length<a;){const w=b.get(h.length);if(isNaN(w))break;h.push(w),p+=w}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return[[NaN,NaN,NaN]];const u=p/a;let f=0;for(let b=0;b<a;b++)f+=Math.pow(h[b]-u,2);const m=Math.sqrt(f/a),x=u+n*m,_=u-n*m;return[[t.precision(u),t.precision(x),t.precision(_)]]}}function _u(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`bbw_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=g.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const w=h.pop();p-=w}if(h.length<a&&t.idx>=a-1){const w=g.from(e);for(;h.length<a;){const v=w.get(h.length);if(isNaN(v))break;h.push(v),p+=v}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return NaN;const u=p/a;let f=0;for(let w=0;w<a;w++){const v=h[w]-u;f+=v*v}const m=f/a,x=Math.sqrt(m),_=n*x;if(u===0)return t.precision(0);const b=2*_/u*100;return t.precision(b)}}function bu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`cci_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevSum=n.currentSum,n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0);if(isNaN(o))return NaN;const l=[...n.prevWindow];let c=n.prevSum;for(l.unshift(o),c+=o;l.length>s;){const x=l.pop();c-=x}const h=n.prevCallCount+1;if(l.length<s&&(h>=s||t.idx>=s-1)){const x=g.from(e);for(;l.length<s;){const _=x.get(l.length);if(isNaN(_))break;l.push(_),c+=_}}if(n.currentWindow=l,n.currentSum=c,n.currentCallCount=h,l.length<s)return NaN;const p=c/s;let u=0;for(let x=0;x<s;x++)u+=Math.abs(l[x]-p);const f=u/s;if(f===0)return 0;const m=(o-p)/(.015*f);return t.precision(m)}}function vu(t){return(e,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`change_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s+1;)l.pop();const c=n.prevCallCount+1;if(l.length<s+1&&(c>=s+1||t.idx>=s)){const p=g.from(e);for(;l.length<s+1;)l.push(p.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<=s)return NaN;const h=o-l[s];return t.precision(h)}}function wu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`cmo_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevGainsWindow=[...n.currentGainsWindow],n.prevLossesWindow=[...n.currentLossesWindow],n.prevGainsSum=n.currentGainsSum,n.prevLossesSum=n.currentLossesSum),n.lastIdx=t.idx);const o=g.from(e).get(0),l=g.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;const c=o-l,h=c>=0?c:0,p=c>=0?0:-c,u=[...n.prevGainsWindow],f=[...n.prevLossesWindow];let m=n.prevGainsSum,x=n.prevLossesSum;if(u.unshift(h),f.unshift(p),m+=h,x+=p,u.length<s)return n.currentGainsWindow=u,n.currentLossesWindow=f,n.currentGainsSum=m,n.currentLossesSum=x,NaN;if(u.length>s){const w=u.pop(),v=f.pop();m-=w,x-=v}n.currentGainsWindow=u,n.currentLossesWindow=f,n.currentGainsSum=m,n.currentLossesSum=x;const _=m+x;if(_===0)return t.precision(0);const b=100*(m-x)/_;return t.precision(b)}}function Su(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);let n=0,o=!1;for(let h=0;h<s;h++){const p=a.get(h);if(isNaN(p)){o=!0;break}n+=p}if(o)return NaN;let l=0;for(let h=0;h<s;h++){const p=a.get(h);l+=p*(h+1)}if(n===0)return NaN;const c=-l/n;return t.precision(c)}}function Eu(t){return(e,i,r,s)=>{const a=g.from(r).get(0),n=g.from(e),o=g.from(i);if(t.idx<a-1)return NaN;let l=0,c=0,h=0,p=0,u=0,f=0;for(let w=0;w<a;w++){const v=n.get(w),E=o.get(w);isNaN(v)||isNaN(E)||(l+=v,c+=E,h+=v*E,p+=v*v,u+=E*E,f++)}if(f<2)return NaN;const m=f*h-l*c,x=f*p-l*l,_=f*u-c*c;if(x<=0||_<=0)return t.precision(0);const b=m/Math.sqrt(x*_);return t.precision(b)}}function Nu(t){return(e,i,r)=>{const s=g.from(e),a=g.from(i),n=s.get(0),o=a.get(0),l=s.get(1),c=a.get(1);if(isNaN(n)||isNaN(o)||isNaN(l)||isNaN(c))return!1;const h=n>o&&l<=c,p=n<o&&l>=c;return h||p}}function Cu(t){return(e,i)=>{const r=g.from(e),s=g.from(i),a=r.get(0),n=s.get(0),o=r.get(1),l=s.get(1);return o<=l&&a>n}}function Iu(t){return(e,i)=>{const r=g.from(e),s=g.from(i),a=r.get(0),n=s.get(0),o=r.get(1),l=s.get(1);return o>=l&&a<n}}function ku(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const s=t.taState[r];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevCumulativeSum=s.currentCumulativeSum),s.lastIdx=t.idx);const a=g.from(e).get(0);if(isNaN(a))return s.currentCumulativeSum=s.prevCumulativeSum,t.precision(s.prevCumulativeSum);const n=s.prevCumulativeSum+a;return s.currentCumulativeSum=n,t.precision(n)}}function Au(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`dev_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevSum=n.currentSum,n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0)||0,l=[...n.prevWindow];let c=n.prevSum;for(l.unshift(o),c+=o;l.length>s;){const m=l.pop();c-=m}const h=n.prevCallCount+1;if(l.length<s&&(h>=s||t.idx>=s-1)){const m=g.from(e);for(;l.length<s;){const x=m.get(l.length);l.push(x),c+=x}}if(n.currentWindow=l,n.currentSum=c,n.currentCallCount=h,l.length<s)return NaN;const p=c/s;let u=0;for(let m=0;m<s;m++)u+=Math.abs(l[m]-p);const f=u/s;return t.precision(f)}}function Tu(t){return(e,i,r)=>{const s=g.from(e).get(0),a=g.from(i).get(0);t.taState||(t.taState={});const n=r||`dmi_${s}_${a}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});const o=t.taState[n];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN,NaN]];const p=t.idx>0?t.get(t.data.high,1):NaN,u=t.idx>0?t.get(t.data.low,1):NaN,f=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];const m=Math.max(l-c,Math.abs(l-f),Math.abs(c-f)),x=l-p,_=u-c,b=x>_&&x>0?x:0,w=_>x&&_>0?_:0;let v=o.prevInitCount,E=o.prevTrInitSum,T=o.prevPlusInitSum,C=o.prevMinusInitSum,O=o.prevSmoothedTR,B=o.prevSmoothedPlus,z=o.prevSmoothedMinus;if(v++,v<=s)E+=m,T+=b,C+=w,v===s&&(O=E/s,B=T/s,z=C/s);else{const ce=1/s;O=ce*m+(1-ce)*O,B=ce*b+(1-ce)*B,z=ce*w+(1-ce)*z}if(o.currentInitCount=v,o.currentTrInitSum=E,o.currentPlusInitSum=T,o.currentMinusInitSum=C,o.currentSmoothedTR=O,o.currentSmoothedPlus=B,o.currentSmoothedMinus=z,v<s)return[[NaN,NaN,NaN]];const q=O===0?0:100*B/O,V=O===0?0:100*z/O,Q=q+V,pe=Q===0?0:100*Math.abs(q-V)/Q;let Ce=o.prevAdxInitCount,Ie=o.prevDxInitSum,ke=o.prevADX,ut=NaN;if(Ce++,Ce<=a)Ie+=pe,Ce===a&&(ke=Ie/a,ut=ke);else{const ce=1/a;ke=ce*pe+(1-ce)*ke,ut=ke}return o.currentAdxInitCount=Ce,o.currentDxInitSum=Ie,o.currentADX=ke,[[t.precision(q),t.precision(V),t.precision(ut)]]}}function Pu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`ema_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevEma=n.currentEma,n.prevInitSum=n.currentInitSum,n.prevInitCount=n.currentInitCount),n.lastIdx=t.idx);const o=g.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=n.prevInitCount,c=n.prevInitSum,h=n.prevEma;if(l<s){if(c+=o,l++,n.currentInitSum=c,n.currentInitCount=l,l===s){const f=c/s;return n.currentEma=f,t.precision(f)}return NaN}const p=2/(s+1),u=o*p+h*(1-p);return n.currentEma=u,t.precision(u)}}function Du(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);for(let n=0;n<s;n++){const o=a.get(n),l=a.get(n+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Mu(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.high);const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`highest_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const u=g.from(e);for(;l.length<s;)l.push(u.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.max(...h);return t.precision(p)}}function Ru(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s-1)return NaN;let n=-1/0,o=NaN;for(let l=0;l<s;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c>n)&&(n=c,o=-l)}return o}}function Ou(t){return(e,i,r)=>{const s=g.from(i).get(0),a=Math.floor(s/2),n=Math.floor(Math.sqrt(s)),o=t.pine.ta.wma,l=o(e,a,r?`${r}_wma1`:void 0),c=o(e,s,r?`${r}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});const h=r||`hma_raw_${s}`;t.taState[h]||(t.taState[h]={lastIdx:-1,prevValues:[],currentValues:[]});const p=t.taState[h];t.idx>p.lastIdx&&(p.lastIdx>=0&&(p.prevValues=[...p.currentValues]),p.lastIdx=t.idx);const u=2*l-c,f=[...p.prevValues];f.unshift(u),f.length>n+1&&f.pop(),p.currentValues=f;const m=r?`${r}_hma_final`:`hma_final_${s}`;t.taState[m]||(t.taState[m]={lastIdx:-1,prevWindow:[],currentWindow:[]});const x=t.taState[m];t.idx>x.lastIdx&&(x.lastIdx>=0&&(x.prevWindow=[...x.currentWindow]),x.lastIdx=t.idx);const _=[...x.prevWindow];if(_.unshift(u),_.length<n)return x.currentWindow=_,NaN;for(;_.length>n;)_.pop();x.currentWindow=_;let b=0,w=0;for(let E=0;E<n;E++){const T=n-E;b+=_[E]*T,w+=T}const v=b/w;return t.precision(v)}}function Vu(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(a))return NaN;const n=(r-s)*a;if(n===0)return t.precision(0);const o=(2*i-r-s)/n;return t.precision(o)}}function Lu(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0);let l=!0;typeof s=="string"?a=s:s!==void 0&&(l=g.from(s).get(0));let c;const h=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){const E=t.get(t.data.close,1);isNaN(E)?c=NaN:c=Math.max(h-p,Math.abs(h-E),Math.abs(p-E))}else c=h-p;const u=g.from(e).get(0);t.taState||(t.taState={});const f=a||`kc_${n}_${o}_${l}`;t.taState[f]||(t.taState[f]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const m=t.taState[f];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.basisState={...m.currentBasisState},m.rangeState={...m.currentRangeState}),m.lastIdx=t.idx);const x=(E,T,C,O)=>{if(isNaN(C))return Object.assign(T,E),T.prevEma!==null?T.prevEma:NaN;let B=E.initCount,z=E.initSum,q=E.prevEma;if(B<O){if(z+=C,B++,T.initSum=z,T.initCount=B,T.prevEma=q,B===O){const pe=z/O;return T.prevEma=pe,pe}return NaN}const V=2/(O+1),Q=C*V+q*(1-V);return T.prevEma=Q,T.initSum=z,T.initCount=B,Q},_=x(m.basisState,m.currentBasisState,u,n),b=x(m.rangeState,m.currentRangeState,c,n);if(isNaN(_)||isNaN(b))return[[NaN,NaN,NaN]];const w=_+b*o,v=_-b*o;return[[t.precision(_),t.precision(w),t.precision(v)]]}}function $u(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0);let l=!0;typeof s=="string"?a=s:s!==void 0&&(l=g.from(s).get(0)),t.taState||(t.taState={});const c=a||`kcw_${n}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.basisState={...h.currentBasisState},h.rangeState={...h.currentRangeState}),h.lastIdx=t.idx);const p=(v,E,T,C)=>{if(isNaN(T))return Object.assign(E,v),E.prevEma!==null?E.prevEma:NaN;let O=v.initCount,B=v.initSum,z=v.prevEma;if(O<C){if(B+=T,O++,E.initSum=B,E.initCount=O,E.prevEma=z,O===C){const Q=B/C;return E.prevEma=Q,Q}return NaN}const q=2/(C+1),V=T*q+z*(1-q);return E.prevEma=V,E.initSum=B,E.initCount=O,V};let u;const f=t.get(t.data.high,0),m=t.get(t.data.low,0);if(l){const v=t.get(t.data.close,1);isNaN(v)?u=NaN:u=Math.max(f-m,Math.abs(f-v),Math.abs(m-v))}else u=f-m;const x=g.from(e).get(0),_=p(h.basisState,h.currentBasisState,x,n),b=p(h.rangeState,h.currentRangeState,u,n);if(isNaN(_)||isNaN(b))return NaN;if(_===0)return t.precision(0);const w=2*b*o/_;return t.precision(w)}}function ju(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`linreg_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=g.from(e).get(0),h=[...l.prevWindow];for(h.unshift(c);h.length>a;)h.pop();const p=l.prevCallCount+1;if(h.length<a&&(p>=a||t.idx>=a-1)){const E=g.from(e);for(;h.length<a;)h.push(E.get(h.length))}if(l.currentWindow=h,l.currentCallCount=p,h.length<a)return NaN;let u=0,f=0,m=0,x=0;const _=a;for(let E=0;E<a;E++){const T=a-1-E,C=h[E];u+=T,f+=C,m+=T*C,x+=T*T}const b=_*x-u*u;if(b===0)return NaN;const w=(_*m-u*f)/b,v=(f-w*u)/_+w*(a-1-n);return t.precision(v)}}function Bu(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.low);const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`lowest_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const u=g.from(e);for(;l.length<s;)l.push(u.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.min(...h);return t.precision(p)}}function Fu(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s-1)return NaN;let n=1/0,o=NaN;for(let l=0;l<s;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c<n)&&(n=c,o=-l)}return o}}function Wu(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0),l=g.from(s).get(0),c=a||`macd_${n}_${o}_${l}`,h=`${c}_fast`,p=`${c}_slow`,u=`${c}_signal`,f=t.pine.ta.ema(e,n,h),m=t.pine.ta.ema(e,o,p);let x=NaN;!isNaN(f)&&!isNaN(m)&&(x=f-m);let _=NaN;isNaN(x)||(_=t.pine.ta.ema(x,l,u));let b=NaN;return!isNaN(x)&&!isNaN(_)&&(b=x-_),[[t.precision(x),t.precision(_),t.precision(b)]]}}function Uu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`median_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const f=g.from(e);for(;l.length<s;)l.push(f.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;const h=l.slice().sort((f,m)=>f-m),p=Math.floor(s/2),u=s%2===0?(h[p-1]+h[p])/2:h[p];return t.precision(u)}}function qu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`mfi_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevUpperWindow=[...n.currentUpperWindow],n.prevLowerWindow=[...n.currentLowerWindow],n.prevUpperSum=n.currentUpperSum,n.prevLowerSum=n.currentLowerSum),n.lastIdx=t.idx);const o=g.from(e).get(0),l=g.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;const h=isNaN(l)?NaN:o-l,p=c*(h<=0?0:o),u=c*(h>=0?0:o),f=[...n.prevUpperWindow],m=[...n.prevLowerWindow];let x=n.prevUpperSum,_=n.prevLowerSum;if(f.unshift(p),m.unshift(u),x+=p,_+=u,f.length<s)return n.currentUpperWindow=f,n.currentLowerWindow=m,n.currentUpperSum=x,n.currentLowerSum=_,NaN;if(f.length>s){const w=f.pop(),v=m.pop();x-=w,_-=v}if(n.currentUpperWindow=f,n.currentLowerWindow=m,n.currentUpperSum=x,n.currentLowerSum=_,_===0)return t.precision(100);if(x===0)return t.precision(0);const b=100-100/(1+x/_);return t.precision(b)}}function Ku(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s-1)return NaN;const n=new Map;for(let c=0;c<s;c++){const h=a.get(c);isNaN(h)||n.set(h,(n.get(h)||0)+1)}if(n.size===0)return NaN;let o=NaN,l=-1;for(const[c,h]of n.entries())h>l?(l=h,o=c):h===l&&c<o&&(o=c);return o}}function zu(t){return(e,i,r)=>{const s=g.from(i).get(0);return t.pine.ta.change(e,s,r)}}function Hu(t){return e=>{t.taState||(t.taState={});const i=e||"nvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedNVI:1,tentativeNVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.close,1),n=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(s)?0:s,c=isNaN(a)?0:a,h=isNaN(n)?0:n,p=isNaN(o)?0:o;let u=r.committedNVI;if(!(l===0||c===0)&&h<p){const f=(l-c)/c;u=u+f*u}return r.tentativeNVI=u,t.precision(u)}}function Gu(t){return()=>{t.taState||(t.taState={});const e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});const i=t.taState[e];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.committedOBV=i.tentativeOBV),i.lastIdx=t.idx);const r=t.get(t.data.close,0),s=t.get(t.data.volume,0),a=t.get(t.data.close,1);if(isNaN(a))return i.tentativeOBV=0,t.precision(0);let n=i.committedOBV;return r>a?n+=s:r<a&&(n-=s),i.tentativeOBV=n,t.precision(n)}}function Yu(t){return(e,i,r)=>e instanceof g?i?new g(e.data,e.offset+i):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new g(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new g(t.params[r],i||0)))}function Xu(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e);if(t.idx<a-1)return NaN;const l=[];for(let m=0;m<a;m++){const x=o.get(m);if(isNaN(x))return NaN;l.push(x)}l.sort((m,x)=>m-x);let c=n/100*a-.5;c<0&&(c=0),c>a-1&&(c=a-1);const h=Math.floor(c),p=Math.ceil(c);if(h===p)return t.precision(l[h]);const u=c-h,f=l[h]+u*(l[p]-l[h]);return t.precision(f)}}function Qu(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e);if(t.idx<a-1)return NaN;const l=[];for(let h=0;h<a;h++){const p=o.get(h);isNaN(p)||l.push(p)}if(l.length===0)return NaN;l.sort((h,p)=>h-p);let c=Math.ceil(n/100*l.length)-1;return c<0&&(c=0),c>=l.length&&(c=l.length-1),t.precision(l[c])}}function Zu(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s)return NaN;const n=a.get(0);if(isNaN(n))return NaN;let o=0,l=0;for(let c=1;c<=s;c++){const h=a.get(c);isNaN(h)||(l++,h<=n&&o++)}return l===0?NaN:t.precision(o/l*100)}}function Ju(t,e,i){const r=new Array(t.length).fill(NaN);for(let s=e+i;s<t.length;s++){const a=t[s-i];let n=!0;for(let o=1;o<=e;o++)if(t[s-i-o]>=a){n=!1;break}if(n){for(let o=1;o<=i;o++)if(t[s-i+o]>=a){n=!1;break}}n&&(r[s]=a)}return r}function ep(t){return(e,i,r,s)=>{typeof r=="string"&&(r=i,i=e,e=t.data.high);const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e).toArray(),l=Ju(o,a,n),c=t.idx;return t.precision(l[c])}}function tp(t,e,i){const r=new Array(t.length).fill(NaN);for(let s=e+i;s<t.length;s++){const a=t[s-i];let n=!0;for(let o=1;o<=e;o++)if(t[s-i-o]<=a){n=!1;break}if(n){for(let o=1;o<=i;o++)if(t[s-i+o]<=a){n=!1;break}}n&&(r[s]=a)}return r}function ip(t){return(e,i,r,s)=>{typeof r=="string"&&(r=i,i=e,e=t.data.low);const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e).toArray(),l=tp(o,a,n),c=t.idx;return t.precision(l[c])}}function rp(t){return e=>{t.taState||(t.taState={});const i=e||"pvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedPVI:1,tentativePVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.close,1),n=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(s)?0:s,c=isNaN(a)?0:a,h=isNaN(n)?0:n,p=isNaN(o)?0:o;let u=r.committedPVI;if(!(l===0||c===0)&&h>p){const f=(l-c)/c;u=u+f*u}return r.tentativePVI=u,t.precision(u)}}function sp(t){return e=>{t.taState||(t.taState={});const i=e||"pvt";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.close,1),n=t.get(t.data.volume,0);let o=r.prevCumulativeSum;if(!isNaN(s)&&!isNaN(a)&&!isNaN(n)&&a!==0){const l=(s-a)/a*n;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function np(t){return(e,i,r)=>{const s=t.pine.ta.highest(e,i,(r||"range")+"_h"),a=t.pine.ta.lowest(e,i,(r||"range")+"_l");return isNaN(s)||isNaN(a)?NaN:t.precision(s-a)}}function ap(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);for(let n=0;n<s;n++){const o=a.get(n),l=a.get(n+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function op(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`rma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevRma=n.currentRma,n.prevInitSum=n.currentInitSum,n.prevInitCount=n.currentInitCount),n.lastIdx=t.idx);const o=g.from(e).get(0)||0;let l=n.prevInitCount,c=n.prevInitSum,h=n.prevRma;if(l<s){if(c+=o,l++,n.currentInitSum=c,n.currentInitCount=l,l===s){const f=c/s;return n.currentRma=f,t.precision(f)}return NaN}const p=1/s,u=o*p+h*(1-p);return n.currentRma=u,t.precision(u)}}function lp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`roc_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s+1;)l.pop();const c=n.prevCallCount+1;if(l.length<s+1&&(c>=s+1||t.idx>=s)){const u=g.from(e);for(;l.length<s+1;)l.push(u.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<=s)return NaN;const h=l[s],p=(o-h)/h*100;return t.precision(p)}}function cp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`rsi_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevPrevValue=n.currentPrevValue,n.prevAvgGain=n.currentAvgGain,n.prevAvgLoss=n.currentAvgLoss,n.prevInitGains=[...n.currentInitGains],n.prevInitLosses=[...n.currentInitLosses]),n.lastIdx=t.idx);const o=g.from(e).get(0);if(o==null||isNaN(o))return NaN;const l=n.prevPrevValue;if(l===null||isNaN(l))return n.currentPrevValue=o,n.currentInitGains=[...n.prevInitGains],n.currentInitLosses=[...n.prevInitLosses],n.currentAvgGain=n.prevAvgGain,n.currentAvgLoss=n.prevAvgLoss,NaN;let c=n.prevAvgGain,h=n.prevAvgLoss;const p=[...n.prevInitGains],u=[...n.prevInitLosses],f=o-l,m=f>0?f:0,x=f<0?-f:0;if(p.length<s){if(p.push(m),u.push(x),n.currentInitGains=p,n.currentInitLosses=u,n.currentPrevValue=o,p.length===s){c=p.reduce((w,v)=>w+v,0)/s,h=u.reduce((w,v)=>w+v,0)/s,n.currentAvgGain=c,n.currentAvgLoss=h;const b=h===0?100:100-100/(1+c/h);return t.precision(b)}return NaN}c=(c*(s-1)+m)/s,h=(h*(s-1)+x)/s,n.currentAvgGain=c,n.currentAvgLoss=h,n.currentPrevValue=o;const _=h===0?100:100-100/(1+c/h);return t.precision(_)}}function hp(t){return(e,i,r,s)=>{const a=g.from(e).get(0),n=g.from(i).get(0),o=g.from(r).get(0);t.taState||(t.taState={});const l=s||`sar_${a}_${n}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});const c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let h=c.prevResult,p=c.prevMaxMin,u=c.prevAcceleration,f=c.prevIsBelow,m=c.prevBarIndex;const x=t.get(t.data.high,0),_=t.get(t.data.low,0),b=t.get(t.data.close,0),w=t.get(t.data.close,1),v=t.get(t.data.high,1),E=t.get(t.data.low,1),T=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(x)||isNaN(_)||isNaN(b))return c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,NaN;let O=!1;return m===1&&(b>w?(f=!0,p=x,h=E):(f=!1,p=_,h=v),O=!0,u=a),m>=1&&(h=h+u*(p-h),f?h>_&&(O=!0,f=!1,h=Math.max(x,p),p=_,u=a):h<x&&(O=!0,f=!0,h=Math.min(_,p),p=x,u=a),O||(f?x>p&&(p=x,u=Math.min(u+n,o)):_<p&&(p=_,u=Math.min(u+n,o))),f?(h=Math.min(h,E),m>1&&(h=Math.min(h,C))):(h=Math.max(h,v),m>1&&(h=Math.max(h,T)))),m++,c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,m<=1?NaN:t.precision(h)}}function up(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`sma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevSum=n.currentSum,n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;let h=!1;if(l.length<s&&(c>=s||t.idx>=s-1)){const x=g.from(e);for(;l.length<s;)l.push(x.get(l.length));h=!0}let p;const u=o==null||Number.isNaN(o);let f=!Number.isNaN(n.prevSum)&&!u&&!h;if(f){let x=n.prevSum+o;if(n.prevWindow.length>=s){const _=n.prevWindow[n.prevWindow.length-1];_==null||Number.isNaN(_)?f=!1:x-=_}f&&(p=x)}if(!f){p=0;let x=!1;for(const _ of l){if(_==null||Number.isNaN(_)){x=!0;break}p+=_}x&&(p=NaN)}if(n.currentWindow=l,n.currentSum=p,n.currentCallCount=c,l.length<s)return NaN;const m=p/s;return t.precision(m)}}function pp(t){return(e,i,r=!0,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`stdev_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum,l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=g.from(e).get(0);if(c==null||isNaN(c))return NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}const u=l.prevCallCount+1;if(h.length<a&&(u>=a||t.idx>=a-1)){const b=g.from(e);for(;h.length<a;){const w=b.get(h.length);if(w==null||isNaN(w))break;h.push(w),p+=w}}if(l.currentWindow=h,l.currentSum=p,l.currentCallCount=u,h.length<a)return NaN;const f=p/a;let m=0;for(let b=0;b<a;b++)m+=Math.pow(h[b]-f,2);const x=n?a:a-1,_=Math.sqrt(m/x);return t.precision(_)}}function fp(t){return(e,i,r,s,a)=>{const n=g.from(s).get(0);t.taState||(t.taState={});const o=a||`stoch_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);const c=g.from(e).get(0),h=g.from(i).get(0),p=g.from(r).get(0);if(isNaN(c)||isNaN(h)||isNaN(p))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;const u=[...l.prevHighWindow],f=[...l.prevLowWindow];if(u.unshift(h),f.unshift(p),u.length>n&&(u.pop(),f.pop()),l.currentHighWindow=u,l.currentLowWindow=f,u.length<n)return NaN;let m=u[0],x=f[0];for(let w=1;w<n;w++)u[w]>m&&(m=u[w]),f[w]<x&&(x=f[w]);const _=m-x;if(_===0)return NaN;const b=100*(c-x)/_;return t.precision(b)}}function dp(t){return(e,i,r)=>{const s=g.from(e).get(0),a=g.from(i).get(0);t.taState||(t.taState={});const n=r||`supertrend_${s}_${a}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});const o=t.taState[n];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrSum=o.currentTrSum,o.prevAtrValue=o.currentAtrValue,o.prevAtrCount=o.currentAtrCount,o.prevLowerBand=o.currentLowerBand,o.prevUpperBand=o.currentUpperBand,o.prevSuperTrend=o.currentSuperTrend,o.prevDirection=o.currentDirection),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN]];const p=(l+c)/2,u=t.idx>0?t.get(t.data.close,1):NaN;let f;isNaN(u)?f=l-c:f=Math.max(l-c,Math.abs(l-u),Math.abs(c-u));let m=o.prevAtrCount,x=o.prevTrSum,_=o.prevAtrValue;m++,m<=a?(x+=f,m===a&&(_=x/a)):_=(_*(a-1)+f)/a;const b=_;if(o.currentAtrCount=m,o.currentTrSum=x,o.currentAtrValue=_,isNaN(b))return[[NaN,NaN]];let w=p+s*b,v=p-s*b;const E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,T=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||v>E||u<E||(v=E),isNaN(o.prevUpperBand)||w<T||u>T||(w=T);let C,O;const B=o.prevSuperTrend;return m===a?C=1:B===o.prevUpperBand?C=h>w?-1:1:C=h<v?1:-1,O=C===-1?v:w,o.currentLowerBand=v,o.currentUpperBand=w,o.currentSuperTrend=O,o.currentDirection=C,[[t.precision(O),C]]}}function mp(t){return(e,i)=>{const r=[1,2,2,1],s=6;t.taState||(t.taState={});const a=i||"swma";t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],currentWindow:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow]),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){const h=g.from(e);for(;l.length<4;)l.push(h.get(l.length))}if(n.currentWindow=l,l.length<4)return NaN;let c=0;for(let h=0;h<4;h++)c+=r[h]*l[3-h];return c/=s,t.precision(c)}}function gp(t){return(e,i)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=g.from(e).get(0));const s=t.get(t.data.high,0),a=t.get(t.data.low,0),n=t.get(t.data.close,1);if(isNaN(n))return r?t.precision(s-a):NaN;const o=Math.max(s-a,Math.abs(s-n),Math.abs(a-n));return t.precision(o)}}function yp(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`tsi_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);const c=g.from(e).get(0);if(isNaN(c))return NaN;const h=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(h))return NaN;const p=Math.abs(h),u=2/(n+1),f=2/(a+1),m=2/(n+1),x=2/(a+1);let _=l.prevEma1PcCount,b=l.prevEma1PcSum,w=l.prevEma1PcValue;_++,_<=n?(b+=h,_===n&&(w=b/n)):w=h*u+w*(1-u);let v=l.prevEma1AbsCount,E=l.prevEma1AbsSum,T=l.prevEma1AbsValue;if(v++,v<=n?(E+=p,v===n&&(T=E/n)):T=p*m+T*(1-m),isNaN(w)||isNaN(T))return l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=T,NaN;let C=l.prevEma2PcCount,O=l.prevEma2PcSum,B=l.prevEma2PcValue;C++,C<=a?(O+=w,C===a&&(B=O/a)):B=w*f+B*(1-f);let z=l.prevEma2AbsCount,q=l.prevEma2AbsSum,V=l.prevEma2AbsValue;if(z++,z<=a?(q+=T,z===a&&(V=q/a)):V=T*x+V*(1-x),l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=T,l.currentEma2PcCount=C,l.currentEma2PcSum=O,l.currentEma2PcValue=B,l.currentEma2AbsCount=z,l.currentEma2AbsSum=q,l.currentEma2AbsValue=V,isNaN(B)||isNaN(V))return NaN;if(V===0)return t.precision(0);const Q=B/V;return t.precision(Q)}}function xp(t){return(e,i,r,s)=>{t.taState||(t.taState={});const a=s||"valuewhen";t.taState[a]||(t.taState[a]={lastIdx:-1,prevValues:[],currentValues:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevValues=[...n.currentValues]),n.lastIdx=t.idx);const o=g.from(e).get(0),l=g.from(i).get(0),c=g.from(r).get(0),h=[...n.prevValues];if(o&&h.push(l),n.currentValues=h,isNaN(c)||c<0)return NaN;const p=h.length-1-c;if(p<0)return NaN;const u=h[p];return typeof u=="number"?t.precision(u):u}}function _p(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`variance_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const m=g.from(e);for(;l.length<s;)l.push(m.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;let h=0,p=0;for(let m=0;m<s;m++)h+=l[m],p+=l[m]*l[m];const u=h/s,f=p/s-u*u;return t.precision(f)}}function bp(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"vwap";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});const s=t.taState[r];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevCumulativePV=s.currentCumulativePV,s.prevCumulativeVolume=s.currentCumulativeVolume,s.prevLastSessionDate=s.currentLastSessionDate),s.lastIdx=t.idx);const a=g.from(e).get(0),n=g.from(t.data.volume).get(0),o=g.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=Pt(o,l),h=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`;let p=s.prevCumulativePV,u=s.prevCumulativeVolume,f=s.prevLastSessionDate;if(f!==h&&(p=0,u=0,f=h),p+=a*n,u+=n,s.currentCumulativePV=p,s.currentCumulativeVolume=u,s.currentLastSessionDate=f,u===0)return NaN;const m=p/u;return t.precision(m)}}function vp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`vwma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevVolumeWindow=[...n.currentVolumeWindow]),n.lastIdx=t.idx);const o=g.from(e).get(0),l=t.get(t.data.volume,0),c=[...n.prevWindow],h=[...n.prevVolumeWindow];for(c.unshift(o),h.unshift(l);c.length>s;)c.pop(),h.pop();if(c.length<s&&t.idx>=s-1){const m=g.from(e),x=g.from(t.data.volume);for(;c.length<s;)c.push(m.get(c.length)),h.push(x.get(h.length))}if(n.currentWindow=c,n.currentVolumeWindow=h,c.length<s)return NaN;let p=0,u=0;for(let m=0;m<s;m++)p+=c[m]*h[m],u+=h[m];const f=p/u;return t.precision(f)}}function wp(t){return e=>{t.taState||(t.taState={});const i=e||"wad";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.high,0),n=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(s)||isNaN(a)||isNaN(n))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){const h=Math.max(a,o),p=Math.min(n,o),u=s-o;u>0?l=s-p:u<0&&(l=s-h)}const c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function Sp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`wma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const f=g.from(e);for(;l.length<s;)l.push(f.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;let h=0,p=0;for(let f=0;f<s;f++){const m=s-f;h+=l[f]*m,p+=m}const u=h/p;return t.precision(u)}}function Ep(t){return(e,i)=>{const r=g.from(e).get(0);t.taState||(t.taState={});const s=i||`wpr_${r}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevHighWindow=[...a.currentHighWindow],a.prevLowWindow=[...a.currentLowWindow]),a.lastIdx=t.idx);const n=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(n)||isNaN(o)||isNaN(l))return a.currentHighWindow=[...a.prevHighWindow],a.currentLowWindow=[...a.prevLowWindow],NaN;const c=[...a.prevHighWindow],h=[...a.prevLowWindow];if(c.unshift(n),h.unshift(o),c.length>r&&(c.pop(),h.pop()),a.currentHighWindow=c,a.currentLowWindow=h,c.length<r)return NaN;let p=c[0],u=h[0];for(let x=1;x<r;x++)c[x]>p&&(p=c[x]),h[x]<u&&(u=h[x]);const f=p-u;if(f===0)return t.precision(0);const m=(p-l)/f*-100;return t.precision(m)}}function Np(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.open,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),n=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(a)||isNaN(n))return NaN;const o=s-a;if(o===0)return t.precision(0);const l=(i-r)/o*n;return t.precision(l)}}var Cp=Object.defineProperty,Ip=(t,e,i)=>e in t?Cp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,I=(t,e,i)=>Ip(t,typeof e!="symbol"?e+"":e,i);const kp={accdist:du,alma:mu,atr:gu,barssince:yu,bb:xu,bbw:_u,cci:bu,change:vu,cmo:wu,cog:Su,correlation:Eu,cross:Nu,crossover:Cu,crossunder:Iu,cum:ku,dev:Au,dmi:Tu,ema:Pu,falling:Du,highest:Mu,highestbars:Ru,hma:Ou,iii:Vu,kc:Lu,kcw:$u,linreg:ju,lowest:Bu,lowestbars:Fu,macd:Wu,median:Uu,mfi:qu,mode:Ku,mom:zu,nvi:Hu,obv:Gu,param:Yu,percentile_linear_interpolation:Xu,percentile_nearest_rank:Qu,percentrank:Zu,pivothigh:ep,pivotlow:ip,pvi:rp,pvt:sp,range:np,rising:ap,rma:op,roc:lp,rsi:cp,sar:hp,sma:up,stdev:pp,stoch:fp,supertrend:dp,swma:mp,tr:gp,tsi:yp,valuewhen:xp,variance:_p,vwap:bp,vwma:vp,wad:wp,wma:Sp,wpr:Ep,wvad:Np};class Ap{constructor(e){this.context=e,I(this,"accdist"),I(this,"alma"),I(this,"atr"),I(this,"barssince"),I(this,"bb"),I(this,"bbw"),I(this,"cci"),I(this,"change"),I(this,"cmo"),I(this,"cog"),I(this,"correlation"),I(this,"cross"),I(this,"crossover"),I(this,"crossunder"),I(this,"cum"),I(this,"dev"),I(this,"dmi"),I(this,"ema"),I(this,"falling"),I(this,"highest"),I(this,"highestbars"),I(this,"hma"),I(this,"iii"),I(this,"kc"),I(this,"kcw"),I(this,"linreg"),I(this,"lowest"),I(this,"lowestbars"),I(this,"macd"),I(this,"median"),I(this,"mfi"),I(this,"mode"),I(this,"mom"),I(this,"nvi"),I(this,"obv"),I(this,"param"),I(this,"percentile_linear_interpolation"),I(this,"percentile_nearest_rank"),I(this,"percentrank"),I(this,"pivothigh"),I(this,"pivotlow"),I(this,"pvi"),I(this,"pvt"),I(this,"range"),I(this,"rising"),I(this,"rma"),I(this,"roc"),I(this,"rsi"),I(this,"sar"),I(this,"sma"),I(this,"stdev"),I(this,"stoch"),I(this,"supertrend"),I(this,"swma"),I(this,"tr"),I(this,"tsi"),I(this,"valuewhen"),I(this,"variance"),I(this,"vwap"),I(this,"vwma"),I(this,"wad"),I(this,"wma"),I(this,"wpr"),I(this,"wvad"),Object.entries(kp).forEach(([i,r])=>{this[i]=r(e)})}}function Tp(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC")return 0;const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const n=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return n*(o*60+l)}const s=Pt(t,e),a=new Date(Date.UTC(s.year,s.month-1,s.day,s.hour,s.minute,s.second));return Math.round((a.getTime()-t)/6e4)}function Pp(t,e){const i=e>=0?"+":"-",r=a=>String(Math.floor(Math.abs(a))).padStart(2,"0"),s=i+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${s}]`}class Dp{constructor(e){this.context=e}logFormat(e,...i){return e.replace(/{(\d+)}/g,(r,s)=>i[s])}param(e,i=0,r){return g.from(e).get(i)}_formatTimestamp(){const e=this.context.data.openTime.data[this.context.idx],i=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=Tp(e,i);return Pp(e,r)}warning(e,...i){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}error(e,...i){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}info(e,...i){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}}class Mp{constructor(e){this.context=e}param(e,i=0,r){return g.from(e).get(i)}tostring(e,i){if(typeof e!="number"||isNaN(e)||!i)return String(e);if(i==="mintick"){const s=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(s)));return e.toFixed(a)}if(i==="integer")return String(Math.round(e));if(i==="percent")return(e*100).toFixed(2)+"%";if(i==="price"){const s=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(s)));return e.toFixed(a)}if(i==="volume")return String(Math.round(e));const r=i.indexOf(".");if(r>=0){const s=i.substring(r+1).length;return e.toFixed(s)}return i.includes("#")||i.includes("0")?String(Math.round(e)):String(e)}tonumber(e){return Number(e)}lower(e){return String(e).toLowerCase()}upper(e){return String(e).toUpperCase()}trim(e){return String(e).trim()}repeat(e,i,r=""){return Array(i).fill(e).join(r||"")}replace_all(e,i,r){return String(e).replaceAll(i,r)}replace(e,i,r,s=0){const a=String(e),n=String(i),o=String(r),l=Math.floor(Number(s))||0;if(n==="")return a;let c=0,h=0;for(;;){const p=a.indexOf(n,c);if(p===-1)return a;if(h===l)return a.substring(0,p)+o+a.substring(p+n.length);h++,c=p+n.length}}contains(e,i){return String(e).includes(i)}endswith(e,i){return String(e).endsWith(i)}startswith(e,i){return String(e).startsWith(i)}pos(e,i){const r=String(e).indexOf(i);return r===-1?NaN:r}length(e){return String(e).length}match(e,i){return String(e).match(new RegExp(i))}split(e,i){return new R(String(e).split(i),D.string,this.context)}substring(e,i,r){return String(e).substring(i,r)}format(e,...i){return e.replace(/\{(\d+)(?:,number,([^}]+))?\}/g,(r,s,a)=>{const n=i[s];return a&&typeof n=="number"&&!isNaN(n)?this.tostring(n,a):String(n)})}}var Rp=Object.defineProperty,Op=(t,e,i)=>e in t?Rp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Vp=(t,e,i)=>Op(t,typeof e!="symbol"?e+"":e,i);const ii={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function Lr(t){if(!t||/^\d+$/.test(t))return t;if(ii[t])return ii[t];const e=t.toLowerCase();if(ii[e])return ii[e];if(t.length===1){const r=t.toUpperCase();if(["D","W","M","S"].includes(r))return r}const i=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(i)){const r=parseInt(t);if(!isNaN(r))return r+i}return t}class Lp{constructor(e){this.context=e,Vp(this,"_normalized",null)}param(e,i=0,r){return g.from(e).get(i)}get normalized(){return this._normalized===null&&(this._normalized=Lr(this.context.timeframe)),this._normalized}get unit(){return this.normalized.slice(-1).toUpperCase()}get main_period(){return this.normalized}get period(){return this.normalized}get multiplier(){const e=parseInt(this.normalized);return isNaN(e)?1:e}get isdwm(){return["D","W","M"].includes(this.unit)}get isdaily(){return this.unit==="D"}get isweekly(){return this.unit==="W"}get ismonthly(){return this.unit==="M"}get isseconds(){return this.unit==="S"}get isminutes(){return/^\d+$/.test(this.normalized)}get isintraday(){return!this.isdwm}change(e){const i=typeof e=="function"?e():e,r=i instanceof g?i.get(0):i,s=zi(r||"");if(!s)return!1;const a=g.from(this.context.data.openTime).get(0),n=g.from(this.context.data.openTime).get(1);if(isNaN(a)||isNaN(n))return!1;const o=Hi(a,s),l=Hi(n,s);return o!==l}from_seconds(e){return e<60?Math.ceil(e/5)*5+"S":e<3600*24?Math.ceil(e/60):e<=3600*24*7*52?e%(3600*24*7)===0?Math.ceil(e/604800)+"W":Math.ceil(e/(3600*24))+"D":"12M"}in_seconds(e){e==null?e=this.normalized:e=Lr(e);const i=e.slice(-1).toUpperCase(),r=parseInt(e);return i==="S"?isNaN(r)?1:r:i==="D"?(isNaN(r)?1:r)*60*60*24:i==="W"?(isNaN(r)?1:r)*60*60*24*7:i==="M"?(isNaN(r)?1:r)*60*60*24*30:isNaN(r)?0:r*60}}const $p=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],jp=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Bp={series:"series",title:"string",char:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Fp=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Wp=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],Up=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],qp=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],$r=["color","offset","editable","show_last","title","display","force_overlay"],Kp=["price","title","color","linestyle","linewidth","editable","display"],zp=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],Hp={series:"series",title:"string",color:"color",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"},Gp={series:"series",title:"string",style:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Yp={series:"series",title:"string",colorup:"color",colordown:"color",offset:"number",minheight:"number",maxheight:"number",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Xp={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Qp={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",wickcolor:"color",bordercolor:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},jr={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},Zp={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},Jp={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"};class ef{constructor(e){this.context=e}_resolvePlotKey(e,i){if(e){const r=this.context.plots[e];return!r||!i||r._callsiteId===i?e:e+i}return i||"plot"}extractPlotOptions(e){const i={};for(let r in e)i[r]=g.from(e[r]).get(0);return i}get linestyle_dashed(){return"linestyle_dashed"}get linestyle_dotted(){return"linestyle_dotted"}get linestyle_solid(){return"linestyle_solid"}get style_area(){return"style_area"}get style_areabr(){return"style_areabr"}get style_circles(){return"style_circles"}get style_columns(){return"style_columns"}get style_cross(){return"style_cross"}get style_histogram(){return"style_histogram"}get style_line(){return"style_line"}get style_linebr(){return"style_linebr"}get style_stepline(){return"style_stepline"}get style_stepline_diamond(){return"style_stepline_diamond"}get style_steplinebr(){return"style_steplinebr"}param(e,i=0,r){return g.from(e).get(i)}plotchar(...e){const i=Ue(e),r=se(e,jp,Bp),{series:s,title:a,...n}=r,o=this.extractPlotOptions(n),l=this._resolvePlotKey(a,i);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:a,_plotKey:l,_callsiteId:i});const c=g.from(s).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){const i=Ue(e),r=se(e,$p,Hp),{series:s,title:a,...n}=r,o=this.extractPlotOptions(n),l=this._resolvePlotKey(a,i),c="color"in n;if(!this.context.plots[l]){const f=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:f},title:a,_plotKey:l,_callsiteId:i}}const h=g.from(s).get(0);let p=o.color;typeof p=="function"&&(p=p());const u={color:c?typeof p=="string"?p:void 0:p||"#2962ff"};return"offset"in n&&(u.offset=o.offset),this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:h,options:u}),this.context.plots[l]}plotshape(...e){const i=Ue(e),r=se(e,Fp,Gp),{series:s,title:a,...n}=r,o=this.extractPlotOptions(n),l=this._resolvePlotKey(a,i);if(!this.context.plots[l]){const h=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:h},title:a,_plotKey:l,_callsiteId:i}}const c=g.from(s).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){const i=Ue(e),r=se(e,Wp,Yp),{series:s,title:a,...n}=r,o=g.from(s).get(0),l=this.extractPlotOptions(n),c=this._resolvePlotKey(a,i);if(!this.context.plots[c]){const h=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:h},title:a,_plotKey:c,_callsiteId:i}}return this.context.plots[c].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){const i=Ue(e),r=se(e,Up,Xp),{open:s,high:a,low:n,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"bar",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[g.from(s).get(0),g.from(a).get(0),g.from(n).get(0),g.from(o).get(0)];this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color}})}plotcandle(...e){const i=Ue(e),r=se(e,qp,Qp),{open:s,high:a,low:n,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"candle",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[g.from(s).get(0),g.from(a).get(0),g.from(n).get(0),g.from(o).get(0)];return this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color,wickcolor:h.wickcolor,bordercolor:h.bordercolor}}),this.context.plots[p]}bgcolor(...e){const i=Ue(e),r=se(e,$r,jr),{title:s,...a}=r,n=this.extractPlotOptions(a),o=this._resolvePlotKey(s,i);if(!this.context.plots[o]){const l=n.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...n,style:"background",overlay:l},title:s,_plotKey:o,_callsiteId:i}}this.context.plots[o].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:n.color&&n.color!=="na"&&n?.color.toString()!=="NaN",options:{color:n.color}})}barcolor(...e){const i=Ue(e),r=se(e,$r,jr),{title:s,...a}=r,n=this.extractPlotOptions(a),o=this._resolvePlotKey(s,i);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...n,style:"barcolor"},title:s,_plotKey:o,_callsiteId:i}),this.context.plots[o].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:n.color&&n.color!=="na"&&n?.color.toString()!=="NaN",options:{color:n.color}}),this.context.plots[o]}}class tf{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,i=0,r){return g.from(e).get(i)}any(...e){const i=Ue(e),r=se(e,Kp,Zp),{price:s,title:a,color:n,linestyle:o,linewidth:l,editable:c,display:h}=r,p=[s,{title:a,color:n,linestyle:o,linewidth:l,editable:c,display:h,style:"hline"}];return i&&p.push({__callsiteId:i}),this.context.pine.plot.any(...p)}}class rf{constructor(e){this.context=e}param(e,i=0,r){return g.from(e).get(i)}any(...e){const i=Ue(e),r=e.length>=6&&typeof e[2]=="number",s=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||s!==null){const a=e[0],n=e[1],o=s?g.from(s.top_value).get(0):e[2],l=s?g.from(s.bottom_value).get(0):e[3],c=s?g.from(s.top_color).get(0):e[4],h=s?g.from(s.bottom_color).get(0):e[5],p=s?s.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,u=a?._plotKey||a?.title,f=n?._plotKey||n?.title;let m=p||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i),this.context.plots[m]||(this.context.plots[m]={title:p||"Fill",plot1:u,plot2:f,data:[],options:{plot1:u,plot2:f,style:"fill",gradient:!0},_plotKey:m,_callsiteId:i}),this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:h}})}else{const a=se(e,zp,Jp),{plot1:n,plot2:o,color:l,title:c,editable:h,show_last:p,fillgaps:u,display:f}=a;let m=c||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i);const _=g.from(l).get(0);if(!this.context.plots[m]){const b=n?._plotKey||n?.title,w=o?._plotKey||o?.title;this.context.plots[m]={title:c||"Fill",plot1:b,plot2:w,data:[],options:{plot1:b,plot2:w,color:_,editable:h,show_last:p,fillgaps:u,display:f,style:"fill"},_plotKey:m,_callsiteId:i}}this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:_}})}}}var sf=Object.defineProperty,nf=(t,e,i)=>e in t?sf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,af=(t,e,i)=>nf(t,typeof e!="symbol"?e+"":e,i);class of{constructor(e){this.context=e,af(this,"point");const i=this.context;this.point={new(r,s,a){return new me(r,s,a??NaN)},from_index(r,s){return new me(void 0,r,s)},from_time(r,s){return new me(r,void 0,s)},copy(r){return r.copy()},now(r){const s=i.idx,a=i.marketData[s]?.openTime;return new me(a,s,r)}}}param(e,i=0,r){return g.from(e).get(i)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){return!0}is_heikinashi(){return!1}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}}var lf=Object.defineProperty,cf=(t,e,i)=>e in t?lf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,oe=(t,e,i)=>cf(t,typeof e!="symbol"?e+"":e,i);let hf=0;class or{constructor(e,i,r="",s="bi",a="pr",n="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){oe(this,"id"),oe(this,"x"),oe(this,"y"),oe(this,"text"),oe(this,"xloc"),oe(this,"yloc"),oe(this,"color"),oe(this,"style"),oe(this,"textcolor"),oe(this,"size"),oe(this,"textalign"),oe(this,"tooltip"),oe(this,"text_font_family"),oe(this,"force_overlay"),oe(this,"_deleted"),oe(this,"_helper"),oe(this,"_createdAtBar",-1),this.id=hf++,this.x=e,this.y=i,this.text=r,this.xloc=s,this.yloc=a,this.color=n,this.style=o,this.textcolor=l,this.size=c,this.textalign=h,this.tooltip=p,this.text_font_family=u,this.force_overlay=f,this._deleted=!1,this._helper=null}set_x(e){this._helper?this._helper.set_x(this,e):this._deleted||(this.x=e)}set_y(e){this._helper?this._helper.set_y(this,e):this._deleted||(this.y=e)}set_xy(e,i){this._helper?this._helper.set_xy(this,e,i):this._deleted||(this.x=e,this.y=i)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_textcolor(e){this._helper?this._helper.set_textcolor(this,e):this._deleted||(this.textcolor=e)}set_size(e){this._helper?this._helper.set_size(this,e):this._deleted||(this.size=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_textalign(e){this._helper?this._helper.set_textalign(this,e):this._deleted||(this.textalign=e)}set_tooltip(e){this._helper?this._helper.set_tooltip(this,e):this._deleted||(this.tooltip=e)}set_xloc(e){this._helper?this._helper.set_xloc(this,e):this._deleted||(this.xloc=e)}set_yloc(e){this._helper?this._helper.set_yloc(this,e):this._deleted||(this.yloc=e)}set_point(e){this._helper&&this._helper.set_point(this,e)}set_text_font_family(e){this._deleted||(this.text_font_family=e)}get_x(){return this.x}get_y(){return this.y}get_text(){return this.text}delete(){this._deleted=!0}copy(){return new or(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay)}toPlotData(){return{id:this.id,x:this.x,y:this.y,text:this.text,xloc:this.xloc,yloc:this.yloc,color:this.color,style:this.style,textcolor:this.textcolor,size:this.size,textalign:this.textalign,tooltip:this.tooltip,text_font_family:this.text_font_family,force_overlay:this.force_overlay,_deleted:this._deleted}}}var uf=Object.defineProperty,pf=(t,e,i)=>e in t?uf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ff=(t,e,i)=>pf(t,typeof e!="symbol"?e+"":e,i);const df=[["x","y","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"],["point","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"]],mf={x:"number",y:"number",text:"string",xloc:"string",yloc:"string",color:"color",style:"string",textcolor:"color",size:"string",textalign:"string",tooltip:"string",text_font_family:"string",force_overlay:"boolean",point:"point"};class gf{constructor(e){this.context=e,ff(this,"_labels",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._labels.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],s.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:s,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof Vt)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){const i=e.get(0);return typeof i=="number"&&isNaN(i)?null:i}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,i,r="",s="bi",a="pr",n="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){const m=new or(e,i,this._resolve(r),this._resolve(s),this._resolve(a),this._resolve(n),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(h),this._resolve(p),this._resolve(u),f);return m._helper=this,m._createdAtBar=this.context.idx,this._labels.push(m),this._enforceMaxCount(),this.syncToPlot(),m}_enforceMaxCount(){const e=this.context.indicator?.max_labels_count??50,i=this._labels.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._labels){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}new(...e){const i=se(e,df,mf);let r,s,a=i.xloc;if(i.point instanceof me){const n=i.point;n.index!==void 0?(r=n.index,a=a||"bi"):n.time!==void 0?(r=n.time,a=a||"bt"):(r=0,a=a||"bi"),s=n.price}else r=i.x,s=i.y;return this._createLabel(r,s,i.text,a,i.yloc,i.color,i.style,i.textcolor,i.size,i.textalign,i.tooltip,i.text_font_family,i.force_overlay)}any(...e){return this.new(...e)}set_x(e,i){e&&!e._deleted&&(e.x=i)}set_y(e,i){e&&!e._deleted&&(e.y=i)}set_xy(e,i,r){e&&!e._deleted&&(e.x=i,e.y=r)}set_text(e,i){e&&!e._deleted&&(e.text=i)}set_color(e,i){e&&!e._deleted&&(e.color=i)}set_textcolor(e,i){e&&!e._deleted&&(e.textcolor=i)}set_size(e,i){e&&!e._deleted&&(e.size=i)}set_style(e,i){e&&!e._deleted&&(e.style=i)}set_textalign(e,i){e&&!e._deleted&&(e.textalign=i)}set_tooltip(e,i){e&&!e._deleted&&(e.tooltip=i)}set_xloc(e,i){e&&!e._deleted&&(e.xloc=i)}set_yloc(e,i){e&&!e._deleted&&(e.yloc=i)}set_point(e,i){e&&!e._deleted&&i&&(i.index!==void 0?(e.x=i.index,e.xloc="bi"):i.time!==void 0&&(e.x=i.time,e.xloc="bt"),e.y=i.price)}get_x(e){return e?e.x:NaN}get_y(e){return e?e.y:NaN}get_text(e){return e?e.text:""}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._labels.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_label_down(){return"style_label_down"}get style_label_up(){return"style_label_up"}get style_label_left(){return"style_label_left"}get style_label_right(){return"style_label_right"}get style_label_lower_left(){return"style_label_lower_left"}get style_label_lower_right(){return"style_label_lower_right"}get style_label_upper_left(){return"style_label_upper_left"}get style_label_upper_right(){return"style_label_upper_right"}get style_label_center(){return"style_label_center"}get style_circle(){return"style_circle"}get style_square(){return"style_square"}get style_diamond(){return"style_diamond"}get style_flag(){return"style_flag"}get style_arrowup(){return"style_arrowup"}get style_arrowdown(){return"style_arrowdown"}get style_cross(){return"style_cross"}get style_xcross(){return"style_xcross"}get style_triangleup(){return"style_triangleup"}get style_triangledown(){return"style_triangledown"}get style_none(){return"style_none"}get style_text_outline(){return"style_text_outline"}}var yf=Object.defineProperty,xf=(t,e,i)=>e in t?yf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,xe=(t,e,i)=>xf(t,typeof e!="symbol"?e+"":e,i);let _f=0;class lr{constructor(e,i,r,s,a="bi",n="none",o="",l="style_solid",c=1,h=!1){xe(this,"id"),xe(this,"x1"),xe(this,"y1"),xe(this,"x2"),xe(this,"y2"),xe(this,"xloc"),xe(this,"extend"),xe(this,"color"),xe(this,"style"),xe(this,"width"),xe(this,"force_overlay"),xe(this,"_deleted"),xe(this,"_helper"),xe(this,"_createdAtBar",-1),this.id=_f++,this.x1=e,this.y1=i,this.x2=r,this.y2=s,this.xloc=a,this.extend=n,this.color=o,this.style=l,this.width=c,this.force_overlay=h,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,i){this._helper?this._helper.set_xy1(this,e,i):this._deleted||(this.x1=e,this.y1=i)}set_xy2(e,i){this._helper?this._helper.set_xy2(this,e,i):this._deleted||(this.x2=e,this.y2=i)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_width(e){this._helper?this._helper.set_width(this,e):this._deleted||(this.width=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.x1=e,this.x2=i,this.xloc=r)}set_first_point(e){this._helper&&this._helper.set_first_point(this,e)}set_second_point(e){this._helper&&this._helper.set_second_point(this,e)}get_x1(){return this.x1}get_y1(){return this.y1}get_x2(){return this.x2}get_y2(){return this.y2}get_price(e){return this._helper?this._helper.get_price(this,e):NaN}delete(){this._deleted=!0}copy(){return new lr(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}}var bf=Object.defineProperty,vf=(t,e,i)=>e in t?bf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,wf=(t,e,i)=>vf(t,typeof e!="symbol"?e+"":e,i);const Sf=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],Ef={x1:"number",y1:"number",x2:"number",y2:"number",xloc:"string",extend:"string",color:"color",style:"string",width:"number",force_overlay:"boolean",first_point:"point",second_point:"point"};class Nf{constructor(e){this.context=e,wf(this,"_lines",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._lines.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],s.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:s,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_createLine(e,i,r,s,a="bi",n="none",o="",l="style_solid",c=1,h=!1){const p=new lr(e,i,r,s,a,this._resolve(n),this._resolve(o),this._resolve(l),this._resolve(c)||1,h);return p._helper=this,p._createdAtBar=this.context.idx,this._lines.push(p),this._enforceMaxCount(),this.syncToPlot(),p}_enforceMaxCount(){const e=this.context.indicator?.max_lines_count??50,i=this._lines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._lines){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}new(...e){const i=se(e,Sf,Ef);let r,s,a,n,o=i.xloc;if(i.first_point instanceof me){const l=i.first_point,c=i.second_point,h=this._resolvePoint(l);r=h.x,s=l.price,o=o||h.xloc,c instanceof me?(a=this._resolvePoint(c).x,n=c.price):(a=0,n=NaN)}else r=i.x1,s=i.y1,a=i.x2,n=i.y2;return this._createLine(r,s,a,n,o,i.extend,i.color,i.style,i.width,i.force_overlay)}any(...e){return this.new(...e)}set_x1(e,i){e&&!e._deleted&&(e.x1=this._resolve(i))}set_y1(e,i){e&&!e._deleted&&(e.y1=this._resolve(i))}set_x2(e,i){e&&!e._deleted&&(e.x2=this._resolve(i))}set_y2(e,i){e&&!e._deleted&&(e.y2=this._resolve(i))}set_xy1(e,i,r){e&&!e._deleted&&(e.x1=this._resolve(i),e.y1=this._resolve(r))}set_xy2(e,i,r){e&&!e._deleted&&(e.x2=this._resolve(i),e.y2=this._resolve(r))}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i))}set_width(e,i){e&&!e._deleted&&(e.width=this._resolve(i)||1)}set_style(e,i){e&&!e._deleted&&(e.style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_xloc(e,i,r,s){e&&!e._deleted&&(e.x1=i,e.x2=r,e.xloc=s)}set_first_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x1=r.x,e.y1=i.price,e.xloc=r.xloc}}set_second_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x2=r.x,e.y2=i.price,e.xloc=r.xloc}}get_x1(e){return e?e.x1:NaN}get_y1(e){return e?e.y1:NaN}get_x2(e){return e?e.x2:NaN}get_y2(e){return e?e.y2:NaN}get_price(e,i){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;const r=e.x2-e.x1;return r===0?e.y1:e.y1+(i-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._lines.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_solid(){return"style_solid"}get style_dotted(){return"style_dotted"}get style_dashed(){return"style_dashed"}get style_arrow_left(){return"style_arrow_left"}get style_arrow_right(){return"style_arrow_right"}get style_arrow_both(){return"style_arrow_both"}}var Cf=Object.defineProperty,If=(t,e,i)=>e in t?Cf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,X=(t,e,i)=>If(t,typeof e!="symbol"?e+"":e,i);let kf=0;class cr{constructor(e,i,r,s,a="bi",n="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",w="format_none",v=!1){X(this,"id"),X(this,"left"),X(this,"top"),X(this,"right"),X(this,"bottom"),X(this,"xloc"),X(this,"extend"),X(this,"border_color"),X(this,"border_style"),X(this,"border_width"),X(this,"bgcolor"),X(this,"text"),X(this,"text_color"),X(this,"text_size"),X(this,"text_halign"),X(this,"text_valign"),X(this,"text_wrap"),X(this,"text_font_family"),X(this,"text_formatting"),X(this,"force_overlay"),X(this,"_deleted"),X(this,"_helper"),X(this,"_createdAtBar",-1),this.id=kf++,this.left=e,this.top=i,this.right=r,this.bottom=s,this.xloc=a,this.extend=n,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=h,this.text=p,this.text_color=u,this.text_size=f,this.text_halign=m,this.text_valign=x,this.text_wrap=_,this.text_font_family=b,this.text_formatting=w,this.force_overlay=v,this._deleted=!1,this._helper=null}set_left(e){this._helper?this._helper.set_left(this,e):this._deleted||(this.left=e)}set_right(e){this._helper?this._helper.set_right(this,e):this._deleted||(this.right=e)}set_top(e){this._helper?this._helper.set_top(this,e):this._deleted||(this.top=e)}set_bottom(e){this._helper?this._helper.set_bottom(this,e):this._deleted||(this.bottom=e)}set_lefttop(e,i){this._helper?this._helper.set_lefttop(this,e,i):this._deleted||(this.left=e,this.top=i)}set_rightbottom(e,i){this._helper?this._helper.set_rightbottom(this,e,i):this._deleted||(this.right=e,this.bottom=i)}set_top_left_point(e){this._helper&&this._helper.set_top_left_point(this,e)}set_bottom_right_point(e){this._helper&&this._helper.set_bottom_right_point(this,e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.left=e,this.right=i,this.xloc=r)}set_bgcolor(e){this._helper?this._helper.set_bgcolor(this,e):this._deleted||(this.bgcolor=e)}set_border_color(e){this._helper?this._helper.set_border_color(this,e):this._deleted||(this.border_color=e)}set_border_width(e){this._helper?this._helper.set_border_width(this,e):this._deleted||(this.border_width=e)}set_border_style(e){this._helper?this._helper.set_border_style(this,e):this._deleted||(this.border_style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_text_color(e){this._helper?this._helper.set_text_color(this,e):this._deleted||(this.text_color=e)}set_text_size(e){this._helper?this._helper.set_text_size(this,e):this._deleted||(this.text_size=e)}set_text_halign(e){this._helper?this._helper.set_text_halign(this,e):this._deleted||(this.text_halign=e)}set_text_valign(e){this._helper?this._helper.set_text_valign(this,e):this._deleted||(this.text_valign=e)}set_text_wrap(e){this._helper?this._helper.set_text_wrap(this,e):this._deleted||(this.text_wrap=e)}set_text_font_family(e){this._helper?this._helper.set_text_font_family(this,e):this._deleted||(this.text_font_family=e)}set_text_formatting(e){this._helper?this._helper.set_text_formatting(this,e):this._deleted||(this.text_formatting=e)}get_left(){return this.left}get_right(){return this.right}get_top(){return this.top}get_bottom(){return this.bottom}delete(){this._deleted=!0}toPlotData(){return{id:this.id,left:this.left,top:this.top,right:this.right,bottom:this.bottom,xloc:this.xloc,extend:this.extend,border_color:this.border_color,border_style:this.border_style,border_width:this.border_width,bgcolor:this.bgcolor,text:this.text,text_color:this.text_color,text_size:this.text_size,text_halign:this.text_halign,text_valign:this.text_valign,text_wrap:this.text_wrap,text_font_family:this.text_font_family,text_formatting:this.text_formatting,force_overlay:this.force_overlay,_deleted:this._deleted}}copy(){return new cr(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}}var Af=Object.defineProperty,Tf=(t,e,i)=>e in t?Af(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Pf=(t,e,i)=>Tf(t,typeof e!="symbol"?e+"":e,i);const Df=[["left","top","right","bottom","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"],["top_left","bottom_right","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"]],Mf={left:"number",top:"number",right:"number",bottom:"number",top_left:"point",bottom_right:"point",border_color:"color",border_width:"number",border_style:"string",extend:"string",xloc:"string",bgcolor:"color",text:"string",text_size:"string",text_color:"color",text_halign:"string",text_valign:"string",text_wrap:"string",text_font_family:"string",force_overlay:"boolean"};class Rf{constructor(e){this.context=e,Pf(this,"_boxes",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._boxes.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],s.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:s,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_createBox(e,i,r,s,a="bi",n="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",w="format_none",v=!1){const E=new cr(e,i,r,s,a,this._resolve(n),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(h,"#2962ff"),this._resolve(p)||"",this._resolveColor(u,"#000000"),this._resolve(f)||"auto",this._resolve(m)||"center",this._resolve(x)||"center",this._resolve(_)||"wrap_none",this._resolve(b)||"default",this._resolve(w)||"format_none",v);return E._helper=this,E._createdAtBar=this.context.idx,this._boxes.push(E),this._enforceMaxCount(),this.syncToPlot(),E}_enforceMaxCount(){const e=this.context.indicator?.max_boxes_count??50,i=this._boxes.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._boxes){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}new(...e){const i=se(e,Df,Mf);let r,s,a,n,o=i.xloc;if(i.top_left instanceof me){const l=i.top_left,c=i.bottom_right,h=this._resolvePoint(l);r=h.x,s=l.price,o=o||h.xloc,c instanceof me?(a=this._resolvePoint(c).x,n=c.price):(a=0,n=NaN)}else r=this._resolve(i.left),s=this._resolve(i.top),a=this._resolve(i.right),n=this._resolve(i.bottom);return this._createBox(r,s,a,n,o,i.extend,i.border_color,i.border_style,i.border_width,i.bgcolor,i.text,i.text_color,i.text_size,i.text_halign,i.text_valign,i.text_wrap,i.text_font_family,void 0,i.force_overlay)}any(...e){return this.new(...e)}set_left(e,i){e&&!e._deleted&&(e.left=this._resolve(i))}set_right(e,i){e&&!e._deleted&&(e.right=this._resolve(i))}set_top(e,i){e&&!e._deleted&&(e.top=this._resolve(i))}set_bottom(e,i){e&&!e._deleted&&(e.bottom=this._resolve(i))}set_lefttop(e,i,r){e&&!e._deleted&&(e.left=this._resolve(i),e.top=this._resolve(r))}set_rightbottom(e,i,r){e&&!e._deleted&&(e.right=this._resolve(i),e.bottom=this._resolve(r))}set_top_left_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.left=r.x,e.top=i.price,e.xloc=r.xloc}}set_bottom_right_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.right=r.x,e.bottom=i.price,e.xloc=r.xloc}}set_xloc(e,i,r,s){e&&!e._deleted&&(e.left=this._resolve(i),e.right=this._resolve(r),e.xloc=this._resolve(s))}set_bgcolor(e,i){e&&!e._deleted&&(e.bgcolor=this._resolve(i))}set_border_color(e,i){e&&!e._deleted&&(e.border_color=this._resolve(i))}set_border_width(e,i){e&&!e._deleted&&(e.border_width=this._resolve(i)??1)}set_border_style(e,i){e&&!e._deleted&&(e.border_style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_text(e,i){e&&!e._deleted&&(e.text=this._resolve(i)||"")}set_text_color(e,i){e&&!e._deleted&&(e.text_color=this._resolve(i))}set_text_size(e,i){e&&!e._deleted&&(e.text_size=this._resolve(i))}set_text_halign(e,i){e&&!e._deleted&&(e.text_halign=this._resolve(i))}set_text_valign(e,i){e&&!e._deleted&&(e.text_valign=this._resolve(i))}set_text_wrap(e,i){e&&!e._deleted&&(e.text_wrap=this._resolve(i))}set_text_font_family(e,i){e&&!e._deleted&&(e.text_font_family=this._resolve(i))}set_text_formatting(e,i){e&&!e._deleted&&(e.text_formatting=this._resolve(i))}get_left(e){return e?e.left:NaN}get_right(e){return e?e.right:NaN}get_top(e){return e?e.top:NaN}get_bottom(e){return e?e.bottom:NaN}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._boxes.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(i=>i._createdAtBar<e),this.syncToPlot()}}var Of=Object.defineProperty,Vf=(t,e,i)=>e in t?Of(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,It=(t,e,i)=>Vf(t,typeof e!="symbol"?e+"":e,i);let Lf=0;class $f{constructor(e,i,r){It(this,"id"),It(this,"line1"),It(this,"line2"),It(this,"color"),It(this,"_deleted"),It(this,"_createdAtBar",-1),this.id=Lf++,this.line1=e,this.line2=i,this.color=r,this._deleted=!1}get_line1(){return this.line1}get_line2(){return this.line2}set_color(e){this._deleted||(typeof e=="function"&&(e=e()),e&&typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"&&(e=e.get(0)),this.color=e||"")}delete(){this._deleted=!0}toPlotData(){const e=r=>r?{id:r.id,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,xloc:r.xloc,extend:r.extend,color:r.color,style:r.style,width:r.width,_deleted:r._deleted}:null,i=!!(this.line1?.force_overlay||this.line2?.force_overlay);return{id:this.id,line1:e(this.line1),line2:e(this.line2),color:this.color,force_overlay:i,_deleted:this._deleted}}}var jf=Object.defineProperty,Bf=(t,e,i)=>e in t?jf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ff=(t,e,i)=>Bf(t,typeof e!="symbol"?e+"":e,i);class Wf{constructor(e){this.context=e,Ff(this,"_linefills",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._linefills.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:r,options:{style:"linefill"}}],s.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:s,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(e,i,r){const s=this._resolve(e),a=this._resolve(i),n=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolve(n)||"";if(s&&a){const c=s.id,h=a.id;for(const p of this._linefills){if(p._deleted)continue;const u=p.line1?.id,f=p.line2?.id;if(u===c&&f===h||u===h&&f===c)return p.color=o,p._createdAtBar=this.context.idx,this.syncToPlot(),p}}const l=new $f(s,a,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),this.syncToPlot(),l}any(...e){return this.new(e[0],e[1],e[2])}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i)||"")}get_line1(e){return e?e.line1:void 0}get_line2(e){return e?e.line2:void 0}delete(e){e&&(e._deleted=!0)}get all(){return this._linefills.filter(e=>!e._deleted)}rollbackFromBar(e){this._linefills=this._linefills.filter(i=>i._createdAtBar<e),this.syncToPlot()}}var Uf=Object.defineProperty,qf=(t,e,i)=>e in t?Uf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,De=(t,e,i)=>qf(t,typeof e!="symbol"?e+"":e,i);let Kf=0;class zf{constructor(e,i=!1,r=!1,s="bi",a="#2962ff",n="",o="style_solid",l=1,c=!1){De(this,"id"),De(this,"points"),De(this,"curved"),De(this,"closed"),De(this,"xloc"),De(this,"line_color"),De(this,"fill_color"),De(this,"line_style"),De(this,"line_width"),De(this,"force_overlay"),De(this,"_deleted"),De(this,"_createdAtBar",-1),this.id=Kf++,this.points=e,this.curved=i,this.closed=r,this.xloc=s,this.line_color=a,this.fill_color=n,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}}var Hf=Object.defineProperty,Gf=(t,e,i)=>e in t?Hf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Yf=(t,e,i)=>Gf(t,typeof e!="symbol"?e+"":e,i);class Xf{constructor(e){this.context=e,Yf(this,"_polylines",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(i=>i.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_extractPoints(e){let i=this._resolve(e);const r=i&&i.array?i.array:i;return Array.isArray(r)?r.filter(s=>s instanceof me):[]}new(...e){let i,r=!1,s=!1,a="bi",n="#2962ff",o="",l="style_solid",c=1,h=!1;const p=_=>{r=_.curved??r,s=_.closed??s,a=_.xloc??a,n=_.line_color??n,o=_.fill_color??o,l=_.line_style??l,c=_.line_width??c,h=_.force_overlay??h},u=e.length>=1?e[e.length-1]:null,f=e.length>=2&&u&&typeof u=="object"&&!Array.isArray(u)&&!(u instanceof g)&&!(u instanceof me);if(e.length===1&&u&&typeof u=="object"&&!Array.isArray(u)&&"points"in u)i=u.points,p(u);else{const _=f?e.slice(0,-1):e;i=_[0],r=_[1]??r,s=_[2]??s,a=_[3]??a,n=_[4]??n,o=_[5]??o,l=_[6]??l,c=_[7]??c,h=_[8]??h,f&&p(u)}const m=this._extractPoints(i),x=new zf(m,this._resolve(r)??!1,this._resolve(s)??!1,this._resolve(a)||"bi",this._resolveColor(n,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(h)??!1);return x._createdAtBar=this.context.idx,this._polylines.push(x),this._enforceMaxCount(),this.syncToPlot(),x}_enforceMaxCount(){const e=this.context.indicator?.max_polylines_count??50,i=this._polylines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._polylines){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}any(...e){return this.new(...e)}delete(e){e&&(e._deleted=!0)}get all(){return this._polylines.filter(e=>!e._deleted)}rollbackFromBar(e){this._polylines=this._polylines.filter(i=>i._createdAtBar<e),this.syncToPlot()}}var Qf=Object.defineProperty,Zf=(t,e,i)=>e in t?Qf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,_e=(t,e,i)=>Zf(t,typeof e!="symbol"?e+"":e,i);let Jf=0;class ed{constructor(e="top_right",i=1,r=1,s="",a="",n=0,o="",l=0,c=!1){_e(this,"id"),_e(this,"position"),_e(this,"columns"),_e(this,"rows"),_e(this,"bgcolor"),_e(this,"frame_color"),_e(this,"frame_width"),_e(this,"border_color"),_e(this,"border_width"),_e(this,"force_overlay"),_e(this,"_deleted"),_e(this,"cells"),_e(this,"merges"),_e(this,"_helper"),this.id=Jf++,this.position=e,this.columns=i,this.rows=r,this.bgcolor=s,this.frame_color=a,this.frame_width=n,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let h=0;h<r;h++){this.cells[h]=[];for(let p=0;p<i;p++)this.cells[h][p]=null}}delete(){this._deleted=!0}toPlotData(){const e=this.cells.map(i=>i.map(r=>r?{...r}:null));return{id:this.id,position:this.position,columns:this.columns,rows:this.rows,bgcolor:this.bgcolor,frame_color:this.frame_color,frame_width:this.frame_width,border_color:this.border_color,border_width:this.border_width,force_overlay:this.force_overlay,_deleted:this._deleted,cells:e,merges:this.merges.map(i=>({...i}))}}setCell(e,i,r){if(i<0||i>=this.rows||e<0||e>=this.columns)return;const s=this.cells[i][e];if(s&&s._merged&&s._merge_parent){const[n,o]=s._merge_parent;if(n===e&&o===i)s._merged=!1,s._merge_parent=void 0;else{this.setCell(n,o,r);return}}const a=s||this._defaultCell();Object.assign(a,r),this.cells[i][e]=a}getCell(e,i){return i<0||i>=this.rows||e<0||e>=this.columns?null:this.cells[i][e]}clearCell(e,i){i<0||i>=this.rows||e<0||e>=this.columns||(this.cells[i][e]=null)}_setHelper(e){this._helper=e}cell(...e){return this._helper.cell(this,...e)}clear(...e){return this._helper.clear(this,...e)}merge_cells(...e){return this._helper.merge_cells(this,...e)}cell_set_text(...e){return this._helper.cell_set_text(this,...e)}cell_set_bgcolor(...e){return this._helper.cell_set_bgcolor(this,...e)}cell_set_text_color(...e){return this._helper.cell_set_text_color(this,...e)}cell_set_text_size(...e){return this._helper.cell_set_text_size(this,...e)}cell_set_height(...e){return this._helper.cell_set_height(this,...e)}cell_set_width(...e){return this._helper.cell_set_width(this,...e)}cell_set_tooltip(...e){return this._helper.cell_set_tooltip(this,...e)}cell_set_text_halign(...e){return this._helper.cell_set_text_halign(this,...e)}cell_set_text_valign(...e){return this._helper.cell_set_text_valign(this,...e)}cell_set_text_font_family(...e){return this._helper.cell_set_text_font_family(this,...e)}set_position(...e){return this._helper.set_position(this,...e)}set_bgcolor(...e){return this._helper.set_bgcolor(this,...e)}set_border_color(...e){return this._helper.set_border_color(this,...e)}set_border_width(...e){return this._helper.set_border_width(this,...e)}set_frame_color(...e){return this._helper.set_frame_color(this,...e)}set_frame_width(...e){return this._helper.set_frame_width(this,...e)}_defaultCell(){return{text:"",width:0,height:0,text_color:"#000000",text_halign:"center",text_valign:"center",text_size:"normal",bgcolor:"",tooltip:"",text_font_family:"default",_merged:!1,_merge_parent:null}}}var td=Object.defineProperty,id=(t,e,i)=>e in t?td(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,rd=(t,e,i)=>id(t,typeof e!="symbol"?e+"":e,i);class sd{constructor(e){this.context=e,rd(this,"_tables",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__tables__.data=[{time:e,value:this._tables.map(i=>i.toPlotData()),options:{style:"table"}}]}_resolve(e){return e==null?e:typeof e=="object"&&"__value"in e?e.__value:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(...e){let i="top_right",r=1,s=1,a="",n="",o=0,l="",c=0,h=!1;const p=e[e.length-1];if(p&&typeof p=="object"&&!Array.isArray(p)&&("bgcolor"in p||"frame_color"in p||"border_color"in p||"position"in p||"columns"in p||"rows"in p)){const f=p,m=e.slice(0,-1);i=m[0]??f.position??i,r=m[1]??f.columns??r,s=m[2]??f.rows??s,a=f.bgcolor??a,n=f.frame_color??n,o=f.frame_width??o,l=f.border_color??l,c=f.border_width??c,h=f.force_overlay??h}else i=e[0]??i,r=e[1]??r,s=e[2]??s,a=e[3]??a,n=e[4]??n,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h;const u=new ed(this._resolve(i)||"top_right",this._resolve(r)||1,this._resolve(s)||1,this._resolve(a)||"",this._resolve(n)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(h)??!1);return u._setHelper(this),this._tables.push(u),this.syncToPlot(),u}any(...e){return this.new(...e)}cell(...e){let i,r,s,a="",n=0,o=0,l="#000000",c="center",h="center",p="normal",u="",f="",m="default";const x=e[e.length-1];if(x&&typeof x=="object"&&!Array.isArray(x)&&("text"in x||"bgcolor"in x||"text_color"in x||"text_size"in x||"text_halign"in x||"tooltip"in x||"column"in x||"row"in x||"height"in x||"width"in x||"text_valign"in x||"text_font_family"in x)){const v=x,E=e.slice(0,-1);i=E[0],r=E.length>1?E[1]:v.column??0,s=E.length>2?E[2]:v.row??0,a=E[3]??v.text??a,n=E[4]??v.width??n,o=E[5]??v.height??o,l=E[6]??v.text_color??l,c=E[7]??v.text_halign??c,h=E[8]??v.text_valign??h,p=E[9]??v.text_size??p,u=E[10]??v.bgcolor??u,f=E[11]??v.tooltip??f,m=E[12]??v.text_font_family??m}else i=e[0],r=e[1]??0,s=e[2]??0,a=e[3]??a,n=e[4]??n,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h,p=e[9]??p,u=e[10]??u,f=e[11]??f,m=e[12]??m;const _=this._resolve(i);if(!_||_._deleted)return;const b=this._resolve(r)??0,w=this._resolve(s)??0;_.setCell(b,w,{text:this._resolveText(this._resolve(a)),width:this._resolve(n)||0,height:this._resolve(o)||0,text_color:this._resolve(l)||"#000000",text_halign:this._resolve(c)||"center",text_valign:this._resolve(h)||"center",text_size:this._resolve(p)||"normal",bgcolor:this._resolve(u)||"",tooltip:this._resolveText(this._resolve(f)),text_font_family:this._resolve(m)||"default"}),this.syncToPlot()}delete(e){e&&(e._deleted=!0)}clear(...e){let i,r,s,a,n;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,s=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:r),n=f.end_row??(e.length>5?e[4]:s)}else i=e[0],r=e[1]??0,s=e[2]??0,a=e[3]??r,n=e[4]??s;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(s)??0,p=this._resolve(a)??c,u=this._resolve(n)??h;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)l.clearCell(m,f);this.syncToPlot()}merge_cells(...e){let i,r,s,a,n;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,s=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:0),n=f.end_row??(e.length>5?e[4]:0)}else i=e[0],r=e[1]??0,s=e[2]??0,a=e[3]??0,n=e[4]??0;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(s)??0,p=this._resolve(a)??0,u=this._resolve(n)??0;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)f===h&&m===c||l.setCell(m,f,{_merged:!0,_merge_parent:[c,h]});l.merges.push({startCol:c,startRow:h,endCol:p,endRow:u}),this.syncToPlot()}cell_set_text(e,i,r,s){this._setCellProp(e,i,r,"text",s,!0)}cell_set_bgcolor(e,i,r,s){this._setCellProp(e,i,r,"bgcolor",s)}cell_set_text_color(e,i,r,s){this._setCellProp(e,i,r,"text_color",s)}cell_set_text_size(e,i,r,s){this._setCellProp(e,i,r,"text_size",s)}cell_set_height(e,i,r,s){this._setCellProp(e,i,r,"height",s)}cell_set_width(e,i,r,s){this._setCellProp(e,i,r,"width",s)}cell_set_tooltip(e,i,r,s){this._setCellProp(e,i,r,"tooltip",s,!0)}cell_set_text_halign(e,i,r,s){this._setCellProp(e,i,r,"text_halign",s)}cell_set_text_valign(e,i,r,s){this._setCellProp(e,i,r,"text_valign",s)}cell_set_text_font_family(e,i,r,s){this._setCellProp(e,i,r,"text_font_family",s)}set_position(e,i){const r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(i)||r.position,this.syncToPlot())}set_bgcolor(e,i){const r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(i)||"",this.syncToPlot())}set_border_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(i)||"",this.syncToPlot())}set_border_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(i)||0,this.syncToPlot())}set_frame_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(i)||"",this.syncToPlot())}set_frame_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(i)||0,this.syncToPlot())}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,i,r,s,a,n=!1){const o=this._resolve(e);if(!o||o._deleted)return;const l=this._resolve(i)??0,c=this._resolve(r)??0,h=this._resolve(a);o.setCell(l,c,{[s]:n?this._resolveText(h):h}),this.syncToPlot()}_resolveText(e){return e==null||e!==e?"":String(e)}}var nd=Object.defineProperty,ad=(t,e,i)=>e in t?nd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,$=(t,e,i)=>ad(t,typeof e!="symbol"?e+"":e,i);const Yi=class oi{constructor({marketData:e,source:i,tickerId:r,timeframe:s,limit:a,sDate:n,eDate:o,fullContext:l,inputs:c}){$(this,"data",{open:new g([]),high:new g([]),low:new g([]),close:new g([]),volume:new g([]),hl2:new g([]),hlc3:new g([]),ohlc4:new g([]),hlcc4:new g([]),bar_index:new g([])}),$(this,"indicator"),$(this,"cache",{}),$(this,"taState",{}),$(this,"isSecondaryContext",!1),$(this,"chartTimezone",null),$(this,"dataVersion",0),$(this,"__maxLoops",5e5),$(this,"NA",NaN),$(this,"warnings",[]),$(this,"alerts",[]),$(this,"_alertMode","realtime"),$(this,"_execTick",0),$(this,"lang"),$(this,"length",0),$(this,"_drawingHelpers",[]),$(this,"pine"),$(this,"idx",0),$(this,"params",{}),$(this,"const",{}),$(this,"var",{}),$(this,"let",{}),$(this,"lctx",new Map),$(this,"result"),$(this,"plots",{}),$(this,"marketData"),$(this,"source"),$(this,"tickerId"),$(this,"timeframe",""),$(this,"limit"),$(this,"sDate"),$(this,"eDate"),$(this,"fullContext"),$(this,"pineTSCode"),$(this,"inputs",{}),$(this,"_callStack",[]),this.marketData=e,this.source=i,this.tickerId=r,this.timeframe=s,this.limit=a,this.sDate=n,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};const h=new Hc(this),p={Type:h.Type.bind(h),na:new Vt,nz:h.nz.bind(h),indicator:h.indicator.bind(h),fixnan:h.fixnan.bind(h),alertcondition:h.alertcondition.bind(h),alert:new zc(this),error:h.error.bind(h),max_bars_back:h.max_bars_back.bind(h),timestamp:h.timestamp.bind(h),time:new Rr(this,"openTime"),time_close:new Rr(this,"closeTime"),dayofmonth:new nt(this,at.dayofmonth),dayofweek:new nt(this,at.dayofweek),hour:new nt(this,at.hour),minute:new nt(this,at.minute),month:new nt(this,at.month),second:new nt(this,at.second),weekofyear:new nt(this,at.weekofyear),year:new nt(this,at.year),bool:h.bool.bind(h),int:h.int.bind(h),float:h.float.bind(h),string:h.string.bind(h)},u=this;this.pine={input:new Eh(this),ta:new Ap(this),math:new au(this),request:new fu(this),array:new gl(this),map:new Pl(this),matrix:new Pc(this),syminfo:null,timeframe:new Lp(this),barstate:new Oc(this),get bar_index(){return u.data.bar_index},get last_bar_index(){return u.data.close.length-1},get last_bar_time(){return u.data.openTime.get(u.data.openTime.length-1)},get timenow(){return new Date().getTime()},get time_tradingday(){const z=g.from(u.data.closeTime).get(0);if(isNaN(z))return NaN;const q=u.pine?.syminfo?.timezone||"UTC",V=Pt(z,q);return Date.UTC(V.year,V.month-1,V.day,0,0,0)},get inputs(){return u.inputs},log:new Dp(this),str:new Mp(this),...p,...Ho};const f=p.dayofweek;Object.assign(f,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=f;const m=new ef(this),x=new tf(this),_=new rf(this);this.bindContextObject(m,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(m,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(x,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(_,["any","param"],"fill");const b=new of(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),is_standard:b.is_standard.bind(b),is_heikinashi:b.is_heikinashi.bind(b),is_kagi:b.is_kagi.bind(b),is_linebreak:b.is_linebreak.bind(b),is_pnf:b.is_pnf.bind(b),is_range:b.is_range.bind(b),is_renko:b.is_renko.bind(b),point:b.point};const w=new gf(this);this.bindContextObject(w,["any","new","param","set_x","set_y","set_xy","set_text","set_color","set_textcolor","set_size","set_style","set_textalign","set_tooltip","set_point","set_xloc","set_yloc","get_x","get_y","get_text","copy","delete","style_label_down","style_label_up","style_label_left","style_label_right","style_label_lower_left","style_label_lower_right","style_label_upper_left","style_label_upper_right","style_label_center","style_circle","style_square","style_diamond","style_flag","style_arrowup","style_arrowdown","style_cross","style_xcross","style_triangleup","style_triangledown","style_none","style_text_outline"],"label"),Object.defineProperty(this.pine.label,"all",{get:()=>w.all});const v=new Nf(this);this.bindContextObject(v,["any","new","param","set_x1","set_y1","set_x2","set_y2","set_xy1","set_xy2","set_color","set_width","set_style","set_extend","set_xloc","set_first_point","set_second_point","get_x1","get_y1","get_x2","get_y2","get_price","copy","delete","style_solid","style_dotted","style_dashed","style_arrow_left","style_arrow_right","style_arrow_both"],"line"),Object.defineProperty(this.pine.line,"all",{get:()=>v.all});const E=new Rf(this);this.bindContextObject(E,["any","new","param","copy","delete","set_left","set_right","set_top","set_bottom","set_lefttop","set_rightbottom","set_top_left_point","set_bottom_right_point","set_bgcolor","set_border_color","set_border_width","set_border_style","set_extend","set_xloc","set_text","set_text_color","set_text_size","set_text_halign","set_text_valign","set_text_wrap","set_text_font_family","set_text_formatting","get_left","get_right","get_top","get_bottom"],"box"),Object.defineProperty(this.pine.box,"all",{get:()=>E.all});const T=new Wf(this);this.bindContextObject(T,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>T.all});const C=new Xf(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>C.all});const O=new sd(this);this.bindContextObject(O,["any","new","param","cell","delete","clear","merge_cells","cell_set_text","cell_set_bgcolor","cell_set_text_color","cell_set_text_size","cell_set_height","cell_set_width","cell_set_tooltip","cell_set_text_halign","cell_set_text_valign","cell_set_text_font_family","set_position","set_bgcolor","set_border_color","set_border_width","set_frame_color","set_frame_width"],"table"),Object.defineProperty(this.pine.table,"all",{get:()=>O.all}),this._drawingHelpers=[w,v,E,T,C,O];const B=new Yc(this);this.bindContextObject(B,["any","param","new","rgb","from_gradient","r","g","b","t","aqua","black","blue","fuchsia","gray","green","lime","maroon","navy","olive","orange","purple","red","silver","teal","white","yellow"],"color")}warn(e,i){this.warnings.push({message:e,method:i,bar:this.idx})}rollbackDrawings(e){for(const i of this._drawingHelpers)i.rollbackFromBar(e)}bindContextObject(e,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const s=r?this.pine[r]:this.pine;for(const a of i)typeof e[a]=="function"?s[a]=e[a].bind(e):s[a]=e[a]}init(e,i,r=0){let s;return i instanceof g?s=i.get(0):Array.isArray(i)?Array.isArray(i[0])?s=i[0]:s=i[i.length-1+r]:s=i,e?e instanceof g?(e.data[e.data.length-1]=s,e):Array.isArray(e)?(e[e.length-1]=s,new g(e)):new g([s]):new g([s])}initVar(e,i){if(e)return e;if(typeof i=="function"&&(i=i()),i instanceof kt){const s=i.__def__;for(const a in s)typeof i[a]=="function"&&(i[a]=i[a]())}let r;return i instanceof g?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 g([r])}precision(e,i=10){const r=i===10?oi.PRECISION_EPSILON:10**i;return typeof e=="number"?Math.round(e*r)/r:e}param(e,i,r){return typeof e=="string"?e:e instanceof g?i?new g(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new g(e,i||0):(this.params[r].length===0?this.params[r].push(e):this.params[r][this.params[r].length-1]=e,new g(this.params[r],i||0)))}get(e,i){if(e instanceof g)return e.get(i);if(Array.isArray(e)){const r=e.length-1-i;return r<0||r>=e.length?NaN:e[r]}return e}set(e,i){if(e instanceof g){e.set(0,typeof i=="number"?this.precision(i):i);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=i:e.push(i);return}}pushId(e){this._callStack.push(e)}popId(){this._callStack.pop()}peekId(){return this._callStack.length>0?this._callStack[this._callStack.length-1]:""}peekCtx(){const e=this.peekId();if(!e)return this;let i=this.lctx.get(e);return i||(i={id:e,let:{},const:{},var:{}},this.lctx.set(e,i)),i}call(e,i,...r){this.pushId(i);try{return e(...r)}finally{this.popId()}}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,fill:this.pine.fill,plotchar:this.pine.plotchar,plotshape:this.pine.plotshape,plotarrow:this.pine.plotarrow,color:this.pine.color,plot:this.pine.plot,nz:this.pine.nz}}_showDeprecationWarning(e,i){const r=`${e}->${i}`;oi._deprecationWarningsShown.has(r)||(oi._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;",e,i):console.warn(`\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}};$(Yi,"_deprecationWarningsShown",new Set),$(Yi,"PRECISION_EPSILON",10**10);let Br=Yi;var od=Object.defineProperty,ld=(t,e,i)=>e in t?od(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Fr=(t,e,i)=>ld(t,typeof e!="symbol"?e+"":e,i);class Wr{constructor(e,i={}){Fr(this,"source"),Fr(this,"inputs"),this.source=e,this.inputs=i}}var cd=Object.defineProperty,hd=(t,e,i)=>e in t?cd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,J=(t,e,i)=>hd(t,typeof e!="symbol"?e+"":e,i);const Ur={1:6e4,3:18e4,5:3e5,15:9e5,30:18e5,60:36e5,120:72e5,180:108e5,240:144e5,"4H":144e5,"1D":864e5,D:864e5,"1W":6048e5,W:6048e5,"1M":30*864e5,M:30*864e5};function ud(t){return t?Ur[t]??Ur[t.toUpperCase()]??864e5:864e5}class dn{constructor(e,i,r,s,a,n){this.source=e,this.tickerId=i,this.timeframe=r,this.limit=s,this.sDate=a,this.eDate=n,J(this,"data",[]),J(this,"open",[]),J(this,"high",[]),J(this,"low",[]),J(this,"close",[]),J(this,"volume",[]),J(this,"hl2",[]),J(this,"hlc3",[]),J(this,"ohlc4",[]),J(this,"hlcc4",[]),J(this,"openTime",[]),J(this,"closeTime",[]),J(this,"_readyPromise",null),J(this,"_ready",!1),J(this,"_debugSettings",{ln:!1,debug:!1}),J(this,"_transpiledCode",null),J(this,"_isSecondaryContext",!1),J(this,"_syminfo"),J(this,"_chartTimezone",null),J(this,"_maxLoops",5e5),J(this,"_alertMode","realtime"),this._readyPromise=new Promise(o=>{this.loadMarketData(e,i,r,s,a,n).then(l=>{const c=l;this.data=c;const h=c.map(C=>C.open),p=c.map(C=>C.close),u=c.map(C=>C.high),f=c.map(C=>C.low),m=c.map(C=>C.volume),x=c.map(C=>(C.high+C.low+C.close)/3),_=c.map(C=>(C.high+C.low)/2),b=c.map(C=>(C.high+C.low+C.open+C.close)/4),w=c.map(C=>(C.high+C.low+C.close+C.close)/4),v=c.map(C=>C.openTime),E=ud(this.timeframe),T=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+E);this.open=h,this.close=p,this.high=u,this.low=f,this.volume=m,this.hl2=_,this.hlc3=x,this.ohlc4=b,this.hlcc4=w,this.openTime=v,this.closeTime=T,e&&e.getSymbolInfo?e.getSymbolInfo(i).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setTimezone(e){this._chartTimezone=e}setMaxLoops(e){this._maxLoops=e}setAlertMode(e){this._alertMode=e}setDebugSettings({ln:e,debug:i}){this._debugSettings.ln=e,this._debugSettings.debug=i}async loadMarketData(e,i,r,s,a,n){return Array.isArray(e)?e:e.getMarketData(i,r,s,a,n)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,i,r){let s,a={};if(e instanceof Wr?(s=e.source,a=e.inputs||{}):s=e,r&&r>0){const n=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(s,a,i,r,n)}else return this._runComplete(s,a,i)}stream(e,i={}){const{live:r=!0,interval:s=1e3}=i,a=i.pageSize||this.data.length;let n,o={};e instanceof Wr?(n=e.source,o=e.inputs||{}):n=e;const l={data:[],error:[],warning:[],alert:[]};let c=!1;const h=(f,...m)=>{l[f]&&l[f].forEach(x=>x(...m))},p=(f,m)=>{l[f]||(l[f]=[]),l[f].push(m)},u=()=>{c=!0};return(async()=>{try{const f=typeof this.eDate>"u"&&!Array.isArray(this.source)&&r,m=this._runPaginated(n,o,void 0,a,f);for await(const x of m){if(c)break;if(x===null){await new Promise(_=>setTimeout(_,s));continue}if(h("data",x),x.warnings&&x.warnings.length>0){for(const _ of x.warnings)h("warning",_);x.warnings.length=0}if(x.alerts&&x.alerts.length>0){for(const _ of x.alerts)h("alert",_);x.alerts.length=0}if(f&&!c){const _=x.marketData[x.idx],b=_&&_.closeTime<Date.now(),w=x.idx>=x.marketData.length-1;(!b||w)&&await new Promise(v=>setTimeout(v,s))}}}catch(f){h("error",f)}})(),{on:p,stop:u}}async _runComplete(e,i,r){await this.ready(),r||(r=this.data.length);const s=this._initializeContext(e,i,this._isSecondaryContext);return this._transpiledCode=this._transpileCode(e),await this._executeIterations(s,this._transpiledCode,this.data.length-r,this.data.length),s}async*_runPaginated(e,i,r,s,a=!1){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(e,i,this._isSecondaryContext);this._transpiledCode=this._transpileCode(e);let o=this.data.length-r,l=null;for(;;){const c=this.data.length,h=c-o;if(h>0){const x=Math.min(h,s),_=this._getResultLength(n.result),b=o+x;a&&b>=c&&x>1?(await this._executeIterations(n,this._transpiledCode,o,b-1),l=this._snapshotVarState(n),await this._executeIterations(n,this._transpiledCode,b-1,b)):a&&b>=c&&x===1?await this._executeIterations(n,this._transpiledCode,o,b):await this._executeIterations(n,this._transpiledCode,o,b),o+=x,yield this._createPageContext(n,_);continue}if(!a||Array.isArray(this.source))break;const p=Date.now(),{newCandles:u,updatedLastCandle:f}=await this._updateMarketData(),m=Date.now()-p;if(u===0&&!f){yield null;continue}if(u===0&&f&&m<1e3&&await new Promise(x=>setTimeout(x,1e3-m)),n.dataVersion++,n.length=this.data.length,this._restoreVarState(n,l),Array.isArray(n.result))n.result.pop();else if(typeof n.result=="object"&&n.result!==null)for(let x in n.result)Array.isArray(n.result[x])&&n.result[x].pop();n.data.close.data.pop(),n.data.open.data.pop(),n.data.high.data.pop(),n.data.low.data.pop(),n.data.volume.data.pop(),n.data.hl2.data.pop(),n.data.hlc3.data.pop(),n.data.ohlc4.data.pop(),n.data.hlcc4.data.pop(),n.data.openTime.data.pop(),n.data.closeTime&&n.data.closeTime.data.pop(),n.data.bar_index.data.pop(),o=this.data.length-(u+1),n.rollbackDrawings(o),u>0&&(l=null),n.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const i=Object.keys(e);if(i.length>0&&Array.isArray(e[i[0]]))return e[i[0]].length}return 0}_createPageContext(e,i){const r=new Br({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:e,inputs:e.inputs});if(r.pineTSCode=e.pineTSCode,r.idx=e.idx,Array.isArray(e.result))r.result=e.result.slice(i);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let s in e.result)Array.isArray(e.result[s])?r.result[s]=e.result[s].slice(i):r.result[s]=e.result[s]}else r.result=e.result;return r.plots={...e.plots},r.warnings=e.warnings,r.alerts=e.alerts,r}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const i=this.source,r=this.data.length-1,s=this.data[r].openTime;try{const a=await i.getMarketData(this.tickerId,this.timeframe,void 0,s,e);if(!a||a.length===0)return{newCandles:0,updatedLastCandle:!1};let n=!1,o=0;for(let l=0;l<a.length;l++){const c=a[l];c.openTime===s?(this._replaceCandle(r,c),n=!0):c.openTime>s&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:n}}catch(a){return console.error("Error updating market data:",a),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,i){this.data[e]=i,this.open[e]=i.open,this.close[e]=i.close,this.high[e]=i.high,this.low[e]=i.low,this.volume[e]=i.volume,this.hl2[e]=(i.high+i.low)/2,this.hlc3[e]=(i.high+i.low+i.close)/3,this.ohlc4[e]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[e]=(i.high+i.low+i.close+i.close)/4,this.openTime[e]=i.openTime,this.closeTime[e]=i.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;const{newCandles:i,updatedLastCandle:r}=await this._updateMarketData();if(i===0&&!r)return!1;this._removeLastResult(e),e.length=this.data.length;const s=this.data.length-(i+1);return e.rollbackDrawings(s),await this._executeIterations(e,this._transpiledCode,s,this.data.length),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let s in e.result)Array.isArray(e.result[s])&&e.result[s].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();const i=["const","var","let","params"],r=s=>{for(let a of i)if(s[a])for(let n in s[a]){const o=s[a][n];o instanceof g?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(s=>r(s))}_snapshotVarState(e){const i=["const","var","let","params"],r={main:{},lctx:[]},s=a=>{const n={};for(const o of i)if(a[o]){n[o]={};for(const l in a[o]){const c=a[o][l];if(c instanceof g){const h=c.data.length,p=h>0?c.data[h-1]:void 0;n[o][l]={len:h,lastVal:p}}}}return n};if(r.main=s(e),e.lctx){const a=[];e.lctx.forEach(n=>a.push(s(n))),r.lctx=a}return r.resultLength=this._getResultLength(e.result),r.dataLength=e.data.close?.data?.length??0,r}_restoreVarState(e,i){if(!i)return;const r=["const","var","let","params"],s=(a,n)=>{for(const o of r)if(!(!n[o]||!a[o]))for(const l in n[o]){const c=a[o][l],h=n[o][l];c instanceof g&&h&&typeof h.len=="number"&&(c.data.length>h.len&&(c.data.length=h.len),h.len>0&&h.lastVal!==void 0&&(c.data[h.len-1]=h.lastVal))}};if(s(e,i.main),e.lctx&&i.lctx){let a=0;e.lctx.forEach(n=>{i.lctx[a]&&s(n,i.lctx[a]),a++})}}_initializeContext(e,i={},r=!1){const s=new Br({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:i});return s.pine.syminfo=this._syminfo,this._chartTimezone&&(s.chartTimezone=this._chartTimezone),s.__maxLoops=this._maxLoops,s._alertMode=this._alertMode,s.pineTSCode=e,s.isSecondaryContext=r,s.data.close=new g([]),s.data.open=new g([]),s.data.high=new g([]),s.data.low=new g([]),s.data.volume=new g([]),s.data.hl2=new g([]),s.data.hlc3=new g([]),s.data.ohlc4=new g([]),s.data.hlcc4=new g([]),s.data.openTime=new g([]),s.data.closeTime=new g([]),s.length=this.data.length,s}_transpileCode(e){return oo.bind(this)(e,this._debugSettings)}async _executeIterations(e,i,r,s){const a=["const","var","let","params"];for(let n=r;n<s;n++){e.idx=n,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[n]),e.data.open.data.push(this.open[n]),e.data.high.data.push(this.high[n]),e.data.low.data.push(this.low[n]),e.data.volume.data.push(this.volume[n]),e.data.hl2.data.push(this.hl2[n]),e.data.hlc3.data.push(this.hlc3[n]),e.data.ohlc4.data.push(this.ohlc4[n]),e.data.hlcc4.data.push(this.hlcc4[n]),e.data.openTime.data.push(this.openTime[n]),e.data.closeTime.data.push(this.closeTime[n]),e.data.bar_index.data.push(n);const o=await i(e);if(typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let h;o[c]instanceof g?h=o[c].get(0):Array.isArray(o[c])?h=o[c][o[c].length-1]:h=o[c],e.result[c].push(h)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(const c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();const l=c=>{for(let h of a)if(c[h])for(let p in c[h]){const u=c[h][p];if(u instanceof g){const f=u.get(0);u.data.push(f)}else if(Array.isArray(u)){const f=u[u.length-1];u.push(f)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}}}const qr={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},qt={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3},Zd={"1S":{periodType:"second",multiplier:1},"5S":{periodType:"second",multiplier:5},"10S":{periodType:"second",multiplier:10},"15S":{periodType:"second",multiplier:15},"30S":{periodType:"second",multiplier:30},1:{periodType:"minute",multiplier:1},3:{periodType:"minute",multiplier:3},5:{periodType:"minute",multiplier:5},15:{periodType:"minute",multiplier:15},30:{periodType:"minute",multiplier:30},45:{periodType:"minute",multiplier:45},60:{periodType:"hour",multiplier:1},120:{periodType:"hour",multiplier:2},180:{periodType:"hour",multiplier:3},240:{periodType:"hour",multiplier:4},D:{periodType:"day",multiplier:1},W:{periodType:"week",multiplier:1},M:{periodType:"month",multiplier:1}};function Kt(t,e,i=1){if(e==="month"){const s=new Date(t);return Date.UTC(s.getUTCFullYear(),s.getUTCMonth()+i,1,s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds(),s.getUTCMilliseconds())}const r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+i*r[e]}function qe(t,e,i){const[r,s,a]=t.split("-").map(Number),[n,o]=e.split(":").map(Number),l=Date.UTC(r,s-1,a,n,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(l)),h=b=>parseInt(c.find(w=>w.type===b).value,10);let p=h("year"),u=h("month"),f=h("day"),m=h("hour");m===24&&(m=0);let x=h("minute");const _=Date.UTC(p,u-1,f,m,x,0,0)-l;return l-_}function Kr(t,e,i,r,s=1){if(e==="24x7")return Kt(t,r,s);const a=e.split("-")[1];if(!a||a.length!==4)return Kt(t,r,s);const n=a.slice(0,2),o=a.slice(2,4),l=`${n}:${o}`,c=zr(t,i);if(r==="second"||r==="minute"||r==="hour"){const h=t+s*{second:1e3,minute:6e4,hour:36e5}[r],p=qe(c,l,i);return Math.min(h,p)}if(r==="day")return qe(c,l,i);if(r==="week"){const h=new Date(t).getUTCDay(),p=h<=5?5-h:5-h+7,u=t+p*864e5,f=zr(u,i);return qe(f,l,i)}if(r==="month"){const h=new Date(t),p=h.getUTCFullYear(),u=h.getUTCMonth()+s,f=new Date(Date.UTC(p,u,1)),m=new Date(f.getTime()-864e5);for(;m.getUTCDay()===0||m.getUTCDay()===6;)m.setUTCDate(m.getUTCDate()-1);const x=m.toISOString().split("T")[0];return qe(x,l,i)}return Kt(t,r,s)}function zr(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function pd(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}const fd=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function dd(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;const i=qt[t];if(!i)return null;const r=fd.filter(s=>s!=="W"&&s!=="M"&&e.has(s)&&qt[s]<i&&i%qt[s]===0);return r.length===0?null:r[r.length-1]}function mn(t,e){if(t==="W"||t==="M")return 1/0;const i=qt[t],r=qt[e];return!i||!r||r===0?1/0:i/r}function md(t,e,i){if(t.length===0)return[];if(e==="W")return yd(t);if(e==="M")return xd(t);const r=mn(e,i);return gd(t,r)}function gd(t,e){if(t.length===0)return[];const i=[];let r=[t[0]];const s=_d(t),a=s>0?s*1.5:0;for(let n=1;n<t.length;n++){const o=t[n].openTime-t[n-1].openTime;(a>0&&o>a||r.length>=e)&&(i.push(di(r)),r=[]),r.push(t[n])}return r.length>0&&i.push(di(r)),i}function yd(t){const e=[];let i=[],r="";for(const s of t){const a=bd(s.openTime);a!==r&&i.length>0&&(e.push(i),i=[]),r=a,i.push(s)}return i.length>0&&e.push(i),e.map(di)}function xd(t){const e=[];let i=[],r="";for(const s of t){const a=new Date(s.openTime),n=`${a.getUTCFullYear()}-${a.getUTCMonth()}`;n!==r&&i.length>0&&(e.push(i),i=[]),r=n,i.push(s)}return i.length>0&&e.push(i),e.map(di)}function di(t){const e=t[0],i=t[t.length-1];let r=e.high,s=e.low,a=0,n=0,o=0,l=0,c=0;for(let h=0;h<t.length;h++){const p=t[h];p.high>r&&(r=p.high),p.low<s&&(s=p.low),a+=p.volume,n+=p.quoteAssetVolume,o+=p.numberOfTrades,l+=p.takerBuyBaseAssetVolume,c+=p.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:r,low:s,close:i.close,volume:a,closeTime:i.closeTime,quoteAssetVolume:n,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function _d(t){if(t.length<2)return 0;const e=Math.min(t.length-1,20);let i=1/0;for(let r=0;r<e;r++){const s=t[r+1].openTime-t[r].openTime;s>0&&s<i&&(i=s)}return i===1/0?0:i}function bd(t){const e=new Date(t),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1)),s=Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${s}`}var vd=Object.defineProperty,wd=(t,e,i)=>e in t?vd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ri=(t,e,i)=>wd(t,typeof e!="symbol"?e+"":e,i);const si={"1s":"1S","5s":"5S","10s":"10S","15s":"15S","30s":"30S","1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1D":"D","1W":"W","1M":"M","4H":"240",D:"D",W:"W",M:"M"};function Sd(t){if(si[t]!==void 0)return si[t];const e=t.toLowerCase();return si[e]!==void 0?si[e]:/^\d+$/.test(t)?t:/^\d+S$/i.test(t)?t.toUpperCase():t}class Si{constructor(e){ri(this,"_configured"),ri(this,"_requiresApiKey"),ri(this,"_providerName"),ri(this,"_aggregationSubTimeframe",null),this._requiresApiKey=e.requiresApiKey,this._providerName=e.providerName,this._configured=!e.requiresApiKey}ensureConfigured(){if(!this._configured)throw new Error(`${this._providerName} requires configuration before use. Call Provider.${this._providerName}.configure({ apiKey: '...' }) or instantiate directly: new ${this._providerName}Provider({ apiKey: '...' })`)}configure(e){this._configured=!0}get isConfigured(){return this._configured}normalizeCloseTime(e){pd(e)}setAggregationSubTimeframe(e){this._aggregationSubTimeframe=e}getSupportedTimeframes(){return new Set(["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"])}async getMarketData(e,i,r,s,a){const n=Sd(i),o=this.getSupportedTimeframes();if(o.has(n))return this._getMarketDataNative(e,n,r,s,a);const l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:dd(n,o);if(!c)return console.error(`${this._providerName}: Timeframe '${i}' is not supported and no valid sub-timeframe found for aggregation.`),[];const h=this._computeSubLimit(n,c,r),p=await this._getMarketDataNative(e,c,h,s,a);if(p.length===0)return[];const u=md(p,n,c);return r&&r>0&&u.length>r?u.slice(u.length-r):u}_computeSubLimit(e,i,r){if(!r)return;const s=mn(e,i);return s===1/0?e==="W"?r*7+14:e==="M"?r*31+31:r*30:Math.ceil(r*s)+Math.ceil(s)}}var Ed=Object.defineProperty,Nd=(t,e,i)=>e in t?Ed(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,mi=(t,e,i)=>Nd(t,typeof e!="symbol"?e+"":e,i);const Mi="https://api.binance.com/api/v3",Hr="https://api.binance.us/api/v3",ni={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 Cd{constructor(e=300*1e3){mi(this,"cache"),mi(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(e){const i=this.generateKey(e),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(e,i){const r=this.generateKey(e);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[i,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class Id extends Si{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),mi(this,"cacheManager"),mi(this,"activeApiUrl",null),this.cacheManager=new Cd(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Mi}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=Mi,this.activeApiUrl}catch{}try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Hr}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=Hr,this.activeApiUrl}catch{}return Mi}async _fetchRawChunk(e,i,r,s,a){const n=ni[i.toUpperCase()];if(!n)return console.error(`Unsupported timeframe: ${i}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${n}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),s&&(o+=`&startTime=${s}`),a&&(o+=`&endTime=${a}`);const l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,i,r,s){try{const a=ni[i.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${i}`),[];let n=[],o=r;const l=s,c=qr[a];if(!c)return console.error(`Duration not defined for interval: ${a}`),[];for(;o<l;){const h=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,i,1e3,o,h);if(p.length===0)break;n=n.concat(p),o=p[p.length-1].closeTime+1}return this.normalizeCloseTime(n),n}catch(a){return console.error("Error in getMarketDataInterval:",a),[]}}async getMarketDataBackwards(e,i,r,s){let a=r,n=[],o=s,l=0;const c=Math.ceil(r/1e3)+5;for(;a>0&&l<c;){l++;const h=Math.min(a,1e3),p=await this._fetchRawChunk(e,i,h,void 0,o);if(p.length===0||(n=p.concat(n),a-=p.length,o=p[0].openTime-1,p.length<h))break}return this.normalizeCloseTime(n),n}getSupportedTimeframes(){return new Set(["1","3","5","15","30","60","120","240","D","W","M"])}async _getMarketDataNative(e,i,r,s,a){try{const n=a!==void 0,o={tickerId:e,timeframe:i,limit:r,sDate:s,eDate:a};if(n){const c=this.cacheManager.get(o);if(c)return c}if(!ni[i.toUpperCase()])return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,s,a)){if(s&&a){const c=await this.getMarketDataInterval(e,i,s,a),h=r?c.slice(0,r):c;return this.cacheManager.set(o,h),h}else if(r&&r>1e3){const c=await this.getMarketDataBackwards(e,i,r,a);return this.cacheManager.set(o,c),c}}const l=await this._fetchRawChunk(e,i,r,s,a);return this.normalizeCloseTime(l),n&&this.cacheManager.set(o,l),l}catch(n){return console.error("Error in binance.klines:",n),[]}}shouldPaginate(e,i,r,s){if(i&&i>1e3)return!0;if(r&&s){const a=ni[e.toUpperCase()],n=qr[a];if(n)return Math.ceil((s-r)/n)>1e3}return!1}async getSymbolInfo(e){try{let i="crypto",r=await this.getBaseUrl(),s=e,a="";e.endsWith(".P")?(i="futures",s=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",a="Perpetual"):e.includes("_")&&(i="futures",s=e,r="https://dapi.binance.com/dapi/v1",a="Delivery");const n=i==="crypto"?`${r}/exchangeInfo?symbol=${s}`:`${r}/exchangeInfo`,o=await fetch(n);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;const c=i==="futures"?l.find(v=>v.symbol===s):l[0];if(!c)return console.error(`Symbol ${s} not found in exchange info`),null;const h=c.filters?.find(v=>v.filterType==="PRICE_FILTER"),p=c.filters?.find(v=>v.filterType==="LOT_SIZE"),u=h?parseFloat(h.tickSize):.01,f=p?parseFloat(p.minQty):0,m=Math.round(1/u),x=c.baseAsset,_=c.quoteAsset,b=a?` ${a}`:"",w=`${x} / ${_}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:x,description:w,type:i,main_tickerid:`BINANCE:${e}`,current_contract:a,isin:"",basecurrency:x,currency:_,timezone:"Etc/UTC",country:"",mintick:u,pricescale:m,minmove:1,pointvalue:c.contractSize||1,mincontract:f,session:"24x7",volumetype:"base",expiration_date:c.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in binance.exchangeInfo:",i),null}}}var kd=Object.defineProperty,Ad=(t,e,i)=>e in t?kd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,jt=(t,e,i)=>Ad(t,typeof e!="symbol"?e+"":e,i);const Td="https://financialmodelingprep.com",Gr=new Set(["USD","EUR","GBP","JPY","CHF","AUD","CAD","NZD","SEK","NOK","DKK","SGD","HKD","KRW","MXN","ZAR","TRY","BRL","INR","CNY","PLN","CZK","HUF","ILS","THB","TWD","PHP","IDR","MYR","RUB","CLP","COP"]),Yr={"1D":{endpoint:"/stable/historical-price-eod/full",type:"daily"},D:{endpoint:"/stable/historical-price-eod/full",type:"daily"},1:{endpoint:"/stable/historical-chart/1min",interval:"1min",type:"intraday"},5:{endpoint:"/stable/historical-chart/5min",interval:"5min",type:"intraday"},15:{endpoint:"/stable/historical-chart/15min",interval:"15min",type:"intraday"},30:{endpoint:"/stable/historical-chart/30min",interval:"30min",type:"intraday"},60:{endpoint:"/stable/historical-chart/1hour",interval:"1hour",type:"intraday"},240:{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"},"4H":{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"}},Xr={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",NYSEArca:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",PNK:"America/New_York",TSX:"America/Toronto",TSXV:"America/Toronto",LSE:"Europe/London",EURONEXT:"Europe/Paris",XETRA:"Europe/Berlin",JPX:"Asia/Tokyo",HKSE:"Asia/Hong_Kong",SSE:"Asia/Shanghai",SHZ:"Asia/Shanghai",ASX:"Australia/Sydney",NSE:"Asia/Kolkata",BSE:"Asia/Kolkata",KRX:"Asia/Seoul",CRYPTO:"Etc/UTC"},Qr={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",NYSEArca:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",PNK:"0930-1600",TSX:"0930-1600",TSXV:"0930-1600",LSE:"0800-1630",EURONEXT:"0900-1730",XETRA:"0900-1730",JPX:"0900-1530",HKSE:"0930-1600",SSE:"0930-1500",SHZ:"0930-1500",ASX:"1000-1600",NSE:"0915-1530",BSE:"0915-1530",KRX:"0900-1530",CRYPTO:"24x7"},Pd={daily:{periodType:"day",multiplier:1},"1min":{periodType:"minute",multiplier:1},"5min":{periodType:"minute",multiplier:5},"15min":{periodType:"minute",multiplier:15},"30min":{periodType:"minute",multiplier:30},"1hour":{periodType:"hour",multiplier:1},"4hour":{periodType:"hour",multiplier:4}};class Dd extends Si{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),jt(this,"_apiKey",null),jt(this,"_baseUrl",Td),jt(this,"_profileCache",new Map),jt(this,"_symbolInfoCache",new Map),jt(this,"_mintickCache",new Map),e?.apiKey&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,e.baseUrl&&(this._baseUrl=e.baseUrl)}getSupportedTimeframes(){return new Set(["1","5","15","30","60","240","D"])}async _getMarketDataNative(e,i,r,s,a){this.ensureConfigured();try{const n=i.toUpperCase(),o=Yr[n]||Yr[i];if(!o)return console.error(`FMP: Unsupported timeframe: ${i}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,s,a,r):l=await this._fetchDailyData(e,s,a,r),l.length>0&&!this._mintickCache.has(e)){const c=this._estimateMintick(l);c!==void 0&&this._mintickCache.set(e,c)}return l}catch(n){return console.error("Error in FMPProvider.getMarketData:",n),[]}}async _fetchDailyData(e,i,r,s){let a=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;i&&(a+=`&from=${this._msToDateStr(i)}`),r&&(a+=`&to=${this._msToDateStr(r)}`);const n=await fetch(a);if(!n.ok){const p=await n.text();throw new Error(`FMP HTTP ${n.status}: ${p}`)}const o=await n.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();const l=s&&s>0&&s<o.length?o.slice(o.length-s):o,{session:c,timezone:h}=await this._resolveSessionInfo(e);return l.map(p=>{const u=this._dateStrToMs(p.date),f=Kr(u,c,h,"day");return{openTime:u,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:f,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,i,r,s,a,n){let o=`${this._baseUrl}${i}?symbol=${e}&apikey=${this._apiKey}`;s&&(o+=`&from=${this._msToDateStr(s)}`),a&&(o+=`&to=${this._msToDateStr(a)}`);const l=await fetch(o);if(!l.ok){const x=await l.text();if(l.status===403||x.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${r}) requires a paid plan. Use daily timeframe ('D') with a free API key, or upgrade at https://financialmodelingprep.com/`),[];throw new Error(`FMP HTTP ${l.status}: ${x}`)}const c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();const h=n&&n>0&&n<c.length?c.slice(c.length-n):c,{periodType:p,multiplier:u}=Pd[r]||{periodType:"minute",multiplier:1},{session:f,timezone:m}=await this._resolveSessionInfo(e);return h.map(x=>{const _=this._dateTimeStrToMs(x.date),b=Kr(_,f,m,p,u);return{openTime:_,open:x.open,high:x.high,low:x.low,close:x.close,volume:x.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){if(this.ensureConfigured(),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{const i=await this._fetchProfile(e);let r="stock";i?.isEtf?r="etf":i?.isFund?r="fund":this._isForex(e)?r="forex":this._isCrypto(e)&&(r="crypto");const s=i?.exchange||(r==="crypto"?"CRYPTO":r==="forex"?"FX":""),a=r==="crypto"||r==="forex"?"Etc/UTC":Xr[s]||"America/New_York",n=r==="crypto"?"24x7":r==="forex"?"0000-0000":Qr[s]||"0930-1600",o=i?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):i?.currency||"USD",c=this._mintickCache.get(e)??.01,h=Math.round(1/c),p=Math.round(c*h),u={ticker:i?.symbol||e,tickerid:`${s}:${i?.symbol||e}`,prefix:s,root:i?.symbol||e,description:i?.companyName||e,type:r,main_tickerid:`${s}:${i?.symbol||e}`,current_contract:"",isin:i?.isin||"",basecurrency:l,currency:o,timezone:a,country:i?.country||"",mintick:c,pricescale:h,minmove:p,pointvalue:1,mincontract:0,session:n,volumetype:"base",expiration_date:0,employees:i&&parseInt(i.fullTimeEmployees)||0,industry:i?.industry||"",sector:i?.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};return this._mintickCache.has(e)&&this._symbolInfoCache.set(e,u),u}catch(i){return console.error("Error in FMPProvider.getSymbolInfo:",i),null}}_estimateMintick(e){const i=[];for(let o=0;o<e.length;o++){const l=e[o],c=Math.abs(l.close-l.open),h=Math.abs(l.high-l.low);if(c>0&&i.push(c),h>0&&i.push(h),o>0){const p=Math.abs(l.close-e[o-1].close);p>0&&i.push(p)}}if(i.length===0)return;const r=Math.min(...i),s=Math.floor(Math.log10(r)),a=r/10**s,n=(Math.floor(a+1e-12)<5?1:10)*10**s;return n>=1?.01:n}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);const i=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(i);if(!r.ok)return null;const s=await r.json();if(!Array.isArray(s)||s.length===0)return null;const a=s[0];return this._profileCache.set(e,a),a}async _resolveSessionInfo(e){try{const i=await this._fetchProfile(e);if(i){const r=i.exchange||"",s=this._isCrypto(e),a=s?"Etc/UTC":Xr[r]||"America/New_York";return{session:s?"24x7":Qr[r]||"0930-1600",timezone:a}}}catch{}return{session:"0930-1600",timezone:"America/New_York"}}_msToDateStr(e){return new Date(e).toISOString().split("T")[0]}_dateStrToMs(e){return new Date(e+"T00:00:00Z").getTime()}_dateTimeStrToMs(e){return new Date(e.replace(" ","T")+"Z").getTime()}_isForex(e){return/^[A-Z]{6}$/.test(e)&&Gr.has(e.slice(0,3))&&Gr.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}}var Md=Object.defineProperty,Rd=(t,e,i)=>e in t?Md(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ft=(t,e,i)=>Rd(t,typeof e!="symbol"?e+"":e,i);const Od="https://data.alpaca.markets",Vd="https://paper-api.alpaca.markets/v2",Ld="https://api.alpaca.markets/v2",Ri=1e4,Zr={1:"1Min",3:"3Min",5:"5Min",15:"15Min",30:"30Min",60:"1Hour",120:"2Hour",240:"4Hour","4H":"4Hour","1D":"1Day",D:"1Day","1W":"1Week",W:"1Week","1M":"1Month",M:"1Month"},$d={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",ARCA:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",CRYPTO:"Etc/UTC"},jd={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},Bd={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"};class Fd extends Si{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),ft(this,"_apiKey",null),ft(this,"_apiSecret",null),ft(this,"_dataUrl",Od),ft(this,"_tradingUrl",Vd),ft(this,"_feed",null),ft(this,"_assetCache",new Map),ft(this,"_calendarCache",new Map),e?.apiKey&&e?.apiSecret&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,this._apiSecret=e.apiSecret,e.feed&&(this._feed=e.feed),e.dataUrl&&(this._dataUrl=e.dataUrl),e.tradingUrl?this._tradingUrl=e.tradingUrl:e.paper===!1&&(this._tradingUrl=Ld)}_headers(){return{"APCA-API-KEY-ID":this._apiKey,"APCA-API-SECRET-KEY":this._apiSecret}}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,s,a){this.ensureConfigured();try{const n=this._resolveTimeframe(i);if(!n)return console.error(`Alpaca: Unsupported timeframe: ${i}`),[];const o=this._isCrypto(e),l=await this._fetchAllBars(e,n,o,s,a,r);if(l.length===0)return[];const{periodType:c,multiplier:h}=this._parseAlpacaTimeframe(n);if(o)return this._convertBarsCrypto(l,c,h);const p=l[0].t.slice(0,10),u=l[l.length-1].t.slice(0,10),f=this._addDaysToDate(u,40);return await this._ensureCalendar(p,f),this._convertBarsStock(l,c,h)}catch(n){return console.error("Error in AlpacaProvider.getMarketData:",n),[]}}async _fetchAllBars(e,i,r,s,a,n){const o=[];let l=null;const c=n||1/0,h=Math.min(n||Ri,Ri);do{const p=this._buildBarsUrl(e,i,r,s,a,h,l),u=await fetch(p,{headers:this._headers()});if(!u.ok){const x=await u.text();throw new Error(`Alpaca HTTP ${u.status}: ${x}`)}const f=await u.json(),m=Object.keys(f.bars||{})[0];if(!m||!f.bars[m]||(o.push(...f.bars[m]),l=f.next_page_token,o.length>=c))break}while(l);return n&&n>0&&o.length>n?o.slice(0,n):o}_buildBarsUrl(e,i,r,s,a,n,o){const l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",i),c.set("sort","asc"),s&&c.set("start",new Date(s).toISOString()),a&&c.set("end",new Date(a).toISOString()),n&&c.set("limit",String(Math.min(n,Ri))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchAsset(e);if(!i)return console.error(`Alpaca: Symbol ${e} not found`),null;const r=i.exchange||"",s=i.class==="crypto",a=s?"Etc/UTC":$d[r]||"America/New_York",n=s?"24x7":jd[r]||"0930-1600";let o="stock";s&&(o="crypto");const l=s&&e.split("/")[1]||"USD",c=s?e.split("/")[0]||e:l,h=i.price_increment?parseFloat(i.price_increment):.01,p=Math.round(1/h);return{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:s?e.split("/")[0]:i.symbol,description:i.name||i.symbol,type:o,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:a,country:s?"":"US",mintick:h,pricescale:p,minmove:1,pointvalue:1,mincontract:i.min_order_size?parseFloat(i.min_order_size):0,session:n,volumetype:"base",expiration_date: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 AlpacaProvider.getSymbolInfo:",i),null}}_convertBarsCrypto(e,i,r){return e.map((s,a,n)=>{const o=new Date(s.t).getTime(),l=a<n.length-1?new Date(n[a+1].t).getTime():Kt(o,i,r);return this._toKline(s,o,l)})}_convertBarsStock(e,i,r){const s="America/New_York";return e.map(a=>{const n=new Date(a.t).getTime(),o=a.t.slice(0,10);let l;if(i==="day"){const c=this._calendarCache.get(o),h=c?c.close:"16:00";l=qe(o,h,s)}else if(i==="minute"||i==="hour"){const c=n+r*{minute:6e4,hour:36e5}[i],h=this._calendarCache.get(o),p=h?h.close:"16:00",u=qe(o,p,s);l=Math.min(c,u)}else i==="week"?l=this._weeklyCloseFromCalendar(o,s):i==="month"?l=this._monthlyCloseFromCalendar(o,s):l=Kt(n,i,r);return this._toKline(a,n,l)})}_toKline(e,i,r){return{openTime:i,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:r,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,i){const r=new Date(e+"T00:00:00Z"),s=r.getUTCDay(),a=s<=5?5-s:5-s+7;for(let l=a;l>=0;l--){const c=r.getTime()+l*864e5,h=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(h);if(p)return qe(h,p.close,i)}const n=r.getTime()+a*864e5,o=new Date(n).toISOString().split("T")[0];return qe(o,"16:00",i)}_monthlyCloseFromCalendar(e,i){const[r,s]=e.split("-").map(Number),a=new Date(Date.UTC(r,s,0)).getUTCDate();for(let o=a;o>=1;o--){const l=`${r}-${String(s).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return qe(l,c.close,i)}const n=new Date(Date.UTC(r,s,0));for(;n.getUTCDay()===0||n.getUTCDay()===6;)n.setUTCDate(n.getUTCDate()-1);return qe(n.toISOString().split("T")[0],"16:00",i)}async _ensureCalendar(e,i){if(this._calendarCache.has(e)&&this._calendarCache.has(i))return;const r=`${this._tradingUrl}/calendar?start=${e}&end=${i}`,s=await fetch(r,{headers:this._headers()});if(!s.ok){console.warn(`Alpaca calendar API returned ${s.status}, falling back to defaults`);return}const a=await s.json();for(const n of a)this._calendarCache.set(n.date,n)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);const i=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${i}`,s=await fetch(r,{headers:this._headers()});if(!s.ok)return null;const a=await s.json();return this._assetCache.set(e,a),a}_parseAlpacaTimeframe(e){const i=e.match(/^(\d+)(Min|Hour|Day|Week|Month)$/);if(i){const r=parseInt(i[1],10),s=Bd[i[2]];if(s)return{periodType:s,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Zr[e.toUpperCase()]||Zr[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,i){const r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+i),r.toISOString().split("T")[0]}}var Wd=Object.defineProperty,Ud=(t,e,i)=>e in t?Wd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Oi=(t,e,i)=>Ud(t,typeof e!="symbol"?e+"":e,i);const qd=gn(import.meta.url),Kd=Bt.dirname(qd);class zd extends Si{constructor(e){super({requiresApiKey:!1,providerName:"Mock"}),Oi(this,"dataCache",new Map),Oi(this,"exchangeInfoCache",{}),Oi(this,"dataDirectory");const i=typeof e=="string"?e:e?.dataDirectory;if(i)this.dataDirectory=i;else{const r=Bt.resolve(Kd,"../../../");this.dataDirectory=Bt.join(r,"tests","compatibility","_data")}}configure(e){super.configure(e),e.dataDirectory&&(this.dataDirectory=e.dataDirectory)}getDataFileName(e,i,r,s){return r&&s?`${e}-${i}-${r}-${s}.json`:null}loadDataFromFile(e){const i=`file:${e}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=Bt.join(this.dataDirectory,e);if(!wt.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const s=wt.readFileSync(r,"utf-8"),a=JSON.parse(s);return this.dataCache.set(i,a),a}findDataFile(e,i,r,s){if(!wt.existsSync(this.dataDirectory))return null;const a=wt.readdirSync(this.dataDirectory).filter(l=>l.endsWith(".json"));if(r&&s){const l=`${e}-${i}-${r}-${s}.json`;if(a.includes(l))return l}const n=new RegExp(`^${e}-${i}-(\\d+)-(\\d+)\\.json$`),o=a.filter(l=>n.test(l)).map(l=>{const c=l.match(n);return{file:l,startTime:parseInt(c[1]),endTime:parseInt(c[2])}}).sort((l,c)=>c.endTime-l.endTime);if(o.length===0)return null;if(r&&s){const l=o.find(c=>c.startTime<=r&&c.endTime>=s);if(l)return l.file}return o[0].file}filterData(e,i,r,s){let a=e;return(i||r)&&(a=e.filter(n=>{const o=!i||n.openTime>=i,l=!r||n.openTime<=r;return o&&l})),a.sort((n,o)=>n.openTime-o.openTime),s&&s>0&&(a=a.slice(0,s)),a}normalizeTimeframe(e){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[e.toUpperCase()]||e.toLowerCase()}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,s,a){try{const n=this.normalizeTimeframe(i),o=this.findDataFile(e,n,s,a);if(!o)return console.warn(`No mock data file found for ${e} ${n}. Searched in: ${this.dataDirectory}`),[];const l=this.loadDataFromFile(o),c=this.filterData(l,s,a,r);return this.normalizeCloseTime(c),c}catch(n){return console.error("Error in MockProvider.getMarketData:",n),[]}}loadExchangeInfo(e){if(this.exchangeInfoCache[e])return this.exchangeInfoCache[e];const i=e==="spot"?"api-exchangeInfo.json":"fapi-exchangeInfo.json",r=Bt.join(this.dataDirectory,i);if(!wt.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const s=wt.readFileSync(r,"utf-8"),a=JSON.parse(s);return this.exchangeInfoCache[e]=a,a}catch(s){return console.error(`Error loading exchange info from ${i}:`,s),null}}async getSymbolInfo(e){try{let i="crypto",r=e,s="";e.endsWith(".P")?(i="futures",r=e.replace(".P",""),s="Perpetual"):e.includes("_")&&(i="futures",r=e,s="Delivery");const a=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!a||!a.symbols)return console.error(`Exchange info not available for ${i}`),null;const n=a.symbols.find(_=>_.symbol===r);if(!n)return console.error(`Symbol ${r} not found in ${i} exchange info`),null;const o=n.filters?.find(_=>_.filterType==="PRICE_FILTER"),l=n.filters?.find(_=>_.filterType==="LOT_SIZE"),c=o?parseFloat(o.tickSize):.01,h=l?parseFloat(l.minQty):0,p=Math.round(1/c),u=n.baseAsset,f=n.quoteAsset,m=s?` ${s}`:"",x=`${u} / ${f}${m}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:u,description:x,type:i,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:u,currency:f,timezone:"Etc/UTC",country:"",mintick:c,pricescale:p,minmove:1,pointvalue:n.contractSize||1,mincontract:h,session:"24x7",volumetype:"base",expiration_date:n.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(e){this.dataDirectory=e,this.clearCache()}}const Hd=typeof process<"u"&&process.versions&&process.versions.node;let gi=null;if(Hd)try{gi=new zd}catch{gi=null}const Jd={Binance:new Id,FMP:new Dd,Alpaca:new Fd,...gi?{Mock:gi}:{}};var Gd=Object.defineProperty,Yd=(t,e,i)=>e in t?Gd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Xd=(t,e,i)=>Yd(t,typeof e!="symbol"?e+"":e,i);class em extends Error{constructor(e,i){super(e),Xd(this,"method"),this.name="PineRuntimeError",this.method=i}}export{Fd as AlpacaProvider,Si as BaseProvider,Id as BinanceProvider,Br as Context,Dd as FMPProvider,Wr as Indicator,em as PineRuntimeError,dn as PineTS,Jd as Provider,Zd as TIMEFRAME_PERIOD_INFO,qt as TIMEFRAME_SECONDS,md as aggregateCandles,Kt as computeNextPeriodStart,Kr as computeSessionClose,mn as getAggregationRatio,qe as localTimeToUTC,dd as selectSubTimeframe};
|
|
121
|
+
`,e+="["+this.matrix[i].join(", ")+"]";return e}add_col(...e){return this._add_col(this,...e)}add_row(...e){return this._add_row(this,...e)}avg(...e){return this._avg(this,...e)}col(...e){return this._col(this,...e)}columns(...e){return this._columns(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}det(...e){return this._det(this,...e)}diff(...e){return this._diff(this,...e)}eigenvalues(...e){return this._eigenvalues(this,...e)}eigenvectors(...e){return this._eigenvectors(this,...e)}elements_count(...e){return this._elements_count(this,...e)}fill(...e){return this._fill(this,...e)}get(...e){return this._get(this,...e)}inv(...e){return this._inv(this,...e)}is_antidiagonal(...e){return this._is_antidiagonal(this,...e)}is_antisymmetric(...e){return this._is_antisymmetric(this,...e)}is_binary(...e){return this._is_binary(this,...e)}is_diagonal(...e){return this._is_diagonal(this,...e)}is_identity(...e){return this._is_identity(this,...e)}is_square(...e){return this._is_square(this,...e)}is_stochastic(...e){return this._is_stochastic(this,...e)}is_symmetric(...e){return this._is_symmetric(this,...e)}is_triangular(...e){return this._is_triangular(this,...e)}is_zero(...e){return this._is_zero(this,...e)}kron(...e){return this._kron(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}mult(...e){return this._mult(this,...e)}pinv(...e){return this._pinv(this,...e)}pow(...e){return this._pow(this,...e)}rank(...e){return this._rank(this,...e)}remove_col(...e){return this._remove_col(this,...e)}remove_row(...e){return this._remove_row(this,...e)}reshape(...e){return this._reshape(this,...e)}reverse(...e){return this._reverse(this,...e)}row(...e){return this._row(this,...e)}rows(...e){return this._rows(this,...e)}set(...e){return this._set(this,...e)}sort(...e){return this._sort(this,...e)}submatrix(...e){return this._submatrix(this,...e)}sum(...e){return this._sum(this,...e)}swap_columns(...e){return this._swap_columns(this,...e)}swap_rows(...e){return this._swap_rows(this,...e)}trace(...e){return this._trace(this,...e)}transpose(...e){return this._transpose(this,...e)}}function $e(t){return(e,i,r)=>new K(e,i,r,t)}function Tc(t){return(e,i=0)=>g.from(e).get(i)}class Pc{constructor(e){this.context=e,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=$e(e),this.param=Tc(),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),this.new_float=$e(e),this.new_int=$e(e),this.new_string=$e(e),this.new_bool=$e(e),this.new_color=$e(e),this.new_line=$e(e),this.new_label=$e(e),this.new_box=$e(e),this.new_linefill=$e(e),this.new_table=$e(e)}}var Dc=Object.defineProperty,Mc=(t,e,i)=>e in t?Dc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Rc=(t,e,i)=>Mc(t,typeof e!="symbol"?e+"":e,i);class Oc{constructor(e){this.context=e,Rc(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){const e=this.context.idx,i=this.context.length;if(e===i-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===i-2){const r=this.context.marketData?.[i-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}}class kt{constructor(e,i){this._definition=e,this.context=i;for(let r in e)this[r]=e[r]}get __def__(){return this._definition}copy(){return new kt(this.__def__,this.context)}toString(){const e={};for(let i in this.__def__){const r=this[i];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[i]=r.toString():e[i]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(i=>`"${i}":${String(e[i])}`).join(",")+"}"}}}var Vc=Object.defineProperty,Lc=(t,e,i)=>e in t?Vc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Pi=(t,e,i)=>Lc(t,typeof e!="symbol"?e+"":e,i);class me{constructor(e,i,r){Pi(this,"time"),Pi(this,"index"),Pi(this,"price"),this.time=e,this.index=i,this.price=r}copy(){return new me(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}}function $c(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}const Mr={series:t=>t instanceof g||typeof t=="number"||typeof t=="string"||typeof t=="boolean",string:t=>typeof t=="string",color:t=>typeof t=="string"||t===null||typeof t=="number"&&isNaN(t)||t instanceof g,number:t=>typeof t=="number",boolean:t=>typeof t=="boolean",array:t=>Array.isArray(t),object:t=>typeof t=="object",point:t=>t instanceof me,primitive:t=>typeof t===null||typeof t!="object"&&typeof t!="function",function:t=>typeof t=="function",undefined:t=>t===void 0,null:t=>t===null,NaN:t=>isNaN(t),remaining_options:t=>t!==null&&typeof t=="object"&&!(t instanceof g)&&!(t instanceof me)&&!$c(t)};function Ue(t){const e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function se(t,e,i,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);const s={};let a={};const n=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){const l=t[o];if(Mr.remaining_options(l)){a=l;break}const c=e.map((h,p)=>n[p]?h[o]:void 0);for(let h=0;h<c.length;h++){const p=c[h];if(p===void 0){n[h]=!1;continue}const u=i[p];if(typeof l=="number"&&isNaN(l)&&(u==="number"||u==="series"))s[p]=l;else{const f=Mr[i[p]];typeof f=="function"&&f(l)?s[p]=l:n[h]=!1}}}return{...s,...a,...r}}var jc=Object.defineProperty,Bc=(t,e,i)=>e in t?jc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,At=(t,e,i)=>Bc(t,typeof e!="symbol"?e+"":e,i);const Fc=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Wc={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Uc=["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"],qc={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 Kc(t){return se(t,Uc,qc)}class Vt{get __value(){return NaN}param(e,i=0){return g.from(e).get(i)}any(e){const i=g.from(e).get(0);return i==null?!0:typeof i=="number"?i!==i:!1}}const Et={freq_all:"alert.freq_all",freq_once_per_bar:"alert.freq_once_per_bar",freq_once_per_bar_close:"alert.freq_once_per_bar_close"};class zc{constructor(e){this.context=e,At(this,"_firedKeys",new Set),At(this,"_fallbackCounter",0),At(this,"_fallbackLastExecTick",-1)}get freq_all(){return Et.freq_all}get freq_once_per_bar(){return Et.freq_once_per_bar}get freq_once_per_bar_close(){return Et.freq_once_per_bar_close}param(e,i,r){return g.from(e).get(0)}any(e,i,r){const s=g.from(e).get(0),a=i?g.from(i).get(0):Et.freq_once_per_bar;let n;if(r&&typeof r=="object"&&r.__callsiteId)n=r.__callsiteId;else{const h=this.context._execTick||0;h!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=h),n=`alert_${this._fallbackCounter++}`}const o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${n}:${o}`;if(a===Et.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(a===Et.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(c))return;this._firedKeys.add(c)}this.context.alerts.push({type:"alert",id:n,message:s,freq:a,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}}class Hc{constructor(e){this.context=e,At(this,"_acCounter",0),At(this,"_acLastExecTick",-1),At(this,"_acFiredKeys",new Set)}extractPlotOptions(e){const i={};for(let r in e)i[r]=g.from(e[r]).get(0);return i}indicator(...e){const i=Kc(e),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(e){const i=g.from(e).get(0);return i==null||typeof i=="number"&&isNaN(i)}nz(e,i=0){const r=g.from(e).get(0),s=g.from(i).get(0);return r==null||typeof r=="number"&&isNaN(r)?s:r}fixnan(e){const i=g.from(e);for(let r=0;r<i.length;r++){const s=i.get(r);if(!isNaN(s))return s}return NaN}alertcondition(e,i,r){const s=g.from(e).get(0),a=this.context.idx,n=this.context._execTick||0;n!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=n);const o=`alertcondition_${this._acCounter++}`;if(!s)return;const l=this.context.pine?.barstate?.isrealtime??a===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${o}:${a}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);const h=i?g.from(i).get(0):"",p=r?g.from(r).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:h,message:p,bar_index:a,time:this.context.data.openTime?.data?.[a]??0})}error(...e){console.error("error called but is currently not implemented",e)}max_bars_back(e,i){}timestamp(...e){const i=e.map(s=>s instanceof g?s.get(0):s),r=se(i,Fc,Wc);if(r.year!==void 0){const s=r.year,a=r.month,n=r.day,o=r.hour||0,l=r.minute||0,c=r.second||0,h=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(h,s,a,n,o,l,c)}if(r.dateString!==void 0){const s=r.dateString.trim();if(/[Zz]$/.test(s)||/[+-]\d{2}:?\d{2}$/.test(s))return new Date(s).getTime();const a=s.includes("T")?s+"Z":s.replace(/\s+/,"T")+"Z",n=new Date(a);if(!isNaN(n.getTime())){const o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,n.getUTCFullYear(),n.getUTCMonth()+1,n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds())}return new Date(s).getTime()}return NaN}_timestampFromComponents(e,i,r,s,a,n,o){const l=new Date(Date.UTC(i,r-1,s,a,n,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();const h=c.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(h){const p=h[1]==="+"?1:-1,u=parseInt(h[2],10),f=parseInt(h[3]||"0",10),m=p*(u*60+f)*60*1e3;return l.getTime()-m}try{return this._timestampFromIANA(e,i,r,s,a,n,o)}catch{return l.getTime()}}_timestampFromIANA(e,i,r,s,a,n,o){const l=new Date(Date.UTC(i,r-1,s,a,n,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),h=v=>parseInt(c.find(E=>E.type===v)?.value||"0",10),p=h("year"),u=h("month"),f=h("day");let m=h("hour");m===24&&(m=0);const x=h("minute"),_=h("second"),b=new Date(Date.UTC(p,u-1,f,m,x,_));p>=0&&p<100&&b.setUTCFullYear(p);const w=b.getTime()-l.getTime();return l.getTime()-w}bool(e){const i=g.from(e).get(0);return!isNaN(i)&&i!==0}int(e){const i=g.from(e).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.trunc(i)}float(e){const i=g.from(e).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(e){return g.from(e).get(0).toString()}Type(e){const i=Object.keys(e),r={};for(const s of i){let a=e[s];a instanceof g&&(a=a.data),Array.isArray(a)&&(a[0],r[s]=a[1])}return{new:function(...s){const a={};let n=null;if(s.length===1&&s[0]&&typeof s[0]=="object"&&!(s[0]instanceof g)&&!Array.isArray(s[0])&&!(s[0]instanceof kt)){const o=Object.keys(s[0]);o.length>0&&o.some(l=>i.includes(l))&&(n=s[0],s=[])}for(let o=0;o<i.length;o++){const l=i[o];n&&l in n?a[l]=n[l]:o<s.length?a[l]=s[o]:l in r&&(a[l]=g.from(r[l]).get(0))}return new kt(a,this.context)},copy:function(s){return new kt(s.__def__,this.context)}}}}function Nt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){const i=t.slice(1);return i.length===6?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),1]:i.length===8?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),parseInt(i.slice(6,8),16)/255]:null}const e=t.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function Gc(t,e,i,r){const s=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),n=Math.round(Math.max(0,Math.min(255,i))).toString(16).padStart(2,"0");if(r>=1)return`#${s}${a}${n}`.toUpperCase();const o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${s}${a}${n}${o}`.toUpperCase()}const re={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function We(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}class Yc{constructor(e){this.context=e}any(e){const i=g.from(e).get(0);return typeof i=="number"&&isNaN(i)?null:i}param(e,i=0){return g.from(e).get(i)}new(e,i){if(e=We(e),!e||typeof e!="string")return e;if(typeof i=="number"&&isNaN(i)&&(i=void 0),e.startsWith("#")){const r=e.slice(1),s=r.length===8?r.slice(0,6):r;return i!=null?`#${s}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:`#${r}`}else{const r=re[e];if(r)return i!=null?`#${r.slice(1)}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:r;const s=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);if(s){const a=s[1],n=s[2],o=s[3];if(i!=null){const l=parseInt(a).toString(16).padStart(2,"0"),c=parseInt(n).toString(16).padStart(2,"0"),h=parseInt(o).toString(16).padStart(2,"0"),p=Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${h}${p}`}return e}return i!=null?`rgba(${e}, ${(100-i)/100})`:e}}rgb(e,i,r,s){return typeof s=="number"&&isNaN(s)&&(s=void 0),s!=null?`rgba(${e}, ${i}, ${r}, ${(100-s)/100})`:`rgb(${e}, ${i}, ${r})`}from_gradient(e,i,r,s,a){if(e=We(e),i=We(i),r=We(r),s=We(s),a=We(a),e==null||typeof e=="number"&&isNaN(e)||i==null||typeof i=="number"&&isNaN(i)||r==null||typeof r=="number"&&isNaN(r)||s==null||typeof s=="number"&&isNaN(s)||a==null||typeof a=="number"&&isNaN(a))return;let n=0;r!==i&&(n=(e-i)/(r-i)),n=Math.max(0,Math.min(1,n));const o=Nt(typeof s=="string"?s:"#000000")||[0,0,0,1],l=Nt(typeof a=="string"?a:"#FFFFFF")||[255,255,255,1],c=o[0]+(l[0]-o[0])*n,h=o[1]+(l[1]-o[1])*n,p=o[2]+(l[2]-o[2])*n,u=o[3]+(l[3]-o[3])*n;return Gc(c,h,p,u)}r(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?i[0]:NaN}g(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?i[1]:NaN}b(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?i[2]:NaN}t(e){if(e=We(e),!e||typeof e!="string")return NaN;const i=Nt(e);return i?Math.round(100-i[3]*100):NaN}aqua(){return re.aqua}black(){return re.black}blue(){return re.blue}fuchsia(){return re.fuchsia}gray(){return re.gray}green(){return re.green}lime(){return re.lime}maroon(){return re.maroon}navy(){return re.navy}olive(){return re.olive}orange(){return re.orange}purple(){return re.purple}red(){return re.red}silver(){return re.silver}teal(){return re.teal}white(){return re.white}yellow(){return re.yellow}}var Xc=Object.defineProperty,Qc=(t,e,i)=>e in t?Xc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,pi=(t,e,i)=>Qc(t,typeof e!="symbol"?e+"":e,i);function zi(t){if(!t)return"";const e=t.trim().toUpperCase();return e==="1D"||e==="D"?"D":e==="1W"||e==="W"?"W":e==="1M"||e==="M"?"M":e}function Hi(t,e){const i=Zc(e);if(e==="M"){const o=new Date(t);return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),1)}if(e==="W"){const o=new Date(t),l=o.getUTCDay(),c=l===0?6:l-1;return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate()-c)}if(e==="D"||i>=1440)return Math.floor(t/864e5)*864e5;const r=i*6e4,s=Math.floor(t/864e5)*864e5,a=t-s,n=Math.floor(a/r)*r;return s+n}function Zc(t){if(t==="D")return 1440;if(t==="W")return 10080;if(t==="M")return 43200;const e=parseInt(t,10);return isNaN(e)?1440:e}function Pt(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC"){const s=new Date(t);return{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate(),hour:s.getUTCHours(),minute:s.getUTCMinutes(),second:s.getUTCSeconds(),dayOfWeek:s.getUTCDay()}}const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const s=r[1]==="+"?1:-1,a=parseInt(r[2],10),n=parseInt(r[3]||"0",10),o=s*(a*60+n)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{const s=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),a=c=>parseInt(s.find(h=>h.type===c)?.value||"0",10);let n=a("hour");n===24&&(n=0);const o=s.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:a("year"),month:a("month"),day:a("day"),hour:n,minute:a("minute"),second:a("second"),dayOfWeek:l[o]??0}}catch{const s=new Date(t);return{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate(),hour:s.getUTCHours(),minute:s.getUTCMinutes(),second:s.getUTCSeconds(),dayOfWeek:s.getUTCDay()}}}function Jc(t,e,i){const r=new Date(Date.UTC(t,e-1,i)),s=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-s);const a=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-a.getTime())/864e5+1)/7)}const eh=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],th={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"};class Rr{constructor(e,i="openTime"){pi(this,"context"),pi(this,"dataField"),this.context=e,this.dataField=i}get __value(){return this.context.data[this.dataField]}param(e,i=0){return g.from(e).get(i)}any(...e){const i=e.map(u=>u instanceof g?u.get(0):u),r=se(i,eh,th),s=r.bars_back??0,a=r.timeframe||"",n=this.context.data[this.dataField],o=g.from(n).get(s);if(isNaN(o)||o==null)return NaN;const l=this.context.timeframe||"",c=zi(a),h=zi(l);let p;if(!c||c===h?p=o:p=Hi(o,c),r.session!==void 0&&r.session!==""){const u=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(p,r.session,u)?p:NaN}return p}_isInSession(e,i,r){const s=i.match(/^(\d{2})(\d{2})-(\d{2})(\d{2})$/);if(!s)return!0;const a=parseInt(s[1],10),n=parseInt(s[2],10),o=parseInt(s[3],10),l=parseInt(s[4],10),c=Pt(e,r),h=c.hour,p=c.minute,u=h*60+p,f=a*60+n,m=o*60+l;return f<=m?u>=f&&u<m:u>=f||u<m}}const ih=[[],["time"],["time","timezone"]],rh={time:"number",timezone:"string"};class nt{constructor(e,i){pi(this,"context"),pi(this,"extractor"),this.context=e,this.extractor=i}get __value(){const e=g.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;const i=this.context.pine?.syminfo?.timezone||"UTC",r=Pt(e,i);return this.extractor(r)}param(e,i=0){return g.from(e).get(i)}any(...e){const i=e.map(o=>o instanceof g?o.get(0):o);if(i.length===0)return this.__value;const r=se(i,ih,rh),s=r.time;if(s===void 0||isNaN(s))return NaN;const a=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",n=Pt(s,a);return this.extractor(n)}}const at={dayofmonth:t=>t.day,dayofweek:t=>t.dayOfWeek===0?1:t.dayOfWeek+1,hour:t=>t.hour,minute:t=>t.minute,month:t=>t.month,second:t=>t.second,weekofyear:t=>Jc(t.year,t.month,t.day),year:t=>t.year},sh=[["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"]],nh={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function we(t){return se(t,sh,nh)}function Ne(t,e){return e.title&&t.inputs&&t.inputs[e.title]!==void 0?t.inputs[e.title]:e.defval}function ah(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function oh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function lh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function ch(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function hh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function uh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function ph(t){return(e,i=0)=>g.from(e).get(i)}function fh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function dh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function mh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function gh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function yh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function xh(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function _h(t){return(...e)=>{const i=we(e);return Ne(t,i)}}function bh(t){return(...e)=>we(e).defval}var vh=Object.defineProperty,wh=(t,e,i)=>e in t?vh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,de=(t,e,i)=>wh(t,typeof e!="symbol"?e+"":e,i);const Sh={any:ah,bool:oh,color:lh,enum:ch,float:hh,int:uh,param:ph,price:fh,session:dh,source:mh,string:gh,symbol:yh,text_area:xh,time:_h,timeframe:bh};class Eh{constructor(e){this.context=e,de(this,"any"),de(this,"bool"),de(this,"color"),de(this,"enum"),de(this,"float"),de(this,"int"),de(this,"param"),de(this,"price"),de(this,"session"),de(this,"source"),de(this,"string"),de(this,"symbol"),de(this,"text_area"),de(this,"time"),de(this,"timeframe"),Object.entries(Sh).forEach(([i,r])=>{this[i]=r(e)})}}function Nh(t){return e=>Math.abs(g.from(e).get(0))}function Ch(t){return e=>Math.acos(g.from(e).get(0))}function Ih(t){return e=>Math.asin(g.from(e).get(0))}function kh(t){return e=>Math.atan(g.from(e).get(0))}function Ah(t){return(...e)=>{const i=e.map(r=>g.from(r).get(0));return i.reduce((r,s)=>r+s,0)/i.length}}function Th(t){return e=>Math.ceil(g.from(e).get(0))}function Ph(t){return e=>Math.cos(g.from(e).get(0))}function Dh(t){return()=>Math.E}function Mh(t){return e=>Math.exp(g.from(e).get(0))}function Rh(t){return e=>Math.floor(g.from(e).get(0))}function Oh(t){return e=>Math.log(g.from(e).get(0))}function Vh(t){return e=>Math.log(g.from(e).get(0))}function Lh(t){return e=>Math.log10(g.from(e).get(0))}function $h(t){return(...e)=>{const i=e.map(r=>g.from(r).get(0));return Math.max(...i)}}function jh(t){return(...e)=>{const i=e.map(r=>g.from(r).get(0));return Math.min(...i)}}function Bh(t){return(e,i,r)=>typeof e=="string"?e:e instanceof g?i?new g(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new g(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new g(t.params[r],i||0)))}function Fh(t){return()=>1.618033988749895}function Wh(t){return()=>Math.PI}function Uh(t){return(e,i)=>Math.pow(g.from(e).get(0),g.from(i).get(0))}function qh(t){return()=>Math.random()}function Di(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function Kh(t){return(e,i)=>{const r=g.from(e).get(0);if(i==null)return Di(r);const s=g.from(i).get(0);if(s===0)return Di(r);const a=Math.pow(10,s);return Di(r*a)/a}}function zh(t){return e=>t.precision(Math.round(g.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Hh(t){return()=>.6180339887498948}function Gh(t){return e=>Math.sign(g.from(e).get(0))}function Yh(t){return e=>Math.sin(g.from(e).get(0))}function Xh(t){return e=>Math.sqrt(g.from(e).get(0))}function Qh(t){return(e,i)=>{const r=g.from(i).get(0),s=g.from(e);let a=0;for(let n=0;n<r;n++){const o=s.get(n);a+=o}return a}}function Zh(t){return e=>Math.tan(g.from(e).get(0))}function Jh(t){return e=>{const i=g.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(180/Math.PI)}}function eu(t){return e=>{const i=g.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(Math.PI/180)}}function tu(t){return(e,i)=>{const r=g.from(e).get(0),s=g.from(i).get(0);return typeof r=="number"&&typeof s=="number"?isNaN(r)||isNaN(s)?!1:Math.abs(r-s)<1e-9:r===s}}function iu(t){return(e,i)=>{const r=g.from(e).get(0),s=g.from(i).get(0);return typeof r=="number"&&typeof s=="number"?isNaN(r)||isNaN(s)?!1:Math.abs(r-s)>=1e-9:r!==s}}var ru=Object.defineProperty,su=(t,e,i)=>e in t?ru(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,W=(t,e,i)=>su(t,typeof e!="symbol"?e+"":e,i);const nu={abs:Nh,acos:Ch,asin:Ih,atan:kh,avg:Ah,ceil:Th,cos:Ph,e:Dh,exp:Mh,floor:Rh,ln:Oh,log:Vh,log10:Lh,max:$h,min:jh,param:Bh,phi:Fh,pi:Wh,pow:Uh,random:qh,round:Kh,round_to_mintick:zh,rphi:Hh,sign:Gh,sin:Yh,sqrt:Xh,sum:Qh,tan:Zh,todegrees:Jh,toradians:eu,__eq:tu,__neq:iu};class au{constructor(e){this.context=e,W(this,"_cache",{}),W(this,"abs"),W(this,"acos"),W(this,"asin"),W(this,"atan"),W(this,"avg"),W(this,"ceil"),W(this,"cos"),W(this,"e"),W(this,"exp"),W(this,"floor"),W(this,"ln"),W(this,"log"),W(this,"log10"),W(this,"max"),W(this,"min"),W(this,"param"),W(this,"phi"),W(this,"pi"),W(this,"pow"),W(this,"random"),W(this,"round"),W(this,"round_to_mintick"),W(this,"rphi"),W(this,"sign"),W(this,"sin"),W(this,"sqrt"),W(this,"sum"),W(this,"tan"),W(this,"todegrees"),W(this,"toradians"),W(this,"__eq"),W(this,"__neq"),Object.entries(nu).forEach(([i,r])=>{this[i]=r(e)})}}function ou(t){return(e,i,r)=>{t.params[r]||(t.params[r]=[]);let s;if(e instanceof g)s=e.get(i||0);else if(Array.isArray(e)){const a=e.some(o=>o instanceof g),n=e.every(o=>!(o instanceof g)&&!Array.isArray(o));(a||n)&&e.length>=1?s=e.map(o=>o instanceof g?o.get(0):o):s=g.from(e).get(i||0)}else s=e;return t.params[r].length===0?t.params[r].push(s):t.params[r][t.params[r].length-1]=s,[s,r]}}const Dt=["1","3","5","15","30","45","60","120","180","240","D","W","M"],ei={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function fi(t){if(Dt.includes(t))return t;if(ei[t])return ei[t];const e=t.toLowerCase();if(ei[e])return ei[e];const i=t.toUpperCase();return Dt.includes(i)?i:t}function Or(t,e,i,r,s=!1,a=!1){for(let n=0;n<i.length;n++)if(i[n]<=t&&t<r[n])return s||a||e>=r[n]?n:n-1;return-1}function Vr(t,e,i,r,s=!1,a,n=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=e&&i[o]>=t){const l=a&&e>a;if(n&&s)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}if(l&&s&&!n)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}return o}if(r[o]<t)break}return-1}function Gi(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof g?t.get(0):Array.isArray(t)?t.map(Gi):t}function lu(t){return async(e,i,r,s=!1,a=!1,n=!1,o=null,l=null)=>{const c=e[0]instanceof g?e[0].get(0):e[0],h=c===""?t.tickerId:c,p=typeof h=="string"&&h.includes(":")?h.split(":")[1]:h,u=i[0]instanceof g?i[0].get(0):i[0],f=u===""?t.timeframe:typeof u=="string"?u:String(u??""),m=r[0],x=r[1],_=Array.isArray(s)?s[0]:s,b=Array.isArray(a)?a[0]:a,w=_===!0||_==="gaps_on",v=b===!0||b==="lookahead_on";if(t.isSecondaryContext){const Se=Gi(m);return Array.isArray(Se)?[Se]:Se}const E=Dt.indexOf(fi(t.timeframe)),T=Dt.indexOf(fi(f));if(E==-1||T==-1)throw new Error("Invalid timeframe");if(E===T){const Se=Gi(m);return Array.isArray(Se)?[Se]:Se}const C=E>T,O=g.from(t.data.openTime).get(0),B=g.from(t.data.closeTime).get(0),z=t.idx===t.length-1&&B>Date.now(),q=`${p}_${f}_${x}`,V=`${q}_prevIdx`;if(t.cache[q]){const Se=t.cache[q];t.dataVersion>Se.dataVersion&&(await Se.pineTS.updateTail(Se.context),Se.dataVersion=t.dataVersion);const Lt=Se.context,Xt=C?Vr(O,B,Lt.data.openTime.data,Lt.data.closeTime.data,v,t.eDate,w):Or(O,B,Lt.data.openTime.data,Lt.data.closeTime.data,v,z);if(Xt==-1)return NaN;const vt=Lt.params[x][Xt];if(!C&&w){const hr=t.cache[V];return hr!==void 0&&hr===Xt?NaN:(t.cache[V]=Xt,Array.isArray(vt)?[vt]:vt)}return Array.isArray(vt)?[vt]:vt}const Q=1e3*60*60*24*30,pe=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),Ce=pe?pe-Q:void 0,Ie=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,ke=t.eDate?Math.max(t.eDate,Ie):(Ie||Date.now())+Q,ut=new dn(t.source,p,f,void 0,Ce,ke);ut.markAsSecondary();const ce=await ut.run(t.pineTSCode);t.cache[q]={pineTS:ut,context:ce,dataVersion:t.dataVersion};const Ei=C?Vr(O,B,ce.data.openTime.data,ce.data.closeTime.data,v,t.eDate,w):Or(O,B,ce.data.openTime.data,ce.data.closeTime.data,v,z);if(Ei==-1)return NaN;const Ni=ce.params[x][Ei];return!C&&w?(t.cache[V]=Ei,NaN):Array.isArray(Ni)?[Ni]:Ni}}function Ct(t){return typeof t=="number"?D.float:typeof t=="boolean"?D.bool:typeof t=="string"?D.string:D.any}function cu(t){return async(e,i,r,s=!1,a=null,n=!1,o=0)=>{const l=e[0]instanceof g?e[0].get(0):e[0],c=l===""?t.tickerId:l,h=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,p=i[0]instanceof g?i[0].get(0):i[0],u=p===""?t.timeframe:typeof p=="string"?p:String(p??""),f=r[0],m=r[1];Array.isArray(s)&&s[0];const x=Array.isArray(n)?n[0]:n;if(t.isSecondaryContext)return Array.isArray(f)?[f.map(V=>new R([V],Ct(V),t))]:new R([f],Ct(f),t);const _=Dt.indexOf(fi(t.timeframe)),b=Dt.indexOf(fi(u));if(_===-1||b===-1){if(x)return NaN;throw new Error("Invalid timeframe")}if(b>_){if(x)return NaN;throw new Error(`Timeframe ${u} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(b===_)return Array.isArray(f)?[f.map(V=>new R([V],Ct(V),t))]:new R([f],Ct(f),t);const w=`${h}_${u}_${m}_lower`;if(!t.cache[w]){const V=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),Q=V?V-2592e6:void 0,pe=t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0,Ce=t.eDate?Math.max(t.eDate,pe):(pe||Date.now())+2592e6,Ie=new dn(t.source,h,u,void 0,Q,Ce);Ie.markAsSecondary();const ke=await Ie.run(t.pineTSCode);t.cache[w]={pineTS:Ie,context:ke,dataVersion:t.dataVersion}}const v=t.cache[w];t.dataVersion>v.dataVersion&&(await v.pineTS.updateTail(v.context),v.dataVersion=t.dataVersion);const E=v.context,T=g.from(t.data.openTime).get(0),C=g.from(t.data.closeTime).get(0),O=E.data.openTime.data,B=E.data.closeTime.data,z=E.params[m];if(!z)return Array.isArray(f)?[f.map(()=>new R([],D.float,t))]:new R([],D.float,t);const q=[];for(let V=0;V<O.length;V++){const Q=O[V];if(!(B[V]<=T)){if(Q>=C)break;Q>=T&&Q<C&&q.push(z[V])}}if(q.length>0&&Array.isArray(q[0])){const V=q[0].length,Q=[];for(let pe=0;pe<V;pe++){const Ce=q.map(ke=>ke[pe]),Ie=Ce.length>0?Ct(Ce[0]):D.float;Q.push(new R(Ce,Ie,t))}return[Q]}else{const V=q.length>0?Ct(q[0]):D.float;return new R(q,V,t)}}}var hu=Object.defineProperty,uu=(t,e,i)=>e in t?hu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ti=(t,e,i)=>uu(t,typeof e!="symbol"?e+"":e,i);const pu={param:ou,security:lu,security_lower_tf:cu};class fu{constructor(e){this.context=e,ti(this,"_cache",{}),ti(this,"param"),ti(this,"security"),ti(this,"security_lower_tf"),Object.entries(pu).forEach(([i,r])=>{this[i]=r(e)})}}function du(t){return e=>{t.taState||(t.taState={});const i=e||"accdist";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.high,0),n=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(s)||isNaN(a)||isNaN(n)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);const l=a-n;let c=0;l!==0&&(c=(s-n-(a-s))/l*o);const h=r.prevCumulativeSum+c;return r.currentCumulativeSum=h,t.precision(h)}}function mu(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0),l=g.from(s).get(0);t.taState||(t.taState={});const c=a||`alma_${n}_${o}_${l}`;if(!t.taState[c]){const x=o*(n-1),_=n/l,b=[];let w=0;for(let v=0;v<n;v++){const E=Math.exp(-Math.pow(v-x,2)/(2*_*_));b.push(E),w+=E}for(let v=0;v<b.length;v++)b[v]/=w;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevWindow=[...h.currentWindow],h.prevCallCount=h.currentCallCount),h.lastIdx=t.idx);const p=g.from(e).get(0),u=[...h.prevWindow];for(u.unshift(p);u.length>n;)u.pop();const f=h.prevCallCount+1;if(u.length<n&&(f>=n||t.idx>=n-1)){const x=g.from(e);for(;u.length<n;)u.push(x.get(u.length))}if(h.currentWindow=u,h.currentCallCount=f,u.length<n)return NaN;let m=0;for(let x=0;x<n;x++)m+=h.weights[x]*u[n-1-x];return t.precision(m)}}function gu(t){return(e,i)=>{const r=g.from(e).get(0);t.taState||(t.taState={});const s=i||`atr_${r}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevAtr=a.currentAtr,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);const n=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(n)||isNaN(o)||isNaN(l))return NaN;const c=t.idx>0?t.get(t.data.close,1):null;let h;if(c!==null&&!isNaN(c)){const x=n-o,_=Math.abs(n-c),b=Math.abs(o-c);h=Math.max(x,_,b)}else h=n-o;let p=a.prevInitCount,u=a.prevInitSum,f=a.prevAtr;if(p<r){if(u+=h,p++,a.currentInitSum=u,a.currentInitCount=p,p===r){const x=u/r;return a.currentAtr=x,t.precision(x)}return NaN}const m=(f*(r-1)+h)/r;return a.currentAtr=m,t.precision(m)}}function yu(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});const s=t.taState[r];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevLastTrueIndex=s.currentLastTrueIndex),s.lastIdx=t.idx);const a=g.from(e).get(0);let n=s.prevLastTrueIndex;return a&&(n=t.idx),s.currentLastTrueIndex=n,n===null?NaN:t.idx-n}}function xu(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`bb_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=g.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}if(h.length<a&&t.idx>=a-1){const b=g.from(e);for(;h.length<a;){const w=b.get(h.length);if(isNaN(w))break;h.push(w),p+=w}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return[[NaN,NaN,NaN]];const u=p/a;let f=0;for(let b=0;b<a;b++)f+=Math.pow(h[b]-u,2);const m=Math.sqrt(f/a),x=u+n*m,_=u-n*m;return[[t.precision(u),t.precision(x),t.precision(_)]]}}function _u(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`bbw_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=g.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const w=h.pop();p-=w}if(h.length<a&&t.idx>=a-1){const w=g.from(e);for(;h.length<a;){const v=w.get(h.length);if(isNaN(v))break;h.push(v),p+=v}}if(l.currentWindow=h,l.currentSum=p,h.length<a)return NaN;const u=p/a;let f=0;for(let w=0;w<a;w++){const v=h[w]-u;f+=v*v}const m=f/a,x=Math.sqrt(m),_=n*x;if(u===0)return t.precision(0);const b=2*_/u*100;return t.precision(b)}}function bu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`cci_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevSum=n.currentSum,n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0);if(isNaN(o))return NaN;const l=[...n.prevWindow];let c=n.prevSum;for(l.unshift(o),c+=o;l.length>s;){const x=l.pop();c-=x}const h=n.prevCallCount+1;if(l.length<s&&(h>=s||t.idx>=s-1)){const x=g.from(e);for(;l.length<s;){const _=x.get(l.length);if(isNaN(_))break;l.push(_),c+=_}}if(n.currentWindow=l,n.currentSum=c,n.currentCallCount=h,l.length<s)return NaN;const p=c/s;let u=0;for(let x=0;x<s;x++)u+=Math.abs(l[x]-p);const f=u/s;if(f===0)return 0;const m=(o-p)/(.015*f);return t.precision(m)}}function vu(t){return(e,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`change_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s+1;)l.pop();const c=n.prevCallCount+1;if(l.length<s+1&&(c>=s+1||t.idx>=s)){const p=g.from(e);for(;l.length<s+1;)l.push(p.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<=s)return NaN;const h=o-l[s];return t.precision(h)}}function wu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`cmo_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevGainsWindow=[...n.currentGainsWindow],n.prevLossesWindow=[...n.currentLossesWindow],n.prevGainsSum=n.currentGainsSum,n.prevLossesSum=n.currentLossesSum),n.lastIdx=t.idx);const o=g.from(e).get(0),l=g.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;const c=o-l,h=c>=0?c:0,p=c>=0?0:-c,u=[...n.prevGainsWindow],f=[...n.prevLossesWindow];let m=n.prevGainsSum,x=n.prevLossesSum;if(u.unshift(h),f.unshift(p),m+=h,x+=p,u.length<s)return n.currentGainsWindow=u,n.currentLossesWindow=f,n.currentGainsSum=m,n.currentLossesSum=x,NaN;if(u.length>s){const w=u.pop(),v=f.pop();m-=w,x-=v}n.currentGainsWindow=u,n.currentLossesWindow=f,n.currentGainsSum=m,n.currentLossesSum=x;const _=m+x;if(_===0)return t.precision(0);const b=100*(m-x)/_;return t.precision(b)}}function Su(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);let n=0,o=!1;for(let h=0;h<s;h++){const p=a.get(h);if(isNaN(p)){o=!0;break}n+=p}if(o)return NaN;let l=0;for(let h=0;h<s;h++){const p=a.get(h);l+=p*(h+1)}if(n===0)return NaN;const c=-l/n;return t.precision(c)}}function Eu(t){return(e,i,r,s)=>{const a=g.from(r).get(0),n=g.from(e),o=g.from(i);if(t.idx<a-1)return NaN;let l=0,c=0,h=0,p=0,u=0,f=0;for(let w=0;w<a;w++){const v=n.get(w),E=o.get(w);isNaN(v)||isNaN(E)||(l+=v,c+=E,h+=v*E,p+=v*v,u+=E*E,f++)}if(f<2)return NaN;const m=f*h-l*c,x=f*p-l*l,_=f*u-c*c;if(x<=0||_<=0)return t.precision(0);const b=m/Math.sqrt(x*_);return t.precision(b)}}function Nu(t){return(e,i,r)=>{const s=g.from(e),a=g.from(i),n=s.get(0),o=a.get(0),l=s.get(1),c=a.get(1);if(isNaN(n)||isNaN(o)||isNaN(l)||isNaN(c))return!1;const h=n>o&&l<=c,p=n<o&&l>=c;return h||p}}function Cu(t){return(e,i)=>{const r=g.from(e),s=g.from(i),a=r.get(0),n=s.get(0),o=r.get(1),l=s.get(1);return o<=l&&a>n}}function Iu(t){return(e,i)=>{const r=g.from(e),s=g.from(i),a=r.get(0),n=s.get(0),o=r.get(1),l=s.get(1);return o>=l&&a<n}}function ku(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const s=t.taState[r];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevCumulativeSum=s.currentCumulativeSum),s.lastIdx=t.idx);const a=g.from(e).get(0);if(isNaN(a))return s.currentCumulativeSum=s.prevCumulativeSum,t.precision(s.prevCumulativeSum);const n=s.prevCumulativeSum+a;return s.currentCumulativeSum=n,t.precision(n)}}function Au(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`dev_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevSum=n.currentSum,n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0)||0,l=[...n.prevWindow];let c=n.prevSum;for(l.unshift(o),c+=o;l.length>s;){const m=l.pop();c-=m}const h=n.prevCallCount+1;if(l.length<s&&(h>=s||t.idx>=s-1)){const m=g.from(e);for(;l.length<s;){const x=m.get(l.length);l.push(x),c+=x}}if(n.currentWindow=l,n.currentSum=c,n.currentCallCount=h,l.length<s)return NaN;const p=c/s;let u=0;for(let m=0;m<s;m++)u+=Math.abs(l[m]-p);const f=u/s;return t.precision(f)}}function Tu(t){return(e,i,r)=>{const s=g.from(e).get(0),a=g.from(i).get(0);t.taState||(t.taState={});const n=r||`dmi_${s}_${a}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});const o=t.taState[n];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN,NaN]];const p=t.idx>0?t.get(t.data.high,1):NaN,u=t.idx>0?t.get(t.data.low,1):NaN,f=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];const m=Math.max(l-c,Math.abs(l-f),Math.abs(c-f)),x=l-p,_=u-c,b=x>_&&x>0?x:0,w=_>x&&_>0?_:0;let v=o.prevInitCount,E=o.prevTrInitSum,T=o.prevPlusInitSum,C=o.prevMinusInitSum,O=o.prevSmoothedTR,B=o.prevSmoothedPlus,z=o.prevSmoothedMinus;if(v++,v<=s)E+=m,T+=b,C+=w,v===s&&(O=E/s,B=T/s,z=C/s);else{const ce=1/s;O=ce*m+(1-ce)*O,B=ce*b+(1-ce)*B,z=ce*w+(1-ce)*z}if(o.currentInitCount=v,o.currentTrInitSum=E,o.currentPlusInitSum=T,o.currentMinusInitSum=C,o.currentSmoothedTR=O,o.currentSmoothedPlus=B,o.currentSmoothedMinus=z,v<s)return[[NaN,NaN,NaN]];const q=O===0?0:100*B/O,V=O===0?0:100*z/O,Q=q+V,pe=Q===0?0:100*Math.abs(q-V)/Q;let Ce=o.prevAdxInitCount,Ie=o.prevDxInitSum,ke=o.prevADX,ut=NaN;if(Ce++,Ce<=a)Ie+=pe,Ce===a&&(ke=Ie/a,ut=ke);else{const ce=1/a;ke=ce*pe+(1-ce)*ke,ut=ke}return o.currentAdxInitCount=Ce,o.currentDxInitSum=Ie,o.currentADX=ke,[[t.precision(q),t.precision(V),t.precision(ut)]]}}function Pu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`ema_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevEma=n.currentEma,n.prevInitSum=n.currentInitSum,n.prevInitCount=n.currentInitCount),n.lastIdx=t.idx);const o=g.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=n.prevInitCount,c=n.prevInitSum,h=n.prevEma;if(l<s){if(c+=o,l++,n.currentInitSum=c,n.currentInitCount=l,l===s){const f=c/s;return n.currentEma=f,t.precision(f)}return NaN}const p=2/(s+1),u=o*p+h*(1-p);return n.currentEma=u,t.precision(u)}}function Du(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);for(let n=0;n<s;n++){const o=a.get(n),l=a.get(n+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Mu(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.high);const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`highest_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const u=g.from(e);for(;l.length<s;)l.push(u.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.max(...h);return t.precision(p)}}function Ru(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s-1)return NaN;let n=-1/0,o=NaN;for(let l=0;l<s;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c>n)&&(n=c,o=-l)}return o}}function Ou(t){return(e,i,r)=>{const s=g.from(i).get(0),a=Math.floor(s/2),n=Math.floor(Math.sqrt(s)),o=t.pine.ta.wma,l=o(e,a,r?`${r}_wma1`:void 0),c=o(e,s,r?`${r}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});const h=r||`hma_raw_${s}`;t.taState[h]||(t.taState[h]={lastIdx:-1,prevValues:[],currentValues:[]});const p=t.taState[h];t.idx>p.lastIdx&&(p.lastIdx>=0&&(p.prevValues=[...p.currentValues]),p.lastIdx=t.idx);const u=2*l-c,f=[...p.prevValues];f.unshift(u),f.length>n+1&&f.pop(),p.currentValues=f;const m=r?`${r}_hma_final`:`hma_final_${s}`;t.taState[m]||(t.taState[m]={lastIdx:-1,prevWindow:[],currentWindow:[]});const x=t.taState[m];t.idx>x.lastIdx&&(x.lastIdx>=0&&(x.prevWindow=[...x.currentWindow]),x.lastIdx=t.idx);const _=[...x.prevWindow];if(_.unshift(u),_.length<n)return x.currentWindow=_,NaN;for(;_.length>n;)_.pop();x.currentWindow=_;let b=0,w=0;for(let E=0;E<n;E++){const T=n-E;b+=_[E]*T,w+=T}const v=b/w;return t.precision(v)}}function Vu(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(a))return NaN;const n=(r-s)*a;if(n===0)return t.precision(0);const o=(2*i-r-s)/n;return t.precision(o)}}function Lu(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0);let l=!0;typeof s=="string"?a=s:s!==void 0&&(l=g.from(s).get(0));let c;const h=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){const E=t.get(t.data.close,1);isNaN(E)?c=NaN:c=Math.max(h-p,Math.abs(h-E),Math.abs(p-E))}else c=h-p;const u=g.from(e).get(0);t.taState||(t.taState={});const f=a||`kc_${n}_${o}_${l}`;t.taState[f]||(t.taState[f]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const m=t.taState[f];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.basisState={...m.currentBasisState},m.rangeState={...m.currentRangeState}),m.lastIdx=t.idx);const x=(E,T,C,O)=>{if(isNaN(C))return Object.assign(T,E),T.prevEma!==null?T.prevEma:NaN;let B=E.initCount,z=E.initSum,q=E.prevEma;if(B<O){if(z+=C,B++,T.initSum=z,T.initCount=B,T.prevEma=q,B===O){const pe=z/O;return T.prevEma=pe,pe}return NaN}const V=2/(O+1),Q=C*V+q*(1-V);return T.prevEma=Q,T.initSum=z,T.initCount=B,Q},_=x(m.basisState,m.currentBasisState,u,n),b=x(m.rangeState,m.currentRangeState,c,n);if(isNaN(_)||isNaN(b))return[[NaN,NaN,NaN]];const w=_+b*o,v=_-b*o;return[[t.precision(_),t.precision(w),t.precision(v)]]}}function $u(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0);let l=!0;typeof s=="string"?a=s:s!==void 0&&(l=g.from(s).get(0)),t.taState||(t.taState={});const c=a||`kcw_${n}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});const h=t.taState[c];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.basisState={...h.currentBasisState},h.rangeState={...h.currentRangeState}),h.lastIdx=t.idx);const p=(v,E,T,C)=>{if(isNaN(T))return Object.assign(E,v),E.prevEma!==null?E.prevEma:NaN;let O=v.initCount,B=v.initSum,z=v.prevEma;if(O<C){if(B+=T,O++,E.initSum=B,E.initCount=O,E.prevEma=z,O===C){const Q=B/C;return E.prevEma=Q,Q}return NaN}const q=2/(C+1),V=T*q+z*(1-q);return E.prevEma=V,E.initSum=B,E.initCount=O,V};let u;const f=t.get(t.data.high,0),m=t.get(t.data.low,0);if(l){const v=t.get(t.data.close,1);isNaN(v)?u=NaN:u=Math.max(f-m,Math.abs(f-v),Math.abs(m-v))}else u=f-m;const x=g.from(e).get(0),_=p(h.basisState,h.currentBasisState,x,n),b=p(h.rangeState,h.currentRangeState,u,n);if(isNaN(_)||isNaN(b))return NaN;if(_===0)return t.precision(0);const w=2*b*o/_;return t.precision(w)}}function ju(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`linreg_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=g.from(e).get(0),h=[...l.prevWindow];for(h.unshift(c);h.length>a;)h.pop();const p=l.prevCallCount+1;if(h.length<a&&(p>=a||t.idx>=a-1)){const E=g.from(e);for(;h.length<a;)h.push(E.get(h.length))}if(l.currentWindow=h,l.currentCallCount=p,h.length<a)return NaN;let u=0,f=0,m=0,x=0;const _=a;for(let E=0;E<a;E++){const T=a-1-E,C=h[E];u+=T,f+=C,m+=T*C,x+=T*T}const b=_*x-u*u;if(b===0)return NaN;const w=(_*m-u*f)/b,v=(f-w*u)/_+w*(a-1-n);return t.precision(v)}}function Bu(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.low);const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`lowest_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const u=g.from(e);for(;l.length<s;)l.push(u.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;const h=l.filter(u=>!isNaN(u)&&u!==void 0);if(h.length===0)return NaN;const p=Math.min(...h);return t.precision(p)}}function Fu(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s-1)return NaN;let n=1/0,o=NaN;for(let l=0;l<s;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c<n)&&(n=c,o=-l)}return o}}function Wu(t){return(e,i,r,s,a)=>{const n=g.from(i).get(0),o=g.from(r).get(0),l=g.from(s).get(0),c=a||`macd_${n}_${o}_${l}`,h=`${c}_fast`,p=`${c}_slow`,u=`${c}_signal`,f=t.pine.ta.ema(e,n,h),m=t.pine.ta.ema(e,o,p);let x=NaN;!isNaN(f)&&!isNaN(m)&&(x=f-m);let _=NaN;isNaN(x)||(_=t.pine.ta.ema(x,l,u));let b=NaN;return!isNaN(x)&&!isNaN(_)&&(b=x-_),[[t.precision(x),t.precision(_),t.precision(b)]]}}function Uu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`median_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const f=g.from(e);for(;l.length<s;)l.push(f.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;const h=l.slice().sort((f,m)=>f-m),p=Math.floor(s/2),u=s%2===0?(h[p-1]+h[p])/2:h[p];return t.precision(u)}}function qu(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`mfi_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevUpperWindow=[...n.currentUpperWindow],n.prevLowerWindow=[...n.currentLowerWindow],n.prevUpperSum=n.currentUpperSum,n.prevLowerSum=n.currentLowerSum),n.lastIdx=t.idx);const o=g.from(e).get(0),l=g.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;const h=isNaN(l)?NaN:o-l,p=c*(h<=0?0:o),u=c*(h>=0?0:o),f=[...n.prevUpperWindow],m=[...n.prevLowerWindow];let x=n.prevUpperSum,_=n.prevLowerSum;if(f.unshift(p),m.unshift(u),x+=p,_+=u,f.length<s)return n.currentUpperWindow=f,n.currentLowerWindow=m,n.currentUpperSum=x,n.currentLowerSum=_,NaN;if(f.length>s){const w=f.pop(),v=m.pop();x-=w,_-=v}if(n.currentUpperWindow=f,n.currentLowerWindow=m,n.currentUpperSum=x,n.currentLowerSum=_,_===0)return t.precision(100);if(x===0)return t.precision(0);const b=100-100/(1+x/_);return t.precision(b)}}function Ku(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s-1)return NaN;const n=new Map;for(let c=0;c<s;c++){const h=a.get(c);isNaN(h)||n.set(h,(n.get(h)||0)+1)}if(n.size===0)return NaN;let o=NaN,l=-1;for(const[c,h]of n.entries())h>l?(l=h,o=c):h===l&&c<o&&(o=c);return o}}function zu(t){return(e,i,r)=>{const s=g.from(i).get(0);return t.pine.ta.change(e,s,r)}}function Hu(t){return e=>{t.taState||(t.taState={});const i=e||"nvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedNVI:1,tentativeNVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.close,1),n=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(s)?0:s,c=isNaN(a)?0:a,h=isNaN(n)?0:n,p=isNaN(o)?0:o;let u=r.committedNVI;if(!(l===0||c===0)&&h<p){const f=(l-c)/c;u=u+f*u}return r.tentativeNVI=u,t.precision(u)}}function Gu(t){return()=>{t.taState||(t.taState={});const e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});const i=t.taState[e];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.committedOBV=i.tentativeOBV),i.lastIdx=t.idx);const r=t.get(t.data.close,0),s=t.get(t.data.volume,0),a=t.get(t.data.close,1);if(isNaN(a))return i.tentativeOBV=0,t.precision(0);let n=i.committedOBV;return r>a?n+=s:r<a&&(n-=s),i.tentativeOBV=n,t.precision(n)}}function Yu(t){return(e,i,r)=>e instanceof g?i?new g(e.data,e.offset+i):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new g(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new g(t.params[r],i||0)))}function Xu(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e);if(t.idx<a-1)return NaN;const l=[];for(let m=0;m<a;m++){const x=o.get(m);if(isNaN(x))return NaN;l.push(x)}l.sort((m,x)=>m-x);let c=n/100*a-.5;c<0&&(c=0),c>a-1&&(c=a-1);const h=Math.floor(c),p=Math.ceil(c);if(h===p)return t.precision(l[h]);const u=c-h,f=l[h]+u*(l[p]-l[h]);return t.precision(f)}}function Qu(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e);if(t.idx<a-1)return NaN;const l=[];for(let h=0;h<a;h++){const p=o.get(h);isNaN(p)||l.push(p)}if(l.length===0)return NaN;l.sort((h,p)=>h-p);let c=Math.ceil(n/100*l.length)-1;return c<0&&(c=0),c>=l.length&&(c=l.length-1),t.precision(l[c])}}function Zu(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);if(t.idx<s)return NaN;const n=a.get(0);if(isNaN(n))return NaN;let o=0,l=0;for(let c=1;c<=s;c++){const h=a.get(c);isNaN(h)||(l++,h<=n&&o++)}return l===0?NaN:t.precision(o/l*100)}}function Ju(t,e,i){const r=new Array(t.length).fill(NaN);for(let s=e+i;s<t.length;s++){const a=t[s-i];let n=!0;for(let o=1;o<=e;o++)if(t[s-i-o]>=a){n=!1;break}if(n){for(let o=1;o<=i;o++)if(t[s-i+o]>=a){n=!1;break}}n&&(r[s]=a)}return r}function ep(t){return(e,i,r,s)=>{typeof r=="string"&&(r=i,i=e,e=t.data.high);const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e).toArray(),l=Ju(o,a,n),c=t.idx;return t.precision(l[c])}}function tp(t,e,i){const r=new Array(t.length).fill(NaN);for(let s=e+i;s<t.length;s++){const a=t[s-i];let n=!0;for(let o=1;o<=e;o++)if(t[s-i-o]<=a){n=!1;break}if(n){for(let o=1;o<=i;o++)if(t[s-i+o]<=a){n=!1;break}}n&&(r[s]=a)}return r}function ip(t){return(e,i,r,s)=>{typeof r=="string"&&(r=i,i=e,e=t.data.low);const a=g.from(i).get(0),n=g.from(r).get(0),o=g.from(e).toArray(),l=tp(o,a,n),c=t.idx;return t.precision(l[c])}}function rp(t){return e=>{t.taState||(t.taState={});const i=e||"pvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedPVI:1,tentativePVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.close,1),n=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(s)?0:s,c=isNaN(a)?0:a,h=isNaN(n)?0:n,p=isNaN(o)?0:o;let u=r.committedPVI;if(!(l===0||c===0)&&h>p){const f=(l-c)/c;u=u+f*u}return r.tentativePVI=u,t.precision(u)}}function sp(t){return e=>{t.taState||(t.taState={});const i=e||"pvt";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.close,1),n=t.get(t.data.volume,0);let o=r.prevCumulativeSum;if(!isNaN(s)&&!isNaN(a)&&!isNaN(n)&&a!==0){const l=(s-a)/a*n;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function np(t){return(e,i,r)=>{const s=t.pine.ta.highest(e,i,(r||"range")+"_h"),a=t.pine.ta.lowest(e,i,(r||"range")+"_l");return isNaN(s)||isNaN(a)?NaN:t.precision(s-a)}}function ap(t){return(e,i,r)=>{const s=g.from(i).get(0),a=g.from(e);for(let n=0;n<s;n++){const o=a.get(n),l=a.get(n+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function op(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`rma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevRma=n.currentRma,n.prevInitSum=n.currentInitSum,n.prevInitCount=n.currentInitCount),n.lastIdx=t.idx);const o=g.from(e).get(0)||0;let l=n.prevInitCount,c=n.prevInitSum,h=n.prevRma;if(l<s){if(c+=o,l++,n.currentInitSum=c,n.currentInitCount=l,l===s){const f=c/s;return n.currentRma=f,t.precision(f)}return NaN}const p=1/s,u=o*p+h*(1-p);return n.currentRma=u,t.precision(u)}}function lp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`roc_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s+1;)l.pop();const c=n.prevCallCount+1;if(l.length<s+1&&(c>=s+1||t.idx>=s)){const u=g.from(e);for(;l.length<s+1;)l.push(u.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<=s)return NaN;const h=l[s],p=(o-h)/h*100;return t.precision(p)}}function cp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`rsi_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevPrevValue=n.currentPrevValue,n.prevAvgGain=n.currentAvgGain,n.prevAvgLoss=n.currentAvgLoss,n.prevInitGains=[...n.currentInitGains],n.prevInitLosses=[...n.currentInitLosses]),n.lastIdx=t.idx);const o=g.from(e).get(0);if(o==null||isNaN(o))return NaN;const l=n.prevPrevValue;if(l===null||isNaN(l))return n.currentPrevValue=o,n.currentInitGains=[...n.prevInitGains],n.currentInitLosses=[...n.prevInitLosses],n.currentAvgGain=n.prevAvgGain,n.currentAvgLoss=n.prevAvgLoss,NaN;let c=n.prevAvgGain,h=n.prevAvgLoss;const p=[...n.prevInitGains],u=[...n.prevInitLosses],f=o-l,m=f>0?f:0,x=f<0?-f:0;if(p.length<s){if(p.push(m),u.push(x),n.currentInitGains=p,n.currentInitLosses=u,n.currentPrevValue=o,p.length===s){c=p.reduce((w,v)=>w+v,0)/s,h=u.reduce((w,v)=>w+v,0)/s,n.currentAvgGain=c,n.currentAvgLoss=h;const b=h===0?100:100-100/(1+c/h);return t.precision(b)}return NaN}c=(c*(s-1)+m)/s,h=(h*(s-1)+x)/s,n.currentAvgGain=c,n.currentAvgLoss=h,n.currentPrevValue=o;const _=h===0?100:100-100/(1+c/h);return t.precision(_)}}function hp(t){return(e,i,r,s)=>{const a=g.from(e).get(0),n=g.from(i).get(0),o=g.from(r).get(0);t.taState||(t.taState={});const l=s||`sar_${a}_${n}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});const c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let h=c.prevResult,p=c.prevMaxMin,u=c.prevAcceleration,f=c.prevIsBelow,m=c.prevBarIndex;const x=t.get(t.data.high,0),_=t.get(t.data.low,0),b=t.get(t.data.close,0),w=t.get(t.data.close,1),v=t.get(t.data.high,1),E=t.get(t.data.low,1),T=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(x)||isNaN(_)||isNaN(b))return c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,NaN;let O=!1;return m===1&&(b>w?(f=!0,p=x,h=E):(f=!1,p=_,h=v),O=!0,u=a),m>=1&&(h=h+u*(p-h),f?h>_&&(O=!0,f=!1,h=Math.max(x,p),p=_,u=a):h<x&&(O=!0,f=!0,h=Math.min(_,p),p=x,u=a),O||(f?x>p&&(p=x,u=Math.min(u+n,o)):_<p&&(p=_,u=Math.min(u+n,o))),f?(h=Math.min(h,E),m>1&&(h=Math.min(h,C))):(h=Math.max(h,v),m>1&&(h=Math.max(h,T)))),m++,c.currentResult=h,c.currentMaxMin=p,c.currentAcceleration=u,c.currentIsBelow=f,c.currentBarIndex=m,m<=1?NaN:t.precision(h)}}function up(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`sma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevSum=n.currentSum,n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;let h=!1;if(l.length<s&&(c>=s||t.idx>=s-1)){const x=g.from(e);for(;l.length<s;)l.push(x.get(l.length));h=!0}let p;const u=o==null||Number.isNaN(o);let f=!Number.isNaN(n.prevSum)&&!u&&!h;if(f){let x=n.prevSum+o;if(n.prevWindow.length>=s){const _=n.prevWindow[n.prevWindow.length-1];_==null||Number.isNaN(_)?f=!1:x-=_}f&&(p=x)}if(!f){p=0;let x=!1;for(const _ of l){if(_==null||Number.isNaN(_)){x=!0;break}p+=_}x&&(p=NaN)}if(n.currentWindow=l,n.currentSum=p,n.currentCallCount=c,l.length<s)return NaN;const m=p/s;return t.precision(m)}}function pp(t){return(e,i,r=!0,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`stdev_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum,l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=g.from(e).get(0);if(c==null||isNaN(c))return NaN;const h=[...l.prevWindow];let p=l.prevSum;for(h.unshift(c),p+=c;h.length>a;){const b=h.pop();p-=b}const u=l.prevCallCount+1;if(h.length<a&&(u>=a||t.idx>=a-1)){const b=g.from(e);for(;h.length<a;){const w=b.get(h.length);if(w==null||isNaN(w))break;h.push(w),p+=w}}if(l.currentWindow=h,l.currentSum=p,l.currentCallCount=u,h.length<a)return NaN;const f=p/a;let m=0;for(let b=0;b<a;b++)m+=Math.pow(h[b]-f,2);const x=n?a:a-1,_=Math.sqrt(m/x);return t.precision(_)}}function fp(t){return(e,i,r,s,a)=>{const n=g.from(s).get(0);t.taState||(t.taState={});const o=a||`stoch_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);const c=g.from(e).get(0),h=g.from(i).get(0),p=g.from(r).get(0);if(isNaN(c)||isNaN(h)||isNaN(p))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;const u=[...l.prevHighWindow],f=[...l.prevLowWindow];if(u.unshift(h),f.unshift(p),u.length>n&&(u.pop(),f.pop()),l.currentHighWindow=u,l.currentLowWindow=f,u.length<n)return NaN;let m=u[0],x=f[0];for(let w=1;w<n;w++)u[w]>m&&(m=u[w]),f[w]<x&&(x=f[w]);const _=m-x;if(_===0)return NaN;const b=100*(c-x)/_;return t.precision(b)}}function dp(t){return(e,i,r)=>{const s=g.from(e).get(0),a=g.from(i).get(0);t.taState||(t.taState={});const n=r||`supertrend_${s}_${a}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});const o=t.taState[n];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrSum=o.currentTrSum,o.prevAtrValue=o.currentAtrValue,o.prevAtrCount=o.currentAtrCount,o.prevLowerBand=o.currentLowerBand,o.prevUpperBand=o.currentUpperBand,o.prevSuperTrend=o.currentSuperTrend,o.prevDirection=o.currentDirection),o.lastIdx=t.idx);const l=t.get(t.data.high,0),c=t.get(t.data.low,0),h=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(h))return[[NaN,NaN]];const p=(l+c)/2,u=t.idx>0?t.get(t.data.close,1):NaN;let f;isNaN(u)?f=l-c:f=Math.max(l-c,Math.abs(l-u),Math.abs(c-u));let m=o.prevAtrCount,x=o.prevTrSum,_=o.prevAtrValue;m++,m<=a?(x+=f,m===a&&(_=x/a)):_=(_*(a-1)+f)/a;const b=_;if(o.currentAtrCount=m,o.currentTrSum=x,o.currentAtrValue=_,isNaN(b))return[[NaN,NaN]];let w=p+s*b,v=p-s*b;const E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,T=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||v>E||u<E||(v=E),isNaN(o.prevUpperBand)||w<T||u>T||(w=T);let C,O;const B=o.prevSuperTrend;return m===a?C=1:B===o.prevUpperBand?C=h>w?-1:1:C=h<v?1:-1,O=C===-1?v:w,o.currentLowerBand=v,o.currentUpperBand=w,o.currentSuperTrend=O,o.currentDirection=C,[[t.precision(O),C]]}}function mp(t){return(e,i)=>{const r=[1,2,2,1],s=6;t.taState||(t.taState={});const a=i||"swma";t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],currentWindow:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow]),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){const h=g.from(e);for(;l.length<4;)l.push(h.get(l.length))}if(n.currentWindow=l,l.length<4)return NaN;let c=0;for(let h=0;h<4;h++)c+=r[h]*l[3-h];return c/=s,t.precision(c)}}function gp(t){return(e,i)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=g.from(e).get(0));const s=t.get(t.data.high,0),a=t.get(t.data.low,0),n=t.get(t.data.close,1);if(isNaN(n))return r?t.precision(s-a):NaN;const o=Math.max(s-a,Math.abs(s-n),Math.abs(a-n));return t.precision(o)}}function yp(t){return(e,i,r,s)=>{const a=g.from(i).get(0),n=g.from(r).get(0);t.taState||(t.taState={});const o=s||`tsi_${a}_${n}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);const c=g.from(e).get(0);if(isNaN(c))return NaN;const h=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(h))return NaN;const p=Math.abs(h),u=2/(n+1),f=2/(a+1),m=2/(n+1),x=2/(a+1);let _=l.prevEma1PcCount,b=l.prevEma1PcSum,w=l.prevEma1PcValue;_++,_<=n?(b+=h,_===n&&(w=b/n)):w=h*u+w*(1-u);let v=l.prevEma1AbsCount,E=l.prevEma1AbsSum,T=l.prevEma1AbsValue;if(v++,v<=n?(E+=p,v===n&&(T=E/n)):T=p*m+T*(1-m),isNaN(w)||isNaN(T))return l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=T,NaN;let C=l.prevEma2PcCount,O=l.prevEma2PcSum,B=l.prevEma2PcValue;C++,C<=a?(O+=w,C===a&&(B=O/a)):B=w*f+B*(1-f);let z=l.prevEma2AbsCount,q=l.prevEma2AbsSum,V=l.prevEma2AbsValue;if(z++,z<=a?(q+=T,z===a&&(V=q/a)):V=T*x+V*(1-x),l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=T,l.currentEma2PcCount=C,l.currentEma2PcSum=O,l.currentEma2PcValue=B,l.currentEma2AbsCount=z,l.currentEma2AbsSum=q,l.currentEma2AbsValue=V,isNaN(B)||isNaN(V))return NaN;if(V===0)return t.precision(0);const Q=B/V;return t.precision(Q)}}function xp(t){return(e,i,r,s)=>{t.taState||(t.taState={});const a=s||"valuewhen";t.taState[a]||(t.taState[a]={lastIdx:-1,prevValues:[],currentValues:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevValues=[...n.currentValues]),n.lastIdx=t.idx);const o=g.from(e).get(0),l=g.from(i).get(0),c=g.from(r).get(0),h=[...n.prevValues];if(o&&h.push(l),n.currentValues=h,isNaN(c)||c<0)return NaN;const p=h.length-1-c;if(p<0)return NaN;const u=h[p];return typeof u=="number"?t.precision(u):u}}function _p(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`variance_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const m=g.from(e);for(;l.length<s;)l.push(m.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;let h=0,p=0;for(let m=0;m<s;m++)h+=l[m],p+=l[m]*l[m];const u=h/s,f=p/s-u*u;return t.precision(f)}}function bp(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"vwap";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});const s=t.taState[r];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevCumulativePV=s.currentCumulativePV,s.prevCumulativeVolume=s.currentCumulativeVolume,s.prevLastSessionDate=s.currentLastSessionDate),s.lastIdx=t.idx);const a=g.from(e).get(0),n=g.from(t.data.volume).get(0),o=g.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=Pt(o,l),h=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`;let p=s.prevCumulativePV,u=s.prevCumulativeVolume,f=s.prevLastSessionDate;if(f!==h&&(p=0,u=0,f=h),p+=a*n,u+=n,s.currentCumulativePV=p,s.currentCumulativeVolume=u,s.currentLastSessionDate=f,u===0)return NaN;const m=p/u;return t.precision(m)}}function vp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`vwma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevVolumeWindow=[...n.currentVolumeWindow]),n.lastIdx=t.idx);const o=g.from(e).get(0),l=t.get(t.data.volume,0),c=[...n.prevWindow],h=[...n.prevVolumeWindow];for(c.unshift(o),h.unshift(l);c.length>s;)c.pop(),h.pop();if(c.length<s&&t.idx>=s-1){const m=g.from(e),x=g.from(t.data.volume);for(;c.length<s;)c.push(m.get(c.length)),h.push(x.get(h.length))}if(n.currentWindow=c,n.currentVolumeWindow=h,c.length<s)return NaN;let p=0,u=0;for(let m=0;m<s;m++)p+=c[m]*h[m],u+=h[m];const f=p/u;return t.precision(f)}}function wp(t){return e=>{t.taState||(t.taState={});const i=e||"wad";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const s=t.get(t.data.close,0),a=t.get(t.data.high,0),n=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(s)||isNaN(a)||isNaN(n))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){const h=Math.max(a,o),p=Math.min(n,o),u=s-o;u>0?l=s-p:u<0&&(l=s-h)}const c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function Sp(t){return(e,i,r)=>{const s=g.from(i).get(0);t.taState||(t.taState={});const a=r||`wma_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const n=t.taState[a];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevWindow=[...n.currentWindow],n.prevCallCount=n.currentCallCount),n.lastIdx=t.idx);const o=g.from(e).get(0),l=[...n.prevWindow];for(l.unshift(o);l.length>s;)l.pop();const c=n.prevCallCount+1;if(l.length<s&&(c>=s||t.idx>=s-1)){const f=g.from(e);for(;l.length<s;)l.push(f.get(l.length))}if(n.currentWindow=l,n.currentCallCount=c,l.length<s)return NaN;let h=0,p=0;for(let f=0;f<s;f++){const m=s-f;h+=l[f]*m,p+=m}const u=h/p;return t.precision(u)}}function Ep(t){return(e,i)=>{const r=g.from(e).get(0);t.taState||(t.taState={});const s=i||`wpr_${r}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevHighWindow=[...a.currentHighWindow],a.prevLowWindow=[...a.currentLowWindow]),a.lastIdx=t.idx);const n=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(n)||isNaN(o)||isNaN(l))return a.currentHighWindow=[...a.prevHighWindow],a.currentLowWindow=[...a.prevLowWindow],NaN;const c=[...a.prevHighWindow],h=[...a.prevLowWindow];if(c.unshift(n),h.unshift(o),c.length>r&&(c.pop(),h.pop()),a.currentHighWindow=c,a.currentLowWindow=h,c.length<r)return NaN;let p=c[0],u=h[0];for(let x=1;x<r;x++)c[x]>p&&(p=c[x]),h[x]<u&&(u=h[x]);const f=p-u;if(f===0)return t.precision(0);const m=(p-l)/f*-100;return t.precision(m)}}function Np(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.open,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),n=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(s)||isNaN(a)||isNaN(n))return NaN;const o=s-a;if(o===0)return t.precision(0);const l=(i-r)/o*n;return t.precision(l)}}var Cp=Object.defineProperty,Ip=(t,e,i)=>e in t?Cp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,I=(t,e,i)=>Ip(t,typeof e!="symbol"?e+"":e,i);const kp={accdist:du,alma:mu,atr:gu,barssince:yu,bb:xu,bbw:_u,cci:bu,change:vu,cmo:wu,cog:Su,correlation:Eu,cross:Nu,crossover:Cu,crossunder:Iu,cum:ku,dev:Au,dmi:Tu,ema:Pu,falling:Du,highest:Mu,highestbars:Ru,hma:Ou,iii:Vu,kc:Lu,kcw:$u,linreg:ju,lowest:Bu,lowestbars:Fu,macd:Wu,median:Uu,mfi:qu,mode:Ku,mom:zu,nvi:Hu,obv:Gu,param:Yu,percentile_linear_interpolation:Xu,percentile_nearest_rank:Qu,percentrank:Zu,pivothigh:ep,pivotlow:ip,pvi:rp,pvt:sp,range:np,rising:ap,rma:op,roc:lp,rsi:cp,sar:hp,sma:up,stdev:pp,stoch:fp,supertrend:dp,swma:mp,tr:gp,tsi:yp,valuewhen:xp,variance:_p,vwap:bp,vwma:vp,wad:wp,wma:Sp,wpr:Ep,wvad:Np};class Ap{constructor(e){this.context=e,I(this,"accdist"),I(this,"alma"),I(this,"atr"),I(this,"barssince"),I(this,"bb"),I(this,"bbw"),I(this,"cci"),I(this,"change"),I(this,"cmo"),I(this,"cog"),I(this,"correlation"),I(this,"cross"),I(this,"crossover"),I(this,"crossunder"),I(this,"cum"),I(this,"dev"),I(this,"dmi"),I(this,"ema"),I(this,"falling"),I(this,"highest"),I(this,"highestbars"),I(this,"hma"),I(this,"iii"),I(this,"kc"),I(this,"kcw"),I(this,"linreg"),I(this,"lowest"),I(this,"lowestbars"),I(this,"macd"),I(this,"median"),I(this,"mfi"),I(this,"mode"),I(this,"mom"),I(this,"nvi"),I(this,"obv"),I(this,"param"),I(this,"percentile_linear_interpolation"),I(this,"percentile_nearest_rank"),I(this,"percentrank"),I(this,"pivothigh"),I(this,"pivotlow"),I(this,"pvi"),I(this,"pvt"),I(this,"range"),I(this,"rising"),I(this,"rma"),I(this,"roc"),I(this,"rsi"),I(this,"sar"),I(this,"sma"),I(this,"stdev"),I(this,"stoch"),I(this,"supertrend"),I(this,"swma"),I(this,"tr"),I(this,"tsi"),I(this,"valuewhen"),I(this,"variance"),I(this,"vwap"),I(this,"vwma"),I(this,"wad"),I(this,"wma"),I(this,"wpr"),I(this,"wvad"),Object.entries(kp).forEach(([i,r])=>{this[i]=r(e)})}}function Tp(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC")return 0;const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const n=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return n*(o*60+l)}const s=Pt(t,e),a=new Date(Date.UTC(s.year,s.month-1,s.day,s.hour,s.minute,s.second));return Math.round((a.getTime()-t)/6e4)}function Pp(t,e){const i=e>=0?"+":"-",r=a=>String(Math.floor(Math.abs(a))).padStart(2,"0"),s=i+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${s}]`}class Dp{constructor(e){this.context=e}logFormat(e,...i){return e.replace(/{(\d+)}/g,(r,s)=>i[s])}param(e,i=0,r){return g.from(e).get(i)}_formatTimestamp(){const e=this.context.data.openTime.data[this.context.idx],i=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=Tp(e,i);return Pp(e,r)}warning(e,...i){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}error(e,...i){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}info(e,...i){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}}class Mp{constructor(e){this.context=e}param(e,i=0,r){return g.from(e).get(i)}tostring(e,i){if(typeof e!="number"||isNaN(e)||!i)return String(e);if(i==="mintick"){const s=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(s)));return e.toFixed(a)}if(i==="integer")return String(Math.round(e));if(i==="percent")return(e*100).toFixed(2)+"%";if(i==="price"){const s=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(s)));return e.toFixed(a)}if(i==="volume")return String(Math.round(e));const r=i.indexOf(".");if(r>=0){const s=i.substring(r+1).length;return e.toFixed(s)}return i.includes("#")||i.includes("0")?String(Math.round(e)):String(e)}tonumber(e){return Number(e)}lower(e){return String(e).toLowerCase()}upper(e){return String(e).toUpperCase()}trim(e){return String(e).trim()}repeat(e,i,r=""){return Array(i).fill(e).join(r||"")}replace_all(e,i,r){return String(e).replaceAll(i,r)}replace(e,i,r,s=0){const a=String(e),n=String(i),o=String(r),l=Math.floor(Number(s))||0;if(n==="")return a;let c=0,h=0;for(;;){const p=a.indexOf(n,c);if(p===-1)return a;if(h===l)return a.substring(0,p)+o+a.substring(p+n.length);h++,c=p+n.length}}contains(e,i){return String(e).includes(i)}endswith(e,i){return String(e).endsWith(i)}startswith(e,i){return String(e).startsWith(i)}pos(e,i){const r=String(e).indexOf(i);return r===-1?NaN:r}length(e){return String(e).length}match(e,i){return String(e).match(new RegExp(i))}split(e,i){return new R(String(e).split(i),D.string,this.context)}substring(e,i,r){return String(e).substring(i,r)}format(e,...i){return e.replace(/\{(\d+)(?:,number,([^}]+))?\}/g,(r,s,a)=>{const n=i[s];return a&&typeof n=="number"&&!isNaN(n)?this.tostring(n,a):String(n)})}}var Rp=Object.defineProperty,Op=(t,e,i)=>e in t?Rp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Vp=(t,e,i)=>Op(t,typeof e!="symbol"?e+"":e,i);const ii={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function Lr(t){if(!t||/^\d+$/.test(t))return t;if(ii[t])return ii[t];const e=t.toLowerCase();if(ii[e])return ii[e];if(t.length===1){const r=t.toUpperCase();if(["D","W","M","S"].includes(r))return r}const i=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(i)){const r=parseInt(t);if(!isNaN(r))return r+i}return t}class Lp{constructor(e){this.context=e,Vp(this,"_normalized",null)}param(e,i=0,r){return g.from(e).get(i)}get normalized(){return this._normalized===null&&(this._normalized=Lr(this.context.timeframe)),this._normalized}get unit(){return this.normalized.slice(-1).toUpperCase()}get main_period(){return this.normalized}get period(){return this.normalized}get multiplier(){const e=parseInt(this.normalized);return isNaN(e)?1:e}get isdwm(){return["D","W","M"].includes(this.unit)}get isdaily(){return this.unit==="D"}get isweekly(){return this.unit==="W"}get ismonthly(){return this.unit==="M"}get isseconds(){return this.unit==="S"}get isminutes(){return/^\d+$/.test(this.normalized)}get isintraday(){return!this.isdwm}change(e){const i=typeof e=="function"?e():e,r=i instanceof g?i.get(0):i,s=zi(r||"");if(!s)return!1;const a=g.from(this.context.data.openTime).get(0),n=g.from(this.context.data.openTime).get(1);if(isNaN(a)||isNaN(n))return!1;const o=Hi(a,s),l=Hi(n,s);return o!==l}from_seconds(e){return e<60?Math.ceil(e/5)*5+"S":e<3600*24?Math.ceil(e/60):e<=3600*24*7*52?e%(3600*24*7)===0?Math.ceil(e/604800)+"W":Math.ceil(e/(3600*24))+"D":"12M"}in_seconds(e){e==null?e=this.normalized:e=Lr(e);const i=e.slice(-1).toUpperCase(),r=parseInt(e);return i==="S"?isNaN(r)?1:r:i==="D"?(isNaN(r)?1:r)*60*60*24:i==="W"?(isNaN(r)?1:r)*60*60*24*7:i==="M"?(isNaN(r)?1:r)*60*60*24*30:isNaN(r)?0:r*60}}const $p=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],jp=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Bp={series:"series",title:"string",char:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Fp=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Wp=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],Up=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],qp=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],$r=["color","offset","editable","show_last","title","display","force_overlay"],Kp=["price","title","color","linestyle","linewidth","editable","display"],zp=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],Hp={series:"series",title:"string",color:"color",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"},Gp={series:"series",title:"string",style:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Yp={series:"series",title:"string",colorup:"color",colordown:"color",offset:"number",minheight:"number",maxheight:"number",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Xp={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Qp={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",wickcolor:"color",bordercolor:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},jr={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},Zp={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},Jp={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"};class ef{constructor(e){this.context=e}_resolvePlotKey(e,i){if(e){const r=this.context.plots[e];return!r||!i||r._callsiteId===i?e:e+i}return i||"plot"}extractPlotOptions(e){const i={};for(let r in e)i[r]=g.from(e[r]).get(0);return i}get linestyle_dashed(){return"linestyle_dashed"}get linestyle_dotted(){return"linestyle_dotted"}get linestyle_solid(){return"linestyle_solid"}get style_area(){return"style_area"}get style_areabr(){return"style_areabr"}get style_circles(){return"style_circles"}get style_columns(){return"style_columns"}get style_cross(){return"style_cross"}get style_histogram(){return"style_histogram"}get style_line(){return"style_line"}get style_linebr(){return"style_linebr"}get style_stepline(){return"style_stepline"}get style_stepline_diamond(){return"style_stepline_diamond"}get style_steplinebr(){return"style_steplinebr"}param(e,i=0,r){return g.from(e).get(i)}plotchar(...e){const i=Ue(e),r=se(e,jp,Bp),{series:s,title:a,...n}=r,o=this.extractPlotOptions(n),l=this._resolvePlotKey(a,i);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:a,_plotKey:l,_callsiteId:i});const c=g.from(s).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){const i=Ue(e),r=se(e,$p,Hp),{series:s,title:a,...n}=r,o=this.extractPlotOptions(n),l=this._resolvePlotKey(a,i),c="color"in n;if(!this.context.plots[l]){const f=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:f},title:a,_plotKey:l,_callsiteId:i}}const h=g.from(s).get(0);let p=o.color;typeof p=="function"&&(p=p());const u={color:c?typeof p=="string"?p:void 0:p||"#2962ff"};return"offset"in n&&(u.offset=o.offset),this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:h,options:u}),this.context.plots[l]}plotshape(...e){const i=Ue(e),r=se(e,Fp,Gp),{series:s,title:a,...n}=r,o=this.extractPlotOptions(n),l=this._resolvePlotKey(a,i);if(!this.context.plots[l]){const h=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:h},title:a,_plotKey:l,_callsiteId:i}}const c=g.from(s).get(0);return this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){const i=Ue(e),r=se(e,Wp,Yp),{series:s,title:a,...n}=r,o=g.from(s).get(0),l=this.extractPlotOptions(n),c=this._resolvePlotKey(a,i);if(!this.context.plots[c]){const h=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:h},title:a,_plotKey:c,_callsiteId:i}}return this.context.plots[c].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){const i=Ue(e),r=se(e,Up,Xp),{open:s,high:a,low:n,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"bar",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[g.from(s).get(0),g.from(a).get(0),g.from(n).get(0),g.from(o).get(0)];this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color}})}plotcandle(...e){const i=Ue(e),r=se(e,qp,Qp),{open:s,high:a,low:n,close:o,title:l,...c}=r,h=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=h.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...h,style:"candle",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const u=[g.from(s).get(0),g.from(a).get(0),g.from(n).get(0),g.from(o).get(0)];return this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:u,options:{color:h.color,wickcolor:h.wickcolor,bordercolor:h.bordercolor}}),this.context.plots[p]}bgcolor(...e){const i=Ue(e),r=se(e,$r,jr),{title:s,...a}=r,n=this.extractPlotOptions(a),o=this._resolvePlotKey(s,i);if(!this.context.plots[o]){const l=n.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...n,style:"background",overlay:l},title:s,_plotKey:o,_callsiteId:i}}this.context.plots[o].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:n.color&&n.color!=="na"&&n?.color.toString()!=="NaN",options:{color:n.color}})}barcolor(...e){const i=Ue(e),r=se(e,$r,jr),{title:s,...a}=r,n=this.extractPlotOptions(a),o=this._resolvePlotKey(s,i);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...n,style:"barcolor"},title:s,_plotKey:o,_callsiteId:i}),this.context.plots[o].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:n.color&&n.color!=="na"&&n?.color.toString()!=="NaN",options:{color:n.color}}),this.context.plots[o]}}class tf{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,i=0,r){return g.from(e).get(i)}any(...e){const i=Ue(e),r=se(e,Kp,Zp),{price:s,title:a,color:n,linestyle:o,linewidth:l,editable:c,display:h}=r,p=[s,{title:a,color:n,linestyle:o,linewidth:l,editable:c,display:h,style:"hline"}];return i&&p.push({__callsiteId:i}),this.context.pine.plot.any(...p)}}class rf{constructor(e){this.context=e}param(e,i=0,r){return g.from(e).get(i)}any(...e){const i=Ue(e),r=e.length>=6&&typeof e[2]=="number",s=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||s!==null){const a=e[0],n=e[1],o=s?g.from(s.top_value).get(0):e[2],l=s?g.from(s.bottom_value).get(0):e[3],c=s?g.from(s.top_color).get(0):e[4],h=s?g.from(s.bottom_color).get(0):e[5],p=s?s.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,u=a?._plotKey||a?.title,f=n?._plotKey||n?.title;let m=p||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i),this.context.plots[m]||(this.context.plots[m]={title:p||"Fill",plot1:u,plot2:f,data:[],options:{plot1:u,plot2:f,style:"fill",gradient:!0},_plotKey:m,_callsiteId:i}),this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:h}})}else{const a=se(e,zp,Jp),{plot1:n,plot2:o,color:l,title:c,editable:h,show_last:p,fillgaps:u,display:f}=a;let m=c||"fill";const x=this.context.plots[m];x&&i&&x._callsiteId!==i&&(m=i);const _=g.from(l).get(0);if(!this.context.plots[m]){const b=n?._plotKey||n?.title,w=o?._plotKey||o?.title;this.context.plots[m]={title:c||"Fill",plot1:b,plot2:w,data:[],options:{plot1:b,plot2:w,color:_,editable:h,show_last:p,fillgaps:u,display:f,style:"fill"},_plotKey:m,_callsiteId:i}}this.context.plots[m].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:_}})}}}var sf=Object.defineProperty,nf=(t,e,i)=>e in t?sf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,af=(t,e,i)=>nf(t,typeof e!="symbol"?e+"":e,i);class of{constructor(e){this.context=e,af(this,"point");const i=this.context;this.point={new(r,s,a){return new me(r,s,a??NaN)},from_index(r,s){return new me(void 0,r,s)},from_time(r,s){return new me(r,void 0,s)},copy(r){return r.copy()},now(r){const s=i.idx,a=i.marketData[s]?.openTime;return new me(a,s,r)}}}param(e,i=0,r){return g.from(e).get(i)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){return!0}is_heikinashi(){return!1}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}}var lf=Object.defineProperty,cf=(t,e,i)=>e in t?lf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,oe=(t,e,i)=>cf(t,typeof e!="symbol"?e+"":e,i);let hf=0;class or{constructor(e,i,r="",s="bi",a="pr",n="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){oe(this,"id"),oe(this,"x"),oe(this,"y"),oe(this,"text"),oe(this,"xloc"),oe(this,"yloc"),oe(this,"color"),oe(this,"style"),oe(this,"textcolor"),oe(this,"size"),oe(this,"textalign"),oe(this,"tooltip"),oe(this,"text_font_family"),oe(this,"force_overlay"),oe(this,"_deleted"),oe(this,"_helper"),oe(this,"_createdAtBar",-1),this.id=hf++,this.x=e,this.y=i,this.text=r,this.xloc=s,this.yloc=a,this.color=n,this.style=o,this.textcolor=l,this.size=c,this.textalign=h,this.tooltip=p,this.text_font_family=u,this.force_overlay=f,this._deleted=!1,this._helper=null}set_x(e){this._helper?this._helper.set_x(this,e):this._deleted||(this.x=e)}set_y(e){this._helper?this._helper.set_y(this,e):this._deleted||(this.y=e)}set_xy(e,i){this._helper?this._helper.set_xy(this,e,i):this._deleted||(this.x=e,this.y=i)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_textcolor(e){this._helper?this._helper.set_textcolor(this,e):this._deleted||(this.textcolor=e)}set_size(e){this._helper?this._helper.set_size(this,e):this._deleted||(this.size=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_textalign(e){this._helper?this._helper.set_textalign(this,e):this._deleted||(this.textalign=e)}set_tooltip(e){this._helper?this._helper.set_tooltip(this,e):this._deleted||(this.tooltip=e)}set_xloc(e){this._helper?this._helper.set_xloc(this,e):this._deleted||(this.xloc=e)}set_yloc(e){this._helper?this._helper.set_yloc(this,e):this._deleted||(this.yloc=e)}set_point(e){this._helper&&this._helper.set_point(this,e)}set_text_font_family(e){this._deleted||(this.text_font_family=e)}get_x(){return this.x}get_y(){return this.y}get_text(){return this.text}delete(){this._deleted=!0}copy(){return new or(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay)}toPlotData(){return{id:this.id,x:this.x,y:this.y,text:this.text,xloc:this.xloc,yloc:this.yloc,color:this.color,style:this.style,textcolor:this.textcolor,size:this.size,textalign:this.textalign,tooltip:this.tooltip,text_font_family:this.text_font_family,force_overlay:this.force_overlay,_deleted:this._deleted}}}var uf=Object.defineProperty,pf=(t,e,i)=>e in t?uf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ff=(t,e,i)=>pf(t,typeof e!="symbol"?e+"":e,i);const df=[["x","y","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"],["point","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"]],mf={x:"number",y:"number",text:"string",xloc:"string",yloc:"string",color:"color",style:"string",textcolor:"color",size:"string",textalign:"string",tooltip:"string",text_font_family:"string",force_overlay:"boolean",point:"point"};class gf{constructor(e){this.context=e,ff(this,"_labels",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._labels.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],s.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:s,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof Vt)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){const i=e.get(0);return typeof i=="number"&&isNaN(i)?null:i}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,i,r="",s="bi",a="pr",n="",o="style_label_down",l="",c="normal",h="center",p="",u="default",f=!1){const m=new or(e,i,this._resolve(r),this._resolve(s),this._resolve(a),this._resolve(n),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(h),this._resolve(p),this._resolve(u),f);return m._helper=this,m._createdAtBar=this.context.idx,this._labels.push(m),this._enforceMaxCount(),this.syncToPlot(),m}_enforceMaxCount(){const e=this.context.indicator?.max_labels_count??50,i=this._labels.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._labels){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}new(...e){const i=se(e,df,mf);let r,s,a=i.xloc;if(i.point instanceof me){const n=i.point;n.index!==void 0?(r=n.index,a=a||"bi"):n.time!==void 0?(r=n.time,a=a||"bt"):(r=0,a=a||"bi"),s=n.price}else r=i.x,s=i.y;return this._createLabel(r,s,i.text,a,i.yloc,i.color,i.style,i.textcolor,i.size,i.textalign,i.tooltip,i.text_font_family,i.force_overlay)}any(...e){return this.new(...e)}set_x(e,i){e&&!e._deleted&&(e.x=i)}set_y(e,i){e&&!e._deleted&&(e.y=i)}set_xy(e,i,r){e&&!e._deleted&&(e.x=i,e.y=r)}set_text(e,i){e&&!e._deleted&&(e.text=i)}set_color(e,i){e&&!e._deleted&&(e.color=i)}set_textcolor(e,i){e&&!e._deleted&&(e.textcolor=i)}set_size(e,i){e&&!e._deleted&&(e.size=i)}set_style(e,i){e&&!e._deleted&&(e.style=i)}set_textalign(e,i){e&&!e._deleted&&(e.textalign=i)}set_tooltip(e,i){e&&!e._deleted&&(e.tooltip=i)}set_xloc(e,i){e&&!e._deleted&&(e.xloc=i)}set_yloc(e,i){e&&!e._deleted&&(e.yloc=i)}set_point(e,i){e&&!e._deleted&&i&&(i.index!==void 0?(e.x=i.index,e.xloc="bi"):i.time!==void 0&&(e.x=i.time,e.xloc="bt"),e.y=i.price)}get_x(e){return e?e.x:NaN}get_y(e){return e?e.y:NaN}get_text(e){return e?e.text:""}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._labels.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_label_down(){return"style_label_down"}get style_label_up(){return"style_label_up"}get style_label_left(){return"style_label_left"}get style_label_right(){return"style_label_right"}get style_label_lower_left(){return"style_label_lower_left"}get style_label_lower_right(){return"style_label_lower_right"}get style_label_upper_left(){return"style_label_upper_left"}get style_label_upper_right(){return"style_label_upper_right"}get style_label_center(){return"style_label_center"}get style_circle(){return"style_circle"}get style_square(){return"style_square"}get style_diamond(){return"style_diamond"}get style_flag(){return"style_flag"}get style_arrowup(){return"style_arrowup"}get style_arrowdown(){return"style_arrowdown"}get style_cross(){return"style_cross"}get style_xcross(){return"style_xcross"}get style_triangleup(){return"style_triangleup"}get style_triangledown(){return"style_triangledown"}get style_none(){return"style_none"}get style_text_outline(){return"style_text_outline"}}var yf=Object.defineProperty,xf=(t,e,i)=>e in t?yf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,xe=(t,e,i)=>xf(t,typeof e!="symbol"?e+"":e,i);let _f=0;class lr{constructor(e,i,r,s,a="bi",n="none",o="",l="style_solid",c=1,h=!1){xe(this,"id"),xe(this,"x1"),xe(this,"y1"),xe(this,"x2"),xe(this,"y2"),xe(this,"xloc"),xe(this,"extend"),xe(this,"color"),xe(this,"style"),xe(this,"width"),xe(this,"force_overlay"),xe(this,"_deleted"),xe(this,"_helper"),xe(this,"_createdAtBar",-1),this.id=_f++,this.x1=e,this.y1=i,this.x2=r,this.y2=s,this.xloc=a,this.extend=n,this.color=o,this.style=l,this.width=c,this.force_overlay=h,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,i){this._helper?this._helper.set_xy1(this,e,i):this._deleted||(this.x1=e,this.y1=i)}set_xy2(e,i){this._helper?this._helper.set_xy2(this,e,i):this._deleted||(this.x2=e,this.y2=i)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_width(e){this._helper?this._helper.set_width(this,e):this._deleted||(this.width=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.x1=e,this.x2=i,this.xloc=r)}set_first_point(e){this._helper&&this._helper.set_first_point(this,e)}set_second_point(e){this._helper&&this._helper.set_second_point(this,e)}get_x1(){return this.x1}get_y1(){return this.y1}get_x2(){return this.x2}get_y2(){return this.y2}get_price(e){return this._helper?this._helper.get_price(this,e):NaN}delete(){this._deleted=!0}copy(){return new lr(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}}var bf=Object.defineProperty,vf=(t,e,i)=>e in t?bf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,wf=(t,e,i)=>vf(t,typeof e!="symbol"?e+"":e,i);const Sf=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],Ef={x1:"number",y1:"number",x2:"number",y2:"number",xloc:"string",extend:"string",color:"color",style:"string",width:"number",force_overlay:"boolean",first_point:"point",second_point:"point"};class Nf{constructor(e){this.context=e,wf(this,"_lines",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._lines.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],s.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:s,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_createLine(e,i,r,s,a="bi",n="none",o="",l="style_solid",c=1,h=!1){const p=new lr(e,i,r,s,a,this._resolve(n),this._resolve(o),this._resolve(l),this._resolve(c)||1,h);return p._helper=this,p._createdAtBar=this.context.idx,this._lines.push(p),this._enforceMaxCount(),this.syncToPlot(),p}_enforceMaxCount(){const e=this.context.indicator?.max_lines_count??50,i=this._lines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._lines){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}new(...e){const i=se(e,Sf,Ef);let r,s,a,n,o=i.xloc;if(i.first_point instanceof me){const l=i.first_point,c=i.second_point,h=this._resolvePoint(l);r=h.x,s=l.price,o=o||h.xloc,c instanceof me?(a=this._resolvePoint(c).x,n=c.price):(a=0,n=NaN)}else r=i.x1,s=i.y1,a=i.x2,n=i.y2;return this._createLine(r,s,a,n,o,i.extend,i.color,i.style,i.width,i.force_overlay)}any(...e){return this.new(...e)}set_x1(e,i){e&&!e._deleted&&(e.x1=this._resolve(i))}set_y1(e,i){e&&!e._deleted&&(e.y1=this._resolve(i))}set_x2(e,i){e&&!e._deleted&&(e.x2=this._resolve(i))}set_y2(e,i){e&&!e._deleted&&(e.y2=this._resolve(i))}set_xy1(e,i,r){e&&!e._deleted&&(e.x1=this._resolve(i),e.y1=this._resolve(r))}set_xy2(e,i,r){e&&!e._deleted&&(e.x2=this._resolve(i),e.y2=this._resolve(r))}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i))}set_width(e,i){e&&!e._deleted&&(e.width=this._resolve(i)||1)}set_style(e,i){e&&!e._deleted&&(e.style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_xloc(e,i,r,s){e&&!e._deleted&&(e.x1=i,e.x2=r,e.xloc=s)}set_first_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x1=r.x,e.y1=i.price,e.xloc=r.xloc}}set_second_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x2=r.x,e.y2=i.price,e.xloc=r.xloc}}get_x1(e){return e?e.x1:NaN}get_y1(e){return e?e.y1:NaN}get_x2(e){return e?e.x2:NaN}get_y2(e){return e?e.y2:NaN}get_price(e,i){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;const r=e.x2-e.x1;return r===0?e.y1:e.y1+(i-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._lines.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(i=>i._createdAtBar<e),this.syncToPlot()}get style_solid(){return"style_solid"}get style_dotted(){return"style_dotted"}get style_dashed(){return"style_dashed"}get style_arrow_left(){return"style_arrow_left"}get style_arrow_right(){return"style_arrow_right"}get style_arrow_both(){return"style_arrow_both"}}var Cf=Object.defineProperty,If=(t,e,i)=>e in t?Cf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,X=(t,e,i)=>If(t,typeof e!="symbol"?e+"":e,i);let kf=0;class cr{constructor(e,i,r,s,a="bi",n="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",w="format_none",v=!1){X(this,"id"),X(this,"left"),X(this,"top"),X(this,"right"),X(this,"bottom"),X(this,"xloc"),X(this,"extend"),X(this,"border_color"),X(this,"border_style"),X(this,"border_width"),X(this,"bgcolor"),X(this,"text"),X(this,"text_color"),X(this,"text_size"),X(this,"text_halign"),X(this,"text_valign"),X(this,"text_wrap"),X(this,"text_font_family"),X(this,"text_formatting"),X(this,"force_overlay"),X(this,"_deleted"),X(this,"_helper"),X(this,"_createdAtBar",-1),this.id=kf++,this.left=e,this.top=i,this.right=r,this.bottom=s,this.xloc=a,this.extend=n,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=h,this.text=p,this.text_color=u,this.text_size=f,this.text_halign=m,this.text_valign=x,this.text_wrap=_,this.text_font_family=b,this.text_formatting=w,this.force_overlay=v,this._deleted=!1,this._helper=null}set_left(e){this._helper?this._helper.set_left(this,e):this._deleted||(this.left=e)}set_right(e){this._helper?this._helper.set_right(this,e):this._deleted||(this.right=e)}set_top(e){this._helper?this._helper.set_top(this,e):this._deleted||(this.top=e)}set_bottom(e){this._helper?this._helper.set_bottom(this,e):this._deleted||(this.bottom=e)}set_lefttop(e,i){this._helper?this._helper.set_lefttop(this,e,i):this._deleted||(this.left=e,this.top=i)}set_rightbottom(e,i){this._helper?this._helper.set_rightbottom(this,e,i):this._deleted||(this.right=e,this.bottom=i)}set_top_left_point(e){this._helper&&this._helper.set_top_left_point(this,e)}set_bottom_right_point(e){this._helper&&this._helper.set_bottom_right_point(this,e)}set_xloc(e,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.left=e,this.right=i,this.xloc=r)}set_bgcolor(e){this._helper?this._helper.set_bgcolor(this,e):this._deleted||(this.bgcolor=e)}set_border_color(e){this._helper?this._helper.set_border_color(this,e):this._deleted||(this.border_color=e)}set_border_width(e){this._helper?this._helper.set_border_width(this,e):this._deleted||(this.border_width=e)}set_border_style(e){this._helper?this._helper.set_border_style(this,e):this._deleted||(this.border_style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_text_color(e){this._helper?this._helper.set_text_color(this,e):this._deleted||(this.text_color=e)}set_text_size(e){this._helper?this._helper.set_text_size(this,e):this._deleted||(this.text_size=e)}set_text_halign(e){this._helper?this._helper.set_text_halign(this,e):this._deleted||(this.text_halign=e)}set_text_valign(e){this._helper?this._helper.set_text_valign(this,e):this._deleted||(this.text_valign=e)}set_text_wrap(e){this._helper?this._helper.set_text_wrap(this,e):this._deleted||(this.text_wrap=e)}set_text_font_family(e){this._helper?this._helper.set_text_font_family(this,e):this._deleted||(this.text_font_family=e)}set_text_formatting(e){this._helper?this._helper.set_text_formatting(this,e):this._deleted||(this.text_formatting=e)}get_left(){return this.left}get_right(){return this.right}get_top(){return this.top}get_bottom(){return this.bottom}delete(){this._deleted=!0}toPlotData(){return{id:this.id,left:this.left,top:this.top,right:this.right,bottom:this.bottom,xloc:this.xloc,extend:this.extend,border_color:this.border_color,border_style:this.border_style,border_width:this.border_width,bgcolor:this.bgcolor,text:this.text,text_color:this.text_color,text_size:this.text_size,text_halign:this.text_halign,text_valign:this.text_valign,text_wrap:this.text_wrap,text_font_family:this.text_font_family,text_formatting:this.text_formatting,force_overlay:this.force_overlay,_deleted:this._deleted}}copy(){return new cr(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}}var Af=Object.defineProperty,Tf=(t,e,i)=>e in t?Af(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Pf=(t,e,i)=>Tf(t,typeof e!="symbol"?e+"":e,i);const Df=[["left","top","right","bottom","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"],["top_left","bottom_right","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"]],Mf={left:"number",top:"number",right:"number",bottom:"number",top_left:"point",bottom_right:"point",border_color:"color",border_width:"number",border_style:"string",extend:"string",xloc:"string",bgcolor:"color",text:"string",text_size:"string",text_color:"color",text_halign:"string",text_valign:"string",text_wrap:"string",text_font_family:"string",force_overlay:"boolean"};class Rf{constructor(e){this.context=e,Pf(this,"_boxes",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._boxes.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],s.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:s,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){return e.index!==void 0?{x:e.index,xloc:"bi"}:e.time!==void 0?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_createBox(e,i,r,s,a="bi",n="none",o="#2962ff",l="style_solid",c=1,h="#2962ff",p="",u="#000000",f="auto",m="center",x="center",_="wrap_none",b="default",w="format_none",v=!1){const E=new cr(e,i,r,s,a,this._resolve(n),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(h,"#2962ff"),this._resolve(p)||"",this._resolveColor(u,"#000000"),this._resolve(f)||"auto",this._resolve(m)||"center",this._resolve(x)||"center",this._resolve(_)||"wrap_none",this._resolve(b)||"default",this._resolve(w)||"format_none",v);return E._helper=this,E._createdAtBar=this.context.idx,this._boxes.push(E),this._enforceMaxCount(),this.syncToPlot(),E}_enforceMaxCount(){const e=this.context.indicator?.max_boxes_count??50,i=this._boxes.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._boxes){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}new(...e){const i=se(e,Df,Mf);let r,s,a,n,o=i.xloc;if(i.top_left instanceof me){const l=i.top_left,c=i.bottom_right,h=this._resolvePoint(l);r=h.x,s=l.price,o=o||h.xloc,c instanceof me?(a=this._resolvePoint(c).x,n=c.price):(a=0,n=NaN)}else r=this._resolve(i.left),s=this._resolve(i.top),a=this._resolve(i.right),n=this._resolve(i.bottom);return this._createBox(r,s,a,n,o,i.extend,i.border_color,i.border_style,i.border_width,i.bgcolor,i.text,i.text_color,i.text_size,i.text_halign,i.text_valign,i.text_wrap,i.text_font_family,void 0,i.force_overlay)}any(...e){return this.new(...e)}set_left(e,i){e&&!e._deleted&&(e.left=this._resolve(i))}set_right(e,i){e&&!e._deleted&&(e.right=this._resolve(i))}set_top(e,i){e&&!e._deleted&&(e.top=this._resolve(i))}set_bottom(e,i){e&&!e._deleted&&(e.bottom=this._resolve(i))}set_lefttop(e,i,r){e&&!e._deleted&&(e.left=this._resolve(i),e.top=this._resolve(r))}set_rightbottom(e,i,r){e&&!e._deleted&&(e.right=this._resolve(i),e.bottom=this._resolve(r))}set_top_left_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.left=r.x,e.top=i.price,e.xloc=r.xloc}}set_bottom_right_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.right=r.x,e.bottom=i.price,e.xloc=r.xloc}}set_xloc(e,i,r,s){e&&!e._deleted&&(e.left=this._resolve(i),e.right=this._resolve(r),e.xloc=this._resolve(s))}set_bgcolor(e,i){e&&!e._deleted&&(e.bgcolor=this._resolve(i))}set_border_color(e,i){e&&!e._deleted&&(e.border_color=this._resolve(i))}set_border_width(e,i){e&&!e._deleted&&(e.border_width=this._resolve(i)??1)}set_border_style(e,i){e&&!e._deleted&&(e.border_style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_text(e,i){e&&!e._deleted&&(e.text=this._resolve(i)||"")}set_text_color(e,i){e&&!e._deleted&&(e.text_color=this._resolve(i))}set_text_size(e,i){e&&!e._deleted&&(e.text_size=this._resolve(i))}set_text_halign(e,i){e&&!e._deleted&&(e.text_halign=this._resolve(i))}set_text_valign(e,i){e&&!e._deleted&&(e.text_valign=this._resolve(i))}set_text_wrap(e,i){e&&!e._deleted&&(e.text_wrap=this._resolve(i))}set_text_font_family(e,i){e&&!e._deleted&&(e.text_font_family=this._resolve(i))}set_text_formatting(e,i){e&&!e._deleted&&(e.text_formatting=this._resolve(i))}get_left(e){return e?e.left:NaN}get_right(e){return e?e.right:NaN}get_top(e){return e?e.top:NaN}get_bottom(e){return e?e.bottom:NaN}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._boxes.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(i=>i._createdAtBar<e),this.syncToPlot()}}var Of=Object.defineProperty,Vf=(t,e,i)=>e in t?Of(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,It=(t,e,i)=>Vf(t,typeof e!="symbol"?e+"":e,i);let Lf=0;class $f{constructor(e,i,r){It(this,"id"),It(this,"line1"),It(this,"line2"),It(this,"color"),It(this,"_deleted"),It(this,"_createdAtBar",-1),this.id=Lf++,this.line1=e,this.line2=i,this.color=r,this._deleted=!1}get_line1(){return this.line1}get_line2(){return this.line2}set_color(e){this._deleted||(typeof e=="function"&&(e=e()),e&&typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"&&(e=e.get(0)),this.color=e||"")}delete(){this._deleted=!0}toPlotData(){const e=r=>r?{id:r.id,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,xloc:r.xloc,extend:r.extend,color:r.color,style:r.style,width:r.width,_deleted:r._deleted}:null,i=!!(this.line1?.force_overlay||this.line2?.force_overlay);return{id:this.id,line1:e(this.line1),line2:e(this.line2),color:this.color,force_overlay:i,_deleted:this._deleted}}}var jf=Object.defineProperty,Bf=(t,e,i)=>e in t?jf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ff=(t,e,i)=>Bf(t,typeof e!="symbol"?e+"":e,i);class Wf{constructor(e){this.context=e,Ff(this,"_linefills",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._linefills.map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),s=i.filter(a=>a.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:r,options:{style:"linefill"}}],s.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:s,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(e,i,r){const s=this._resolve(e),a=this._resolve(i),n=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolve(n)||"";if(s&&a){const c=s.id,h=a.id;for(const p of this._linefills){if(p._deleted)continue;const u=p.line1?.id,f=p.line2?.id;if(u===c&&f===h||u===h&&f===c)return p.color=o,p._createdAtBar=this.context.idx,this.syncToPlot(),p}}const l=new $f(s,a,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),this.syncToPlot(),l}any(...e){return this.new(e[0],e[1],e[2])}set_color(e,i){e&&!e._deleted&&(e.color=this._resolve(i)||"")}get_line1(e){return e?e.line1:void 0}get_line2(e){return e?e.line2:void 0}delete(e){e&&(e._deleted=!0)}get all(){return this._linefills.filter(e=>!e._deleted)}rollbackFromBar(e){this._linefills=this._linefills.filter(i=>i._createdAtBar<e),this.syncToPlot()}}var Uf=Object.defineProperty,qf=(t,e,i)=>e in t?Uf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,De=(t,e,i)=>qf(t,typeof e!="symbol"?e+"":e,i);let Kf=0;class zf{constructor(e,i=!1,r=!1,s="bi",a="#2962ff",n="",o="style_solid",l=1,c=!1){De(this,"id"),De(this,"points"),De(this,"curved"),De(this,"closed"),De(this,"xloc"),De(this,"line_color"),De(this,"fill_color"),De(this,"line_style"),De(this,"line_width"),De(this,"force_overlay"),De(this,"_deleted"),De(this,"_createdAtBar",-1),this.id=Kf++,this.points=e,this.curved=i,this.closed=r,this.xloc=s,this.line_color=a,this.fill_color=n,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}}var Hf=Object.defineProperty,Gf=(t,e,i)=>e in t?Hf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Yf=(t,e,i)=>Gf(t,typeof e!="symbol"?e+"":e,i);class Xf{constructor(e){this.context=e,Yf(this,"_polylines",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(i=>i.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof Vt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return typeof r=="number"&&isNaN(r)?NaN:r||i}_extractPoints(e){let i=this._resolve(e);const r=i&&i.array?i.array:i;return Array.isArray(r)?r.filter(s=>s instanceof me):[]}new(...e){let i,r=!1,s=!1,a="bi",n="#2962ff",o="",l="style_solid",c=1,h=!1;const p=_=>{r=_.curved??r,s=_.closed??s,a=_.xloc??a,n=_.line_color??n,o=_.fill_color??o,l=_.line_style??l,c=_.line_width??c,h=_.force_overlay??h},u=e.length>=1?e[e.length-1]:null,f=e.length>=2&&u&&typeof u=="object"&&!Array.isArray(u)&&!(u instanceof g)&&!(u instanceof me);if(e.length===1&&u&&typeof u=="object"&&!Array.isArray(u)&&"points"in u)i=u.points,p(u);else{const _=f?e.slice(0,-1):e;i=_[0],r=_[1]??r,s=_[2]??s,a=_[3]??a,n=_[4]??n,o=_[5]??o,l=_[6]??l,c=_[7]??c,h=_[8]??h,f&&p(u)}const m=this._extractPoints(i),x=new zf(m,this._resolve(r)??!1,this._resolve(s)??!1,this._resolve(a)||"bi",this._resolveColor(n,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(h)??!1);return x._createdAtBar=this.context.idx,this._polylines.push(x),this._enforceMaxCount(),this.syncToPlot(),x}_enforceMaxCount(){const e=this.context.indicator?.max_polylines_count??50,i=this._polylines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let s=0;for(const a of this._polylines){if(s>=r)break;a._deleted||(a._deleted=!0,s++)}}}any(...e){return this.new(...e)}delete(e){e&&(e._deleted=!0)}get all(){return this._polylines.filter(e=>!e._deleted)}rollbackFromBar(e){this._polylines=this._polylines.filter(i=>i._createdAtBar<e),this.syncToPlot()}}var Qf=Object.defineProperty,Zf=(t,e,i)=>e in t?Qf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,_e=(t,e,i)=>Zf(t,typeof e!="symbol"?e+"":e,i);let Jf=0;class ed{constructor(e="top_right",i=1,r=1,s="",a="",n=0,o="",l=0,c=!1){_e(this,"id"),_e(this,"position"),_e(this,"columns"),_e(this,"rows"),_e(this,"bgcolor"),_e(this,"frame_color"),_e(this,"frame_width"),_e(this,"border_color"),_e(this,"border_width"),_e(this,"force_overlay"),_e(this,"_deleted"),_e(this,"cells"),_e(this,"merges"),_e(this,"_helper"),this.id=Jf++,this.position=e,this.columns=i,this.rows=r,this.bgcolor=s,this.frame_color=a,this.frame_width=n,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let h=0;h<r;h++){this.cells[h]=[];for(let p=0;p<i;p++)this.cells[h][p]=null}}delete(){this._deleted=!0}toPlotData(){const e=this.cells.map(i=>i.map(r=>r?{...r}:null));return{id:this.id,position:this.position,columns:this.columns,rows:this.rows,bgcolor:this.bgcolor,frame_color:this.frame_color,frame_width:this.frame_width,border_color:this.border_color,border_width:this.border_width,force_overlay:this.force_overlay,_deleted:this._deleted,cells:e,merges:this.merges.map(i=>({...i}))}}setCell(e,i,r){if(i<0||i>=this.rows||e<0||e>=this.columns)return;const s=this.cells[i][e];if(s&&s._merged&&s._merge_parent){const[n,o]=s._merge_parent;if(n===e&&o===i)s._merged=!1,s._merge_parent=void 0;else{this.setCell(n,o,r);return}}const a=s||this._defaultCell();Object.assign(a,r),this.cells[i][e]=a}getCell(e,i){return i<0||i>=this.rows||e<0||e>=this.columns?null:this.cells[i][e]}clearCell(e,i){i<0||i>=this.rows||e<0||e>=this.columns||(this.cells[i][e]=null)}_setHelper(e){this._helper=e}cell(...e){return this._helper.cell(this,...e)}clear(...e){return this._helper.clear(this,...e)}merge_cells(...e){return this._helper.merge_cells(this,...e)}cell_set_text(...e){return this._helper.cell_set_text(this,...e)}cell_set_bgcolor(...e){return this._helper.cell_set_bgcolor(this,...e)}cell_set_text_color(...e){return this._helper.cell_set_text_color(this,...e)}cell_set_text_size(...e){return this._helper.cell_set_text_size(this,...e)}cell_set_height(...e){return this._helper.cell_set_height(this,...e)}cell_set_width(...e){return this._helper.cell_set_width(this,...e)}cell_set_tooltip(...e){return this._helper.cell_set_tooltip(this,...e)}cell_set_text_halign(...e){return this._helper.cell_set_text_halign(this,...e)}cell_set_text_valign(...e){return this._helper.cell_set_text_valign(this,...e)}cell_set_text_font_family(...e){return this._helper.cell_set_text_font_family(this,...e)}set_position(...e){return this._helper.set_position(this,...e)}set_bgcolor(...e){return this._helper.set_bgcolor(this,...e)}set_border_color(...e){return this._helper.set_border_color(this,...e)}set_border_width(...e){return this._helper.set_border_width(this,...e)}set_frame_color(...e){return this._helper.set_frame_color(this,...e)}set_frame_width(...e){return this._helper.set_frame_width(this,...e)}_defaultCell(){return{text:"",width:0,height:0,text_color:"#000000",text_halign:"center",text_valign:"center",text_size:"normal",bgcolor:"",tooltip:"",text_font_family:"default",_merged:!1,_merge_parent:null}}}var td=Object.defineProperty,id=(t,e,i)=>e in t?td(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,rd=(t,e,i)=>id(t,typeof e!="symbol"?e+"":e,i);class sd{constructor(e){this.context=e,rd(this,"_tables",[])}param(e,i=0,r){return g.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__tables__.data=[{time:e,value:this._tables.map(i=>i.toPlotData()),options:{style:"table"}}]}_resolve(e){return e==null?e:typeof e=="object"&&"__value"in e?e.__value:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(...e){let i="top_right",r=1,s=1,a="",n="",o=0,l="",c=0,h=!1;const p=e[e.length-1];if(p&&typeof p=="object"&&!Array.isArray(p)&&("bgcolor"in p||"frame_color"in p||"border_color"in p||"position"in p||"columns"in p||"rows"in p)){const f=p,m=e.slice(0,-1);i=m[0]??f.position??i,r=m[1]??f.columns??r,s=m[2]??f.rows??s,a=f.bgcolor??a,n=f.frame_color??n,o=f.frame_width??o,l=f.border_color??l,c=f.border_width??c,h=f.force_overlay??h}else i=e[0]??i,r=e[1]??r,s=e[2]??s,a=e[3]??a,n=e[4]??n,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h;const u=new ed(this._resolve(i)||"top_right",this._resolve(r)||1,this._resolve(s)||1,this._resolve(a)||"",this._resolve(n)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(h)??!1);return u._setHelper(this),this._tables.push(u),this.syncToPlot(),u}any(...e){return this.new(...e)}cell(...e){let i,r,s,a="",n=0,o=0,l="#000000",c="center",h="center",p="normal",u="",f="",m="default";const x=e[e.length-1];if(x&&typeof x=="object"&&!Array.isArray(x)&&("text"in x||"bgcolor"in x||"text_color"in x||"text_size"in x||"text_halign"in x||"tooltip"in x||"column"in x||"row"in x||"height"in x||"width"in x||"text_valign"in x||"text_font_family"in x)){const v=x,E=e.slice(0,-1);i=E[0],r=E.length>1?E[1]:v.column??0,s=E.length>2?E[2]:v.row??0,a=E[3]??v.text??a,n=E[4]??v.width??n,o=E[5]??v.height??o,l=E[6]??v.text_color??l,c=E[7]??v.text_halign??c,h=E[8]??v.text_valign??h,p=E[9]??v.text_size??p,u=E[10]??v.bgcolor??u,f=E[11]??v.tooltip??f,m=E[12]??v.text_font_family??m}else i=e[0],r=e[1]??0,s=e[2]??0,a=e[3]??a,n=e[4]??n,o=e[5]??o,l=e[6]??l,c=e[7]??c,h=e[8]??h,p=e[9]??p,u=e[10]??u,f=e[11]??f,m=e[12]??m;const _=this._resolve(i);if(!_||_._deleted)return;const b=this._resolve(r)??0,w=this._resolve(s)??0;_.setCell(b,w,{text:this._resolveText(this._resolve(a)),width:this._resolve(n)||0,height:this._resolve(o)||0,text_color:this._resolve(l)||"#000000",text_halign:this._resolve(c)||"center",text_valign:this._resolve(h)||"center",text_size:this._resolve(p)||"normal",bgcolor:this._resolve(u)||"",tooltip:this._resolveText(this._resolve(f)),text_font_family:this._resolve(m)||"default"}),this.syncToPlot()}delete(e){e&&(e._deleted=!0)}clear(...e){let i,r,s,a,n;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,s=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:r),n=f.end_row??(e.length>5?e[4]:s)}else i=e[0],r=e[1]??0,s=e[2]??0,a=e[3]??r,n=e[4]??s;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(s)??0,p=this._resolve(a)??c,u=this._resolve(n)??h;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)l.clearCell(m,f);this.syncToPlot()}merge_cells(...e){let i,r,s,a,n;const o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,s=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:0),n=f.end_row??(e.length>5?e[4]:0)}else i=e[0],r=e[1]??0,s=e[2]??0,a=e[3]??0,n=e[4]??0;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,h=this._resolve(s)??0,p=this._resolve(a)??0,u=this._resolve(n)??0;for(let f=h;f<=u;f++)for(let m=c;m<=p;m++)f===h&&m===c||l.setCell(m,f,{_merged:!0,_merge_parent:[c,h]});l.merges.push({startCol:c,startRow:h,endCol:p,endRow:u}),this.syncToPlot()}cell_set_text(e,i,r,s){this._setCellProp(e,i,r,"text",s,!0)}cell_set_bgcolor(e,i,r,s){this._setCellProp(e,i,r,"bgcolor",s)}cell_set_text_color(e,i,r,s){this._setCellProp(e,i,r,"text_color",s)}cell_set_text_size(e,i,r,s){this._setCellProp(e,i,r,"text_size",s)}cell_set_height(e,i,r,s){this._setCellProp(e,i,r,"height",s)}cell_set_width(e,i,r,s){this._setCellProp(e,i,r,"width",s)}cell_set_tooltip(e,i,r,s){this._setCellProp(e,i,r,"tooltip",s,!0)}cell_set_text_halign(e,i,r,s){this._setCellProp(e,i,r,"text_halign",s)}cell_set_text_valign(e,i,r,s){this._setCellProp(e,i,r,"text_valign",s)}cell_set_text_font_family(e,i,r,s){this._setCellProp(e,i,r,"text_font_family",s)}set_position(e,i){const r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(i)||r.position,this.syncToPlot())}set_bgcolor(e,i){const r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(i)||"",this.syncToPlot())}set_border_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(i)||"",this.syncToPlot())}set_border_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(i)||0,this.syncToPlot())}set_frame_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(i)||"",this.syncToPlot())}set_frame_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(i)||0,this.syncToPlot())}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,i,r,s,a,n=!1){const o=this._resolve(e);if(!o||o._deleted)return;const l=this._resolve(i)??0,c=this._resolve(r)??0,h=this._resolve(a);o.setCell(l,c,{[s]:n?this._resolveText(h):h}),this.syncToPlot()}_resolveText(e){return e==null||e!==e?"":String(e)}}var nd=Object.defineProperty,ad=(t,e,i)=>e in t?nd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,$=(t,e,i)=>ad(t,typeof e!="symbol"?e+"":e,i);const Yi=class oi{constructor({marketData:e,source:i,tickerId:r,timeframe:s,limit:a,sDate:n,eDate:o,fullContext:l,inputs:c}){$(this,"data",{open:new g([]),high:new g([]),low:new g([]),close:new g([]),volume:new g([]),hl2:new g([]),hlc3:new g([]),ohlc4:new g([]),hlcc4:new g([]),bar_index:new g([])}),$(this,"indicator"),$(this,"cache",{}),$(this,"taState",{}),$(this,"isSecondaryContext",!1),$(this,"chartTimezone",null),$(this,"dataVersion",0),$(this,"__maxLoops",5e5),$(this,"NA",NaN),$(this,"warnings",[]),$(this,"alerts",[]),$(this,"_alertMode","realtime"),$(this,"_execTick",0),$(this,"lang"),$(this,"length",0),$(this,"_drawingHelpers",[]),$(this,"pine"),$(this,"idx",0),$(this,"params",{}),$(this,"const",{}),$(this,"var",{}),$(this,"let",{}),$(this,"lctx",new Map),$(this,"result"),$(this,"plots",{}),$(this,"marketData"),$(this,"source"),$(this,"tickerId"),$(this,"timeframe",""),$(this,"limit"),$(this,"sDate"),$(this,"eDate"),$(this,"fullContext"),$(this,"pineTSCode"),$(this,"inputs",{}),$(this,"_callStack",[]),this.marketData=e,this.source=i,this.tickerId=r,this.timeframe=s,this.limit=a,this.sDate=n,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};const h=new Hc(this),p={Type:h.Type.bind(h),na:new Vt,nz:h.nz.bind(h),indicator:h.indicator.bind(h),fixnan:h.fixnan.bind(h),alertcondition:h.alertcondition.bind(h),alert:new zc(this),error:h.error.bind(h),max_bars_back:h.max_bars_back.bind(h),timestamp:h.timestamp.bind(h),time:new Rr(this,"openTime"),time_close:new Rr(this,"closeTime"),dayofmonth:new nt(this,at.dayofmonth),dayofweek:new nt(this,at.dayofweek),hour:new nt(this,at.hour),minute:new nt(this,at.minute),month:new nt(this,at.month),second:new nt(this,at.second),weekofyear:new nt(this,at.weekofyear),year:new nt(this,at.year),bool:h.bool.bind(h),int:h.int.bind(h),float:h.float.bind(h),string:h.string.bind(h)},u=this;this.pine={input:new Eh(this),ta:new Ap(this),math:new au(this),request:new fu(this),array:new gl(this),map:new Pl(this),matrix:new Pc(this),syminfo:null,timeframe:new Lp(this),barstate:new Oc(this),get bar_index(){return u.data.bar_index},get last_bar_index(){return u.data.close.length-1},get last_bar_time(){return u.data.openTime.get(u.data.openTime.length-1)},get timenow(){return new Date().getTime()},get time_tradingday(){const z=g.from(u.data.closeTime).get(0);if(isNaN(z))return NaN;const q=u.pine?.syminfo?.timezone||"UTC",V=Pt(z,q);return Date.UTC(V.year,V.month-1,V.day,0,0,0)},get inputs(){return u.inputs},log:new Dp(this),str:new Mp(this),...p,...Ho};const f=p.dayofweek;Object.assign(f,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=f;const m=new ef(this),x=new tf(this),_=new rf(this);this.bindContextObject(m,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(m,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(x,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(_,["any","param"],"fill");const b=new of(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),is_standard:b.is_standard.bind(b),is_heikinashi:b.is_heikinashi.bind(b),is_kagi:b.is_kagi.bind(b),is_linebreak:b.is_linebreak.bind(b),is_pnf:b.is_pnf.bind(b),is_range:b.is_range.bind(b),is_renko:b.is_renko.bind(b),point:b.point};const w=new gf(this);this.bindContextObject(w,["any","new","param","set_x","set_y","set_xy","set_text","set_color","set_textcolor","set_size","set_style","set_textalign","set_tooltip","set_point","set_xloc","set_yloc","get_x","get_y","get_text","copy","delete","style_label_down","style_label_up","style_label_left","style_label_right","style_label_lower_left","style_label_lower_right","style_label_upper_left","style_label_upper_right","style_label_center","style_circle","style_square","style_diamond","style_flag","style_arrowup","style_arrowdown","style_cross","style_xcross","style_triangleup","style_triangledown","style_none","style_text_outline"],"label"),Object.defineProperty(this.pine.label,"all",{get:()=>w.all});const v=new Nf(this);this.bindContextObject(v,["any","new","param","set_x1","set_y1","set_x2","set_y2","set_xy1","set_xy2","set_color","set_width","set_style","set_extend","set_xloc","set_first_point","set_second_point","get_x1","get_y1","get_x2","get_y2","get_price","copy","delete","style_solid","style_dotted","style_dashed","style_arrow_left","style_arrow_right","style_arrow_both"],"line"),Object.defineProperty(this.pine.line,"all",{get:()=>v.all});const E=new Rf(this);this.bindContextObject(E,["any","new","param","copy","delete","set_left","set_right","set_top","set_bottom","set_lefttop","set_rightbottom","set_top_left_point","set_bottom_right_point","set_bgcolor","set_border_color","set_border_width","set_border_style","set_extend","set_xloc","set_text","set_text_color","set_text_size","set_text_halign","set_text_valign","set_text_wrap","set_text_font_family","set_text_formatting","get_left","get_right","get_top","get_bottom"],"box"),Object.defineProperty(this.pine.box,"all",{get:()=>E.all});const T=new Wf(this);this.bindContextObject(T,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>T.all});const C=new Xf(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>C.all});const O=new sd(this);this.bindContextObject(O,["any","new","param","cell","delete","clear","merge_cells","cell_set_text","cell_set_bgcolor","cell_set_text_color","cell_set_text_size","cell_set_height","cell_set_width","cell_set_tooltip","cell_set_text_halign","cell_set_text_valign","cell_set_text_font_family","set_position","set_bgcolor","set_border_color","set_border_width","set_frame_color","set_frame_width"],"table"),Object.defineProperty(this.pine.table,"all",{get:()=>O.all}),this._drawingHelpers=[w,v,E,T,C,O];const B=new Yc(this);this.bindContextObject(B,["any","param","new","rgb","from_gradient","r","g","b","t","aqua","black","blue","fuchsia","gray","green","lime","maroon","navy","olive","orange","purple","red","silver","teal","white","yellow"],"color")}warn(e,i){this.warnings.push({message:e,method:i,bar:this.idx})}rollbackDrawings(e){for(const i of this._drawingHelpers)i.rollbackFromBar(e)}bindContextObject(e,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const s=r?this.pine[r]:this.pine;for(const a of i)typeof e[a]=="function"?s[a]=e[a].bind(e):s[a]=e[a]}init(e,i,r=0){let s;return i instanceof g?s=i.get(0):Array.isArray(i)?Array.isArray(i[0])?s=i[0]:s=i[i.length-1+r]:s=i,e?e instanceof g?(e.data[e.data.length-1]=s,e):Array.isArray(e)?(e[e.length-1]=s,new g(e)):new g([s]):new g([s])}initVar(e,i){if(e)return e;if(typeof i=="function"&&(i=i()),i instanceof kt){const s=i.__def__;for(const a in s)typeof i[a]=="function"&&(i[a]=i[a]())}let r;return i instanceof g?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 g([r])}precision(e,i=10){const r=i===10?oi.PRECISION_EPSILON:10**i;return typeof e=="number"?Math.round(e*r)/r:e}param(e,i,r){return typeof e=="string"?e:e instanceof g?i?new g(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new g(e,i||0):(this.params[r].length===0?this.params[r].push(e):this.params[r][this.params[r].length-1]=e,new g(this.params[r],i||0)))}get(e,i){if(e instanceof g)return e.get(i);if(Array.isArray(e)){const r=e.length-1-i;return r<0||r>=e.length?NaN:e[r]}return e}set(e,i){if(e instanceof g){e.set(0,typeof i=="number"?this.precision(i):i);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=i:e.push(i);return}}pushId(e){this._callStack.push(e)}popId(){this._callStack.pop()}peekId(){return this._callStack.length>0?this._callStack[this._callStack.length-1]:""}peekCtx(){const e=this.peekId();if(!e)return this;let i=this.lctx.get(e);return i||(i={id:e,let:{},const:{},var:{}},this.lctx.set(e,i)),i}call(e,i,...r){this.pushId(i);try{return e(...r)}finally{this.popId()}}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,fill:this.pine.fill,plotchar:this.pine.plotchar,plotshape:this.pine.plotshape,plotarrow:this.pine.plotarrow,color:this.pine.color,plot:this.pine.plot,nz:this.pine.nz}}_showDeprecationWarning(e,i){const r=`${e}->${i}`;oi._deprecationWarningsShown.has(r)||(oi._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;",e,i):console.warn(`\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}};$(Yi,"_deprecationWarningsShown",new Set),$(Yi,"PRECISION_EPSILON",10**10);let Br=Yi;var od=Object.defineProperty,ld=(t,e,i)=>e in t?od(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Fr=(t,e,i)=>ld(t,typeof e!="symbol"?e+"":e,i);class Wr{constructor(e,i={}){Fr(this,"source"),Fr(this,"inputs"),this.source=e,this.inputs=i}}var cd=Object.defineProperty,hd=(t,e,i)=>e in t?cd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,J=(t,e,i)=>hd(t,typeof e!="symbol"?e+"":e,i);const Ur={1:6e4,3:18e4,5:3e5,15:9e5,30:18e5,60:36e5,120:72e5,180:108e5,240:144e5,"4H":144e5,"1D":864e5,D:864e5,"1W":6048e5,W:6048e5,"1M":30*864e5,M:30*864e5};function ud(t){return t?Ur[t]??Ur[t.toUpperCase()]??864e5:864e5}class dn{constructor(e,i,r,s,a,n){this.source=e,this.tickerId=i,this.timeframe=r,this.limit=s,this.sDate=a,this.eDate=n,J(this,"data",[]),J(this,"open",[]),J(this,"high",[]),J(this,"low",[]),J(this,"close",[]),J(this,"volume",[]),J(this,"hl2",[]),J(this,"hlc3",[]),J(this,"ohlc4",[]),J(this,"hlcc4",[]),J(this,"openTime",[]),J(this,"closeTime",[]),J(this,"_readyPromise",null),J(this,"_ready",!1),J(this,"_debugSettings",{ln:!1,debug:!1}),J(this,"_transpiledCode",null),J(this,"_isSecondaryContext",!1),J(this,"_syminfo"),J(this,"_chartTimezone",null),J(this,"_maxLoops",5e5),J(this,"_alertMode","realtime"),this._readyPromise=new Promise(o=>{this.loadMarketData(e,i,r,s,a,n).then(l=>{const c=l;this.data=c;const h=c.map(C=>C.open),p=c.map(C=>C.close),u=c.map(C=>C.high),f=c.map(C=>C.low),m=c.map(C=>C.volume),x=c.map(C=>(C.high+C.low+C.close)/3),_=c.map(C=>(C.high+C.low)/2),b=c.map(C=>(C.high+C.low+C.open+C.close)/4),w=c.map(C=>(C.high+C.low+C.close+C.close)/4),v=c.map(C=>C.openTime),E=ud(this.timeframe),T=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+E);this.open=h,this.close=p,this.high=u,this.low=f,this.volume=m,this.hl2=_,this.hlc3=x,this.ohlc4=b,this.hlcc4=w,this.openTime=v,this.closeTime=T,e&&e.getSymbolInfo?e.getSymbolInfo(i).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setTimezone(e){this._chartTimezone=e}setMaxLoops(e){this._maxLoops=e}setAlertMode(e){this._alertMode=e}setDebugSettings({ln:e,debug:i}){this._debugSettings.ln=e,this._debugSettings.debug=i}async loadMarketData(e,i,r,s,a,n){return Array.isArray(e)?e:e.getMarketData(i,r,s,a,n)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,i,r){let s,a={};if(e instanceof Wr?(s=e.source,a=e.inputs||{}):s=e,r&&r>0){const n=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(s,a,i,r,n)}else return this._runComplete(s,a,i)}stream(e,i={}){const{live:r=!0,interval:s=1e3}=i,a=i.pageSize||this.data.length;let n,o={};e instanceof Wr?(n=e.source,o=e.inputs||{}):n=e;const l={data:[],error:[],warning:[],alert:[]};let c=!1;const h=(f,...m)=>{l[f]&&l[f].forEach(x=>x(...m))},p=(f,m)=>{l[f]||(l[f]=[]),l[f].push(m)},u=()=>{c=!0};return(async()=>{try{r&&typeof this.eDate<"u"&&(this.eDate=Math.max(this.eDate,Date.now()));const f=!Array.isArray(this.source)&&r,m=this._runPaginated(n,o,void 0,a,f);for await(const x of m){if(c)break;if(x===null){await new Promise(_=>setTimeout(_,s));continue}if(h("data",x),x.warnings&&x.warnings.length>0){for(const _ of x.warnings)h("warning",_);x.warnings.length=0}if(x.alerts&&x.alerts.length>0){for(const _ of x.alerts)h("alert",_);x.alerts.length=0}if(f&&!c){const _=x.marketData[x.idx],b=_&&_.closeTime<Date.now(),w=x.idx>=x.marketData.length-1;(!b||w)&&await new Promise(v=>setTimeout(v,s))}}}catch(f){h("error",f)}})(),{on:p,stop:u}}async _runComplete(e,i,r){await this.ready(),r||(r=this.data.length);const s=this._initializeContext(e,i,this._isSecondaryContext);return this._transpiledCode=this._transpileCode(e),await this._executeIterations(s,this._transpiledCode,this.data.length-r,this.data.length),s}async*_runPaginated(e,i,r,s,a=!1){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(e,i,this._isSecondaryContext);this._transpiledCode=this._transpileCode(e);let o=this.data.length-r,l=null;for(;;){const c=this.data.length,h=c-o;if(h>0){const x=Math.min(h,s),_=this._getResultLength(n.result),b=o+x;a&&b>=c&&x>1?(await this._executeIterations(n,this._transpiledCode,o,b-1),l=this._snapshotVarState(n),await this._executeIterations(n,this._transpiledCode,b-1,b)):a&&b>=c&&x===1?await this._executeIterations(n,this._transpiledCode,o,b):await this._executeIterations(n,this._transpiledCode,o,b),o+=x,yield this._createPageContext(n,_);continue}if(!a||Array.isArray(this.source))break;const p=Date.now(),{newCandles:u,updatedLastCandle:f}=await this._updateMarketData(),m=Date.now()-p;if(u===0&&!f){yield null;continue}if(u===0&&f&&m<1e3&&await new Promise(x=>setTimeout(x,1e3-m)),n.dataVersion++,n.length=this.data.length,this._restoreVarState(n,l),Array.isArray(n.result))n.result.pop();else if(typeof n.result=="object"&&n.result!==null)for(let x in n.result)Array.isArray(n.result[x])&&n.result[x].pop();n.data.close.data.pop(),n.data.open.data.pop(),n.data.high.data.pop(),n.data.low.data.pop(),n.data.volume.data.pop(),n.data.hl2.data.pop(),n.data.hlc3.data.pop(),n.data.ohlc4.data.pop(),n.data.hlcc4.data.pop(),n.data.openTime.data.pop(),n.data.closeTime&&n.data.closeTime.data.pop(),n.data.bar_index.data.pop(),o=this.data.length-(u+1),n.rollbackDrawings(o),u>0&&(l=null),n.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const i=Object.keys(e);if(i.length>0&&Array.isArray(e[i[0]]))return e[i[0]].length}return 0}_createPageContext(e,i){const r=new Br({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:e,inputs:e.inputs});if(r.pineTSCode=e.pineTSCode,r.idx=e.idx,Array.isArray(e.result))r.result=e.result.slice(i);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let s in e.result)Array.isArray(e.result[s])?r.result[s]=e.result[s].slice(i):r.result[s]=e.result[s]}else r.result=e.result;return r.plots={...e.plots},r.warnings=e.warnings,r.alerts=e.alerts,r}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const i=this.source,r=this.data.length-1,s=this.data[r].openTime;try{const a=await i.getMarketData(this.tickerId,this.timeframe,void 0,s,e);if(!a||a.length===0)return{newCandles:0,updatedLastCandle:!1};let n=!1,o=0;for(let l=0;l<a.length;l++){const c=a[l];c.openTime===s?(this._replaceCandle(r,c),n=!0):c.openTime>s&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:n}}catch(a){return console.error("Error updating market data:",a),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,i){this.data[e]=i,this.open[e]=i.open,this.close[e]=i.close,this.high[e]=i.high,this.low[e]=i.low,this.volume[e]=i.volume,this.hl2[e]=(i.high+i.low)/2,this.hlc3[e]=(i.high+i.low+i.close)/3,this.ohlc4[e]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[e]=(i.high+i.low+i.close+i.close)/4,this.openTime[e]=i.openTime,this.closeTime[e]=i.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;const{newCandles:i,updatedLastCandle:r}=await this._updateMarketData();if(i===0&&!r)return!1;this._removeLastResult(e),e.length=this.data.length;const s=this.data.length-(i+1);return e.rollbackDrawings(s),await this._executeIterations(e,this._transpiledCode,s,this.data.length),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let s in e.result)Array.isArray(e.result[s])&&e.result[s].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();const i=["const","var","let","params"],r=s=>{for(let a of i)if(s[a])for(let n in s[a]){const o=s[a][n];o instanceof g?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(s=>r(s))}_snapshotVarState(e){const i=["const","var","let","params"],r={main:{},lctx:[]},s=a=>{const n={};for(const o of i)if(a[o]){n[o]={};for(const l in a[o]){const c=a[o][l];if(c instanceof g){const h=c.data.length,p=h>0?c.data[h-1]:void 0;n[o][l]={len:h,lastVal:p}}}}return n};if(r.main=s(e),e.lctx){const a=[];e.lctx.forEach(n=>a.push(s(n))),r.lctx=a}return r.resultLength=this._getResultLength(e.result),r.dataLength=e.data.close?.data?.length??0,r}_restoreVarState(e,i){if(!i)return;const r=["const","var","let","params"],s=(a,n)=>{for(const o of r)if(!(!n[o]||!a[o]))for(const l in n[o]){const c=a[o][l],h=n[o][l];c instanceof g&&h&&typeof h.len=="number"&&(c.data.length>h.len&&(c.data.length=h.len),h.len>0&&h.lastVal!==void 0&&(c.data[h.len-1]=h.lastVal))}};if(s(e,i.main),e.lctx&&i.lctx){let a=0;e.lctx.forEach(n=>{i.lctx[a]&&s(n,i.lctx[a]),a++})}}_initializeContext(e,i={},r=!1){const s=new Br({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:i});return s.pine.syminfo=this._syminfo,this._chartTimezone&&(s.chartTimezone=this._chartTimezone),s.__maxLoops=this._maxLoops,s._alertMode=this._alertMode,s.pineTSCode=e,s.isSecondaryContext=r,s.data.close=new g([]),s.data.open=new g([]),s.data.high=new g([]),s.data.low=new g([]),s.data.volume=new g([]),s.data.hl2=new g([]),s.data.hlc3=new g([]),s.data.ohlc4=new g([]),s.data.hlcc4=new g([]),s.data.openTime=new g([]),s.data.closeTime=new g([]),s.length=this.data.length,s}_transpileCode(e){return oo.bind(this)(e,this._debugSettings)}async _executeIterations(e,i,r,s){const a=["const","var","let","params"];for(let n=r;n<s;n++){e.idx=n,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[n]),e.data.open.data.push(this.open[n]),e.data.high.data.push(this.high[n]),e.data.low.data.push(this.low[n]),e.data.volume.data.push(this.volume[n]),e.data.hl2.data.push(this.hl2[n]),e.data.hlc3.data.push(this.hlc3[n]),e.data.ohlc4.data.push(this.ohlc4[n]),e.data.hlcc4.data.push(this.hlcc4[n]),e.data.openTime.data.push(this.openTime[n]),e.data.closeTime.data.push(this.closeTime[n]),e.data.bar_index.data.push(n);const o=await i(e);if(typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let h;o[c]instanceof g?h=o[c].get(0):Array.isArray(o[c])?h=o[c][o[c].length-1]:h=o[c],e.result[c].push(h)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(const c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();const l=c=>{for(let h of a)if(c[h])for(let p in c[h]){const u=c[h][p];if(u instanceof g){const f=u.get(0);u.data.push(f)}else if(Array.isArray(u)){const f=u[u.length-1];u.push(f)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}}}const qr={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},qt={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3},Zd={"1S":{periodType:"second",multiplier:1},"5S":{periodType:"second",multiplier:5},"10S":{periodType:"second",multiplier:10},"15S":{periodType:"second",multiplier:15},"30S":{periodType:"second",multiplier:30},1:{periodType:"minute",multiplier:1},3:{periodType:"minute",multiplier:3},5:{periodType:"minute",multiplier:5},15:{periodType:"minute",multiplier:15},30:{periodType:"minute",multiplier:30},45:{periodType:"minute",multiplier:45},60:{periodType:"hour",multiplier:1},120:{periodType:"hour",multiplier:2},180:{periodType:"hour",multiplier:3},240:{periodType:"hour",multiplier:4},D:{periodType:"day",multiplier:1},W:{periodType:"week",multiplier:1},M:{periodType:"month",multiplier:1}};function Kt(t,e,i=1){if(e==="month"){const s=new Date(t);return Date.UTC(s.getUTCFullYear(),s.getUTCMonth()+i,1,s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds(),s.getUTCMilliseconds())}const r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+i*r[e]}function qe(t,e,i){const[r,s,a]=t.split("-").map(Number),[n,o]=e.split(":").map(Number),l=Date.UTC(r,s-1,a,n,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(l)),h=b=>parseInt(c.find(w=>w.type===b).value,10);let p=h("year"),u=h("month"),f=h("day"),m=h("hour");m===24&&(m=0);let x=h("minute");const _=Date.UTC(p,u-1,f,m,x,0,0)-l;return l-_}function Kr(t,e,i,r,s=1){if(e==="24x7")return Kt(t,r,s);const a=e.split("-")[1];if(!a||a.length!==4)return Kt(t,r,s);const n=a.slice(0,2),o=a.slice(2,4),l=`${n}:${o}`,c=zr(t,i);if(r==="second"||r==="minute"||r==="hour"){const h=t+s*{second:1e3,minute:6e4,hour:36e5}[r],p=qe(c,l,i);return Math.min(h,p)}if(r==="day")return qe(c,l,i);if(r==="week"){const h=new Date(t).getUTCDay(),p=h<=5?5-h:5-h+7,u=t+p*864e5,f=zr(u,i);return qe(f,l,i)}if(r==="month"){const h=new Date(t),p=h.getUTCFullYear(),u=h.getUTCMonth()+s,f=new Date(Date.UTC(p,u,1)),m=new Date(f.getTime()-864e5);for(;m.getUTCDay()===0||m.getUTCDay()===6;)m.setUTCDate(m.getUTCDate()-1);const x=m.toISOString().split("T")[0];return qe(x,l,i)}return Kt(t,r,s)}function zr(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function pd(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}const fd=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function dd(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;const i=qt[t];if(!i)return null;const r=fd.filter(s=>s!=="W"&&s!=="M"&&e.has(s)&&qt[s]<i&&i%qt[s]===0);return r.length===0?null:r[r.length-1]}function mn(t,e){if(t==="W"||t==="M")return 1/0;const i=qt[t],r=qt[e];return!i||!r||r===0?1/0:i/r}function md(t,e,i){if(t.length===0)return[];if(e==="W")return yd(t);if(e==="M")return xd(t);const r=mn(e,i);return gd(t,r)}function gd(t,e){if(t.length===0)return[];const i=[];let r=[t[0]];const s=_d(t),a=s>0?s*1.5:0;for(let n=1;n<t.length;n++){const o=t[n].openTime-t[n-1].openTime;(a>0&&o>a||r.length>=e)&&(i.push(di(r)),r=[]),r.push(t[n])}return r.length>0&&i.push(di(r)),i}function yd(t){const e=[];let i=[],r="";for(const s of t){const a=bd(s.openTime);a!==r&&i.length>0&&(e.push(i),i=[]),r=a,i.push(s)}return i.length>0&&e.push(i),e.map(di)}function xd(t){const e=[];let i=[],r="";for(const s of t){const a=new Date(s.openTime),n=`${a.getUTCFullYear()}-${a.getUTCMonth()}`;n!==r&&i.length>0&&(e.push(i),i=[]),r=n,i.push(s)}return i.length>0&&e.push(i),e.map(di)}function di(t){const e=t[0],i=t[t.length-1];let r=e.high,s=e.low,a=0,n=0,o=0,l=0,c=0;for(let h=0;h<t.length;h++){const p=t[h];p.high>r&&(r=p.high),p.low<s&&(s=p.low),a+=p.volume,n+=p.quoteAssetVolume,o+=p.numberOfTrades,l+=p.takerBuyBaseAssetVolume,c+=p.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:r,low:s,close:i.close,volume:a,closeTime:i.closeTime,quoteAssetVolume:n,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function _d(t){if(t.length<2)return 0;const e=Math.min(t.length-1,20);let i=1/0;for(let r=0;r<e;r++){const s=t[r+1].openTime-t[r].openTime;s>0&&s<i&&(i=s)}return i===1/0?0:i}function bd(t){const e=new Date(t),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1)),s=Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${s}`}var vd=Object.defineProperty,wd=(t,e,i)=>e in t?vd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ri=(t,e,i)=>wd(t,typeof e!="symbol"?e+"":e,i);const si={"1s":"1S","5s":"5S","10s":"10S","15s":"15S","30s":"30S","1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1D":"D","1W":"W","1M":"M","4H":"240",D:"D",W:"W",M:"M"};function Sd(t){if(si[t]!==void 0)return si[t];const e=t.toLowerCase();return si[e]!==void 0?si[e]:/^\d+$/.test(t)?t:/^\d+S$/i.test(t)?t.toUpperCase():t}class Si{constructor(e){ri(this,"_configured"),ri(this,"_requiresApiKey"),ri(this,"_providerName"),ri(this,"_aggregationSubTimeframe",null),this._requiresApiKey=e.requiresApiKey,this._providerName=e.providerName,this._configured=!e.requiresApiKey}ensureConfigured(){if(!this._configured)throw new Error(`${this._providerName} requires configuration before use. Call Provider.${this._providerName}.configure({ apiKey: '...' }) or instantiate directly: new ${this._providerName}Provider({ apiKey: '...' })`)}configure(e){this._configured=!0}get isConfigured(){return this._configured}normalizeCloseTime(e){pd(e)}setAggregationSubTimeframe(e){this._aggregationSubTimeframe=e}getSupportedTimeframes(){return new Set(["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"])}async getMarketData(e,i,r,s,a){const n=Sd(i),o=this.getSupportedTimeframes();if(o.has(n))return this._getMarketDataNative(e,n,r,s,a);const l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:dd(n,o);if(!c)return console.error(`${this._providerName}: Timeframe '${i}' is not supported and no valid sub-timeframe found for aggregation.`),[];const h=this._computeSubLimit(n,c,r),p=await this._getMarketDataNative(e,c,h,s,a);if(p.length===0)return[];const u=md(p,n,c);return r&&r>0&&u.length>r?u.slice(u.length-r):u}_computeSubLimit(e,i,r){if(!r)return;const s=mn(e,i);return s===1/0?e==="W"?r*7+14:e==="M"?r*31+31:r*30:Math.ceil(r*s)+Math.ceil(s)}}var Ed=Object.defineProperty,Nd=(t,e,i)=>e in t?Ed(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,mi=(t,e,i)=>Nd(t,typeof e!="symbol"?e+"":e,i);const Mi="https://api.binance.com/api/v3",Hr="https://api.binance.us/api/v3",ni={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 Cd{constructor(e=300*1e3){mi(this,"cache"),mi(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(e){const i=this.generateKey(e),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(e,i){const r=this.generateKey(e);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[i,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class Id extends Si{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),mi(this,"cacheManager"),mi(this,"activeApiUrl",null),this.cacheManager=new Cd(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Mi}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=Mi,this.activeApiUrl}catch{}try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Hr}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=Hr,this.activeApiUrl}catch{}return Mi}async _fetchRawChunk(e,i,r,s,a){const n=ni[i.toUpperCase()];if(!n)return console.error(`Unsupported timeframe: ${i}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${n}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),s&&(o+=`&startTime=${s}`),a&&(o+=`&endTime=${a}`);const l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,i,r,s){try{const a=ni[i.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${i}`),[];let n=[],o=r;const l=s,c=qr[a];if(!c)return console.error(`Duration not defined for interval: ${a}`),[];for(;o<l;){const h=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,i,1e3,o,h);if(p.length===0)break;n=n.concat(p),o=p[p.length-1].closeTime+1}return this.normalizeCloseTime(n),n}catch(a){return console.error("Error in getMarketDataInterval:",a),[]}}async getMarketDataBackwards(e,i,r,s){let a=r,n=[],o=s,l=0;const c=Math.ceil(r/1e3)+5;for(;a>0&&l<c;){l++;const h=Math.min(a,1e3),p=await this._fetchRawChunk(e,i,h,void 0,o);if(p.length===0||(n=p.concat(n),a-=p.length,o=p[0].openTime-1,p.length<h))break}return this.normalizeCloseTime(n),n}getSupportedTimeframes(){return new Set(["1","3","5","15","30","60","120","240","D","W","M"])}async _getMarketDataNative(e,i,r,s,a){try{const n=a!==void 0,o={tickerId:e,timeframe:i,limit:r,sDate:s,eDate:a};if(n){const c=this.cacheManager.get(o);if(c)return c}if(!ni[i.toUpperCase()])return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,s,a)){if(s&&a){const c=await this.getMarketDataInterval(e,i,s,a),h=r?c.slice(0,r):c;return this.cacheManager.set(o,h),h}else if(r&&r>1e3){const c=await this.getMarketDataBackwards(e,i,r,a);return this.cacheManager.set(o,c),c}}const l=await this._fetchRawChunk(e,i,r,s,a);return this.normalizeCloseTime(l),n&&this.cacheManager.set(o,l),l}catch(n){return console.error("Error in binance.klines:",n),[]}}shouldPaginate(e,i,r,s){if(i&&i>1e3)return!0;if(r&&s){const a=ni[e.toUpperCase()],n=qr[a];if(n)return Math.ceil((s-r)/n)>1e3}return!1}async getSymbolInfo(e){try{let i="crypto",r=await this.getBaseUrl(),s=e,a="";e.endsWith(".P")?(i="futures",s=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",a="Perpetual"):e.includes("_")&&(i="futures",s=e,r="https://dapi.binance.com/dapi/v1",a="Delivery");const n=i==="crypto"?`${r}/exchangeInfo?symbol=${s}`:`${r}/exchangeInfo`,o=await fetch(n);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;const c=i==="futures"?l.find(v=>v.symbol===s):l[0];if(!c)return console.error(`Symbol ${s} not found in exchange info`),null;const h=c.filters?.find(v=>v.filterType==="PRICE_FILTER"),p=c.filters?.find(v=>v.filterType==="LOT_SIZE"),u=h?parseFloat(h.tickSize):.01,f=p?parseFloat(p.minQty):0,m=Math.round(1/u),x=c.baseAsset,_=c.quoteAsset,b=a?` ${a}`:"",w=`${x} / ${_}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:x,description:w,type:i,main_tickerid:`BINANCE:${e}`,current_contract:a,isin:"",basecurrency:x,currency:_,timezone:"Etc/UTC",country:"",mintick:u,pricescale:m,minmove:1,pointvalue:c.contractSize||1,mincontract:f,session:"24x7",volumetype:"base",expiration_date:c.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(i){return console.error("Error in binance.exchangeInfo:",i),null}}}var kd=Object.defineProperty,Ad=(t,e,i)=>e in t?kd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,jt=(t,e,i)=>Ad(t,typeof e!="symbol"?e+"":e,i);const Td="https://financialmodelingprep.com",Gr=new Set(["USD","EUR","GBP","JPY","CHF","AUD","CAD","NZD","SEK","NOK","DKK","SGD","HKD","KRW","MXN","ZAR","TRY","BRL","INR","CNY","PLN","CZK","HUF","ILS","THB","TWD","PHP","IDR","MYR","RUB","CLP","COP"]),Yr={"1D":{endpoint:"/stable/historical-price-eod/full",type:"daily"},D:{endpoint:"/stable/historical-price-eod/full",type:"daily"},1:{endpoint:"/stable/historical-chart/1min",interval:"1min",type:"intraday"},5:{endpoint:"/stable/historical-chart/5min",interval:"5min",type:"intraday"},15:{endpoint:"/stable/historical-chart/15min",interval:"15min",type:"intraday"},30:{endpoint:"/stable/historical-chart/30min",interval:"30min",type:"intraday"},60:{endpoint:"/stable/historical-chart/1hour",interval:"1hour",type:"intraday"},240:{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"},"4H":{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"}},Xr={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",NYSEArca:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",PNK:"America/New_York",TSX:"America/Toronto",TSXV:"America/Toronto",LSE:"Europe/London",EURONEXT:"Europe/Paris",XETRA:"Europe/Berlin",JPX:"Asia/Tokyo",HKSE:"Asia/Hong_Kong",SSE:"Asia/Shanghai",SHZ:"Asia/Shanghai",ASX:"Australia/Sydney",NSE:"Asia/Kolkata",BSE:"Asia/Kolkata",KRX:"Asia/Seoul",CRYPTO:"Etc/UTC"},Qr={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",NYSEArca:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",PNK:"0930-1600",TSX:"0930-1600",TSXV:"0930-1600",LSE:"0800-1630",EURONEXT:"0900-1730",XETRA:"0900-1730",JPX:"0900-1530",HKSE:"0930-1600",SSE:"0930-1500",SHZ:"0930-1500",ASX:"1000-1600",NSE:"0915-1530",BSE:"0915-1530",KRX:"0900-1530",CRYPTO:"24x7"},Pd={daily:{periodType:"day",multiplier:1},"1min":{periodType:"minute",multiplier:1},"5min":{periodType:"minute",multiplier:5},"15min":{periodType:"minute",multiplier:15},"30min":{periodType:"minute",multiplier:30},"1hour":{periodType:"hour",multiplier:1},"4hour":{periodType:"hour",multiplier:4}};class Dd extends Si{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),jt(this,"_apiKey",null),jt(this,"_baseUrl",Td),jt(this,"_profileCache",new Map),jt(this,"_symbolInfoCache",new Map),jt(this,"_mintickCache",new Map),e?.apiKey&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,e.baseUrl&&(this._baseUrl=e.baseUrl)}getSupportedTimeframes(){return new Set(["1","5","15","30","60","240","D"])}async _getMarketDataNative(e,i,r,s,a){this.ensureConfigured();try{const n=i.toUpperCase(),o=Yr[n]||Yr[i];if(!o)return console.error(`FMP: Unsupported timeframe: ${i}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,s,a,r):l=await this._fetchDailyData(e,s,a,r),l.length>0&&!this._mintickCache.has(e)){const c=this._estimateMintick(l);c!==void 0&&this._mintickCache.set(e,c)}return l}catch(n){return console.error("Error in FMPProvider.getMarketData:",n),[]}}async _fetchDailyData(e,i,r,s){let a=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;i&&(a+=`&from=${this._msToDateStr(i)}`),r&&(a+=`&to=${this._msToDateStr(r)}`);const n=await fetch(a);if(!n.ok){const p=await n.text();throw new Error(`FMP HTTP ${n.status}: ${p}`)}const o=await n.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();const l=s&&s>0&&s<o.length?o.slice(o.length-s):o,{session:c,timezone:h}=await this._resolveSessionInfo(e);return l.map(p=>{const u=this._dateStrToMs(p.date),f=Kr(u,c,h,"day");return{openTime:u,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:f,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,i,r,s,a,n){let o=`${this._baseUrl}${i}?symbol=${e}&apikey=${this._apiKey}`;s&&(o+=`&from=${this._msToDateStr(s)}`),a&&(o+=`&to=${this._msToDateStr(a)}`);const l=await fetch(o);if(!l.ok){const x=await l.text();if(l.status===403||x.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${r}) requires a paid plan. Use daily timeframe ('D') with a free API key, or upgrade at https://financialmodelingprep.com/`),[];throw new Error(`FMP HTTP ${l.status}: ${x}`)}const c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();const h=n&&n>0&&n<c.length?c.slice(c.length-n):c,{periodType:p,multiplier:u}=Pd[r]||{periodType:"minute",multiplier:1},{session:f,timezone:m}=await this._resolveSessionInfo(e);return h.map(x=>{const _=this._dateTimeStrToMs(x.date),b=Kr(_,f,m,p,u);return{openTime:_,open:x.open,high:x.high,low:x.low,close:x.close,volume:x.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){if(this.ensureConfigured(),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{const i=await this._fetchProfile(e);let r="stock";i?.isEtf?r="etf":i?.isFund?r="fund":this._isForex(e)?r="forex":this._isCrypto(e)&&(r="crypto");const s=i?.exchange||(r==="crypto"?"CRYPTO":r==="forex"?"FX":""),a=r==="crypto"||r==="forex"?"Etc/UTC":Xr[s]||"America/New_York",n=r==="crypto"?"24x7":r==="forex"?"0000-0000":Qr[s]||"0930-1600",o=i?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):i?.currency||"USD",c=this._mintickCache.get(e)??.01,h=Math.round(1/c),p=Math.round(c*h),u={ticker:i?.symbol||e,tickerid:`${s}:${i?.symbol||e}`,prefix:s,root:i?.symbol||e,description:i?.companyName||e,type:r,main_tickerid:`${s}:${i?.symbol||e}`,current_contract:"",isin:i?.isin||"",basecurrency:l,currency:o,timezone:a,country:i?.country||"",mintick:c,pricescale:h,minmove:p,pointvalue:1,mincontract:0,session:n,volumetype:"base",expiration_date:0,employees:i&&parseInt(i.fullTimeEmployees)||0,industry:i?.industry||"",sector:i?.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};return this._mintickCache.has(e)&&this._symbolInfoCache.set(e,u),u}catch(i){return console.error("Error in FMPProvider.getSymbolInfo:",i),null}}_estimateMintick(e){const i=[];for(let o=0;o<e.length;o++){const l=e[o],c=Math.abs(l.close-l.open),h=Math.abs(l.high-l.low);if(c>0&&i.push(c),h>0&&i.push(h),o>0){const p=Math.abs(l.close-e[o-1].close);p>0&&i.push(p)}}if(i.length===0)return;const r=Math.min(...i),s=Math.floor(Math.log10(r)),a=r/10**s,n=(Math.floor(a+1e-12)<5?1:10)*10**s;return n>=1?.01:n}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);const i=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(i);if(!r.ok)return null;const s=await r.json();if(!Array.isArray(s)||s.length===0)return null;const a=s[0];return this._profileCache.set(e,a),a}async _resolveSessionInfo(e){try{const i=await this._fetchProfile(e);if(i){const r=i.exchange||"",s=this._isCrypto(e),a=s?"Etc/UTC":Xr[r]||"America/New_York";return{session:s?"24x7":Qr[r]||"0930-1600",timezone:a}}}catch{}return{session:"0930-1600",timezone:"America/New_York"}}_msToDateStr(e){return new Date(e).toISOString().split("T")[0]}_dateStrToMs(e){return new Date(e+"T00:00:00Z").getTime()}_dateTimeStrToMs(e){return new Date(e.replace(" ","T")+"Z").getTime()}_isForex(e){return/^[A-Z]{6}$/.test(e)&&Gr.has(e.slice(0,3))&&Gr.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}}var Md=Object.defineProperty,Rd=(t,e,i)=>e in t?Md(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ft=(t,e,i)=>Rd(t,typeof e!="symbol"?e+"":e,i);const Od="https://data.alpaca.markets",Vd="https://paper-api.alpaca.markets/v2",Ld="https://api.alpaca.markets/v2",Ri=1e4,Zr={1:"1Min",3:"3Min",5:"5Min",15:"15Min",30:"30Min",60:"1Hour",120:"2Hour",240:"4Hour","4H":"4Hour","1D":"1Day",D:"1Day","1W":"1Week",W:"1Week","1M":"1Month",M:"1Month"},$d={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",ARCA:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",CRYPTO:"Etc/UTC"},jd={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},Bd={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"};class Fd extends Si{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),ft(this,"_apiKey",null),ft(this,"_apiSecret",null),ft(this,"_dataUrl",Od),ft(this,"_tradingUrl",Vd),ft(this,"_feed",null),ft(this,"_assetCache",new Map),ft(this,"_calendarCache",new Map),e?.apiKey&&e?.apiSecret&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,this._apiSecret=e.apiSecret,e.feed&&(this._feed=e.feed),e.dataUrl&&(this._dataUrl=e.dataUrl),e.tradingUrl?this._tradingUrl=e.tradingUrl:e.paper===!1&&(this._tradingUrl=Ld)}_headers(){return{"APCA-API-KEY-ID":this._apiKey,"APCA-API-SECRET-KEY":this._apiSecret}}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,s,a){this.ensureConfigured();try{const n=this._resolveTimeframe(i);if(!n)return console.error(`Alpaca: Unsupported timeframe: ${i}`),[];const o=this._isCrypto(e),l=await this._fetchAllBars(e,n,o,s,a,r);if(l.length===0)return[];const{periodType:c,multiplier:h}=this._parseAlpacaTimeframe(n);if(o)return this._convertBarsCrypto(l,c,h);const p=l[0].t.slice(0,10),u=l[l.length-1].t.slice(0,10),f=this._addDaysToDate(u,40);return await this._ensureCalendar(p,f),this._convertBarsStock(l,c,h)}catch(n){return console.error("Error in AlpacaProvider.getMarketData:",n),[]}}async _fetchAllBars(e,i,r,s,a,n){const o=[];let l=null;const c=n||1/0,h=Math.min(n||Ri,Ri);do{const p=this._buildBarsUrl(e,i,r,s,a,h,l),u=await fetch(p,{headers:this._headers()});if(!u.ok){const x=await u.text();throw new Error(`Alpaca HTTP ${u.status}: ${x}`)}const f=await u.json(),m=Object.keys(f.bars||{})[0];if(!m||!f.bars[m]||(o.push(...f.bars[m]),l=f.next_page_token,o.length>=c))break}while(l);return n&&n>0&&o.length>n?o.slice(0,n):o}_buildBarsUrl(e,i,r,s,a,n,o){const l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",i),c.set("sort","asc"),s&&c.set("start",new Date(s).toISOString()),a&&c.set("end",new Date(a).toISOString()),n&&c.set("limit",String(Math.min(n,Ri))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchAsset(e);if(!i)return console.error(`Alpaca: Symbol ${e} not found`),null;const r=i.exchange||"",s=i.class==="crypto",a=s?"Etc/UTC":$d[r]||"America/New_York",n=s?"24x7":jd[r]||"0930-1600";let o="stock";s&&(o="crypto");const l=s&&e.split("/")[1]||"USD",c=s?e.split("/")[0]||e:l,h=i.price_increment?parseFloat(i.price_increment):.01,p=Math.round(1/h);return{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:s?e.split("/")[0]:i.symbol,description:i.name||i.symbol,type:o,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:a,country:s?"":"US",mintick:h,pricescale:p,minmove:1,pointvalue:1,mincontract:i.min_order_size?parseFloat(i.min_order_size):0,session:n,volumetype:"base",expiration_date: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 AlpacaProvider.getSymbolInfo:",i),null}}_convertBarsCrypto(e,i,r){return e.map((s,a,n)=>{const o=new Date(s.t).getTime(),l=a<n.length-1?new Date(n[a+1].t).getTime():Kt(o,i,r);return this._toKline(s,o,l)})}_convertBarsStock(e,i,r){const s="America/New_York";return e.map(a=>{const n=new Date(a.t).getTime(),o=a.t.slice(0,10);let l;if(i==="day"){const c=this._calendarCache.get(o),h=c?c.close:"16:00";l=qe(o,h,s)}else if(i==="minute"||i==="hour"){const c=n+r*{minute:6e4,hour:36e5}[i],h=this._calendarCache.get(o),p=h?h.close:"16:00",u=qe(o,p,s);l=Math.min(c,u)}else i==="week"?l=this._weeklyCloseFromCalendar(o,s):i==="month"?l=this._monthlyCloseFromCalendar(o,s):l=Kt(n,i,r);return this._toKline(a,n,l)})}_toKline(e,i,r){return{openTime:i,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:r,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,i){const r=new Date(e+"T00:00:00Z"),s=r.getUTCDay(),a=s<=5?5-s:5-s+7;for(let l=a;l>=0;l--){const c=r.getTime()+l*864e5,h=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(h);if(p)return qe(h,p.close,i)}const n=r.getTime()+a*864e5,o=new Date(n).toISOString().split("T")[0];return qe(o,"16:00",i)}_monthlyCloseFromCalendar(e,i){const[r,s]=e.split("-").map(Number),a=new Date(Date.UTC(r,s,0)).getUTCDate();for(let o=a;o>=1;o--){const l=`${r}-${String(s).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return qe(l,c.close,i)}const n=new Date(Date.UTC(r,s,0));for(;n.getUTCDay()===0||n.getUTCDay()===6;)n.setUTCDate(n.getUTCDate()-1);return qe(n.toISOString().split("T")[0],"16:00",i)}async _ensureCalendar(e,i){if(this._calendarCache.has(e)&&this._calendarCache.has(i))return;const r=`${this._tradingUrl}/calendar?start=${e}&end=${i}`,s=await fetch(r,{headers:this._headers()});if(!s.ok){console.warn(`Alpaca calendar API returned ${s.status}, falling back to defaults`);return}const a=await s.json();for(const n of a)this._calendarCache.set(n.date,n)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);const i=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${i}`,s=await fetch(r,{headers:this._headers()});if(!s.ok)return null;const a=await s.json();return this._assetCache.set(e,a),a}_parseAlpacaTimeframe(e){const i=e.match(/^(\d+)(Min|Hour|Day|Week|Month)$/);if(i){const r=parseInt(i[1],10),s=Bd[i[2]];if(s)return{periodType:s,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Zr[e.toUpperCase()]||Zr[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,i){const r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+i),r.toISOString().split("T")[0]}}var Wd=Object.defineProperty,Ud=(t,e,i)=>e in t?Wd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Oi=(t,e,i)=>Ud(t,typeof e!="symbol"?e+"":e,i);const qd=gn(import.meta.url),Kd=Bt.dirname(qd);class zd extends Si{constructor(e){super({requiresApiKey:!1,providerName:"Mock"}),Oi(this,"dataCache",new Map),Oi(this,"exchangeInfoCache",{}),Oi(this,"dataDirectory");const i=typeof e=="string"?e:e?.dataDirectory;if(i)this.dataDirectory=i;else{const r=Bt.resolve(Kd,"../../../");this.dataDirectory=Bt.join(r,"tests","compatibility","_data")}}configure(e){super.configure(e),e.dataDirectory&&(this.dataDirectory=e.dataDirectory)}getDataFileName(e,i,r,s){return r&&s?`${e}-${i}-${r}-${s}.json`:null}loadDataFromFile(e){const i=`file:${e}`;if(this.dataCache.has(i))return this.dataCache.get(i);const r=Bt.join(this.dataDirectory,e);if(!wt.existsSync(r))throw new Error(`Mock data file not found: ${r}`);const s=wt.readFileSync(r,"utf-8"),a=JSON.parse(s);return this.dataCache.set(i,a),a}findDataFile(e,i,r,s){if(!wt.existsSync(this.dataDirectory))return null;const a=wt.readdirSync(this.dataDirectory).filter(l=>l.endsWith(".json"));if(r&&s){const l=`${e}-${i}-${r}-${s}.json`;if(a.includes(l))return l}const n=new RegExp(`^${e}-${i}-(\\d+)-(\\d+)\\.json$`),o=a.filter(l=>n.test(l)).map(l=>{const c=l.match(n);return{file:l,startTime:parseInt(c[1]),endTime:parseInt(c[2])}}).sort((l,c)=>c.endTime-l.endTime);if(o.length===0)return null;if(r&&s){const l=o.find(c=>c.startTime<=r&&c.endTime>=s);if(l)return l.file}return o[0].file}filterData(e,i,r,s){let a=e;return(i||r)&&(a=e.filter(n=>{const o=!i||n.openTime>=i,l=!r||n.openTime<=r;return o&&l})),a.sort((n,o)=>n.openTime-o.openTime),s&&s>0&&(a=a.slice(0,s)),a}normalizeTimeframe(e){return{1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"}[e.toUpperCase()]||e.toLowerCase()}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,i,r,s,a){try{const n=this.normalizeTimeframe(i),o=this.findDataFile(e,n,s,a);if(!o)return console.warn(`No mock data file found for ${e} ${n}. Searched in: ${this.dataDirectory}`),[];const l=this.loadDataFromFile(o),c=this.filterData(l,s,a,r);return this.normalizeCloseTime(c),c}catch(n){return console.error("Error in MockProvider.getMarketData:",n),[]}}loadExchangeInfo(e){if(this.exchangeInfoCache[e])return this.exchangeInfoCache[e];const i=e==="spot"?"api-exchangeInfo.json":"fapi-exchangeInfo.json",r=Bt.join(this.dataDirectory,i);if(!wt.existsSync(r))return console.warn(`Exchange info file not found: ${r}`),null;try{const s=wt.readFileSync(r,"utf-8"),a=JSON.parse(s);return this.exchangeInfoCache[e]=a,a}catch(s){return console.error(`Error loading exchange info from ${i}:`,s),null}}async getSymbolInfo(e){try{let i="crypto",r=e,s="";e.endsWith(".P")?(i="futures",r=e.replace(".P",""),s="Perpetual"):e.includes("_")&&(i="futures",r=e,s="Delivery");const a=this.loadExchangeInfo(i==="futures"?"futures":"spot");if(!a||!a.symbols)return console.error(`Exchange info not available for ${i}`),null;const n=a.symbols.find(_=>_.symbol===r);if(!n)return console.error(`Symbol ${r} not found in ${i} exchange info`),null;const o=n.filters?.find(_=>_.filterType==="PRICE_FILTER"),l=n.filters?.find(_=>_.filterType==="LOT_SIZE"),c=o?parseFloat(o.tickSize):.01,h=l?parseFloat(l.minQty):0,p=Math.round(1/c),u=n.baseAsset,f=n.quoteAsset,m=s?` ${s}`:"",x=`${u} / ${f}${m}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:u,description:x,type:i,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:u,currency:f,timezone:"Etc/UTC",country:"",mintick:c,pricescale:p,minmove:1,pointvalue:n.contractSize||1,mincontract:h,session:"24x7",volumetype:"base",expiration_date:n.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(e){this.dataDirectory=e,this.clearCache()}}const Hd=typeof process<"u"&&process.versions&&process.versions.node;let gi=null;if(Hd)try{gi=new zd}catch{gi=null}const Jd={Binance:new Id,FMP:new Dd,Alpaca:new Fd,...gi?{Mock:gi}:{}};var Gd=Object.defineProperty,Yd=(t,e,i)=>e in t?Gd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Xd=(t,e,i)=>Yd(t,typeof e!="symbol"?e+"":e,i);class em extends Error{constructor(e,i){super(e),Xd(this,"method"),this.name="PineRuntimeError",this.method=i}}export{Fd as AlpacaProvider,Si as BaseProvider,Id as BinanceProvider,Br as Context,Dd as FMPProvider,Wr as Indicator,em as PineRuntimeError,dn as PineTS,Jd as Provider,Zd as TIMEFRAME_PERIOD_INFO,qt as TIMEFRAME_SECONDS,md as aggregateCandles,Kt as computeNextPeriodStart,Kr as computeSessionClose,mn as getAggregationRatio,qe as localTimeToUTC,dd as selectSubTimeframe};
|
|
122
122
|
//# sourceMappingURL=pinets.min.es.js.map
|